Exemple #1
0
        void ParseStruct(string block)
        {
            string[] tokens = block.Split(new[] { " ", "\t", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            int      index  = 1;

            ShaderStruct uniformStruct = new ShaderStruct(tokens[index++]);

            index++; // {
            while (!tokens[index].Equals("}"))
            {
                string type = tokens[index++];
                string name = tokens[index++];

                if (type == ":")
                {
                    continue;
                }

                // Strip ; from name if present
                name = name.Replace(";", "");
                uniformStruct.AddField(new ShaderUniformDeclaration(ShaderUniformTypeMethods.StringToUniformType(type), name));
            }
            m_Structs.Add(uniformStruct);
        }
Exemple #2
0
        void ParseCBuffer(string block)
        {
            string[] tokens = block.Split(new[] { " ", "\t", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            int      index  = 1;

            string bufferName = tokens[index++];
            int    reg        = 0;

            if (tokens[index++] == ":") // Register specified
            {
                reg = int.Parse(Regex.Match(tokens[index++], @"\d+").Value);
            }

            ShaderUniformBufferDeclaration buffer = null;
            ShaderType shaderType = ShaderType.NONE;

            if (bufferName.StartsWith("VS"))
            {
                shaderType = ShaderType.VERTEX;
            }
            else if (bufferName.StartsWith("PS"))
            {
                shaderType = ShaderType.PIXEL;
            }
            else
            {
                Debug.Assert(false, "CBuffer no shader type");
            }

            index++; // {
            while (!tokens[index].Equals("}"))
            {
                string type = tokens[index++];
                string name = tokens[index++];

                // Strip ; from name if present
                name = name.Replace(";", "");

                if (buffer == null)
                {
                    buffer = new ShaderUniformBufferDeclaration(bufferName, reg, shaderType);
                    if (name.StartsWith("sys_"))
                    {
                        switch (shaderType)
                        {
                        case ShaderType.VERTEX: m_VSUniformBuffers.Add(buffer);
                            break;

                        case ShaderType.PIXEL: m_PSUniformBuffers.Add(buffer);
                            break;
                        }
                    }
                    else
                    {
                        switch (shaderType)
                        {
                        case ShaderType.VERTEX:
                            Debug.Assert(m_VSUserUniformBuffer == null);
                            m_VSUserUniformBuffer = buffer;
                            break;

                        case ShaderType.PIXEL:
                            Debug.Assert(m_PSUserUniformBuffer == null);
                            m_PSUserUniformBuffer = buffer;
                            break;
                        }
                    }
                }
                ShaderUniformType        t    = ShaderUniformTypeMethods.StringToUniformType(type);
                ShaderUniformDeclaration decl = null;
                if (t == ShaderUniformType.NONE)
                {
                    ShaderStruct s = FindStruct(type);
                    decl = new ShaderUniformDeclaration(s, name);
                }
                else
                {
                    decl = new ShaderUniformDeclaration(t, name);
                }
                buffer.PushUniform(decl);
            }
            buffer.Align();
        }