Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to udpate the depth buffer without using glCopyPixels()

20 views
Skip to first unread message

Judie

unread,
Jan 16, 2008, 11:21:20 AM1/16/08
to
I am able to create a texture from the framebuffer and draw a quad as
my background with this texture instead of redrawing my background
each time.

I am able to save the depth buffer information and copy it back to the
depth buffer using glDrawPixels() and then I can render on top of the
background and if part of an object should be overlapped by the
background, it is not drawn as expected.

But what i really want is to be able to use the saved depth buffer as
a texture and apply it to my background quad and have it write to the
depth buffer so that I don't need to use the glDrawPixels(). It
doesn't seem like

glEnable2D();
glReadPixels(0, 0, Width, Height, GL_DEPTH_COMPONENT,
GL_UNSIGNED_INT, m_DepthBuffer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0,
GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, m_DepthBuffer);
glGenTextures(1, &m_DepthBufferTexture);
glBindTexture(GL_TEXTURE_2D, m_DepthBufferTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0,
GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, m_DepthBuffer);
glDisable2D();

was meant to do this because my rendering algorithm:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable2D();
glEnable(GL_TEXTURE_2D);
glColor3f( 1.0f, 1.0f, 1.0f );
glDepthFunc(GL_ALWAYS);

//render the background quad with the color texture

glDepthMask(GL_FALSE);
glBindTexture(GL_TEXTURE_2D, m_BackBufferTexture);
DrawBackgroundQuad();
glDepthMask(GL_TRUE);

//render the background quad with the color texture
glColorMask(0,0,0,0);
glBindTexture(GL_TEXTURE_2D, m_DepthBufferTexture);

DrawBackgroundQuad();
glColorMask(1,1,1,1);
glDepthFunc(GL_LEQUAL);

glDisable(GL_TEXTURE_2D);
glDisable2D();

DrawOtherObjects();

SwapBuffers(mhDC);

Doesn't seem to be putting the correct information into the depth
buffer. I am using OpenGL version 2.0. Has anybody used a texture for
the depth buffer in this way?

Judie

fungus

unread,
Jan 18, 2008, 7:31:53 AM1/18/08
to
On Jan 16, 5:21 pm, Judie <judie.m.stan...@gmail.com> wrote:
> Has anybody used a texture for the depth buffer in this way?
>

To answer the question: glDrawPixels() is the only way.

But...the general advice is "don't do it".

It's a nice theory but it's almost never faster than just
redrawing the whole scene. Modern graphics cards
store the depth buffer in compressed format so trying
to store/restore it is very inefficient. The background
has to be incredibly complex to make this worth while.

--
<\___/>
/ O O \
\_____/ FTB. Remove my socks for email address.

0 new messages