Updates to GeometryNew, Array and ArraDispatchers to clean up GeometryNew so that is no longer uses ArrayData.
This commit is contained in:
parent
cbea97009c
commit
eb693f6a92
@ -76,16 +76,33 @@ class OSG_EXPORT Array : public BufferData
|
||||
MatrixArrayType = 22
|
||||
};
|
||||
|
||||
enum Binding
|
||||
{
|
||||
BIND_OFF=0,
|
||||
BIND_OVERALL=1,
|
||||
BIND_PER_PRIMITIVE_SET=2,
|
||||
BIND_PER_VERTEX=4,
|
||||
BIND_AUTO=5
|
||||
};
|
||||
|
||||
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
|
||||
_arrayType(arrayType),
|
||||
_dataSize(dataSize),
|
||||
_dataType(dataType) {}
|
||||
_dataType(dataType),
|
||||
_normalize(false),
|
||||
_preserveDataType(false),
|
||||
_attribDivisor(false),
|
||||
_binding(BIND_AUTO) {}
|
||||
|
||||
Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
BufferData(array,copyop),
|
||||
_arrayType(array._arrayType),
|
||||
_dataSize(array._dataSize),
|
||||
_dataType(array._dataType) {}
|
||||
_dataType(array._dataType),
|
||||
_normalize(array._normalize),
|
||||
_preserveDataType(array._preserveDataType),
|
||||
_attribDivisor(array._attribDivisor),
|
||||
_binding(array._binding) {}
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
@ -123,28 +140,18 @@ class OSG_EXPORT Array : public BufferData
|
||||
|
||||
/** Get hint to ask that the array data is passed via integer or double, or normal setVertexAttribPointer function.*/
|
||||
bool getPreserveDataType() const { return _preserveDataType; }
|
||||
|
||||
/** Set the rate at which generic vertex attributes advance during instanced rendering. Uses the glVertexAttribDivisor feature of OpenGL 4.0*/
|
||||
void setAttribDivisor(GLuint divisor) { _attribDivisor = divisor; }
|
||||
|
||||
/** Get the rate at which generic vertex attributes advance during instanced rendering.*/
|
||||
GLuint getAttribDivisor() const { return _attribDivisor; }
|
||||
|
||||
enum Binding
|
||||
{
|
||||
BIND_OFF=0,
|
||||
BIND_OVERALL,
|
||||
BIND_PER_PRIMITIVE_SET,
|
||||
BIND_PER_VERTEX
|
||||
};
|
||||
|
||||
/** Specify how this array should be passed to OpenGL.*/
|
||||
void setBinding(Binding binding) { _binding = binding; }
|
||||
|
||||
/** Get how this array should be passed to OpenGL.*/
|
||||
Binding getBinding() const { return _binding; }
|
||||
|
||||
|
||||
|
||||
/** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/
|
||||
virtual void trim() {}
|
||||
|
||||
|
@ -41,19 +41,8 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
|
||||
void setState(osg::State* state);
|
||||
|
||||
AttributeDispatch* vertexDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* normalDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* colorDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* secondaryColorDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* fogCoordDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices);
|
||||
AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array, IndexArray* indices);
|
||||
|
||||
void reset();
|
||||
|
||||
void setUseGLBeginEndAdapter(bool flag) { _useGLBeginEndAdapter = flag; }
|
||||
bool getUseGLBeginEndAdapter() const { return _useGLBeginEndAdapter; }
|
||||
|
||||
void setUseVertexAttribAlias(bool flag) { _useVertexAttribAlias = flag; }
|
||||
bool getUseVertexAttribAlias() const { return _useVertexAttribAlias; }
|
||||
|
||||
@ -62,6 +51,23 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
if (at) _activeDispatchList[binding].push_back(at);
|
||||
}
|
||||
|
||||
void activateVertexArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), vertexDispatcher(array, 0)); }
|
||||
void activateColorArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), colorDispatcher(array, 0)); }
|
||||
void activateNormalArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), normalDispatcher(array, 0)); }
|
||||
void activateSecondaryColorArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), secondaryColorDispatcher(array, 0)); }
|
||||
void activateFogCoordArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), fogCoordDispatcher(array, 0)); }
|
||||
void activateTexCoordArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), texCoordDispatcher(unit, array, 0)); }
|
||||
void activateVertexAttribArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), vertexAttribDispatcher(unit, array, 0)); }
|
||||
|
||||
|
||||
AttributeDispatch* vertexDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* normalDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* colorDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* secondaryColorDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* fogCoordDispatcher(Array* array, IndexArray* indices);
|
||||
AttributeDispatch* texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices);
|
||||
AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array, IndexArray* indices);
|
||||
|
||||
void activateVertexArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, vertexDispatcher(array, indices)); }
|
||||
void activateColorArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, colorDispatcher(array, indices)); }
|
||||
void activateNormalArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, normalDispatcher(array, indices)); }
|
||||
@ -83,6 +89,10 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
|
||||
bool active(unsigned int binding) const { return !_activeDispatchList[binding].empty(); }
|
||||
|
||||
void setUseGLBeginEndAdapter(bool flag) { _useGLBeginEndAdapter = flag; }
|
||||
bool getUseGLBeginEndAdapter() const { return _useGLBeginEndAdapter; }
|
||||
|
||||
|
||||
void Begin(GLenum mode)
|
||||
{
|
||||
#ifdef OSG_GL1_AVAILABLE
|
||||
|
@ -23,7 +23,6 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
class OSG_EXPORT GeometryNew : public Drawable
|
||||
{
|
||||
public:
|
||||
@ -46,156 +45,62 @@ class OSG_EXPORT GeometryNew : public Drawable
|
||||
|
||||
bool empty() const;
|
||||
|
||||
/** Same values as Array::Binding.*/
|
||||
enum AttributeBinding
|
||||
{
|
||||
BIND_OFF=0,
|
||||
BIND_OVERALL,
|
||||
BIND_PER_PRIMITIVE_SET,
|
||||
BIND_PER_PRIMITIVE,
|
||||
BIND_PER_VERTEX
|
||||
BIND_OVERALL=1,
|
||||
BIND_PER_PRIMITIVE_SET=2,
|
||||
BIND_PER_PRIMITIVE=3, /// deprecated
|
||||
BIND_PER_VERTEX=4
|
||||
};
|
||||
|
||||
struct OSG_EXPORT ArrayData
|
||||
{
|
||||
ArrayData():
|
||||
binding(BIND_OFF),
|
||||
normalize(GL_FALSE) {}
|
||||
|
||||
ArrayData(const ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
ArrayData(Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
binding(b),
|
||||
normalize(n) {}
|
||||
|
||||
ArrayData(Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
binding(b),
|
||||
normalize(n) {}
|
||||
|
||||
ArrayData& operator = (const ArrayData& rhs)
|
||||
{
|
||||
array = rhs.array;
|
||||
binding = rhs.binding;
|
||||
normalize = rhs.normalize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool empty() const { return !array.valid(); }
|
||||
|
||||
ref_ptr<Array> array;
|
||||
AttributeBinding binding;
|
||||
GLboolean normalize;
|
||||
};
|
||||
|
||||
struct OSG_EXPORT Vec3ArrayData
|
||||
{
|
||||
Vec3ArrayData():
|
||||
binding(BIND_OFF),
|
||||
normalize(GL_FALSE) {}
|
||||
|
||||
Vec3ArrayData(const Vec3ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
Vec3ArrayData(Vec3Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
binding(b),
|
||||
normalize(n) {}
|
||||
|
||||
Vec3ArrayData(Vec3Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
binding(b),
|
||||
normalize(n) {}
|
||||
|
||||
Vec3ArrayData& operator = (const Vec3ArrayData& rhs)
|
||||
{
|
||||
array = rhs.array;
|
||||
binding = rhs.binding;
|
||||
normalize = rhs.normalize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool empty() const { return !array.valid(); }
|
||||
|
||||
ref_ptr<Vec3Array> array;
|
||||
AttributeBinding binding;
|
||||
GLboolean normalize;
|
||||
};
|
||||
|
||||
/** Static ArrayData which is returned from getTexCoordData(i) const and getVertexAttribData(i) const
|
||||
* when i is out of range.
|
||||
*/
|
||||
static const ArrayData s_InvalidArrayData;
|
||||
|
||||
typedef std::vector< ArrayData > ArrayDataList;
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Array> > ArrayList;
|
||||
|
||||
void setVertexArray(Array* array);
|
||||
Array* getVertexArray() { return _vertexData.array.get(); }
|
||||
const Array* getVertexArray() const { return _vertexData.array.get(); }
|
||||
|
||||
void setVertexData(const ArrayData& arrayData);
|
||||
ArrayData& getVertexData() { return _vertexData; }
|
||||
const ArrayData& getVertexData() const { return _vertexData; }
|
||||
Array* getVertexArray() { return _vertexArray.get(); }
|
||||
const Array* getVertexArray() const { return _vertexArray.get(); }
|
||||
|
||||
|
||||
void setNormalBinding(AttributeBinding ab);
|
||||
AttributeBinding getNormalBinding() const { return _normalData.binding; }
|
||||
AttributeBinding getNormalBinding() const;
|
||||
|
||||
void setNormalArray(Array* array);
|
||||
Array* getNormalArray() { return _normalData.array.get(); }
|
||||
const Array* getNormalArray() const { return _normalData.array.get(); }
|
||||
|
||||
void setNormalData(const ArrayData& arrayData);
|
||||
ArrayData& getNormalData() { return _normalData; }
|
||||
const ArrayData& getNormalData() const { return _normalData; }
|
||||
Array* getNormalArray() { return _normalArray.get(); }
|
||||
const Array* getNormalArray() const { return _normalArray.get(); }
|
||||
|
||||
|
||||
void setColorBinding(AttributeBinding ab);
|
||||
AttributeBinding getColorBinding() const { return _colorData.binding; }
|
||||
AttributeBinding getColorBinding() const;
|
||||
|
||||
void setColorArray(Array* array);
|
||||
Array* getColorArray() { return _colorData.array.get(); }
|
||||
const Array* getColorArray() const { return _colorData.array.get(); }
|
||||
|
||||
void setColorData(const ArrayData& arrayData);
|
||||
ArrayData& getColorData() { return _colorData; }
|
||||
const ArrayData& getColorData() const { return _colorData; }
|
||||
Array* getColorArray() { return _colorArray.get(); }
|
||||
const Array* getColorArray() const { return _colorArray.get(); }
|
||||
|
||||
|
||||
void setSecondaryColorBinding(AttributeBinding ab);
|
||||
AttributeBinding getSecondaryColorBinding() const { return _secondaryColorData.binding; }
|
||||
AttributeBinding getSecondaryColorBinding() const;
|
||||
|
||||
void setSecondaryColorArray(Array* array);
|
||||
Array* getSecondaryColorArray() { return _secondaryColorData.array.get(); }
|
||||
const Array* getSecondaryColorArray() const { return _secondaryColorData.array.get(); }
|
||||
|
||||
void setSecondaryColorData(const ArrayData& arrayData);
|
||||
ArrayData& getSecondaryColorData() { return _secondaryColorData; }
|
||||
const ArrayData& getSecondaryColorData() const { return _secondaryColorData; }
|
||||
Array* getSecondaryColorArray() { return _secondaryColorArray.get(); }
|
||||
const Array* getSecondaryColorArray() const;
|
||||
|
||||
|
||||
void setFogCoordBinding(AttributeBinding ab);
|
||||
AttributeBinding getFogCoordBinding() const { return _fogCoordData.binding; }
|
||||
AttributeBinding getFogCoordBinding() const;
|
||||
|
||||
void setFogCoordArray(Array* array);
|
||||
Array* getFogCoordArray() { return _fogCoordData.array.get(); }
|
||||
const Array* getFogCoordArray() const { return _fogCoordData.array.get(); }
|
||||
|
||||
void setFogCoordData(const ArrayData& arrayData);
|
||||
ArrayData& getFogCoordData() { return _fogCoordData; }
|
||||
const ArrayData& getFogCoordData() const { return _fogCoordData; }
|
||||
Array* getFogCoordArray() { return _fogCoordArray.get(); }
|
||||
const Array* getFogCoordArray() const { return _fogCoordArray.get(); }
|
||||
|
||||
|
||||
void setTexCoordArray(unsigned int unit,Array*);
|
||||
Array* getTexCoordArray(unsigned int unit);
|
||||
const Array* getTexCoordArray(unsigned int unit) const;
|
||||
|
||||
void setTexCoordData(unsigned int index,const ArrayData& arrayData);
|
||||
ArrayData& getTexCoordData(unsigned int index);
|
||||
const ArrayData& getTexCoordData(unsigned int index) const;
|
||||
|
||||
unsigned int getNumTexCoordArrays() const { return static_cast<unsigned int>(_texCoordList.size()); }
|
||||
ArrayDataList& getTexCoordArrayList() { return _texCoordList; }
|
||||
const ArrayDataList& getTexCoordArrayList() const { return _texCoordList; }
|
||||
ArrayList& getTexCoordArrayList() { return _texCoordList; }
|
||||
const ArrayList& getTexCoordArrayList() const { return _texCoordList; }
|
||||
|
||||
|
||||
|
||||
@ -209,13 +114,9 @@ class OSG_EXPORT GeometryNew : public Drawable
|
||||
void setVertexAttribNormalize(unsigned int index,GLboolean norm);
|
||||
GLboolean getVertexAttribNormalize(unsigned int index) const;
|
||||
|
||||
void setVertexAttribData(unsigned int index,const ArrayData& arrayData);
|
||||
ArrayData& getVertexAttribData(unsigned int index);
|
||||
const ArrayData& getVertexAttribData(unsigned int index) const;
|
||||
|
||||
unsigned int getNumVertexAttribArrays() const { return static_cast<unsigned int>(_vertexAttribList.size()); }
|
||||
ArrayDataList& getVertexAttribArrayList() { return _vertexAttribList; }
|
||||
const ArrayDataList& getVertexAttribArrayList() const { return _vertexAttribList; }
|
||||
ArrayList& getVertexAttribArrayList() { return _vertexAttribList; }
|
||||
const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; }
|
||||
|
||||
|
||||
|
||||
@ -267,38 +168,15 @@ class OSG_EXPORT GeometryNew : public Drawable
|
||||
* for all graphics contexts. */
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
typedef std::vector<osg::Array*> ArrayList;
|
||||
bool getArrayList(ArrayList& arrayList) const;
|
||||
|
||||
typedef std::vector<osg::DrawElements*> DrawElementsList;
|
||||
bool getDrawElementsList(DrawElementsList& drawElementsList) const;
|
||||
|
||||
osg::VertexBufferObject* getOrCreateVertexBufferObject();
|
||||
|
||||
osg::ElementBufferObject* getOrCreateElementBufferObject();
|
||||
|
||||
|
||||
/** Set whether fast paths should be used when supported. */
|
||||
void setFastPathHint(bool on) { _fastPathHint = on; }
|
||||
|
||||
/** Get whether fast paths should be used when supported. */
|
||||
bool getFastPathHint() const { return _fastPathHint; }
|
||||
|
||||
|
||||
/** Return true if OpenGL fast paths will be used with drawing this Geometry.
|
||||
* Fast paths directly use vertex arrays, and glDrawArrays/glDrawElements so have low CPU overhead.
|
||||
* With Slow paths the osg::Geometry::drawImplementation has to dynamically assemble OpenGL
|
||||
* compatible vertex arrays from the osg::Geometry arrays data and then dispatch these to OpenGL,
|
||||
* so have higher CPU overhead than the Fast paths.
|
||||
* Use of per primitive bindings or per vertex indexed arrays will drop the rendering path off the fast path.
|
||||
*/
|
||||
inline bool areFastPathsUsed() const
|
||||
{
|
||||
return _fastPath && _fastPathHint;
|
||||
}
|
||||
|
||||
bool computeFastPathsUsed();
|
||||
|
||||
bool verifyBindings() const;
|
||||
|
||||
void computeCorrectBindingsAndArraySizes();
|
||||
@ -359,27 +237,22 @@ class OSG_EXPORT GeometryNew : public Drawable
|
||||
|
||||
virtual ~GeometryNew();
|
||||
|
||||
bool verifyBindings(const ArrayData& arrayData) const;
|
||||
bool verifyBindings(const Vec3ArrayData& arrayData) const;
|
||||
bool verifyBindings(const osg::ref_ptr<Array>& array) const;
|
||||
|
||||
void computeCorrectBindingsAndArraySizes(ArrayData& arrayData,const char* arrayName);
|
||||
void computeCorrectBindingsAndArraySizes(Vec3ArrayData& arrayData,const char* arrayName);
|
||||
void computeCorrectBindingsAndArraySizes(osg::ref_ptr<Array>& ,const char* arrayName);
|
||||
|
||||
void addVertexBufferObjectIfRequired(osg::Array* array);
|
||||
void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
|
||||
|
||||
|
||||
PrimitiveSetList _primitives;
|
||||
ArrayData _vertexData;
|
||||
ArrayData _normalData;
|
||||
ArrayData _colorData;
|
||||
ArrayData _secondaryColorData;
|
||||
ArrayData _fogCoordData;
|
||||
ArrayDataList _texCoordList;
|
||||
ArrayDataList _vertexAttribList;
|
||||
|
||||
mutable bool _fastPath;
|
||||
bool _fastPathHint;
|
||||
osg::ref_ptr<Array> _vertexArray;
|
||||
osg::ref_ptr<Array> _normalArray;
|
||||
osg::ref_ptr<Array> _colorArray;
|
||||
osg::ref_ptr<Array> _secondaryColorArray;
|
||||
osg::ref_ptr<Array> _fogCoordArray;
|
||||
ArrayList _texCoordList;
|
||||
ArrayList _vertexAttribList;
|
||||
};
|
||||
|
||||
/** Convenience function to be used for creating quad geometry with texture coords.
|
||||
|
@ -465,6 +465,10 @@ void ArrayDispatchers::init()
|
||||
_activeDispatchList.resize(5);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// With inidices
|
||||
//
|
||||
AttributeDispatch* ArrayDispatchers::vertexDispatcher(Array* array, IndexArray* indices)
|
||||
{
|
||||
return _useVertexAttribAlias ?
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user