diff --git a/include/osg/ArrayDispatchers b/include/osg/ArrayDispatchers index 64a5ead2b..92c1a0911 100644 --- a/include/osg/ArrayDispatchers +++ b/include/osg/ArrayDispatchers @@ -54,6 +54,9 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced void setUseGLBeginEndAdapter(bool flag) { _useGLBeginEndAdapter = flag; } bool getUseGLBeginEndAdapter() const { return _useGLBeginEndAdapter; } + void setUseVertexAttribAlias(bool flag) { _useVertexAttribAlias = flag; } + bool getUseVertexAttribAlias() const { return _useVertexAttribAlias; } + void activate(unsigned int binding, AttributeDispatch* at) { if (at) _activeDispatchList[binding].push_back(at); @@ -118,7 +121,8 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced typedef std::vector ActiveDispatchList; ActiveDispatchList _activeDispatchList; - bool _useGLBeginEndAdapter; + bool _useVertexAttribAlias; + bool _useGLBeginEndAdapter; }; } diff --git a/include/osg/State b/include/osg/State index ca3bc12d5..35aecddc7 100644 --- a/include/osg/State +++ b/include/osg/State @@ -71,6 +71,31 @@ namespace osg { // forward declare GraphicsContext, View and State class GraphicsContext; +class VertexAttribAlias +{ + public: + VertexAttribAlias(): + _location(0) {} + + VertexAttribAlias(const VertexAttribAlias& rhs): + _location(rhs._location), + _glName(rhs._glName), + _osgName(rhs._osgName), + _declaration(rhs._declaration) {} + + VertexAttribAlias(GLuint location, const std::string glName, const std::string osgName, const std::string& declaration): + _location(location), + _glName(glName), + _osgName(osgName), + _declaration(declaration) {} + + GLuint _location; + std::string _glName; + std::string _osgName; + std::string _declaration; +}; + + /** Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings, * implements lazy state updating and provides accessors for querying the current state. * The venerable Red Book says that "OpenGL is a state machine", and this class @@ -188,9 +213,20 @@ class OSG_EXPORT State : public Referenced, public Observer Polytope getViewFrustum() const; + void setUseVertexAttributeAliasing(bool flag) { _useVertexAttributeAliasing = flag; } bool getUseVertexAttributeAliasing() const { return _useVertexAttributeAliasing ; } + typedef std::vector VertexAttribAliasList; + + const VertexAttribAlias& getVertexAlias() { return _vertexAlias; } + const VertexAttribAlias& getNormalAlias() { return _normalAlias; } + const VertexAttribAlias& getColorAlias() { return _colorAlias; } + const VertexAttribAlias& getSecondaryColorAlias() { return _secondaryColorAlias; } + const VertexAttribAlias& getFogCoordAlias() { return _fogCoordAlias; } + const VertexAttribAliasList& getTexCoordAliasList() { return _texCoordAliasList; } + + const Program::AttribBindingList& getAttributeBindingList() { return _attributeBindingList; } bool convertVertexShaderSourceToOsgBuiltIns(std::string& source) const; @@ -1276,24 +1312,6 @@ class OSG_EXPORT State : public Referenced, public Observer bool* _abortRenderingPtr; CheckForGLErrors _checkGLErrors; - struct VertexAttribAlias - { - VertexAttribAlias(): - _location(0) {} - - VertexAttribAlias(GLuint location, const std::string glName, const std::string osgName, const std::string& declaration): - _location(location), - _glName(glName), - _osgName(osgName), - _declaration(declaration) {} - - GLuint _location; - std::string _glName; - std::string _osgName; - std::string _declaration; - }; - - typedef std::vector VertexAttribAliasList; bool _useVertexAttributeAliasing; VertexAttribAlias _vertexAlias; diff --git a/src/osg/ArrayDispatchers.cpp b/src/osg/ArrayDispatchers.cpp index c7bec6a88..e6d7e862e 100644 --- a/src/osg/ArrayDispatchers.cpp +++ b/src/osg/ArrayDispatchers.cpp @@ -430,14 +430,45 @@ void ArrayDispatchers::init() _activeDispatchList.resize(5); } -AttributeDispatch* ArrayDispatchers::vertexDispatcher(Array* array, IndexArray* indices) { return _vertexDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); } -AttributeDispatch* ArrayDispatchers::normalDispatcher(Array* array, IndexArray* indices) { return _normalDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); } -AttributeDispatch* ArrayDispatchers::colorDispatcher(Array* array, IndexArray* indices) { return _colorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); } -AttributeDispatch* ArrayDispatchers::secondaryColorDispatcher(Array* array, IndexArray* indices) { return _secondaryColorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); } -AttributeDispatch* ArrayDispatchers::fogCoordDispatcher(Array* array, IndexArray* indices) { return _fogCoordDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); } +AttributeDispatch* ArrayDispatchers::vertexDispatcher(Array* array, IndexArray* indices) +{ + return _useVertexAttribAlias ? + vertexAttribDispatcher(_state->getVertexAlias()._location, array, indices) : + _vertexDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); +} + +AttributeDispatch* ArrayDispatchers::normalDispatcher(Array* array, IndexArray* indices) +{ + return _useVertexAttribAlias ? + vertexAttribDispatcher(_state->getNormalAlias()._location, array, indices) : + _normalDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); +} + +AttributeDispatch* ArrayDispatchers::colorDispatcher(Array* array, IndexArray* indices) +{ + return _useVertexAttribAlias ? + vertexAttribDispatcher(_state->getColorAlias()._location, array, indices) : + _colorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); +} + +AttributeDispatch* ArrayDispatchers::secondaryColorDispatcher(Array* array, IndexArray* indices) +{ + return _useVertexAttribAlias ? + vertexAttribDispatcher(_state->getSecondaryColorAlias()._location, array, indices) : + _secondaryColorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); +} + +AttributeDispatch* ArrayDispatchers::fogCoordDispatcher(Array* array, IndexArray* indices) +{ + return _useVertexAttribAlias ? + vertexAttribDispatcher(_state->getFogCoordAlias()._location, array, indices) : + _fogCoordDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); +} AttributeDispatch* ArrayDispatchers::texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices) { + if (_useVertexAttribAlias) return vertexAttribDispatcher(_state->getTexCoordAliasList()[unit]._location, array, indices); + if (unit>=_texCoordDispatchers.size()) assignTexCoordDispatchers(unit); return _texCoordDispatchers[unit]->dispatcher(_useGLBeginEndAdapter, array, indices); } diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index bd577a09d..0e92ecda7 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -1288,7 +1288,6 @@ void Geometry::releaseGLObjects(State* state) const void Geometry::drawImplementation(RenderInfo& renderInfo) const { State& state = *renderInfo.getState(); - bool vertexAttribAlias = state.getUseVertexAttributeAliasing(); Drawable::Extensions* extensions = Drawable::getExtensions(state.getContextID(),true); bool useFastPath = areFastPathsUsed(); @@ -1297,6 +1296,7 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers(); + arrayDispatchers.setUseVertexAttribAlias(state.getUseVertexAttributeAliasing()); arrayDispatchers.reset(); // arrayDispatchers.setUseGLBeginEndAdapter(!useFastPath); diff --git a/src/osgWrappers/genwrapper.conf b/src/osgWrappers/genwrapper.conf index 16c0382b7..3d2c67f6e 100644 --- a/src/osgWrappers/genwrapper.conf +++ b/src/osgWrappers/genwrapper.conf @@ -496,7 +496,7 @@ configure reflector "osg::Shader" end configure reflector "osg::State" - configure method /.*_(ModeStack|AttributeStack|ModeMap|AttributeMap|UniformMap|VertexAttribAlias)_.*/ + configure method /.*_(ModeStack|AttributeStack|ModeMap|AttributeMap|UniformMap)_.*/ replace with "" end end diff --git a/src/osgWrappers/osg/State.cpp b/src/osgWrappers/osg/State.cpp index 1c9228051..4f8db1d38 100644 --- a/src/osgWrappers/osg/State.cpp +++ b/src/osgWrappers/osg/State.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -42,6 +43,8 @@ END_REFLECTOR TYPE_NAME_ALIAS(std::vector< const osg::StateSet * >, osg::State::StateSetStack) +TYPE_NAME_ALIAS(std::vector< osg::VertexAttribAlias >, osg::State::VertexAttribAliasList) + TYPE_NAME_ALIAS(std::pair< const osg::StateAttribute * COMMA osg::StateAttribute::OverrideValue >, osg::State::AttributePair) TYPE_NAME_ALIAS(std::vector< osg::State::AttributePair >, osg::State::AttributeVec) @@ -223,6 +226,36 @@ BEGIN_OBJECT_REFLECTOR(osg::State) __bool__getUseVertexAttributeAliasing, "", ""); + I_Method0(const osg::VertexAttribAlias &, getVertexAlias, + Properties::NON_VIRTUAL, + __C5_VertexAttribAlias_R1__getVertexAlias, + "", + ""); + I_Method0(const osg::VertexAttribAlias &, getNormalAlias, + Properties::NON_VIRTUAL, + __C5_VertexAttribAlias_R1__getNormalAlias, + "", + ""); + I_Method0(const osg::VertexAttribAlias &, getColorAlias, + Properties::NON_VIRTUAL, + __C5_VertexAttribAlias_R1__getColorAlias, + "", + ""); + I_Method0(const osg::VertexAttribAlias &, getSecondaryColorAlias, + Properties::NON_VIRTUAL, + __C5_VertexAttribAlias_R1__getSecondaryColorAlias, + "", + ""); + I_Method0(const osg::VertexAttribAlias &, getFogCoordAlias, + Properties::NON_VIRTUAL, + __C5_VertexAttribAlias_R1__getFogCoordAlias, + "", + ""); + I_Method0(const osg::State::VertexAttribAliasList &, getTexCoordAliasList, + Properties::NON_VIRTUAL, + __C5_VertexAttribAliasList_R1__getTexCoordAliasList, + "", + ""); I_Method0(const osg::Program::AttribBindingList &, getAttributeBindingList, Properties::NON_VIRTUAL, __C5_Program_AttribBindingList_R1__getAttributeBindingList, @@ -863,7 +896,17 @@ BEGIN_OBJECT_REFLECTOR(osg::State) __GLBeginEndAdapter_R1__getGLBeginEndAdapter, "get the GL adapter object used to map OpenGL 1.0 glBegin/glEnd usage to vertex arrays. ", ""); - + I_Method0(osg::ArrayDispatchers &, getArrayDispatchers, + Properties::NON_VIRTUAL, + __ArrayDispatchers_R1__getArrayDispatchers, + "get the helper class for dispatching osg::Arrays as OpenGL attribute data. ", + ""); + I_ProtectedMethod5(void, setUpVertexAttribAlias, IN, osg::VertexAttribAlias &, alias, IN, GLuint, location, IN, const std::string, glName, IN, const std::string, osgName, IN, const std::string &, declaration, + Properties::NON_VIRTUAL, + Properties::NON_CONST, + __void__setUpVertexAttribAlias__VertexAttribAlias_R1__GLuint__C5_std_string__C5_std_string__C5_std_string_R1, + "", + ""); @@ -922,6 +965,9 @@ BEGIN_OBJECT_REFLECTOR(osg::State) I_SimpleProperty(unsigned int, ActiveTextureUnit, __unsigned_int__getActiveTextureUnit, __bool__setActiveTextureUnit__unsigned_int); + I_SimpleProperty(osg::ArrayDispatchers &, ArrayDispatchers, + __ArrayDispatchers_R1__getArrayDispatchers, + 0); I_SimpleProperty(const osg::Program::AttribBindingList &, AttributeBindingList, __C5_Program_AttribBindingList_R1__getAttributeBindingList, 0); @@ -931,6 +977,9 @@ BEGIN_OBJECT_REFLECTOR(osg::State) I_SimpleProperty(unsigned int, ClientActiveTextureUnit, __unsigned_int__getClientActiveTextureUnit, __bool__setClientActiveTextureUnit__unsigned_int); + I_SimpleProperty(const osg::VertexAttribAlias &, ColorAlias, + __C5_VertexAttribAlias_R1__getColorAlias, + 0); I_SimpleProperty(const osg::Array *, ColorPointer, 0, __void__setColorPointer__C5_Array_P1); @@ -958,6 +1007,9 @@ BEGIN_OBJECT_REFLECTOR(osg::State) I_SimpleProperty(osg::State::DynamicObjectRenderingCompletedCallback *, DynamicObjectRenderingCompletedCallback, __DynamicObjectRenderingCompletedCallback_P1__getDynamicObjectRenderingCompletedCallback, __void__setDynamicObjectRenderingCompletedCallback__DynamicObjectRenderingCompletedCallback_P1); + I_SimpleProperty(const osg::VertexAttribAlias &, FogCoordAlias, + __C5_VertexAttribAlias_R1__getFogCoordAlias, + 0); I_SimpleProperty(const osg::Array *, FogCoordPointer, 0, __void__setFogCoordPointer__C5_Array_P1); @@ -1009,6 +1061,9 @@ BEGIN_OBJECT_REFLECTOR(osg::State) I_SimpleProperty(osg::Uniform *, ModelViewProjectionMatrixUniform, __osg_Uniform_P1__getModelViewProjectionMatrixUniform, 0); + I_SimpleProperty(const osg::VertexAttribAlias &, NormalAlias, + __C5_VertexAttribAlias_R1__getNormalAlias, + 0); I_SimpleProperty(osg::Uniform *, NormalMatrixUniform, __osg_Uniform_P1__getNormalMatrixUniform, 0); @@ -1021,6 +1076,9 @@ BEGIN_OBJECT_REFLECTOR(osg::State) I_SimpleProperty(osg::Uniform *, ProjectionMatrixUniform, __osg_Uniform_P1__getProjectionMatrixUniform, 0); + I_SimpleProperty(const osg::VertexAttribAlias &, SecondaryColorAlias, + __C5_VertexAttribAlias_R1__getSecondaryColorAlias, + 0); I_SimpleProperty(const osg::Array *, SecondaryColorPointer, 0, __void__setSecondaryColorPointer__C5_Array_P1); @@ -1030,12 +1088,18 @@ BEGIN_OBJECT_REFLECTOR(osg::State) I_SimpleProperty(unsigned int, StateSetStackSize, __unsigned_int__getStateSetStackSize, 0); + I_SimpleProperty(const osg::State::VertexAttribAliasList &, TexCoordAliasList, + __C5_VertexAttribAliasList_R1__getTexCoordAliasList, + 0); I_SimpleProperty(bool, UseModelViewAndProjectionUniforms, __bool__getUseModelViewAndProjectionUniforms, __void__setUseModelViewAndProjectionUniforms__bool); I_SimpleProperty(bool, UseVertexAttributeAliasing, __bool__getUseVertexAttributeAliasing, __void__setUseVertexAttributeAliasing__bool); + I_SimpleProperty(const osg::VertexAttribAlias &, VertexAlias, + __C5_VertexAttribAlias_R1__getVertexAlias, + 0); I_SimpleProperty(const osg::Array *, VertexPointer, 0, __void__setVertexPointer__C5_Array_P1); @@ -1057,9 +1121,31 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::State::DynamicObjectRenderingCompletedCallb ""); END_REFLECTOR +BEGIN_VALUE_REFLECTOR(osg::VertexAttribAlias) + I_DeclaringFile("osg/State"); + I_Constructor0(____VertexAttribAlias, + "", + ""); + I_Constructor1(IN, const osg::VertexAttribAlias &, rhs, + Properties::NON_EXPLICIT, + ____VertexAttribAlias__C5_VertexAttribAlias_R1, + "", + ""); + I_Constructor4(IN, GLuint, location, IN, const std::string, glName, IN, const std::string, osgName, IN, const std::string &, declaration, + ____VertexAttribAlias__GLuint__C5_std_string__C5_std_string__C5_std_string_R1, + "", + ""); + I_PublicMemberProperty(GLuint, _location); + I_PublicMemberProperty(std::string, _glName); + I_PublicMemberProperty(std::string, _osgName); + I_PublicMemberProperty(std::string, _declaration); +END_REFLECTOR + STD_PAIR_REFLECTOR(std::pair< const osg::StateAttribute * COMMA osg::StateAttribute::OverrideValue >) STD_VECTOR_REFLECTOR(std::vector< const osg::StateSet * >) STD_VECTOR_REFLECTOR(std::vector< osg::State::AttributePair >) +STD_VECTOR_REFLECTOR(std::vector< osg::VertexAttribAlias >) +