Updates to the handling of vertex attributes.

This commit is contained in:
Robert Osfield
2003-05-09 13:07:06 +00:00
parent b7fcc68e6f
commit 57af40ee95
7 changed files with 369 additions and 163 deletions

View File

@@ -250,12 +250,19 @@ class SG_EXPORT Drawable : public Object
static void flushDeletedDisplayLists(unsigned int contextID);
enum AttributeType
typedef unsigned int AttributeType;
enum AttributeTypes
{
VERTICES,
NORMALS,
COLORS,
TEXTURE_COORDS,
VERTICES = 0,
WEIGHTS = 1,
NORMALS = 2,
COLORS = 3,
SECONDARY_COLORS = 4,
FOG_COORDS = 5,
ATTIBUTE_6 = 6,
ATTIBUTE_7 = 7,
TEXTURE_COORDS = 8,
TEXTURE_COORDS_0 = TEXTURE_COORDS,
TEXTURE_COORDS_1 = TEXTURE_COORDS_0+1,
TEXTURE_COORDS_2 = TEXTURE_COORDS_0+2,

View File

@@ -127,6 +127,49 @@ class SG_EXPORT Geometry : public Drawable
const TexCoordArrayList& getTexCoordArrayList() const { return _texCoordList; }
#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS
void setArray(AttributeType type, Array* array);
Array* getArray(AttributeType type);
const Array* getArray(AttributeType type) const;
void setIndices(AttributeType type, IndexArray* indices);
IndexArray* getIndices(AttributeType type);
const IndexArray* getIndices(AttributeType type) const;
void setNormalize(AttributeType type, GLboolean normalize);
GLboolean getNormalize(AttributeType type) const;
void setBinding(AttributeType type,AttributeBinding binding);
AttributeBinding getBinding(AttributeType type) const;
struct AttributeData
{
AttributeData():
_normalize(GL_FALSE),
_binding(BIND_OFF) {}
ref_ptr<Array> _array;
ref_ptr<IndexArray> _indices;
GLboolean _normalize;
AttributeBinding _binding;
};
unsigned int getNumArrays() const { return _attributeList.size(); }
AttributeData& getAttributeData(unsigned int type) { return _attributeList[type]; }
const AttributeData& getAttributeData(unsigned int type) const { return _attributeList[type]; }
typedef std::vector<AttributeData> AttributeList;
void setAttributeList(AttributeList& al) { _attributeList = al; }
AttributeList& getAttributeList() { return _attributeList; }
const AttributeList& getAttributeList() const { return _attributeList; }
#endif
typedef std::pair< ref_ptr<Array>, ref_ptr<IndexArray> > VertexAttribArrayPair;
typedef std::pair< GLboolean, VertexAttribArrayPair > VertexAttribNormArrayPair;
@@ -320,6 +363,9 @@ class SG_EXPORT Geometry : public Drawable
PrimitiveSetList _primitives;
#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS
AttributeList _attributeList;
#endif
ref_ptr<Vec3Array> _vertexArray;
ref_ptr<IndexArray> _vertexIndices;

View File

@@ -17,7 +17,6 @@
#include <osg/Export>
#include <osg/StateSet>
#include <osg/Matrix>
#include <osg/GLExtensions>
#include <osg/FrameStamp>
#include <osg/DisplaySettings>
@@ -537,85 +536,18 @@ class SG_EXPORT State : public Referenced
* note, only updates values that change.*/
bool setActiveTextureUnit( unsigned int unit );
typedef void (APIENTRY * VertexAttribPointerProc) (unsigned int, GLint, GLenum, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
typedef void (APIENTRY * EnableVertexAttribProc) (unsigned int);
typedef void (APIENTRY * DisableVertexAttribProc) (unsigned int);
/** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribPointerARB(..);
* note, only updates values that change.*/
inline void setVertexAttribPointer( unsigned int index,
GLint size, GLenum type, GLboolean normalized,
GLsizei stride, const GLvoid *ptr )
{
static VertexAttribPointerProc s_glVertexAttribPointer =
(VertexAttribPointerProc) osg::getGLExtensionFuncPtr("glVertexAttribPointer","glVertexAttribPointerARB");
static EnableVertexAttribProc s_glEnableVertexAttribArray =
(EnableVertexAttribProc) osg::getGLExtensionFuncPtr("glEnableVertexAttribArray","glEnableVertexAttribArrayARB");
if( s_glVertexAttribPointer )
{
if ( index >= _vertexAttribArrayList.size()) _vertexAttribArrayList.resize(index+1);
EnabledArrayPair& eap = _vertexAttribArrayList[index];
if (!eap._enabled || eap._dirty)
{
eap._enabled = true;
s_glEnableVertexAttribArray( index );
}
if (eap._pointer != ptr || eap._normalized!=normalized || eap._dirty)
{
s_glVertexAttribPointer( index, size, type, normalized, stride, ptr );
eap._pointer = ptr;
eap._normalized = normalized;
}
eap._dirty = false;
}
}
void setVertexAttribPointer( unsigned int index,
GLint size, GLenum type, GLboolean normalized,
GLsizei stride, const GLvoid *ptr );
/** wrapper around DisableVertexAttribArrayARB(index);
* note, only updates values that change.*/
inline void disableVertexAttribPointer( unsigned int index )
{
static DisableVertexAttribProc s_glDisableVertexAttribArray =
(DisableVertexAttribProc) osg::getGLExtensionFuncPtr("glDisableVertexAttribArray","glDisableVertexAttribArrayARB");
if (s_glDisableVertexAttribArray)
{
if ( index >= _vertexAttribArrayList.size()) _vertexAttribArrayList.resize(index+1);
EnabledArrayPair& eap = _vertexAttribArrayList[index];
if (eap._enabled || eap._dirty)
{
eap._enabled = false;
eap._dirty = false;
s_glDisableVertexAttribArray( index );
}
}
}
inline void disableVertexAttribPointersAboveAndIncluding( unsigned int index )
{
static DisableVertexAttribProc s_glDisableVertexAttribArray =
(DisableVertexAttribProc) osg::getGLExtensionFuncPtr("glDisableVertexAttribArray","glDisableVertexAttribArrayARB");
if (s_glDisableVertexAttribArray)
{
while (index<_vertexAttribArrayList.size())
{
EnabledArrayPair& eap = _vertexAttribArrayList[index];
if (eap._enabled || eap._dirty)
{
eap._enabled = false;
eap._dirty = false;
s_glDisableVertexAttribArray( index );
}
++index;
}
}
}
void disableVertexAttribPointer( unsigned int index );
void disableVertexAttribPointersAboveAndIncluding( unsigned int index );
inline void dirtyVertexAttribPointersAboveAndIncluding( unsigned int index )
{
while (index<_vertexAttribArrayList.size())