From 656a1b6da50703c8b41230f1e471f1bf5ed8a8f6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 1 Jun 2010 14:12:03 +0000 Subject: [PATCH] From Frederic Bouvier, "here is my proposal. It is supposed to be used like this : osg::Camera* c = createCamera(); c->attach( osg::Camera::COLOR_BUFFER0, texture3d, 0, osg::Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER ); it works also for cubemap textures and 2d texture arrays " --- include/osg/Camera | 2 ++ include/osg/FrameBufferObject | 2 ++ src/osg/Camera.cpp | 2 ++ src/osg/FrameBufferObject.cpp | 18 +++++++++++++++--- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/osg/Camera b/include/osg/Camera index d2ae3a50f..5eb3dc216 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -330,6 +330,8 @@ class OSG_EXPORT Camera : public Transform, public CullSettings COLOR_BUFFER15 = COLOR_BUFFER0+15 }; + static const unsigned int FACE_CONTROLLED_BY_GEOMETRY_SHADER; + /** Attach a buffer with specified OpenGL internal format.*/ void attach(BufferComponent buffer, GLenum internalFormat); diff --git a/include/osg/FrameBufferObject b/include/osg/FrameBufferObject index 3a84c4a29..4401450b1 100644 --- a/include/osg/FrameBufferObject +++ b/include/osg/FrameBufferObject @@ -157,6 +157,7 @@ namespace osg typedef void GL_APIENTRY TglFramebufferTexture1D(GLenum, GLenum, GLenum, GLuint, GLint); typedef void GL_APIENTRY TglFramebufferTexture2D(GLenum, GLenum, GLenum, GLuint, GLint); typedef void GL_APIENTRY TglFramebufferTexture3D(GLenum, GLenum, GLenum, GLuint, GLint, GLint); + typedef void GL_APIENTRY TglFramebufferTexture(GLenum, GLenum, GLint, GLint); typedef void GL_APIENTRY TglFramebufferTextureLayer(GLenum, GLenum, GLuint, GLint, GLint); typedef void GL_APIENTRY TglFramebufferRenderbuffer(GLenum, GLenum, GLenum, GLuint); typedef void GL_APIENTRY TglGenerateMipmap(GLenum); @@ -176,6 +177,7 @@ namespace osg TglFramebufferTexture1D* glFramebufferTexture1D; TglFramebufferTexture2D* glFramebufferTexture2D; TglFramebufferTexture3D* glFramebufferTexture3D; + TglFramebufferTexture* glFramebufferTexture; TglFramebufferTextureLayer* glFramebufferTextureLayer; TglFramebufferRenderbuffer* glFramebufferRenderbuffer; TglGenerateMipmap* glGenerateMipmap; diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index 3b3584e1b..ccef7f8bd 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -16,6 +16,8 @@ using namespace osg; +const unsigned int Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER = 0xffffffff; + Camera::Camera(): _view(0), _allowEventFocus(true), diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index cb23a82f5..ce94c3014 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -55,6 +55,7 @@ FBOExtensions::FBOExtensions(unsigned int contextID) glFramebufferTexture1D(0), glFramebufferTexture2D(0), glFramebufferTexture3D(0), + glFramebufferTexture(0), glFramebufferTextureLayer(0), glFramebufferRenderbuffer(0), glGenerateMipmap(0), @@ -73,6 +74,7 @@ FBOExtensions::FBOExtensions(unsigned int contextID) LOAD_FBO_EXT(glFramebufferTexture1D); LOAD_FBO_EXT(glFramebufferTexture2D); LOAD_FBO_EXT(glFramebufferTexture3D); + LOAD_FBO_EXT(glFramebufferTexture); LOAD_FBO_EXT(glFramebufferTextureLayer); LOAD_FBO_EXT(glFramebufferRenderbuffer); LOAD_FBO_EXT(glGenerateMipmap); @@ -90,6 +92,7 @@ FBOExtensions::FBOExtensions(unsigned int contextID) glFramebufferTexture1D != 0 && glFramebufferTexture2D != 0 && glFramebufferTexture3D != 0 && + glFramebufferTexture != 0 && glFramebufferRenderbuffer != 0 && glGenerateMipmap != 0 && glGetRenderbufferParameteriv != 0; @@ -554,16 +557,25 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen ext->glFramebufferTexture2D(target, attachment_point, GL_TEXTURE_2D_MULTISAMPLE, tobj->id(), _ximpl->level); break; case Pimpl::TEXTURE3D: - ext->glFramebufferTexture3D(target, attachment_point, GL_TEXTURE_3D, tobj->id(), _ximpl->level, _ximpl->zoffset); + if (_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER) + ext->glFramebufferTexture(target, attachment_point, tobj->id(), _ximpl->level); + else + ext->glFramebufferTexture3D(target, attachment_point, GL_TEXTURE_3D, tobj->id(), _ximpl->level, _ximpl->zoffset); break; case Pimpl::TEXTURE2DARRAY: - ext->glFramebufferTextureLayer(target, attachment_point, tobj->id(), _ximpl->level, _ximpl->zoffset); + if (_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER) + ext->glFramebufferTexture(target, attachment_point, tobj->id(), _ximpl->level); + else + ext->glFramebufferTextureLayer(target, attachment_point, tobj->id(), _ximpl->level, _ximpl->zoffset); break; case Pimpl::TEXTURERECT: ext->glFramebufferTexture2D(target, attachment_point, GL_TEXTURE_RECTANGLE, tobj->id(), 0); break; case Pimpl::TEXTURECUBE: - ext->glFramebufferTexture2D(target, attachment_point, GL_TEXTURE_CUBE_MAP_POSITIVE_X + _ximpl->cubeMapFace, tobj->id(), _ximpl->level); + if (_ximpl->cubeMapFace == Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER) + ext->glFramebufferTexture(target, attachment_point, tobj->id(), _ximpl->level); + else + ext->glFramebufferTexture2D(target, attachment_point, GL_TEXTURE_CUBE_MAP_POSITIVE_X + _ximpl->cubeMapFace, tobj->id(), _ximpl->level); break; } }