Updates to GeometryNew, Array and ArraDispatchers to clean up GeometryNew so that is no longer uses ArrayData.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user