public void PushUniform(ShaderUniformDeclaration decl)
        {
            int offset = 0;

            if (Uniforms.Count > 0)
            {
                ShaderUniformDeclaration previous = Uniforms.Last();
                offset = previous.Offset + previous.Size;
            }
            decl.Offset = offset;
            Size       += decl.Size;
            Uniforms.Add(decl);
        }
示例#2
0
        public void AddField(ShaderUniformDeclaration decl)
        {
            Size += decl.Size;
            int offset = 0;

            if (Fields.Count != 0)
            {
                ShaderUniformDeclaration previous = Fields.Last();
                offset = previous.Offset + previous.Size;
            }
            decl.Offset = offset;
            Fields.Add(decl);
        }
示例#3
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();
        }