Skip to content

Commit 46bc819

Browse files
committed
xrRenderDX10/dx10ResourceManager_Resources.cpp: removed code duplication
1 parent bba8744 commit 46bc819

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

src/Layers/xrRender/ResourceManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class ECORE_API CResourceManager
258258
T* CreateShader(const char* name, const char* filename = nullptr, const bool searchForEntryAndTarget = false);
259259

260260
template <typename T>
261-
void DestroyShader(const T* sh);
261+
bool DestroyShader(const T* sh);
262262
};
263263

264264
#endif // ResourceManagerH

src/Layers/xrRender/ShaderResourceTraits.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,10 @@ inline T* CResourceManager::CreateShader(const char* name, const char* filename
426426
}
427427

428428
template <typename T>
429-
inline void CResourceManager::DestroyShader(const T* sh)
429+
bool CResourceManager::DestroyShader(const T* sh)
430430
{
431431
if (0 == (sh->dwFlags & xr_resource_flagged::RF_REGISTERED))
432-
return;
432+
return false;
433433

434434
ShaderTypeTraits<T>::MapType& sh_map = GetShaderMap<ShaderTypeTraits<T>::MapType>();
435435

@@ -439,7 +439,9 @@ inline void CResourceManager::DestroyShader(const T* sh)
439439
if (iterator != sh_map.end())
440440
{
441441
sh_map.erase(iterator);
442-
return;
442+
return true;
443443
}
444+
444445
Msg("! ERROR: Failed to find compiled shader '%s'", sh->cName.c_str());
446+
return false;
445447
}

src/Layers/xrRenderDX10/dx10ResourceManager_Resources.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,31 +140,19 @@ SVS* CResourceManager::_CreateVS(LPCSTR _name)
140140

141141
void CResourceManager::_DeleteVS(const SVS* vs)
142142
{
143-
// XXX: try to use code below
144-
// DestroyShader(vs);
145-
146-
if (0 == (vs->dwFlags & xr_resource_flagged::RF_REGISTERED))
147-
return;
148-
LPSTR N = LPSTR(*vs->cName);
149-
map_VS::iterator I = m_vs.find(N);
150-
if (I != m_vs.end())
143+
if (DestroyShader(vs))
151144
{
152-
m_vs.erase(I);
153-
xr_vector<SDeclaration*>::iterator iDecl;
154-
for (iDecl = v_declarations.begin(); iDecl != v_declarations.end(); ++iDecl)
145+
for (const auto& iDecl : v_declarations)
155146
{
156-
xr_map<ID3DBlob*, ID3DInputLayout*>::iterator iLayout;
157-
iLayout = (*iDecl)->vs_to_layout.find(vs->signature->signature);
158-
if (iLayout != (*iDecl)->vs_to_layout.end())
147+
const auto iLayout = iDecl->vs_to_layout.find(vs->signature->signature);
148+
if (iLayout != iDecl->vs_to_layout.end())
159149
{
160150
// Release vertex layout
161151
_RELEASE(iLayout->second);
162-
(*iDecl)->vs_to_layout.erase(iLayout);
152+
iDecl->vs_to_layout.erase(iLayout);
163153
}
164154
}
165-
return;
166155
}
167-
Msg("! ERROR: Failed to find compiled vertex-shader '%s'", *vs->cName);
168156
}
169157

170158
//--------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)