Results 1 to 4 of 4

Thread: glCopyTexImage2D problem

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    27

    glCopyTexImage2D problem

    I use glCopyTexImage2D to copy the depth buffer to a texture:
    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_DEPTH_COMPONENT , 0, 0, m_nCurrentW, m_nCurrentH, 0);

    However, I found the memory usage keep increasing. There are anything I did wrong?
    and how to use glCopyTexSubImage2D to read the depth buffer? Thanks!

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    569

    Re: glCopyTexImage2D problem

    If you're creating a new texture object (glGenTextures()) each time before uploading your data with glCopyTexSubImage2D then you'll be wasting memory. Create the texture object once and then just bind the same one before your texture upload.

    In order to use the depth buffer as a texture using glCopyTexImage you'll need to read the frame buffer into memory first using glReadPixels using the GL_DEPTH_COMPONENT enumeration. This is because glCopyTexImage expects the texture data to be in system memory.

    An alternative (which saves you the data transfer overhead - which is significant by the way) is to render the scene to a pbuffer (or frame buffer object - which im not sure is available yet) and write a fragment shader that that sets the fragment color's RGB value to that fragments z-depth. In the end you get a grayscale image that is a representation of your depth buffer - you can then bind the frame buffer object or the pbuffer as a texture.

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: glCopyTexImage2D problem

    Originally posted by Aeluned:
    In order to use the depth buffer as a texture using glCopyTexImage you'll need to read the texture buffer into memory first using glReadPixels using the GL_DEPTH_COMPONENT enumeration. This is because glCopyTexImage expects the texture data to be in system memory.
    That's wrong. Spec says:
    "The image is taken from the framebuffer exactly as if these arguments were passed to
    CopyPixels with argument type set to COLOR or DEPTH, depending on internalformat,..."

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    569

    Re: glCopyTexImage2D problem

    Oops, that's right...
    I stand corrected.

Similar Threads

  1. glCopyTexImage2D
    By devdept in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 09-20-2008, 02:19 PM
  2. Problem using glCopyTexImage2d
    By sergi in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 05-22-2002, 10:02 AM
  3. glCopyTexImage2D Problem -> Texture to copy bigger than frame buffer
    By Kilam Malik in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 03-13-2002, 12:03 AM
  4. problem with using of glCopyTexImage2D.
    By vincent.guerin in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 01-16-2002, 03:59 AM
  5. glCopyTexImage2D Problem
    By jra101 in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 01-24-2001, 03:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean