Changed OsgCameraGroup so that it shares osg::State between Producer::Camera's which
share the same Producer::RenderSurface. Added support for more colors in slideshow3D's constructor code.
This commit is contained in:
parent
5ca7659cda
commit
f5b4f7ace0
@ -15,6 +15,9 @@
|
||||
|
||||
static Producer::CameraConfig *BuildConfig(void)
|
||||
{
|
||||
#define TWO_SEPERATE_WINDOWS
|
||||
|
||||
#ifdef TWO_SEPERATE_WINDOWS
|
||||
Producer::RenderSurface *rs1 = new Producer::RenderSurface;
|
||||
rs1->setScreenNum(0);
|
||||
rs1->setWindowName("osgwindows");
|
||||
@ -45,6 +48,32 @@ static Producer::CameraConfig *BuildConfig(void)
|
||||
cfg->addCamera("Camera 2", camera2);
|
||||
cfg->setInputArea(ia);
|
||||
return cfg;
|
||||
|
||||
#else
|
||||
// one window with four camera's.
|
||||
Producer::Camera* pcam1 = new Producer::Camera ();
|
||||
pcam1->setProjectionRectangle (0.0f, 0.5f, 0.5f, 1.0f);
|
||||
|
||||
Producer::Camera* pcam2 = new Producer::Camera ();
|
||||
pcam2->setRenderSurface (pcam1->getRenderSurface ());
|
||||
pcam2->setProjectionRectangle (0.5f, 1.0f, 0.5f, 1.0f);
|
||||
|
||||
Producer::Camera* pcam3 = new Producer::Camera ();
|
||||
pcam3->setRenderSurface (pcam1->getRenderSurface ());
|
||||
pcam3->setProjectionRectangle (0.0f, 0.5f, 0.0f, 0.5f);
|
||||
|
||||
Producer::Camera* pcam4 = new Producer::Camera ();
|
||||
pcam4->setRenderSurface (pcam1->getRenderSurface ());
|
||||
pcam4->setProjectionRectangle (0.5f, 1.0f, 0.0f, 0.5f);
|
||||
|
||||
Producer::CameraConfig *cfg = new Producer::CameraConfig;
|
||||
cfg->addCamera("Camera 1",pcam1);
|
||||
cfg->addCamera("Camera 2",pcam2);
|
||||
cfg->addCamera("Camera 3",pcam3);
|
||||
cfg->addCamera("Camera 4",pcam4);
|
||||
|
||||
return cfg;
|
||||
#endif
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
|
@ -17,7 +17,17 @@
|
||||
class ReaderWriterSS3D : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
ReaderWriterSS3D() { }
|
||||
ReaderWriterSS3D()
|
||||
{
|
||||
_colorMap["WHITE"] .set(1.0f,1.0f,1.0f,1.0f);
|
||||
_colorMap["BLACK"] .set(0.0f,0.0f,0.0f,1.0f);
|
||||
_colorMap["PURPLE"] .set(1.0f,0.0f,1.0f,1.0f);
|
||||
_colorMap["BLUE"] .set(0.0f,0.0f,1.0f,1.0f);
|
||||
_colorMap["RED"] .set(1.0f,0.0f,0.0f,1.0f);
|
||||
_colorMap["CYAN"] .set(0.0f,1.0f,1.0f,1.0f);
|
||||
_colorMap["YELLOW"] .set(1.0f,1.0f,0.0f,1.0f);
|
||||
_colorMap["GREEN"] .set(0.0f,1.0f,0.0f,1.0f);
|
||||
}
|
||||
|
||||
virtual const char* className()
|
||||
{
|
||||
@ -42,10 +52,12 @@ public:
|
||||
|
||||
osg::Vec4 mapStringToColor(const std::string& str)
|
||||
{
|
||||
if (str=="BLACK") return osg::Vec4(0.0f,0.0f,0.0f,1.0f);
|
||||
else return osg::Vec4(1.0f,1.0f,1.0f,1.0f);
|
||||
return _colorMap[str];
|
||||
}
|
||||
|
||||
|
||||
std::map<std::string,osg::Vec4> _colorMap;
|
||||
|
||||
};
|
||||
|
||||
// Register with Registry to instantiate the above reader/writer.
|
||||
|
@ -322,9 +322,16 @@ bool OsgCameraGroup::realize()
|
||||
if (_ds->getDepthBuffer()) clear_mask |= GL_DEPTH_BUFFER_BIT;
|
||||
if (_ds->getStencilBuffer()) clear_mask |= GL_STENCIL_BUFFER_BIT;
|
||||
|
||||
// make sure any camera's which share the same render surface also share the same osg::State.
|
||||
// use a std::map to keep track of what render surfaces are associated with what state.
|
||||
typedef std::map<Producer::RenderSurface*,osg::State*> RenderSurfaceStateMap;
|
||||
RenderSurfaceStateMap _renderSurfaceStateMap;
|
||||
unsigned int contextID = 0;
|
||||
|
||||
for(unsigned int i = 0; i < _cfg->getNumberOfCameras(); i++ )
|
||||
{
|
||||
Producer::Camera *cam = _cfg->getCamera(i);
|
||||
Producer::RenderSurface* rs = cam->getRenderSurface();
|
||||
|
||||
// create the scene handler.
|
||||
osgProducer::OsgSceneHandler *sh = new osgProducer::OsgSceneHandler(_ds.get());
|
||||
@ -332,7 +339,15 @@ bool OsgCameraGroup::realize()
|
||||
osgUtil::SceneView* sv = sh->getSceneView();
|
||||
sv->setDefaults();
|
||||
|
||||
sh->setContextID(i);
|
||||
if (_renderSurfaceStateMap.count(rs)==0)
|
||||
{
|
||||
_renderSurfaceStateMap[rs] = sv->getState();
|
||||
sv->getState()->setContextID(contextID++);
|
||||
}
|
||||
else
|
||||
{
|
||||
sv->setState(_renderSurfaceStateMap[rs]);
|
||||
}
|
||||
|
||||
_shvec.push_back( sh );
|
||||
cam->setSceneHandler( sh );
|
||||
@ -342,7 +357,6 @@ bool OsgCameraGroup::realize()
|
||||
if (stage) stage->setClearMask(clear_mask);
|
||||
|
||||
// set the realize callback.
|
||||
Producer::RenderSurface* rs = cam->getRenderSurface();
|
||||
rs->setRealizeCallback( new RenderSurfaceRealizeCallback(this, sh));
|
||||
|
||||
// set up the visual chooser.
|
||||
@ -374,6 +388,7 @@ bool OsgCameraGroup::realize()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( _global_stateset == NULL && _shvec.size() > 0 )
|
||||
{
|
||||
SceneHandlerList::iterator p = _shvec.begin();
|
||||
|
Loading…
Reference in New Issue
Block a user