Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / DirectX Copy Textures Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Illco

March 18, 2005, 05:28 AM

Hello all,

I have a problem with copying textures under DirectX. Let me explain. I have one 'base' texture which contains a number of texture animation frames. At load time, I want to take the base texture and generate separate textures for each frame of animation (and afterwards discard the base texture). For each frame, I thus need to copy a rectangle of the base texture to the full frame texture. I currently use DirectX's StrecthRect function, but there are a number of problems:

1. For using StrechRect, the target texture should have D3DUSAGE_RENDERTARGET set. However, after the StrechtRect call this is of no use and I don't want to have it set.

2. For using StrechRect, the source and target textures must have the same format. For the input texture I use compressed DDS-files (DXT_1) which cannot be created at runtime, at least not with the appropriate usage flags.

Is there anyone who has experience with copying the contents of (parts of) textures differently? I figure one could use the D3DLOCKED_RECT structure and copy bits by hand, but this hasn't worked for me yet.

Any comments appreciated. Greets,

Illco

 
L.e.Denninger

March 18, 2005, 07:03 AM

Why not just leave your source-texture as-is,
and just adjust your uv-coordinates every render-frame to get the right frame of your animation ?

 
Illco

March 18, 2005, 08:19 AM

Because that would require me to lock the vertex buffer every frame, ajdust each uv coordinate and unlock it. That's already time consuming and if the meshes are complex (many vertices and hence many uv coordinates) it will kill the FPS. Moreover because multiple meshes are using the same animation, so I have to restore the uvs after adjusting them and repeat this for every instance. A definite no-no. But thanks for the reply.

 
Steven Hansen

March 18, 2005, 11:54 AM

Which memory pool is your source texture in? What flags are set on your base texture? Can it be used as the source of a DrawPrimitive operation? Can you render to different render targets (surfaces) and then pull the result from there into whatever texture you want with either stretch rect, or GetRenderTargetData? How are you getting from your compressed format to a typical RGB display format?

More details please...

 
Illco

March 18, 2005, 01:13 PM

Ok, more information coming up. The memory pool is currently D3DPOOL_DEFAULT but it could be changed. The flags on the base texture: similar story. It does not really matter; I can set it to anything because I'm creating the texture on the spot. Converting the texture to a displayable format is done by DX, as far as I know. The DDS format is directly readable by most cards or by the DX driver, I'm not sure. At least it is handled below application level.

As for GetRenderTargetData(): I didn't know about that call. Perhaps I could, after doing the StretchRect call onto a RT-surface, use GetRenderTargetData to put it on any texture. A bit of overhead, because the intermediate texture can be discarded, but if it works it works. Thanks; I will try that.

 
Gerald Knizia (cgk)

March 18, 2005, 01:18 PM

L.e.Denninger:

Why not just leave your source-texture as-is, and just adjust your uv-coordinates every render-frame to get the right frame of your animation?

Illco:
Because that would require me to lock the vertex buffer every frame, ajdust each uv coordinate and unlock it. [...]

Actually, this would not be neccessary. You could do the this using the texture coordinate transformation features of the hardware. This even works when using only the fixed pipeline (D3dDevice->SetTransform(D3DTS_TEXTURE0, .. ) and old cards.

For using StrechRect, the target texture should have D3DUSAGE_RENDERTARGET set. However, after the StrechtRect call this is of no use and I don't want to have it set.

Why? If you don't require that the texture is managed, that should not have any negative impact, afaik.

For using StrechRect, the source and target textures must have the same format. For the input texture I use compressed DDS-files (DXT_1) which cannot be created at runtime, at least not with the appropriate usage flags.

DXTn textures can be created at runtime. But they most probably cannot be used as render target.
You might be able to use the D3dDevice->UpdateSurface method (which copies rectangular regions of surfaces around, not quite what one would expect from the name) on the textures however. These don't need the RenderTarget flag set on the target textures.

 
Illco

March 18, 2005, 01:27 PM

Thanks Gerald -- I didn't know that! That will solve the problem because I can leave the original base texture intact and simply animate UV-coordinates. Denniger: if that was what you meant, thanks too.

 
This thread contains 7 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.