Experimental support for OpenGL Vertex Array Object

This commit is contained in:
Robert Osfield
2016-07-15 15:41:43 +01:00
parent d51036f57e
commit 14d1483b06
16 changed files with 1822 additions and 62 deletions

View File

@@ -221,6 +221,7 @@ SET(TARGET_H
${HEADER_PATH}/Vec4ui
${HEADER_PATH}/Vec4us
${HEADER_PATH}/VertexAttribDivisor
${HEADER_PATH}/VertexArrayState
${HEADER_PATH}/VertexProgram
${HEADER_PATH}/View
${HEADER_PATH}/Viewport
@@ -390,6 +391,7 @@ SET(TARGET_SRC
ValueStack.cpp
Version.cpp
VertexAttribDivisor.cpp
VertexArrayState.cpp
VertexProgram.cpp
View.cpp
Viewport.cpp

View File

@@ -116,6 +116,8 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs)
_glContextProfileMask = vs._glContextProfileMask;
_swapMethod = vs._swapMethod;
_geometryImplementation = vs._geometryImplementation;
_keystoneHint = vs._keystoneHint;
_keystoneFileNames = vs._keystoneFileNames;
_keystones = vs._keystones;
@@ -241,6 +243,8 @@ void DisplaySettings::setDefaults()
_swapMethod = SWAP_DEFAULT;
_syncSwapBuffers = 0;
_geometryImplementation = VERTEX_ARRAY_OBJECT;
_keystoneHint = false;
_OSXMenubarBehavior = MENUBAR_AUTO_HIDE;
@@ -361,6 +365,9 @@ static ApplicationUsageProxy DisplaySetting_e30(ApplicationUsage::ENVIRONMENTAL_
static ApplicationUsageProxy DisplaySetting_e31(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
"OSG_NvOptimusEnablement <value>",
"Set the hint to NvOptimus of whether to enable it or not, set 1 to enable, 0 to disable");
static ApplicationUsageProxy DisplaySetting_e32(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
"OSG_GEOMETRY_IMPLEMENTATION <value>",
"Set the hint to what backend osg::Geometry implementation to use. OLD | NEW | VERTEX_ARRAY_OBJECT");
void DisplaySettings::readEnvironmentalVariables()
{
@@ -671,6 +678,24 @@ void DisplaySettings::readEnvironmentalVariables()
}
}
if ((ptr = getenv("OSG_GEOMETRY_IMPLEMENTATION")) != 0)
{
if (strcmp(ptr,"OLD")==0)
{
_geometryImplementation = OLD_GEOMETRY_IMPLEMENTATION;
}
else if (strcmp(ptr,"NEW")==0 )
{
_geometryImplementation = NEW_GEOMETRY_IMPLEMENTATION;
}
else if (strcmp(ptr,"VERTEX_ARRAY_OBJECT")==0 || strcmp(ptr,"VAO")==0)
{
_geometryImplementation = VERTEX_ARRAY_OBJECT;
}
}
if( (ptr = getenv("OSG_KEYSTONE")) != 0)
{
if (strcmp(ptr,"OFF")==0)

View File

@@ -226,9 +226,14 @@ Drawable::Drawable()
_useDisplayList = false;
#endif
#if 0
_supportsVertexBufferObjects = false;
//_useVertexBufferObjects = false;
_useVertexBufferObjects = false;
// _useVertexBufferObjects = true;
#else
_supportsVertexBufferObjects = true;
_useVertexBufferObjects = false;
#endif
}
Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):

View File

