Moved implementations from .cpp's to headers as inline methods to improve performance.

This commit is contained in:
Robert Osfield
2016-08-04 22:00:58 +01:00
parent 97df15b205
commit 1f147f6bc6
7 changed files with 448 additions and 396 deletions

View File

@@ -624,81 +624,6 @@ void Drawable::compileGLObjects(RenderInfo& renderInfo) const
#endif
}
void Drawable::draw(RenderInfo& renderInfo) const
{
// OSG_NOTICE<<std::endl<<"Drawable::draw() "<<typeid(*this).name()<<std::endl;
#if 1
State& state = *renderInfo.getState();
bool useVertexArrayObject = _useVertexBufferObjects && state.useVertexArrayObject();
if (useVertexArrayObject)
{
unsigned int contextID = renderInfo.getContextID();
VertexArrayState* vas = _vertexArrayStateList[contextID].get();
if (!vas)
{
_vertexArrayStateList[contextID] = vas = createVertexArrayState(renderInfo, true);
}
else
{
vas->setRequiresSetArrays(getDataVariance()==osg::Object::DYNAMIC);
}
State::SetCurrentVertexArrayStateProxy setVASProxy(state, vas);
vas->bindVertexArrayObject();
drawInner(renderInfo);
// vas->setRequiresSetArrays(getDataVariance()==osg::Object::DYNAMIC);
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::createVertexArrayState(RenderInfo& renderInfo, bool usingVBOs) const
{
osg::State* state = renderInfo.getState();

View File

@@ -770,7 +770,6 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const
vas->bindVertexArrayObject();
drawVertexArraysImplementation(renderInfo);
}
}

View File

@@ -1050,16 +1050,6 @@ void State::disableAllVertexArrays()
disableVertexAttribPointersAboveAndIncluding(0);
}
void State::dirtyAllVertexArrays()
{
dirtyVertexPointer();
dirtyColorPointer();
dirtyFogCoordPointer();
dirtyNormalPointer();
dirtySecondaryColorPointer();
dirtyTexCoordPointersAboveAndIncluding(0);
dirtyVertexAttribPointersAboveAndIncluding(0);
}
void State::setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer)
{
@@ -1078,6 +1068,8 @@ void State::setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* p
#if USE_VERTEXARRAYSTATE
#if 0
/////////////////////////////////////////////////////////////////////////
//
// New VertexArrayState version
@@ -1092,11 +1084,6 @@ 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);
@@ -1107,11 +1094,6 @@ void State::disableNormalPointer()
_currentVertexArrayState->disableNormalArray(*this);
}
void State::dirtyNormalPointer()
{
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyNormalPointer() "<<__LINE__<<std::endl;
}
void State::setColorPointer(const Array* array)
{
@@ -1123,18 +1105,8 @@ 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);
@@ -1145,31 +1117,18 @@ 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)
{
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);
@@ -1184,12 +1143,75 @@ void State::disableTexCoordPointersAboveAndIncluding( unsigned int unit )
{
_currentVertexArrayState->disableTexCoordArrayAboveAndIncluding(*this, unit);
}
#endif
#if 0
void State::dirtyVertexPointer()
{
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyVertexPointer() "<<__LINE__<<std::endl;
}
void State::dirtyNormalPointer()
{
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyNormalPointer() "<<__LINE__<<std::endl;
}
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::dirtySecondaryColorPointer()
{
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtySecondaryColorPointer() "<<__LINE__<<std::endl;
}
void State::setFogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized)
{
OSG_NOTICE<<"NOT IMPLEMENTED YET, setFogCoordPointer "<<__LINE__<<std::endl;
}
void State::dirtyFogCoordPointer()
{
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyFogCoordPointer() "<<__LINE__<<std::endl;
}
void State::dirtyTexCoordPointersAboveAndIncluding( unsigned int unit )
{
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::dirtyVertexAttribPointer( unsigned int index )
{
OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyVertexAttribPointer() "<<__LINE__<<std::endl;
}
void State::dirtyAllVertexArrays()
{
dirtyVertexPointer();
dirtyColorPointer();
dirtyFogCoordPointer();
dirtyNormalPointer();
dirtySecondaryColorPointer();
dirtyTexCoordPointersAboveAndIncluding(0);
dirtyVertexAttribPointersAboveAndIncluding(0);
}
#endif
void State::dirtyAllVertexArrays()
{
OSG_INFO<<"State::dirtyAllVertexArrays()"<<std::endl;
}
bool State::setClientActiveTextureUnit( unsigned int unit )
{
@@ -1252,11 +1274,6 @@ void State::setVertexAttribLPointer( unsigned int index,
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);
@@ -1267,10 +1284,6 @@ 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()
{

View File

@@ -439,18 +439,6 @@ void VertexArrayState::generateVretexArrayObject()
_ext->glGenVertexArrays(1, &_vertexArrayObject);
}
void VertexArrayState::bindVertexArrayObject() const
{
VAS_NOTICE<<"glBindVertexArray() _vertexArrayObject="<<_vertexArrayObject<<std::endl;
_ext->glBindVertexArray (_vertexArrayObject);
}
void VertexArrayState::unbindVertexArrayObject() const
{
_ext->glBindVertexArray (0);
}
void VertexArrayState::deleteVertexArrayObject()
{
if (_vertexArrayObject)
@@ -577,60 +565,24 @@ void VertexArrayState::assignAllDispatchers()
assignVertexAttribArrayDispatcher(numVertexAttrib);
}
void VertexArrayState::lazyDisablingOfVertexAttributes()
void VertexArrayState::release()
{
VAS_NOTICE<<" VertexArrayState<"<<this<<">::lazyDisablingOfVertexAttributes() _activeDispatchers.size()="<<_activeDispatchers.size()<<", _previous_activeDispatchers.size()="<<_previous_activeDispatchers.size()<<std::endl;
VAS_NOTICE<<"VertexArrayState::release() "<<this<<std::endl;
_activeDispatchers.swap(_previous_activeDispatchers);
_activeDispatchers.clear();
for(ActiveDispatchers::iterator itr = _previous_activeDispatchers.begin();
itr != _previous_activeDispatchers.end();
++itr)
{
ArrayDispatch* ad = (*itr);
// ad->array = 0;
ad->active = false;
}
}
void VertexArrayState::applyDisablingOfVertexAttributes(osg::State& state)
{
VAS_NOTICE<<" VertexArrayState<"<<this<<">::applyDisablingOfVertexAttributes() _activeDispatchers.size()="<<_activeDispatchers.size()<<", _previous_activeDispatchers.size()="<<_previous_activeDispatchers.size()<<std::endl;
for(ActiveDispatchers::iterator itr = _previous_activeDispatchers.begin();
itr != _previous_activeDispatchers.end();
++itr)
{
ArrayDispatch* ad = (*itr);
if (!ad->active)
{
ad->disable(state);
ad->array = 0;
ad->modifiedCount = 0xffffffff;
}
}
_previous_activeDispatchers.clear();
osg::get<VertexArrayStateManager>(_ext->contextID)->release(this);
}
void VertexArrayState::setArray(ArrayDispatch* vad, osg::State& state, const osg::Array* new_array)
{
if (new_array)
{
VAS_NOTICE<<" VertexArrayState<"<<this<<">::setArray() "<<typeid(*vad).name()<<" new_array="<<new_array<<", size()="<<new_array->getNumElements()<<std::endl;
if (!vad->active)
{
vad->active = true;
_activeDispatchers.push_back(vad);
}
#define LAZY_UPDATE
#define CHECK_IF_UPDATE
#ifdef LAZY_UPDATE
if (vad->array==0)
#endif
{
GLBufferObject* vbo = isVertexBufferObjectSupported() ? new_array->getOrCreateGLBufferObject(state.getContextID()) : 0;
if (vbo)
@@ -644,11 +596,7 @@ void VertexArrayState::setArray(ArrayDispatch* vad, osg::State& state, const osg
vad->enable_and_dispatch(state, new_array);
}
}
#ifdef LAZY_UPDATE
else
#ifdef CHECK_IF_UPDATE
if (new_array!=vad->array || new_array->getModifiedCount()!=vad->modifiedCount)
#endif
else if (new_array!=vad->array || new_array->getModifiedCount()!=vad->modifiedCount)
{
GLBufferObject* vbo = isVertexBufferObjectSupported() ? new_array->getOrCreateGLBufferObject(state.getContextID()) : 0;
if (vbo)
@@ -662,14 +610,6 @@ void VertexArrayState::setArray(ArrayDispatch* vad, osg::State& state, const osg
vad->dispatch(state, new_array);
}
}
#ifdef CHECK_IF_UPDATE
else
{
VAS_NOTICE<<"**************** No need to update *************************"<<std::endl;
return;
}
#endif
#endif
vad->array = new_array;
vad->modifiedCount = new_array->getModifiedCount();
@@ -677,31 +617,6 @@ void VertexArrayState::setArray(ArrayDispatch* vad, osg::State& state, const osg
}
else if (vad->array)
{
VAS_NOTICE<<" VertexArrayState::setArray() need to disable "<<typeid(*vad).name()<<std::endl;
disable(vad, state);
}
}
void VertexArrayState::disableTexCoordArrayAboveAndIncluding(osg::State& state, unsigned int index)
{
for(unsigned int i=index; i<_texCoordArrays.size(); ++i)
{
disable(_texCoordArrays[i].get(), state);
}
}
void VertexArrayState::disableVertexAttribArrayAboveAndIncluding(osg::State& state, unsigned int index)
{
for(unsigned int i=index; i<_vertexAttribArrays.size(); ++i)
{
disable(_vertexAttribArrays[i].get(), state);
}
}
void VertexArrayState::release()
{
VAS_NOTICE<<"VertexArrayState::release() "<<this<<std::endl;
osg::get<VertexArrayStateManager>(_ext->contextID)->release(this);
}