Switch render target

Started by
4 comments, last by circlesoft 18 years, 8 months ago
Hi. A beautiful evening we have. And I'm digging into shaders more and more. So I want to switch render target to a texture('s surface level 0). Then render, as usuall, and then switch back, and use the texture in the later passes. So I first: - get the original target, and acquire its decription, - create a texture with same parameters (width, height, format, pool) and usage RENDERTARGET, Then, before rendering I: - call SetRenderTarget(0, pSurface), got S_OK, - call Clear(..., D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, ...) and BAM! "MultiSampleType between DepthStencil Buffer and RenderTarget must match." So I checked. The device has: d3dpp.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE; d3dpp.MultiSampleQuality = 2; Which seems to be ok. Now, I read the F.Manual and there's only an example using CreateRenderTarget, where they tell me to set proper multisample type. But with creating a render-target-texture, there's no such option. So 2 (exclusive) questions: 1.) Can I set the Multisample type when creating the texture? Or should I simply change the resolution, or some other tricky thing? 2.) Can I use CreateRenderTarget and somehow transform it to a texture for later use? Thanks. ~def
Advertisement
Quote:Original post by deffer
So I want to switch render target to a texture('s surface level 0). Then render, as usuall, and then switch back, and use the texture in the later passes.

.
.
.

2.) Can I use CreateRenderTarget and somehow transform it to a texture for later


If you want to use a RT later as a texture, you have to create a texture interface, not a surface. So instead of CreateRenderTarget(), you must use CreateTexture(), with D3DUSAGE_RENDERTARGET.

To get your surface for the SetRenderTarget(), just use IDirect3DTexture9::GetSurfaceLevel( 0 ) - this will give you a surface on the texture. After rendering, you can then turn around and use this texture in a ID3DXEffect::SetTexture() call.

By the way, when you call GetSurfaceLevel(), the reference count on the surface it returns is increased. This means you should release it.

Also, since you have to create a texture now, you can't do multisampling.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Quote:Original post by circlesoft
If you want to use a RT later as a texture, you have to create a texture interface, not a surface. So instead of CreateRenderTarget(), you must use CreateTexture(), with D3DUSAGE_RENDERTARGET.

To get your surface for the SetRenderTarget(), just use IDirect3DTexture9::GetSurfaceLevel( 0 ) - this will give you a surface on the texture. After rendering, you can then turn around and use this texture in a ID3DXEffect::SetTexture() call.

That's exactly what I'm doing now, so no prob here. Don't want to be picky, but I already told that [grin]

Quote:
Also, since you have to create a texture now, you can't do multisampling.


Do you mean, that I cannot do multisampling at all? Or do I have to somehow switch it off during rendering?
~def
Ah, sorry. Apparently I have lost my reading ability [crying]

First, try changing your multisample to D3DMULTISAMPLE_NONE and quality to 0. It should work then.

I suppose your are getting that error because the depth buffer and active RT must match. However, since you can't create a multisampled texture, you can't match a depth stencil that is multisampled.

The solution would be to create a matching depth stencil surface for use with your texture rendertarget, using CreateDepthStencilSurface(). Then, just use SetDepthStencilSurface(). This way, you can keep your backbuffer multisampled and still use RTs.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Well, that's not the answer I was looking forward to get [depressed]

Yes, it works *great* with no multisampling...
If it won't work any other way, so be it (* Multisampling->Off() *)

Thanks for your effort (in all my RT threads).
~def
Quote:Original post by deffer
Well, that's not the answer I was looking forward to get [depressed]

Yes, it works *great* with no multisampling...
If it won't work any other way, so be it (* Multisampling->Off() *)

Thanks for your effort (in all my RT threads).
~def

Did you try creating the separate depth buffer for the RT? This would allow you to keep multisampling on for the backbuffer.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

This topic is closed to new replies.

Advertisement