Added SceneView::Options for SceneView::setDefaults(options) and
OsgCameraGroup::setRealizeSceneViewOptions(options) to allow better control of what functionality is compiled in by default.
This commit is contained in:
@@ -116,10 +116,15 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
|
||||
|
||||
float getLODScale() const { return _LODScale; }
|
||||
|
||||
|
||||
void setFusionDistance( osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f);
|
||||
|
||||
|
||||
/** Set the options to set up SceneView with, see osgUtil::SceneView::Options for available options.*/
|
||||
void setRealizeSceneViewOptions(unsigned int options) { _realizeSceneViewOptions = options; }
|
||||
|
||||
unsigned int getRealizeSceneViewOptions() { return _realizeSceneViewOptions; }
|
||||
|
||||
|
||||
/** RealizeCallback class one should override to provide an the implemention of realize callbacks.
|
||||
* Note, this callback overrides the normal call to OsgSceneHandler::init() so it become the your
|
||||
* responisibility to call this within your callback if required, it is a safe assumption to
|
||||
@@ -184,6 +189,8 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
|
||||
|
||||
osgUtil::SceneView::FusionDistanceMode _fusionDistanceMode;
|
||||
float _fusionDistanceValue;
|
||||
|
||||
unsigned int _realizeSceneViewOptions;
|
||||
|
||||
SceneHandlerList _shvec;
|
||||
|
||||
|
||||
@@ -38,10 +38,20 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting
|
||||
/** Construct a default scene view.*/
|
||||
SceneView(osg::DisplaySettings* ds=NULL);
|
||||
|
||||
enum Options
|
||||
{
|
||||
NO_SCENEVIEW_LIGHT = 0x0,
|
||||
HEADLIGHT = 0x1,
|
||||
SKY_LIGHT = 0x2,
|
||||
COMPILE_GLOBJECTS_AT_INIT = 0x4,
|
||||
STANDARD_SETTINGS = HEADLIGHT |
|
||||
COMPILE_GLOBJECTS_AT_INIT
|
||||
};
|
||||
|
||||
/** Set scene view to use default global state, light, camera
|
||||
* and render visitor.
|
||||
*/
|
||||
void setDefaults();
|
||||
void setDefaults(unsigned int options = STANDARD_SETTINGS);
|
||||
|
||||
/** Set the data which to view. The data will typically be
|
||||
* an osg::Scene but can be any osg::Node type.
|
||||
@@ -121,12 +131,15 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting
|
||||
osg::StateSet* getLocalStateSet() { return _localStateSet.get(); }
|
||||
const osg::StateSet* getLocalStateSet() const { return _localStateSet.get(); }
|
||||
|
||||
#if 1
|
||||
typedef Options LightingMode;
|
||||
#else
|
||||
enum LightingMode {
|
||||
HEADLIGHT, // default
|
||||
SKY_LIGHT,
|
||||
NO_SCENEVIEW_LIGHT
|
||||
};
|
||||
|
||||
#endif
|
||||
void setLightingMode(LightingMode mode) { _lightingMode=mode; }
|
||||
LightingMode getLightingMode() const { return _lightingMode; }
|
||||
|
||||
|
||||
@@ -133,6 +133,8 @@ void OsgCameraGroup::_init()
|
||||
|
||||
_fusionDistanceMode = osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE;
|
||||
_fusionDistanceValue = 1.0f;
|
||||
|
||||
_realizeSceneViewOptions = osgUtil::SceneView::STANDARD_SETTINGS;
|
||||
|
||||
_initialized = false;
|
||||
|
||||
@@ -342,8 +344,7 @@ bool OsgCameraGroup::realize()
|
||||
osgProducer::OsgSceneHandler *sh = new osgProducer::OsgSceneHandler(_ds.get());
|
||||
|
||||
osgUtil::SceneView* sv = sh->getSceneView();
|
||||
sv->setDefaults();
|
||||
//sv->setLight(0);
|
||||
sv->setDefaults(_realizeSceneViewOptions);
|
||||
|
||||
if (_renderSurfaceStateMap.count(rs)==0)
|
||||
{
|
||||
|
||||
@@ -60,42 +60,57 @@ SceneView::~SceneView()
|
||||
}
|
||||
|
||||
|
||||
void SceneView::setDefaults()
|
||||
void SceneView::setDefaults(unsigned int options)
|
||||
{
|
||||
// CullSettings::setDefaults();
|
||||
|
||||
_projectionMatrix.makePerspective(50.0f,1.4f,1.0f,10000.0f);
|
||||
_viewMatrix.makeIdentity();
|
||||
|
||||
_globalStateSet = new osg::StateSet;
|
||||
|
||||
_lightingMode=HEADLIGHT;
|
||||
_light = new osg::Light;
|
||||
_light->setLightNum(0);
|
||||
_light->setAmbient(Vec4(0.00f,0.0f,0.00f,1.0f));
|
||||
_light->setDiffuse(Vec4(0.8f,0.8f,0.8f,1.0f));
|
||||
_light->setSpecular(Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
if ((options & HEADLIGHT) || (options & SKY_LIGHT))
|
||||
{
|
||||
_lightingMode=(options&HEADLIGHT) ? HEADLIGHT : SKY_LIGHT;
|
||||
_light = new osg::Light;
|
||||
_light->setLightNum(0);
|
||||
_light->setAmbient(Vec4(0.00f,0.0f,0.00f,1.0f));
|
||||
_light->setDiffuse(Vec4(0.8f,0.8f,0.8f,1.0f));
|
||||
_light->setSpecular(Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
|
||||
_globalStateSet->setAssociatedModes(_light.get(),osg::StateAttribute::ON);
|
||||
|
||||
osg::LightModel* lightmodel = new osg::LightModel;
|
||||
lightmodel->setAmbientIntensity(osg::Vec4(0.1f,0.1f,0.1f,1.0f));
|
||||
_globalStateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON);
|
||||
|
||||
// enable lighting by default.
|
||||
_globalStateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
||||
|
||||
}
|
||||
|
||||
_state = new State;
|
||||
|
||||
_rendergraph = new RenderGraph;
|
||||
_renderStage = new RenderStage;
|
||||
|
||||
|
||||
GLObjectsVisitor::Mode dlvMode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;
|
||||
if (options & COMPILE_GLOBJECTS_AT_INIT)
|
||||
{
|
||||
GLObjectsVisitor::Mode dlvMode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;
|
||||
|
||||
#ifdef __sgi
|
||||
dlvMode = GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;
|
||||
#endif
|
||||
#ifdef __sgi
|
||||
dlvMode = GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;
|
||||
#endif
|
||||
|
||||
// sgi's IR graphics has a problem with lighting and display lists, as it seems to store
|
||||
// lighting state with the display list, and the display list visitor doesn't currently apply
|
||||
// state before creating display lists. So will disable the init visitor default, this won't
|
||||
// affect functionality since the display lists will be created as and when needed.
|
||||
GLObjectsVisitor* dlv = new GLObjectsVisitor(dlvMode);
|
||||
dlv->setNodeMaskOverride(0xffffffff);
|
||||
_initVisitor = dlv;
|
||||
// sgi's IR graphics has a problem with lighting and display lists, as it seems to store
|
||||
// lighting state with the display list, and the display list visitor doesn't currently apply
|
||||
// state before creating display lists. So will disable the init visitor default, this won't
|
||||
// affect functionality since the display lists will be created as and when needed.
|
||||
GLObjectsVisitor* dlv = new GLObjectsVisitor(dlvMode);
|
||||
dlv->setNodeMaskOverride(0xffffffff);
|
||||
_initVisitor = dlv;
|
||||
|
||||
}
|
||||
|
||||
_updateVisitor = new UpdateVisitor;
|
||||
|
||||
_cullVisitor = new CullVisitor;
|
||||
@@ -105,9 +120,6 @@ void SceneView::setDefaults()
|
||||
|
||||
_globalStateSet->setGlobalDefaults();
|
||||
|
||||
// enable lighting by default.
|
||||
_globalStateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
||||
_globalStateSet->setAssociatedModes(_light.get(),osg::StateAttribute::ON);
|
||||
|
||||
// enable depth testing by default.
|
||||
_globalStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
|
||||
@@ -122,9 +134,6 @@ void SceneView::setDefaults()
|
||||
texenv->setMode(osg::TexEnv::MODULATE);
|
||||
_globalStateSet->setTextureAttributeAndModes(0,texenv, osg::StateAttribute::ON);
|
||||
|
||||
osg::LightModel* lightmodel = new osg::LightModel;
|
||||
lightmodel->setAmbientIntensity(osg::Vec4(0.1f,0.1f,0.1f,1.0f));
|
||||
_globalStateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON);
|
||||
|
||||
_clearColor.set(0.2f, 0.2f, 0.4f, 1.0f);
|
||||
}
|
||||
@@ -552,7 +561,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
|
||||
if (_light.valid()) renderStage->addPositionedAttribute(mv.get(),_light.get());
|
||||
else osg::notify(osg::WARN)<<"Warning: no osg::Light attached to ogUtil::SceneView to provide sky light.*/"<<std::endl;
|
||||
break;
|
||||
case(NO_SCENEVIEW_LIGHT):
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user