@@ -246,6 +246,8 @@ void GLBeginEndAdapter::End()
}
_state->lazyDisablingOfVertexAttributes();
_state->unbindVertexBufferObject();
_state->unbindElementBufferObject();
if (_colorAssigned)
{
@@ -286,6 +288,8 @@ void GLBeginEndAdapter::End()
_state->applyDisablingOfVertexAttributes();
if (_primitiveMode==GL_QUADS)
{
_state->drawQuads(0, _vertices->size());

View File

@@ -22,8 +22,8 @@
#include <float.h>
#include <string>
#include <vector>
#include <set>
#include <sstream>
#if defined(WIN32)
#ifndef WIN32_LEAN_AND_MEAN
@@ -92,6 +92,12 @@ bool osg::isGLExtensionSupported(unsigned int contextID, const char *extension)
return osg::isGLExtensionOrVersionSupported(contextID, extension, FLT_MAX);
}
bool osg::isGLExtensionSupported(unsigned int contextID, const char *extension1, const char *extension2)
{
return osg::isGLExtensionOrVersionSupported(contextID, extension1, FLT_MAX) ||
osg::isGLExtensionOrVersionSupported(contextID, extension2, FLT_MAX);
}
bool osg::isGLExtensionOrVersionSupported(unsigned int contextID, const char *extension, float requiredGLVersion)
{
ExtensionSet& extensionSet = s_glExtensionSetList[contextID];
@@ -415,23 +421,24 @@ OSG_INIT_SINGLETON_PROXY(GLExtensionDisableStringInitializationProxy, osg::getGL
typedef osg::buffered_object< osg::ref_ptr<GLExtensions> > BufferedExtensions;
static BufferedExtensions s_extensions;
GLExtensions* GLExtensions::Get(unsigned int contextID, bool createIfNotInitalized)
GLExtensions* GLExtensions::Get(unsigned int in_contextID, bool createIfNotInitalized)
{
if (!s_extensions[contextID] && createIfNotInitalized)
s_extensions[contextID] = new GLExtensions(contextID);
if (!s_extensions[in_contextID] && createIfNotInitalized)
s_extensions[in_contextID] = new GLExtensions(in_contextID);
return s_extensions[contextID].get();
return s_extensions[in_contextID].get();
}
void GLExtensions::Set(unsigned int contextID, GLExtensions* extensions)
void GLExtensions::Set(unsigned int in_contextID, GLExtensions* extensions)
{
s_extensions[contextID] = extensions;
s_extensions[in_contextID] = extensions;
}
///////////////////////////////////////////////////////////////////////////
// Extension function pointers for OpenGL v2.x
GLExtensions::GLExtensions(unsigned int contextID)
GLExtensions::GLExtensions(unsigned int in_contextID):
contextID(in_contextID)
{
const char* versionString = (const char*) glGetString( GL_VERSION );
bool validContext = versionString!=0;
@@ -589,7 +596,9 @@ GLExtensions::GLExtensions(unsigned int contextID)
setGLExtensionFuncPtr(glVertexAttrib4ubv, "glVertexAttrib4ubv", validContext);
setGLExtensionFuncPtr(glVertexAttrib4uiv, "glVertexAttrib4uiv", validContext);
setGLExtensionFuncPtr(glVertexAttrib4usv, "glVertexAttrib4usv", validContext);
setGLExtensionFuncPtr(glVertexAttribPointer, "glVertexAttribPointer", validContext);
setGLExtensionFuncPtr(glVertexAttribPointer, "glVertexAttribPointer","glVertexAttribPointerARB", validContext);
setGLExtensionFuncPtr(glVertexAttribIPointer, "glVertexAttribIPointer","glVertexAttribIPointerARB", validContext);
setGLExtensionFuncPtr(glVertexAttribLPointer, "glVertexAttribLPointer","glVertexAttribPointerARB", validContext);
setGLExtensionFuncPtr(glVertexAttribDivisor, "glVertexAttribDivisor", validContext);
// v1.5-only ARB entry points, in case they're needed for fallback
@@ -666,6 +675,7 @@ GLExtensions::GLExtensions(unsigned int contextID)
// ARB_compute_shader
setGLExtensionFuncPtr(glDispatchCompute, "glDispatchCompute" , validContext);
setGLExtensionFuncPtr(glMemoryBarrier, "glMemoryBarrier", "glMemoryBarrierEXT" , validContext);
// BufferObject extensions
@@ -685,12 +695,13 @@ GLExtensions::GLExtensions(unsigned int contextID)
setGLExtensionFuncPtr(glBindBufferBase, "glBindBufferBase", "glBindBufferBaseEXT", "glBindBufferBaseNV" , validContext);
setGLExtensionFuncPtr(glTexBuffer, "glTexBuffer","glTexBufferARB" , validContext);
isPBOSupported = validContext && (OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID,"GL_ARB_pixel_buffer_object"));
isVBOSupported = validContext && (OSG_GLES2_FEATURES || OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID,"GL_ARB_vertex_buffer_object"));
isPBOSupported = validContext && (OSG_GLES2_FEATURES || OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID,"GL_ARB_pixel_buffer_object"));
isUniformBufferObjectSupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_uniform_buffer_object");
isTBOSupported = validContext && osg::isGLExtensionSupported(contextID,"GL_ARB_texture_buffer_object");
isVAOSupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_vertex_array_object");
isVAOSupported = validContext && (OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID, "GL_ARB_vertex_array_object", "GL_OES_vertex_array_object"));
isTransformFeedbackSupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_transform_feedback2");
isBufferObjectSupported = isPBOSupported && isVAOSupported;
isBufferObjectSupported = isVBOSupported && isPBOSupported;
// BlendFunc extensions
@@ -715,14 +726,24 @@ GLExtensions::GLExtensions(unsigned int contextID)
isTimerQuerySupported = validContext && osg::isGLExtensionSupported(contextID, "GL_EXT_timer_query");
isARBTimerQuerySupported = validContext && osg::isGLExtensionSupported(contextID, "GL_ARB_timer_query");
setGLExtensionFuncPtr(glDrawArraysInstanced, "glDrawArraysInstanced","glDrawArraysInstancedARB","glDrawArraysInstancedEXT", validContext);
setGLExtensionFuncPtr(glDrawElementsInstanced, "glDrawElementsInstanced","glDrawElementsInstancedARB","glDrawElementsInstancedEXT", validContext);
setGLExtensionFuncPtr(glFogCoordfv, "glFogCoordfv","glFogCoordfvEXT", validContext);
setGLExtensionFuncPtr(glSecondaryColor3ubv, "glSecondaryColor3ubv","glSecondaryColor3ubvEXT", validContext);
setGLExtensionFuncPtr(glSecondaryColor3fv, "glSecondaryColor3fv","glSecondaryColor3fvEXT", validContext);
setGLExtensionFuncPtr(glMultiTexCoord1f, "glMultiTexCoord1f","glMultiTexCoord1fARB", validContext);
setGLExtensionFuncPtr(glMultiTexCoord4f, "glMultiTexCoord4f","glMultiTexCoord4fARB", validContext);
setGLExtensionFuncPtr(glMultiTexCoord1fv, "glMultiTexCoord1fv","glMultiTexCoord1fvARB", validContext);
setGLExtensionFuncPtr(glMultiTexCoord2fv, "glMultiTexCoord2fv","glMultiTexCoord2fvARB", validContext);
setGLExtensionFuncPtr(glMultiTexCoord3fv, "glMultiTexCoord3fv","glMultiTexCoord3fvARB", validContext);
setGLExtensionFuncPtr(glMultiTexCoord4fv, "glMultiTexCoord4fv","glMultiTexCoord4fvARB", validContext);
setGLExtensionFuncPtr(glMultiTexCoord1d, "glMultiTexCoord1d","glMultiTexCoorddfARB", validContext);
setGLExtensionFuncPtr(glMultiTexCoord1dv, "glMultiTexCoord1dv","glMultiTexCoord1dvARB", validContext);
setGLExtensionFuncPtr(glMultiTexCoord2dv, "glMultiTexCoord2dv","glMultiTexCoord2dvARB", validContext);
@@ -1122,6 +1143,43 @@ GLExtensions::GLExtensions(unsigned int contextID)
osg::setGLExtensionFuncPtr(glDisableIndexedEXT, "glDisableIndexedEXT", validContext);
osg::setGLExtensionFuncPtr(glIsEnabledIndexedEXT, "glIsEnabledIndexedEXT", validContext);
setGLExtensionFuncPtr(glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB", validContext);
setGLExtensionFuncPtr(glActiveTexture, "glActiveTexture","glActiveTextureARB", validContext);
setGLExtensionFuncPtr(glFogCoordPointer, "glFogCoordPointer","glFogCoordPointerEXT", validContext);
setGLExtensionFuncPtr(glSecondaryColorPointer, "glSecondaryColorPointer","glSecondaryColorPointerEXT", validContext);
if (validContext)
{
if (osg::getGLVersionNumber() >= 2.0 || osg::isGLExtensionSupported(contextID, "GL_ARB_vertex_shader") || OSG_GLES2_FEATURES || OSG_GL3_FEATURES)
{
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,&glMaxTextureUnits);
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
glGetIntegerv(GL_MAX_TEXTURE_COORDS, &glMaxTextureCoords);
#else
glMaxTextureCoords = _glMaxTextureUnits;
#endif
}
else if ( osg::getGLVersionNumber() >= 1.3 ||
osg::isGLExtensionSupported(contextID,"GL_ARB_multitexture") ||
osg::isGLExtensionSupported(contextID,"GL_EXT_multitexture") ||
OSG_GLES1_FEATURES)
{
GLint maxTextureUnits = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS,&maxTextureUnits);
glMaxTextureUnits = maxTextureUnits;
glMaxTextureCoords = maxTextureUnits;
}
else
{
glMaxTextureUnits = 1;
glMaxTextureCoords = 1;
}
}
else
{
glMaxTextureUnits = 0;
glMaxTextureCoords = 0;
}
}
@@ -1230,3 +1288,62 @@ bool GLExtensions::getFragDataLocation( const char* fragDataName, GLuint& locati
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 ");
}
}
}

