0

I am looking to bind a new texture to an existing FBO. But at the moment it decreases my speed significantly.

        int holdTextureId = glGenTextures();

        glBindTexture(GL_TEXTURE_2D, 0);
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, panoramaModelsFboId); 

        glBindTexture(GL_TEXTURE_2D, holdTextureId);                                
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);                   
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);           
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, SAVE_WIDTH, SAVE_HEIGHT, 0,GL_RGBA, GL_INT, (java.nio.ByteBuffer) null);
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, holdTextureId, 0);

        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, panoramaModelsDepthRenderBufferId);              
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, SAVE_WIDTH, SAVE_HEIGHT);
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, panoramaModelsDepthRenderBufferId);

  //Rendering starts here..
  // After which I unbind the FBO and use the texture

I have a feeling glTexImage2D is the perpetrator, so perhaps creating the textures before this process starts is an idea? Also, I probably don't need to create the renderbuffer each time, but you can save me some time and tell me if it is needed :)

genpfault
  • 51,148
  • 11
  • 85
  • 139
RobotRock
  • 4,211
  • 6
  • 46
  • 86

1 Answers1

1

The performance hit lies in the call glTexImage2D which is a very expensive call. If you just want to bind a already existing texture, you don't have to create a new texture object, and also don't need to re-initialize it.

Just calling glFramebufferTexture2D is enough. No need to bind the texture in advance; in fact the texture must not be bound to be used as a framebuffer target.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • I do notice glFramebufferTexture2DEXT is a heavy call, not sure why. Do you happen to now how to make it faster? – RobotRock Jan 10 '13 at 19:43
  • @RobotRock: It might actually be, that previous rendering operations need to be finished, as glFramebufferTexture is a synchronization point. Using multiple textures and FBOs in a triple buffer fashion might help in that case. – datenwolf Jan 10 '13 at 20:57