Drawing to front buffer

Started by
7 comments, last by amtri 16 years, 11 months ago
Hi there, Is there a Direct3D equivalent to the OpenGL calls glDrawBuffer(GL_FRONT) and glDrawBuffer(GL_BACK)? Thanks.
Advertisement
The closest thing I know of is the GetBackBuffer() method which retrieves device's backbuffer which you can modify as you please.

But still , even if there is such way to modify the front buffer manually it is extremely not recommended. There is a reason why you have back and front buffers.

Let DirectX do the dirty work for swapping the buffers for you to achieve a clean and smooth rendering as possible.
There is nothing that can't be solved. Just people that can't solve it. :)
I agree, always use the backbuffer.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Ideally you won't be directly manipulating any part of the implicit/explicit swap-chain.

Retrieving and swapping 'pointers' to the elements is required for some RtT operations and that's absolutely fine - but as soon as you want to start reading/writing the raw data you're going to be killing your performance [oh]

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Given that everybody seems to be of the opinion that I should draw to the back buffer, then I need one more pointer: all of a sudden I may decide that I need to draw to the front buffer. Since this is not possible, I will need to copy the front buffer to the back buffer, add to the back buffer, then present the back buffer.

How do I copy the front to the back buffer?

Thanks again.
I think the method is to render to texture the entire scene. Then render a fullscreen quad with that texture.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I thought it would be best if I could give an example of why I thought of writing to the front buffer in the first place.

The problem I have is that my scene is VERY large: maybe 10 million triangles or more. I know it will take time to draw it, but it's ok.

Now suppose I want to zoom into an area, and need to draw a rectangle picked with the mouse for the zoom area. All I want to do is to add the rectangle (or whatever shape I desire) to the front buffer without having to redraw everything. In other words, there is no z-buffering to be done at this point; just simply draw the rectangle on top of what I have.

Does that ring a bell with somebody?

Thanks.
Quote:Original post by amtri
I thought it would be best if I could give an example of why I thought of writing to the front buffer in the first place.

The problem I have is that my scene is VERY large: maybe 10 million triangles or more. I know it will take time to draw it, but it's ok.

Now suppose I want to zoom into an area, and need to draw a rectangle picked with the mouse for the zoom area. All I want to do is to add the rectangle (or whatever shape I desire) to the front buffer without having to redraw everything. In other words, there is no z-buffering to be done at this point; just simply draw the rectangle on top of what I have.

Does that ring a bell with somebody?

Thanks.
Render the whole scene to a texture, then render one quad per frame after that, with the texture applied to the quad. Then you can draw whatever you want on top of it (A selection rectangle for instance).
Evil Steve,

It's a good idea, but I would have to do it all the time since I never know when I'm going to need to write to the front buffer.

So I compromised: I count on the hardware's speed and create my device with the option of copying the back buffer into the front buffer. This means both are equal until the next image primitive is drawn.

As long as everything remains synchronized - i.e., the flag to draw to the front buffer is triggered before any new entities are drawn - then the front and back buffers are equal. Then I draw and immediately Present.

It works.

Thanks all!

This topic is closed to new replies.

Advertisement