PDA

View Full Version : creating depth texture without rendering twice?



Vexator
12-22-2006, 08:04 AM
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 :p 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?

CrazyButcher
12-22-2006, 09:08 AM
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).

Jackis
12-22-2006, 11:02 AM
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

Vexator
12-23-2006, 12:48 AM
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..?

jide
12-23-2006, 01:14 AM
If your texture was already generated, then use CopyTexSubImage, it is told to be faster. You don't need to CopyTexImage first.