private static SemanticType GetSemanticType(VariableDeclaratorSyntax vds)
        {
            AttributeSyntax[] attrs = Utilities.GetMemberAttributes(vds, "VertexSemantic");
            if (attrs.Length == 1)
            {
                AttributeSyntax semanticTypeAttr = attrs[0];
                string          fullArg0         = semanticTypeAttr.ArgumentList.Arguments[0].ToFullString();
                if (fullArg0.Contains("."))
                {
                    fullArg0 = fullArg0.Substring(fullArg0.LastIndexOf('.') + 1);
                }
                if (Enum.TryParse(fullArg0, out SemanticType ret))
                {
                    return(ret);
                }
                else
                {
                    throw new ShaderGenerationException("Incorrectly formatted attribute: " + semanticTypeAttr.ToFullString());
                }
            }
            else if (attrs.Length > 1)
            {
                throw new ShaderGenerationException("Too many vertex semantics applied to field: " + vds.ToFullString());
            }

            if (CheckSingleAttribute(vds, "SystemPositionSemantic"))
            {
                return(SemanticType.SystemPosition);
            }
            else if (CheckSingleAttribute(vds, "PositionSemantic"))
            {
                return(SemanticType.Position);
            }
            else if (CheckSingleAttribute(vds, "NormalSemantic"))
            {
                return(SemanticType.Normal);
            }
            else if (CheckSingleAttribute(vds, "TextureCoordinateSemantic"))
            {
                return(SemanticType.TextureCoordinate);
            }
            else if (CheckSingleAttribute(vds, "ColorSemantic"))
            {
                return(SemanticType.Color);
            }
            else if (CheckSingleAttribute(vds, "TangentSemantic"))
            {
                return(SemanticType.Tangent);
            }
            else if (CheckSingleAttribute(vds, "ColorTargetSemantic"))
            {
                return(SemanticType.ColorTarget);
            }

            return(SemanticType.None);
        }
예제 #2
0
        private static GeometrySemantic GetGeometrySemantic(VariableDeclaratorSyntax vds)
        {
            AttributeSyntax[] attrs = Utilities.GetMemberAttributes(vds, "GeometrySemantic");
            if (attrs.Length == 1)
            {
                AttributeSyntax semanticTypeAttr = attrs[0];
                string          fullArg0         = semanticTypeAttr.ArgumentList.Arguments[0].ToFullString();
                if (fullArg0.Contains("."))
                {
                    fullArg0 = fullArg0.Substring(fullArg0.LastIndexOf('.') + 1);
                }
                if (Enum.TryParse(fullArg0, out GeometrySemantic ret))
                {
                    return(ret);
                }
                else
                {
                    throw new ShaderGenerationException("Incorrectly formatted attribute: " + semanticTypeAttr.ToFullString());
                }
            }
            else if (attrs.Length > 1)
            {
                throw new ShaderGenerationException("Too many geometry semantics applied to field: " + vds.ToFullString());
            }

            return(GeometrySemantic.None);
        }