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:
parent
4d8a29b987
commit
7d83d735ad
@ -66,14 +66,6 @@ class Geometry;
|
||||
class NodeVisitor;
|
||||
class ArrayDispatchers;
|
||||
|
||||
// this is defined to alter the way display lists are compiled inside the
|
||||
// the draw method, it has been found that the NVidia drivers fail completely
|
||||
// to optimize COMPILE_AND_EXECUTE in fact make it go slower than for no display
|
||||
// lists, but optimize a separate COMPILE very well?! Define it as default
|
||||
// the use of a separate COMPILE, then glCallList rather than use COMPILE_AND_EXECUTE.
|
||||
|
||||
#define USE_SEPARATE_COMPILE_AND_EXECUTE
|
||||
|
||||
/** Pure virtual base class for drawable geometry. In OSG, everything that can
|
||||
* be rendered is implemented as a class derived from \c Drawable. The
|
||||
* \c Drawable class contains no drawing primitives, since these are provided
|
||||
@ -235,9 +227,19 @@ class OSG_EXPORT Drawable : public Node
|
||||
inline bool getUseVertexBufferObjects() const { return _useVertexBufferObjects; }
|
||||
|
||||
|
||||
/** Force a recompile on next draw() of any OpenGL display list associated with this geoset.*/
|
||||
/** Set whether to use a local VertexArrayObject for this Drawable.*/
|
||||
void setUseVertexArrayObject(bool flag);
|
||||
|
||||
/** Return whether to use a local VertexArrayObject for this Drawable.*/
|
||||
bool getUseVertexArrayObject() const { return _useVertexArrayObject; }
|
||||
|
||||
|
||||
/** Deprecated, use dirtyGLObjects() instead. */
|
||||
virtual void dirtyDisplayList();
|
||||
|
||||
/** Force a recompile on next draw() of any OpenGL objects associated with this geoset.*/
|
||||
virtual void dirtyGLObjects();
|
||||
|
||||
|
||||
/** Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with this drawable.
|
||||
* This size is used a hint for reuse of deleted display lists/vertex buffer objects. */
|
||||
@ -254,13 +256,29 @@ class OSG_EXPORT Drawable : public Node
|
||||
* \c virtual). Subclasses should override
|
||||
* \c drawImplementation() instead.
|
||||
*/
|
||||
#if 0
|
||||
inline void draw(RenderInfo& renderInfo) const;
|
||||
#else
|
||||
void draw(RenderInfo& renderInfo) const;
|
||||
#endif
|
||||
|
||||
inline void drawInner(RenderInfo& renderInfo) const
|
||||
{
|
||||
if (_drawCallback.valid())
|
||||
_drawCallback->drawImplementation(renderInfo,this);
|
||||
else
|
||||
drawImplementation(renderInfo);
|
||||
}
|
||||
|
||||
|
||||
/** Immediately compile this \c Drawable into an OpenGL Display List/VertexBufferObjects.
|
||||
* @note Operation is ignored if \c _useDisplayList is \c false or VertexBufferObjects are not used.
|
||||
*/
|
||||
virtual void compileGLObjects(RenderInfo& renderInfo) const;
|
||||
|
||||
virtual VertexArrayState* setUpVertexArrayState(RenderInfo& renderInfo, bool usingVBOs) const;
|
||||
|
||||
|
||||
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
|
||||
virtual void setThreadSafeRefUnref(bool threadSafe);
|
||||
|
||||
@ -466,14 +484,18 @@ class OSG_EXPORT Drawable : public Node
|
||||
bool _useDisplayList;
|
||||
bool _supportsVertexBufferObjects;
|
||||
bool _useVertexBufferObjects;
|
||||
bool _useVertexArrayObject;
|
||||
|
||||
typedef osg::buffered_value<GLuint> GLObjectList;
|
||||
mutable GLObjectList _globjList;
|
||||
|
||||
typedef buffered_object< osg::ref_ptr<VertexArrayState> > VertexArrayStateList;
|
||||
mutable VertexArrayStateList _vertexArrayStateList;
|
||||
|
||||
ref_ptr<DrawCallback> _drawCallback;
|
||||
};
|
||||
|
||||
|
||||
#if 0
|
||||
inline void Drawable::draw(RenderInfo& renderInfo) const
|
||||
{
|
||||
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
|
||||
@ -486,36 +508,24 @@ inline void Drawable::draw(RenderInfo& renderInfo) const
|
||||
// get the globj for the current contextID.
|
||||
GLuint& globj = _globjList[contextID];
|
||||
|
||||
// call the globj if already set otherwise compile and execute.
|
||||
if( globj != 0 )
|
||||
if( globj == 0 )
|
||||
{
|
||||
glCallList( globj );
|
||||
}
|
||||
else if (_useDisplayList)
|
||||
{
|
||||
#ifdef USE_SEPARATE_COMPILE_AND_EXECUTE
|
||||
// compile the display list
|
||||
globj = generateDisplayList(contextID, getGLObjectSizeHint());
|
||||
glNewList( globj, GL_COMPILE );
|
||||
if (_drawCallback.valid())
|
||||
_drawCallback->drawImplementation(renderInfo,this);
|
||||
else
|
||||
drawImplementation(renderInfo);
|
||||
glEndList();
|
||||
|
||||
glCallList( globj);
|
||||
#else
|
||||
globj = generateDisplayList(contextID, getGLObjectSizeHint());
|
||||
glNewList( globj, GL_COMPILE_AND_EXECUTE );
|
||||
if (_drawCallback.valid())
|
||||
_drawCallback->drawImplementation(renderInfo,this);
|
||||
else
|
||||
drawImplementation(renderInfo);
|
||||
|
||||
glEndList();
|
||||
#endif
|
||||
}
|
||||
|
||||
return;
|
||||
// call the display list
|
||||
glCallList( globj);
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -525,6 +535,7 @@ inline void Drawable::draw(RenderInfo& renderInfo) const
|
||||
else
|
||||
drawImplementation(renderInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
class AttributeFunctorArrayVisitor : public ArrayVisitor
|
||||
{
|
||||
|
@ -140,8 +140,8 @@ class OSG_EXPORT Geometry : public Drawable
|
||||
method to use OpenGL vertex buffer objects for rendering.*/
|
||||
virtual void setUseVertexBufferObjects(bool flag);
|
||||
|
||||
/** Force a recompile on next draw() of any OpenGL display list associated with this geoset.*/
|
||||
virtual void dirtyDisplayList();
|
||||
/** Force a recompile on next draw() of any OpenGL objects associated with this geoset.*/
|
||||
virtual void dirtyGLObjects();
|
||||
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
@ -178,14 +178,10 @@ class OSG_EXPORT Geometry : public Drawable
|
||||
|
||||
|
||||
/** Set up the vertex arrays for the purpose of rendering, called by drawImplemtation() prior to it calling drawPrimitivesImplementation().*/
|
||||
void old_drawVertexArraysImplementation(RenderInfo& renderInfo) const;
|
||||
void drawVertexArraysImplementation(RenderInfo& renderInfo) const;
|
||||
|
||||
/** dispatch the primitives to OpenGL, called by drawImplemtation() after calling drawVertexArraysImplementation().*/
|
||||
void old_drawPrimitivesImplementation(RenderInfo& renderInfo) const;
|
||||
|
||||
|
||||
/** Set up the vertex arrays for the purpose of rendering, called by drawImplemtation() prior to it calling drawPrimitivesImplementation().*/
|
||||
void new_drawImplementation(RenderInfo& renderInfo) const;
|
||||
void drawPrimitivesImplementation(RenderInfo& renderInfo) const;
|
||||
|
||||
|
||||
/** Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&). */
|
||||
@ -223,10 +219,6 @@ class OSG_EXPORT Geometry : public Drawable
|
||||
void addVertexBufferObjectIfRequired(osg::Array* array);
|
||||
void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
|
||||
|
||||
typedef buffered_object< osg::ref_ptr<VertexArrayState> > VertexArrayStateList;
|
||||
mutable VertexArrayStateList _vertexArrayStateList;
|
||||
|
||||
|
||||
PrimitiveSetList _primitives;
|
||||
osg::ref_ptr<Array> _vertexArray;
|
||||
osg::ref_ptr<Array> _normalArray;
|
||||
|
@ -517,8 +517,17 @@ class OSG_EXPORT State : public Referenced
|
||||
|
||||
|
||||
|
||||
|
||||
#if 1
|
||||
void setCurrentVertexBufferObject(osg::GLBufferObject* vbo);
|
||||
const GLBufferObject* getCurrentVertexBufferObject();
|
||||
|
||||
void bindVertexBufferObject(osg::GLBufferObject* vbo);
|
||||
void unbindVertexBufferObject();
|
||||
#else
|
||||
void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; }
|
||||
const GLBufferObject* getCurrentVertexBufferObject() { return _currentVBO; }
|
||||
|
||||
inline void bindVertexBufferObject(osg::GLBufferObject* vbo)
|
||||
{
|
||||
if (vbo)
|
||||
@ -537,7 +546,15 @@ class OSG_EXPORT State : public Referenced
|
||||
_glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
|
||||
_currentVBO = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void setCurrentElementBufferObject(osg::GLBufferObject* ebo);
|
||||
const GLBufferObject* getCurrentElementBufferObject();
|
||||
|
||||
void bindElementBufferObject(osg::GLBufferObject* ebo);
|
||||
void unbindElementBufferObject();
|
||||
#else
|
||||
void setCurrentElementBufferObject(osg::GLBufferObject* ebo) { _currentEBO = ebo; }
|
||||
const GLBufferObject* getCurrentElementBufferObject() { return _currentEBO; }
|
||||
|
||||
@ -559,6 +576,7 @@ class OSG_EXPORT State : public Referenced
|
||||
_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
|
||||
_currentEBO = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void setCurrentPixelBufferObject(osg::GLBufferObject* pbo) { _currentPBO = pbo; }
|
||||
const GLBufferObject* getCurrentPixelBufferObject() { return _currentPBO; }
|
||||
@ -681,6 +699,9 @@ class OSG_EXPORT State : public Referenced
|
||||
void setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer);
|
||||
|
||||
/** Set the vertex pointer using an osg::Array, and manage any VBO that are required.*/
|
||||
#if 1
|
||||
void setVertexPointer(const Array* array);
|
||||
#else
|
||||
inline void setVertexPointer(const Array* array)
|
||||
{
|
||||
if (array)
|
||||
@ -698,7 +719,7 @@ class OSG_EXPORT State : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
/** wrapper around glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer(..);
|
||||
* note, only updates values that change.*/
|
||||
inline void setVertexPointer( GLint size, GLenum type,
|
||||
@ -730,6 +751,9 @@ class OSG_EXPORT State : public Referenced
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 1
|
||||
void disableVertexPointer();
|
||||
#else
|
||||
/** wrapper around glDisableClientState(GL_VERTEX_ARRAY).
|
||||
* note, only updates values that change.*/
|
||||
inline void disableVertexPointer()
|
||||
@ -753,7 +777,11 @@ class OSG_EXPORT State : public Referenced
|
||||
disableVertexAttribPointer(_vertexAlias._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void dirtyVertexPointer();
|
||||
#else
|
||||
inline void dirtyVertexPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
@ -770,8 +798,12 @@ class OSG_EXPORT State : public Referenced
|
||||
dirtyVertexAttribPointer(_vertexAlias._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
void setNormalPointer(const Array* array);
|
||||
#else
|
||||
/** Set the normal pointer using an osg::Array, and manage any VBO that are required.*/
|
||||
inline void setNormalPointer(const Array* array)
|
||||
{
|
||||
@ -790,7 +822,7 @@ class OSG_EXPORT State : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
/** wrapper around glEnableClientState(GL_NORMAL_ARRAY);glNormalPointer(..);
|
||||
* note, only updates values that change.*/
|
||||
inline void setNormalPointer( GLenum type, GLsizei stride,
|
||||
@ -822,6 +854,9 @@ class OSG_EXPORT State : public Referenced
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 1
|
||||
void disableNormalPointer();
|
||||
#else
|
||||
/** wrapper around glDisableClientState(GL_NORMAL_ARRAY);
|
||||
* note, only updates values that change.*/
|
||||
inline void disableNormalPointer()
|
||||
@ -845,7 +880,11 @@ class OSG_EXPORT State : public Referenced
|
||||
disableVertexAttribPointer(_normalAlias._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void dirtyNormalPointer();
|
||||
#else
|
||||
inline void dirtyNormalPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
@ -862,7 +901,11 @@ class OSG_EXPORT State : public Referenced
|
||||
dirtyVertexAttribPointer(_normalAlias._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void setColorPointer(const Array* array);
|
||||
#else
|
||||
/** Set the color pointer using an osg::Array, and manage any VBO that are required.*/
|
||||
inline void setColorPointer(const Array* array)
|
||||
{
|
||||
@ -881,7 +924,7 @@ class OSG_EXPORT State : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** wrapper around glEnableClientState(GL_COLOR_ARRAY);glColorPointer(..);
|
||||
* note, only updates values that change.*/
|
||||
@ -914,6 +957,9 @@ class OSG_EXPORT State : public Referenced
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 1
|
||||
void disableColorPointer();
|
||||
#else
|
||||
/** wrapper around glDisableClientState(GL_COLOR_ARRAY);
|
||||
* note, only updates values that change.*/
|
||||
inline void disableColorPointer()
|
||||
@ -937,7 +983,11 @@ class OSG_EXPORT State : public Referenced
|
||||
disableVertexAttribPointer(_colorAlias._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void dirtyColorPointer();
|
||||
#else
|
||||
inline void dirtyColorPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
@ -954,11 +1004,14 @@ class OSG_EXPORT State : public Referenced
|
||||
dirtyVertexAttribPointer(_colorAlias._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline bool isSecondaryColorSupported() const { return _isSecondaryColorSupportResolved?_isSecondaryColorSupported:computeSecondaryColorSupported(); }
|
||||
|
||||
|
||||
#if 1
|
||||
void setSecondaryColorPointer(const Array* array);
|
||||
#else
|
||||
/** Set the secondary color pointer using an osg::Array, and manage any VBO that are required.*/
|
||||
inline void setSecondaryColorPointer(const Array* array)
|
||||
{
|
||||
@ -977,11 +1030,15 @@ class OSG_EXPORT State : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/** wrapper around glEnableClientState(GL_SECONDARY_COLOR_ARRAY);glSecondayColorPointer(..);
|
||||
* note, only updates values that change.*/
|
||||
void setSecondaryColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_TRUE );
|
||||
|
||||
#if 1
|
||||
void disableSecondaryColorPointer();
|
||||
#else
|
||||
/** wrapper around glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
|
||||
* note, only updates values that change.*/
|
||||
inline void disableSecondaryColorPointer()
|
||||
@ -1005,7 +1062,11 @@ class OSG_EXPORT State : public Referenced
|
||||
disableVertexAttribPointer(_secondaryColorAlias._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
inline void dirtySecondaryColorPointer();
|
||||
#else
|
||||
inline void dirtySecondaryColorPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
@ -1022,10 +1083,14 @@ class OSG_EXPORT State : public Referenced
|
||||
dirtyVertexAttribPointer(_secondaryColorAlias._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
inline bool isFogCoordSupported() const { return _isFogCoordSupportResolved?_isFogCoordSupported:computeFogCoordSupported(); }
|
||||
|
||||
|
||||
#if 1
|
||||
void setFogCoordPointer(const Array* array);
|
||||
#else
|
||||
/** Set the fog coord pointer using an osg::Array, and manage any VBO that are required.*/
|
||||
inline void setFogCoordPointer(const Array* array)
|
||||
{
|
||||
@ -1044,12 +1109,15 @@ class OSG_EXPORT State : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** wrapper around glEnableClientState(GL_FOG_COORDINATE_ARRAY);glFogCoordPointer(..);
|
||||
* note, only updates values that change.*/
|
||||
void setFogCoordPointer( GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE );
|
||||
|
||||
#if 1
|
||||
void disableFogCoordPointer();
|
||||
#else
|
||||
/** wrapper around glDisableClientState(GL_FOG_COORDINATE_ARRAY);
|
||||
* note, only updates values that change.*/
|
||||
inline void disableFogCoordPointer()
|
||||
@ -1073,7 +1141,11 @@ class OSG_EXPORT State : public Referenced
|
||||
disableVertexAttribPointer(_fogCoordAlias._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void dirtyFogCoordPointer();
|
||||
#else
|
||||
inline void dirtyFogCoordPointer()
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
@ -1090,9 +1162,12 @@ class OSG_EXPORT State : public Referenced
|
||||
dirtyVertexAttribPointer(_fogCoordAlias._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if 1
|
||||
void setTexCoordPointer(unsigned int unit, const Array* array);
|
||||
#else
|
||||
/** Set the tex coord pointer using an osg::Array, and manage any VBO that are required.*/
|
||||
inline void setTexCoordPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
@ -1111,7 +1186,7 @@ class OSG_EXPORT State : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
/** wrapper around glEnableClientState(GL_TEXTURE_COORD_ARRAY);glTexCoordPointer(..);
|
||||
* note, only updates values that change.*/
|
||||
inline void setTexCoordPointer( unsigned int unit,
|
||||
@ -1150,6 +1225,9 @@ class OSG_EXPORT State : public Referenced
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 1
|
||||
void disableTexCoordPointer( unsigned int unit );
|
||||
#else
|
||||
/** wrapper around glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
* note, only updates values that change.*/
|
||||
inline void disableTexCoordPointer( unsigned int unit )
|
||||
@ -1179,7 +1257,11 @@ class OSG_EXPORT State : public Referenced
|
||||
disableVertexAttribPointer(_texCoordAliasList[unit]._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void dirtyTexCoordPointer( unsigned int unit );
|
||||
#else
|
||||
inline void dirtyTexCoordPointer( unsigned int unit )
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
@ -1198,8 +1280,11 @@ class OSG_EXPORT State : public Referenced
|
||||
dirtyVertexAttribPointer(_texCoordAliasList[unit]._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
void disableTexCoordPointersAboveAndIncluding( unsigned int unit );
|
||||
#else
|
||||
inline void disableTexCoordPointersAboveAndIncluding( unsigned int unit )
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
@ -1229,7 +1314,11 @@ class OSG_EXPORT State : public Referenced
|
||||
disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void dirtyTexCoordPointersAboveAndIncluding( unsigned int unit );
|
||||
#else
|
||||
inline void dirtyTexCoordPointersAboveAndIncluding( unsigned int unit )
|
||||
{
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
@ -1251,7 +1340,7 @@ class OSG_EXPORT State : public Referenced
|
||||
dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// For GL>=2.0 uses GL_MAX_TEXTURE_COORDS, for GL<2 uses GL_MAX_TEXTURE_UNITS
|
||||
inline GLint getMaxTextureCoords() const { return _glMaxTextureCoords; }
|
||||
@ -1274,8 +1363,11 @@ class OSG_EXPORT State : public Referenced
|
||||
bool setClientActiveTextureUnit( unsigned int unit );
|
||||
|
||||
/** Get the current tex coord array texture unit.*/
|
||||
unsigned int getClientActiveTextureUnit() const { return _currentClientActiveTextureUnit; }
|
||||
unsigned int getClientActiveTextureUnit() const;
|
||||
|
||||
#if 1
|
||||
void setVertexAttribPointer(unsigned int unit, const Array* array);
|
||||
#else
|
||||
/** Set the vertex attrib pointer using an osg::Array, and manage any VBO that are required.*/
|
||||
inline void setVertexAttribPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
@ -1294,7 +1386,11 @@ class OSG_EXPORT State : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void setVertexAttribLPointer(unsigned int unit, const Array* array);
|
||||
#else
|
||||
/** Set the vertex attrib pointer using an osg::Array, and manage any VBO that are required.*/
|
||||
inline void setVertexAttribLPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
@ -1313,7 +1409,11 @@ class OSG_EXPORT State : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void setVertexAttribIPointer(unsigned int unit, const Array* array);
|
||||
#else
|
||||
/** Set the vertex attrib pointer using an osg::Array, and manage any VBO that are required.*/
|
||||
inline void setVertexAttribIPointer(unsigned int unit, const Array* array)
|
||||
{
|
||||
@ -1332,6 +1432,7 @@ class OSG_EXPORT State : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribPointerARB(..);
|
||||
* note, only updates values that change.*/
|
||||
@ -1357,6 +1458,9 @@ class OSG_EXPORT State : public Referenced
|
||||
|
||||
void disableVertexAttribPointersAboveAndIncluding( unsigned int index );
|
||||
|
||||
#if 1
|
||||
void dirtyVertexAttribPointer( unsigned int index );
|
||||
#else
|
||||
inline void dirtyVertexAttribPointer( unsigned int index )
|
||||
{
|
||||
if (index<_vertexAttribArrayList.size())
|
||||
@ -1366,7 +1470,11 @@ class OSG_EXPORT State : public Referenced
|
||||
eap._dirty = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
void dirtyVertexAttribPointersAboveAndIncluding( unsigned int index );
|
||||
#else
|
||||
inline void dirtyVertexAttribPointersAboveAndIncluding( unsigned int index )
|
||||
{
|
||||
while (index<_vertexAttribArrayList.size())
|
||||
@ -1377,6 +1485,7 @@ class OSG_EXPORT State : public Referenced
|
||||
++index;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool isVertexBufferObjectSupported() const { return _isVertexBufferObjectSupportResolved?_isVertexBufferObjectSupported:computeVertexBufferObjectSupported(); }
|
||||
|
||||
|
@ -21,8 +21,6 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
|
||||
class VertexArrayState : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
@ -31,113 +29,109 @@ public:
|
||||
|
||||
struct ArrayDispatch : public osg::Referenced
|
||||
{
|
||||
ArrayDispatch(Array* in_array):
|
||||
array(in_array),
|
||||
modifiedCount(0xffffffff) {}
|
||||
ArrayDispatch():
|
||||
array(0),
|
||||
modifiedCount(0xffffffff),
|
||||
active(false) {}
|
||||
|
||||
inline void dispatchIfDirty(osg::State& state, unsigned int index=0)
|
||||
{
|
||||
if (modifiedCount!=array->getModifiedCount()) dispatch(state, index);
|
||||
}
|
||||
virtual void enable_and_dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/) {} // = 0;
|
||||
|
||||
virtual void dispatch(osg::State& state, unsigned int index=0) = 0;
|
||||
virtual void enable_and_dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/, const osg::GLBufferObject* /*vbo*/) {} // = 0;
|
||||
|
||||
virtual void dispatchDeprecated(osg::State& state, unsigned int index=0);
|
||||
virtual void dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/) {} // = 0;
|
||||
|
||||
osg::Array* array;
|
||||
unsigned int modifiedCount;
|
||||
virtual void dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/, const osg::GLBufferObject* /*vbo*/) {} // = 0;
|
||||
|
||||
virtual void disable(osg::State& /*state*/) {} // = 0;
|
||||
|
||||
const osg::Array* array;
|
||||
unsigned int modifiedCount;
|
||||
bool active;
|
||||
};
|
||||
|
||||
typedef std::vector< ref_ptr<ArrayDispatch> > ArrayDispatchList;
|
||||
|
||||
ArrayDispatchList& getArrayDispatchList(Array::Binding binding)
|
||||
void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; }
|
||||
GLBufferObject* getCurrentVertexBufferObject() { return _currentVBO; }
|
||||
|
||||
inline void bindVertexBufferObject(osg::GLBufferObject* vbo)
|
||||
{
|
||||
switch(binding)
|
||||
{
|
||||
case(osg::Array::BIND_PER_VERTEX): return _dispatchArrays;
|
||||
case(osg::Array::BIND_PER_PRIMITIVE_SET): return _dispatchPerPrimitiveSet;
|
||||
default: return _dispatchOverall;
|
||||
}
|
||||
if (vbo == _currentVBO) return;
|
||||
if (vbo->isDirty()) vbo->compileBuffer();
|
||||
else vbo->bindBuffer();
|
||||
_currentVBO = vbo;
|
||||
}
|
||||
|
||||
inline void unbindVertexBufferObject()
|
||||
{
|
||||
if (!_currentVBO) return;
|
||||
_ext->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
|
||||
_currentVBO = 0;
|
||||
}
|
||||
|
||||
|
||||
enum VertexArrayIdentifier
|
||||
void setCurrentElementBufferObject(osg::GLBufferObject* ebo) { _currentEBO = ebo; }
|
||||
GLBufferObject* getCurrentElementBufferObject() { return _currentEBO; }
|
||||
|
||||
inline void bindElementBufferObject(osg::GLBufferObject* ebo)
|
||||
{
|
||||
VERTEX_ARRAY,
|
||||
NORMAL_ARRAY,
|
||||
COLOR_ARRAY,
|
||||
SECONDARY_COLOR_ARRAY,
|
||||
FOG_COORD_ARRAY,
|
||||
TEX_COORD_ARRAY,
|
||||
VERTEX_ATTRIB_ARRAY=TEX_COORD_ARRAY+32
|
||||
};
|
||||
|
||||
|
||||
void assignVertexArray(osg::Array* array);
|
||||
void assignColorArray(osg::Array* array);
|
||||
void assignNormalArray(osg::Array* array);
|
||||
|
||||
void assignSecondaryColorArray(osg::Array* array);
|
||||
void assignFogCoordArray(osg::Array* array);
|
||||
|
||||
void assignTexCoordArray(unsigned int unit, osg::Array* array);
|
||||
void assignVertexAttribArray(unsigned int unit, osg::Array* array);
|
||||
|
||||
inline void dispatchOverall(osg::State& state)
|
||||
{
|
||||
for(ArrayDispatchList::iterator itr = _dispatchOverall.begin();
|
||||
itr != _dispatchOverall.end();
|
||||
++itr)
|
||||
{
|
||||
(*(*itr)).dispatch(state);
|
||||
}
|
||||
if (ebo == _currentEBO) return;
|
||||
if (ebo->isDirty()) ebo->compileBuffer();
|
||||
else ebo->bindBuffer();
|
||||
_currentEBO = ebo;
|
||||
}
|
||||
|
||||
void dispatchPerPrimitveSet(osg::State& state, unsigned int index)
|
||||
inline void unbindElementBufferObject()
|
||||
{
|
||||
for(ArrayDispatchList::iterator itr = _dispatchPerPrimitiveSet.begin();
|
||||
itr != _dispatchPerPrimitiveSet.end();
|
||||
++itr)
|
||||
{
|
||||
(*(*itr)).dispatch(state, index);
|
||||
}
|
||||
if (!_currentEBO) return;
|
||||
_ext->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
|
||||
_currentEBO = 0;
|
||||
}
|
||||
|
||||
inline void dispatchArrays(osg::State& state)
|
||||
{
|
||||
// need to check previous enabled/disabled mode
|
||||
void assignAllDispatchers();
|
||||
|
||||
if (_vertexArrayObject)
|
||||
{
|
||||
for(ArrayDispatchList::iterator itr = _dispatchArrays.begin();
|
||||
itr != _dispatchArrays.end();
|
||||
++itr)
|
||||
{
|
||||
(*(*itr)).dispatch(state);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(ArrayDispatchList::iterator itr = _dispatchArrays.begin();
|
||||
itr != _dispatchArrays.end();
|
||||
++itr)
|
||||
{
|
||||
(*(*itr)).dispatchDeprecated(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void assignVertexArrayDispatcher();
|
||||
virtual void assignNormalArrayDispatcher();
|
||||
virtual void assignColorArrayDispatcher();
|
||||
virtual void assignSecondaryColorArrayDispatcher();
|
||||
virtual void assignFogCoordArrayDispatcher();
|
||||
virtual void assignTexCoordArrayDispatcher(unsigned int numUnits);
|
||||
virtual void assignVertexAttribArrayDispatcher(unsigned int numUnits);
|
||||
|
||||
inline void dispatchArraysIfDirty(osg::State& state)
|
||||
{
|
||||
// need to check previous enabled/disabled mode
|
||||
inline bool isVertexBufferObjectSupported() const { return true; }
|
||||
|
||||
void setArray(ArrayDispatch* vad, osg::State& state, const osg::Array* new_array);
|
||||
void disable(ArrayDispatch* vad, osg::State& state) { vad->disable(state); vad->array=0; vad->modifiedCount=0xffffffff; vad->active=false; }
|
||||
|
||||
inline void setVertexArray(osg::State& state, const osg::Array* array) { setArray(_vertexArray.get(), state, array); }
|
||||
inline void disableVertexArray(osg::State& state) { disable(_vertexArray.get(), state); }
|
||||
|
||||
inline void setNormalArray(osg::State& state, const osg::Array* array) { setArray(_normalArray.get(), state, array); }
|
||||
inline void disableNormalArray(osg::State& state) { disable(_normalArray.get(), state); }
|
||||
|
||||
inline void setColorArray(osg::State& state, const osg::Array* array) { setArray(_colorArray.get(), state, array); }
|
||||
inline void disableColorArray(osg::State& state) { disable(_colorArray.get(), state); }
|
||||
|
||||
inline void setSecondaryColorArray(osg::State& state, const osg::Array* array) { setArray(_secondaryColorArray.get(), state, array); }
|
||||
inline void disableSecondaryColorArray(osg::State& state) { disable(_secondaryColorArray.get(), state); }
|
||||
|
||||
inline void setFogCoordArray(osg::State& state, const osg::Array* array) { setArray(_fogCoordArray.get(), state, array); }
|
||||
inline void disableFogCoordArray(osg::State& state) { disable(_fogCoordArray.get(), state); }
|
||||
|
||||
inline void setTexCoordArray(osg::State& state, unsigned int unit, const osg::Array* array) { setArray(_texCoordArrays[unit].get(), state, array); }
|
||||
inline void disableTexCoordArray(osg::State& state, unsigned int unit) { disable(_texCoordArrays[unit].get(),state); }
|
||||
void disableTexCoordArrayAboveAndIncluding(osg::State& state, unsigned int index);
|
||||
|
||||
inline void setVertexAttribArray(osg::State& state, unsigned int unit, const osg::Array* array) { setArray(_vertexAttribArrays[unit].get(), state, array); }
|
||||
inline void disableVertexAttribArray(osg::State& state, unsigned int unit) { disable(_vertexAttribArrays[unit].get(), state); }
|
||||
void disableVertexAttribArrayAboveAndIncluding(osg::State& state, unsigned int index);
|
||||
|
||||
/** Mark all the vertex attributes as being disabled but leave the disabling till a later call to applyDisablingOfVertexAttributes.*/
|
||||
void lazyDisablingOfVertexAttributes();
|
||||
|
||||
/** Disable all the vertex attributes that have been marked as to be disabled.*/
|
||||
void applyDisablingOfVertexAttributes(osg::State& state);
|
||||
|
||||
for(ArrayDispatchList::iterator itr = _dispatchArrays.begin();
|
||||
itr != _dispatchArrays.end();
|
||||
++itr)
|
||||
{
|
||||
(*(*itr)).dispatchIfDirty(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -154,49 +148,6 @@ public:
|
||||
|
||||
|
||||
|
||||
void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; }
|
||||
GLBufferObject* getCurrentVertexBufferObject() { return _currentVBO; }
|
||||
inline void bindVertexBufferObject(osg::GLBufferObject* vbo)
|
||||
{
|
||||
if (vbo)
|
||||
{
|
||||
if (vbo == _currentVBO) return;
|
||||
if (vbo->isDirty()) vbo->compileBuffer();
|
||||
else vbo->bindBuffer();
|
||||
_currentVBO = vbo;
|
||||
}
|
||||
else unbindVertexBufferObject();
|
||||
}
|
||||
|
||||
inline void unbindVertexBufferObject()
|
||||
{
|
||||
if (!_currentVBO) return;
|
||||
_ext->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
|
||||
_currentVBO = 0;
|
||||
}
|
||||
|
||||
|
||||
void setCurrentElementBufferObject(osg::GLBufferObject* ebo) { _currentEBO = ebo; }
|
||||
GLBufferObject* getCurrentElementBufferObject() { return _currentEBO; }
|
||||
|
||||
inline void bindElementBufferObject(osg::GLBufferObject* ebo)
|
||||
{
|
||||
if (ebo)
|
||||
{
|
||||
//if (ebo == _currentEBO) return;
|
||||
if (ebo->isDirty()) ebo->compileBuffer();
|
||||
else ebo->bindBuffer();
|
||||
_currentEBO = ebo;
|
||||
}
|
||||
else unbindElementBufferObject();
|
||||
}
|
||||
|
||||
inline void unbindElementBufferObject()
|
||||
{
|
||||
//if (!_currentEBO) return;
|
||||
_ext->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
|
||||
_currentEBO = 0;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
@ -208,12 +159,21 @@ public:
|
||||
|
||||
GLuint _vertexArrayObject;
|
||||
|
||||
|
||||
osg::ref_ptr<ArrayDispatch> _vertexArray;
|
||||
osg::ref_ptr<ArrayDispatch> _normalArray;
|
||||
osg::ref_ptr<ArrayDispatch> _colorArray;
|
||||
osg::ref_ptr<ArrayDispatch> _secondaryColorArray;
|
||||
osg::ref_ptr<ArrayDispatch> _fogCoordArray;
|
||||
ArrayDispatchList _texCoordArrays;
|
||||
ArrayDispatchList _vertexAttribArrays;
|
||||
|
||||
typedef std::vector<ArrayDispatch*> ActiveDispatchers;
|
||||
ActiveDispatchers _activeDispatchers;
|
||||
ActiveDispatchers _previous_activeDispatchers;
|
||||
|
||||
GLBufferObject* _currentVBO;
|
||||
GLBufferObject* _currentEBO;
|
||||
|
||||
ArrayDispatchList _dispatchOverall;
|
||||
ArrayDispatchList _dispatchPerPrimitiveSet;
|
||||
ArrayDispatchList _dispatchArrays;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user