Refactored the VertexArrayState's handling of vertex attribute aliasing
This commit is contained in:
@@ -698,58 +698,6 @@ class OSG_EXPORT GLExtensions : public osg::Referenced
|
||||
|
||||
GLint glMaxTextureCoords;
|
||||
GLint glMaxTextureUnits;
|
||||
public:
|
||||
|
||||
|
||||
void setUseVertexAttributeAliasing(bool flag) { _useVertexAttributeAliasing = flag; }
|
||||
bool getUseVertexAttributeAliasing() const { return _useVertexAttributeAliasing ; }
|
||||
|
||||
typedef std::vector<VertexAttribAlias> VertexAttribAliasList;
|
||||
typedef std::map<std::string,GLuint> AttribBindingList;
|
||||
|
||||
void setUpVertexAttribAlias(VertexAttribAlias& alias, GLuint location, const std::string glName, const std::string osgName, const std::string& declaration);
|
||||
|
||||
/** 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, unsigned int numTextureUnits=8);
|
||||
|
||||
/** 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 AttribBindingList& attribBindingList) { _attributeBindingList = attribBindingList; }
|
||||
const AttribBindingList& getAttributeBindingList() { return _attributeBindingList; }
|
||||
|
||||
|
||||
bool _useVertexAttributeAliasing;
|
||||
VertexAttribAlias _vertexAlias;
|
||||
VertexAttribAlias _normalAlias;
|
||||
VertexAttribAlias _colorAlias;
|
||||
VertexAttribAlias _secondaryColorAlias;
|
||||
VertexAttribAlias _fogCoordAlias;
|
||||
VertexAttribAliasList _texCoordAliasList;
|
||||
|
||||
AttribBindingList _attributeBindingList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class VertexArrayState : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
VertexArrayState(osg::GLExtensions* ext);
|
||||
VertexArrayState(osg::State* state);
|
||||
|
||||
struct ArrayDispatch : public osg::Referenced
|
||||
{
|
||||
@@ -157,6 +157,7 @@ public:
|
||||
|
||||
// osg::GLBufferObject* getGLBufferObject(osg::Array* array);
|
||||
|
||||
osg::State* _state;
|
||||
osg::ref_ptr<osg::GLExtensions> _ext;
|
||||
|
||||
GLuint _vertexArrayObject;
|
||||
|
||||
@@ -626,6 +626,5 @@ void Drawable::compileGLObjects(RenderInfo& renderInfo) const
|
||||
|
||||
VertexArrayState* Drawable::createVertexArrayState(RenderInfo& renderInfo, bool usingVBOs) const
|
||||
{
|
||||
osg::State* state = renderInfo.getState();
|
||||
return new osg::VertexArrayState(state->get<GLExtensions>());
|
||||
return new osg::VertexArrayState(renderInfo.getState());
|
||||
}
|
||||
|
||||
@@ -1180,14 +1180,6 @@ GLExtensions::GLExtensions(unsigned int in_contextID):
|
||||
glMaxTextureUnits = 0;
|
||||
glMaxTextureCoords = 0;
|
||||
}
|
||||
|
||||
#if !defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
|
||||
_useVertexAttributeAliasing = true;
|
||||
#else
|
||||
_useVertexAttributeAliasing = false;
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1295,63 +1287,3 @@ bool GLExtensions::getFragDataLocation( const char* fragDataName, GLuint& locati
|
||||
location = loc;
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Vertex Attrib Aliasing
|
||||
//
|
||||
void GLExtensions::setUpVertexAttribAlias(VertexAttribAlias& alias, GLuint location, const std::string glName, const std::string osgName, const std::string& declaration)
|
||||
{
|
||||
alias = VertexAttribAlias(location, glName, osgName, declaration);
|
||||
_attributeBindingList[osgName] = location;
|
||||
// OSG_NOTICE<<"State::setUpVertexAttribAlias("<<location<<" "<<glName<<" "<<osgName<<")"<<std::endl;
|
||||
}
|
||||
|
||||
void GLExtensions::resetVertexAttributeAlias(bool compactAliasing, unsigned int numTextureUnits)
|
||||
{
|
||||
_texCoordAliasList.clear();
|
||||
_attributeBindingList.clear();
|
||||
|
||||
if (compactAliasing)
|
||||
{
|
||||
unsigned int slot = 0;
|
||||
setUpVertexAttribAlias(_vertexAlias, slot++, "gl_Vertex","osg_Vertex","attribute vec4 ");
|
||||
setUpVertexAttribAlias(_normalAlias, slot++, "gl_Normal","osg_Normal","attribute vec3 ");
|
||||
setUpVertexAttribAlias(_colorAlias, slot++, "gl_Color","osg_Color","attribute vec4 ");
|
||||
|
||||
_texCoordAliasList.resize(numTextureUnits);
|
||||
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], slot++, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
|
||||
}
|
||||
|
||||
setUpVertexAttribAlias(_secondaryColorAlias, slot++, "gl_SecondaryColor","osg_SecondaryColor","attribute vec4 ");
|
||||
setUpVertexAttribAlias(_fogCoordAlias, slot++, "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 ");
|
||||
|
||||
unsigned int base = 8;
|
||||
_texCoordAliasList.resize(numTextureUnits);
|
||||
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], base+i, gl_MultiTexCoord.str(), osg_MultiTexCoord.str(), "attribute vec4 ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,7 +671,7 @@ VertexArrayState* Geometry::createVertexArrayState(RenderInfo& renderInfo, bool
|
||||
|
||||
VertexArrayState* vas = 0;
|
||||
|
||||
_vertexArrayStateList[state.getContextID()] = vas = new osg::VertexArrayState(state.get<GLExtensions>());
|
||||
_vertexArrayStateList[state.getContextID()] = vas = new osg::VertexArrayState(&state);
|
||||
|
||||
if (_vertexArray.valid()) vas->assignVertexArrayDispatcher();
|
||||
if (_colorArray.valid()) vas->assignColorArrayDispatcher();
|
||||
|
||||
@@ -178,7 +178,6 @@ void State::initializeExtensionProcs()
|
||||
_glExtensions = new GLExtensions(_contextID);
|
||||
GLExtensions::Set(_contextID, _glExtensions.get());
|
||||
|
||||
|
||||
computeSecondaryColorSupported();
|
||||
computeFogCoordSupported();
|
||||
computeVertexBufferObjectSupported();
|
||||
@@ -190,7 +189,7 @@ void State::initializeExtensionProcs()
|
||||
|
||||
|
||||
#ifdef USE_VERTEXARRAYSTATE
|
||||
_globalVertexArrayState = new VertexArrayState(_glExtensions.get());
|
||||
_globalVertexArrayState = new VertexArrayState(this);
|
||||
_globalVertexArrayState->assignAllDispatchers();
|
||||
setCurrentToGloabalVertexArrayState();
|
||||
#endif
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
|
||||
using namespace osg;
|
||||
|
||||
#if 1
|
||||
#define VAS_NOTICE OSG_INFO
|
||||
//#define VAS_NOTICE OSG_NOTICE
|
||||
|
||||
#else
|
||||
#define VAS_NOTICE OSG_NOTICE
|
||||
#endif
|
||||
|
||||
class VertexArrayStateManager : public GraphicsObjectManager
|
||||
{
|
||||
@@ -425,13 +427,14 @@ struct VertexAttribArrayDispatch : public VertexArrayState::ArrayDispatch
|
||||
//
|
||||
// VertexArrayState
|
||||
//
|
||||
VertexArrayState::VertexArrayState(osg::GLExtensions* ext):
|
||||
_ext(ext),
|
||||
VertexArrayState::VertexArrayState(osg::State* state):
|
||||
_state(state),
|
||||
_vertexArrayObject(0),
|
||||
_currentVBO(0),
|
||||
_currentEBO(0),
|
||||
_requiresSetArrays(true)
|
||||
{
|
||||
_ext = _state->get<GLExtensions>();
|
||||
}
|
||||
|
||||
void VertexArrayState::generateVretexArrayObject()
|
||||
@@ -452,78 +455,83 @@ void VertexArrayState::deleteVertexArrayObject()
|
||||
|
||||
void VertexArrayState::assignVertexArrayDispatcher()
|
||||
{
|
||||
OSG_NOTICE<<"VertexArrayState::assignVertexArrayDispatcher() _state->getUseVertexAttributeAliasing()="<<_state->getUseVertexAttributeAliasing()<<std::endl;
|
||||
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_ext->getUseVertexAttributeAliasing())
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
_vertexArray = new VertexArrayDispatch();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
_vertexArray = new VertexAttribArrayDispatch(_ext->getVertexAlias()._location);
|
||||
VAS_NOTICE<<"VertexArrayState::assignNormalArrayDispatcher() _state->getVertexAlias()._location="<<_state->getVertexAlias()._location<<std::endl;
|
||||
_vertexArray = new VertexAttribArrayDispatch(_state->getVertexAlias()._location);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayState::assignNormalArrayDispatcher()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_ext->getUseVertexAttributeAliasing())
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
_normalArray = new NormalArrayDispatch();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
_normalArray = new VertexAttribArrayDispatch(_ext->getNormalAlias()._location);
|
||||
VAS_NOTICE<<"VertexArrayState::assignNormalArrayDispatcher() _state->getNormalAlias()._location="<<_state->getNormalAlias()._location<<std::endl;
|
||||
_normalArray = new VertexAttribArrayDispatch(_state->getNormalAlias()._location);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayState::assignColorArrayDispatcher()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_ext->getUseVertexAttributeAliasing())
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
_colorArray = new ColorArrayDispatch();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
_colorArray = new VertexAttribArrayDispatch(_ext->getColorAlias()._location);
|
||||
VAS_NOTICE<<"VertexArrayState::assignColorArrayDispatcher() _state->getColorAlias()._location="<<_state->getColorAlias()._location<<std::endl;
|
||||
_colorArray = new VertexAttribArrayDispatch(_state->getColorAlias()._location);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayState::assignSecondaryColorArrayDispatcher()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_ext->getUseVertexAttributeAliasing())
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
_secondaryColorArray = new SecondaryColorArrayDispatch();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
_secondaryColorArray = new VertexAttribArrayDispatch(_ext->getSecondaryColorAlias()._location);
|
||||
_secondaryColorArray = new VertexAttribArrayDispatch(_state->getSecondaryColorAlias()._location);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayState::assignFogCoordArrayDispatcher()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_ext->getUseVertexAttributeAliasing())
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
_fogCoordArray = new FogCoordArrayDispatch();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
_fogCoordArray = new VertexAttribArrayDispatch(_ext->getFogCoordAlias()._location);
|
||||
_fogCoordArray = new VertexAttribArrayDispatch(_state->getFogCoordAlias()._location);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayState::assignTexCoordArrayDispatcher(unsigned int numUnits)
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_ext->getUseVertexAttributeAliasing())
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
_texCoordArrays.clear();
|
||||
for(unsigned int i=0; i<numUnits; ++i)
|
||||
@@ -537,7 +545,8 @@ void VertexArrayState::assignTexCoordArrayDispatcher(unsigned int numUnits)
|
||||
_texCoordArrays.clear();
|
||||
for(unsigned int i=0; i<numUnits; ++i)
|
||||
{
|
||||
_texCoordArrays.push_back( new VertexAttribArrayDispatch(_ext->getTexCoordAliasList()[i]._location) );
|
||||
VAS_NOTICE<<"VertexArrayState::VertexArrayState::assignTexCoordArrayDispatcher() _state->getTexCoordAliasList()[i]._location="<<_state->getTexCoordAliasList()[i]._location<<std::endl;
|
||||
_texCoordArrays.push_back( new VertexAttribArrayDispatch(_state->getTexCoordAliasList()[i]._location) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user