2009-01-15 18:44:52 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2006-11-27 22:52:07 +08:00
*
2009-01-15 18:44:52 +08:00
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
2006-11-27 22:52:07 +08:00
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
2009-01-15 18:44:52 +08:00
*
2006-11-27 22:52:07 +08:00
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2009-01-15 18:44:52 +08:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2006-11-27 22:52:07 +08:00
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_CAMERA
#define OSG_CAMERA 1
#include <osg/Transform>
#include <osg/Viewport>
#include <osg/ColorMask>
#include <osg/CullSettings>
#include <osg/Texture>
#include <osg/Image>
#include <osg/GraphicsContext>
2007-01-20 03:53:23 +08:00
#include <osg/Stats>
2006-11-27 22:52:07 +08:00
#include <OpenThreads/Mutex>
2013-05-27 16:10:42 +08:00
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)
#define GL_FRONT_LEFT 0x0400
#define GL_FRONT_RIGHT 0x0401
#define GL_BACK_LEFT 0x0402
#define GL_BACK_RIGHT 0x0403
#endif
2006-11-27 22:52:07 +08:00
namespace osg {
// forward declare View to allow Camera to point back to the View that its within
class View;
2008-02-29 23:25:57 +08:00
class RenderInfo;
2006-11-27 22:52:07 +08:00
/** Camera - is a subclass of Transform which represents encapsulates the settings of a Camera.
*/
class OSG_EXPORT Camera : public Transform, public CullSettings
{
public :
Camera();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Camera(const Camera&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, Camera);
2011-09-14 18:02:11 +08:00
virtual Camera* asCamera() { return this; }
virtual const Camera* asCamera() const { return this; }
2006-11-27 22:52:07 +08:00
/** Set the View that this Camera is part of. */
void setView(View* view) { _view = view; }
/** Get the View that this Camera is part of. */
View* getView() { return _view; }
/** Get the const View that this Camera is part of. */
const View* getView() const { return _view; }
2015-04-08 02:01:12 +08:00
/** Set the Stats object used to collect various frame related
2010-09-15 20:00:12 +08:00
* timing and scene graph stats. */
2007-01-20 03:53:23 +08:00
void setStats(osg::Stats* stats) { _stats = stats; }
/** Get the Stats object.*/
osg::Stats* getStats() { return _stats.get(); }
/** Get the const Stats object.*/
const osg::Stats* getStats() const { return _stats.get(); }
2012-03-22 01:36:20 +08:00
/** Set whether this camera allows events to be generated by the
2010-09-15 20:00:12 +08:00
* associated graphics window to be associated with this camera. */
2007-02-22 03:06:43 +08:00
void setAllowEventFocus(bool focus) { _allowEventFocus = focus; }
2010-09-15 20:00:12 +08:00
/** Get whether this camera allows events to be generated by the
* associated graphics window to be associated with this camera. */
2007-02-22 03:06:43 +08:00
bool getAllowEventFocus() const { return _allowEventFocus; }
2009-07-24 22:45:44 +08:00
/** Set the DisplaySettings object associated with this view.*/
2007-06-09 18:06:38 +08:00
void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
2009-01-15 18:44:52 +08:00
2009-07-24 22:45:44 +08:00
/** Get the DisplaySettings object associated with this view.*/
2007-06-09 18:06:38 +08:00
osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
2009-01-15 18:44:52 +08:00
2009-07-24 22:45:44 +08:00
/** Get the const DisplaySettings object associated with this view.*/
2007-06-09 18:06:38 +08:00
const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
2010-09-16 17:49:22 +08:00
/** Set the clear mask used in glClear().
2006-11-27 22:52:07 +08:00
* Defaults to GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT. */
From Paul Martz, "This change address the following issue: an app opens a Viewer on a multidisplay system, configured to setUpViewAcrossAllDisplays, with a non-default clear mask. In this case, OSG failed to propagate the clear mask to the slave Cameras, resulting in the clear mask being ignored. To fix this issue, this revision adds a new CullSettings::VariablesMask bit, CLEAR_MASK, to explicitly control inheritance of the clear mask. This bit is set by default, which means that the clear mask now inherits by default, whereas previously it did not."
2009-11-27 23:32:43 +08:00
inline void setClearMask(GLbitfield mask) { _clearMask = mask; applyMaskAction(CLEAR_MASK); }
2006-11-27 22:52:07 +08:00
/** Get the clear mask.*/
inline GLbitfield getClearMask() const { return _clearMask; }
2010-09-16 17:49:22 +08:00
/** Set the clear color used in glClearColor().
2008-03-31 19:44:31 +08:00
* glClearColor is only called if mask & GL_COLOR_BUFFER_BIT is true*/
2008-05-31 04:15:31 +08:00
void setClearColor(const osg::Vec4& color) { _clearColor=color; applyMaskAction(CLEAR_COLOR); }
2009-01-15 18:44:52 +08:00
2008-03-31 19:44:31 +08:00
/** Get the clear color.*/
const osg::Vec4& getClearColor() const { return _clearColor; }
2009-01-15 18:44:52 +08:00
2010-09-16 17:49:22 +08:00
/** Set the clear accum used in glClearAccum().
2008-03-31 19:44:31 +08:00
* glClearAcumm is only called if mask & GL_ACCUM_BUFFER_BIT is true. */
void setClearAccum(const osg::Vec4& color) { _clearAccum=color; }
2009-01-15 18:44:52 +08:00
2008-03-31 19:44:31 +08:00
/** Get the clear accum value.*/
const osg::Vec4& getClearAccum() const { return _clearAccum; }
2009-01-15 18:44:52 +08:00
2010-09-16 17:49:22 +08:00
/** Set the clear depth used in glClearDepth(). Defaults to 1.0
2008-03-31 19:44:31 +08:00
* glClearDepth is only called if mask & GL_DEPTH_BUFFER_BIT is true. */
void setClearDepth(double depth) { _clearDepth=depth; }
2009-01-15 18:44:52 +08:00
2008-03-31 19:44:31 +08:00
/** Get the clear depth value.*/
double getClearDepth() const { return _clearDepth; }
2006-11-27 22:52:07 +08:00
2008-03-31 19:44:31 +08:00
/** Set the clear stencil value used in glClearStencil(). Defaults to 0;
* glClearStencil is only called if mask & GL_STENCIL_BUFFER_BIT is true*/
void setClearStencil(int stencil) { _clearStencil=stencil; }
2009-01-15 18:44:52 +08:00
2008-03-31 19:44:31 +08:00
/** Get the clear stencil value.*/
int getClearStencil() const { return _clearStencil; }
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Set the color mask of the camera to use specified osg::ColorMask. */
void setColorMask(osg::ColorMask* colorMask);
2008-03-31 19:44:31 +08:00
2006-11-27 22:52:07 +08:00
/** Set the color mask of the camera to specified values. */
void setColorMask(bool red, bool green, bool blue, bool alpha);
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Get the const ColorMask. */
const ColorMask* getColorMask() const { return _colorMask.get(); }
/** Get the ColorMask. */
ColorMask* getColorMask() { return _colorMask.get(); }
/** Set the viewport of the camera to use specified osg::Viewport. */
void setViewport(osg::Viewport* viewport);
/** Set the viewport of the camera to specified dimensions. */
void setViewport(int x,int y,int width,int height);
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Get the const viewport. */
const Viewport* getViewport() const { return _viewport.get(); }
/** Get the viewport. */
Viewport* getViewport() { return _viewport.get(); }
2015-03-31 23:08:13 +08:00
2006-11-27 22:52:07 +08:00
enum TransformOrder
{
PRE_MULTIPLY,
2009-01-15 18:44:52 +08:00
POST_MULTIPLY
2006-11-27 22:52:07 +08:00
};
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Set the transformation order for world-to-local and local-to-world transformation.*/
void setTransformOrder(TransformOrder order) { _transformOrder = order; }
/** Get the transformation order.*/
TransformOrder getTransformOrder() const { return _transformOrder; }
2009-01-15 18:44:52 +08:00
2007-05-22 17:32:38 +08:00
enum ProjectionResizePolicy
{
2010-09-15 20:00:12 +08:00
FIXED, /**< Keep the projection matrix fixed, despite window resizes.*/
HORIZONTAL, /**< Adjust the HORIZONTAL field of view on window resizes.*/
VERTICAL /**< Adjust the VERTICAL field of view on window resizes.*/
2007-05-22 17:32:38 +08:00
};
2009-01-15 18:44:52 +08:00
2007-12-11 01:30:18 +08:00
/** Set the policy used to determine if and how the projection matrix should be adjusted on window resizes. */
2007-05-22 17:32:38 +08:00
inline void setProjectionResizePolicy(ProjectionResizePolicy policy) { _projectionResizePolicy = policy; }
2007-12-11 01:30:18 +08:00
/** Get the policy used to determine if and how the projection matrix should be adjusted on window resizes. */
2007-05-22 17:32:38 +08:00
inline ProjectionResizePolicy getProjectionResizePolicy() const { return _projectionResizePolicy; }
2006-11-27 22:52:07 +08:00
/** Set the projection matrix. Can be thought of as setting the lens of a camera. */
inline void setProjectionMatrix(const osg::Matrixf& matrix) { _projectionMatrix.set(matrix); }
/** Set the projection matrix. Can be thought of as setting the lens of a camera. */
inline void setProjectionMatrix(const osg::Matrixd& matrix) { _projectionMatrix.set(matrix); }
/** Set to an orthographic projection. See OpenGL glOrtho for documentation further details.*/
void setProjectionMatrixAsOrtho(double left, double right,
double bottom, double top,
double zNear, double zFar);
/** Set to a 2D orthographic projection. See OpenGL glOrtho2D documentation for further details.*/
void setProjectionMatrixAsOrtho2D(double left, double right,
double bottom, double top);
/** Set to a perspective projection. See OpenGL glFrustum documentation for further details.*/
void setProjectionMatrixAsFrustum(double left, double right,
double bottom, double top,
double zNear, double zFar);
/** Create a symmetrical perspective projection, See OpenGL gluPerspective documentation for further details.
* Aspect ratio is defined as width/height.*/
void setProjectionMatrixAsPerspective(double fovy,double aspectRatio,
double zNear, double zFar);
/** Get the projection matrix.*/
osg::Matrixd& getProjectionMatrix() { return _projectionMatrix; }
/** Get the const projection matrix.*/
const osg::Matrixd& getProjectionMatrix() const { return _projectionMatrix; }
2009-01-15 18:44:52 +08:00
/** Get the orthographic settings of the orthographic projection matrix.
2006-11-27 22:52:07 +08:00
* Returns false if matrix is not an orthographic matrix, where parameter values are undefined.*/
bool getProjectionMatrixAsOrtho(double& left, double& right,
double& bottom, double& top,
2009-01-15 18:36:04 +08:00
double& zNear, double& zFar) const;
2006-11-27 22:52:07 +08:00
/** Get the frustum setting of a perspective projection matrix.
* Returns false if matrix is not a perspective matrix, where parameter values are undefined.*/
bool getProjectionMatrixAsFrustum(double& left, double& right,
double& bottom, double& top,
2009-01-15 18:36:04 +08:00
double& zNear, double& zFar) const;
2006-11-27 22:52:07 +08:00
/** Get the frustum setting of a symmetric perspective projection matrix.
2009-01-15 18:44:52 +08:00
* Returns false if matrix is not a perspective matrix, where parameter values are undefined.
2006-11-27 22:52:07 +08:00
* Note, if matrix is not a symmetric perspective matrix then the shear will be lost.
* Asymmetric matrices occur when stereo, power walls, caves and reality center display are used.
* In these configurations one should use the 'getProjectionMatrixAsFrustum' method instead.*/
bool getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
2009-01-15 18:36:04 +08:00
double& zNear, double& zFar) const;
2006-11-27 22:52:07 +08:00
/** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */
inline void setViewMatrix(const osg::Matrixf& matrix) { _viewMatrix.set(matrix); dirtyBound();}
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */
inline void setViewMatrix(const osg::Matrixd& matrix) { _viewMatrix.set(matrix); dirtyBound();}
/** Get the view matrix. */
osg::Matrixd& getViewMatrix() { return _viewMatrix; }
/** Get the const view matrix. */
const osg::Matrixd& getViewMatrix() const { return _viewMatrix; }
2008-03-04 19:53:09 +08:00
/** Set to the position and orientation of view matrix, using the same convention as gluLookAt. */
void setViewMatrixAsLookAt(const osg::Vec3d& eye,const osg::Vec3d& center,const osg::Vec3d& up);
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
2009-01-15 18:36:04 +08:00
void getViewMatrixAsLookAt(osg::Vec3d& eye,osg::Vec3d& center,osg::Vec3d& up,double lookDistance=1.0) const;
2008-03-04 19:53:09 +08:00
2006-11-27 22:52:07 +08:00
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
2009-01-15 18:36:04 +08:00
void getViewMatrixAsLookAt(osg::Vec3f& eye,osg::Vec3f& center,osg::Vec3f& up,float lookDistance=1.0f) const;
2006-11-27 22:52:07 +08:00
/** Get the inverse view matrix.*/
Matrixd getInverseViewMatrix() const;
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
enum RenderOrder
{
PRE_RENDER,
NESTED_RENDER,
POST_RENDER
};
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Set the rendering order of this camera's subgraph relative to any camera that this subgraph is nested within.
* For rendering to a texture, one typically uses PRE_RENDER.
* For Head Up Displays, one would typically use POST_RENDER.*/
void setRenderOrder(RenderOrder order, int orderNum = 0) { _renderOrder = order; _renderOrderNum = orderNum; }
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Get the rendering order of this camera's subgraph relative to any camera that this subgraph is nested within.*/
RenderOrder getRenderOrder() const { return _renderOrder; }
/** Get the rendering order number of this camera relative to any sibling cameras in this subgraph.*/
2009-01-15 18:44:52 +08:00
int getRenderOrderNum() const { return _renderOrderNum; }
2006-11-27 22:52:07 +08:00
/** Return true if this Camera is set up as a render to texture camera, i.e. it has textures assigned to it.*/
bool isRenderToTextureCamera() const;
enum RenderTargetImplementation
{
FRAME_BUFFER_OBJECT,
PIXEL_BUFFER_RTT,
PIXEL_BUFFER,
FRAME_BUFFER,
2015-04-13 19:48:28 +08:00
SEPARATE_WINDOW
2006-11-27 22:52:07 +08:00
};
/** Set the render target.*/
void setRenderTargetImplementation(RenderTargetImplementation impl);
/** Set the render target and fall-back that's used if the former isn't available.*/
void setRenderTargetImplementation(RenderTargetImplementation impl, RenderTargetImplementation fallback);
/** Get the render target.*/
RenderTargetImplementation getRenderTargetImplementation() const { return _renderTargetImplementation; }
/** Get the render target fallback.*/
RenderTargetImplementation getRenderTargetFallback() const { return _renderTargetFallback; }
2009-01-15 18:44:52 +08:00
/** Set the draw buffer used at the start of each frame draw.
2015-04-08 02:01:12 +08:00
* Note, a buffer value of GL_NONE is used to specify that the rendering back-end should choose the most appropriate buffer.*/
2009-08-21 17:34:48 +08:00
void setDrawBuffer(GLenum buffer) { _drawBuffer = buffer; applyMaskAction( DRAW_BUFFER ); }
2006-11-27 22:52:07 +08:00
/** Get the draw buffer used at the start of each frame draw. */
GLenum getDrawBuffer() const { return _drawBuffer; }
2009-01-15 18:44:52 +08:00
/** Set the read buffer for any required copy operations to use.
2015-04-08 02:01:12 +08:00
* Note, a buffer value of GL_NONE is used to specify that the rendering back-end should choose the most appropriate buffer.*/
2009-08-21 17:34:48 +08:00
void setReadBuffer(GLenum buffer) { _readBuffer = buffer; applyMaskAction( READ_BUFFER ); }
2006-11-27 22:52:07 +08:00
/** Get the read buffer for any required copy operations to use. */
GLenum getReadBuffer() const { return _readBuffer; }
enum BufferComponent
{
DEPTH_BUFFER,
STENCIL_BUFFER,
2008-11-09 19:55:11 +08:00
PACKED_DEPTH_STENCIL_BUFFER,
2006-11-27 22:52:07 +08:00
COLOR_BUFFER,
2008-04-02 21:47:45 +08:00
COLOR_BUFFER0,
COLOR_BUFFER1 = COLOR_BUFFER0+1,
COLOR_BUFFER2 = COLOR_BUFFER0+2,
COLOR_BUFFER3 = COLOR_BUFFER0+3,
COLOR_BUFFER4 = COLOR_BUFFER0+4,
COLOR_BUFFER5 = COLOR_BUFFER0+5,
COLOR_BUFFER6 = COLOR_BUFFER0+6,
2008-04-18 22:51:21 +08:00
COLOR_BUFFER7 = COLOR_BUFFER0+7,
COLOR_BUFFER8 = COLOR_BUFFER0+8,
COLOR_BUFFER9 = COLOR_BUFFER0+9,
COLOR_BUFFER10 = COLOR_BUFFER0+10,
COLOR_BUFFER11 = COLOR_BUFFER0+11,
COLOR_BUFFER12 = COLOR_BUFFER0+12,
COLOR_BUFFER13 = COLOR_BUFFER0+13,
COLOR_BUFFER14 = COLOR_BUFFER0+14,
COLOR_BUFFER15 = COLOR_BUFFER0+15
2006-11-27 22:52:07 +08:00
};
2010-06-01 22:12:03 +08:00
static const unsigned int FACE_CONTROLLED_BY_GEOMETRY_SHADER;
2008-05-07 19:59:15 +08:00
/** Attach a buffer with specified OpenGL internal format.*/
2006-11-27 22:52:07 +08:00
void attach(BufferComponent buffer, GLenum internalFormat);
2009-01-15 18:44:52 +08:00
/** Attach a Texture to specified buffer component.
* The level parameter controls the mip map level of the texture that is attached.
* The face parameter controls the face of texture cube map or z level of 3d texture.
2008-05-07 19:59:15 +08:00
* The mipMapGeneration flag controls whether mipmap generation should be done for texture.*/
2008-06-18 22:09:11 +08:00
void attach(BufferComponent buffer, osg::Texture* texture, unsigned int level = 0, unsigned int face=0, bool mipMapGeneration=false,
unsigned int multisampleSamples = 0,
unsigned int multisampleColorSamples = 0);
2006-11-27 22:52:07 +08:00
2008-05-07 19:59:15 +08:00
/** Attach a Image to specified buffer component.*/
2008-06-18 22:09:11 +08:00
void attach(BufferComponent buffer, osg::Image* image,
unsigned int multisampleSamples = 0,
unsigned int multisampleColorSamples = 0);
2006-11-27 22:52:07 +08:00
2008-05-07 19:59:15 +08:00
/** Detach specified buffer component.*/
2006-11-27 22:52:07 +08:00
void detach(BufferComponent buffer);
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
struct Attachment
{
Attachment():
_internalFormat(GL_NONE),
_level(0),
_face(0),
2008-06-18 22:09:11 +08:00
_mipMapGeneration(false),
_multisampleSamples(0),
_multisampleColorSamples(0) {}
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
int width() const
{
2009-01-15 18:44:52 +08:00
if (_texture.valid()) return _texture->getTextureWidth();
2006-11-27 22:52:07 +08:00
if (_image.valid()) return _image->s();
return 0;
};
int height() const
{
2009-01-15 18:44:52 +08:00
if (_texture.valid()) return _texture->getTextureHeight();
2006-11-27 22:52:07 +08:00
if (_image.valid()) return _image->t();
return 0;
};
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
int depth() const
{
2009-01-15 18:44:52 +08:00
if (_texture.valid()) return _texture->getTextureDepth();
2006-11-27 22:52:07 +08:00
if (_image.valid()) return _image->r();
return 0;
};
GLenum _internalFormat;
ref_ptr<Image> _image;
ref_ptr<Texture> _texture;
unsigned int _level;
unsigned int _face;
bool _mipMapGeneration;
2008-06-18 22:09:11 +08:00
unsigned int _multisampleSamples;
unsigned int _multisampleColorSamples;
2006-11-27 22:52:07 +08:00
};
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
typedef std::map< BufferComponent, Attachment> BufferAttachmentMap;
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Get the BufferAttachmentMap, used to configure frame buffer objects, pbuffers and texture reads.*/
BufferAttachmentMap& getBufferAttachmentMap() { return _bufferAttachmentMap; }
/** Get the const BufferAttachmentMap, used to configure frame buffer objects, pbuffers and texture reads.*/
const BufferAttachmentMap& getBufferAttachmentMap() const { return _bufferAttachmentMap; }
2008-06-18 22:09:11 +08:00
2015-03-31 18:36:38 +08:00
/** Increment the _attachementMapModifiedCount so that the rendering backend will know that it needs to be updated to handle any new settings (such as format change/resizes.).*/
void dirtyAttachmentMap() { ++_attachmentMapModifiedCount; }
/** Set the AttachmentMapModifiedCount to a specific value. Note, normal usage you would simply call dirtyAttachmentMap(). */
void setAttachmentMapModifiedCount(unsigned int v) { _attachmentMapModifiedCount = v; }
/** Get the AttachmentMapModifiedCount. */
unsigned int getAttachmentMapModifiedCount() const { return _attachmentMapModifiedCount; }
2015-03-31 23:08:13 +08:00
/** Resize the image and textures in the AttachementMap.*/
void resizeAttachments(int width, int height);
2015-03-31 18:36:38 +08:00
2015-04-01 00:23:43 +08:00
enum ResizeMask
{
RESIZE_VIEWPORT=1,
RESIZE_ATTACHMENTS=2,
RESIZE_PROJECTIONMATRIX=4,
RESIZE_DEFAULT=RESIZE_VIEWPORT|RESIZE_ATTACHMENTS
};
/** Resize, to the specified width and height, the viewport, attachments and projection matrix according to the resizeMask provided.
* Note, the adjustment of the projection matrix is done if the RESIZE_PROJECTIONMATRIX mask to set and according to the rules specified in the ProjectionResizePolicy. */
void resize(int width, int height, int resizeMask=RESIZE_DEFAULT);
2009-11-19 18:10:50 +08:00
/** Explicit control over implicit allocation of buffers when using FBO.
Implicit buffers are automatically substituted when user have not attached such buffer.
Camera may set up two FBOs: primary Render FBO and secondary Resolve FBO for multisample usage.
2015-04-08 02:01:12 +08:00
So in practice we have two masks defined for the Camera:
2009-11-19 18:10:50 +08:00
implicitBufferAttachmentRenderMask
implicitBufferAttachmentResolveMask
They can be set together by setImplicitBufferAttachmentMask method, or separately
by setImplicitBufferAttachmentRenderMask and setImplicitBufferAttachmentResolveMask.
Camera defaults are USE_DISPLAY_SETTINGS_MASK which means that by default
2015-04-08 02:01:12 +08:00
Camera chooses to substitute buffer attachments as defined by DisplaySettings.
2009-11-19 18:10:50 +08:00
2012-03-22 01:36:20 +08:00
Usually DisplaySettings implicit buffer attachment selection defaults to: DEPTH and COLOR
2009-11-19 18:10:50 +08:00
for both primary (Render) FBO and seconday Multisample (Resolve) FBO
2015-04-08 02:01:12 +08:00
ie: IMPLICIT_DEPTH_BUFFER_ATTACHMENT | IMPLICIT_COLOR_BUFFER_ATTACHMENT
2009-11-19 18:10:50 +08:00
2012-03-22 01:36:20 +08:00
If these masks are not changed and user did not attach depth buffer and/or color buffer
2015-04-08 02:01:12 +08:00
to Camera, then OSG implicitly substitutes these buffers.
2009-11-19 18:10:50 +08:00
By default it does not implicitly allocate a stencil buffer.
2015-04-08 02:01:12 +08:00
Use implicit buffer attachment masks to override default behavior:
2009-11-19 18:10:50 +08:00
to turn off DEPTH or COLOR buffer substitution or to enforce STENCIL buffer substitution.
Note that both values are ignored if not using FBO.
Note that the second mask value is ignored if not using MSFBO.
*/
enum ImplicitBufferAttachment
{
IMPLICIT_DEPTH_BUFFER_ATTACHMENT = DisplaySettings::IMPLICIT_DEPTH_BUFFER_ATTACHMENT,
IMPLICIT_STENCIL_BUFFER_ATTACHMENT = DisplaySettings::IMPLICIT_STENCIL_BUFFER_ATTACHMENT,
IMPLICIT_COLOR_BUFFER_ATTACHMENT = DisplaySettings::IMPLICIT_COLOR_BUFFER_ATTACHMENT,
USE_DISPLAY_SETTINGS_MASK = (~0)
};
typedef int ImplicitBufferAttachmentMask;
void setImplicitBufferAttachmentMask(ImplicitBufferAttachmentMask renderMask = DisplaySettings::DEFAULT_IMPLICIT_BUFFER_ATTACHMENT, ImplicitBufferAttachmentMask resolveMask = DisplaySettings::DEFAULT_IMPLICIT_BUFFER_ATTACHMENT)
{
_implicitBufferAttachmentRenderMask = renderMask;
_implicitBufferAttachmentResolveMask = resolveMask;
}
void setImplicitBufferAttachmentRenderMask(ImplicitBufferAttachmentMask implicitBufferAttachmentRenderMask)
{
_implicitBufferAttachmentRenderMask = implicitBufferAttachmentRenderMask;
}
void setImplicitBufferAttachmentResolveMask(ImplicitBufferAttachmentMask implicitBufferAttachmentResolveMask)
{
_implicitBufferAttachmentResolveMask = implicitBufferAttachmentResolveMask;
}
2012-03-22 01:36:20 +08:00
/**
2015-04-08 02:01:12 +08:00
Get mask selecting implicit buffer attachments for Camera primary FBO
2009-11-19 18:10:50 +08:00
if effectiveMask parameter is set, method follows USE_DISPLAY_SETTINGS_MASK dependence and returns effective mask
if effectiveMask parameter is reset, method returns nominal mask set by the Camera
*/
ImplicitBufferAttachmentMask getImplicitBufferAttachmentRenderMask(bool effectiveMask = false) const
2012-03-22 01:36:20 +08:00
{
2009-11-19 18:10:50 +08:00
if( effectiveMask && _implicitBufferAttachmentRenderMask == USE_DISPLAY_SETTINGS_MASK )
{
2010-05-12 19:37:27 +08:00
const DisplaySettings * ds = _displaySettings.valid() ? _displaySettings.get() : DisplaySettings::instance().get();
2009-11-19 18:10:50 +08:00
return ds->getImplicitBufferAttachmentRenderMask();
}
else
{
return _implicitBufferAttachmentRenderMask;
}
}
2012-03-22 01:36:20 +08:00
/**
2015-04-08 02:01:12 +08:00
Get mask selecting implicit buffer attachments for Camera secondary MULTISAMPLE FBO
2009-11-19 18:10:50 +08:00
if effectiveMask parameter is set, method follows USE_DISPLAY_SETTINGS_MASK dependence and returns effective mask
if effectiveMask parameter is reset, method returns nominal mask set by the Camera
*/
ImplicitBufferAttachmentMask getImplicitBufferAttachmentResolveMask(bool effectiveMask = false) const
2012-03-22 01:36:20 +08:00
{
2009-11-19 18:10:50 +08:00
if( effectiveMask && _implicitBufferAttachmentResolveMask == USE_DISPLAY_SETTINGS_MASK )
{
2010-05-12 19:37:27 +08:00
const DisplaySettings * ds = _displaySettings.valid() ? _displaySettings.get() : DisplaySettings::instance().get();
return ds->getImplicitBufferAttachmentResolveMask();
2009-11-19 18:10:50 +08:00
}
else
{
return _implicitBufferAttachmentResolveMask;
}
}
2007-02-05 21:44:16 +08:00
/** Create a operation thread for this camera.*/
void createCameraThread();
/** Assign a operation thread to the camera.*/
2007-07-12 23:54:45 +08:00
void setCameraThread(OperationThread* gt);
2007-02-05 21:44:16 +08:00
/** Get the operation thread assigned to this camera.*/
2007-07-12 23:54:45 +08:00
OperationThread* getCameraThread() { return _cameraThread.get(); }
2007-02-05 21:44:16 +08:00
/** Get the const operation thread assigned to this camera.*/
2007-07-12 23:54:45 +08:00
const OperationThread* getCameraThread() const { return _cameraThread.get(); }
2007-02-05 21:44:16 +08:00
2006-11-27 22:52:07 +08:00
/** Set the GraphicsContext that provides the mechansim for managing the OpenGL graphics context associated with this camera.*/
2007-01-02 02:20:10 +08:00
void setGraphicsContext(GraphicsContext* context);
2006-11-27 22:52:07 +08:00
/** Get the GraphicsContext.*/
GraphicsContext* getGraphicsContext() { return _graphicsContext.get(); }
/** Get the const GraphicsContext.*/
const GraphicsContext* getGraphicsContext() const { return _graphicsContext.get(); }
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Set the Rendering object that is used to implement rendering of the subgraph.*/
2007-08-02 19:02:47 +08:00
void setRenderer(osg::GraphicsOperation* rc) { _renderer = rc; }
2006-11-27 22:52:07 +08:00
/** Get the Rendering object that is used to implement rendering of the subgraph.*/
2007-08-02 19:02:47 +08:00
osg::GraphicsOperation* getRenderer() { return _renderer.get(); }
2006-11-27 22:52:07 +08:00
/** Get the const Rendering object that is used to implement rendering of the subgraph.*/
2007-08-02 19:02:47 +08:00
const osg::GraphicsOperation* getRenderer() const { return _renderer.get(); }
2009-01-15 18:44:52 +08:00
2007-08-02 19:02:47 +08:00
/** Set the Rendering cache that is used for cached objects associated with rendering of subgraphs.*/
void setRenderingCache(osg::Object* rc) { _renderingCache = rc; }
/** Get the Rendering cache that is used for cached objects associated with rendering of subgraphs.*/
osg::Object* getRenderingCache() { return _renderingCache.get(); }
/** Get the const Rendering cache that is used for cached objects associated with rendering of subgraphs.*/
const osg::Object* getRenderingCache() const { return _renderingCache.get(); }
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
/** Draw callback for custom operations.*/
2008-03-01 21:40:57 +08:00
struct OSG_EXPORT DrawCallback : virtual public Object
2006-11-27 22:52:07 +08:00
{
DrawCallback() {}
DrawCallback(const DrawCallback&,const CopyOp&) {}
From Erik van Dekker,
"I made several modifications:
* The cause of my errors was that my OSG source directory path contains spaces. To fix this issue I wrapped all paths with quotes, as stated in doxygen documentation.
* I also received some warning messages about deprecated doxygen settings, which I fixed by updating the doxygen file, i.e. running \u2018doxygen \u2013u doxygen.cmake\u2018. By running this command deprecated doxygen options are removed, some option comments have changed and quite some options have been added (I kept their default settings unless mentioned).
* I was surprised to find that the doxygen OUTPUT_DIRECTORY was set to \u201c${OpenSceneGraph_SOURCE_DIR}/doc\u201d, which does not seem appropriate for out of source builds; I changed this to \u201c${OpenSceneGraph_BINARY_DIR}/doc\u201d. (On the other hand, maybe a cmake selectable option should be given to the user?)
* Fixed two warnings I received about unexpected end-of-list-markers in \u2018osg\AnimationPath and \u2018osgUtil\CullVisitor due to excess trailing points in comments.
* Fixed a warning in osgWidget\StyleInterface due to an #include directive (strangely) placed inside a namespace.
* Fixed a warning in osg\Camera due to the META_Object macro that confused doxygen. Adding a semi-colon fixed this.
* Removed auto_Mainpage from the INCLUDE option, because I am positive that this file does not belong there; It never generated useful documentation anyway.
* I added the OSG version number environment variable to the PROJECT_NUMBER option so that the version number is now shown on the main page of generated documentation (e.g. index.html).
* Changed option FULL_PATH_NAMES to YES, but made sure STRIP_FROM_PATH stripped the absolute path until the include dir. This fixed an issue that created mangled names for identical filenames in different directories. E.g. osg/Export and osgDB/Export are now correctly named.
* Changed option SHOW_DIRECTORIES to yes, which is a case of preference I guess.
"
2008-08-18 19:00:40 +08:00
META_Object(osg, DrawCallback);
2008-06-18 22:09:11 +08:00
2009-01-15 18:44:52 +08:00
/** Functor method called by rendering thread. Users will typically override this method to carry tasks such as screen capture.*/
2008-02-29 23:25:57 +08:00
virtual void operator () (osg::RenderInfo& renderInfo) const;
2009-01-15 18:44:52 +08:00
/** Functor method, provided for backwards compatibility, called by operator() (osg::RenderInfo& renderInfo) method.*/
2006-11-27 22:52:07 +08:00
virtual void operator () (const osg::Camera& /*camera*/) const {}
};
2009-01-15 18:44:52 +08:00
2008-02-29 23:25:57 +08:00
/** Set the initial draw callback for custom operations to be done before the drawing of the camera's subgraph and pre render stages.*/
2008-05-08 21:22:52 +08:00
void setInitialDrawCallback(DrawCallback* cb) { _initialDrawCallback = cb; }
2008-02-29 23:25:57 +08:00
/** Get the initial draw callback.*/
DrawCallback* getInitialDrawCallback() { return _initialDrawCallback.get(); }
/** Get the const initial draw callback.*/
2008-03-01 20:50:54 +08:00
const DrawCallback* getInitialDrawCallback() const { return _initialDrawCallback.get(); }
2009-01-15 18:44:52 +08:00
2008-02-29 23:25:57 +08:00
/** Set the pre draw callback for custom operations to be done before the drawing of the camera's subgraph but after any pre render stages have been completed.*/
2007-06-02 03:45:24 +08:00
void setPreDrawCallback(DrawCallback* cb) { _preDrawCallback = cb; }
/** Get the pre draw callback.*/
DrawCallback* getPreDrawCallback() { return _preDrawCallback.get(); }
/** Get the const pre draw callback.*/
const DrawCallback* getPreDrawCallback() const { return _preDrawCallback.get(); }
2009-01-15 18:44:52 +08:00
2007-06-02 03:45:24 +08:00
2008-02-29 23:25:57 +08:00
/** Set the post draw callback for custom operations to be done after the drawing of the camera's subgraph but before the any post render stages have been completed.*/
2006-11-27 22:52:07 +08:00
void setPostDrawCallback(DrawCallback* cb) { _postDrawCallback = cb; }
/** Get the post draw callback.*/
DrawCallback* getPostDrawCallback() { return _postDrawCallback.get(); }
/** Get the const post draw callback.*/
const DrawCallback* getPostDrawCallback() const { return _postDrawCallback.get(); }
2009-01-15 18:44:52 +08:00
2008-02-29 23:25:57 +08:00
/** Set the final draw callback for custom operations to be done after the drawing of the camera's subgraph and all of the post render stages has been completed.*/
void setFinalDrawCallback(DrawCallback* cb) { _finalDrawCallback = cb; }
/** Get the final draw callback.*/
DrawCallback* getFinalDrawCallback() { return _finalDrawCallback.get(); }
/** Get the const final draw callback.*/
const DrawCallback* getFinalDrawCallback() const { return _finalDrawCallback.get(); }
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
OpenThreads::Mutex* getDataChangeMutex() const { return &_dataChangeMutex; }
2007-01-04 22:11:51 +08:00
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize);
2006-11-27 22:52:07 +08:00
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const;
public:
/** Transform method that must be defined to provide generic interface for scene graph traversals.*/
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const;
/** Transform method that must be defined to provide generic interface for scene graph traversals.*/
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const;
2008-06-17 04:22:16 +08:00
/** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/
virtual void inheritCullSettings(const CullSettings& settings, unsigned int inheritanceMask);
2006-11-27 22:52:07 +08:00
protected :
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
virtual ~Camera();
2009-01-15 18:44:52 +08:00
2007-06-09 18:06:38 +08:00
mutable OpenThreads::Mutex _dataChangeMutex;
2006-11-27 22:52:07 +08:00
2007-06-09 18:06:38 +08:00
View* _view;
2007-01-20 03:53:23 +08:00
2007-06-09 18:06:38 +08:00
osg::ref_ptr<osg::Stats> _stats;
2007-02-22 03:06:43 +08:00
2007-06-09 18:06:38 +08:00
bool _allowEventFocus;
2009-01-15 18:44:52 +08:00
2007-06-09 18:06:38 +08:00
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
GLbitfield _clearMask;
2008-03-31 19:44:31 +08:00
osg::Vec4 _clearColor;
osg::Vec4 _clearAccum;
double _clearDepth;
int _clearStencil;
2009-01-15 18:44:52 +08:00
2007-06-09 18:06:38 +08:00
ref_ptr<ColorMask> _colorMask;
ref_ptr<Viewport> _viewport;
2006-11-27 22:52:07 +08:00
2007-06-09 18:06:38 +08:00
TransformOrder _transformOrder;
ProjectionResizePolicy _projectionResizePolicy;
2007-05-22 17:32:38 +08:00
2007-06-09 18:06:38 +08:00
Matrixd _projectionMatrix;
Matrixd _viewMatrix;
2009-01-15 18:44:52 +08:00
2007-06-09 18:06:38 +08:00
RenderOrder _renderOrder;
int _renderOrderNum;
2009-01-15 18:44:52 +08:00
2007-06-09 18:06:38 +08:00
GLenum _drawBuffer;
GLenum _readBuffer;
2009-01-15 18:44:52 +08:00
2007-06-09 18:06:38 +08:00
RenderTargetImplementation _renderTargetImplementation;
RenderTargetImplementation _renderTargetFallback;
BufferAttachmentMap _bufferAttachmentMap;
2009-11-19 18:10:50 +08:00
ImplicitBufferAttachmentMask _implicitBufferAttachmentRenderMask;
ImplicitBufferAttachmentMask _implicitBufferAttachmentResolveMask;
2006-11-27 22:52:07 +08:00
2015-03-31 18:36:38 +08:00
unsigned int _attachmentMapModifiedCount;
2007-07-28 18:28:40 +08:00
ref_ptr<OperationThread> _cameraThread;
2009-01-15 18:44:52 +08:00
2006-11-27 22:52:07 +08:00
ref_ptr<GraphicsContext> _graphicsContext;
2009-01-15 18:44:52 +08:00
2007-08-02 19:02:47 +08:00
ref_ptr<GraphicsOperation> _renderer;
ref_ptr<Object> _renderingCache;
2009-01-15 18:44:52 +08:00
2008-02-29 23:25:57 +08:00
ref_ptr<DrawCallback> _initialDrawCallback;
2007-06-02 03:45:24 +08:00
ref_ptr<DrawCallback> _preDrawCallback;
2006-11-27 22:52:07 +08:00
ref_ptr<DrawCallback> _postDrawCallback;
2008-02-29 23:25:57 +08:00
ref_ptr<DrawCallback> _finalDrawCallback;
2006-11-27 22:52:07 +08:00
};
2014-06-27 23:30:56 +08:00
2015-04-08 02:01:12 +08:00
/** Functor to assist with ordering cameras in the order they should be rendered in.*/
2014-06-27 23:30:56 +08:00
struct CameraRenderOrderSortOp
{
inline bool operator() (const Camera* lhs,const Camera* rhs) const
{
if (lhs->getRenderOrder()<rhs->getRenderOrder()) return true;
if (rhs->getRenderOrder()<lhs->getRenderOrder()) return false;
return lhs->getRenderOrderNum()<rhs->getRenderOrderNum();
}
};
2006-11-27 22:52:07 +08:00
}
#endif