GetBackbuffer???

Started by
6 comments, last by Christoph 19 years, 11 months ago
Hi, I want to copy a part from the backbuffer to a surface in order to lock it and compare the color values with a key color. I''m using GetBackbuffer, but the surface this function gives me is not lockable. I have also tried to copy a part of the backbuffer to another surface with StretchRect - an error occurs here as well. Do you have a tip how I can lock a rect of the backbuffer and read the color values? thx
Advertisement
You have to specify D3DPRESENT_LOCKABLE_BACKBUFFER in D3DPRESENT_PARAMETERS::Flags when you create the device. (I''m not 100% positive on the flag and structure member names, but I think they''re close)

Note that requesting a lockable backbuffer puts the driver "at it's toes". It has to allocate a linear space in AGP memory for transferring the image back for the processor to use (and that can potentially take a huge amount of memory).
In games, locking the backbuffer is not recommended, for that reason; for productivity apps, it might not matter.

-Nik

EDIT: To clarify, taking a huge amount of extra memory == probable performance reduction. Not to mention that reading back from the video memory is slow in any case.

[edited by - Nik02 on May 26, 2004 4:07:44 PM]

Niko Suni

Thanks for your responses.
I have to lock the backbuffer, because I want to decide how much of the sun is visible. Thus, I can calculate perfect lens flares...
Have you looked at asynchronous notifications?

IDirect3DDevice::CreateQuery can create an occlusion query object, with which you can determine how many pixels pass the z testing. This count can be used in determining how much pixels have been occluded. This is very efficient, since drivers that support this capability track the number of occluded pixels anyway.

As the queries are asynchronous, the device returns the data if it can. If not ready, it bails quickly and returns the control to the calling thread, and you can use the previous value until the new value is ready to download.

Note that not all hardware will support asynch notification - you''d need to fall back to locking if this is the case.

-Nik

Niko Suni

Don''t lock the back-buffer for the sun visibility check...It''s simply too slow. I easily got ~40 FPS on a Radeon 8500 with 800x600 when reading the back-buffer back.

Either use occlusion culling as Nik02 suggests, or write your own software solution.

Right, the backbuffer function is working, but now the performance sucks ;-).
So, what exactly should I do? Before testing, I render everything but the skybox. My sun is a billboard of the color RGB(0,255,255).
How do I have to apply a query object in combination with the z-test? Can you please post the settings I have to use?
For an example of using occlusion queries, you can check one of the samples at ATI (don''t recall the name), and circlesoft''s occlusion culling tutorial

This topic is closed to new replies.

Advertisement