Implemented a different approach to vertex array object support to enable creation of a single global vertex array object as well as provide individual vertex array objects per Drawable when required.
This commit is contained in:
@@ -243,7 +243,8 @@ void DisplaySettings::setDefaults()
|
||||
_swapMethod = SWAP_DEFAULT;
|
||||
_syncSwapBuffers = 0;
|
||||
|
||||
_geometryImplementation = VERTEX_ARRAY_OBJECT;
|
||||
// _geometryImplementation = VERTEX_ARRAY_OBJECT;
|
||||
_geometryImplementation = OLD_GEOMETRY_IMPLEMENTATION;
|
||||
|
||||
_keystoneHint = false;
|
||||
|
||||
|
||||
@@ -234,6 +234,8 @@ Drawable::Drawable()
|
||||
_supportsVertexBufferObjects = true;
|
||||
_useVertexBufferObjects = false;
|
||||
#endif
|
||||
|
||||
_useVertexArrayObject = false;
|
||||
}
|
||||
|
||||
Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
|
||||
@@ -246,6 +248,7 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
|
||||
_useDisplayList(drawable._useDisplayList),
|
||||
_supportsVertexBufferObjects(drawable._supportsVertexBufferObjects),
|
||||
_useVertexBufferObjects(drawable._useVertexBufferObjects),
|
||||
_useVertexArrayObject(drawable._useVertexArrayObject),
|
||||
_drawCallback(drawable._drawCallback)
|
||||
{
|
||||
setStateSet(copyop(drawable._stateset.get()));
|
||||
@@ -285,38 +288,6 @@ void Drawable::computeDataVariance()
|
||||
setDataVariance(dynamic ? DYNAMIC : STATIC);
|
||||
}
|
||||
|
||||
void Drawable::compileGLObjects(RenderInfo& renderInfo) const
|
||||
{
|
||||
if (!_useDisplayList) return;
|
||||
|
||||
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
|
||||
// get the contextID (user defined ID of 0 upwards) for the
|
||||
// current OpenGL context.
|
||||
unsigned int contextID = renderInfo.getContextID();
|
||||
|
||||
// get the globj for the current contextID.
|
||||
GLuint& globj = _globjList[contextID];
|
||||
|
||||
// call the globj if already set otherwise compile and execute.
|
||||
if( globj != 0 )
|
||||
{
|
||||
glDeleteLists( globj, 1 );
|
||||
}
|
||||
|
||||
globj = generateDisplayList(contextID, getGLObjectSizeHint());
|
||||
glNewList( globj, GL_COMPILE );
|
||||
|
||||
if (_drawCallback.valid())
|
||||
_drawCallback->drawImplementation(renderInfo,this);
|
||||
else
|
||||
drawImplementation(renderInfo);
|
||||
|
||||
glEndList();
|
||||
#else
|
||||
OSG_NOTICE<<"Warning: Drawable::compileGLObjects(RenderInfo&) - not supported."<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Drawable::setThreadSafeRefUnref(bool threadSafe)
|
||||
{
|
||||
Object::setThreadSafeRefUnref(threadSafe);
|
||||
@@ -331,6 +302,8 @@ void Drawable::resizeGLObjectBuffers(unsigned int maxSize)
|
||||
if (_drawCallback.valid()) _drawCallback->resizeGLObjectBuffers(maxSize);
|
||||
|
||||
_globjList.resize(maxSize);
|
||||
|
||||
_vertexArrayStateList.resize(maxSize);
|
||||
}
|
||||
|
||||
void Drawable::releaseGLObjects(State* state) const
|
||||
@@ -361,6 +334,9 @@ void Drawable::releaseGLObjects(State* state) const
|
||||
{
|
||||
const_cast<Drawable*>(this)->dirtyDisplayList();
|
||||
}
|
||||
|
||||
|
||||
// TODO release VAO's..
|
||||
}
|
||||
|
||||
void Drawable::setSupportsDisplayList(bool flag)
|
||||
@@ -425,6 +401,13 @@ void Drawable::setUseDisplayList(bool flag)
|
||||
}
|
||||
|
||||
|
||||
void Drawable::setUseVertexArrayObject(bool flag)
|
||||
{
|
||||
_useVertexArrayObject = flag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Drawable::setUseVertexBufferObjects(bool flag)
|
||||
{
|
||||
// _useVertexBufferObjects = true;
|
||||
@@ -444,6 +427,11 @@ void Drawable::setUseVertexBufferObjects(bool flag)
|
||||
}
|
||||
|
||||
void Drawable::dirtyDisplayList()
|
||||
{
|
||||
dirtyGLObjects();
|
||||
}
|
||||
|
||||
void Drawable::dirtyGLObjects()
|
||||
{
|
||||
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
|
||||
unsigned int i;
|
||||
@@ -589,3 +577,115 @@ void Drawable::setBound(const BoundingBox& bb) const
|
||||
_boundingSphere = computeBound();
|
||||
_boundingSphereComputed = true;
|
||||
}
|
||||
|
||||
|
||||
void Drawable::compileGLObjects(RenderInfo& renderInfo) const
|
||||
{
|
||||
|
||||
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
|
||||
if (_useDisplayList)
|
||||
{
|
||||
// get the contextID (user defined ID of 0 upwards) for the
|
||||
// current OpenGL context.
|
||||
unsigned int contextID = renderInfo.getContextID();
|
||||
|
||||
// get the globj for the current contextID.
|
||||
GLuint& globj = _globjList[contextID];
|
||||
|
||||
// call the globj if already set otherwise compile and execute.
|
||||
if( globj != 0 )
|
||||
{
|
||||
glDeleteLists( globj, 1 );
|
||||
}
|
||||
|
||||
globj = generateDisplayList(contextID, getGLObjectSizeHint());
|
||||
glNewList( globj, GL_COMPILE );
|
||||
|
||||
drawInner(renderInfo);
|
||||
|
||||
glEndList();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Drawable::draw(RenderInfo& renderInfo) const
|
||||
{
|
||||
// OSG_NOTICE<<std::endl<<"Drawable::draw() "<<typeid(*this).name()<<std::endl;
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
State& state = *renderInfo.getState();
|
||||
const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance();
|
||||
bool useVertexArrayObject = _useVertexBufferObjects && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT);
|
||||
|
||||
if (useVertexArrayObject /*&& state.VAOSupported*/)
|
||||
{
|
||||
unsigned int contextID = renderInfo.getContextID();
|
||||
|
||||
VertexArrayState* vas = _vertexArrayStateList[contextID].get();
|
||||
if (!vas)
|
||||
{
|
||||
_vertexArrayStateList[contextID] = vas = setUpVertexArrayState(renderInfo, true);
|
||||
}
|
||||
|
||||
//state.pushVAO(localVAO);
|
||||
osg::ref_ptr<VertexArrayState> previous_vas = state.getCurrentVertexArrayState();
|
||||
|
||||
state.setCurrentVertexArrayState(vas);
|
||||
|
||||
vas->bindVertexArrayObject();
|
||||
|
||||
drawInner(renderInfo);
|
||||
|
||||
// state.popVAO();
|
||||
state.setCurrentVertexArrayState(previous_vas);
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO, add check against whether VOA is active and supported
|
||||
if (state.getCurrentVertexArrayState()) state.getCurrentVertexArrayState()->bindVertexArrayObject();
|
||||
|
||||
|
||||
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
|
||||
if (_useDisplayList)
|
||||
{
|
||||
// get the contextID (user defined ID of 0 upwards) for the
|
||||
// current OpenGL context.
|
||||
unsigned int contextID = renderInfo.getContextID();
|
||||
|
||||
// get the globj for the current contextID.
|
||||
GLuint& globj = _globjList[contextID];
|
||||
|
||||
if( globj == 0 )
|
||||
{
|
||||
// compile the display list
|
||||
globj = generateDisplayList(contextID, getGLObjectSizeHint());
|
||||
glNewList( globj, GL_COMPILE );
|
||||
|
||||
drawInner(renderInfo);
|
||||
|
||||
glEndList();
|
||||
}
|
||||
|
||||
// call the display list
|
||||
glCallList( globj);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// if state.previousVertexArrayState() is different than currentVertexArrayState bind current
|
||||
|
||||
// OSG_NOTICE<<"Fallback drawInner()........................"<<std::endl;
|
||||
|
||||
drawInner(renderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
VertexArrayState* Drawable::setUpVertexArrayState(RenderInfo& renderInfo, bool usingVBOs) const
|
||||
{
|
||||
osg::State* state = renderInfo.getState();
|
||||
return new osg::VertexArrayState(state->get<GLExtensions>());
|
||||
}
|
||||
|
||||
@@ -183,13 +183,13 @@ void GLBeginEndAdapter::Begin(GLenum mode)
|
||||
|
||||
// reset geometry
|
||||
_primitiveMode = mode;
|
||||
if (_vertices.valid()) _vertices->clear();
|
||||
if (_vertices.valid()) { _vertices->clear(); _vertices->dirty(); }
|
||||
|
||||
_normalAssigned = false;
|
||||
if (_normals.valid()) _normals->clear();
|
||||
if (_normals.valid()) { _normals->clear(); _normals->dirty(); }
|
||||
|
||||
_colorAssigned = false;
|
||||
if (_colors.valid()) _colors->clear();
|
||||
if (_colors.valid()) { _colors->clear(); _colors->dirty(); }
|
||||
|
||||
_texCoordAssignedList.clear();
|
||||
_texCoordList.clear();
|
||||
@@ -197,7 +197,7 @@ void GLBeginEndAdapter::Begin(GLenum mode)
|
||||
itr != _texCoordsList.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->valid()) (*itr)->clear();
|
||||
if (itr->valid()) { (*itr)->clear(); (*itr)->dirty(); }
|
||||
}
|
||||
|
||||
_vertexAttribAssignedList.clear();
|
||||
|
||||
@@ -29,7 +29,7 @@ Geometry::Geometry():
|
||||
// setSupportsDisplayList(false);
|
||||
#else
|
||||
_supportsVertexBufferObjects = true;
|
||||
_useVertexBufferObjects = true;
|
||||
_useVertexBufferObjects = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -600,17 +600,15 @@ void Geometry::setUseVertexBufferObjects(bool flag)
|
||||
}
|
||||
}
|
||||
|
||||
void Geometry::dirtyDisplayList()
|
||||
void Geometry::dirtyGLObjects()
|
||||
{
|
||||
Drawable::dirtyDisplayList();
|
||||
Drawable::dirtyGLObjects();
|
||||
}
|
||||
|
||||
void Geometry::resizeGLObjectBuffers(unsigned int maxSize)
|
||||
{
|
||||
Drawable::resizeGLObjectBuffers(maxSize);
|
||||
|
||||
_vertexArrayStateList.resize(maxSize);
|
||||
|
||||
ArrayList arrays;
|
||||
if (getArrayList(arrays))
|
||||
{
|
||||
@@ -675,21 +673,14 @@ VertexArrayState* Geometry::setUpVertexArrayState(RenderInfo& renderInfo, bool u
|
||||
|
||||
_vertexArrayStateList[state.getContextID()] = vas = new osg::VertexArrayState(state.get<GLExtensions>());
|
||||
|
||||
if (_vertexArray.valid()) vas->assignVertexArray(_vertexArray.get());
|
||||
if (_colorArray.valid()) vas->assignColorArray(_colorArray.get());
|
||||
if (_normalArray.valid()) vas->assignNormalArray(_normalArray.get());
|
||||
if (_secondaryColorArray.valid()) vas->assignSecondaryColorArray(_secondaryColorArray.get());
|
||||
if (_fogCoordArray.valid()) vas->assignFogCoordArray(_fogCoordArray.get());
|
||||
if (_vertexArray.valid()) vas->assignVertexArrayDispatcher();
|
||||
if (_colorArray.valid()) vas->assignColorArrayDispatcher();
|
||||
if (_normalArray.valid()) vas->assignNormalArrayDispatcher();
|
||||
if (_secondaryColorArray.valid()) vas->assignSecondaryColorArrayDispatcher();
|
||||
if (_fogCoordArray.valid()) vas->assignFogCoordArrayDispatcher();
|
||||
|
||||
for(unsigned int i=0; i<_texCoordList.size(); ++i)
|
||||
{
|
||||
if (_texCoordList[i].valid()) vas->assignTexCoordArray(i, _texCoordList[i].get());
|
||||
}
|
||||
|
||||
for(unsigned int i=0; i<_vertexAttribList.size(); ++i)
|
||||
{
|
||||
if (_vertexAttribList[i].valid()) vas->assignVertexAttribArray(i, _vertexAttribList[i].get());
|
||||
}
|
||||
if (!_texCoordList.empty()) vas->assignTexCoordArrayDispatcher(_texCoordList.size());
|
||||
if (!_vertexAttribList.empty()) vas->assignVertexAttribArrayDispatcher(_vertexAttribList.size());
|
||||
|
||||
if (usingVBOs && ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT)
|
||||
{
|
||||
@@ -771,24 +762,21 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const
|
||||
extensions->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
|
||||
|
||||
if (ds->getGeometryImplementation()!=DisplaySettings::OLD_GEOMETRY_IMPLEMENTATION)
|
||||
if (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT && !bufferObjects.empty())
|
||||
{
|
||||
setUpVertexArrayState(renderInfo, !bufferObjects.empty());
|
||||
setUpVertexArrayState(renderInfo, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ds->getGeometryImplementation()!=DisplaySettings::OLD_GEOMETRY_IMPLEMENTATION)
|
||||
{
|
||||
setUpVertexArrayState(renderInfo, false);
|
||||
}
|
||||
|
||||
Drawable::compileGLObjects(renderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void Geometry::drawImplementation(RenderInfo& renderInfo) const
|
||||
{
|
||||
// OSG_NOTICE<<" Geometry::drawImplementation()"<<std::endl;
|
||||
|
||||
if (_containsDeprecatedData)
|
||||
{
|
||||
OSG_WARN<<"Geometry::drawImplementation() unable to render due to deprecated data, call geometry->fixDeprecatedData();"<<std::endl;
|
||||
@@ -796,41 +784,30 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const
|
||||
}
|
||||
|
||||
State& state = *renderInfo.getState();
|
||||
const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance();
|
||||
|
||||
bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
|
||||
if (checkForGLErrors) state.checkGLErrors("start of Geometry::drawImplementation()");
|
||||
|
||||
|
||||
bool useNewImplementation = (ds->getGeometryImplementation()!=DisplaySettings::OLD_GEOMETRY_IMPLEMENTATION);
|
||||
if (useNewImplementation)
|
||||
{
|
||||
new_drawImplementation(renderInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
// OSG_NOTICE<<"Old implementation"<<std::endl;
|
||||
drawVertexArraysImplementation(renderInfo);
|
||||
|
||||
old_drawVertexArraysImplementation(renderInfo);
|
||||
if (checkForGLErrors) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup.");
|
||||
|
||||
if (checkForGLErrors) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup.");
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// draw the primitives themselves.
|
||||
//
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// draw the primitives themselves.
|
||||
//
|
||||
drawPrimitivesImplementation(renderInfo);
|
||||
|
||||
old_drawPrimitivesImplementation(renderInfo);
|
||||
// unbind the VBO's if any are used.
|
||||
state.unbindVertexBufferObject();
|
||||
state.unbindElementBufferObject();
|
||||
|
||||
// unbind the VBO's if any are used.
|
||||
state.unbindVertexBufferObject();
|
||||
state.unbindElementBufferObject();
|
||||
|
||||
if (checkForGLErrors) state.checkGLErrors("end of Geometry::drawImplementation().");
|
||||
}
|
||||
if (checkForGLErrors) state.checkGLErrors("end of Geometry::drawImplementation().");
|
||||
}
|
||||
|
||||
void Geometry::old_drawVertexArraysImplementation(RenderInfo& renderInfo) const
|
||||
void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const
|
||||
{
|
||||
State& state = *renderInfo.getState();
|
||||
|
||||
@@ -909,7 +886,7 @@ void Geometry::old_drawVertexArraysImplementation(RenderInfo& renderInfo) const
|
||||
state.applyDisablingOfVertexAttributes();
|
||||
}
|
||||
|
||||
void Geometry::old_drawPrimitivesImplementation(RenderInfo& renderInfo) const
|
||||
void Geometry::drawPrimitivesImplementation(RenderInfo& renderInfo) const
|
||||
{
|
||||
State& state = *renderInfo.getState();
|
||||
ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
|
||||
@@ -928,97 +905,6 @@ void Geometry::old_drawPrimitivesImplementation(RenderInfo& renderInfo) const
|
||||
}
|
||||
|
||||
|
||||
void Geometry::new_drawImplementation(RenderInfo& renderInfo) const
|
||||
{
|
||||
State& state = *renderInfo.getState();
|
||||
const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance();
|
||||
|
||||
unsigned int contextID = state.getContextID();
|
||||
|
||||
bool usingVertexBufferObjects = _supportsVertexBufferObjects && _useVertexBufferObjects && state.isVertexBufferObjectSupported();
|
||||
bool useVAO = usingVertexBufferObjects && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT);
|
||||
bool dispatchIfDirty = useVAO;
|
||||
|
||||
|
||||
VertexArrayState* vas = _vertexArrayStateList[contextID].get();
|
||||
|
||||
OSG_NOTICE<<"Geometry::new_drawImplementation() "<<this<<" _vertexArray.get()="<<_vertexArray.get()<<std::endl;
|
||||
|
||||
|
||||
bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
|
||||
|
||||
if (checkForGLErrors) state.checkGLErrors("Geometry::new_drawImplementation() before vertex arrays setup.");
|
||||
|
||||
if (!useVAO)
|
||||
{
|
||||
state.lazyDisablingOfVertexAttributes();
|
||||
}
|
||||
|
||||
if (!vas)
|
||||
{
|
||||
vas = setUpVertexArrayState(renderInfo, usingVertexBufferObjects);
|
||||
}
|
||||
|
||||
if (useVAO)
|
||||
{
|
||||
vas->bindVertexArrayObject();
|
||||
}
|
||||
|
||||
osg::ref_ptr<VertexArrayState> previous_vas = state.getCurrentVertexArrayState();
|
||||
|
||||
state.setCurrentVertexArrayState(vas);
|
||||
|
||||
vas->dispatchOverall(state);
|
||||
|
||||
|
||||
if (dispatchIfDirty)
|
||||
{
|
||||
vas->dispatchArraysIfDirty(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
vas->dispatchArrays(state);
|
||||
}
|
||||
|
||||
if (!useVAO)
|
||||
{
|
||||
state.applyDisablingOfVertexAttributes();
|
||||
}
|
||||
|
||||
for(unsigned int primitiveSetNum=0; primitiveSetNum<_primitives.size(); ++primitiveSetNum)
|
||||
{
|
||||
// dispatch any attributes that are bound per primitive
|
||||
vas->dispatchPerPrimitveSet(state, primitiveSetNum);
|
||||
|
||||
// disaptch the primitives
|
||||
_primitives[primitiveSetNum]->draw(state, usingVertexBufferObjects);
|
||||
}
|
||||
|
||||
state.setCurrentVertexArrayState(previous_vas);
|
||||
|
||||
if (!useVAO && usingVertexBufferObjects)
|
||||
{
|
||||
// unbind the VBO's if any are used.
|
||||
state.unbindVertexBufferObject();
|
||||
state.unbindElementBufferObject();
|
||||
}
|
||||
|
||||
if (useVAO)
|
||||
{
|
||||
vas->unbindVertexArrayObject();
|
||||
|
||||
state.setCurrentVertexBufferObject(vas->getCurrentVertexBufferObject());
|
||||
state.setCurrentElementBufferObject(vas->getCurrentElementBufferObject());
|
||||
|
||||
// unbind the VBO's if any are used.
|
||||
state.unbindVertexBufferObject();
|
||||
state.unbindElementBufferObject();
|
||||
}
|
||||
|
||||
if (checkForGLErrors) state.checkGLErrors("Geometry::new_drawImplementation() after primitive dispatch.");
|
||||
}
|
||||
|
||||
|
||||
void Geometry::accept(AttributeFunctor& af)
|
||||
{
|
||||
AttributeFunctorArrayVisitor afav(af);
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
using namespace osg;
|
||||
|
||||
#define VOA_NOTICE OSG_INFO
|
||||
//#define VOA_NOTICE OSG_NOTICE
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PrimitiveSet
|
||||
@@ -260,12 +263,12 @@ void DrawElementsUShort::draw(State& state, bool useVertexBufferObjects) const
|
||||
|
||||
if (state.getCurrentVertexArrayState())
|
||||
{
|
||||
OSG_NOTICE<<" DrawElementsUShort::draw() size="<<size()<<" A bind="<<ebo<<std::endl;
|
||||
VOA_NOTICE<<" DrawElementsUShort::draw() size="<<size()<<" A bind="<<ebo<<std::endl;
|
||||
state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" DrawElementsUShort::draw() size="<<size()<<" B bind="<<ebo<<std::endl;
|
||||
VOA_NOTICE<<" DrawElementsUShort::draw() size="<<size()<<" B bind="<<ebo<<std::endl;
|
||||
state.bindElementBufferObject(ebo);
|
||||
}
|
||||
|
||||
@@ -376,7 +379,7 @@ void DrawElementsUInt::offsetIndices(int offset)
|
||||
#ifdef OSG_HAS_MULTIDRAWARRAYS
|
||||
void MultiDrawArrays::draw(osg::State& state, bool) const
|
||||
{
|
||||
// OSG_NOTICE<<"osg::MultiDrawArrays::draw"<<std::endl;
|
||||
// VOA_NOTICE<<"osg::MultiDrawArrays::draw"<<std::endl;
|
||||
|
||||
GLExtensions* ext = state.get<GLExtensions>();
|
||||
if (ext->glMultiDrawArrays)
|
||||
|
||||
@@ -1945,7 +1945,7 @@ void ShapeDrawable::setColor(const Vec4& color)
|
||||
{
|
||||
if (_color!=color)
|
||||
{
|
||||
_color = color; dirtyDisplayList();
|
||||
_color = color; dirtyGLObjects();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1954,7 +1954,7 @@ void ShapeDrawable::setTessellationHints(TessellationHints* hints)
|
||||
if (_tessellationHints!=hints)
|
||||
{
|
||||
_tessellationHints = hints;
|
||||
dirtyDisplayList();
|
||||
dirtyGLObjects();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#define GL_MAX_TEXTURE_UNITS 0x84E2
|
||||
#endif
|
||||
|
||||
#define USE_VERTEXARRAYSTATE 1
|
||||
|
||||
using namespace std;
|
||||
using namespace osg;
|
||||
|
||||
@@ -208,6 +210,8 @@ void State::releaseGLObjects()
|
||||
|
||||
void State::reset()
|
||||
{
|
||||
OSG_NOTICE<<std::endl<<"State::reset() *************************** "<<std::endl;
|
||||
|
||||
#if 1
|
||||
for(ModeMap::iterator mitr=_modeMap.begin();
|
||||
mitr!=_modeMap.end();
|
||||
@@ -272,7 +276,7 @@ void State::reset()
|
||||
|
||||
dirtyAllVertexArrays();
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
// reset active texture unit values and call OpenGL
|
||||
// note, this OpenGL op precludes the use of State::reset() without a
|
||||
// valid graphics context, therefore the new implementation below
|
||||
@@ -929,23 +933,23 @@ void State::resetVertexAttributeAlias(bool compactAliasing, unsigned int numText
|
||||
void State::disableAllVertexArrays()
|
||||
{
|
||||
disableVertexPointer();
|
||||
disableTexCoordPointersAboveAndIncluding(0);
|
||||
disableVertexAttribPointersAboveAndIncluding(0);
|
||||
disableColorPointer();
|
||||
disableFogCoordPointer();
|
||||
disableNormalPointer();
|
||||
disableSecondaryColorPointer();
|
||||
disableTexCoordPointersAboveAndIncluding(0);
|
||||
disableVertexAttribPointersAboveAndIncluding(0);
|
||||
}
|
||||
|
||||
void State::dirtyAllVertexArrays()
|
||||
{
|
||||
dirtyVertexPointer();
|
||||
dirtyTexCoordPointersAboveAndIncluding(0);
|
||||
dirtyVertexAttribPointersAboveAndIncluding(0);
|
||||
dirtyColorPointer();
|
||||
dirtyFogCoordPointer();
|
||||
dirtyNormalPointer();
|
||||
dirtySecondaryColorPointer();
|
||||
dirtyTexCoordPointersAboveAndIncluding(0);
|
||||
dirtyVertexAttribPointersAboveAndIncluding(0);
|
||||
}
|
||||
|
||||
void State::setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer)
|
||||
@@ -981,7 +985,10 @@ void State::initializeExtensionProcs()
|
||||
_glExtensions = new GLExtensions(_contextID);
|
||||
GLExtensions::Set(_contextID, _glExtensions.get());
|
||||
|
||||
// _currentVertexArrayState = new VertexArrayState(_glExtensions.get());
|
||||
#ifdef USE_VERTEXARRAYSTATE
|
||||
_currentVertexArrayState = new VertexArrayState(_glExtensions.get());
|
||||
_currentVertexArrayState->assignAllDispatchers();
|
||||
#endif
|
||||
|
||||
setGLExtensionFuncPtr(_glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB");
|
||||
setGLExtensionFuncPtr(_glActiveTexture, "glActiveTexture","glActiveTextureARB");
|
||||
@@ -1055,54 +1062,395 @@ void State::initializeExtensionProcs()
|
||||
}
|
||||
}
|
||||
|
||||
bool State::setClientActiveTextureUnit( unsigned int unit )
|
||||
#if USE_VERTEXARRAYSTATE
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// New VertexArrayState version
|
||||
//
|
||||
void State::setVertexPointer(const Array* array)
|
||||
{
|
||||
if (unit!=_currentClientActiveTextureUnit)
|
||||
{
|
||||
if (_glClientActiveTexture && unit < (unsigned int)_glMaxTextureCoords)
|
||||
{
|
||||
_glClientActiveTexture(GL_TEXTURE0+unit);
|
||||
_currentClientActiveTextureUnit = unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
return unit==0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
_currentVertexArrayState->setVertexArray(*this, array);
|
||||
}
|
||||
|
||||
void State::disableVertexPointer()
|
||||
{
|
||||
_currentVertexArrayState->disableVertexArray(*this);
|
||||
}
|
||||
|
||||
void State::dirtyVertexPointer()
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyVertexPointer() "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::setNormalPointer(const Array* array)
|
||||
{
|
||||
_currentVertexArrayState->setNormalArray(*this, array);
|
||||
}
|
||||
|
||||
void State::disableNormalPointer()
|
||||
{
|
||||
_currentVertexArrayState->disableNormalArray(*this);
|
||||
}
|
||||
|
||||
void State::dirtyNormalPointer()
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyNormalPointer() "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
void State::setColorPointer(const Array* array)
|
||||
{
|
||||
_currentVertexArrayState->setColorArray(*this, array);
|
||||
}
|
||||
|
||||
void State::disableColorPointer()
|
||||
{
|
||||
_currentVertexArrayState->disableColorArray(*this);
|
||||
}
|
||||
|
||||
void State::dirtyColorPointer()
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyColorPointer() "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
void State::setSecondaryColorPointer( GLint size, GLenum type,
|
||||
GLsizei stride, const GLvoid *ptr, GLboolean normalized )
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET, setSecondaryColorPointer() "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::setSecondaryColorPointer(const Array* array)
|
||||
{
|
||||
_currentVertexArrayState->setSecondaryColorArray(*this, array);
|
||||
}
|
||||
|
||||
void State::disableSecondaryColorPointer()
|
||||
{
|
||||
_currentVertexArrayState->disableSecondaryColorArray(*this);
|
||||
}
|
||||
|
||||
void State::dirtySecondaryColorPointer()
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtySecondaryColorPointer() "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::setFogCoordPointer(const Array* array)
|
||||
{
|
||||
_currentVertexArrayState->setFogCoordArray(*this, array);
|
||||
}
|
||||
|
||||
void State::setFogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized)
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET, setFogCoordPointer "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::disableFogCoordPointer()
|
||||
{
|
||||
_currentVertexArrayState->disableFogCoordArray(*this);
|
||||
}
|
||||
|
||||
void State::dirtyFogCoordPointer()
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyFogCoordPointer() "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::setTexCoordPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
_currentVertexArrayState->setTexCoordArray(*this, unit, array);
|
||||
}
|
||||
|
||||
void State::disableTexCoordPointer( unsigned int unit )
|
||||
{
|
||||
_currentVertexArrayState->disableTexCoordArray(*this, unit);
|
||||
}
|
||||
|
||||
void State::disableTexCoordPointersAboveAndIncluding( unsigned int unit )
|
||||
{
|
||||
_currentVertexArrayState->disableTexCoordArrayAboveAndIncluding(*this, unit);
|
||||
}
|
||||
|
||||
void State::dirtyTexCoordPointersAboveAndIncluding( unsigned int unit )
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
bool State::setClientActiveTextureUnit( unsigned int unit )
|
||||
{
|
||||
// if (true)
|
||||
if (_currentClientActiveTextureUnit!=unit)
|
||||
{
|
||||
setVertexAttribPointer(_fogCoordAlias._location, 1, type, normalized, stride, ptr);
|
||||
// OSG_NOTICE<<"State::setClientActiveTextureUnit( "<<unit<<") done"<<std::endl;
|
||||
|
||||
_glClientActiveTexture(GL_TEXTURE0+unit);
|
||||
|
||||
_currentClientActiveTextureUnit = unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_glFogCoordPointer)
|
||||
{
|
||||
//OSG_NOTICE<<"State::setClientActiveTextureUnit( "<<unit<<") not required."<<std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_fogArray._enabled || _fogArray._dirty)
|
||||
{
|
||||
_fogArray._enabled = true;
|
||||
glEnableClientState(GL_FOG_COORDINATE_ARRAY);
|
||||
}
|
||||
//if (_fogArray._pointer!=ptr || _fogArray._dirty)
|
||||
{
|
||||
_fogArray._pointer=ptr;
|
||||
_glFogCoordPointer( type, stride, ptr );
|
||||
}
|
||||
_fogArray._lazy_disable = false;
|
||||
_fogArray._dirty = false;
|
||||
|
||||
unsigned int State::getClientActiveTextureUnit() const
|
||||
{
|
||||
return _currentClientActiveTextureUnit;
|
||||
}
|
||||
|
||||
void State::setVertexAttribPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
_currentVertexArrayState->setVertexAttribArray(*this, unit, array);
|
||||
}
|
||||
|
||||
|
||||
void State::setVertexAttribPointer( unsigned int index,
|
||||
GLint size, GLenum type, GLboolean normalized,
|
||||
GLsizei stride, const GLvoid *ptr )
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::setVertexAttribIPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
_currentVertexArrayState->setVertexAttribArray(*this, unit, array);
|
||||
}
|
||||
|
||||
void State::setVertexAttribIPointer( unsigned int index,
|
||||
GLint size, GLenum type,
|
||||
GLsizei stride, const GLvoid *ptr )
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::setVertexAttribLPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
_currentVertexArrayState->setVertexAttribArray(*this, unit, array);
|
||||
}
|
||||
|
||||
void State::setVertexAttribLPointer( unsigned int index,
|
||||
GLint size, GLenum type,
|
||||
GLsizei stride, const GLvoid *ptr )
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::dirtyVertexAttribPointersAboveAndIncluding( unsigned int index )
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyVertexAttribPointersAboveAndIncluding "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::disableVertexAttribPointer( unsigned int index )
|
||||
{
|
||||
_currentVertexArrayState->disableVertexAttribArray(*this, index);
|
||||
}
|
||||
|
||||
void State::disableVertexAttribPointersAboveAndIncluding( unsigned int index )
|
||||
{
|
||||
_currentVertexArrayState->disableVertexAttribArrayAboveAndIncluding(*this, index);
|
||||
}
|
||||
|
||||
void State::dirtyVertexAttribPointer( unsigned int index )
|
||||
{
|
||||
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyVertexAttribPointer() "<<__LINE__<<std::endl;
|
||||
}
|
||||
|
||||
void State::lazyDisablingOfVertexAttributes()
|
||||
{
|
||||
_currentVertexArrayState->lazyDisablingOfVertexAttributes();;
|
||||
}
|
||||
|
||||
void State::applyDisablingOfVertexAttributes()
|
||||
{
|
||||
_currentVertexArrayState->applyDisablingOfVertexAttributes(*this);
|
||||
}
|
||||
|
||||
void State::setCurrentVertexBufferObject(osg::GLBufferObject* vbo)
|
||||
{
|
||||
_currentVertexArrayState->setCurrentVertexBufferObject(vbo);
|
||||
}
|
||||
|
||||
const GLBufferObject* State::getCurrentVertexBufferObject()
|
||||
{
|
||||
return _currentVertexArrayState->getCurrentVertexBufferObject();
|
||||
}
|
||||
|
||||
void State::bindVertexBufferObject(osg::GLBufferObject* vbo)
|
||||
{
|
||||
_currentVertexArrayState->bindVertexBufferObject(vbo);
|
||||
}
|
||||
|
||||
void State::unbindVertexBufferObject()
|
||||
{
|
||||
_currentVertexArrayState->unbindVertexBufferObject();
|
||||
}
|
||||
|
||||
void State::setCurrentElementBufferObject(osg::GLBufferObject* ebo)
|
||||
{
|
||||
_currentVertexArrayState->setCurrentElementBufferObject(ebo);
|
||||
}
|
||||
|
||||
const GLBufferObject* State::getCurrentElementBufferObject()
|
||||
{
|
||||
return _currentVertexArrayState->getCurrentElementBufferObject();
|
||||
}
|
||||
|
||||
void State::bindElementBufferObject(osg::GLBufferObject* ebo)
|
||||
{
|
||||
_currentVertexArrayState->bindElementBufferObject(ebo);
|
||||
}
|
||||
|
||||
void State::unbindElementBufferObject()
|
||||
{
|
||||
_currentVertexArrayState->unbindElementBufferObject();
|
||||
}
|
||||
|
||||
#else
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Moved from State header
|
||||
//
|
||||
void State::setVertexPointer(const Array* array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0;
|
||||
if (vbo)
|
||||
{
|
||||
OSG_NOTICE<<" State::setVertexPointer("<<array<<") vbo="<<vbo<<std::endl;
|
||||
bindVertexBufferObject(vbo);
|
||||
setVertexPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize());
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" State::setVertexPointer("<<array<<") NO vbo="<<vbo<<std::endl;
|
||||
unbindVertexBufferObject();
|
||||
setVertexPointer(array->getDataSize(),array->getDataType(),0,array->getDataPointer(),array->getNormalize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void State::disableVertexPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
disableVertexAttribPointer(_vertexAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_vertexArray._enabled || _vertexArray._dirty)
|
||||
{
|
||||
_vertexArray._lazy_disable = false;
|
||||
_vertexArray._enabled = false;
|
||||
_vertexArray._dirty = false;
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
}
|
||||
#else
|
||||
setVertexAttribPointer(_fogCoordAlias._location, 1, type, normalized, stride, ptr);
|
||||
disableVertexAttribPointer(_vertexAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::dirtyVertexPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
dirtyVertexAttribPointer(_vertexAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
_vertexArray._pointer = 0;
|
||||
_vertexArray._dirty = true;
|
||||
}
|
||||
#else
|
||||
dirtyVertexAttribPointer(_vertexAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::setColorPointer(const Array* array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0;
|
||||
if (vbo)
|
||||
{
|
||||
OSG_NOTICE<<" State::setColorPointer("<<array<<") vbo="<<vbo<<std::endl;
|
||||
bindVertexBufferObject(vbo);
|
||||
setColorPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize());
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" State::setColorPointer("<<array<<") NO vbo="<<vbo<<std::endl;
|
||||
unbindVertexBufferObject();
|
||||
setColorPointer(array->getDataSize(),array->getDataType(),0,array->getDataPointer(),array->getNormalize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void State::disableColorPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
disableVertexAttribPointer(_colorAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_colorArray._enabled || _colorArray._dirty)
|
||||
{
|
||||
_colorArray._lazy_disable = false;
|
||||
_colorArray._enabled = false;
|
||||
_colorArray._dirty = false;
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
}
|
||||
#else
|
||||
disableVertexAttribPointer(_colorAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::dirtyColorPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
dirtyVertexAttribPointer(_colorAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
_colorArray._pointer = 0;
|
||||
_colorArray._dirty = true;
|
||||
}
|
||||
#else
|
||||
dirtyVertexAttribPointer(_colorAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void State::setNormalPointer(const Array* array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0;
|
||||
if (vbo)
|
||||
{
|
||||
OSG_NOTICE<<" State::setNormalPointer("<<array<<") vbo="<<vbo<<std::endl;
|
||||
bindVertexBufferObject(vbo);
|
||||
setNormalPointer(array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize());
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" State::setNormalPointer("<<array<<") NO vbo="<<vbo<<std::endl;
|
||||
unbindVertexBufferObject();
|
||||
setNormalPointer(array->getDataType(),0,array->getDataPointer(),array->getNormalize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void State::setSecondaryColorPointer( GLint size, GLenum type,
|
||||
GLsizei stride, const GLvoid *ptr, GLboolean normalized )
|
||||
{
|
||||
@@ -1135,8 +1483,335 @@ void State::setSecondaryColorPointer( GLint size, GLenum type,
|
||||
#endif
|
||||
}
|
||||
|
||||
/** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribPointerARB(..);
|
||||
* note, only updates values that change.*/
|
||||
void State::setSecondaryColorPointer(const Array* array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0;
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize());
|
||||
}
|
||||
else
|
||||
{
|
||||
unbindVertexBufferObject();
|
||||
setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,array->getDataPointer(),array->getNormalize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void State::disableSecondaryColorPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
disableVertexAttribPointer(_secondaryColorAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_secondaryColorArray._enabled || _secondaryColorArray._dirty)
|
||||
{
|
||||
_secondaryColorArray._lazy_disable = false;
|
||||
_secondaryColorArray._enabled = false;
|
||||
_secondaryColorArray._dirty = false;
|
||||
if (isSecondaryColorSupported()) glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
|
||||
}
|
||||
}
|
||||
#else
|
||||
disableVertexAttribPointer(_secondaryColorAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::dirtySecondaryColorPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
dirtyVertexAttribPointer(_secondaryColorAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
_secondaryColorArray._pointer = 0;
|
||||
_secondaryColorArray._dirty = true;
|
||||
}
|
||||
#else
|
||||
dirtyVertexAttribPointer(_secondaryColorAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
void State::disableNormalPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
disableVertexAttribPointer(_normalAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_normalArray._enabled || _normalArray._dirty)
|
||||
{
|
||||
_normalArray._lazy_disable = false;
|
||||
_normalArray._enabled = false;
|
||||
_normalArray._dirty = false;
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
}
|
||||
#else
|
||||
disableVertexAttribPointer(_normalAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::dirtyNormalPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
dirtyVertexAttribPointer(_normalAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
_normalArray._pointer = 0;
|
||||
_normalArray._dirty = true;
|
||||
}
|
||||
#else
|
||||
dirtyVertexAttribPointer(_normalAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::setFogCoordPointer(const Array* array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0;
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
setFogCoordPointer(array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize());
|
||||
}
|
||||
else
|
||||
{
|
||||
unbindVertexBufferObject();
|
||||
setFogCoordPointer(array->getDataType(),0,array->getDataPointer(),array->getNormalize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void State::setFogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized)
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
setVertexAttribPointer(_fogCoordAlias._location, 1, type, normalized, stride, ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_glFogCoordPointer)
|
||||
{
|
||||
|
||||
if (!_fogArray._enabled || _fogArray._dirty)
|
||||
{
|
||||
_fogArray._enabled = true;
|
||||
glEnableClientState(GL_FOG_COORDINATE_ARRAY);
|
||||
}
|
||||
//if (_fogArray._pointer!=ptr || _fogArray._dirty)
|
||||
{
|
||||
_fogArray._pointer=ptr;
|
||||
_glFogCoordPointer( type, stride, ptr );
|
||||
}
|
||||
_fogArray._lazy_disable = false;
|
||||
_fogArray._dirty = false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
setVertexAttribPointer(_fogCoordAlias._location, 1, type, normalized, stride, ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::disableFogCoordPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
disableVertexAttribPointer(_fogCoordAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_fogArray._enabled || _fogArray._dirty)
|
||||
{
|
||||
_fogArray._lazy_disable = false;
|
||||
_fogArray._enabled = false;
|
||||
_fogArray._dirty = false;
|
||||
if (isFogCoordSupported()) glDisableClientState(GL_FOG_COORDINATE_ARRAY);
|
||||
}
|
||||
}
|
||||
#else
|
||||
disableVertexAttribPointer(_fogCoordAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::dirtyFogCoordPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
dirtyVertexAttribPointer(_fogCoordAlias._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
_fogArray._pointer = 0;
|
||||
_fogArray._dirty = true;
|
||||
}
|
||||
#else
|
||||
dirtyVertexAttribPointer(_fogCoordAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::setTexCoordPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0;
|
||||
if (vbo)
|
||||
{
|
||||
OSG_NOTICE<<" State::setTexCoordPointer("<<unit<<", "<<array<<") vbo="<<vbo<<std::endl;
|
||||
bindVertexBufferObject(vbo);
|
||||
setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0, (const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize());
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" State::setTexCoordPointer("<<unit<<", "<<array<<") NO vbo="<<vbo<<std::endl;
|
||||
unbindVertexBufferObject();
|
||||
setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0,array->getDataPointer(),array->getNormalize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void State::disableTexCoordPointer( unsigned int unit )
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
disableVertexAttribPointer(_texCoordAliasList[unit]._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( unit >= _texCoordArrayList.size()) _texCoordArrayList.resize(unit+1);
|
||||
EnabledArrayPair& eap = _texCoordArrayList[unit];
|
||||
|
||||
if (eap._enabled || eap._dirty)
|
||||
{
|
||||
if(setClientActiveTextureUnit(unit))
|
||||
{
|
||||
eap._lazy_disable = false;
|
||||
eap._enabled = false;
|
||||
eap._dirty = false;
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
disableVertexAttribPointer(_texCoordAliasList[unit]._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::disableTexCoordPointersAboveAndIncluding( unsigned int unit )
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (unit<_texCoordArrayList.size())
|
||||
{
|
||||
EnabledArrayPair& eap = _texCoordArrayList[unit];
|
||||
if (eap._enabled || eap._dirty)
|
||||
{
|
||||
if (setClientActiveTextureUnit(unit))
|
||||
{
|
||||
eap._lazy_disable = false;
|
||||
eap._enabled = false;
|
||||
eap._dirty = false;
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
}
|
||||
++unit;
|
||||
}
|
||||
}
|
||||
#else
|
||||
disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
void State::dirtyTexCoordPointersAboveAndIncluding( unsigned int unit )
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (_useVertexAttributeAliasing)
|
||||
{
|
||||
dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (unit<_texCoordArrayList.size())
|
||||
{
|
||||
EnabledArrayPair& eap = _texCoordArrayList[unit];
|
||||
eap._pointer = 0;
|
||||
eap._dirty = true;
|
||||
++unit;
|
||||
}
|
||||
}
|
||||
#else
|
||||
dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool State::setClientActiveTextureUnit( unsigned int unit )
|
||||
{
|
||||
if (unit!=_currentClientActiveTextureUnit)
|
||||
{
|
||||
if (_glClientActiveTexture && unit < (unsigned int)_glMaxTextureCoords)
|
||||
{
|
||||
_glClientActiveTexture(GL_TEXTURE0+unit);
|
||||
_currentClientActiveTextureUnit = unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
return unit==0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int State::getClientActiveTextureUnit() const
|
||||
{
|
||||
return _currentClientActiveTextureUnit;
|
||||
}
|
||||
|
||||
|
||||
void State::setVertexAttribPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0;
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),array->getNormalize(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
unbindVertexBufferObject();
|
||||
setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),array->getNormalize(),0,array->getDataPointer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void State::setVertexAttribPointer( unsigned int index,
|
||||
GLint size, GLenum type, GLboolean normalized,
|
||||
GLsizei stride, const GLvoid *ptr )
|
||||
@@ -1165,6 +1840,23 @@ void State::setVertexAttribPointer( unsigned int index,
|
||||
eap._dirty = false;
|
||||
}
|
||||
}
|
||||
void State::setVertexAttribIPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
setVertexAttribIPointer(unit, array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
unbindVertexBufferObject();
|
||||
setVertexAttribIPointer(unit, array->getDataSize(),array->getDataType(),0,array->getDataPointer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribIPointer(..);
|
||||
* note, only updates values that change.*/
|
||||
@@ -1196,8 +1888,25 @@ void State::setVertexAttribIPointer( unsigned int index,
|
||||
eap._dirty = false;
|
||||
}
|
||||
}
|
||||
/** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribLPointer(..);
|
||||
* note, only updates values that change.*/
|
||||
|
||||
void State::setVertexAttribLPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
setVertexAttribLPointer(unit, array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
unbindVertexBufferObject();
|
||||
setVertexAttribLPointer(unit, array->getDataSize(),array->getDataType(),0,array->getDataPointer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void State::setVertexAttribLPointer( unsigned int index,
|
||||
GLint size, GLenum type,
|
||||
GLsizei stride, const GLvoid *ptr )
|
||||
@@ -1226,8 +1935,18 @@ void State::setVertexAttribLPointer( unsigned int index,
|
||||
eap._dirty = false;
|
||||
}
|
||||
}
|
||||
/** wrapper around DisableVertexAttribArrayARB(index);
|
||||
* note, only updates values that change.*/
|
||||
|
||||
void State::dirtyVertexAttribPointersAboveAndIncluding( unsigned int index )
|
||||
{
|
||||
while (index<_vertexAttribArrayList.size())
|
||||
{
|
||||
EnabledArrayPair& eap = _vertexAttribArrayList[index];
|
||||
eap._pointer = 0;
|
||||
eap._dirty = true;
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
void State::disableVertexAttribPointer( unsigned int index )
|
||||
{
|
||||
if (_glDisableVertexAttribArray)
|
||||
@@ -1264,6 +1983,16 @@ void State::disableVertexAttribPointersAboveAndIncluding( unsigned int index )
|
||||
}
|
||||
}
|
||||
|
||||
void State::dirtyVertexAttribPointer( unsigned int index )
|
||||
{
|
||||
if (index<_vertexAttribArrayList.size())
|
||||
{
|
||||
EnabledArrayPair& eap = _vertexAttribArrayList[index];
|
||||
eap._pointer = 0;
|
||||
eap._dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void State::lazyDisablingOfVertexAttributes()
|
||||
{
|
||||
// OSG_NOTICE<<"lazyDisablingOfVertexAttributes()"<<std::endl;
|
||||
@@ -1312,6 +2041,86 @@ void State::applyDisablingOfVertexAttributes()
|
||||
// OSG_NOTICE<<"end of applyDisablingOfVertexAttributes()"<<std::endl;
|
||||
}
|
||||
|
||||
void State::bindVertexBufferObject(osg::GLBufferObject* vbo)
|
||||
{
|
||||
OSG_NOTICE<<" State::bindVertexBufferObject("<<vbo<<") _currentVBO="<<_currentVBO<<std::endl;
|
||||
if (vbo)
|
||||
{
|
||||
if (vbo == _currentVBO) return;
|
||||
if (vbo->isDirty())
|
||||
{
|
||||
vbo->compileBuffer();
|
||||
OSG_NOTICE<<" done compileBuffer of "<<vbo<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
vbo->bindBuffer();
|
||||
OSG_NOTICE<<" done bind of "<<vbo<<std::endl;
|
||||
}
|
||||
_currentVBO = vbo;
|
||||
}
|
||||
else unbindVertexBufferObject();
|
||||
}
|
||||
|
||||
void State::unbindVertexBufferObject()
|
||||
{
|
||||
|
||||
OSG_NOTICE<<" State::unbindVertexBufferObject() _currentVBO="<<_currentVBO<<std::endl;
|
||||
if (!_currentVBO) return;
|
||||
_glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
|
||||
_currentVBO = 0;
|
||||
}
|
||||
|
||||
void State::setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; }
|
||||
const GLBufferObject* State::getCurrentVertexBufferObject() { return _currentVBO; }
|
||||
|
||||
void State::bindVertexBufferObject(osg::GLBufferObject* vbo)
|
||||
{
|
||||
if (vbo)
|
||||
{
|
||||
if (vbo == _currentVBO) return;
|
||||
if (vbo->isDirty()) vbo->compileBuffer();
|
||||
else vbo->bindBuffer();
|
||||
_currentVBO = vbo;
|
||||
}
|
||||
else unbindVertexBufferObject();
|
||||
}
|
||||
|
||||
void State::unbindVertexBufferObject()
|
||||
{
|
||||
if (!_currentVBO) return;
|
||||
_glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
|
||||
_currentVBO = 0;
|
||||
}
|
||||
|
||||
void State::setCurrentElementBufferObject(osg::GLBufferObject* ebo) { _currentEBO = ebo; }
|
||||
const GLBufferObject* State::getCurrentElementBufferObject() { return _currentEBO; }
|
||||
|
||||
void State::bindElementBufferObject(osg::GLBufferObject* ebo)
|
||||
{
|
||||
if (ebo)
|
||||
{
|
||||
if (ebo == _currentEBO) return;
|
||||
if (ebo->isDirty()) ebo->compileBuffer();
|
||||
else ebo->bindBuffer();
|
||||
_currentEBO = ebo;
|
||||
}
|
||||
else unbindElementBufferObject();
|
||||
}
|
||||
|
||||
void State::unbindElementBufferObject()
|
||||
{
|
||||
//if (!_currentEBO) return;
|
||||
_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
|
||||
_currentEBO = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// End of Moved from State header
|
||||
//
|
||||
|
||||
bool State::computeSecondaryColorSupported() const
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -385,7 +385,7 @@ void SphereSegment::dirtyAllDrawableDisplayLists()
|
||||
for(unsigned int i=0; i<getNumDrawables(); ++i)
|
||||
{
|
||||
osg::Drawable* drawable = getDrawable(i);
|
||||
if (drawable) drawable->dirtyDisplayList();
|
||||
if (drawable) drawable->dirtyGLObjects();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -907,7 +907,7 @@ struct ActivateTransparencyOnType
|
||||
ss->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK),osg::StateAttribute::ON);
|
||||
ss->setMode(GL_BLEND,osg::StateAttribute::ON);
|
||||
|
||||
drawable->dirtyDisplayList();
|
||||
drawable->dirtyGLObjects();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -931,7 +931,7 @@ struct DeactivateTransparencyOnType
|
||||
osg::StateSet* ss = drawable->getOrCreateStateSet();
|
||||
if(ss) ss->setRenderingHint(osg::StateSet::OPAQUE_BIN);
|
||||
|
||||
drawable->dirtyDisplayList();
|
||||
drawable->dirtyGLObjects();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user