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
This commit is contained in:
Robert Osfield
2002-07-02 19:53:18 +00:00
parent 88a62173d2
commit 3700e7e2cd
9 changed files with 97 additions and 66 deletions

View File

@@ -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; }

View File

@@ -88,17 +88,17 @@ inline T square(T v) { return v*v; }
template<typename T>
inline T signedSquare(T v) { return v<(T)0?-v*v:v*v;; }
template<typename T>
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<typename T>
inline T inRadians(T angle) { return angle; }
template<typename T>
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<typename T>
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; }

View File

@@ -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<osg::FrameStamp> _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<osg::Viewport> _viewport;

View File

@@ -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

View File

@@ -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;

View File

@@ -7,7 +7,7 @@ CullStack::CullStack()
_cullingMode = ENABLE_ALL_CULLING;
_LODBias = 1.0f;
_smallFeatureCullingPixelSize = 3.0f;
_smallFeatureCullingPixelSize = 2.0f;
_frustumVolume=-1.0f;
}

View File

@@ -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;
}

View File

@@ -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<osg::Texture*>(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);

View File

@@ -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);