Ejemplo n.º 1
0
        static void GenerateHeader(List <Setting> settings, string outputName, string outputPath,
                                   List <Type> enumTypes, Dictionary <string, object> constants)
        {
            List <string> lines = new List <string>();

            lines.Add("#pragma once");
            lines.Add("");
            lines.Add("#include <PCH.h>");
            lines.Add("#include <Settings.h>");
            lines.Add("#include <Graphics\\GraphicsTypes.h>");
            lines.Add("");
            lines.Add("using namespace SampleFramework12;");
            lines.Add("");

            WriteEnumTypes(lines, enumTypes);

            lines.Add("namespace " + outputName);
            lines.Add("{");

            foreach (KeyValuePair <string, object> constant in constants)
            {
                Type   constantType = constant.Value.GetType();
                string typeStr      = constantType.ToString();
                string valueStr     = constant.Value.ToString();
                if (constantType == typeof(uint))
                {
                    typeStr = "uint64";
                }
                else if (constantType == typeof(int))
                {
                    typeStr = "int64";
                }
                else if (constantType == typeof(bool))
                {
                    typeStr  = "bool";
                    valueStr = valueStr.ToLower();
                }
                else if (constantType == typeof(float))
                {
                    typeStr  = "float";
                    valueStr = FloatSetting.FloatString((float)constant.Value);
                }
                lines.Add(string.Format("    static const {0} {1} = {2};", typeStr, constant.Key, valueStr));
            }

            lines.Add("");

            uint numCBSettings = 0;

            foreach (Setting setting in settings)
            {
                setting.WriteDeclaration(lines);
                if (setting.UseAsShaderConstant)
                {
                    ++numCBSettings;
                }
            }


            lines.Add("");
            lines.Add(string.Format("    struct {0}CBuffer", outputName));
            lines.Add("    {");


            if (numCBSettings > 0)
            {
                uint cbSize = 0;
                foreach (Setting setting in settings)
                {
                    setting.WriteCBufferStruct(lines, ref cbSize);
                }
            }
            else
            {
                lines.Add("        uint32 Dummy;");
            }

            lines.Add("    };");
            lines.Add("");
            lines.Add("    extern ConstantBuffer CBuffer;");
            lines.Add("    const extern uint32 CBufferRegister;");

            lines.Add("");
            lines.Add("    void Initialize();");
            lines.Add("    void Shutdown();");
            lines.Add("    void Update(uint32 displayWidth, uint32 displayHeight, const Float4x4& viewMatrix);");
            lines.Add("    void UpdateCBuffer();");
            lines.Add("    void BindCBufferGfx(ID3D12GraphicsCommandList* cmdList, uint32 rootParameter);");
            lines.Add("    void BindCBufferCompute(ID3D12GraphicsCommandList* cmdList, uint32 rootParameter);");

            lines.Add("};");

            WriteIfChanged(lines, outputPath);
        }
Ejemplo n.º 2
0
        static void GenerateHLSL(List <Setting> settings, string outputName, string outputPath,
                                 List <Type> enumTypes, Dictionary <string, object> constants)
        {
            uint numCBSettings = 0;

            foreach (Setting setting in settings)
            {
                if (setting.UseAsShaderConstant)
                {
                    ++numCBSettings;
                }
            }

            List <string> lines = new List <string>();

            if (numCBSettings == 0)
            {
                WriteIfChanged(lines, outputPath);
            }

            lines.Add(string.Format("struct {0}_Layout", outputName));
            lines.Add("{");

            foreach (Setting setting in settings)
            {
                setting.WriteHLSL(lines);
            }

            lines.Add("};");
            lines.Add("");

            lines.Add(string.Format("ConstantBuffer<{0}_Layout> {0} : register(b{1});", outputName, CBufferRegister));
            lines.Add("");

            foreach (Type enumType in enumTypes)
            {
                string[] enumNames  = enumType.GetEnumNames();
                Array    enumValues = enumType.GetEnumValues();
                for (int i = 0; i < enumNames.Length; ++i)
                {
                    string line = "static const int " + enumType.Name + "_";
                    line += enumNames[i] + " = " + (int)enumValues.GetValue(i) + ";";
                    lines.Add(line);
                }

                lines.Add("");
            }

            foreach (KeyValuePair <string, object> constant in constants)
            {
                Type   constantType = constant.Value.GetType();
                string typeStr      = constantType.ToString();
                string valueStr     = constant.Value.ToString();
                if (constantType == typeof(uint))
                {
                    typeStr = "uint";
                }
                else if (constantType == typeof(int))
                {
                    typeStr = "int";
                }
                else if (constantType == typeof(bool))
                {
                    typeStr  = "bool";
                    valueStr = valueStr.ToLower();
                }
                else if (constantType == typeof(float))
                {
                    typeStr  = "float";
                    valueStr = FloatSetting.FloatString((float)constant.Value);
                }
                lines.Add(string.Format("static const {0} {1} = {2};", typeStr, constant.Key, valueStr));
            }

            WriteIfChanged(lines, outputPath);
        }
Ejemplo n.º 3
0
        static void GenerateHeader(List <Setting> settings, string outputName, string outputPath,
                                   List <Type> enumTypes, Dictionary <string, object> constants)
        {
            List <string> lines = new List <string>();

            lines.Add("#pragma once");
            lines.Add("");
            lines.Add("#include <PCH.h>");
            lines.Add("#include <Settings.h>");
            lines.Add("#include <Graphics\\GraphicsTypes.h>");
            lines.Add("");
            lines.Add("using namespace GumshoeFramework10;");
            lines.Add("");

            WriteEnumTypes(lines, enumTypes);

            lines.Add("namespace " + outputName);
            lines.Add("{");

            foreach (KeyValuePair <string, object> constant in constants)
            {
                Type   constantType = constant.Value.GetType();
                string typeStr      = constantType.ToString();
                string valueStr     = constant.Value.ToString();
                if (constantType == typeof(uint))
                {
                    typeStr = "uint64";
                }
                else if (constantType == typeof(int))
                {
                    typeStr = "int64";
                }
                else if (constantType == typeof(bool))
                {
                    typeStr  = "bool";
                    valueStr = valueStr.ToLower();
                }
                else if (constantType == typeof(float))
                {
                    typeStr  = "float";
                    valueStr = FloatSetting.FloatString((float)constant.Value);
                }
                lines.Add(string.Format("    static const {0} {1} = {2};", typeStr, constant.Key, valueStr));
            }

            lines.Add("");

            uint numCBSettings = 0;

            foreach (Setting setting in settings)
            {
                setting.WriteDeclaration(lines);
                if (setting.UseAsShaderConstant)
                {
                    ++numCBSettings;
                }
            }

            if (numCBSettings > 0)
            {
                lines.Add("");
                lines.Add(string.Format("    struct {0}CBuffer", outputName));
                lines.Add("    {");

                uint cbSize = 0;
                foreach (Setting setting in settings)
                {
                    setting.WriteCBufferStruct(lines, ref cbSize);
                }

                lines.Add("    };");
                lines.Add("");
                lines.Add(string.Format("    extern ConstantBuffer<{0}CBuffer> CBuffer;", outputName));
            }

            lines.Add("");
            lines.Add("    void Initialize(ID3D11Device* device);");
            lines.Add("    void Update();");
            lines.Add("    void UpdateCBuffer(ID3D11DeviceContext* context);");

            lines.Add("};");

            WriteIfChanged(lines, outputPath);
        }