Z buffer is suddenly appear on top of texture

Started by
1 comment, last by galover 6 years, 11 months ago

I'm trying to draw on top of other DirectX 9 application (Game)

and here it goes, this is strange considering I tried to clean everything but it just draw it nonetheless

I'm drawing a white rectangle here (COLOROP and ALPHAOP is disabled) but it still draw some sort of Z buffer on top of it.

[attachment=35784:something_went_wrong.png]

this code helps so I think this is actually a Z buffer, but... I'm not feeling comfortable about cleaning someone else Z buffer, you know, what if they would need it?


DirectDevice.Clear(0, nil, D3DCLEAR_ZBUFFER, 0, 0.0, 0);

Draw code:


      // trying to clean something, it doesn't help by the way
      Assert(Succeeded(DirectDevice.GetDeviceCaps(Caps)));
      for Index := 1 to Caps.MaxStreams - 1 do
      begin
        Assert(Succeeded(DirectDevice.SetStreamSource(Index, nil, 0, 0)));
        Assert(Succeeded(DirectDevice.SetTexture(Index, nil)));
      end;
      for Index := 1 to Caps.NumSimultaneousRTs  - 1 do
        Assert(Succeeded(DirectDevice.SetRenderTarget(Index, nil)));

      // actual draw
      Assert(Succeeded(DirectDevice.SetFVF(VertexFVF)));
      Assert(Succeeded(DirectDevice.SetStreamSource(0, Vertex, 0, SizeOf(TVertex))));
      Assert(Succeeded(DirectDevice.SetTexture(0, Texture)));
      Assert(Succeeded(DirectDevice.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2))); 

State (pretty much is a copy of ID3DXSprite code):


    Res:= DirectDevice.SetRenderState(D3DRS_ALPHABLENDENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
    Res:= DirectDevice.SetRenderState(D3DRS_ALPHAREF, $00);
    Res:= DirectDevice.SetRenderState(D3DRS_ALPHATESTENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
    Res:= DirectDevice.SetRenderState(D3DRS_CLIPPING, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_CLIPPLANEENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_BLUE or D3DCOLORWRITEENABLE_GREEN or D3DCOLORWRITEENABLE_RED);
    Res:= DirectDevice.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    Res:= DirectDevice.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    Res:= DirectDevice.SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);
    Res:= DirectDevice.SetRenderState(D3DRS_ENABLEADAPTIVETESSELLATION, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
    Res:= DirectDevice.SetRenderState(D3DRS_FOGENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_LIGHTING, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_RANGEFOGENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
    Res:= DirectDevice.SetRenderState(D3DRS_SPECULARENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    Res:= DirectDevice.SetRenderState(D3DRS_SRGBWRITEENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_STENCILENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_VERTEXBLEND, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_WRAP0, 0);


    Res:= DirectDevice.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    Res:= DirectDevice.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
    Res:= DirectDevice.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
    Res:= DirectDevice.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
    Res:= DirectDevice.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
    Res:= DirectDevice.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); // D3DTOP_SELECTARG1
    Res:= DirectDevice.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
    Res:= DirectDevice.SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
    Res:= DirectDevice.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
    Res:= DirectDevice.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);


    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 0);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 1);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_MIPMAPLODBIAS, 0);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_SRGBTEXTURE, 0);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_ELEMENTINDEX, 0);
    Res:= DirectDevice.SetSamplerState(0, D3DSAMP_DMAPOFFSET, 0);


   // below settings is not from ID3DXSprite


    Res:= DirectDevice.SetPixelShader(nil);
    Res:= DirectDevice.SetVertexShader(nil);
    Res:= DirectDevice.SetVertexDeclaration(nil);
    Res:= DirectDevice.LightEnable(0, False);


    Res:= DirectDevice.SetRenderState(D3DRS_ZENABLE, Ord(FALSE));
    Res:= DirectDevice.SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, Ord(FALSE)); 

I really don't know how to deal with it, so maybe anyone can help me, please.

Advertisement
Just now I found out that even StretchRect of my texture to backbuffer result in a same Z buffer on top of my texture.
So we can rule out all states, shaders and other stuff, I guess.
Now it's just a texture and a backbuffer...

DirectDevice.StretchRect(SrcSurface, @SrcRect, BackBuffer, @DstRect, D3DTEXF_NONE);

Okay, I'm not sure, but seems like forced ambient occlusion in NVIDIA driver was causing this.

This topic is closed to new replies.

Advertisement