Jump to content
  • Advertisement
Sign in to follow this  
Fire Lancer

Creating a managed texture from a render target

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

I have some stuff that is drawn in the same order every frame onto a flat surface. Exactly what is drawn is determined at the start of the level, so I can not simply make a new image in advance.

I figured it would be useful for performance if I was only drawing one thing each frame, and so I set it up to render the stuff onto a render target (texture created with D3DUSAGE_RENDERTARGET), which also meant I could unload all the other bits and pieces required to create it.

However, render targets must be D3DPOOL_DEFAULT, which must be destroyed to reset the device, and since I unloaded the other textures used to make it, recreating it again could be slow, etc.

So any I figured once I had my new texture I would make it into a managed texture. However I can not work out a way to go from a render target to a managed texture. I can not lock the render target, I can not use a managed texture with GetRenderTargetData, and I can use UpdateSurface/UpdateTexture it seems :(

Is the only way to do this to use some kind of multiple stage thing (render target -> system texture -> managed texture)? I would also like for the final managed texture to have a full mip map chain.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Fire Lancer
Is the only way to do this to use some kind of multiple stage thing (render target -> system texture -> managed texture)?


Yeah I think that's your best option, unfortunately. MANAGED textures are backed in system memory, which is how they can survive a device reset. So to get a render target into MANAGED you have to go through the CPU, which means using GetRenderTargetData and updating the managed texture.

Quote:
Original post by Fire Lancer
I would also like for the final managed texture to have a full mip map chain.


That's easy. Create your MANAGED texture with a full mip chain, and then fill the top level surface with the render target data. Then you can just call D3DXFilterTexture to fill out the mip chain.

Share this post


Link to post
Share on other sites
Ok, I was kind of hoping it would be possible to go straight into the system portion of a managed texture to avoid the extra copy on the system side and the creation of a temporary D3D object (although I guess creating a D3DPOOL_SYSTEMMEM resource is cheaper than default or managed anyway?).

Share this post


Link to post
Share on other sites
You didn't describe the kind of stuff you need to draw to the texture but if it is all 2D another option is to not use DirectX for the generation of the textures at all, and thus never need for anything to be a render target.

For example, you can use the FreeImage library to compose together png's, scale, and crop and so forth and then convert the results into managed textures using D3DXCreateTextureFromFileInMemory().

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!