Sign in to follow this  
sipickles

Copying part of one texture into another

Recommended Posts

Hi, Can anyone tell me the best way to copy one IDirect3DTexture9 to another? I specifically want to be able to copy part of one to part of another. I will be doing so at initialisation, so speed is not paramount. I am trying to attach together several procedurally generated textures to create a single one, thus avoiding unnecessary SetTexture() calls at run time. Many thanks Simon

Share this post


Link to post
Share on other sites
StretchRect and UpdateSurface can do what you want. Each has different limitations. UpdateSurface only works from a surface in the SYSMEM pool to one in the DEFAULT pool. StretchRect is more flexible but can only copy onto a render target (except for off-screen planes, which can be copied onto other off-screen planes).

If you want to copy everything into a normal texture in the MANAGED pool, the easiest way is probably to lock the end result (or use GetRenderTarget and lock the result of that) and copy to the texture.

Share this post


Link to post
Share on other sites
Can I simply lock both textures and perform a pixel to pixel looping copy, if both textures were of identical format?

If so how would I perform that copy?

Thanks

Si

Share this post


Link to post
Share on other sites
Render to a texture. If you want to copy the top-left quarter of your texture, render a quad from u = 0 -> 0.5 and v = 0 -> 0.5. Just make sure you render to the entire texture (basically rendering fullscreen, but to the texture).

Share this post


Link to post
Share on other sites
blaze, u r a genius! thats such an easier way of doing it. I got rendering to textures working the other day.

I'll try it right now!

Thanks

Share this post


Link to post
Share on other sites
You can use D3DXLoadSurfaceFromSurface to copy parts from one texture top level surface to another one. If your texture destination texture has mipmaps you should call D3DXFilterTexture as final operation to regenerate all mips.

Share this post


Link to post
Share on other sites
Quote:
Original post by sipickles
blaze, u r a genius! thats such an easier way of doing it. I got rendering to textures working the other day.


If you're going to use render targets, I'd suggest using StretchRect. Why go the ugly way when there's a function that already does what you want?

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