Commit a4808b33 authored by Christopher Tenter's avatar Christopher Tenter

FBO: render to 3D texture

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@19917 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b7922209
......@@ -66,6 +66,35 @@ init()
//-----------------------------------------------------------------------------
void FBO::attachTexture( GLenum _attachment, GLuint _texture, GLuint _level )
{
#ifdef GL_VERSION_3_2
// bind fbo
bind();
// add texture to frame buffer object
glFramebufferTexture( GL_FRAMEBUFFER_EXT, _attachment, _texture, _level );
// GLint layered = 0;
// glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER_EXT, _attachment, GL_FRAMEBUFFER_ATTACHMENT_LAYERED, &layered);
checkGLError();
// check status
checkFramebufferStatus();
// unbind fbo
unbind();
// track texture id
attachments_[_attachment] = std::pair<GLuint, GLenum>(_texture, GL_NONE);
#else
std::cerr << "error: FBO::attachTexture unsupported - update glew headers and rebuild" << std::endl;
#endif
}
//-----------------------------------------------------------------------------
void
FBO::
attachTexture2D( GLenum _attachment, GLuint _texture, GLenum _target )
......@@ -149,6 +178,46 @@ void FBO::attachTexture2D( GLenum _attachment, GLsizei _width, GLsizei _height,
//-----------------------------------------------------------------------------
void FBO::attachTexture3D( GLenum _attachment, GLsizei _width, GLsizei _height, GLsizei _depth, GLuint _internalFmt, GLenum _format, GLint _wrapMode , GLint _minFilter , GLint _magFilter )
{
// gen texture id
GLuint texID;
glGenTextures(1, &texID);
GLenum target = GL_TEXTURE_3D;
// store texture id in internal array
RenderTexture intID;
intID.id = texID;
intID.internalFormat = _internalFmt;
intID.format = _format;
intID.target = target;
internalTextures_.push_back(intID);
// specify texture
glBindTexture(target, texID);
glTexParameteri(target, GL_TEXTURE_WRAP_S, _wrapMode);
glTexParameteri(target, GL_TEXTURE_WRAP_T, _wrapMode);
glTexParameteri(target, GL_TEXTURE_WRAP_R, _wrapMode);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, _minFilter);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, _magFilter);
glTexImage3D(target, 0, _internalFmt, _width, _height, _depth, 0, _format, GL_FLOAT, 0);
checkGLError();
width_ = _width;
height_ = _height;
glBindTexture(target, 0);
// attach
attachTexture(_attachment, texID, 0);
}
//-----------------------------------------------------------------------------
void FBO::attachTexture2DDepth( GLsizei _width, GLsizei _height, GLuint _internalFmt /*= GL_DEPTH_COMPONENT32*/, GLenum _format /*= GL_DEPTH_COMPONENT */ )
{
// gen texture id
......@@ -443,7 +512,7 @@ void FBO::resize( GLsizei _width, GLsizei _height, bool _forceResize )
}
// check if we have to convert to multisampling
if (rt->target != GL_TEXTURE_2D_MULTISAMPLE && samples_ > 0)
if (rt->target == GL_TEXTURE_2D && samples_ > 0)
{
rt->target = GL_TEXTURE_2D_MULTISAMPLE;
reattachTextures = true;
......
......@@ -60,6 +60,11 @@ public:
/// get number of samples
GLsizei getMultisamplingCount() const {return samples_;}
/// attach a texture of arbitrary dimension (requires OpenGL 3.2)
void attachTexture( GLenum _attachment,
GLuint _texture,
GLuint _level = 0);
/// function to attach a texture to fbo
void attachTexture2D( GLenum _attachment,
GLsizei _width, GLsizei _height,
......@@ -78,6 +83,15 @@ public:
/// function to attach a stencil-buffer texture to fbo (texformat = GL_STENCIL_INDEX8)
void attachTexture2DStencil(GLsizei _width, GLsizei _height);
/// attach a 3D texture for render to volume (requires OpenGL 3.2)
/// binds all slices at once, target slice has to be chosen via gl_Layer in geometry shader
void attachTexture3D( GLenum _attachment,
GLsizei _width, GLsizei _height, GLsizei _depth,
GLuint _internalFmt, GLenum _format,
GLint _wrapMode = GL_CLAMP,
GLint _minFilter = GL_NEAREST,
GLint _magFilter = GL_NEAREST);
/// function to add a depth renderbuffer to the fbo
void addDepthBuffer( GLuint _width, GLuint _height );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment