1
votes

I'm doing double-buffering by creating a render target with its associated depth and stencil buffer, drawing to it, and then drawing a fullscreen, possibly stretched, quad with the back buffer as the texture.

To do this I'm using a CreateTexture() call to create the back buffer, and then a GetSurfaceLevel() call to get the texture from the Surface. This works fine.

However, I'd like to use CreateRenderTarget() directly. It returns a Surface. But then I need a Texture to draw a quad to the front buffer.

The problem is, I can't find a function to get a texture from a surface. I've searched the DX8.1 doc again and again with no luck. Does such function even exist?

2
Why are you using such an old version of DirectX? - Zac Howland
Is there some reason to use so old DirectX? - Virne
Compatibility. Our publishers and distribution partners often insist on supporting insanely low end and never updated systems... - ggambett

2 Answers

1
votes

You can create empty texture matching size and color format of the surface. Then copy contents of the surface to the surface of the texture.

Here is a snippet from my DirectX9 code without error handling and other complications. It actually creates mipmap-chain. Note StretchRect that does the actual copying by stretching surface to match geometry of the destination surface.

IDirect3DSurface9* srcSurface = renderTargetSurface;
IDirect3DTexture9* tex = textureFromRenderTarget;
int levels = tex->GetLevelCount(); 

    for (int i=0; i<levels; i++)
    {
        IDirect3DSurface9* destSurface = 0;
        tex->GetSurfaceLevel(i, &destSurface);
        pd3dd->StretchRect(srcSurface, NULL, destSurface, NULL, D3DTEXF_LINEAR);
    }

But of course, this is for DirectX 9. For 8.1 you can try CopyRect or Blt.

On Dx9 there is ID3DXRenderToSurface that can use surface from texture directly. I am not sure if that's possible with Dx8.1, but above copy-method should work.

0
votes

If backwards compatibility is the reason your using D3D8, try using SwiftShader instead. http://transgaming.com/business/swiftshader

It a software implementation of D3D9. You can utilize it when you don't have a video card. It costs about 12k though.