1
0
Fork 0

Use names to identify cameras in camera group

This commit is contained in:
Frederic Bouvier 2012-04-15 17:45:43 +02:00
parent 81d181beb5
commit e55c0b8819
3 changed files with 26 additions and 23 deletions

View file

@ -56,6 +56,15 @@
#include <osgViewer/GraphicsWindow> #include <osgViewer/GraphicsWindow>
#include <osgViewer/Renderer> #include <osgViewer/Renderer>
namespace flightgear {
const char* MAIN_CAMERA = "MAIN_CAMERA";
const char* FAR_CAMERA = "FAR_CAMERA";
const char* GEOMETRY_CAMERA = "GEOMETRY_CAMERA";
const char* SHADOW_CAMERA = "SHADOW_CAMERA";
const char* LIGHTING_CAMERA = "LIGHTING_CAMERA";
const char* DISPLAY_CAMERA = "DISPLAY_CAMERA";
}
static osg::Matrix static osg::Matrix
invert(const osg::Matrix& matrix) invert(const osg::Matrix& matrix)
{ {
@ -242,7 +251,7 @@ void CameraInfo::resized(double w, double h)
} }
} }
osg::Camera* CameraInfo::getCamera(CameraKind k) const osg::Camera* CameraInfo::getCamera(const std::string& k) const
{ {
CameraMap::const_iterator ii = cameras.find( k ); CameraMap::const_iterator ii = cameras.find( k );
if (ii == cameras.end()) if (ii == cameras.end())

View file

@ -72,20 +72,14 @@ struct RenderStageInfo {
bool resizable; bool resizable;
}; };
enum CameraKind { extern const char* MAIN_CAMERA;
MAIN_CAMERA, extern const char* FAR_CAMERA;
FAR_CAMERA, extern const char* GEOMETRY_CAMERA;
GEOMETRY_CAMERA, extern const char* SHADOW_CAMERA;
SHADOW_CAMERA, extern const char* LIGHTING_CAMERA;
BLOOM_CAMERA_1, extern const char* DISPLAY_CAMERA;
BLOOM_CAMERA_2,
AO_CAMERA_1, typedef std::map<std::string,RenderStageInfo> CameraMap;
AO_CAMERA_2,
AO_CAMERA_3,
LIGHTING_CAMERA,
DISPLAY_CAMERA
};
typedef std::map<CameraKind,RenderStageInfo> CameraMap;
/** A wrapper around osg::Camera that contains some extra information. /** A wrapper around osg::Camera that contains some extra information.
*/ */
@ -138,12 +132,12 @@ struct CameraInfo : public osg::Referenced
/** the camera objects /** the camera objects
*/ */
CameraMap cameras; CameraMap cameras;
void addCamera( CameraKind k, osg::Camera* c, int si = -1, bool fs = false ) { cameras[k].camera = c; cameras[k].slaveIndex = si; cameras[k].fullscreen = fs; } void addCamera( const std::string& k, osg::Camera* c, int si = -1, bool fs = false ) { cameras[k].camera = c; cameras[k].slaveIndex = si; cameras[k].fullscreen = fs; }
void addCamera( CameraKind k, osg::Camera* c, bool fs ) { cameras[k].camera = c; cameras[k].fullscreen = fs; } void addCamera( const std::string& k, osg::Camera* c, bool fs ) { cameras[k].camera = c; cameras[k].fullscreen = fs; }
void addCamera( CameraKind k, osg::Camera* c, float s ) { cameras[k].camera = c; cameras[k].scaleFactor = s; } void addCamera( const std::string& k, osg::Camera* c, float s ) { cameras[k].camera = c; cameras[k].scaleFactor = s; }
osg::Camera* getCamera(CameraKind k) const; osg::Camera* getCamera(const std::string& k) const;
int getMainSlaveIndex() const; int getMainSlaveIndex() const;
RenderStageInfo& getRenderStageInfo( CameraKind k ) { return cameras[k]; } RenderStageInfo& getRenderStageInfo( const std::string& k ) { return cameras[k]; }
/** the buffer objects /** the buffer objects
*/ */

View file

@ -686,7 +686,7 @@ FGRenderer::buildClassicalPipeline(flightgear::CameraGroup* cgroup, unsigned fla
class FGDeferredRenderingCameraCullCallback : public osg::NodeCallback { class FGDeferredRenderingCameraCullCallback : public osg::NodeCallback {
public: public:
FGDeferredRenderingCameraCullCallback( flightgear::CameraKind k, CameraInfo* i ) : kind( k ), info( i ) {} FGDeferredRenderingCameraCullCallback( const std::string& k, CameraInfo* i ) : kind( k ), info( i ) {}
virtual void operator()( osg::Node *n, osg::NodeVisitor *nv) { virtual void operator()( osg::Node *n, osg::NodeVisitor *nv) {
simgear::EffectCullVisitor* cv = dynamic_cast<simgear::EffectCullVisitor*>(nv); simgear::EffectCullVisitor* cv = dynamic_cast<simgear::EffectCullVisitor*>(nv);
osg::Camera* camera = static_cast<osg::Camera*>(n); osg::Camera* camera = static_cast<osg::Camera*>(n);
@ -749,7 +749,7 @@ public:
} }
private: private:
flightgear::CameraKind kind; std::string kind;
CameraInfo* info; CameraInfo* info;
}; };
@ -789,7 +789,7 @@ void buildDeferredBuffers( flightgear::CameraInfo* info, int shadowMapSize, bool
info->getBuffer("shadow")->setTextureSize(shadowMapSize,shadowMapSize); info->getBuffer("shadow")->setTextureSize(shadowMapSize,shadowMapSize);
} }
void attachBufferToCamera( flightgear::CameraInfo* info, osg::Camera* camera, osg::Camera::BufferComponent c, flightgear::CameraKind ck, const std::string& bk ) void attachBufferToCamera( flightgear::CameraInfo* info, osg::Camera* camera, osg::Camera::BufferComponent c, const std::string& ck, const std::string& bk )
{ {
camera->attach( c, info->getBuffer(bk) ); camera->attach( c, info->getBuffer(bk) );
info->getRenderStageInfo(ck).buffers.insert( std::make_pair( c, bk ) ); info->getRenderStageInfo(ck).buffers.insert( std::make_pair( c, bk ) );