Added the beginnings of a new osgforest example.

Added support into osg::TriangleFunctor for specifying whether the vertices
being generates are temporary or not.
This commit is contained in:
Robert Osfield
2003-09-25 21:54:33 +00:00
parent 16216b991f
commit 7fb9f6be4b
16 changed files with 750 additions and 69 deletions

View File

@@ -56,7 +56,7 @@ class SG_EXPORT BlendColor : public StateAttribute
modes.push_back(GL_BLEND);
}
void setConstantColor(osg::Vec4& color) { _constantColor = color; }
void setConstantColor(const osg::Vec4& color) { _constantColor = color; }
inline osg::Vec4 getConstantColor() const { return _constantColor; }
virtual void apply(State& state) const;

View File

@@ -91,7 +91,7 @@ class SG_EXPORT CullStack
/** Compute the pixel of an object at position v, with specified radius.*/
float pixelSize(const Vec3& v,float radius) const
{
return _modelviewCullingStack.back()->pixelSize(v,radius);
return getCurrentCullingSet().pixelSize(v,radius);
}
/** Compute the pixel of an bounding sphere.*/
@@ -102,56 +102,59 @@ class SG_EXPORT CullStack
inline void disableAndPushOccludersCurrentMask(NodePath& nodePath)
{
_modelviewCullingStack.back()->disableAndPushOccludersCurrentMask(nodePath);
getCurrentCullingSet().disableAndPushOccludersCurrentMask(nodePath);
}
inline void popOccludersCurrentMask(NodePath& nodePath)
{
_modelviewCullingStack.back()->popOccludersCurrentMask(nodePath);
getCurrentCullingSet().popOccludersCurrentMask(nodePath);
}
inline bool isCulled(const std::vector<Vec3>& vertices)
{
return _modelviewCullingStack.back()->isCulled(vertices);
return getCurrentCullingSet().isCulled(vertices);
}
inline bool isCulled(const BoundingBox& bb)
{
return bb.valid() && _modelviewCullingStack.back()->isCulled(bb);
return bb.valid() && getCurrentCullingSet().isCulled(bb);
}
inline bool isCulled(const BoundingSphere& bs)
{
return _modelviewCullingStack.back()->isCulled(bs);
return getCurrentCullingSet().isCulled(bs);
}
inline bool isCulled(const osg::Node& node)
{
return node.isCullingActive() && _modelviewCullingStack.back()->isCulled(node.getBound());
return node.isCullingActive() && getCurrentCullingSet().isCulled(node.getBound());
}
inline void pushCurrentMask()
{
_modelviewCullingStack.back()->pushCurrentMask();
getCurrentCullingSet().pushCurrentMask();
}
inline void popCurrentMask()
{
_modelviewCullingStack.back()->popCurrentMask();
getCurrentCullingSet().popCurrentMask();
}
typedef fast_back_stack<ref_ptr<CullingSet> > CullingStack;
CullingStack& getClipSpaceCullingStack() { return _clipspaceCullingStack; }
inline CullingStack& getClipSpaceCullingStack() { return _clipspaceCullingStack; }
CullingStack& getProjectionCullingStack() { return _projectionCullingStack; }
inline CullingStack& getProjectionCullingStack() { return _projectionCullingStack; }
CullingStack& getModelViewCullingStack() { return _modelviewCullingStack; }
inline CullingStack& getModelViewCullingStack() { return _modelviewCullingStack; }
CullingSet& getCurrentCullingSet() { return *_modelviewCullingStack.back(); }
// inline CullingSet& getCurrentCullingSet() { return _modelviewCullingStack.back(); }
// inline const CullingSet& getCurrentCullingSet() const { return _modelviewCullingStack.back(); }
inline CullingSet& getCurrentCullingSet() { return *_modelviewCullingStack.back(); }
inline const CullingSet& getCurrentCullingSet() const { return *_modelviewCullingStack.back(); }
inline osg::Viewport* getViewport();
inline osg::RefMatrix& getModelViewMatrix();
inline osg::RefMatrix& getProjectionMatrix();

View File

@@ -28,6 +28,17 @@ class SG_EXPORT CullingSet : public Referenced
CullingSet();
CullingSet(const CullingSet& cs):
Referenced(),
_mask(cs._mask),
_frustum(cs._frustum),
_occluderList(cs._occluderList),
_pixelSizeVector(cs._pixelSizeVector),
_smallFeatureCullingPixelSize(cs._smallFeatureCullingPixelSize)
{
}
CullingSet(const CullingSet& cs,const Matrix& matrix, const Vec4& pixelSizeVector):
_mask(cs._mask),
_frustum(cs._frustum),
@@ -44,6 +55,34 @@ class SG_EXPORT CullingSet : public Referenced
}
}
inline void set(const CullingSet& cs)
{
_mask = cs._mask;
_frustum = cs._frustum;
_occluderList = cs._occluderList;
_pixelSizeVector = cs._pixelSizeVector;
_smallFeatureCullingPixelSize = cs._smallFeatureCullingPixelSize;
}
inline void set(const CullingSet& cs,const Matrix& matrix, const Vec4& pixelSizeVector)
{
_mask = cs._mask;
_frustum = cs._frustum;
_occluderList = cs._occluderList;
_pixelSizeVector = pixelSizeVector;
_smallFeatureCullingPixelSize = cs._smallFeatureCullingPixelSize;
_frustum.transformProvidingInverse(matrix);
for(OccluderList::iterator itr=_occluderList.begin();
itr!=_occluderList.end();
++itr)
{
itr->transformProvidingInverse(matrix);
}
}
typedef std::vector<ShadowVolumeOccluder> OccluderList;
typedef unsigned int Mask;
@@ -218,9 +257,10 @@ class SG_EXPORT CullingSet : public Referenced
void popOccludersCurrentMask(NodePath& nodePath);
virtual ~CullingSet();
protected:
virtual ~CullingSet();
Mask _mask;
Polytope _frustum;

