Sign in to follow this  
slayer1983

how to change the backbuffer format on the fly?

Recommended Posts

slayer1983    100
When I load a bitmap from a file to a offscreen surface,and update it to the back surface,the format of the file is often different from the back buffer. So there must be a methed to change it on the fly.Can I refille the D3DPRESENT_PARAMETERS structure? how? thank for your reply:}

Share this post


Link to post
Share on other sites
Demirug    884
In your case Direct3D does not change your back buffer format. During the transfer the data is converted to the back buffer format.

Share this post


Link to post
Share on other sites
slayer1983    100
Quote:
Original post by Demirug
In your case Direct3D does not change your back buffer format. During the transfer the data is converted to the back buffer format.


Are you sure of that? When I run the app I just see the screen all white(the color I used in the clean()),and when the app ends I see "Direct3D9: (ERROR) :Source and dest surfaces are different formats. UpdateSurface fails"
in the output window.
the codes are:
		D3DXIMAGE_INFO ii;
D3DXGetImageInfoFromFile("photo.jpg",&ii);

IDirect3DSurface9* surfaceSource;
IDirect3DSurface9* surfaceBack;
//source surface必须是D3DPOOL_SYSTEMMEN,dest surface必须是D3DPOOL_DEFAULT
device->CreateOffscreenPlainSurface(ii.Width,ii.Height,ii.Format,D3DPOOL_SYSTEMMEM,&surfaceSource,0);
D3DXLoadSurfaceFromFile(surfaceSource,0,0,"photo.bmp",0,0,0,0);

device->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&surfaceBack);

device->Clear(0,0,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,0xffffffff,1.0f,0);
device->BeginScene();

device->UpdateSurface(surfaceSource,0,surfaceBack,0);

::showFPS(0,0,timeDelta,0xffff0000);
device->EndScene();
device->Present(0,0,0,0);
if(surfaceSource)
{
surfaceSource->Release();
surfaceSource=NULL;
}
if(surfaceBack)
{
surfaceBack->Release();
surfaceBack=NULL;
}


Share this post


Link to post
Share on other sites
Demirug    884
I was talking about the transfer from the file to the off-screen surface. You should create the off-screen surface with the same format as your back buffer. After this step D3DX should convert the format during the load operation.

Share this post


Link to post
Share on other sites
slayer1983    100
Quote:
Original post by Demirug
I was talking about the transfer from the file to the off-screen surface. You should create the off-screen surface with the same format as your back buffer. After this step D3DX should convert the format during the load operation.


yes .it really works, thank you for your help.
so is it to say that I definetly imposible to change the format of the back buffer after initialisition?

Share this post


Link to post
Share on other sites
Nik02    4348
I recommend transfering image data to the backbuffer by using a texture and drawing that texture to the screen by using a triangle. This is how the hardware is optimized to work - direct image transfers from user-mode application to video memory aren't nearly as efficient.

A bonus in my approach is that the formats needn't match, as long as the hardware just supports both source and destination format.

To change backbuffer format, you need to reset the device, which in turn requires you to reallocate all video memory resources (except managed resources, as d3d will handle their reallocation automatically if needed). It is relatively slow to reset the device because of the needed reallocations, both in the hardware and software.

Share this post


Link to post
Share on other sites
slayer1983    100
Quote:
Original post by Nik02
I recommend transfering image data to the backbuffer by using a texture and drawing that texture to the screen by using a triangle. This is how the hardware is optimized to work - direct image transfers from user-mode application to video memory aren't nearly as efficient.

A bonus in my approach is that the formats needn't match, as long as the hardware just supports both source and destination format.

To change backbuffer format, you need to reset the device, which in turn requires you to reallocate all video memory resources (except managed resources, as d3d will handle their reallocation automatically if needed). It is relatively slow to reset the device because of the needed reallocations, both in the hardware and software.



sounds good ~I will try it.thanks a lot~~:)

Share this post


Link to post
Share on other sites
Demirug    884
Quote:
Original post by slayer1983
yes .it really works, thank you for your help.
so is it to say that I definetly imposible to change the format of the back buffer after initialisition?


You can call Reset with an updated PresentParameter struture but I do not recommend updating the back buffer format based on the format of an image. It is possible that your image have a format that is not supported as back buffer format.

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