Support deleting shader materials

This commit is contained in:
sfan5 2024-02-20 21:44:47 +01:00
parent 13a0e5fb4a
commit dce166dc93
1 changed files with 28 additions and 9 deletions

View File

@ -264,6 +264,7 @@ class ShaderSource : public IWritableShaderSource
{ {
public: public:
ShaderSource(); ShaderSource();
~ShaderSource() override;
/* /*
- If shader material specified by name is found from cache, - If shader material specified by name is found from cache,
@ -351,6 +352,22 @@ ShaderSource::ShaderSource()
addShaderConstantSetterFactory(new MainShaderConstantSetterFactory()); addShaderConstantSetterFactory(new MainShaderConstantSetterFactory());
} }
ShaderSource::~ShaderSource()
{
MutexAutoLock lock(m_shaderinfo_cache_mutex);
#if IRRLICHT_VERSION_MT_REVISION >= 15
// Delete materials
video::IGPUProgrammingServices *gpu = RenderingEngine::get_video_driver()->
getGPUProgrammingServices();
for (ShaderInfo &i : m_shaderinfo_cache) {
if (!i.name.empty())
gpu->deleteShaderMaterial(i.material);
}
m_shaderinfo_cache.clear();
#endif
}
u32 ShaderSource::getShader(const std::string &name, u32 ShaderSource::getShader(const std::string &name,
MaterialType material_type, NodeDrawType drawtype) MaterialType material_type, NodeDrawType drawtype)
{ {
@ -472,15 +489,17 @@ void ShaderSource::rebuildShaders()
{ {
MutexAutoLock lock(m_shaderinfo_cache_mutex); MutexAutoLock lock(m_shaderinfo_cache_mutex);
/*// Oh well... just clear everything, they'll load sometime. #if IRRLICHT_VERSION_MT_REVISION >= 15
m_shaderinfo_cache.clear(); // Delete materials
m_name_to_id.clear();*/ video::IGPUProgrammingServices *gpu = RenderingEngine::get_video_driver()->
getGPUProgrammingServices();
/* for (ShaderInfo &i : m_shaderinfo_cache) {
FIXME: Old shader materials can't be deleted in Irrlicht, if (!i.name.empty()) {
or can they? gpu->deleteShaderMaterial(i.material);
(This would be nice to do in the destructor too) i.material = video::EMT_SOLID; // invalidate
*/ }
}
#endif
// Recreate shaders // Recreate shaders
for (ShaderInfo &i : m_shaderinfo_cache) { for (ShaderInfo &i : m_shaderinfo_cache) {