Updates to the handling of vertex attributes.
This commit is contained in:
parent
b7fcc68e6f
commit
57af40ee95
@ -170,6 +170,9 @@ int main( int argc, char **argv )
|
|||||||
// objects for managing the broadcasting and recieving of camera packets.
|
// objects for managing the broadcasting and recieving of camera packets.
|
||||||
Broadcaster bc;
|
Broadcaster bc;
|
||||||
Receiver rc;
|
Receiver rc;
|
||||||
|
|
||||||
|
bc.setPort(socketNumber);
|
||||||
|
rc.setPort(socketNumber);
|
||||||
|
|
||||||
while( !viewer.done() )
|
while( !viewer.done() )
|
||||||
{
|
{
|
||||||
|
@ -250,12 +250,19 @@ class SG_EXPORT Drawable : public Object
|
|||||||
static void flushDeletedDisplayLists(unsigned int contextID);
|
static void flushDeletedDisplayLists(unsigned int contextID);
|
||||||
|
|
||||||
|
|
||||||
enum AttributeType
|
typedef unsigned int AttributeType;
|
||||||
|
|
||||||
|
enum AttributeTypes
|
||||||
{
|
{
|
||||||
VERTICES,
|
VERTICES = 0,
|
||||||
NORMALS,
|
WEIGHTS = 1,
|
||||||
COLORS,
|
NORMALS = 2,
|
||||||
TEXTURE_COORDS,
|
COLORS = 3,
|
||||||
|
SECONDARY_COLORS = 4,
|
||||||
|
FOG_COORDS = 5,
|
||||||
|
ATTIBUTE_6 = 6,
|
||||||
|
ATTIBUTE_7 = 7,
|
||||||
|
TEXTURE_COORDS = 8,
|
||||||
TEXTURE_COORDS_0 = TEXTURE_COORDS,
|
TEXTURE_COORDS_0 = TEXTURE_COORDS,
|
||||||
TEXTURE_COORDS_1 = TEXTURE_COORDS_0+1,
|
TEXTURE_COORDS_1 = TEXTURE_COORDS_0+1,
|
||||||
TEXTURE_COORDS_2 = TEXTURE_COORDS_0+2,
|
TEXTURE_COORDS_2 = TEXTURE_COORDS_0+2,
|
||||||
|
@ -127,6 +127,49 @@ class SG_EXPORT Geometry : public Drawable
|
|||||||
const TexCoordArrayList& getTexCoordArrayList() const { return _texCoordList; }
|
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< ref_ptr<Array>, ref_ptr<IndexArray> > VertexAttribArrayPair;
|
||||||
typedef std::pair< GLboolean, VertexAttribArrayPair > VertexAttribNormArrayPair;
|
typedef std::pair< GLboolean, VertexAttribArrayPair > VertexAttribNormArrayPair;
|
||||||
@ -320,6 +363,9 @@ class SG_EXPORT Geometry : public Drawable
|
|||||||
|
|
||||||
PrimitiveSetList _primitives;
|
PrimitiveSetList _primitives;
|
||||||
|
|
||||||
|
#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS
|
||||||
|
AttributeList _attributeList;
|
||||||
|
#endif
|
||||||
ref_ptr<Vec3Array> _vertexArray;
|
ref_ptr<Vec3Array> _vertexArray;
|
||||||
ref_ptr<IndexArray> _vertexIndices;
|
ref_ptr<IndexArray> _vertexIndices;
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
#include <osg/Export>
|
#include <osg/Export>
|
||||||
#include <osg/StateSet>
|
#include <osg/StateSet>
|
||||||
#include <osg/Matrix>
|
#include <osg/Matrix>
|
||||||
#include <osg/GLExtensions>
|
|
||||||
|
|
||||||
#include <osg/FrameStamp>
|
#include <osg/FrameStamp>
|
||||||
#include <osg/DisplaySettings>
|
#include <osg/DisplaySettings>
|
||||||
@ -537,85 +536,18 @@ class SG_EXPORT State : public Referenced
|
|||||||
* note, only updates values that change.*/
|
* note, only updates values that change.*/
|
||||||
bool setActiveTextureUnit( unsigned int unit );
|
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(..);
|
/** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribPointerARB(..);
|
||||||
* note, only updates values that change.*/
|
* note, only updates values that change.*/
|
||||||
inline void setVertexAttribPointer( unsigned int index,
|
void setVertexAttribPointer( unsigned int index,
|
||||||
GLint size, GLenum type, GLboolean normalized,
|
GLint size, GLenum type, GLboolean normalized,
|
||||||
GLsizei stride, const GLvoid *ptr )
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** wrapper around DisableVertexAttribArrayARB(index);
|
/** wrapper around DisableVertexAttribArrayARB(index);
|
||||||
* note, only updates values that change.*/
|
* note, only updates values that change.*/
|
||||||
inline void disableVertexAttribPointer( unsigned int index )
|
void disableVertexAttribPointer( unsigned int index );
|
||||||
{
|
|
||||||
static DisableVertexAttribProc s_glDisableVertexAttribArray =
|
void disableVertexAttribPointersAboveAndIncluding( unsigned int index );
|
||||||
(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void dirtyVertexAttribPointersAboveAndIncluding( unsigned int index )
|
inline void dirtyVertexAttribPointersAboveAndIncluding( unsigned int index )
|
||||||
{
|
{
|
||||||
while (index<_vertexAttribArrayList.size())
|
while (index<_vertexAttribArrayList.size())
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
using namespace osg;
|
using namespace osg;
|
||||||
|
|
||||||
AutoTransform::AutoTransform():
|
AutoTransform::AutoTransform():
|
||||||
_scale(1.0f,1.0f,1.0f),
|
|
||||||
_autoUpdateEyeMovementTolerance(0.0f),
|
_autoUpdateEyeMovementTolerance(0.0f),
|
||||||
_autoRotateToScreen(false),
|
_autoRotateToScreen(false),
|
||||||
_autoScaleToScreen(false),
|
_autoScaleToScreen(false),
|
||||||
|
_scale(1.0f,1.0f,1.0f),
|
||||||
_firstTimeToInitEyePoint(true),
|
_firstTimeToInitEyePoint(true),
|
||||||
_matrixDirty(true)
|
_matrixDirty(true)
|
||||||
{
|
{
|
||||||
@ -30,8 +30,8 @@ AutoTransform::AutoTransform(const AutoTransform& pat,const CopyOp& copyop):
|
|||||||
Transform(pat,copyop),
|
Transform(pat,copyop),
|
||||||
_position(pat._position),
|
_position(pat._position),
|
||||||
_pivotPoint(pat._pivotPoint),
|
_pivotPoint(pat._pivotPoint),
|
||||||
_scale(pat._scale),
|
_rotation(pat._rotation),
|
||||||
_rotation(pat._rotation)
|
_scale(pat._scale)
|
||||||
{
|
{
|
||||||
// setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
// setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
||||||
}
|
}
|
||||||
|
@ -83,51 +83,51 @@ public:
|
|||||||
_normalized(normalized),
|
_normalized(normalized),
|
||||||
_extensions(extensions),
|
_extensions(extensions),
|
||||||
_attribcoords(attribcoords),
|
_attribcoords(attribcoords),
|
||||||
_indices(indices) {}
|
_indices(indices) {;}
|
||||||
|
|
||||||
void operator () (unsigned int pos)
|
void operator () (unsigned int pos)
|
||||||
{
|
{
|
||||||
if (_indices) _attribcoords->accept(_indices->index(pos),*this);
|
if (_indices) _attribcoords->accept(_indices->index(pos),*this);
|
||||||
else _attribcoords->accept(pos,*this);
|
else _attribcoords->accept(pos,*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void apply(const GLshort& s)
|
virtual void apply(const GLshort& s)
|
||||||
{
|
{
|
||||||
_extensions->glVertexAttrib1s( _index, s );
|
_extensions->glVertexAttrib1s( _index, s );
|
||||||
}
|
}
|
||||||
virtual void apply(const GLfloat& f)
|
virtual void apply(const GLfloat& f)
|
||||||
{
|
{
|
||||||
_extensions->glVertexAttrib1f( _index, f );
|
_extensions->glVertexAttrib1f( _index, f );
|
||||||
}
|
}
|
||||||
virtual void apply(const UByte4& v)
|
virtual void apply(const UByte4& v)
|
||||||
{
|
{
|
||||||
if( _normalized )
|
if( _normalized )
|
||||||
{
|
{
|
||||||
_extensions->glVertexAttrib4Nubv( _index, v.ptr() );
|
_extensions->glVertexAttrib4Nubv( _index, v.ptr() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_extensions->glVertexAttrib4ubv( _index, v.ptr() );
|
_extensions->glVertexAttrib4ubv( _index, v.ptr() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void apply(const Vec2& v)
|
virtual void apply(const Vec2& v)
|
||||||
{
|
{
|
||||||
_extensions->glVertexAttrib2fv( _index, v.ptr() );
|
_extensions->glVertexAttrib2fv( _index, v.ptr() );
|
||||||
}
|
}
|
||||||
virtual void apply(const Vec3& v)
|
virtual void apply(const Vec3& v)
|
||||||
{
|
{
|
||||||
_extensions->glVertexAttrib3fv( _index, v.ptr() );
|
_extensions->glVertexAttrib3fv( _index, v.ptr() );
|
||||||
}
|
}
|
||||||
virtual void apply(const Vec4& v)
|
virtual void apply(const Vec4& v)
|
||||||
{
|
{
|
||||||
_extensions->glVertexAttrib4fv( _index, v.ptr() );
|
_extensions->glVertexAttrib4fv( _index, v.ptr() );
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int _index;
|
const Geometry::Extensions *_extensions;
|
||||||
GLboolean _normalized;
|
const Array* _attribcoords;
|
||||||
const Geometry::Extensions* _extensions;
|
const IndexArray* _indices;
|
||||||
const Array* _attribcoords;
|
GLboolean _normalized;
|
||||||
const IndexArray* _indices;
|
unsigned int _index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawTexCoord : public osg::Referenced, public osg::ConstValueVisitor
|
class DrawTexCoord : public osg::Referenced, public osg::ConstValueVisitor
|
||||||
@ -247,6 +247,9 @@ Geometry::Geometry()
|
|||||||
|
|
||||||
Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop):
|
Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop):
|
||||||
Drawable(geometry,copyop),
|
Drawable(geometry,copyop),
|
||||||
|
#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS
|
||||||
|
_attributeList(geometry._attributeList),
|
||||||
|
#endif
|
||||||
_vertexArray(dynamic_cast<Vec3Array*>(copyop(geometry._vertexArray.get()))),
|
_vertexArray(dynamic_cast<Vec3Array*>(copyop(geometry._vertexArray.get()))),
|
||||||
_normalBinding(geometry._normalBinding),
|
_normalBinding(geometry._normalBinding),
|
||||||
_normalArray(dynamic_cast<Vec3Array*>(copyop(geometry._normalArray.get()))),
|
_normalArray(dynamic_cast<Vec3Array*>(copyop(geometry._normalArray.get()))),
|
||||||
@ -331,6 +334,89 @@ const IndexArray* Geometry::getTexCoordIndices(unsigned int unit) const
|
|||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS
|
||||||
|
|
||||||
|
void Geometry::setArray(AttributeType type,Array* array)
|
||||||
|
{
|
||||||
|
if (_attributeList.size()<=type)
|
||||||
|
_attributeList.resize(type+1);
|
||||||
|
|
||||||
|
_attributeList[type]._array = array;
|
||||||
|
|
||||||
|
dirtyDisplayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Array* Geometry::getArray(AttributeType type)
|
||||||
|
{
|
||||||
|
if (type<_attributeList.size()) return _attributeList[type]._array.get();
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Array* Geometry::getArray(AttributeType type) const
|
||||||
|
{
|
||||||
|
if (type<_attributeList.size()) return _attributeList[type]._array.get();
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Geometry::setIndices(AttributeType type,IndexArray* array)
|
||||||
|
{
|
||||||
|
if (_attributeList.size()<=type)
|
||||||
|
_attributeList.resize(type+1);
|
||||||
|
|
||||||
|
_attributeList[type]._indices = array;
|
||||||
|
|
||||||
|
dirtyDisplayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexArray* Geometry::getIndices(AttributeType type)
|
||||||
|
{
|
||||||
|
if (type<_attributeList.size()) return _attributeList[type]._indices.get();
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const IndexArray* Geometry::getIndices(AttributeType type) const
|
||||||
|
{
|
||||||
|
if (type<_attributeList.size()) return _attributeList[type]._indices.get();
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Geometry::setNormalize(AttributeType type,GLboolean normalize)
|
||||||
|
{
|
||||||
|
if (_attributeList.size()<=type)
|
||||||
|
_attributeList.resize(type+1);
|
||||||
|
|
||||||
|
_attributeList[type]._normalize = normalize;
|
||||||
|
|
||||||
|
dirtyDisplayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
GLboolean Geometry::getNormalize(AttributeType type) const
|
||||||
|
{
|
||||||
|
if (type<_attributeList.size()) return _attributeList[type]._normalize;
|
||||||
|
else return GL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Geometry::setBinding(AttributeType type,AttributeBinding binding)
|
||||||
|
{
|
||||||
|
if (_attributeList.size()<=type)
|
||||||
|
_attributeList.resize(type+1);
|
||||||
|
|
||||||
|
_attributeList[type]._binding = binding;
|
||||||
|
|
||||||
|
dirtyDisplayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Geometry::AttributeBinding Geometry::getBinding(AttributeType type) const
|
||||||
|
{
|
||||||
|
if (type<_attributeList.size()) return _attributeList[type]._binding;
|
||||||
|
else return BIND_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void Geometry::setVertexAttribArray(unsigned int index,bool normalize,Array* array,AttributeBinding ab)
|
void Geometry::setVertexAttribArray(unsigned int index,bool normalize,Array* array,AttributeBinding ab)
|
||||||
{
|
{
|
||||||
if (_vertexAttribList.size()<=index)
|
if (_vertexAttribList.size()<=index)
|
||||||
@ -342,7 +428,15 @@ void Geometry::setVertexAttribArray(unsigned int index,bool normalize,Array* arr
|
|||||||
_vertexAttribList[index].first = normalize;
|
_vertexAttribList[index].first = normalize;
|
||||||
_vertexAttribList[index].second.first = array;
|
_vertexAttribList[index].second.first = array;
|
||||||
|
|
||||||
_vertexAttribBindingList[index] = ab;
|
if( index == 0 )
|
||||||
|
{
|
||||||
|
// Force bind per vertex
|
||||||
|
_vertexAttribBindingList[index] = BIND_PER_VERTEX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_vertexAttribBindingList[index] = ab;
|
||||||
|
}
|
||||||
|
|
||||||
_fastPathComputed = false;
|
_fastPathComputed = false;
|
||||||
dirtyDisplayList();
|
dirtyDisplayList();
|
||||||
@ -683,8 +777,6 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
//
|
//
|
||||||
if(!extensions->isVertexProgramSupported())
|
if(!extensions->isVertexProgramSupported())
|
||||||
{
|
{
|
||||||
notify(WARN) << "Error: VertexProgram not supported by OpenGL driver" << std::endl;
|
|
||||||
|
|
||||||
for( unsigned int va = 0; va < _vertexAttribBindingList.size(); ++va )
|
for( unsigned int va = 0; va < _vertexAttribBindingList.size(); ++va )
|
||||||
{
|
{
|
||||||
if (_vertexAttribBindingList[va]!=BIND_OFF)
|
if (_vertexAttribBindingList[va]!=BIND_OFF)
|
||||||
@ -720,7 +812,10 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
// fast path.
|
// fast path.
|
||||||
//
|
//
|
||||||
|
|
||||||
state.setVertexPointer(3,GL_FLOAT,0,_vertexArray->getDataPointer());
|
if( _vertexArray.valid() )
|
||||||
|
state.setVertexPointer(3,GL_FLOAT,0,_vertexArray->getDataPointer());
|
||||||
|
else
|
||||||
|
state.disableVertexPointer();
|
||||||
|
|
||||||
if (_normalBinding==BIND_PER_VERTEX)
|
if (_normalBinding==BIND_PER_VERTEX)
|
||||||
state.setNormalPointer(GL_FLOAT,0,_normalArray->getDataPointer());
|
state.setNormalPointer(GL_FLOAT,0,_normalArray->getDataPointer());
|
||||||
@ -759,34 +854,29 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
for( index = 0; index < _vertexAttribList.size(); ++index )
|
for( index = 0; index < _vertexAttribList.size(); ++index )
|
||||||
{
|
{
|
||||||
const Array* array = _vertexAttribList[index].second.first.get();
|
const Array* array = _vertexAttribList[index].second.first.get();
|
||||||
const IndexArray* indexArray = _vertexAttribList[index].second.second.get();
|
const AttributeBinding ab = _vertexAttribBindingList[index];
|
||||||
|
|
||||||
if( _vertexAttribBindingList[index] == BIND_PER_VERTEX )
|
if( ab == BIND_PER_VERTEX && array )
|
||||||
{
|
{
|
||||||
if( array )
|
state.setVertexAttribPointer( index, array->getDataSize(), array->getDataType(),
|
||||||
{
|
_vertexAttribList[index].first, 0, array->getDataPointer() );
|
||||||
state.setVertexAttribPointer( index, array->getDataSize(), array->getDataType(),
|
|
||||||
_vertexAttribList[index].first, 0, array->getDataPointer() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
state.disableVertexAttribPointer( index );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( indexArray )
|
if( array )
|
||||||
{
|
{
|
||||||
if( indexArray->getNumElements() > 0 )
|
const IndexArray* indexArray = _vertexAttribList[index].second.second.get();
|
||||||
|
|
||||||
|
if( indexArray && indexArray->getNumElements() > 0 )
|
||||||
{
|
{
|
||||||
drawVertexAttribMap[_vertexAttribBindingList[index]].push_back(
|
drawVertexAttribMap[ab].push_back(
|
||||||
new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,indexArray) );
|
new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,indexArray) );
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
drawVertexAttribMap[ab].push_back(
|
||||||
drawVertexAttribMap[_vertexAttribBindingList[index]].push_back(
|
new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,0) );
|
||||||
new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,0) );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state.disableVertexAttribPointer( index );
|
state.disableVertexAttribPointer( index );
|
||||||
@ -908,24 +998,25 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
if( extensions->isVertexProgramSupported() )
|
if( extensions->isVertexProgramSupported() )
|
||||||
{
|
{
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
for( index = 0; index < _vertexAttribList.size(); ++index )
|
for( index = 1; index < _vertexAttribList.size(); ++index )
|
||||||
{
|
{
|
||||||
const Array* array = _vertexAttribList[index].second.first.get();
|
const Array* array = _vertexAttribList[index].second.first.get();
|
||||||
const IndexArray* indexArray = _vertexAttribList[index].second.second.get();
|
|
||||||
|
|
||||||
if( indexArray )
|
if( array && array->getNumElements() > 0 )
|
||||||
{
|
{
|
||||||
if( indexArray->getNumElements() > 0 )
|
const IndexArray* indexArray = _vertexAttribList[index].second.second.get();
|
||||||
|
|
||||||
|
if( indexArray && indexArray->getNumElements() > 0 )
|
||||||
{
|
{
|
||||||
drawVertexAttribMap[_vertexAttribBindingList[index]].push_back(
|
drawVertexAttribMap[_vertexAttribBindingList[index]].push_back(
|
||||||
new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,indexArray) );
|
new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,indexArray) );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
drawVertexAttribMap[_vertexAttribBindingList[index]].push_back(
|
||||||
|
new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,0) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
drawVertexAttribMap[_vertexAttribBindingList[index]].push_back(
|
|
||||||
new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,0) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,6 +1046,18 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
// set up vertex functor.
|
// set up vertex functor.
|
||||||
DrawVertex drawVertex(_vertexArray.get(),_vertexIndices.get());
|
DrawVertex drawVertex(_vertexArray.get(),_vertexIndices.get());
|
||||||
|
|
||||||
|
bool useVertexAttrib = _vertexAttribList.size() > 0 &&
|
||||||
|
_vertexAttribList[0].second.first.valid() &&
|
||||||
|
_vertexAttribList[0].second.first->getNumElements();
|
||||||
|
|
||||||
|
ref_ptr<DrawVertexAttrib> drawVertexAttribZero;
|
||||||
|
if( useVertexAttrib )
|
||||||
|
{
|
||||||
|
drawVertexAttribZero = new DrawVertexAttrib(extensions,0,
|
||||||
|
_vertexAttribList[0].first,_vertexAttribList[0].second.first.get(),
|
||||||
|
_vertexAttribList[0].second.second.get());
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// draw the primitives themselves.
|
// draw the primitives themselves.
|
||||||
@ -1048,7 +1151,14 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
}
|
}
|
||||||
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
||||||
|
|
||||||
drawVertex(vindex);
|
if( useVertexAttrib )
|
||||||
|
{
|
||||||
|
(*drawVertexAttribZero)(vindex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
drawVertex(vindex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
@ -1109,8 +1219,15 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
}
|
}
|
||||||
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
||||||
|
|
||||||
drawVertex(vindex);
|
if( useVertexAttrib )
|
||||||
|
{
|
||||||
|
(*drawVertexAttribZero)(vindex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
drawVertex(vindex);
|
||||||
|
}
|
||||||
|
|
||||||
++vindex;
|
++vindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1173,7 +1290,14 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
}
|
}
|
||||||
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
||||||
|
|
||||||
drawVertex(vindex);
|
if( useVertexAttrib )
|
||||||
|
{
|
||||||
|
(*drawVertexAttribZero)(vindex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
drawVertex(vindex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
@ -1233,7 +1357,14 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
}
|
}
|
||||||
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
||||||
|
|
||||||
drawVertex(vindex);
|
if( useVertexAttrib )
|
||||||
|
{
|
||||||
|
(*drawVertexAttribZero)(vindex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
drawVertex(vindex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
@ -1293,7 +1424,14 @@ void Geometry::drawImplementation(State& state) const
|
|||||||
}
|
}
|
||||||
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
if (drawTextCoord.valid()) (*drawTextCoord)(vindex);
|
||||||
|
|
||||||
drawVertex(vindex);
|
if( useVertexAttrib )
|
||||||
|
{
|
||||||
|
(*drawVertexAttribZero)(vindex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
drawVertex(vindex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include <osg/State>
|
#include <osg/State>
|
||||||
#include <osg/Notify>
|
#include <osg/Notify>
|
||||||
#include <osg/GLU>
|
#include <osg/GLU>
|
||||||
|
#include <osg/GLExtensions>
|
||||||
|
|
||||||
|
|
||||||
using namespace osg;
|
using namespace osg;
|
||||||
|
|
||||||
@ -614,6 +616,84 @@ void State::setSecondaryColorPointer( GLint size, GLenum type,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.*/
|
||||||
|
void State::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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** wrapper around DisableVertexAttribArrayARB(index);
|
||||||
|
* note, only updates values that change.*/
|
||||||
|
void State::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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void State::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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool State::computeSecondaryColorSupported() const
|
bool State::computeSecondaryColorSupported() const
|
||||||
{
|
{
|
||||||
_isSecondColorSupportResolved = true;
|
_isSecondColorSupportResolved = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user