Introduced GeometryNew which is a cleaned up version of Geometry that removes support for array indices.

GeometryNew is only temporary and will be renamed to Geometry on the completion of refactoring work and feedback from community.
Ported osggeometry across to use GeometryNew.
This commit is contained in:
Robert Osfield 2013-06-04 09:32:59 +00:00
parent 4cca5c1d1c
commit caa3a06c70
4 changed files with 2394 additions and 28 deletions

View File

@ -17,7 +17,7 @@
*/ */
#include <osg/Geode> #include <osg/Geode>
#include <osg/Geometry> #include <osg/GeometryNew>
#include <osg/Material> #include <osg/Material>
#include <osg/Vec3> #include <osg/Vec3>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
@ -37,6 +37,7 @@
#include <iostream> #include <iostream>
// This demo illustrates how to create the various different types of geometry that // This demo illustrates how to create the various different types of geometry that
// the osg::Geometry class can represent. This demo uses the OpenGL red book diagram of different // the osg::Geometry class can represent. This demo uses the OpenGL red book diagram of different
// OpenGL Primitives as a template for all the equivalent OpenSceneGraph Primitives. The OpenSceneGraph // OpenGL Primitives as a template for all the equivalent OpenSceneGraph Primitives. The OpenSceneGraph
@ -92,7 +93,7 @@ osg::Node* createScene()
// create POINTS // create POINTS
{ {
// create Geometry object to store all the vertices and points primitive. // create Geometry object to store all the vertices and points primitive.
osg::Geometry* pointsGeom = new osg::Geometry(); osg::GeometryNew* pointsGeom = new osg::GeometryNew();
// create a Vec3Array and add to it all my coordinates. // create a Vec3Array and add to it all my coordinates.
// Like all the *Array variants (see include/osg/Array) , Vec3Array is derived from both osg::Array // Like all the *Array variants (see include/osg/Array) , Vec3Array is derived from both osg::Array
@ -121,14 +122,14 @@ osg::Node* createScene()
// pass the color array to points geometry, note the binding to tell the geometry // pass the color array to points geometry, note the binding to tell the geometry
// that only use one color for the whole object. // that only use one color for the whole object.
pointsGeom->setColorArray(colors); pointsGeom->setColorArray(colors);
pointsGeom->setColorBinding(osg::Geometry::BIND_OVERALL); pointsGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
// set the normal in the same way color. // set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array; osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
pointsGeom->setNormalArray(normals); pointsGeom->setNormalArray(normals);
pointsGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); pointsGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
// create and add a DrawArray Primitive (see include/osg/Primitive). The first // create and add a DrawArray Primitive (see include/osg/Primitive). The first
@ -146,7 +147,7 @@ osg::Node* createScene()
// create LINES // create LINES
{ {
// create Geometry object to store all the vertices and lines primitive. // create Geometry object to store all the vertices and lines primitive.
osg::Geometry* linesGeom = new osg::Geometry(); osg::GeometryNew* linesGeom = new osg::GeometryNew();
// this time we'll preallocate the vertex array to the size we // this time we'll preallocate the vertex array to the size we
// need and then simple set them as array elements, 8 points // need and then simple set them as array elements, 8 points
@ -169,14 +170,14 @@ osg::Node* createScene()
osg::Vec4Array* colors = new osg::Vec4Array; osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
linesGeom->setColorArray(colors); linesGeom->setColorArray(colors);
linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); linesGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
// set the normal in the same way color. // set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array; osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
linesGeom->setNormalArray(normals); linesGeom->setNormalArray(normals);
linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); linesGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use // This time we simply use primitive, and hardwire the number of coords to use
@ -191,7 +192,7 @@ osg::Node* createScene()
// create LINE_STRIP // create LINE_STRIP
{ {
// create Geometry object to store all the vertices and lines primitive. // create Geometry object to store all the vertices and lines primitive.
osg::Geometry* linesGeom = new osg::Geometry(); osg::GeometryNew* linesGeom = new osg::GeometryNew();
// this time we'll preallocate the vertex array to the size // this time we'll preallocate the vertex array to the size
// and then use an iterator to fill in the values, a bit perverse // and then use an iterator to fill in the values, a bit perverse
@ -211,14 +212,14 @@ osg::Node* createScene()
osg::Vec4Array* colors = new osg::Vec4Array; osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
linesGeom->setColorArray(colors); linesGeom->setColorArray(colors);
linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); linesGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
// set the normal in the same way color. // set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array; osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
linesGeom->setNormalArray(normals); linesGeom->setNormalArray(normals);
linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); linesGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use // This time we simply use primitive, and hardwire the number of coords to use
@ -233,7 +234,7 @@ osg::Node* createScene()
// create LINE_LOOP // create LINE_LOOP
{ {
// create Geometry object to store all the vertices and lines primitive. // create Geometry object to store all the vertices and lines primitive.
osg::Geometry* linesGeom = new osg::Geometry(); osg::GeometryNew* linesGeom = new osg::GeometryNew();
// this time we'll a C arrays to initialize the vertices. // this time we'll a C arrays to initialize the vertices.
@ -258,14 +259,14 @@ osg::Node* createScene()
osg::Vec4Array* colors = new osg::Vec4Array; osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
linesGeom->setColorArray(colors); linesGeom->setColorArray(colors);
linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); linesGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
// set the normal in the same way color. // set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array; osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
linesGeom->setNormalArray(normals); linesGeom->setNormalArray(normals);
linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); linesGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use // This time we simply use primitive, and hardwire the number of coords to use
@ -306,7 +307,7 @@ osg::Node* createScene()
// create POLYGON // create POLYGON
{ {
// create Geometry object to store all the vertices and lines primitive. // create Geometry object to store all the vertices and lines primitive.
osg::Geometry* polyGeom = new osg::Geometry(); osg::GeometryNew* polyGeom = new osg::GeometryNew();
// this time we'll use C arrays to initialize the vertices. // this time we'll use C arrays to initialize the vertices.
// note, anticlockwise ordering. // note, anticlockwise ordering.
@ -332,12 +333,12 @@ osg::Node* createScene()
// use the shared color array. // use the shared color array.
polyGeom->setColorArray(shared_colors.get()); polyGeom->setColorArray(shared_colors.get());
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
// use the shared normal array. // use the shared normal array.
polyGeom->setNormalArray(shared_normals.get()); polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use // This time we simply use primitive, and hardwire the number of coords to use
@ -354,7 +355,7 @@ osg::Node* createScene()
// create QUADS // create QUADS
{ {
// create Geometry object to store all the vertices and lines primitive. // create Geometry object to store all the vertices and lines primitive.
osg::Geometry* polyGeom = new osg::Geometry(); osg::GeometryNew* polyGeom = new osg::GeometryNew();
// note, anticlockwise ordering. // note, anticlockwise ordering.
osg::Vec3 myCoords[] = osg::Vec3 myCoords[] =
@ -379,12 +380,12 @@ osg::Node* createScene()
// use the shared color array. // use the shared color array.
polyGeom->setColorArray(shared_colors.get()); polyGeom->setColorArray(shared_colors.get());
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
// use the shared normal array. // use the shared normal array.
polyGeom->setNormalArray(shared_normals.get()); polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use // This time we simply use primitive, and hardwire the number of coords to use
@ -401,7 +402,7 @@ osg::Node* createScene()
// create QUAD_STRIP // create QUAD_STRIP
{ {
// create Geometry object to store all the vertices and lines primitive. // create Geometry object to store all the vertices and lines primitive.
osg::Geometry* polyGeom = new osg::Geometry(); osg::GeometryNew* polyGeom = new osg::GeometryNew();
// note, first coord at top, second at bottom, reverse to that buggy OpenGL image.. // note, first coord at top, second at bottom, reverse to that buggy OpenGL image..
osg::Vec3 myCoords[] = osg::Vec3 myCoords[] =
@ -428,12 +429,12 @@ osg::Node* createScene()
// use the shared color array. // use the shared color array.
polyGeom->setColorArray(shared_colors.get()); polyGeom->setColorArray(shared_colors.get());
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
// use the shared normal array. // use the shared normal array.
polyGeom->setNormalArray(shared_normals.get()); polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use // This time we simply use primitive, and hardwire the number of coords to use
@ -450,7 +451,7 @@ osg::Node* createScene()
// create TRIANGLES, TRIANGLE_STRIP and TRIANGLE_FAN all in one Geometry/ // create TRIANGLES, TRIANGLE_STRIP and TRIANGLE_FAN all in one Geometry/
{ {
// create Geometry object to store all the vertices and lines primitive. // create Geometry object to store all the vertices and lines primitive.
osg::Geometry* polyGeom = new osg::Geometry(); osg::GeometryNew* polyGeom = new osg::GeometryNew();
// note, first coord at top, second at bottom, reverse to that buggy OpenGL image.. // note, first coord at top, second at bottom, reverse to that buggy OpenGL image..
osg::Vec3 myCoords[] = osg::Vec3 myCoords[] =
@ -496,12 +497,12 @@ osg::Node* createScene()
// use the shared color array. // use the shared color array.
polyGeom->setColorArray(shared_colors.get()); polyGeom->setColorArray(shared_colors.get());
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
// use the shared normal array. // use the shared normal array.
polyGeom->setNormalArray(shared_normals.get()); polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use // This time we simply use primitive, and hardwire the number of coords to use
@ -570,7 +571,7 @@ osg::Node* createBackground()
// create Geometry object to store all the vertices and lines primitive. // create Geometry object to store all the vertices and lines primitive.
osg::Geometry* polyGeom = new osg::Geometry(); osg::GeometryNew* polyGeom = new osg::GeometryNew();
// note, anticlockwise ordering. // note, anticlockwise ordering.
osg::Vec3 myCoords[] = osg::Vec3 myCoords[] =
@ -589,14 +590,14 @@ osg::Node* createBackground()
osg::Vec4Array* colors = new osg::Vec4Array; osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
polyGeom->setColorArray(colors); polyGeom->setColorArray(colors);
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL);
// set the normal in the same way color. // set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array; osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
polyGeom->setNormalArray(normals); polyGeom->setNormalArray(normals);
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL);
osg::Vec2 myTexCoords[] = osg::Vec2 myTexCoords[] =
{ {

401
include/osg/GeometryNew Normal file
View File

@ -0,0 +1,401 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_GEOMETRYNEW
#define OSG_GEOMETRYNEW 1
#include <osg/Drawable>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Array>
#include <osg/PrimitiveSet>
namespace osg {
class OSG_EXPORT GeometryNew : public Drawable
{
public:
GeometryNew();
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
GeometryNew(const GeometryNew& geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual Object* cloneType() const { return new GeometryNew(); }
virtual Object* clone(const CopyOp& copyop) const { return new GeometryNew(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const GeometryNew*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "GeometryNew"; }
#if 0
virtual Geometry* asGeometry() { return this; }
virtual const Geometry* asGeometry() const { return this; }
#endif
bool empty() const;
enum AttributeBinding
{
BIND_OFF=0,
BIND_OVERALL,
BIND_PER_PRIMITIVE_SET,
BIND_PER_PRIMITIVE,
BIND_PER_VERTEX
};
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;
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; }
void setNormalBinding(AttributeBinding ab);
AttributeBinding getNormalBinding() const { return _normalData.binding; }
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; }
void setColorBinding(AttributeBinding ab);
AttributeBinding getColorBinding() const { return _colorData.binding; }
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; }
void setSecondaryColorBinding(AttributeBinding ab);
AttributeBinding getSecondaryColorBinding() const { return _secondaryColorData.binding; }
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; }
void setFogCoordBinding(AttributeBinding ab);
AttributeBinding getFogCoordBinding() const { return _fogCoordData.binding; }
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; }
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; }
void setVertexAttribArray(unsigned int index,Array* array);
Array *getVertexAttribArray(unsigned int index);
const Array *getVertexAttribArray(unsigned int index) const;
void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
AttributeBinding getVertexAttribBinding(unsigned int index) const;
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; }
typedef std::vector< ref_ptr<PrimitiveSet> > PrimitiveSetList;
void setPrimitiveSetList(const PrimitiveSetList& primitives);
PrimitiveSetList& getPrimitiveSetList() { return _primitives; }
const PrimitiveSetList& getPrimitiveSetList() const { return _primitives; }
unsigned int getNumPrimitiveSets() const { return static_cast<unsigned int>(_primitives.size()); }
PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); }
const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); }
/** Add a primitive set to the geometry. */
bool addPrimitiveSet(PrimitiveSet* primitiveset);
/** Set a primitive set to the specified position in geometry's primitive set list. */
bool setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
/** Insert a primitive set to the specified position in geometry's primitive set list. */
bool insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
/** Remove primitive set(s) from the specified position in geometry's primitive set list. */
bool removePrimitiveSet(unsigned int i,unsigned int numElementsToRemove=1);
/** Get the index number of a primitive set, return a value between
* 0 and getNumPrimitiveSet()-1 if found, if not found then return getNumPrimitiveSet().
* When checking for a valid find value use if ((value=geometry->getPrimitiveSetIndex(primitive))!=geometry.getNumPrimitiveSet())
*/
unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const;
/** When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation
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();
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize);
/** If State is non-zero, this function releases OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objects
* 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();
/** check whether the arrays, indices, bindings and primitives all match correctly, return false is .*/
bool verifyArrays(std::ostream& out) const;
bool containsSharedArrays() const;
void duplicateSharedArrays();
/** 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. */
virtual unsigned int getGLObjectSizeHint() const;
/** 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;
/** Draw Geometry directly ignoring an OpenGL display list which could be attached.
* This is the internal draw method which does the drawing itself,
* and is the method to override when deriving from Geometry for user-drawn objects.
*/
virtual void drawImplementation(RenderInfo& renderInfo) const;
/** Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&). */
virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
/** Accept an Drawable::AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */
virtual void accept(Drawable::AttributeFunctor& af);
/** Return true, osg::Geometry does support accept(Drawable::ConstAttributeFunctor&). */
virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
/** Accept a Drawable::ConstAttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */
virtual void accept(Drawable::ConstAttributeFunctor& af) const;
/** Return true, osg::Geometry does support accept(PrimitiveFunctor&). */
virtual bool supports(const PrimitiveFunctor&) const { return true; }
/** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has. */
virtual void accept(PrimitiveFunctor& pf) const;
/** Return true, osg::Geometry does support accept(PrimitiveIndexFunctor&). */
virtual bool supports(const PrimitiveIndexFunctor&) const { return true; }
/** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has. */
virtual void accept(PrimitiveIndexFunctor& pf) const;
protected:
GeometryNew& operator = (const GeometryNew&) { return *this;}
virtual ~GeometryNew();
bool verifyBindings(const ArrayData& arrayData) const;
bool verifyBindings(const Vec3ArrayData& arrayData) const;
void computeCorrectBindingsAndArraySizes(ArrayData& arrayData,const char* arrayName);
void computeCorrectBindingsAndArraySizes(Vec3ArrayData& arrayData,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;
};
/** Convenience function to be used for creating quad geometry with texture coords.
* Tex coords go from left bottom (l,b) to right top (r,t).
*/
extern OSG_EXPORT GeometryNew* createTexturedQuadGeometryNew(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float l, float b, float r, float t);
/** Convenience function to be used for creating quad geometry with texture coords.
* Tex coords go from bottom left (0,0) to top right (s,t).
*/
inline GeometryNew* createTexturedQuadGeometryNew(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float s=1.0f, float t=1.0f)
{
return createTexturedQuadGeometryNew(corner,widthVec,heightVec, 0.0f, 0.0f, s, t);
}
}
#endif

View File

@ -256,6 +256,7 @@ SET(TARGET_SRC
FrontFace.cpp FrontFace.cpp
Geode.cpp Geode.cpp
Geometry.cpp Geometry.cpp
GeometryNew.cpp
GL2Extensions.cpp GL2Extensions.cpp
GLExtensions.cpp GLExtensions.cpp
GLBeginEndAdapter.cpp GLBeginEndAdapter.cpp

1963
src/osg/GeometryNew.cpp Normal file

File diff suppressed because it is too large Load Diff