Sign in to follow this  

DXGI_FORMAT convert

This topic is 2519 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

Hi, ALL
I got a ID3D10Texture2D, its format is DXGI_FORMAT_B8G8R8X8_UNORM, How could I create a ID3D10Texture2D whose format is DXGI_FORMAT_R8G8B8A8_UNORM using the data of the first texture? thanks for answers.

Share this post


Link to post
Share on other sites
Something like this, if the texture is mappable (CPU read misc flags):

unsigned char data[width*height*4];
pB8G8R8X8Texture->Map(..);
for(y < height) {
unsigned char *row = (unsigned char*)map.pData + y * map.RowPitch;
for(x < width) {
data[y*width*4 + x*4 + 0] = row[x*4 + 2];// b->r
data[y*width*4 + x*4 + 1] = row[x*4 + 1];// g->g
data[y*width*4 + x*4 + 2] = row[x*4 + 0];// r->b
data[y*width*4 + x*4 + 3] = 255;// a
}
}
Unmap();

D3D10_SUBRESOURCE_DATA initData;
initData.pSysMem = data;
initData.SysMemPitch = width*4;
CreateTexture2D(..., &initData, &pR8G8B8A8Texure);


If the texture is not mappable, start by creating another B8G8R8X8 texture with D3D10_USAGE_STAGING usage and use CopyResource to copy your texture to it. Then map that staging texture and convert it to the new texture.

Another way is to create the R8G8B8A8 texture as a render target and bind the B8G8R8X8 texture as a shader resource, then render a textured quad to the new texture.

Share this post


Link to post
Share on other sites
Thank you Erik
The first advice you give sounds easily for me. but its performance is worse than the second advice.
But I am very very fresh to d3d10. So I dont know how to ..bind the B8G8R8X8 texture as a shader resource, then render a textured quad to the new texture.
Could anybody give me some documents or code snippets about this?
Thank you!

Share this post


Link to post
Share on other sites

This topic is 2519 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.

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