View File

@@ -29,9 +29,13 @@ public:
_vertexArraySize=0;
_vertexArrayPtr=0;
_modeCache=0;
_treatVertexDataAsTemporary=false;
}
virtual ~TriangleFunctor() {}
void setTreatVertexDataAsTemporary(bool treatVertexDataAsTemporary) { _treatVertexDataAsTemporary=treatVertexDataAsTemporary; }
bool getTreatVertexDataAsTemporary() const { return _treatVertexDataAsTemporary; }
virtual void setVertexArray(unsigned int,const Vec2*)
{
@@ -60,7 +64,7 @@ public:
{
const Vec3* vlast = &_vertexArrayPtr[first+count];
for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=3)
operator()(*(vptr),*(vptr+1),*(vptr+2));
operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary);
break;
}
case(GL_TRIANGLE_STRIP):
@@ -68,8 +72,8 @@ public:
const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=2;i<count;++i,++vptr)
{
if ((i%2)) operator()(*(vptr),*(vptr+2),*(vptr+1));
else operator()(*(vptr),*(vptr+1),*(vptr+2));
if ((i%2)) operator()(*(vptr),*(vptr+2),*(vptr+1),_treatVertexDataAsTemporary);
else operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary);
}
break;
}
@@ -78,8 +82,8 @@ public:
const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=3;i<count;i+=4,vptr+=4)
{
operator()(*(vptr),*(vptr+1),*(vptr+2));
operator()(*(vptr),*(vptr+2),*(vptr+3));
operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary);
operator()(*(vptr),*(vptr+2),*(vptr+3),_treatVertexDataAsTemporary);
}
break;
}
@@ -88,8 +92,8 @@ public:
const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=3;i<count;i+=2,vptr+=2)
{
operator()(*(vptr),*(vptr+1),*(vptr+2));
operator()(*(vptr+1),*(vptr+3),*(vptr+2));
operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary);
operator()(*(vptr+1),*(vptr+3),*(vptr+2),_treatVertexDataAsTemporary);
}
break;
}
@@ -100,7 +104,7 @@ public:
const Vec3* vptr = vfirst+1;
for(GLsizei i=2;i<count;++i,++vptr)
{
operator()(*(vfirst),*(vptr),*(vptr+1));
operator()(*(vfirst),*(vptr),*(vptr+1),_treatVertexDataAsTemporary);
}
break;
}
@@ -126,7 +130,7 @@ public:
{
IndexPointer ilast = &indices[count];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
break;
}
case(GL_TRIANGLE_STRIP):
@@ -134,8 +138,8 @@ public:
IndexPointer iptr = indices;
for(GLsizei i=2;i<count;++i,++iptr)
{
if ((i%2)) operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)]);
else operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
if ((i%2)) operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary);
else operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
}
break;
}
@@ -144,8 +148,8 @@ public:
IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=4,iptr+=4)
{
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],_treatVertexDataAsTemporary);
}
break;
}
@@ -154,8 +158,8 @@ public:
IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=2,iptr+=2)
{
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
}
break;
}
@@ -167,7 +171,7 @@ public:
++iptr;
for(GLsizei i=2;i<count;++i,++iptr)
{
operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)]);
operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary);
}
break;
}
@@ -194,7 +198,7 @@ public:
IndexPointer ilast = &indices[count];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
{
operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
}
break;
}
@@ -203,8 +207,8 @@ public:
IndexPointer iptr = indices;
for(GLsizei i=2;i<count;++i,++iptr)
{
if ((i%2)) operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)]);
else operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
if ((i%2)) operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary);
else operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
}
break;
}
@@ -213,8 +217,8 @@ public:
IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=4,iptr+=4)
{
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],_treatVertexDataAsTemporary);
}
break;
}
@@ -223,8 +227,8 @@ public:
IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=2,iptr+=2)
{
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
}
break;
}
@@ -236,7 +240,7 @@ public:
++iptr;
for(GLsizei i=2;i<count;++i,++iptr)
{
operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)]);
operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary);
}
break;
}
@@ -262,7 +266,7 @@ public:
{
IndexPointer ilast = &indices[count];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
break;
}
case(GL_TRIANGLE_STRIP):
@@ -270,8 +274,8 @@ public:
IndexPointer iptr = indices;
for(GLsizei i=2;i<count;++i,++iptr)
{
if ((i%2)) operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)]);
else operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
if ((i%2)) operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary);
else operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
}
break;
}
@@ -280,8 +284,8 @@ public:
IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=4,iptr+=4)
{
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],_treatVertexDataAsTemporary);
}
break;
}
@@ -290,8 +294,8 @@ public:
IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=2,iptr+=2)
{
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)]);
operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary);
}
break;
}
@@ -303,7 +307,7 @@ public:
++iptr;
for(GLsizei i=2;i<count;++i,++iptr)
{
operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)]);
operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary);
}
break;
}
@@ -340,6 +344,7 @@ public:
if (!_vertexCache.empty())
{
setVertexArray(_vertexCache.size(),&_vertexCache.front());
_treatVertexDataAsTemporary = true;
drawArrays(_modeCache,0,_vertexCache.size());
}
}
@@ -352,7 +357,7 @@ protected:
GLenum _modeCache;
std::vector<Vec3> _vertexCache;
bool _treatVertexDataAsTemporary;
};