Sign in to follow this  
killan

Copy RenderTarget texture to a new Texture lockable

Recommended Posts

Hello, (before, excuse me for my bad english) I search to copy a RenderTarget texture (non-lockable) to a new texture to lock it for read it. my code of RenderTarget texture is : textureTarget = new Texture(m_Device, Width, Height, 1, Usage.RenderTarget, m_Device.DisplayMode.Format, Pool.Default); textureBuffer = textureTarget.GetSurfaceLevel(0); backBuffer = m_Device.GetRenderTarget(0); And i want to copy textureTarget to a new Texture. Can you help me ? i have readed a lot of post here who talk about lockable surface but i need a Texture and not a Surface for my application Thank for all Killan

Share this post


Link to post
Share on other sites
Quote:
Original post by killan
i have readed a lot of post here who talk about lockable surface but i need a Texture and not a Surface for my application
A texture is just a collection of surfaces (arranged as a MIP chain), such that locking/reading from a texture is fundamentally the same as from a surface...

I don't know what the MDX equivalent is, but in C/C++ we have IDirect3DDevice9::GetRenderTargetData() which will copy from a render-target surface to a lockable sysmem surface. It should be sufficient for what you describe...

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by killan
ok but i need at last a texture object, how put the surface we obtains in a texture object ?
It's not amazingly intuitive, but you should be able to use IDirect3DDevice9::UpdateSurface() to re-upload it from sysmem to vram by pointing the destination surface as the top-level surface in your texture. You'll need to regenerate the mip-chain if you're using one.

hth
Jack

Share this post


Link to post
Share on other sites
by jollyjeffers

-----------------
Hi,

I recommend you re-post this information to your thread. More people will be able to read it, and they might have an answer for you

I don't use C# or .NET, so I can't help you with the exact code.

1. Create your texture as a render-target in the 'default' pool
2. Render to your texture
3. Create a temporary surface in system memory
4. Use GetRenderTargetData() or whatever the Managed DirectX version is to copy the data
5. Lock the temporary surface
6. Modify the temporary surface (like the code you sent in your message)
7. Use GetSurfaceLevel() (or the Managed DirectX equivalent) for your *original* texture to get the top-level surface
8. Use UpdateSurface() (or the MDX equivalent) to copy from your temporary surface to the one retrieved in step #7 (above).

I think that should work - but I've not tried it myself.

Because I haven't tried it, and because I'm not an MDX programmer, you might get a better answer by using the public thread in the DirectX forum...

hope that helps!

Jack

----------------------------------

i'll try it and back to say the result, thanks

Share this post


Link to post
Share on other sites
i have a problem to create the surface and GetRenderTargetData, i have use 2 differents methods

texturebuffer is textureTarget.GetSurfaceLevel(0);

1)

Surface surf = null;
m_Device.GetRenderTargetData(textureBuffer, surf);

i obtain "application error" erro message and nothing else, after executing the second line

2)

Surface surf = null;
m_Device.CreateOffscreenPlainSurface(width, height, m_Device.DisplayMode.Format, Pool.SystemMemory);
m_Device.GetRenderTargetData(textureBuffer, surf);

i obtain too the same error message

someone have an idea ?

Share this post


Link to post
Share on other sites
You have to use the Surface that CreateOffscreenPlainSurface returns as parameter for GetRenderTargetData.

Surface surf = m_Device.CreateOffscreenPlainSurface(width, height, m_Device.DisplayMode.Format, Pool.SystemMemory);
m_Device.GetRenderTargetData(textureBuffer, surf);


Don’t forget to dispose the offscreen surface after you don’t need it anymore.

Share this post


Link to post
Share on other sites
EDIT : Sorry for the error it is correct now

Quote:
Original post by killan
And i want to copy textureTarget to a new Texture.

Can you help me ?

i have readed a lot of post here who talk about lockable surface but i need a Texture and not a Surface for my application

Killan


hello killan i know the troubles u r facing to make render to texture work , that what happened with me also i have been trying to work with it for long time but nothing helped me till today it worked (at last) so am gonna give u the whole application i did but it is in c# it renders text to texture and mesh to texture and texture to texture so have fun and if u found that i helped u ADD my Rate :) check this:

www.2digital.tv/Data/render.zip

and u can reed my post on MSDN which helped me in making the application work:

http://forums.microsoft.com/MSDN/showpost.aspx?postid=325542&siteid=1

best regards

[Edited by - jad_salloum on April 2, 2006 7:09:52 AM]

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