Discussion:
Buffering and Bliting in DirectX
(too old to reply)
Aaron Stubbendieck
2008-12-24 05:20:00 UTC
Permalink
Hello,

I'm new to DirectX and hope this isn't a basic question. I'm looking for
some hard suggestions (i.e. code or links to code) on how to implement this.

I'm building a charting control that plots points (500k+) using Direct3D
using Device.DrawUserPrimativies. This part all works correctly.

Now that I've rendered the points I'd like the user to be able to draw a
selection box over the data while dragging without replotting all the data
each time the mouse moves.

I'd do this in GDI+ by rendering my control to a bitmap and bliting to the
screen. Then when the mouse moved I would blit the stored bitmap and draw
the rectangle over it. What I need to know is: how to duplicate this in
DirectX?

I should be able to get a copy of the buffer with GetFrontBufferData into a
surface. But I don't know how to get the surface back into the main buffer
or even if this is the right approach.

Also, I'm working in C#.

Thanks
legalize+ (Richard [Microsoft Direct3D MVP])
2008-12-24 20:04:06 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by Aaron Stubbendieck
Now that I've rendered the points I'd like the user to be able to draw a
selection box over the data while dragging without replotting all the data
each time the mouse moves. [...]
The Direct3D way of doing this is to render everything into a plain
render target surface that is *not* your back buffer. Then to do a
quick refresh, you copy the plain render target contents to the back
buffer and draw your rectangle, then present.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Aaron Stubbendieck
2008-12-25 23:39:00 UTC
Permalink
Thank you for the response.

I think my confusion stems from the Surface object
(Microsoft.DirectX.Direct3D.Surface) has no direct DrawUserPrimatives or
anything similar. I can use Surface.GetGraphics to get a device context
which I can use GDI on, but I don't think that's what you're referring to.

Again, I'm new to this, so I need a bit of hand holding.

Thanks,
Aaron
Post by legalize+ (Richard [Microsoft Direct3D MVP])
[Please do not mail me a copy of your followup]
Post by Aaron Stubbendieck
Now that I've rendered the points I'd like the user to be able to draw a
selection box over the data while dragging without replotting all the data
each time the mouse moves. [...]
The Direct3D way of doing this is to render everything into a plain
render target surface that is *not* your back buffer. Then to do a
quick refresh, you copy the plain render target contents to the back
buffer and draw your rectangle, then present.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>
Legalize Adulthood! <http://blogs.xmission.com/legalize/>
faulty.lee
2008-12-26 05:31:49 UTC
Permalink
You can actually draw each point on the 3D view space instead of using
GDI. You will get some performance gain since it's graphic card
accelerated, GDI is not. If you do so, the plotting is done every
frame. Might seems over kill, but that's normal and it's what most 3D
game/app did it anyway. As for the selection box, you can draw a
rectangular box using lines or 2 triangle (transparent texture, or
semi transparent)

On Dec 26, 7:39 am, Aaron Stubbendieck
Post by Aaron Stubbendieck
Thank you for the response.
I think my confusion stems from the Surface object
(Microsoft.DirectX.Direct3D.Surface) has no direct DrawUserPrimatives or
anything similar.  I can use Surface.GetGraphics to get a device context
which I can use GDI on, but I don't think that's what you're referring to.
Again, I'm new to this, so I need a bit of hand holding.
Thanks,
Aaron
Post by legalize+ (Richard [Microsoft Direct3D MVP])
[Please do not mail me a copy of your followup]
Post by Aaron Stubbendieck
Now that I've rendered the points I'd like the user to be able to draw a
selection box over the data while dragging without replotting all the data
each time the mouse moves. [...]
The Direct3D way of doing this is to render everything into a plain
render target surface that is *not* your back buffer.  Then to do a
quick refresh, you copy the plain render target contents to the back
buffer and draw your rectangle, then present.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
      <http://www.xmission.com/~legalize/book/download/index.html>
        Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Aaron Stubbendieck
2008-12-28 17:25:01 UTC
Permalink
Right now I'm plotting every point in one plane of the 3D view. The
performance gain is noticeable over GDI. Still, my graph is so complicated
that if I plot every time the the selection box is redrawn, I can't achieve
performance much above 1 fps. That's why I'm trying to look into saving the
buffer and bliting.

I've been doing additional googling/MSDNing since my last post, and I've
seen some hints of changing the render target or using the swap chain, but
nothing specific.

Thanks
Post by faulty.lee
You can actually draw each point on the 3D view space instead of using
GDI. You will get some performance gain since it's graphic card
accelerated, GDI is not. If you do so, the plotting is done every
frame. Might seems over kill, but that's normal and it's what most 3D
game/app did it anyway. As for the selection box, you can draw a
rectangular box using lines or 2 triangle (transparent texture, or
semi transparent)
On Dec 26, 7:39 am, Aaron Stubbendieck
Post by Aaron Stubbendieck
Thank you for the response.
I think my confusion stems from the Surface object
(Microsoft.DirectX.Direct3D.Surface) has no direct DrawUserPrimatives or
anything similar. I can use Surface.GetGraphics to get a device context
which I can use GDI on, but I don't think that's what you're referring to..
Again, I'm new to this, so I need a bit of hand holding.
Thanks,
Aaron
Post by legalize+ (Richard [Microsoft Direct3D MVP])
[Please do not mail me a copy of your followup]
Post by Aaron Stubbendieck
Now that I've rendered the points I'd like the user to be able to draw a
selection box over the data while dragging without replotting all the data
each time the mouse moves. [...]
The Direct3D way of doing this is to render everything into a plain
render target surface that is *not* your back buffer. Then to do a
quick refresh, you copy the plain render target contents to the back
buffer and draw your rectangle, then present.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>
Legalize Adulthood! <http://blogs.xmission.com/legalize/>
legalize+ (Richard [Microsoft Direct3D MVP])
2008-12-27 03:07:39 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by Aaron Stubbendieck
I think my confusion stems from the Surface object
(Microsoft.DirectX.Direct3D.Surface) has no direct DrawUserPrimatives or
anything similar.
That's because only a device can draw primitives; a surface is just a
container of pixels.

When you use a device to draw, its using the back buffer as the render
target initially. However, you can set the render target to any
compatible surface, like a plain render target surface you've created.
So you set render target to the plain render target surface, draw the
heavy geometry, then set the render target surface to the back buffer,
copy the auxiliary surface to the back and draw the rectangle on the
back, then present.

Chapter 4. 2D Applications from my book covers the back buffer and presentation:
<http://www.xmission.com/~legalize/book/download/04-2D%20Applications.pdf>

Chapter 5. Modeling covers render targets:
<http://www.xmission.com/~legalize/book/download/05-Modeling.pdf>
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Loading...