Refactored osg::Geometry::drawImplementation(..) to use new osg::ArrayDispatchers that encapsulate the task
of dispatch osg::Array data as OpenGL attributes.
This commit is contained in:
@@ -71,14 +71,14 @@ class OSG_EXPORT Array : public BufferData
|
||||
DoubleArrayType = 18,
|
||||
Vec2dArrayType = 19,
|
||||
Vec3dArrayType = 20,
|
||||
Vec4dArrayType = 21
|
||||
Vec4dArrayType = 21
|
||||
};
|
||||
|
||||
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
|
||||
_arrayType(arrayType),
|
||||
_dataSize(dataSize),
|
||||
_dataType(dataType) {}
|
||||
|
||||
|
||||
Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
BufferData(array,copyop),
|
||||
_arrayType(array._arrayType),
|
||||
@@ -88,7 +88,7 @@ class OSG_EXPORT Array : public BufferData
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const;
|
||||
|
||||
|
||||
virtual void accept(ArrayVisitor&) = 0;
|
||||
virtual void accept(ConstArrayVisitor&) const = 0;
|
||||
|
||||
@@ -131,13 +131,13 @@ template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
|
||||
class TemplateArray : public Array, public MixinVector<T>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
TemplateArray() : Array(ARRAYTYPE,DataSize,DataType) {}
|
||||
|
||||
TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Array(ta,copyop),
|
||||
MixinVector<T>(ta) {}
|
||||
|
||||
|
||||
TemplateArray(unsigned int no) :
|
||||
Array(ARRAYTYPE,DataSize,DataType),
|
||||
MixinVector<T>(no) {}
|
||||
@@ -181,7 +181,7 @@ class TemplateArray : public Array, public MixinVector<T>
|
||||
{
|
||||
MixinVector<T>( *this ).swap( *this );
|
||||
}
|
||||
|
||||
|
||||
virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
|
||||
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); }
|
||||
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
|
||||
@@ -200,16 +200,16 @@ class OSG_EXPORT IndexArray : public Array
|
||||
|
||||
IndexArray(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
|
||||
Array(arrayType,dataSize,dataType) {}
|
||||
|
||||
|
||||
IndexArray(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Array(array,copyop) {}
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const IndexArray*>(obj)!=NULL; }
|
||||
|
||||
|
||||
virtual unsigned int index(unsigned int pos) const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual ~IndexArray() {}
|
||||
};
|
||||
|
||||
@@ -217,13 +217,13 @@ template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
|
||||
class TemplateIndexArray : public IndexArray, public MixinVector<T>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
TemplateIndexArray() : IndexArray(ARRAYTYPE,DataSize,DataType) {}
|
||||
|
||||
TemplateIndexArray(const TemplateIndexArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
IndexArray(ta,copyop),
|
||||
MixinVector<T>(ta) {}
|
||||
|
||||
|
||||
TemplateIndexArray(unsigned int no) :
|
||||
IndexArray(ARRAYTYPE,DataSize,DataType),
|
||||
MixinVector<T>(no) {}
|
||||
@@ -267,7 +267,7 @@ class TemplateIndexArray : public IndexArray, public MixinVector<T>
|
||||
{
|
||||
MixinVector<T>( *this ).swap( *this );
|
||||
}
|
||||
|
||||
|
||||
virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
|
||||
virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); }
|
||||
virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
|
||||
@@ -277,7 +277,7 @@ class TemplateIndexArray : public IndexArray, public MixinVector<T>
|
||||
typedef T ElementDataType; // expose T
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual ~TemplateIndexArray() {}
|
||||
};
|
||||
|
||||
|
||||
106
include/osg/ArrayDispatchers
Normal file
106
include/osg/ArrayDispatchers
Normal file
@@ -0,0 +1,106 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_ArrayDispatchers
|
||||
#define OSG_ArrayDispatchers 1
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Array>
|
||||
#include <osg/Matrixd>
|
||||
|
||||
namespace osg {
|
||||
|
||||
// forward declare
|
||||
class State;
|
||||
class GLBeginEndAdapter;
|
||||
class AttributeDispatchMap;
|
||||
|
||||
struct AttributeDispatch : public osg::Referenced
|
||||
{
|
||||
virtual void assign(const GLvoid*, const IndexArray*) {}
|
||||
virtual void operator() (unsigned int) {};
|
||||
};
|
||||
|
||||
/** Helper class for managing the dispatch to OpenGL of various attribute arrays such as stored in osg::Geometry.*/
|
||||
class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
ArrayDispatchers(osg::State& state);
|
||||
~ArrayDispatchers();
|
||||
|
||||
void assignTexCoordDispatchers(unsigned int unit);
|
||||
void assignVertexAttribDispatchers(unsigned int unit);
|
||||
|
||||
AttributeDispatch* vertexDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* normalDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* colorDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* secondaryColorDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* fogCoordDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices);
|
||||
AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array, IndexArray* indices);
|
||||
|
||||
void reset();
|
||||
|
||||
void setUseGLBeginEndAdapter(bool flag) { _useGLBeginEndAdapter = flag; }
|
||||
bool getUseGLBeginEndAdapter() const { return _useGLBeginEndAdapter; }
|
||||
|
||||
void activate(unsigned int binding, AttributeDispatch* at);
|
||||
|
||||
void activateVertexArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { activate(binding, vertexDispatcher(array, indices)); }
|
||||
void activateColorArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { activate(binding, colorDispatcher(array, indices)); }
|
||||
void activateNormalArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { activate(binding, normalDispatcher(array, indices)); }
|
||||
void activateSecondaryColorArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { activate(binding, secondaryColorDispatcher(array, indices)); }
|
||||
void activateFogCoordArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { activate(binding, fogCoordDispatcher(array, indices)); }
|
||||
void activateTexCoordArray(unsigned int binding, unsigned int unit, osg::Array* array, osg::IndexArray* indices) { activate(binding, texCoordDispatcher(unit, array, indices)); }
|
||||
void activateVertexAttribArray(unsigned int binding, unsigned int unit, osg::Array* array, osg::IndexArray* indices) { activate(binding, vertexAttribDispatcher(unit, array, indices)); }
|
||||
|
||||
void dispatch(unsigned int binding);
|
||||
void dispatch(unsigned int binding, unsigned int index);
|
||||
|
||||
void Begin(GLenum mode);
|
||||
void End();
|
||||
|
||||
protected:
|
||||
|
||||
State* _state;
|
||||
GLBeginEndAdapter* _glBeginEndAdapter;
|
||||
|
||||
AttributeDispatchMap* _vertexDispatchers;
|
||||
AttributeDispatchMap* _normalDispatchers;
|
||||
AttributeDispatchMap* _colorDispatchers;
|
||||
AttributeDispatchMap* _secondaryColorDispatchers;
|
||||
AttributeDispatchMap* _fogCoordDispatchers;
|
||||
|
||||
typedef std::vector<AttributeDispatchMap*> AttributeDispatchMapList;
|
||||
AttributeDispatchMapList _texCoordDispatchers;
|
||||
AttributeDispatchMapList _vertexAttribDispatchers;
|
||||
|
||||
typedef std::vector<AttributeDispatch*> AttributeDispatchList;
|
||||
|
||||
struct BindingGroup
|
||||
{
|
||||
unsigned int _index;
|
||||
AttributeDispatchList _attributeDispatchList;
|
||||
};
|
||||
|
||||
typedef std::vector<BindingGroup> BindingGroupList;
|
||||
BindingGroupList _bindingGroupList;
|
||||
|
||||
bool _useGLBeginEndAdapter;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -666,7 +666,7 @@ class OSG_EXPORT Drawable : public Object
|
||||
void glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) const;
|
||||
void glGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64EXT *params) const;
|
||||
|
||||
protected:
|
||||
public:
|
||||
|
||||
typedef void (APIENTRY * FogCoordProc) (const GLfloat* coord);
|
||||
|
||||
@@ -735,9 +735,11 @@ class OSG_EXPORT Drawable : public Object
|
||||
VertexAttrib1sProc _glVertexAttrib1s;
|
||||
VertexAttrib1fProc _glVertexAttrib1f;
|
||||
VertexAttrib1dProc _glVertexAttrib1d;
|
||||
VertexAttribfvProc _glVertexAttrib1fv;
|
||||
VertexAttribfvProc _glVertexAttrib2fv;
|
||||
VertexAttribfvProc _glVertexAttrib3fv;
|
||||
VertexAttribfvProc _glVertexAttrib4fv;
|
||||
VertexAttribdvProc _glVertexAttrib1dv;
|
||||
VertexAttribdvProc _glVertexAttrib2dv;
|
||||
VertexAttribdvProc _glVertexAttrib3dv;
|
||||
VertexAttribdvProc _glVertexAttrib4dv;
|
||||
@@ -745,10 +747,12 @@ class OSG_EXPORT Drawable : public Object
|
||||
VertexAttribubvProc _glVertexAttrib4Nubv;
|
||||
|
||||
MultiTexCoord1fProc _glMultiTexCoord1f;
|
||||
MultiTexCoordfvProc _glMultiTexCoord1fv;
|
||||
MultiTexCoordfvProc _glMultiTexCoord2fv;
|
||||
MultiTexCoordfvProc _glMultiTexCoord3fv;
|
||||
MultiTexCoordfvProc _glMultiTexCoord4fv;
|
||||
MultiTexCoord1dProc _glMultiTexCoord1d;
|
||||
MultiTexCoorddvProc _glMultiTexCoord1dv;
|
||||
MultiTexCoorddvProc _glMultiTexCoord2dv;
|
||||
MultiTexCoorddvProc _glMultiTexCoord3dv;
|
||||
MultiTexCoorddvProc _glMultiTexCoord4dv;
|
||||
|
||||
@@ -54,13 +54,23 @@ class OSG_EXPORT GLBeginEndAdapter
|
||||
void Scaled(GLdouble x, GLdouble y, GLdouble z);
|
||||
void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
|
||||
|
||||
void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
void Color4fv(const GLfloat* c) { Color4f(c[0], c[1], c[2], c[3]); }
|
||||
|
||||
void Vertex3f(GLfloat x, GLfloat y, GLfloat z);
|
||||
void Vertex3fv(const GLfloat* v) { Vertex3f(v[0], v[1], v[2]); }
|
||||
|
||||
void Normal3f(GLfloat x, GLfloat y, GLfloat z);
|
||||
void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
|
||||
{
|
||||
_normalAssigned = true;
|
||||
_color.set(red,green,blue,alpha);
|
||||
}
|
||||
|
||||
void Color4fv(const GLfloat* c) { Color4f(c[0], c[1], c[2], c[3]); }
|
||||
|
||||
void Normal3f(GLfloat x, GLfloat y, GLfloat z)
|
||||
{
|
||||
_normalAssigned = true;
|
||||
_normal.set(x,y,z);
|
||||
}
|
||||
|
||||
void Normal3fv(const GLfloat* n) { Normal3f(n[0], n[1], n[2]); }
|
||||
|
||||
void TexCoord1f(GLfloat x) { MultiTexCoord4f(0, x, 0.0f, 0.0f, 1.0f); }
|
||||
@@ -140,7 +150,6 @@ class OSG_EXPORT GLBeginEndAdapter
|
||||
VertexArrayList _vertexAttribsList;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -476,13 +476,13 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
else glNormal3f(x,y,z);
|
||||
}
|
||||
|
||||
void TexCoord(float x, float y=0.0f, float z=0.0f, float w=0.0f)
|
||||
void TexCoord(float x, float y=0.0f, float z=0.0f, float w=1.0f)
|
||||
{
|
||||
if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[0]._location, x,y,z,w);
|
||||
else glTexCoord4f(x,y,z,w);
|
||||
}
|
||||
|
||||
void MultiTexCoord(unsigned int unit, float x, float y=0.0f, float z=0.0f, float w=0.0f)
|
||||
void MultiTexCoord(unsigned int unit, float x, float y=0.0f, float z=0.0f, float w=1.0f)
|
||||
{
|
||||
if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[unit]._location, x,y,z,w);
|
||||
else _glMultiTexCoord4f(GL_TEXTURE0+unit,x,y,z,w);
|
||||
|
||||
Reference in New Issue
Block a user