View File

@@ -14,6 +14,7 @@
#include <osg/Geometry>
#include <osg/ArrayDispatchers>
#include <osg/VertexArrayState>
#include <osg/Notify>
using namespace osg;
@@ -603,6 +604,8 @@ void Geometry::resizeGLObjectBuffers(unsigned int maxSize)
{
Drawable::resizeGLObjectBuffers(maxSize);
_vertexArrayStateList.resize(maxSize);
ArrayList arrays;
if (getArrayList(arrays))
{
@@ -630,6 +633,9 @@ void Geometry::releaseGLObjects(State* state) const
{
Drawable::releaseGLObjects(state);
if (state) _vertexArrayStateList[state->getContextID()];
else _vertexArrayStateList.clear();
ArrayList arrays;
if (getArrayList(arrays))
{
@@ -734,28 +740,41 @@ 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()");
drawVertexArraysImplementation(renderInfo);
if (checkForGLErrors) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup.");
bool useNewImplementation = (ds->getGeometryImplementation()!=DisplaySettings::OLD_GEOMETRY_IMPLEMENTATION);
if (useNewImplementation)
{
new_drawImplementation(renderInfo);
}
else
{
// OSG_NOTICE<<"Old implementation"<<std::endl;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// draw the primitives themselves.
//
drawPrimitivesImplementation(renderInfo);
old_drawVertexArraysImplementation(renderInfo);
// unbind the VBO's if any are used.
state.unbindVertexBufferObject();
state.unbindElementBufferObject();
if (checkForGLErrors) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup.");
if (checkForGLErrors) state.checkGLErrors("end of Geometry::drawImplementation().");
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// draw the primitives themselves.
//
old_drawPrimitivesImplementation(renderInfo);
// unbind the VBO's if any are used.
state.unbindVertexBufferObject();
state.unbindElementBufferObject();
if (checkForGLErrors) state.checkGLErrors("end of Geometry::drawImplementation().");
}
}
void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const
void Geometry::old_drawVertexArraysImplementation(RenderInfo& renderInfo) const
{
State& state = *renderInfo.getState();
@@ -834,7 +853,7 @@ void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const
state.applyDisablingOfVertexAttributes();
}
void Geometry::drawPrimitivesImplementation(RenderInfo& renderInfo) const
void Geometry::old_drawPrimitivesImplementation(RenderInfo& renderInfo) const
{
State& state = *renderInfo.getState();
ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
@@ -852,6 +871,112 @@ void Geometry::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 = _useVertexBufferObjects && state.isVertexBufferObjectSupported();
bool useVAO = usingVertexBufferObjects && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT);
bool dispatchIfDirty = useVAO;
VertexArrayState* vas = _vertexArrayStateList[contextID].get();
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)
{
OSG_NOTICE<<"Creating new osg::VertexArrayState"<<std::endl;
_vertexArrayStateList[contextID] = 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());
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 (useVAO)
{
OSG_NOTICE<<" Setup VertexArrayState to use VAO"<<std::endl;
vas->generateVretexArrayObject();
dispatchIfDirty = false;
}
else
{
OSG_NOTICE<<" Setup VertexArrayState to wihtout using VAO"<<std::endl;
}
}
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 (checkForGLErrors) state.checkGLErrors("Geometry::new_drawImplementation() after primitive dispatch.");
}
void Geometry::accept(AttributeFunctor& af)
{
AttributeFunctorArrayVisitor afav(af);

View File

@@ -172,6 +172,7 @@ unsigned int DrawArrayLengths::getNumIndices() const
return count;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// DrawElementsUByte
@@ -192,7 +193,10 @@ void DrawElementsUByte::draw(State& state, bool useVertexBufferObjects) const
if (useVertexBufferObjects)
{
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
state.bindElementBufferObject(ebo);
if (state.getCurrentVertexArrayState()) state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
else state.bindElementBufferObject(ebo);
if (ebo)
{
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_BYTE, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
@@ -252,7 +256,19 @@ void DrawElementsUShort::draw(State& state, bool useVertexBufferObjects) const
if (useVertexBufferObjects)
{
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
state.bindElementBufferObject(ebo);
if (state.getCurrentVertexArrayState())
{
OSG_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;
state.bindElementBufferObject(ebo);
}
if (ebo)
{
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_SHORT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
@@ -311,7 +327,10 @@ void DrawElementsUInt::draw(State& state, bool useVertexBufferObjects) const
if (useVertexBufferObjects)
{
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
state.bindElementBufferObject(ebo);
if (state.getCurrentVertexArrayState()) state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
else state.bindElementBufferObject(ebo);
if (ebo)
{
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_INT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);

View File

@@ -981,6 +981,8 @@ void State::initializeExtensionProcs()
_glExtensions = new GLExtensions(_contextID);
GLExtensions::Set(_contextID, _glExtensions.get());
// _currentVertexArrayState = new VertexArrayState(_glExtensions.get());
setGLExtensionFuncPtr(_glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB");
setGLExtensionFuncPtr(_glActiveTexture, "glActiveTexture","glActiveTextureARB");
setGLExtensionFuncPtr(_glFogCoordPointer, "glFogCoordPointer","glFogCoordPointerEXT");

1097
src/osg/VertexArrayState.cpp Normal file

File diff suppressed because it is too large Load Diff