MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / CompileShader

Method CompileShader

GTE/Graphics/DX11/HLSLShaderFactory.cpp:94–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94ID3DBlob* HLSLShaderFactory::CompileShader(std::string const& name,
95 std::string const& source, std::string const& entry,
96 std::string const& target, uint32_t compileFlags,
97 ProgramDefines const& defines)
98{
99 ID3DInclude* include = D3D_COMPILE_STANDARD_FILE_INCLUDE;
100 ID3DBlob* compiledCode = nullptr;
101 ID3DBlob* errors = nullptr;
102
103 // Repackage the 'defines' for D3DCompile. Prepend a definition based
104 // on the engine's current matrix-vector multiplication convention.
105 auto const& definitions = defines.Get();
106 std::vector<D3D_SHADER_MACRO> localDefinitions(definitions.size() + 2);
107 std::string umvName = "GTE_USE_MAT_VEC";
108 std::string umvValue;
109#if defined(GTE_USE_VEC_MAT)
110 umvValue = "0";
111#else
112 umvValue = "1";
113#endif
114 localDefinitions.front().Name = umvName.c_str();
115 localDefinitions.front().Definition = umvValue.c_str();
116 for (size_t i = 0; i < definitions.size(); ++i)
117 {
118 localDefinitions[i + 1].Name = definitions[i].first.c_str();
119 localDefinitions[i + 1].Definition = definitions[i].second.c_str();
120 }
121 localDefinitions.back().Name = nullptr;
122 localDefinitions.back().Definition = nullptr;
123
124 if (!(compileFlags & D3DCOMPILE_PACK_MATRIX_ROW_MAJOR)
125 && !(compileFlags & D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR))
126 {
127 // The matrix storage was not explicitly set. Use the storage
128 // consistent with the CPU storage.
129#if defined(GTE_USE_COL_MAJOR)
130 compileFlags |= D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR;
131#else
132 compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
133#endif
134 }
135
136 HRESULT hr = D3DCompile(source.c_str(), source.length(), name.c_str(),
137 localDefinitions.data(), include, entry.c_str(), target.c_str(),
138 compileFlags, 0, &compiledCode, &errors);
139
140 if (SUCCEEDED(hr))
141 {
142 if (errors)
143 {
144 // The message is a 'warning' from the HLSL compiler.
145 char const* message =
146 static_cast<char const*>(errors->GetBufferPointer());
147
148 // Write the warning to the output window when the program is
149 // executing through the Microsoft Visual Studio IDE.
150 size_t const length = strlen(message);
151 std::wstring output = L"";

Callers

nothing calls this directly

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected