Browse Source

Log missing vertex element(s) when vertex layout fails to create. Add texcoords to the editor grid to keep D3D11 happy.

Lasse Öörni 10 years ago
parent
commit
2858755334

+ 1 - 0
Docs/Reference.dox

@@ -1135,6 +1135,7 @@ Direct3D9 and Direct3D11 share the same HLSL shader code. Macros and some condit
 - Vertex shader output position and pixel shader output color need to use the SV_POSITION and SV_TARGET semantics. The macros OUTPOSITION and OUTCOLOR0-3 can be used to select the correct semantic on both APIs. In the vertex shader, the output position should be specified last, as otherwise other interpolator outputs may not function correctly.
 - On Direct3D11 the clip plane coordinate must be calculated manually. This is indicated by the CLIPPLANE compilation define, which is added automatically by the Graphics class. See for example the LitSolid.hlsl shader.
 - Direct3D11 does not support luminance and luminance-alpha texture formats, but rather uses the R and RG channels. Therefore be prepared to perform swizzling in the texture reads as appropriate.
+- Direct3D11 will fail to render if the vertex shader refers to vertex elements that don't exist in the vertex buffers.
 
 \section Shaders_Precaching Shader precaching
 

+ 5 - 1
Source/Urho3D/Graphics/Direct3D11/D3D11VertexDeclaration.cpp

@@ -37,6 +37,8 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertex
 {
     PODVector<D3D11_INPUT_ELEMENT_DESC> elementDescs;
 
+    unsigned vbElementMask = 0;
+
     for (unsigned i = 0; i < MAX_VERTEX_STREAMS; ++i)
     {
         if (vertexBuffers[i] && elementMasks[i])
@@ -55,6 +57,7 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertex
                         D3D11_INPUT_PER_INSTANCE_DATA : D3D11_INPUT_PER_VERTEX_DATA;
                     newDesc.InstanceDataStepRate = (j >= ELEMENT_INSTANCEMATRIX1 && j <= ELEMENT_INSTANCEMATRIX3) ? 1 : 0;
                     elementDescs.Push(newDesc);
+                    vbElementMask |= 1 << j;
                 }
             }
         }
@@ -71,7 +74,8 @@ VertexDeclaration::VertexDeclaration(Graphics* graphics, ShaderVariation* vertex
     if (d3dInputLayout)
         inputLayout_ = d3dInputLayout;
     else
-        LOGERRORF("Failed to create input layout for shader %s element mask %d", vertexShader->GetFullName().CString(), vertexShader->GetElementMask());
+        LOGERRORF("Failed to create input layout for shader %s, missing element mask %d",
+            vertexShader->GetFullName().CString(), vertexShader->GetElementMask() & ~vbElementMask);
 }
 
 VertexDeclaration::~VertexDeclaration()

+ 8 - 0
bin/Data/Scripts/Editor/EditorView.as

@@ -1054,25 +1054,33 @@ void UpdateGrid(bool updateGridGeometry = true)
         {
             grid.DefineVertex(Vector3(lineOffset, 0.0, halfSizeScaled));
             grid.DefineColor(lineCenter ? gridZColor : (lineSubdiv ? gridSubdivisionColor : gridColor));
+            grid.DefineTexCoord(Vector2(0.0f, 0.0f));
             grid.DefineVertex(Vector3(lineOffset, 0.0, -halfSizeScaled));
             grid.DefineColor(lineCenter ? gridZColor : (lineSubdiv ? gridSubdivisionColor : gridColor));
+            grid.DefineTexCoord(Vector2(0.0f, 0.0f));
 
             grid.DefineVertex(Vector3(-halfSizeScaled, 0.0, lineOffset));
             grid.DefineColor(lineCenter ? gridXColor : (lineSubdiv ? gridSubdivisionColor : gridColor));
+            grid.DefineTexCoord(Vector2(0.0f, 0.0f));
             grid.DefineVertex(Vector3(halfSizeScaled, 0.0, lineOffset));
             grid.DefineColor(lineCenter ? gridXColor : (lineSubdiv ? gridSubdivisionColor : gridColor));
+            grid.DefineTexCoord(Vector2(0.0f, 0.0f));
         }
         else
         {
             grid.DefineVertex(Vector3(lineOffset, halfSizeScaled, 0.0));
             grid.DefineColor(lineCenter ? gridYColor : (lineSubdiv ? gridSubdivisionColor : gridColor));
+            grid.DefineTexCoord(Vector2(0.0f, 0.0f));
             grid.DefineVertex(Vector3(lineOffset, -halfSizeScaled, 0.0));
             grid.DefineColor(lineCenter ? gridYColor : (lineSubdiv ? gridSubdivisionColor : gridColor));
+            grid.DefineTexCoord(Vector2(0.0f, 0.0f));
 
             grid.DefineVertex(Vector3(-halfSizeScaled, lineOffset, 0.0));
             grid.DefineColor(lineCenter ? gridXColor : (lineSubdiv ? gridSubdivisionColor : gridColor));
+            grid.DefineTexCoord(Vector2(0.0f, 0.0f));
             grid.DefineVertex(Vector3(halfSizeScaled, lineOffset, 0.0));
             grid.DefineColor(lineCenter ? gridXColor : (lineSubdiv ? gridSubdivisionColor : gridColor));
+            grid.DefineTexCoord(Vector2(0.0f, 0.0f));
         }
 
         lineOffset  += scale;