private static void ValidateVertShaderInputsMatchVertLayout(ParsedShader shader, VertexLayoutDescription layout) { var vertInputs = shader.Attributes.Where(a => a.Direction == ShaderAttributeDirection.In).ToArray(); if (vertInputs.Length != layout.Elements.Length) { throw new FormatException($"Vertex shader input count ({vertInputs.Length}) does not match vert type layout elements ({layout.Elements.Length})"); } for (var i = 0; i < vertInputs.Length; ++i) { var vertInput = vertInputs[i]; var vertLayoutElement = layout.Elements[i]; var size = vertLayoutElement.Format.Size(); if (vertInput.Name != vertLayoutElement.Name) { throw new FormatException($"Vertex shader input '{vertInput}' name is {vertInput.Name}, but vertex layout description expected {vertLayoutElement.Name}."); } if (vertInput.DataType.Size() != size) { throw new FormatException($"Vertex shader input '{vertInput}' size is {vertInput.DataType.Size()}, but vertex layout description expected {size}."); } if (vertInput.Component != vertLayoutElement.Offset) { throw new FormatException($"Vertex shader input '{vertInput}' offset is {vertInput.Component}, but vertex layout description expected {vertLayoutElement.Offset}."); } } }
private static void ValidateVertShaderOutputsMatchFragShaderOutputs(ParsedShader vertexShader, ParsedShader fragmentShader) { var vertOutputs = vertexShader.Attributes.Where(a => a.Direction == ShaderAttributeDirection.Out).ToArray(); var fragInputs = fragmentShader.Attributes.Where(a => a.Direction == ShaderAttributeDirection.In).ToArray(); if (vertOutputs.Length != fragInputs.Length) { throw new FormatException($"Vertex shader output count ({vertOutputs.Length}) does not match frag shader input count ({fragInputs.Length}"); } for (var i = 0; i < vertOutputs.Length; ++i) { var vertOutput = vertOutputs[i]; var fragInput = fragInputs[i]; if (!vertOutput.PipesTo(fragInput)) { throw new FormatException($"Vertex shader output '{vertOutput}' does not match frag shader input `{fragInput}'."); } } }