Prep work on new TerrainGeometry Drawable which supports selective display list/VBO's usage.

Updated wrappers
This commit is contained in:
Robert Osfield
2007-04-11 17:39:13 +00:00
parent 17054afc8f
commit 73f980bd49
4 changed files with 335 additions and 54 deletions

View File

@@ -43,9 +43,76 @@ class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique
protected:
virtual ~GeometryTechnique();
osg::ref_ptr<osg::Geode> _geode;
osg::ref_ptr<osg::Geometry> _geometry;
//osg::ref_ptr<TerrainGeometry> _geometry;
};
class OSGTERRAIN_EXPORT TerrainGeometry : public osg::Drawable
{
public:
TerrainGeometry();
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
TerrainGeometry(const TerrainGeometry& geometry,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
virtual osg::Object* cloneType() const { return new TerrainGeometry(); }
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new TerrainGeometry(*this,copyop); }
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const TerrainGeometry*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osgTerrain"; }
virtual const char* className() const { return "TerrainGeometry"; }
void setVertices(osg::Vec3Array* vertices) { _vertices.first = vertices; }
osg::Vec3Array* getVertices() { return _vertices.first.get(); }
const osg::Vec3Array* getVertices() const { return _vertices.first.get(); }
void setNormals(osg::Vec3Array* normals) { _normals.first = normals; }
osg::Vec3Array* getNormals() { return _normals.first.get(); }
const osg::Vec3Array* getNormals() const { return _normals.first.get(); }
void setColors(osg::Vec4Array* colors) { _colors.first = colors; }
osg::Vec4Array* getColors() { return _colors.first.get(); }
const osg::Vec4Array* getColors() const { return _colors.first.get(); }
void setTexCoords(unsigned int unit, osg::Array* array) { _texcoords.resize(unit+1); _texcoords[unit].first = array; }
osg::Array* getTexCoords(unsigned int unit) { return _texcoords[unit].first.get(); }
const osg::Array* getTexCoords(unsigned int unit) const { return _texcoords[unit].first.get(); }
void addPrimitiveSet(osg::PrimitiveSet* primitiveSet) { _primitiveSets.push_back(primitiveSet); }
osg::PrimitiveSet* getPrimtitiveSet(unsigned int i) { return _primitiveSets[i].get(); }
const osg::PrimitiveSet* getPrimtitiveSet(unsigned int i) const { return _primitiveSets[i].get(); }
unsigned int getNumPrimitiveSets() const { return _primitiveSets.size(); }
virtual osg::BoundingBox computeBound() 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(osg::RenderInfo& renderInfo) const;
protected:
typedef osg::Geometry::PrimitiveSetList PrimitiveSetList;
typedef std::pair< osg::ref_ptr<osg::Array>, GLvoid*> ArrayData;
typedef std::pair< osg::ref_ptr<osg::FloatArray>, GLvoid*> FloatArrayData;
typedef std::pair< osg::ref_ptr<osg::Vec2Array>, GLvoid*> Vec2ArrayData;
typedef std::pair< osg::ref_ptr<osg::Vec3Array>, GLvoid*> Vec3ArrayData;
typedef std::pair< osg::ref_ptr<osg::Vec4Array>, GLvoid*> Vec4ArrayData;
typedef std::vector< ArrayData > TexCoordsList;
Vec3ArrayData _vertices;
Vec3ArrayData _normals;
Vec4ArrayData _colors;
TexCoordsList _texcoords;
PrimitiveSetList _primitiveSets;
};

View File

