Jump to content
  • Advertisement
Sign in to follow this  
Kest

Copy back buffer to texture or surface

This topic is 4422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sounds pretty simple, but I can't seem to find anything in the documentation to let me do it. Instead of asking how to copy the back buffer onto a texture surface level without locking the data, I'll just tell you exactly what I'm doing. Maybe there's a better way. I want to create a custom message box deal. Or more accurately, a confirmation window. It will just ask the player a question, and have yes and no buttons, along with an "auto-reply this answer next time". This window will be very small, and most of the screen will still be visible. I want the window to stop the game loop. It will update windows messaging itself, while it waits for the user to respond. But this means I need to keep painting the background. I've had problems trying to keep the same back buffer rendered every frame without updates, as some people seem to get horrible flickering bright colors where Direct3D or the graphics driver is clearing the data, for some unknown reason. So I'm guessing my best bet is to copy the current back buffer onto a texture when the window starts up, then keep drawing that texture onto the background. Anyone know if this can be done without a manual lock and copy? Or better yet, another way to halt the game loop and keep rendering the background behind the window? Thanks for any ideas.

Share this post


Link to post
Share on other sites
Advertisement
You could always use IDirect3DDevice9::GetRenderTargetData to capture whats on the screen.

Share this post


Link to post
Share on other sites
Quote:
Original post by Xmon
You could always use IDirect3DDevice9::GetRenderTargetData to capture whats on the screen.

Everyone please rate this guy up.

Share this post


Link to post
Share on other sites
If you want to get a copy of your back buffer to a texture that can be used for rendering you need to do the following.

Create a Texture with one Mipmap and the same Size as your back buffer in the default pool. Additional you should add D3DUSAGE_RENDERTARGET to your usage flags.

Now you can get the back buffer surface and the first mipmap for your texture.

Every time you want to store the current back buffer to your texture you have to use StretchRect. This will make the copy and you can use it like a regular texture.

There are some caps you should check like non power of 2 support.

Share this post


Link to post
Share on other sites
Quote:
Original post by Xmon
You could always use IDirect3DDevice9::GetRenderTargetData to capture whats on the screen.


Using GetRenderTargetData would move the data from VRAM to system memory. Then you'd need to push it back up to the GPU. That just doesn't make sense...

OP: Have a look at StretchRect. It's hardware optimized, and would support surfaces and/or textures.

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
Quote:
Original post by Xmon
You could always use IDirect3DDevice9::GetRenderTargetData to capture whats on the screen.


Using GetRenderTargetData would move the data from VRAM to system memory. Then you'd need to push it back up to the GPU. That just doesn't make sense...

It makes perfect sense, especially when you need to create an entire screen worth of temporary data to hold it. Throwing it into system memory is the safest way to go.

Quote:
OP: Have a look at StretchRect. It's hardware optimized, and would support surfaces and/or textures.

I appreciate the info, but the system memory backing is my best bet for this task. I just need to show a simple window. It will work well at any frame rate. Chugging up a huge chunk of video memory to temporarily show a little window just doesn't seem like the best way to go for this.

Thanks again.

Share this post


Link to post
Share on other sites
There is one other thing. Does anyone know if it is safe to get the contents of the back buffer outside of Device::Begin and Device::End? More accurately, after Device::Present?

Share this post


Link to post
Share on other sites
Hmm, see that's going to be a problem. The window will likely always show up in updating code.

I tested some things out with GetBackBuffer followed by D3DXSaveSurfaceToFile. I saved a screen cap before and after Present. In window mode, they were identical. But in full screen, the buffer was flipped on present, and the second snap was of the previous frame.

Is it dangerous beyound this? I mean can you rely on the second buffer to still contain your previous frame, as long as the application remains focused and such?

Otherwise, it looks impossible to do what I want.

Share this post


Link to post
Share on other sites
It depends on the swap effect you use.

Flip will cycle through your back buffer and do what you want. Discard could do anything.

But still then you have to be careful as there are tweaking tools out there (one written by myself) that allows player to force the usage of 3 back buffers. This will change the behavior.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!