Sign in to follow this  
51mon

How to control the size of the backbuffer?

Recommended Posts

I have a thing I want to implement. I don't think it should be too difficult to accomplish but don’t know exactly how and would appreciate a good advice. I have implemented an app based on the framework following the SDK. I want the window to be freely resizable but the backbuffer size to be an even multiple of some number (64 for example). The rendered surface will therefore not necessary fill the window completely. How will I do this best? I tried with this: bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps, void* pUserContext ) { // ... pDeviceSettings->pp.BackBufferHeight -= pDeviceSettings->pp.BackBufferHeight % iMultipleOfThisNumber; pDeviceSettings->pp.BackBufferWidth -= pDeviceSettings->pp.BackBufferHeight % iMultipleOfThisNumber; But it didn’t work.

Share this post


Link to post
Share on other sites

Exactly how didn't it work? That might help you get some better replies.

I'll assume you're already resetting your device so the code above is actually called. Here's some code that works for me to determine the closest power of two for any given number:

exponent = round( log(youNumber) / log(2) )
closest = pow(2, exponent)

If you mean it's still filling your window even with a smaller backbuffer, this might be a expected behavior. IIRC d3d actually will try to stretch the backbuffer over the client area by default in windowed mode.

Hope this helps somewhat :)

Share this post


Link to post
Share on other sites
Sorry, I explain better :)
I wanted the window to have free size but the rendered surface to be restricted. The code that I tested filled the window completely. This is not a big deal but I got another more disturbing problem. If I put a breakpoint inside the code I can see that that the size of pDeviceSettings->pp.BackBufferHeight and pDeviceSettings->pp.BackBufferWidth are correct at startup. If I then resize the window, both of these values are resetted to 0. It’s make the app break down. Is the app supose to act this way? How do I fix it? Is there might some DXUT function to use?

Share this post


Link to post
Share on other sites
I don't think it's the DXUT framework that is reseting the backbuffer size back to 0, as that would probably break any application. Maybe it does get confused because your code modifies the backbuffersize so it doesn't match the window client area anymore, but I doubt that's what is happening. Are you sure the code you posted calculates a correct backbuffer size and that the ModifyDeviceSettings method is called when the window is resized?

Why do you want to have a power-of-two backbuffer anyway? Rendertargets such as the backbuffer don't have the size restriction regular textures have and the performance also doesn't take a big hit, so I'm a bit puzzled why you'd need this.

Share this post


Link to post
Share on other sites
Quote:
Original post by remigius
I don't think it's the DXUT framework that is reseting the backbuffer size back to 0, as that would probably break any application. Maybe it does get confused because your code modifies the backbuffersize so it doesn't match the window client area anymore, but I doubt that's what is happening. Are you sure the code you posted calculates a correct backbuffer size and that the ModifyDeviceSettings method is called when the window is resized?

Why do you want to do have a power-of-two backbuffer anyway? Rendertargets such as the backbuffer don't have the size restriction regular textures have and the performance also doesn't take a big hit, so I'm a bit puzzled why you'd need this.


The reason for having a power-of-two backbuffer is the nature of the algorithm I'm working with. I do some custom mip-maping. Even if I don't touch the backbuffer size but just put a breakpoint inside ModifyDeviceSettings, the pDeviceSettings->pp is incorrect when resizing the window.

Share this post


Link to post
Share on other sites
This appears to work:

	int iMultipleOfThis = pow(2.0f, g_iHighestLevel-1);
if( pDeviceSettings->pp.BackBufferWidth == 0 )
{
RECT RectWindow = DXUTGetWindowClientRect();
pDeviceSettings->pp.BackBufferWidth = RectWindow.right - RectWindow.right % iMultipleOfThis;
pDeviceSettings->pp.BackBufferHeight = RectWindow.bottom - RectWindow.bottom % iMultipleOfThis;
}
else
{
pDeviceSettings->pp.BackBufferWidth -= pDeviceSettings->pp.BackBufferWidth % iMultipleOfThis;
pDeviceSettings->pp.BackBufferHeight -= pDeviceSettings->pp.BackBufferHeight % iMultipleOfThis;
}




I don’t know if it’s an optimal solution or its performance conditions. Thanks for the help, though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this