开发者

Texture from Surface in DirectX 8.1

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 dr开发者_开发百科aw 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