#ifndef CAMERAGROUP_HXX
#define CAMERAGROUP_HXX 1
+#include <map>
#include <string>
#include <vector>
#include <osg/ref_ptr>
#include <osg/Referenced>
#include <osg/Node>
+#include <osg/TextureRectangle>
+#include <osg/Texture2D>
+#include <osg/TexGen>
+#include <osgUtil/RenderBin>
// For osgUtil::LineSegmentIntersector::Intersections, which is a typedef.
#include <osgUtil/LineSegmentIntersector>
class GraphicsWindow;
+struct RenderBufferInfo {
+ enum Kind {
+ DEPTH_BUFFER,
+ NORMAL_BUFFER,
+ DIFFUSE_BUFFER,
+ SPEC_EMIS_BUFFER,
+ LIGHTING_BUFFER,
+ SHADOW_BUFFER
+ };
+
+ RenderBufferInfo(osg::Texture2D* t = 0, float s = 1.0 ) : texture(t), scaleFactor(s) {}
+ osg::ref_ptr<osg::Texture2D> texture;
+ float scaleFactor;
+};
+typedef std::map<RenderBufferInfo::Kind,RenderBufferInfo> RenderBufferMap;
+typedef std::map<osg::Camera::BufferComponent,size_t> AttachmentMap;
+
+struct RenderStageInfo {
+ RenderStageInfo(osg::Camera* camera_ = 0, int si = -1, bool fs = false)
+ : camera(camera_), slaveIndex(si), scaleFactor(1.0f), fullscreen(fs)
+ , resizable(true)
+ {
+ }
+
+ osg::ref_ptr<osg::Camera> camera;
+ AttachmentMap buffers;
+ int slaveIndex;
+ float scaleFactor;
+ bool fullscreen;
+ bool resizable;
+};
+
+enum CameraKind {
+ MAIN_CAMERA,
+ FAR_CAMERA,
+ GEOMETRY_CAMERA,
+ SHADOW_CAMERA,
+ BLOOM_CAMERA_1,
+ BLOOM_CAMERA_2,
+ AO_CAMERA_1,
+ 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.
*/
struct CameraInfo : public osg::Referenced
{
- CameraInfo(unsigned flags_, osg::Camera* camera_ = 0)
- : flags(flags_), camera(camera_), slaveIndex(-1), farSlaveIndex(-1),
- x(0.0), y(0.0), width(0.0), height(0.0)
+ CameraInfo(unsigned flags_)
+ : flags(flags_),
+ x(0.0), y(0.0), width(0.0), height(0.0),
+ physicalWidth(0), physicalHeight(0), bezelHeightTop(0),
+ bezelHeightBottom(0), bezelWidthLeft(0), bezelWidthRight(0),
+ relativeCameraParent(~0u),
+ bufferSize( new osg::Uniform("fg_BufferSize", osg::Vec2f() ) ),
+ projInverse( new osg::Uniform( "fg_ProjectionMatrixInverse", osg::Matrixf() ) ),
+ viewInverse( new osg::Uniform( "fg_ViewMatrixInverse",osg::Matrixf() ) ),
+ view( new osg::Uniform( "fg_ViewMatrix",osg::Matrixf() ) ),
+ du( new osg::Uniform( "fg_du",osg::Vec4() ) ),
+ dv( new osg::Uniform( "fg_dv",osg::Vec4() ) )
{
}
+
+ /** Update and resize cameras
+ */
+ void updateCameras();
+ void resized(double w, double h);
+ /** The name as given in the config file.
+ */
+ std::string name;
/** Properties of the camera. @see CameraGroup::Flags.
*/
unsigned flags;
- /** the camera object
- */
- osg::ref_ptr<osg::Camera> camera;
- /** camera for rendering far field, if needed
- */
- osg::ref_ptr<osg::Camera> farCamera;
- /** Index of this camera in the osgViewer::Viewer slave list.
- */
- int slaveIndex;
- /** index of far camera in slave list
- */
- int farSlaveIndex;
+
/** Viewport parameters.
*/
double x;
double y;
double width;
double height;
+ /** Physical size parameters.
+ */
+ double physicalWidth;
+ double physicalHeight;
+ double bezelHeightTop;
+ double bezelHeightBottom;
+ double bezelWidthLeft;
+ double bezelWidthRight;
+ /** The parent camera for relative camera configurations.
+ */
+ unsigned relativeCameraParent;
+
+ /** the camera objects
+ */
+ 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( CameraKind 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; }
+ osg::Camera* getCamera(CameraKind k) const;
+ int getMainSlaveIndex() const;
+ RenderStageInfo& getRenderStageInfo( CameraKind k ) { return cameras[k]; }
+
+ /** the buffer objects
+ */
+ RenderBufferMap buffers;
+ void addBuffer(RenderBufferInfo::Kind k, osg::Texture2D* tex, float scale = 1.0 ) { buffers[k] = RenderBufferInfo(tex,scale); }
+ osg::Texture2D* getBuffer(RenderBufferInfo::Kind k) const;
+
+ osg::ref_ptr<osg::TexGen> shadowTexGen[4];
+
+ osg::ref_ptr<osg::Uniform> bufferSize;
+ //osg::ref_ptr<osg::Uniform> bloomOffset[2];
+ osg::ref_ptr<osg::Uniform> projInverse;
+ osg::ref_ptr<osg::Uniform> viewInverse;
+ osg::ref_ptr<osg::Uniform> view;
+ osg::ref_ptr<osg::Uniform> du;
+ osg::ref_ptr<osg::Uniform> dv;
+
+ void setMatrices( osg::Camera* c );
+
+ osgUtil::RenderBin::RenderBinList savedTransparentBins;
+ /** The reference points in the parents projection space.
+ */
+ osg::Vec2d parentReference[2];
+ /** The reference points in the current projection space.
+ */
+ osg::Vec2d thisReference[2];
};
/** Update the OSG cameras from the camera info.
PROJECTION_ABSOLUTE = 0x2, /**< The projection is absolute. */
ORTHO = 0x4, /**< The projection is orthographic */
GUI = 0x8, /**< Camera draws the GUI. */
- DO_INTERSECTION_TEST = 0x10 /**< scene intersection tests this
+ DO_INTERSECTION_TEST = 0x10,/**< scene intersection tests this
camera. */
+ FIXED_NEAR_FAR = 0x20, /**< take the near far values in the
+ projection for real. */
+ ENABLE_MASTER_ZOOM = 0x40 /**< Can apply the zoom algorithm. */
};
/** Create a camera group associated with an osgViewer::Viewer.
* @param viewer the viewer
* @return the viewer
*/
osgViewer::Viewer* getViewer() { return _viewer.get(); }
- /** Add a camera to the group. The camera is added to the viewer
- * as a slave. See osgViewer::Viewer::addSlave.
- * @param flags properties of the camera; see CameraGroup::Flags
- * @param projection slave projection matrix
- * @param view slave view matrix
- * @param useMasterSceneData whether the camera displays the
- * viewer's scene data.
- * @return a CameraInfo object for the camera.
- */
- CameraInfo* addCamera(unsigned flags, osg::Camera* camera,
- const osg::Matrix& projection,
- const osg::Matrix& view,
- bool useMasterSceneData = true);
/** Create an osg::Camera from a property node and add it to the
* camera group.
* @param cameraNode the property node.
CameraIterator camerasEnd() { return _cameras.end(); }
ConstCameraIterator camerasBegin() const { return _cameras.begin(); }
ConstCameraIterator camerasEnd() const { return _cameras.end(); }
+ void addCamera(CameraInfo* info) { _cameras.push_back(info); }
/** Build a complete CameraGroup from a property node.
* @param viewer the viewer associated with this camera group.
* @param the camera group property node.
/** Update camera properties after a resize event.
*/
void resized();
+
+ void buildDistortionCamera(const SGPropertyNode* psNode,
+ osg::Camera* camera);
+
+ /**
+ * get aspect ratio of master camera's viewport
+ */
+ double getMasterAspectRatio() const;
+
+ /**
+ * find the GUI camera if one is defined
+ */
+ const CameraInfo* getGUICamera() const;
protected:
CameraList _cameras;
osg::ref_ptr<osgViewer::Viewer> _viewer;
static osg::ref_ptr<CameraGroup> _defaultGroup;
+ // Near, far for the master camera if used.
+ float _zNear;
+ float _zFar;
+ float _nearField;
+ typedef std::map<std::string, osg::ref_ptr<osg::TextureRectangle> > TextureMap;
+ TextureMap _textureTargets;
};
}