Added RenderTargetFallback option into osg::CameraNode.

This commit is contained in:
Robert Osfield 2005-11-01 10:42:54 +00:00
parent 030fe7d9ea
commit a742cb682e
4 changed files with 54 additions and 17 deletions

View File

@ -191,9 +191,14 @@ class OSG_EXPORT CameraNode : public Transform, public CullSettings
SEPERATE_WINDOW
};
void setRenderTargetImplementation(RenderTargetImplementation impl) { _renderTargetImplementation = impl; }
void setRenderTargetImplementation(RenderTargetImplementation impl);
void setRenderTargetImplementation(RenderTargetImplementation impl, RenderTargetImplementation fallback);
RenderTargetImplementation getRenderTargetImplementation() const { return _renderTargetImplementation; }
RenderTargetImplementation getRenderTargetFallback() const { return _renderTargetFallback; }
/** Set the draw buffer used at the start of each frame draw.
* Note, a buffer value of GL_NONE is used to sepecify that the rendering back-end should choose the most appropriate buffer.*/
@ -342,6 +347,7 @@ class OSG_EXPORT CameraNode : public Transform, public CullSettings
RenderBufferList _renderBufferList;
RenderTargetImplementation _renderTargetImplementation;
RenderTargetImplementation _renderTargetFallback;
BufferAttachmentMap _bufferAttachmentMap;
ref_ptr<GraphicsContext> _graphicsContext;

View File

@ -11,11 +11,10 @@
* OpenSceneGraph Public License for more details.
*/
#include <osg/CameraNode>
#include <osg/Notify>
using namespace osg;
CameraNode::CameraNode():
_clearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)),
_clearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT),
@ -23,7 +22,8 @@ CameraNode::CameraNode():
_renderOrder(POST_RENDER),
_drawBuffer(GL_NONE),
_readBuffer(GL_NONE),
_renderTargetImplementation(FRAME_BUFFER)
_renderTargetImplementation(FRAME_BUFFER),
_renderTargetFallback(FRAME_BUFFER)
{
setStateSet(new StateSet);
}
@ -42,6 +42,7 @@ CameraNode::CameraNode(const CameraNode& camera,const CopyOp& copyop):
_drawBuffer(camera._drawBuffer),
_readBuffer(camera._readBuffer),
_renderTargetImplementation(camera._renderTargetImplementation),
_renderTargetFallback(camera._renderTargetFallback),
_bufferAttachmentMap(camera._bufferAttachmentMap),
_postDrawCallback(camera._postDrawCallback)
{
@ -52,6 +53,27 @@ CameraNode::~CameraNode()
{
}
void CameraNode::setRenderTargetImplementation(RenderTargetImplementation impl)
{
_renderTargetImplementation = impl;
if (impl<FRAME_BUFFER) _renderTargetFallback = (RenderTargetImplementation)(impl+1);
else _renderTargetFallback = impl;
}
void CameraNode::setRenderTargetImplementation(RenderTargetImplementation impl, RenderTargetImplementation fallback)
{
if (impl<fallback)
{
_renderTargetImplementation = impl;
_renderTargetFallback = fallback;
}
else
{
osg::notify(osg::NOTICE)<<"Warning: CameraNode::setRenderTargetImplementation(impl,fallback) must have a lower rated fallback than the main target implementation."<<std::endl;
setRenderTargetImplementation(impl);
}
}
void CameraNode::setColorMask(osg::ColorMask* colorMask)
{
if (_colorMask == colorMask) return;

View File

@ -456,7 +456,7 @@ ImpostorSprite* Impostor::createImpostorSprite(osgUtil::CullVisitor* cv)
camera->setViewport(0,0,new_s,new_t);
// tell the camera to use OpenGL frame buffer object where supported.
camera->setRenderTargetImplementation(osg::CameraNode::FRAME_BUFFER_OBJECT);
camera->setRenderTargetImplementation(osg::CameraNode::FRAME_BUFFER_OBJECT, osg::CameraNode::FRAME_BUFFER);
// set the camera to render before the main camera.
camera->setRenderOrder(osg::CameraNode::PRE_RENDER);

View File

@ -18,6 +18,7 @@
#include <osg/Texture3D>
#include <osg/TextureRectangle>
#include <osg/TextureCubeMap>
#include <osg/GLExtensions>
#include <osgUtil/Statistics>
@ -151,6 +152,7 @@ void RenderStage::runCameraSetUp(osg::State& state)
if (!_camera) return;
osg::CameraNode::RenderTargetImplementation renderTargetImplemntation = _camera->getRenderTargetImplementation();
osg::CameraNode::RenderTargetImplementation renderTargetFallback = _camera->getRenderTargetFallback();
osg::CameraNode::BufferAttachmentMap& bufferAttachements = _camera->getBufferAttachmentMap();
@ -170,19 +172,15 @@ void RenderStage::runCameraSetUp(osg::State& state)
if (!fbo_supported)
{
// fallback to using pbuffer
#ifdef _WIN32
// Only Win32 currently support PBuffer RTT.
osg::notify(osg::INFO)<<"RenderStage::runCameraSetUp(State&): Using fallback to PIXEL_BUFFER_RTT"<<std::endl;
if (renderTargetImplemntation<renderTargetFallback)
renderTargetImplemntation = renderTargetFallback;
else
renderTargetImplemntation = osg::CameraNode::PIXEL_BUFFER_RTT;
#else
osg::notify(osg::INFO)<<"RenderStage::runCameraSetUp(State&): Using fallback to PIXEL_BUFFER"<<std::endl;
renderTargetImplemntation = osg::CameraNode::PIXEL_BUFFER;
#endif
}
else if (!_fbo)
{
osg::notify(osg::INFO)<<"Setting up osg::CameraNode::FRAME_BUFFER_OBJECT"<<std::endl;
_fbo = new osg::FrameBufferObject;
setDrawBuffer(GL_BACK);
@ -234,6 +232,15 @@ void RenderStage::runCameraSetUp(osg::State& state)
}
}
// check whether PBuffer-RTT is supported or not
if (renderTargetImplemntation==osg::CameraNode::PIXEL_BUFFER_RTT &&
!osg::isGLExtensionSupported(state.getContextID(), "ARB_render_texture"))
{
if (renderTargetImplemntation<renderTargetFallback)
renderTargetImplemntation = renderTargetFallback;
else
renderTargetImplemntation = osg::CameraNode::PIXEL_BUFFER;
}
// if any of the renderTargetImplementations require a seperate graphics context such as with pbuffer try in turn to
// set up, but if each level fails then resort to the next level down.
@ -390,12 +397,14 @@ void RenderStage::runCameraSetUp(osg::State& state)
if (renderTargetImplemntation==osg::CameraNode::PIXEL_BUFFER_RTT)
{
// fallback to using standard PBuffer, this will allow this while loop to continue
renderTargetImplemntation=osg::CameraNode::PIXEL_BUFFER;
if (renderTargetImplemntation<renderTargetFallback)
renderTargetImplemntation = renderTargetFallback;
else
renderTargetImplemntation = osg::CameraNode::PIXEL_BUFFER;
}
else
{
// fallback to using the frame buffer, this while loop will now exit.
renderTargetImplemntation=osg::CameraNode::FRAME_BUFFER;
renderTargetImplemntation = osg::CameraNode::FRAME_BUFFER;
}
}