PDA

View Full Version : FBO + rectangular textures



Aekold
11-02-2007, 06:35 AM
Hi,
I'm trying to create a renderable rectangular texture using FBO and GL_TEXTURE_RECTANGLE_NV extensions.
When I do that with regular GL_TEXTURE_2D target, all is OK, but in this case I have glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT
If this can help, my source code is following:
// Create frame buffer
glGenFramebuffersEXT(1, &m_frameBuffer);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer);
CHECK_GL;

// Create texture
glGenTextures(1, &m_texture);
glEnable(GL_TEXTURE_RECTANGLE_NV);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, m_texture);
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, TEX_SIZE, TEX_SIZE, 0, GL_RGB, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


// Create render buffer
glGenRenderbuffersEXT(1, &m_renderBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_renderBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, TEX_SIZE, TEX_SIZE);


// Attach render buffer and texture to fbo
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, m_texture, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, m_renderBuffer);


// Handle errors
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT || glGetError() != GL_NO_ERROR)
{
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, 0, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, 0);

glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);
glDeleteTextures(1, &m_texture);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glDeleteRenderbuffersEXT(1, &m_frameBuffer);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &m_frameBuffer);

throw std::exception("Bad framebuffer.");
}

Thanks,
Peter

Lindley
11-02-2007, 06:41 AM
I've never had trouble with GL_TEXTURE_RECTANGLE_ARB, but I haven't tried the _NV variant.

The other suspect bit I see is using GL_CLAMP_TO_EDGE. I haven't used that. I have used GL_CLAMP and GL_CLAMP_TO_BORDER successfully....

Aekold
11-02-2007, 06:57 AM
That didn't actually help. The same error.

Komat
11-02-2007, 07:01 AM
The texture uses GL_TEXTURE_RECTANGLE_NV target yet you are sometimes still using the GL_TEXTURE_2D. Most importantly in the call to the glFramebufferTexture2DEXT (the second case are the glTexParameteri calls).

yooyo
11-02-2007, 07:16 AM
you are create GL_TEXTURE_RECTANGLE_NV and use it as GL_TEXTURE_2D. This is not proper usage of FBO and textures.

Aekold
11-03-2007, 02:09 AM
Got it. Thanks, guys.