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)"
This commit is contained in:
parent
831a552dfa
commit
bead0740f2
@ -263,14 +263,35 @@ class OSG_EXPORT State : public Referenced, public Observer
|
|||||||
|
|
||||||
typedef std::vector<VertexAttribAlias> VertexAttribAliasList;
|
typedef std::vector<VertexAttribAlias> 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; }
|
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; }
|
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; }
|
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; }
|
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; }
|
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; }
|
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; }
|
const Program::AttribBindingList& getAttributeBindingList() { return _attributeBindingList; }
|
||||||
|
|
||||||
bool convertVertexShaderSourceToOsgBuiltIns(std::string& source) const;
|
bool convertVertexShaderSourceToOsgBuiltIns(std::string& source) const;
|
||||||
|
@ -67,47 +67,7 @@ State::State():
|
|||||||
_modelViewProjectionMatrixUniform = new Uniform(Uniform::FLOAT_MAT4,"osg_ModelViewProjectionMatrix");
|
_modelViewProjectionMatrixUniform = new Uniform(Uniform::FLOAT_MAT4,"osg_ModelViewProjectionMatrix");
|
||||||
_normalMatrixUniform = new Uniform(Uniform::FLOAT_MAT3,"osg_NormalMatrix");
|
_normalMatrixUniform = new Uniform(Uniform::FLOAT_MAT3,"osg_NormalMatrix");
|
||||||
|
|
||||||
bool compactAliasing = true;
|
resetVertexAttributeAlias();
|
||||||
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"<<i;
|
|
||||||
osg_MultiTexCoord<<"osg_MultiTexCoord"<<i;
|
|
||||||
|
|
||||||
setUpVertexAttribAlias(_texCoordAliasList[i], 3+i, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
|
|
||||||
}
|
|
||||||
|
|
||||||
setUpVertexAttribAlias(_secondaryColorAlias, 6, "gl_SecondaryColor","osg_SecondaryColor","attribute vec4 ");
|
|
||||||
setUpVertexAttribAlias(_fogCoordAlias, 7, "gl_FogCoord","osg_FogCoord","attribute float ");
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setUpVertexAttribAlias(_vertexAlias,0, "gl_Vertex","osg_Vertex","attribute vec4 ");
|
|
||||||
setUpVertexAttribAlias(_normalAlias, 2, "gl_Normal","osg_Normal","attribute vec3 ");
|
|
||||||
setUpVertexAttribAlias(_colorAlias, 3, "gl_Color","osg_Color","attribute vec4 ");
|
|
||||||
setUpVertexAttribAlias(_secondaryColorAlias, 4, "gl_SecondaryColor","osg_SecondaryColor","attribute vec4 ");
|
|
||||||
setUpVertexAttribAlias(_fogCoordAlias, 5, "gl_FogCoord","osg_FogCoord","attribute float ");
|
|
||||||
|
|
||||||
_texCoordAliasList.resize(8);
|
|
||||||
for(unsigned int i=0; i<_texCoordAliasList.size(); i++)
|
|
||||||
{
|
|
||||||
std::stringstream gl_MultiTexCoord;
|
|
||||||
std::stringstream osg_MultiTexCoord;
|
|
||||||
gl_MultiTexCoord<<"gl_MultiTexCoord"<<i;
|
|
||||||
osg_MultiTexCoord<<"osg_MultiTexCoord"<<i;
|
|
||||||
|
|
||||||
setUpVertexAttribAlias(_texCoordAliasList[i], 8+i, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_abortRenderingPtr = NULL;
|
_abortRenderingPtr = NULL;
|
||||||
|
|
||||||
@ -848,6 +808,53 @@ Polytope State::getViewFrustum() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void State::resetVertexAttributeAlias(bool compactAliasing)
|
||||||
|
{
|
||||||
|
_texCoordAliasList.clear();
|
||||||
|
_attributeBindingList.clear();
|
||||||
|
|
||||||
|
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"<<i;
|
||||||
|
osg_MultiTexCoord<<"osg_MultiTexCoord"<<i;
|
||||||
|
|
||||||
|
setUpVertexAttribAlias(_texCoordAliasList[i], 3+i, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpVertexAttribAlias(_secondaryColorAlias, 6, "gl_SecondaryColor","osg_SecondaryColor","attribute vec4 ");
|
||||||
|
setUpVertexAttribAlias(_fogCoordAlias, 7, "gl_FogCoord","osg_FogCoord","attribute float ");
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setUpVertexAttribAlias(_vertexAlias,0, "gl_Vertex","osg_Vertex","attribute vec4 ");
|
||||||
|
setUpVertexAttribAlias(_normalAlias, 2, "gl_Normal","osg_Normal","attribute vec3 ");
|
||||||
|
setUpVertexAttribAlias(_colorAlias, 3, "gl_Color","osg_Color","attribute vec4 ");
|
||||||
|
setUpVertexAttribAlias(_secondaryColorAlias, 4, "gl_SecondaryColor","osg_SecondaryColor","attribute vec4 ");
|
||||||
|
setUpVertexAttribAlias(_fogCoordAlias, 5, "gl_FogCoord","osg_FogCoord","attribute float ");
|
||||||
|
|
||||||
|
_texCoordAliasList.resize(8);
|
||||||
|
for(unsigned int i=0; i<_texCoordAliasList.size(); i++)
|
||||||
|
{
|
||||||
|
std::stringstream gl_MultiTexCoord;
|
||||||
|
std::stringstream osg_MultiTexCoord;
|
||||||
|
gl_MultiTexCoord<<"gl_MultiTexCoord"<<i;
|
||||||
|
osg_MultiTexCoord<<"osg_MultiTexCoord"<<i;
|
||||||
|
|
||||||
|
setUpVertexAttribAlias(_texCoordAliasList[i], 8+i, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void State::disableAllVertexArrays()
|
void State::disableAllVertexArrays()
|
||||||
{
|
{
|
||||||
@ -1313,20 +1320,16 @@ bool State::convertVertexShaderSourceToOsgBuiltIns(std::string& source) const
|
|||||||
declPos = 0;
|
declPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_Normal", "osg_Normal", "attribute vec3 ");
|
State_Utils::replaceAndInsertDeclaration(source, declPos, _vertexAlias._glName, _vertexAlias._osgName, _vertexAlias._declaration);
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_Vertex", "osg_Vertex", "attribute vec4 ");
|
State_Utils::replaceAndInsertDeclaration(source, declPos, _normalAlias._glName, _normalAlias._osgName, _normalAlias._declaration);
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_Color", "osg_Color", "attribute vec4 ");
|
State_Utils::replaceAndInsertDeclaration(source, declPos, _colorAlias._glName, _colorAlias._osgName, _colorAlias._declaration);
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_SecondaryColor", "osg_SecondaryColor", "attribute vec4 ");
|
State_Utils::replaceAndInsertDeclaration(source, declPos, _secondaryColorAlias._glName, _secondaryColorAlias._osgName, _secondaryColorAlias._declaration);
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_FogCoord", "osg_FogCoord", "attribute float ");
|
State_Utils::replaceAndInsertDeclaration(source, declPos, _fogCoordAlias._glName, _fogCoordAlias._osgName, _fogCoordAlias._declaration);
|
||||||
|
for (size_t i=0; i<_texCoordAliasList.size(); i++)
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_MultiTexCoord0", "osg_MultiTexCoord0", "attribute vec4 ");
|
{
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_MultiTexCoord1", "osg_MultiTexCoord1", "attribute vec4 ");
|
const VertexAttribAlias& texCoordAlias = _texCoordAliasList[i];
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_MultiTexCoord2", "osg_MultiTexCoord2", "attribute vec4 ");
|
State_Utils::replaceAndInsertDeclaration(source, declPos, texCoordAlias._glName, texCoordAlias._osgName, texCoordAlias._declaration);
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_MultiTexCoord3", "osg_MultiTexCoord3", "attribute vec4 ");
|
}
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_MultiTexCoord4", "osg_MultiTexCoord4", "attribute vec4 ");
|
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_MultiTexCoord5", "osg_MultiTexCoord5", "attribute vec4 ");
|
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_MultiTexCoord6", "osg_MultiTexCoord6", "attribute vec4 ");
|
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_MultiTexCoord7", "osg_MultiTexCoord7", "attribute vec4 ");
|
|
||||||
|
|
||||||
// replace built in uniform
|
// replace built in uniform
|
||||||
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ModelViewMatrix", "osg_ModelViewMatrix", "uniform mat4 ");
|
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ModelViewMatrix", "osg_ModelViewMatrix", "uniform mat4 ");
|
||||||
|
Loading…
Reference in New Issue
Block a user