creating depth texture without rendering twice?

i’m using a multipass algorithm, so my 1st pass is depth only. i’d like to create a depth texture each frame as i need it in various shaders. so far i’m simply copying the rendered scene to a texture using glCopyTexImage2D. screen resolution is 1280x1024, texture resoltion is 1024x1024, so there’s a bit missing on the right side of the texture :stuck_out_tongue: i could resize the viewport and render again, but i’d like to do it in one pass.

do fbo guarantee to support non-power-of-two dimensions? is there a way to render the scene to a fbo without having to render it twice? i. e. can i render to the screen and to a fbo simultaneously?

you could always just render a quad to the framebuffer with your fbo attached colorbuffer, but as seen in the other thread, rendering directly to framebuffer is quickest.

you could copytex to a rectangle texture instead (pretty widely supported).

Yes, the rectangular texture variant is most appropriate, I hope.

The main difference are that RECT textures don’t have mip-mapping, they can be used only with GL_CLAMP_TO_EDGE, and addressing is not [0…1], but [0…width, 0…height].

Usage is just like 2D: glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, 0, 0, width, height);

See spec for more info: http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt

jep this works fine, thank you!
one general question: when am i supposed to use glCopyTexImage2D and when glCopyTexSubImage2D? is it that i have to use glCopyTexImage2D initially and then i can use glCopyTexSubImage2D? i tried that, but performance was the same as when i used glCopyTexImage2D only…?

If your texture was already generated, then use CopyTexSubImage, it is told to be faster. You don’t need to CopyTexImage first.