Modifying the content of the depth buffer

Hello,

I was wondering if there was any way to manually modify the content of the depth buffer. I’d like to be able to manually set the depth value of specific pixels. I know there’s glReadPixels() to read values of the depth buffer but I haven’t found any functions to write to the depth buffer. I’ve also read about glDrawPixels(), but there doesn’t seem to be a way to specify the starting point of the pixels to draw. ie: drawing over a 4x4 pixel square from pixel (1000,800) to (1004,804).

Thanks

Use glWindowPos to set the origin of the destination rectangle.

Cheers, that works like a charm. Unfortunately, using glDrawPixels also kills my FPS when I have to draw over a large surface.

Looks like I’m going back to the drawing board.

[QUOTE=CodcULaval;1266668]Unfortunately, using glDrawPixels also kills my FPS when I have to draw over a large surface.

Looks like I’m going back to the drawing board.[/QUOTE]

Other options include using a framebuffer object with a depth texture and replacing portions with glTexSubImage2D(), and using a fragment shader which writes to gl_FragDepth.

Try first calling glClearDepth to select the value to clear it to.

Then enable scissor test and set a scissor rect to the area to be cleared.

Finally glClear (GL_DEPTH_BUFFER_BIT), and when done disable scissor test and restore your original glClearDepth value.

I’ve tried using textures but I’m still getting subpar results for what I want to accomplish. Using glDrawPixels was actually faster than using glTexSubImage2D.:dejection:

[QUOTE=mhagain;1266679]Try first calling glClearDepth to select the value to clear it to.

Then enable scissor test and set a scissor rect to the area to be cleared.

Finally glClear (GL_DEPTH_BUFFER_BIT), and when done disable scissor test and restore your original glClearDepth value.[/QUOTE]

I can’t afford to clear the depth buffer as it may already contain important information when my task is executed and the drawing can occur over the whole viewport area and not just small patches. For the same reasons, I’m not too sure of how scissoring could be useful here.

Cheers to both of you.

That’s where the scissor test comes in - glClear obeys the current scissor test options, so for your initial example:

drawing over a 4x4 pixel square from pixel (1000,800) to (1004,804)

You can use:

glEnable (GL_SCISSOR_TEST);
glScissor (1000, 800, 4, 4);
glClearDepth (value_to_set_depth_buffer_to);
glClear (GL_DEPTH_BUFFER_BIT);
glClearDepth (original);
glDisable (GL_SCISSOR_TEST);

And the small pixel square will be all that is cleared.

[QUOTE=mhagain;1266687]That’s where the scissor test comes in - glClear obeys the current scissor test options, so for your initial example:
You can use:

glEnable (GL_SCISSOR_TEST);
glScissor (1000, 800, 4, 4);
glClearDepth (value_to_set_depth_buffer_to);
glClear (GL_DEPTH_BUFFER_BIT);
glClearDepth (original);
glDisable (GL_SCISSOR_TEST);

And the small pixel square will be all that is cleared.[/QUOTE]

Ah okay, I understand now. I will have to test this method to see if it’s any faster than drawing.

Cheers