Skip to main content
GameDev.net gamedev.net
🔒 Locked

Reusing rendertarget

Started by yurixd Oct 27, 2005 at 5:54 AM 3 replies 1.2k views
Original Post
yurixd
yurixd
Hi!! Can someone tell me which is the easy and faster way and give me a small example code, of using the render target (surface...) as an input for a new pixel shader as texture, whithout reading back to the CPU memory??? I'm sure there is a esay way...but as Surfaces are different than textures, I don't knpow how exactly. Thank you!!!
Mezz
Mezz
Step 1.

Use the method IDirect3DDevice9::CreateTexture() to create a texture - this will serve both as your rendertarget and as the texture you will use. You must use D3DUSAGE_RENDERTARGET in the usage flags, and D3DPOOL_DEFAULT for the memory.

Step 2.

Render to your render target. Save your main render target surfaces, and then use IDirect3DTexture9::GetSurfaceLevel() to obtain the top level surface of your previously created (in step 1) texture. Use IDirect3DDevice9::SetRenderTarget() with this surface to set it as the current render target. After doing this you should call Release() on the surface pointer you obtained through GetSurfaceLevel() to maintain correct reference counts.

Step 3.

Restore your original screen render targets you saved as part of step 2. When you wish to use your rendered texture, simply call the usual IDirect3DDevice9::SetTexture() with the texture you created in step 1, and your texture will be available in a pixel shader.

Hope that helps.

-Mezz
yurixd
yurixd
hi,
Im sorry, maybe is for my english, but I dont really understand how to do it! In any case really thanks!

Step 1.

Use the method IDirect3DDevice9::CreateTexture() to create a texture - this will serve both as your rendertarget and as the texture you will use. You must use D3DUSAGE_RENDERTARGET in the usage flags, and D3DPOOL_DEFAULT for the memory. (Ok!)
For the moment I have a Texture, and I think I have to put in the levels value a 0! I dont need miplevels...

Step 2.

Render to your render target.
Which render target ? I have not set any render target and I dont have any surface yet....Can I make a SetRenderTarget using a Texture taht has been create with D3DUSAGE_RENDERTARGET ??

Save your main render target surfaces (whats for you my main render target surfaces, and how I should save them??), and then use IDirect3DTexture9::GetSurfaceLevel() to obtain the top level surface of your previously created (in step 1) texture.
After that, I will have the surface or my level 0 of my texture no??? But, How I know that it's going to render in the level 0 ??
In the case, I created a Texture with 3 levels, where is going to render??

Use IDirect3DDevice9::SetRenderTarget() with this surface (ok!) to set it as the current render target. After doing this you should call Release() on the surface pointer you obtained through GetSurfaceLevel() to maintain correct reference counts.

I dont understand how step 2 is working...!!!! Can you give me any simple example code ?

Step 3.

Restore your original screen render targets you saved as part of step 2 (backbuffer???)
When you wish to use your rendered texture, simply call the usual IDirect3DDevice9::SetTexture() with the texture you created in step 1, and your texture will be available in a pixel shader. (Ok!!!)

Hope that helps.

Sorry! But really thanks anyway, at least I have an idea, but not so clear I would want!!
Mezz
Mezz
Yeah, I think language might have got you a bit confused - here's what I was trying to say with Step 2.

Quote:

Step 2
Render to your render target.
Which render target ? I have not set any render target and I dont have any surface yet....

I was trying to title step 2 as 'rendering to your render target'. That is all.

Quote:

Can I make a SetRenderTarget using a Texture taht has been create with D3DUSAGE_RENDERTARGET ??


Yes! This is what I am trying to describe in Step 2.

Quote:

Save your main render target surfaces (whats for you my main render target surfaces, and how I should save them??)


Your main backbuffer. You can save them like this.

IDirect3DSurface9 *savedRenderTarget;
m_device->GetRenderTarget(0, &savedRenderTarget);

Quote:

then use IDirect3DTexture9::GetSurfaceLevel() to obtain the top level surface of your previously created (in step 1) texture.
After that, I will have the surface or my level 0 of my texture no??? But, How I know that it's going to render in the level 0 ??
In the case, I created a Texture with 3 levels, where is going to render??


Well, you can use GetSurfaceLevel() to get whichever level you want. The first parameter is which level you want, e.g.

IDirect3DSurface9 *surface;
myTexture->GetSurfaceLevel(0, &surface);

Gets you the top level surface (level 0).

I'll try some simple sample code of all the steps. This is off the top of my head, so might not be totally correct.

// create textureIDirect3DTexture9 *texture;D3DDevice->CreateTexture(width, height, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL);// save backbufferIDirect3DSurface9 *savedBackBuffer;D3DDevice->GetRenderTarget(0, &savedBackBuffer);// set up new render target (will render to level 0 of the texture)IDirect3DSurface9 *renderSurface;texture->GetSurfaceLevel(0, &renderSurface);D3DDevice->SetRenderTarget(0, renderSurface);renderSurface->Release();// do rendering to render target here... DrawIndexedPrimitive() etc. etc.// restore old render targetsD3DDevice->SetRenderTarget(0, savedBackBuffer);savedBackBuffer->Release();// and you're ready to use your texture!D3DDevice->SetTexture(0, texture);


Is that clearer?

-Mezz
yurixd
yurixd
Yes!
Thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.