太多的唯一状态对象?

时间:2018-10-25 07:50:06

标签: c# directx monogame

所以我遇到了DirectX问题,并且抛出异常,如下所述:

D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS
0x887C0001

The application has exceeded the maximum number of unique state objects per Direct3D device. 
The limit is 4096 for feature levels up to 11.1

并且找不到有关此问题的文档。作为参考,只有3种使用Monogame的BasicEffect绘制到屏幕上的模型,每个模型的多边形少于50个。

这是怎么发生的,如何解决?

1 个答案:

答案 0 :(得分:0)

这是我发现最有效的解决方法:

static void Render(GraphicsDevice gd, ModelMesh mesh) {
    gd.RasterizerState = RasterizerState.CullNone;

    for (int i = 0; i < mesh.MeshParts.Count; i++) {
        int vertexCount = mesh.MeshParts[i].NumVertices;
        VertexBuffer vb = mesh.MeshParts[i].VertexBuffer;
        IndexBuffer ib = mesh.MeshParts[i].IndexBuffer;

        gd.SetVertexBuffer(vb);
        gd.Indices = ib;

        EffectPass pass = mesh.MeshParts[i].Effect.CurrentTechnique.Passes[0];
        pass.Apply();
        int startIndex = mesh.MeshParts[i].StartIndex;
        int primitiveCount = mesh.MeshParts[i].PrimitiveCount;

        gd.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, startIndex, primitiveCount, 0);
    }