Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: single fbo and multiple texture attachments

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    21

    single fbo and multiple texture attachments

    I want to use a single fbo and multiple texture attachments. I attach textures to different color attachments.
    Then I use glDrawBuffers to switch rendering to different color attachments.

    Textures have different formats and resolutions:
    Code :
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    glBindTexture(GL_TEXTURE_2D, tex1);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, 1024, 1024, 0, GL_RGBA, GL_FLOAT, NULL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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);
    glBindTexture(GL_TEXTURE_2D, 0);
     
    glBindTexture(GL_TEXTURE_2D, tex2);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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);
    glBindTexture(GL_TEXTURE_2D, 0);
     
     
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex1, 0);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex2, 0);
     
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
     
    GLenum drawBuffers0[] = {GL_COLOR_ATTACHMENT0};
    GLenum drawBuffers1[] = {GL_COLOR_ATTACHMENT1};

    Rendering:

    Code :
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    glDrawBuffers(1, drawBuffers1);
    glViewport(0, 0, 256, 256);
    shader1.enable();
    object1.draw();
    shader1.disable();
     
    glDrawBuffers(1, drawBuffers0);
    glViewport(0, 0, 1024, 1024);
    shader2.enable();
    object2.draw();
    shader2.disable();
     
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    tex1 contains only part of the screen (1/4x, 1/4y). What is wrong ?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    590
    AFAIK all attachments must be the same size. You should check for completeness when constructing FBOs

    Code :
        GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if( status != GL_FRAMEBUFFER_COMPLETE)

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    21
    Ok, I have one more question. Is it possible to clear only one texture this way ?:
    Code :
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    glDrawBuffers(1, drawBuffers0);
    glClear(GL_COLOR_BUFFER_BIT);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •