MCPcopy Create free account
hub / github.com/beefytech/Beef / LoadDXShader

Function LoadDXShader

BeefySysLib/platform/win/DXRenderDevice.cpp:237–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235static Func_D3DX10Compile gFunc_D3DX10Compile;
236
237static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, const StringImpl& profile, ID3D10Blob** outBuffer)
238{
239 HRESULT hr;
240 String outObj = filePath + "_" + entry + "_" + profile;
241
242 bool useCache = false;
243 auto srcDate = ::BfpFile_GetTime_LastWrite(filePath.c_str());
244 auto cacheDate = ::BfpFile_GetTime_LastWrite(outObj.c_str());
245 if ((cacheDate != 0) && (cacheDate >= srcDate))
246 useCache = true;
247
248 if (!useCache)
249 {
250 if (gFunc_D3DX10CompileFromFileW == NULL)
251 {
252 auto lib = LoadLibraryA("D3DCompiler_47.dll");
253 if (lib != NULL)
254 gFunc_D3DX10CompileFromFileW = (Func_D3DX10CompileFromFileW)::GetProcAddress(lib, "D3DCompileFromFile");
255 }
256
257 if (gFunc_D3DX10CompileFromFileW == NULL)
258 useCache = true;
259 }
260
261 if (!useCache)
262 {
263 bool useCompile = true;
264
265 HRESULT dxResult;
266 ID3D10Blob* errorMessage = NULL;
267 if (useCompile)
268 {
269 if (gFunc_D3DX10Compile == NULL)
270 {
271 auto lib = LoadLibraryA("D3DCompiler_47.dll");
272 if (lib != NULL)
273 gFunc_D3DX10Compile = (Func_D3DX10Compile)::GetProcAddress(lib, "D3DCompile");
274 }
275
276 int memSize = 0;
277 uint8* memPtr = LoadBinaryData(filePath, &memSize);
278
279 dxResult = gFunc_D3DX10Compile(memPtr, memSize, "Shader", NULL, NULL, entry.c_str(), profile.c_str(),
280 D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage);
281 }
282 else
283 {
284 if (gFunc_D3DX10CompileFromFileW == NULL)
285 {
286 auto lib = LoadLibraryA("D3DCompiler_47.dll");
287 if (lib != NULL)
288 gFunc_D3DX10CompileFromFileW = (Func_D3DX10CompileFromFileW)::GetProcAddress(lib, "D3DCompileFromFile");
289 }
290
291 dxResult = gFunc_D3DX10CompileFromFileW(UTF8Decode(filePath).c_str(), NULL, NULL, entry.c_str(), profile.c_str(),
292 D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage);
293 }
294

Callers 1

LoadMethod · 0.85

Calls 3

c_strMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected