Changed the FrameBufferObject::setAttachment() methods so it now use osg::Camera::BufferComponent
to enable it to distinguish between MRT and non MRT paths
This commit is contained in:
@@ -571,8 +571,43 @@ FrameBufferObject::~FrameBufferObject()
|
||||
|
||||
void FrameBufferObject::setAttachment(GLenum attachment_point, const FrameBufferAttachment &attachment)
|
||||
{
|
||||
setAttachment(convertGLenumToBufferComponent(attachment_point),attachment);
|
||||
}
|
||||
|
||||
void FrameBufferObject::setAttachment(BufferComponent attachment_point, const FrameBufferAttachment &attachment)
|
||||
{
|
||||
GLenum gl_attachment = convertBufferComponentToGLenum(attachment_point);
|
||||
_attachments[attachment_point] = attachment;
|
||||
|
||||
updateDrawBuffers();
|
||||
dirtyAll();
|
||||
}
|
||||
|
||||
|
||||
GLenum FrameBufferObject::convertBufferComponentToGLenum(BufferComponent attachment_point) const
|
||||
{
|
||||
switch(attachment_point)
|
||||
{
|
||||
case(Camera::DEPTH_BUFFER): return GL_DEPTH_ATTACHMENT_EXT;
|
||||
case(Camera::STENCIL_BUFFER): return GL_STENCIL_ATTACHMENT_EXT;
|
||||
case(Camera::COLOR_BUFFER): return GL_COLOR_ATTACHMENT0_EXT;
|
||||
default: return GLenum(GL_COLOR_ATTACHMENT0_EXT + (attachment_point-Camera::COLOR_BUFFER0));
|
||||
}
|
||||
}
|
||||
|
||||
FrameBufferObject::BufferComponent FrameBufferObject::convertGLenumToBufferComponent(GLenum attachment_point) const
|
||||
{
|
||||
switch(attachment_point)
|
||||
{
|
||||
case(GL_DEPTH_ATTACHMENT_EXT): return Camera::DEPTH_BUFFER;
|
||||
case(GL_STENCIL_ATTACHMENT_EXT): return Camera::STENCIL_BUFFER;
|
||||
case(GL_COLOR_ATTACHMENT0_EXT): return Camera::COLOR_BUFFER;
|
||||
default: return BufferComponent(Camera::COLOR_BUFFER0+(attachment_point-GL_COLOR_ATTACHMENT0_EXT));
|
||||
}
|
||||
}
|
||||
|
||||
void FrameBufferObject::updateDrawBuffers()
|
||||
{
|
||||
_drawBuffers.clear();
|
||||
|
||||
// create textures and mipmaps before we bind the frame buffer object
|
||||
@@ -581,12 +616,9 @@ void FrameBufferObject::setAttachment(GLenum attachment_point, const FrameBuffer
|
||||
const FrameBufferAttachment &fa = i->second;
|
||||
|
||||
// setup draw buffers based on the attachment definition
|
||||
if (i->first >= GL_COLOR_ATTACHMENT0_EXT && i->first <= GL_COLOR_ATTACHMENT15_EXT)
|
||||
_drawBuffers.push_back(i->first);
|
||||
if (i->first >= Camera::COLOR_BUFFER0 && i->first <= Camera::COLOR_BUFFER15)
|
||||
_drawBuffers.push_back(convertBufferComponentToGLenum(i->first));
|
||||
}
|
||||
|
||||
|
||||
dirtyAll();
|
||||
}
|
||||
|
||||
void FrameBufferObject::apply(State &state) const
|
||||
@@ -663,7 +695,7 @@ void FrameBufferObject::apply(State &state) const
|
||||
for (AttachmentMap::const_iterator i=_attachments.begin(); i!=_attachments.end(); ++i)
|
||||
{
|
||||
const FrameBufferAttachment &fa = i->second;
|
||||
fa.attach(state, i->first, ext);
|
||||
fa.attach(state, convertBufferComponentToGLenum(i->first), ext);
|
||||
}
|
||||
dirtyAttachmentList = 0;
|
||||
}
|
||||
|
||||
@@ -340,43 +340,21 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo)
|
||||
osg::Camera::BufferComponent buffer = itr->first;
|
||||
osg::Camera::Attachment& attachment = itr->second;
|
||||
|
||||
switch(buffer)
|
||||
{
|
||||
case(osg::Camera::DEPTH_BUFFER):
|
||||
{
|
||||
fbo->setAttachment(GL_DEPTH_ATTACHMENT_EXT, osg::FrameBufferAttachment(attachment));
|
||||
depthAttached = true;
|
||||
break;
|
||||
}
|
||||
case(osg::Camera::STENCIL_BUFFER):
|
||||
{
|
||||
fbo->setAttachment(GL_STENCIL_ATTACHMENT_EXT, osg::FrameBufferAttachment(attachment));
|
||||
stencilAttached = true;
|
||||
break;
|
||||
}
|
||||
case(osg::Camera::COLOR_BUFFER):
|
||||
{
|
||||
fbo->setAttachment(GL_COLOR_ATTACHMENT0_EXT, osg::FrameBufferAttachment(attachment));
|
||||
colorAttached = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
fbo->setAttachment(GL_COLOR_ATTACHMENT0_EXT+(buffer-osg::Camera::COLOR_BUFFER0), osg::FrameBufferAttachment(attachment));
|
||||
colorAttached = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fbo->setAttachment(buffer, osg::FrameBufferAttachment(attachment));
|
||||
|
||||
if (buffer==osg::Camera::DEPTH_BUFFER) depthAttached = true;
|
||||
else if (buffer==osg::Camera::STENCIL_BUFFER) stencilAttached = true;
|
||||
else if (buffer>osg::Camera::COLOR_BUFFER) colorAttached = true;
|
||||
}
|
||||
|
||||
if (!depthAttached)
|
||||
{
|
||||
fbo->setAttachment(GL_DEPTH_ATTACHMENT_EXT, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_DEPTH_COMPONENT24)));
|
||||
fbo->setAttachment(osg::Camera::DEPTH_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_DEPTH_COMPONENT24)));
|
||||
}
|
||||
|
||||
if (!colorAttached)
|
||||
{
|
||||
fbo->setAttachment(GL_COLOR_ATTACHMENT0_EXT, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_RGB)));
|
||||
fbo->setAttachment(osg::Camera::COLOR_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_RGB)));
|
||||
}
|
||||
|
||||
fbo->apply(state);
|
||||
@@ -385,7 +363,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo)
|
||||
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"RenderStage::runCameraSetUp(), FBO setup failed, FBO status= 0x"<<std::hex<<status<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"RenderStage::runCameraSetUp(), FBO setup failed, FBO status= 0x"<<std::hex<<status<<std::endl;
|
||||
|
||||
fbo_supported = false;
|
||||
fbo_ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||
|
||||
Reference in New Issue
Block a user