0

I'm using SlimDX for a Direct3D 10 apps. In the apps I've loaded 2 to more mesh, with images loaded as texture and using a fx code for shader. The code was modified from SlimDX's sample "SimpleModel10"

I move the draw call, shader setup code into a class that manage 1 mesh, shader (effect) and draw call. Then I initialize 2 copy of this class, then call the draw function one after another.

The output, no matter how I change the Z position of the mesh, the one being draw later will always stay on top. Later, when I use PIX to debug the draw call, I found out that the 2nd mesh doesn't have depth while the first one does. I've tried with 3 meshes, 2nd and 3rd one will not have depth too. The funny thing is all of then are instantiated from the same class, using the same draw call.

What could have cause such problem?

Following is part of the code in the draw function of the class, I've omitted the rest as it's lengthy involved a few classes. I keep the existing OnRenderBegin() and OnRenderEnd() of the sample:

        PanelEffect.GetVariableByName("world").AsMatrix().SetMatrix(world);

        lock (this)
        {
            device.InputAssembler.SetInputLayout(layout);
            device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            device.InputAssembler.SetIndexBuffer(indices, Format.R32_UInt, 0);
            device.InputAssembler.SetVertexBuffers(0, binding);

            PanelEffect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply();
            device.DrawIndexed(indexCount, 0, 0);

            device.InputAssembler.SetIndexBuffer(null, Format.Unknown, 0);
            device.InputAssembler.SetVertexBuffers(0, nullBinding);
        }

Edit: After much debugging and code isolation, I found out the culprit is Font.Draw() in my DrawString() function

    internal void DrawString(string text)
    {
        sprite.Begin(SpriteFlags.None);
        string[] texts = text.Split(new string[] {"\r\n"}, StringSplitOptions.None);
        int y = PanelY;
        foreach (string t in texts)
        {
            font.Draw(sprite, t, new System.Drawing.Rectangle(PanelX, y, PanelSize.Width, PanelSize.Height), FontDrawFlags.SingleLine, new Color4(Color.Red));
            y += font.Description.Height;
        }
        sprite.End();
    }

Comment out Font.Draw solve the problem. Maybe it automatically set some states which causes the next Mesh draw to discard depth. Looking into SlimDX's source code now.

2
  • Have you tried turning debug on in the directx control panel? You should get a bunch of messages tellign you what you are doing wrong in the output window.
    – Goz
    Feb 26, 2011 at 11:56
  • Goz: There's some irrelevant warning, nothing much, will dig deeper
    – faulty
    Feb 26, 2011 at 13:51

1 Answer 1

1

After much debugging in PIX, this is the conclusion.

Calling Font.Draw() will automatically set DepthEnable to false and DepthFunction to D3D10_COMPARISON_NEVER, that's after comparing PIX's detail on the OutputMerger of before and after calling Font.Draw

Solution

            Context10_1.Device.OutputMerger.DepthStencilState = depthStencilState;

Put that before the next Mesh draw call fixed the problem.

Previously I only set the DepthStencilState in the OnRenderBegin()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.