From bead0740f236dd5097f3643bf70b2956cea0d8d0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 26 Jun 2013 13:00:12 +0000 Subject: [PATCH] From Aurelien Albert, "This submission allow the user to specify how to setup VertexAttributeAliasing. I think this is necessary on OpenGL 3.2+ since this is no more "default" locations in the OpenGL specs. The default behaviour stay the same. There is a few new methods on osg::State : - resetVertexAttributeAlias : reset all vertex alias to osg's default ones - set**Alias : set a vertex attribute alias configuration - setAttributeBindingList : set the attribute binding list (allow to specify an empty list if you're using "layout" qualifier in glsl code to specify the bindings. This save some CPU operations)" --- include/osg/State | 23 +++++++++- src/osg/State.cpp | 113 ++++++++++++++++++++++++---------------------- 2 files changed, 80 insertions(+), 56 deletions(-) diff --git a/include/osg/State b/include/osg/State index dc9c5c267..c8655374f 100644 --- a/include/osg/State +++ b/include/osg/State @@ -263,14 +263,35 @@ class OSG_EXPORT State : public Referenced, public Observer typedef std::vector VertexAttribAliasList; + /** Reset the vertex attribute aliasing to osg's default. This method needs to be called before render anything unless you really know what you're doing !*/ + void resetVertexAttributeAlias(bool compactAliasing=true); + + /** Set the vertex attribute aliasing for "vertex". This method needs to be called before render anything unless you really know what you're doing !*/ + void setVertexAlias(const VertexAttribAlias& alias) { _vertexAlias = alias; } const VertexAttribAlias& getVertexAlias() { return _vertexAlias; } + + /** Set the vertex attribute aliasing for "normal". This method needs to be called before render anything unless you really know what you're doing !*/ + void setNormalAlias(const VertexAttribAlias& alias) { _normalAlias = alias; } const VertexAttribAlias& getNormalAlias() { return _normalAlias; } + + /** Set the vertex attribute aliasing for "color". This method needs to be called before render anything unless you really know what you're doing !*/ + void setColorAlias(const VertexAttribAlias& alias) { _colorAlias = alias; } const VertexAttribAlias& getColorAlias() { return _colorAlias; } + + /** Set the vertex attribute aliasing for "secondary color". This method needs to be called before render anything unless you really know what you're doing !*/ + void setSecondaryColorAlias(const VertexAttribAlias& alias) { _secondaryColorAlias = alias; } const VertexAttribAlias& getSecondaryColorAlias() { return _secondaryColorAlias; } + + /** Set the vertex attribute aliasing for "fog coord". This method needs to be called before render anything unless you really know what you're doing !*/ + void setFogCoordAlias(const VertexAttribAlias& alias) { _fogCoordAlias = alias; } const VertexAttribAlias& getFogCoordAlias() { return _fogCoordAlias; } + + /** Set the vertex attribute aliasing list for texture coordinates. This method needs to be called before render anything unless you really know what you're doing !*/ + void setTexCoordAliasList(const VertexAttribAliasList& aliasList) { _texCoordAliasList = aliasList; } const VertexAttribAliasList& getTexCoordAliasList() { return _texCoordAliasList; } - + /** Set the vertex attribute binding list. This method needs to be called before render anything unless you really know what you're doing !*/ + void setAttributeBindingList(const Program::AttribBindingList& attribBindingList) { _attributeBindingList = attribBindingList; } const Program::AttribBindingList& getAttributeBindingList() { return _attributeBindingList; } bool convertVertexShaderSourceToOsgBuiltIns(std::string& source) const; diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 471b372a0..e9f7109c8 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -67,47 +67,7 @@ State::State(): _modelViewProjectionMatrixUniform = new Uniform(Uniform::FLOAT_MAT4,"osg_ModelViewProjectionMatrix"); _normalMatrixUniform = new Uniform(Uniform::FLOAT_MAT3,"osg_NormalMatrix"); - bool compactAliasing = true; - if (compactAliasing) - { - setUpVertexAttribAlias(_vertexAlias,0, "gl_Vertex","osg_Vertex","attribute vec4 "); - setUpVertexAttribAlias(_normalAlias, 1, "gl_Normal","osg_Normal","attribute vec3 "); - setUpVertexAttribAlias(_colorAlias, 2, "gl_Color","osg_Color","attribute vec4 "); - - _texCoordAliasList.resize(5); - for(unsigned int i=0; i<_texCoordAliasList.size(); i++) - { - std::stringstream gl_MultiTexCoord; - std::stringstream osg_MultiTexCoord; - gl_MultiTexCoord<<"gl_MultiTexCoord"<