Skip to content

Commit

Permalink
Fixid shader compilation issues for all renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed May 30, 2018
1 parent f94da38 commit 205fab5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Layers/xrRender/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class ECORE_API CResourceManager
T& GetShaderMap();

template <typename T>
T* CreateShader(const char* name, const bool searchForEntryAndTarget = false);
T* CreateShader(const char* name, const char* filename = nullptr, const bool searchForEntryAndTarget = false);

template <typename T>
void DestroyShader(const T* sh);
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/ResourceManager_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ SVS* CResourceManager::_CreateVS(LPCSTR _name)
if (4 == GEnv.Render->m_skinning)
xr_strcat(name, "_4");

return CreateShader<SVS>(name, true);
return CreateShader<SVS>(name, _name, true);
}

void CResourceManager::_DeleteVS(const SVS* vs) { DestroyShader(vs); }

SPS* CResourceManager::_CreatePS(LPCSTR name) { return CreateShader<SPS>(name, true); }
SPS* CResourceManager::_CreatePS(LPCSTR name) { return CreateShader<SPS>(name, nullptr, true); }
void CResourceManager::_DeletePS(const SPS* ps) { DestroyShader(ps); }

R_constant_table* CResourceManager::_CreateConstantTable(R_constant_table& C)
Expand Down
24 changes: 11 additions & 13 deletions src/Layers/xrRender/ShaderResourceTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ inline CResourceManager::map_CS& CResourceManager::GetShaderMap()
#endif

template <typename T>
inline T* CResourceManager::CreateShader(const char* name, const bool searchForEntryAndTarget /*= false*/)
inline T* CResourceManager::CreateShader(const char* name, const char* filename /*= nullptr*/, const bool searchForEntryAndTarget /*= false*/)
{
ShaderTypeTraits<T>::MapType& sh_map = GetShaderMap<ShaderTypeTraits<T>::MapType>();
LPSTR N = LPSTR(name);
Expand All @@ -360,26 +360,24 @@ inline T* CResourceManager::CreateShader(const char* name, const bool searchForE

// Remove ( and everything after it
string_path shName;
const char* pchr = strchr(name, '(');
ptrdiff_t strSize = pchr ? pchr - name : xr_strlen(name);
strncpy(shName, name, strSize);
shName[strSize] = 0;
{
if (filename == nullptr)
filename = name;

pcstr pchr = strchr(filename, '(');
ptrdiff_t size = pchr ? pchr - filename : xr_strlen(filename);
strncpy(shName, filename, size);
shName[size] = 0;
}

// Open file
string_path cname;
strconcat(sizeof(cname), cname, GEnv.Render->getShaderPath(), /*name*/ shName,
strconcat(sizeof(cname), cname, GEnv.Render->getShaderPath(), shName,
ShaderTypeTraits<T>::GetShaderExt());
FS.update_path(cname, "$game_shaders$", cname);

// Try to open
IReader* file = FS.r_open(cname);
if (!file)
{
// Cut last two chars and try again
// Needed for R1 vertex shaders
cname[xr_strlen(cname) - 2] = '\0';
file = FS.r_open(cname);
}

bool fallback = strstr(Core.Params, "-lack_of_shaders");
if (!file && fallback)
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRenderDX10/dx10ResourceManager_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ SVS* CResourceManager::_CreateVS(LPCSTR _name)
if (4 == GEnv.Render->m_skinning)
xr_strcat(name, "_4");

return CreateShader<SVS>(name, true);
return CreateShader<SVS>(name, _name, true);
}

void CResourceManager::_DeleteVS(const SVS* vs)
Expand Down Expand Up @@ -189,7 +189,7 @@ SPS* CResourceManager::_CreatePS(LPCSTR _name)
if (7 == GEnv.Render->m_MSAASample)
xr_strcat(name, "_7");

return CreateShader<SPS>(name, true);
return CreateShader<SPS>(name, _name, true);
}

void CResourceManager::_DeletePS(const SPS* ps) { DestroyShader(ps); }
Expand Down

0 comments on commit 205fab5

Please sign in to comment.