   Difference: render to surface / render to device
  Hi,I googled around a lot and found basically two ways to render contents to a directX device.The first way is to render directly to the device (that's what I call it :~):<code>IDirect3DDevice9* pDevice; //for simplicity no initialization code herepDevice->Clear();pDevice->BeginScene();HRESULT hResult = pDevice->DrawPrimitiveUP( /* ... */ );pDevice->EndScene();pDevice->Present();</code>The second way I found is to render first to a surface and then the complete surface at once to the device:<code>IDirect3DDevice9* pDevice; //for simplicity no initialization code here// now comes the new part of the code: I will first render to surface...CSurface* pBackBuffer; // created by D3DXCreateTexture() and GetSurfaceLevel();ID3DXRenderToSurface* pRenderTarget; // created by D3DXCreateRenderToSurface();pRenderTarget->BeginScene(pSurface, 0);pDevice->SetTexture(0); pDevice->DrawPrimitiveUP( /* ... */ );pRenderTarget->EndScene(D3DTEXF_NONE);// ... and then to the device: the whole surface at once.pDevice->Clear();pDevice->BeginScene();pDevice->SetTexture(pTexture);pDevice->DrawPrimitiveUP( /* ... */ ); //Rendering now the Texture to the device.pDevice->EndScene();pDevice->Present();</code>---------------------My question now is:What benefits do I get from the second approach? Is it faster? For me it looks like I just put one more step in the row. Is there less flickering? Do I have more possibilities with the second approach?My second question is:I found a forum-thread where they told that it is no advised to render directly into a surface, because it would destroy performance. The thread applied to managed directx. Is this true? Does it apply to unmanaged DirectX also? Is it slower to render to surfaces?   
  Hi,For now, I can answer only your 1st question:Quote:What benefits do I get from the second approach? Is it faster? For me it looks like I just put one more step in the row. Is there less flickering? Do I have more possibilities with the second approach?I can't say anything about performance. But I can say "Yes, you've more possibilities." For example, If you want to use some image effects (e.g. Custom HDR techniques (like Bloom, Glare genereation etc.), Motion Blur, Depth of Field, Heat Vision, Light Scattering etc.), you should render your scene to a texture/surface. Many new gen games don't use directly backbuffer as a scene render target. They use textures/surfaces and applying their effects to the image in that render target texture. You'll see that it's more efficient. But there're some extra lines to be written so that you can show your result on the screen/display. This is called "Rendering full screen quad" and the only case you'll use the backbuffer.   ;  Thank you for your fast reply!But doesn't it cost you performance when you render first to a texture?(Yes you said that you can't say anything ybout performance. But isn't it at least an extra step?)Greetings Snowprog   ;  Hi,Quote:... doesn't it cost you performance when you render first to a texture?... isn't it at least an extra step?Just a little example: When I render a mesh consists of approx. 6000 triangles to;* directly backbuffer, I get 800 FPS,* render target surface (then rendering this texture with full-screen quad), I  get 798-799 FPS with my HD2600 Pro.It doesn't cost any performance, I think :)   ;  It depends - the GPU has another full screen of pixels to render. If you have an expensive pixel shader when rendering your texture to the screen, then it'll be slower, or if the GPU is already fillrate bound.Also, you can't get realistic measurements when running at 800FPS, try giving the GPU more work to do and get down to ~30 FPS, then see what difference a render target makes [smile]To answer the original question; it's just more flexible. You tend to only use render targets when you need them for special effects.   ;  Thank you for your answers.Right now I think the best solution will be to design the application for both possibilities. I will design the classes so that it is transparent how the final rendering will be done. So I can switch at anytime to the one or the other.Again thank your for your comments.best regardssnowprog   