From 3700e7e2cdd6a60aaa235f4a71983e130bd4769d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 2 Jul 2002 19:53:18 +0000 Subject: [PATCH] Reimplemted the osgUtil::SceneView::setCalcNearFar() functionality to bring it inline with the CullStack/CullVisitor implementation. Also added the setSmallFeatureCullingPixelSize() method and wired them up inside SceneView.cpp so they set the corresponding CullVisitor paramters. Intergrated pfImage copying change in the Performer plugin, submission sent in by Ulrich Hertlein --- include/osg/CullStack | 12 ++--- include/osg/Math | 12 ++--- include/osgUtil/SceneView | 46 ++++++++++------ include/osgUtil/Tesselator | 10 ++-- src/Demos/osgtext/main.cpp | 2 +- src/osg/CullStack.cpp | 2 +- src/osg/Geode.cpp | 5 +- src/osgPlugins/pfb/ConvertFromPerformer.cpp | 59 +++++++++++++-------- src/osgUtil/SceneView.cpp | 15 +++--- 9 files changed, 97 insertions(+), 66 deletions(-) diff --git a/include/osg/CullStack b/include/osg/CullStack index 66697295c..76730122e 100644 --- a/include/osg/CullStack +++ b/include/osg/CullStack @@ -41,11 +41,6 @@ class SG_EXPORT CullStack typedef unsigned int CullingMode; - /** Sets the current CullingMode.*/ - void setCullingMode(CullingMode mode) { _cullingMode = mode; } - - /** Returns the current CullingMode.*/ - CullingMode getCullingMode() const { return _cullingMode; } void reset(); @@ -65,11 +60,16 @@ class SG_EXPORT CullStack inline float getFrustumVolume() { if (_frustumVolume<0.0f) computeFrustumVolume(); return _frustumVolume; } + /** Sets the current CullingMode.*/ + void setCullingMode(CullingMode mode) { _cullingMode = mode; } + + /** Returns the current CullingMode.*/ + CullingMode getCullingMode() const { return _cullingMode; } + void setLODBias(const float bias) { _LODBias = bias; } const float getLODBias() const { return _LODBias; } void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; } - float& getSmallFeatureCullingPixelSize() { return _smallFeatureCullingPixelSize; } float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; } diff --git a/include/osg/Math b/include/osg/Math index 26e58d6fb..cddad214d 100644 --- a/include/osg/Math +++ b/include/osg/Math @@ -88,17 +88,17 @@ inline T square(T v) { return v*v; } template inline T signedSquare(T v) { return v<(T)0?-v*v:v*v;; } -template -inline T inDegrees(T angle) { return angle*(T)PI/(T)180.0; } +inline float inDegrees(float angle) { return angle*(float)PI/180.0f; } +inline double inDegrees(double angle) { return angle*PI/180.0; } template inline T inRadians(T angle) { return angle; } -template -inline T DegreesToRadians(T angle) { return angle*(T)PI/(T)180.0; } +inline float DegreesToRadians(float angle) { return angle*(float)PI/180.0f; } +inline double DegreesToRadians(double angle) { return angle*PI/180.0; } -template -inline T RadiansToDegrees(T angle) { return angle*(T)180.0/(T)PI; } +inline float RadiansToDegrees(float angle) { return angle*180.0f/(float)PI; } +inline double RadiansToDegrees(double angle) { return angle*180.0/PI; } #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MWERKS__) inline bool isNaN(float v) { return _isnan(v)!=0; } diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index feef49875..9b5ce4b0d 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -156,9 +156,6 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced osgUtil::RenderStage* getRenderStage() { return _renderStage.get(); } const osgUtil::RenderStage* getRenderStage() const { return _renderStage.get(); } - void setLODBias(float bias) { _lodBias = bias; } - float getLODBias() const { return _lodBias; } - void setCullMask(const osg::Node::NodeMask nm) { _cullMask = nm; } const osg::Node::NodeMask getCullMask() const { return _cullMask; } @@ -169,16 +166,31 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced void setCullMaskRight(const osg::Node::NodeMask nm) { _cullMaskRight = nm; } const osg::Node::NodeMask getCullMaskRight() const { return _cullMaskRight; } + /** Set the LOD bias for the CullVisitor to use.*/ + void setLODBias(float bias) { _LODBias = bias; } + + /** Get the LOD bias.*/ + float getLODBias() const { return _LODBias; } + + /** Set the Small Feature Culling Pixel Size.*/ + void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; } + + /** Get the Small Feature Culling Pixel Size.*/ + float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; } + + /** Set the culling mode for the CullVisitor to use.*/ + void setCullingMode(osg::CullStack::CullingMode mode) { _cullingMode = mode; } + + /** Returns the current CullingMode.*/ + osg::CullStack::CullingMode getCullingMode() const { return _cullingMode; } + + /** Set the ComputeNearFarMode for the CullVisitor to use.*/ + void setComputeNearFarMode(CullVisitor::ComputeNearFarMode cnfm) { _computeNearFar=cnfm; } + + /** Get the ComputeNearFarMode.*/ + CullVisitor::ComputeNearFarMode getComputeNearFarMode() const { return _computeNearFar;} + - /** Set to true if you want SceneView to automatically calculate values - for the near/far clipping planes, each frame, set false to use camera's - internal near and far planes. Default value is true. - */ - void setCalcNearFar(bool calc) { _calc_nearfar = calc; } - /** return true if SceneView automatically calculates near and - far clipping planes for each frame. - */ - bool getCalcNearFar() const { return _calc_nearfar; } /** set whether the draw method should call renderer->prioritizeTexture.*/ void setPrioritizeTextures(bool pt) { _prioritizeTextures = pt; } @@ -283,14 +295,14 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced osg::ref_ptr _frameStamp; bool _need_compile; - bool _calc_nearfar; + osg::Vec4 _backgroundColor; - double _near_plane; - double _far_plane; - - float _lodBias; + CullVisitor::ComputeNearFarMode _computeNearFar; + osg::CullStack::CullingMode _cullingMode; + float _LODBias; + float _smallFeatureCullingPixelSize; osg::ref_ptr _viewport; diff --git a/include/osgUtil/Tesselator b/include/osgUtil/Tesselator index c92fd0f23..221a57781 100644 --- a/include/osgUtil/Tesselator +++ b/include/osgUtil/Tesselator @@ -75,13 +75,13 @@ class OSGUTIL_EXPORT Tesselator void error(GLenum errorCode); - static void beginCallback(GLenum which, void* userData); - static void vertexCallback(GLvoid *data, void* userData); - static void combineCallback(GLdouble coords[3], void* vertex_data[4], + static void CALLBACK beginCallback(GLenum which, void* userData); + static void CALLBACK vertexCallback(GLvoid *data, void* userData); + static void CALLBACK combineCallback(GLdouble coords[3], void* vertex_data[4], GLfloat weight[4], void** outData, void* useData); - static void endCallback(void* userData); - static void errorCallback(GLenum errorCode, void* userData); + static void CALLBACK endCallback(void* userData); + static void CALLBACK errorCallback(GLenum errorCode, void* userData); struct Vec3d diff --git a/src/Demos/osgtext/main.cpp b/src/Demos/osgtext/main.cpp index 4ff98fb51..43e444922 100644 --- a/src/Demos/osgtext/main.cpp +++ b/src/Demos/osgtext/main.cpp @@ -463,7 +463,7 @@ public: { _hudSceneView->getRenderStage()->setClearMask(0); _hudSceneView->getCullVisitor()->setCullingMode(osgUtil::CullVisitor::NO_CULLING); - _hudSceneView->setCalcNearFar(false); + _hudSceneView->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR); _hudCam = osgNew osg::Camera; diff --git a/src/osg/CullStack.cpp b/src/osg/CullStack.cpp index 4b66fe6ef..e4c465f2c 100644 --- a/src/osg/CullStack.cpp +++ b/src/osg/CullStack.cpp @@ -7,7 +7,7 @@ CullStack::CullStack() _cullingMode = ENABLE_ALL_CULLING; _LODBias = 1.0f; - _smallFeatureCullingPixelSize = 3.0f; + _smallFeatureCullingPixelSize = 2.0f; _frustumVolume=-1.0f; } diff --git a/src/osg/Geode.cpp b/src/osg/Geode.cpp index 74492bb21..6ebd557e5 100644 --- a/src/osg/Geode.cpp +++ b/src/osg/Geode.cpp @@ -99,9 +99,9 @@ const bool Geode::replaceDrawable( Drawable *origDrawable, Drawable *newDrawable const bool Geode::computeBound() const { - BoundingBox bb; + _bsphere.init(); -// if (_occluder.valid()) _occluder->computeBound(bb); + BoundingBox bb; DrawableList::const_iterator itr; for(itr=_drawables.begin(); @@ -119,7 +119,6 @@ const bool Geode::computeBound() const } else { - _bsphere.init(); _bsphere_computed=true; return false; } diff --git a/src/osgPlugins/pfb/ConvertFromPerformer.cpp b/src/osgPlugins/pfb/ConvertFromPerformer.cpp index 4f1ee7978..451bd0a54 100644 --- a/src/osgPlugins/pfb/ConvertFromPerformer.cpp +++ b/src/osgPlugins/pfb/ConvertFromPerformer.cpp @@ -1121,8 +1121,15 @@ osg::Texture* ConvertFromPerformer::visitTexture(osg::StateSet* osgStateSet,pfTe { if (tex==NULL) return NULL; - osg::Texture* osgTexture = new osg::Texture; - _pfToOsgMap[tex] = osgTexture; + osg::Texture* osgTexture = dynamic_cast(getOsgObject(tex)); + if (osgTexture) { + if (osgStateSet) osgStateSet->setAttribute(osgTexture); + return osgTexture; + } + + osgTexture = new osg::Texture; + registerPfObjectForOsgObject(tex, osgTexture); + //_pfToOsgMap[tex] = osgTexture; if (osgStateSet) osgStateSet->setAttribute(osgTexture); @@ -1130,24 +1137,30 @@ osg::Texture* ConvertFromPerformer::visitTexture(osg::StateSet* osgStateSet,pfTe int repeat_s = tex->getRepeat(PFTEX_WRAP_S); int repeat_t = tex->getRepeat(PFTEX_WRAP_T); - if (repeat_r==PFTEX_CLAMP) osgTexture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP); - else osgTexture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT); + if (repeat_r==PFTEX_CLAMP) + osgTexture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP); + else + osgTexture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT); - if (repeat_s==PFTEX_CLAMP) osgTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP); - else osgTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT); + if (repeat_s==PFTEX_CLAMP) + osgTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP); + else + osgTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT); - if (repeat_t==PFTEX_CLAMP) osgTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP); - else osgTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT); + if (repeat_t==PFTEX_CLAMP) + osgTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP); + else + osgTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT); // filter - #if 1 +#if 1 osgTexture->setFilter(osg::Texture::MIN_FILTER, - getTexfilter(PFTEX_MINFILTER, - tex->getFilter(PFTEX_MINFILTER))); + getTexfilter(PFTEX_MINFILTER, + tex->getFilter(PFTEX_MINFILTER))); osgTexture->setFilter(osg::Texture::MAG_FILTER, - getTexfilter(PFTEX_MAGFILTER, - tex->getFilter(PFTEX_MAGFILTER))); - #endif + getTexfilter(PFTEX_MAGFILTER, + tex->getFilter(PFTEX_MAGFILTER))); +#endif // image std::string texName = tex->getName(); @@ -1173,19 +1186,23 @@ osg::Texture* ConvertFromPerformer::visitTexture(osg::StateSet* osgStateSet,pfTe unsigned int pixelFormat = comp == 1 ? GL_LUMINANCE : - comp == 2 ? GL_LUMINANCE_ALPHA : - comp == 3 ? GL_RGB : - comp == 4 ? GL_RGBA : (GLenum)-1; + comp == 2 ? GL_LUMINANCE_ALPHA : + comp == 3 ? GL_RGB : + comp == 4 ? GL_RGBA : (GLenum)-1; unsigned int dataType = GL_UNSIGNED_BYTE; + // copy image data + int size = s * t * comp; + unsigned char* data = (unsigned char*) malloc(size); + memcpy(data, imageData, size); + osg::Image* image = new osg::Image; image->setFileName(texName.c_str()); image->setImage(s,t,r, - internalFormat, - pixelFormat, - dataType, - (unsigned char*)imageData); + internalFormat, + pixelFormat, + dataType,data); osgTexture->setImage(image); diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index b5e00a2c8..494ba6130 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -19,14 +19,13 @@ SceneView::SceneView(DisplaySettings* ds) { _displaySettings = ds; - _calc_nearfar = true; - _backgroundColor.set(0.2f, 0.2f, 0.4f, 1.0f); - _near_plane = 1.0f; - _far_plane = 1.0f; + _computeNearFar = CullVisitor::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES; - _lodBias = 1.0f; + _cullingMode = osg::CullStack::ENABLE_ALL_CULLING; + _LODBias = 1.0f; + _smallFeatureCullingPixelSize = 2.0f; _lightingMode=HEADLIGHT; @@ -315,6 +314,7 @@ void SceneView::cullStage(osg::Matrix* projection,osg::Matrix* modelview,osgUtil if (!_initCalled) init(); + // collect any occluder in the view frustum. if (_sceneData->containsOccluderNodes()) { @@ -363,7 +363,10 @@ void SceneView::cullStage(osg::Matrix* projection,osg::Matrix* modelview,osgUtil cullVisitor->setTraversalNumber(_frameStamp->getFrameNumber()); } - cullVisitor->setLODBias(_lodBias); + cullVisitor->setComputeNearFarMode(_computeNearFar); + cullVisitor->setLODBias(_LODBias); + cullVisitor->setSmallFeatureCullingPixelSize(_smallFeatureCullingPixelSize); + cullVisitor->setEarthSky(NULL); // reset earth sky on each frame. cullVisitor->setRenderGraph(rendergraph);