From 8876b1a376af3ecbc434d5f5788d85658757ee37 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 19 Aug 2010 14:36:01 +0000 Subject: [PATCH] load d3dx9_*.dll dynamically to get D3DXCompileShader to fix a compile error with mingw headers, this also means it doesn't matter which version is present on the user's system git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10401 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 107 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 36 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index 9abaabf6..84a2974e 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -4700,10 +4700,8 @@ static char *R_HLSL_GetText(const char *filename, qboolean printfromdisknotice) } #include -#include -#ifdef _MSC_VER -#pragma comment(lib, "d3dx9.lib") -#endif +//#include +//#include static void R_HLSL_CacheShader(r_hlsl_permutation_t *p, const char *cachename, const char *vertstring, const char *fragstring) { @@ -4729,42 +4727,79 @@ static void R_HLSL_CacheShader(r_hlsl_permutation_t *p, const char *cachename, c psbin = (DWORD *)FS_LoadFile(va("%s.psbin", cachename), r_main_mempool, true, &psbinsize); if ((!vsbin && vertstring) || (!psbin && fragstring)) { - vsbin = (DWORD *)Mem_Realloc(tempmempool, vsbin, 0); - psbin = (DWORD *)Mem_Realloc(tempmempool, psbin, 0); - if (vertstring && vertstring[0]) - { - vsresult = D3DXCompileShader(vertstring, strlen(vertstring), NULL, NULL, "main", vsversion, 0, &vsbuffer, &vslog, &vsconstanttable); - if (vsbuffer) + const char* dllnames_d3dx9 [] = + { + "d3dx9_43.dll", + "d3dx9_42.dll", + "d3dx9_41.dll", + "d3dx9_40.dll", + "d3dx9_39.dll", + "d3dx9_38.dll", + "d3dx9_37.dll", + "d3dx9_36.dll", + "d3dx9_35.dll", + "d3dx9_34.dll", + "d3dx9_33.dll", + "d3dx9_32.dll", + "d3dx9_31.dll", + "d3dx9_30.dll", + "d3dx9_29.dll", + "d3dx9_28.dll", + "d3dx9_27.dll", + "d3dx9_26.dll", + "d3dx9_25.dll", + "d3dx9_24.dll", + NULL + }; + dllhandle_t d3dx9_dll = NULL; + HRESULT WINAPI (*qD3DXCompileShader)(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable); + dllfunction_t d3dx9_dllfuncs[] = + { + {"D3DXCompileShader", (void **) &qD3DXCompileShader}, + {NULL, NULL} + }; + if (Sys_LoadLibrary(dllnames_d3dx9, &d3dx9_dll, d3dx9_dllfuncs)) + { + vsbin = (DWORD *)Mem_Realloc(tempmempool, vsbin, 0); + psbin = (DWORD *)Mem_Realloc(tempmempool, psbin, 0); + if (vertstring && vertstring[0]) { - vsbinsize = vsbuffer->GetBufferSize(); - vsbin = (DWORD *)Mem_Alloc(tempmempool, vsbinsize); - memcpy(vsbin, vsbuffer->GetBufferPointer(), vsbinsize); - vsbuffer->Release(); - } - if (vslog) - { - strlcpy(temp, (const char *)vslog->GetBufferPointer(), min(sizeof(temp), vslog->GetBufferSize())); - Con_Printf("HLSL vertex shader compile output for %s follows:\n%s\n", cachename, temp); - vslog->Release(); - } - } - if (fragstring && fragstring[0]) - { - psresult = D3DXCompileShader(fragstring, strlen(fragstring), NULL, NULL, "main", psversion, 0, &psbuffer, &pslog, &psconstanttable); - if (psbuffer) - { - psbinsize = psbuffer->GetBufferSize(); - psbin = (DWORD *)Mem_Alloc(tempmempool, psbinsize); - memcpy(psbin, psbuffer->GetBufferPointer(), psbinsize); - psbuffer->Release(); + vsresult = qD3DXCompileShader(vertstring, strlen(vertstring), NULL, NULL, "main", vsversion, 0, &vsbuffer, &vslog, &vsconstanttable); + if (vsbuffer) + { + vsbinsize = vsbuffer->GetBufferSize(); + vsbin = (DWORD *)Mem_Alloc(tempmempool, vsbinsize); + memcpy(vsbin, vsbuffer->GetBufferPointer(), vsbinsize); + vsbuffer->Release(); + } + if (vslog) + { + strlcpy(temp, (const char *)vslog->GetBufferPointer(), min(sizeof(temp), vslog->GetBufferSize())); + Con_Printf("HLSL vertex shader compile output for %s follows:\n%s\n", cachename, temp); + vslog->Release(); + } } - if (pslog) + if (fragstring && fragstring[0]) { - strlcpy(temp, (const char *)pslog->GetBufferPointer(), min(sizeof(temp), pslog->GetBufferSize())); - Con_Printf("HLSL pixel shader compile output for %s follows:\n%s\n", cachename, temp); - pslog->Release(); + psresult = qD3DXCompileShader(fragstring, strlen(fragstring), NULL, NULL, "main", psversion, 0, &psbuffer, &pslog, &psconstanttable); + if (psbuffer) + { + psbinsize = psbuffer->GetBufferSize(); + psbin = (DWORD *)Mem_Alloc(tempmempool, psbinsize); + memcpy(psbin, psbuffer->GetBufferPointer(), psbinsize); + psbuffer->Release(); + } + if (pslog) + { + strlcpy(temp, (const char *)pslog->GetBufferPointer(), min(sizeof(temp), pslog->GetBufferSize())); + Con_Printf("HLSL pixel shader compile output for %s follows:\n%s\n", cachename, temp); + pslog->Release(); + } } + Sys_UnloadLibrary(&d3dx9_dll); } + else + Con_Printf("Unable to compile shader - D3DXCompileShader function not found\n"); } if (vsbin) { @@ -6968,7 +7003,7 @@ skinframe_t *R_SkinFrame_LoadMissing(void) //static char *suffix[6] = {"ft", "bk", "rt", "lf", "up", "dn"}; typedef struct suffixinfo_s { - char *suffix; + const char *suffix; qboolean flipx, flipy, flipdiagonal; } suffixinfo_t; -- 2.39.2