@@ -110,6 +110,7 @@ void GeometryTechnique::init()
_geode = new osg::Geode;
_geometry = new osg::Geometry;
_geode->addDrawable(_geometry.get());
_geode->addDrawable(new osgTerrain::TerrainGeometry);
unsigned int numRows = 100;
unsigned int numColumns = 100;
@@ -124,12 +125,12 @@ void GeometryTechnique::init()
unsigned int numVertices = numRows * numColumns;
// allocate and assign vertices
osg::Vec3Array* vertices = new osg::Vec3Array(numVertices);
_geometry->setVertexArray(vertices);
osg::Vec3Array* _vertices = new osg::Vec3Array(numVertices);
_geometry->setVertexArray(_vertices);
// allocate and assign normals
osg::Vec3Array* normals = new osg::Vec3Array(numVertices);
_geometry->setNormalArray(normals);
osg::Vec3Array* _normals = new osg::Vec3Array(numVertices);
_geometry->setNormalArray(_normals);
_geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
@@ -141,17 +142,17 @@ void GeometryTechnique::init()
float scaleHeight = 1.0;
// allocate and assign tex coords
osg::Vec2Array* texcoords = 0;
osg::Vec2Array* _texcoords = 0;
if (colorLayer)
{
color_index = texcoord_index;
++texcoord_index;
texcoords = new osg::Vec2Array(numVertices);
_geometry->setTexCoordArray(color_index, texcoords);
_texcoords = new osg::Vec2Array(numVertices);
_geometry->setTexCoordArray(color_index, _texcoords);
}
osg::FloatArray* heights = 0;
osg::FloatArray* _elevations = 0;
osg::TransferFunction1D* tf = dynamic_cast<osg::TransferFunction1D*>(colorTF);
if (tf)
{
@@ -160,8 +161,8 @@ void GeometryTechnique::init()
if (!colorLayer)
{
heights = new osg::FloatArray(numVertices);
_geometry->setTexCoordArray(tf_index, heights);
_elevations = new osg::FloatArray(numVertices);
_geometry->setTexCoordArray(tf_index, _elevations);
minHeight = tf->getMinimum();
scaleHeight = 1.0f/(tf->getMaximum()-tf->getMinimum());
@@ -170,10 +171,10 @@ void GeometryTechnique::init()
// allocate and assign color
osg::Vec4Array* colors = new osg::Vec4Array(1);
_geometry->setColorArray(colors);
osg::Vec4Array* _colors = new osg::Vec4Array(1);
_geometry->setColorArray(_colors);
_geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
(*_colors)[0].set(1.0f,1.0f,1.0f,1.0f);
// populate vertex and tex coord arrays
unsigned int j;
@@ -195,7 +196,7 @@ void GeometryTechnique::init()
osg::Vec3d model;
masterLocator->convertLocalToModel(ndc, model);
(*vertices)[iv] = model;
(*_vertices)[iv] = model;
if (colorLayer)
{
@@ -203,18 +204,18 @@ void GeometryTechnique::init()
{
osg::Vec3d color_ndc;
Locator::convertLocalCoordBetween(*masterLocator, ndc, *colorLocator, color_ndc);
(*texcoords)[iv].set(color_ndc.x(), color_ndc.y());
(*_texcoords)[iv].set(color_ndc.x(), color_ndc.y());
}
else
{
(*texcoords)[iv].set(ndc.x(), ndc.y());
(*_texcoords)[iv].set(ndc.x(), ndc.y());
}
}
if (heights)
if (_elevations)
{
(*heights)[iv] = (ndc.z()-minHeight)*scaleHeight;
(*_elevations)[iv] = (ndc.z()-minHeight)*scaleHeight;
}
// compute the local normal
@@ -223,11 +224,12 @@ void GeometryTechnique::init()
masterLocator->convertLocalToModel(ndc_one, model_one);
model_one -= model;
model_one.normalize();
(*normals)[iv] = model_one;
(*_normals)[iv] = model_one;
}
}
// populate primitive sets
// _primitiveSets.clear();
for(j=0; j<numRows-1; ++j)
{
osg::DrawElementsUInt* elements = new osg::DrawElementsUInt(GL_TRIANGLE_STRIP, numColumns*2);
@@ -237,6 +239,9 @@ void GeometryTechnique::init()
(*elements)[i*2] = iv + numColumns;
(*elements)[i*2+1] = iv;
}
//_primitiveSets.push_back(elements);
_geometry->addPrimitiveSet(elements);
}
@@ -354,3 +359,45 @@ void GeometryTechnique::dirty()
{
TerrainTechnique::dirty();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TerrainGeometry
//
TerrainGeometry::TerrainGeometry()
{
}
TerrainGeometry::TerrainGeometry(const TerrainGeometry& geometry,const osg::CopyOp& copyop):
osg::Drawable(geometry, copyop),
_vertices(geometry._vertices),
_normals(geometry._normals),
_colors(geometry._colors),
_texcoords(geometry._texcoords),
_primitiveSets(geometry._primitiveSets)
{
}
osg::BoundingBox TerrainGeometry::computeBound() const
{
osg::BoundingBox bb;
if (_vertices.first.valid())
{
for(osg::Vec3Array::const_iterator itr = _vertices.first->begin();
itr != _vertices.first->end();
++itr)
{
bb.expandBy(*itr);
}
}
return bb;
}
void TerrainGeometry::drawImplementation(osg::RenderInfo& renderInfo) const
{
osg::notify(osg::NOTICE)<<"TerrainGeometry::drawImplementation"<<std::endl;
}

View File

@@ -10,7 +10,12 @@
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>
#include <osg/Array>
#include <osg/BoundingBox>
#include <osg/CopyOp>
#include <osg/Object>
#include <osg/PrimitiveSet>
#include <osg/RenderInfo>
#include <osgTerrain/GeometryTechnique>
#include <osgUtil/CullVisitor>
#include <osgUtil/UpdateVisitor>
@@ -59,3 +64,142 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::GeometryTechnique)
"");
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgTerrain::TerrainGeometry)
I_BaseType(osg::Drawable);
I_Constructor0(____TerrainGeometry,
"",
"");
I_ConstructorWithDefaults2(IN, const osgTerrain::TerrainGeometry &, geometry, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY,
____TerrainGeometry__C5_TerrainGeometry_R1__C5_osg_CopyOp_R1,
"Copy constructor using CopyOp to manage deep vs shallow copy. ",
"");
I_Method0(osg::Object *, cloneType,
Properties::VIRTUAL,
__osg_Object_P1__cloneType,
"Clone the type of an object, with Object* return type. ",
"Must be defined by derived classes. ");
I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop,
Properties::VIRTUAL,
__osg_Object_P1__clone__C5_osg_CopyOp_R1,
"Clone an object, with Object* return type. ",
"Must be defined by derived classes. ");
I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj,
Properties::VIRTUAL,
__bool__isSameKindAs__C5_osg_Object_P1,
"",
"");
I_Method0(const char *, libraryName,
Properties::VIRTUAL,
__C5_char_P1__libraryName,
"return the name of the object's library. ",
"Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. ");
I_Method0(const char *, className,
Properties::VIRTUAL,
__C5_char_P1__className,
"return the name of the object's class type. ",
"Must be defined by derived classes. ");
I_Method1(void, setVertices, IN, osg::Vec3Array *, vertices,
Properties::NON_VIRTUAL,
__void__setVertices__osg_Vec3Array_P1,
"",
"");
I_Method0(osg::Vec3Array *, getVertices,
Properties::NON_VIRTUAL,
__osg_Vec3Array_P1__getVertices,
"",
"");
I_Method0(const osg::Vec3Array *, getVertices,
Properties::NON_VIRTUAL,
__C5_osg_Vec3Array_P1__getVertices,
"",
"");
I_Method1(void, setNormals, IN, osg::Vec3Array *, normals,
Properties::NON_VIRTUAL,
__void__setNormals__osg_Vec3Array_P1,
"",
"");
I_Method0(osg::Vec3Array *, getNormals,
Properties::NON_VIRTUAL,
__osg_Vec3Array_P1__getNormals,
"",
"");
I_Method0(const osg::Vec3Array *, getNormals,
Properties::NON_VIRTUAL,
__C5_osg_Vec3Array_P1__getNormals,
"",
"");
I_Method1(void, setColors, IN, osg::Vec4Array *, colors,
Properties::NON_VIRTUAL,
__void__setColors__osg_Vec4Array_P1,
"",
"");
I_Method0(osg::Vec4Array *, getColors,
Properties::NON_VIRTUAL,
__osg_Vec4Array_P1__getColors,
"",
"");
I_Method0(const osg::Vec4Array *, getColors,
Properties::NON_VIRTUAL,
__C5_osg_Vec4Array_P1__getColors,
"",
"");
I_Method2(void, setTexCoords, IN, unsigned int, unit, IN, osg::Array *, array,
Properties::NON_VIRTUAL,
__void__setTexCoords__unsigned_int__osg_Array_P1,
"",
"");
I_Method1(osg::Array *, getTexCoords, IN, unsigned int, unit,
Properties::NON_VIRTUAL,
__osg_Array_P1__getTexCoords__unsigned_int,
"",
"");
I_Method1(const osg::Array *, getTexCoords, IN, unsigned int, unit,
Properties::NON_VIRTUAL,
__C5_osg_Array_P1__getTexCoords__unsigned_int,
"",
"");
I_Method1(void, addPrimitiveSet, IN, osg::PrimitiveSet *, primitiveSet,
Properties::NON_VIRTUAL,
__void__addPrimitiveSet__osg_PrimitiveSet_P1,
"",
"");
I_Method1(osg::PrimitiveSet *, getPrimtitiveSet, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__osg_PrimitiveSet_P1__getPrimtitiveSet__unsigned_int,
"",
"");
I_Method1(const osg::PrimitiveSet *, getPrimtitiveSet, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__C5_osg_PrimitiveSet_P1__getPrimtitiveSet__unsigned_int,
"",
"");
I_Method0(unsigned int, getNumPrimitiveSets,
Properties::NON_VIRTUAL,
__unsigned_int__getNumPrimitiveSets,
"",
"");
I_Method0(osg::BoundingBox, computeBound,
Properties::VIRTUAL,
__osg_BoundingBox__computeBound,
"Compute the bounding box around Drawables's geometry. ",
"");
I_Method1(void, drawImplementation, IN, osg::RenderInfo &, renderInfo,
Properties::VIRTUAL,
__void__drawImplementation__osg_RenderInfo_R1,
"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.");
I_SimpleProperty(osg::Vec4Array *, Colors,
__osg_Vec4Array_P1__getColors,
__void__setColors__osg_Vec4Array_P1);
I_SimpleProperty(osg::Vec3Array *, Normals,
__osg_Vec3Array_P1__getNormals,
__void__setNormals__osg_Vec3Array_P1);
I_IndexedProperty(osg::Array *, TexCoords,
__osg_Array_P1__getTexCoords__unsigned_int,
__void__setTexCoords__unsigned_int__osg_Array_P1,
0);
I_SimpleProperty(osg::Vec3Array *, Vertices,
__osg_Vec3Array_P1__getVertices,
__void__setVertices__osg_Vec3Array_P1);
END_REFLECTOR

View File

@@ -105,65 +105,88 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::TerrainNode)
I_Method1(void, setElevationLayer, IN, osgTerrain::Layer *, layer,
Properties::NON_VIRTUAL,
__void__setElevationLayer__Layer_P1,
"",
"Set the layer to use to define the elevations of the terrain. ",
"");
I_Method0(osgTerrain::Layer *, getElevationLayer,
Properties::NON_VIRTUAL,
__Layer_P1__getElevationLayer,
"",
"Get the layer to use to define the elevations of the terrain. ",
"");
I_Method0(const osgTerrain::Layer *, getElevationLayer,
Properties::NON_VIRTUAL,
__C5_Layer_P1__getElevationLayer,
"Get the const layer to use to define the elevations of the terrain. ",
"");
I_Method2(void, setColorLayer, IN, unsigned int, i, IN, osgTerrain::Layer *, layer,
Properties::NON_VIRTUAL,
__void__setColorLayer__unsigned_int__osgTerrain_Layer_P1,
"Set a color layer with specified layer number. ",
"");
I_Method1(osgTerrain::Layer *, getColorLayer, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__Layer_P1__getColorLayer__unsigned_int,
"Get color layer with specified layer number. ",
"");
I_Method1(const osgTerrain::Layer *, getColorLayer, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__C5_Layer_P1__getColorLayer__unsigned_int,
"Set const color layer with specified layer number. ",
"");
I_Method2(void, setColorTransferFunction, IN, unsigned int, i, IN, osg::TransferFunction *, tf,
Properties::NON_VIRTUAL,
__void__setColorTransferFunction__unsigned_int__osg_TransferFunction_P1,
"Set a color transfer function with specified layer number. ",
"");
I_Method1(osg::TransferFunction *, getColorTransferFunction, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__osg_TransferFunction_P1__getColorTransferFunction__unsigned_int,
"Get color transfer function with specified layer number. ",
"");
I_Method1(const osg::TransferFunction *, getColorTransferFunction, IN, unsigned int, i,
Properties::NON_VIRTUAL,
__C5_osg_TransferFunction_P1__getColorTransferFunction__unsigned_int,
"Get const color transfer function with specified layer number. ",
"");
I_Method0(unsigned int, getNumColorLayers,
Properties::NON_VIRTUAL,
__unsigned_int__getNumColorLayers,
"",
"");
I_Method1(void, setColorLayer, IN, osgTerrain::Layer *, layer,
I_Method1(void, setRequiresNormals, IN, bool, flag,
Properties::NON_VIRTUAL,
__void__setColorLayer__osgTerrain_Layer_P1,
"",
__void__setRequiresNormals__bool,
"Set whether the TerrainTechnique should create per vertex normals for lighting purposes. ",
"");
I_Method0(osgTerrain::Layer *, getColorLayer,
I_Method0(bool, getRequiresNormals,
Properties::NON_VIRTUAL,
__Layer_P1__getColorLayer,
"",
"");
I_Method0(const osgTerrain::Layer *, getColorLayer,
Properties::NON_VIRTUAL,
__C5_Layer_P1__getColorLayer,
"",
"");
I_Method1(void, setColorTransferFunction, IN, osg::TransferFunction *, tf,
Properties::NON_VIRTUAL,
__void__setColorTransferFunction__osg_TransferFunction_P1,
"",
"");
I_Method0(osg::TransferFunction *, getColorTransferFunction,
Properties::NON_VIRTUAL,
__osg_TransferFunction_P1__getColorTransferFunction,
"",
"");
I_Method0(const osg::TransferFunction *, getColorTransferFunction,
Properties::NON_VIRTUAL,
__C5_osg_TransferFunction_P1__getColorTransferFunction,
"",
__bool__getRequiresNormals,
"Get whether the TerrainTechnique should create per vertex normals for lighting purposes. ",
"");
I_Method0(osg::BoundingSphere, computeBound,
Properties::VIRTUAL,
__osg_BoundingSphere__computeBound,
"Compute the bounding volume of the terrain by computing the union of the bounding volumes of all layers. ",
"");
I_SimpleProperty(osgTerrain::Layer *, ColorLayer,
__Layer_P1__getColorLayer,
__void__setColorLayer__osgTerrain_Layer_P1);
I_SimpleProperty(osg::TransferFunction *, ColorTransferFunction,
__osg_TransferFunction_P1__getColorTransferFunction,
__void__setColorTransferFunction__osg_TransferFunction_P1);
I_ArrayProperty(osgTerrain::Layer *, ColorLayer,
__Layer_P1__getColorLayer__unsigned_int,
__void__setColorLayer__unsigned_int__osgTerrain_Layer_P1,
__unsigned_int__getNumColorLayers,
0,
0,
0);
I_IndexedProperty(osg::TransferFunction *, ColorTransferFunction,
__osg_TransferFunction_P1__getColorTransferFunction__unsigned_int,
__void__setColorTransferFunction__unsigned_int__osg_TransferFunction_P1,
0);
I_SimpleProperty(osgTerrain::Layer *, ElevationLayer,
__Layer_P1__getElevationLayer,
__void__setElevationLayer__Layer_P1);
I_SimpleProperty(osgTerrain::Locator *, Locator,
__Locator_P1__getLocator,
__void__setLocator__Locator_P1);
I_SimpleProperty(bool, RequiresNormals,
__bool__getRequiresNormals,
__void__setRequiresNormals__bool);
I_SimpleProperty(osgTerrain::TerrainTechnique *, TerrainTechnique,
__TerrainTechnique_P1__getTerrainTechnique,
__void__setTerrainTechnique__osgTerrain_TerrainTechnique_P1);