DirectX: "render to surface" or "render to device" (unmanaged)
-
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 :~):
IDirect3DDevice9* pDevice; //for simplicity no initialization code here pDevice->Clear(); pDevice->BeginScene(); HRESULT hResult = pDevice->DrawPrimitiveUP( /* ... */ ); pDevice->EndScene(); pDevice->Present();
The second way I found is to render first to a surface and then the complete surface at once to the device: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();
--------------------- 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? Thanks in advance Snowprog -
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 :~):
IDirect3DDevice9* pDevice; //for simplicity no initialization code here pDevice->Clear(); pDevice->BeginScene(); HRESULT hResult = pDevice->DrawPrimitiveUP( /* ... */ ); pDevice->EndScene(); pDevice->Present();
The second way I found is to render first to a surface and then the complete surface at once to the device: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();
--------------------- 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? Thanks in advance SnowprogSnowprog77 wrote:
My question now is: What benefits do I get from the second approach?
Snowprog77 wrote:
For me it looks like I just put one more step in the row. Is there less flickering?
Yes, AFAIK. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
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 :~):
IDirect3DDevice9* pDevice; //for simplicity no initialization code here pDevice->Clear(); pDevice->BeginScene(); HRESULT hResult = pDevice->DrawPrimitiveUP( /* ... */ ); pDevice->EndScene(); pDevice->Present();
The second way I found is to render first to a surface and then the complete surface at once to the device: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();
--------------------- 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? Thanks in advance SnowprogSnowprog77 wrote:
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?
Yes - graphics hardware has highly optimised bit-blit operations, which is precisely what's used to move the off-screen surface to the device.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p