Skip to content

Commit

Permalink
#5503: Add ReloadImages command to MaterialManager
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Aug 15, 2022
1 parent 8ba6e9f commit a90e50d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/ishaders.h
Expand Up @@ -599,6 +599,9 @@ class IMaterialManager

// Tries to find the named table, returns an empty reference if nothing found
virtual ITableDefinition::Ptr getTable(const std::string& name) = 0;

// Reload the textures used by the active shaders
virtual void reloadImages() = 0;
};

inline IMaterialManager& GlobalMaterialManager()
Expand Down
1 change: 1 addition & 0 deletions install/menu.xml
Expand Up @@ -23,6 +23,7 @@
<menuItem name="ConvertModel" caption="Import/Convert Model..." command="ConvertModelDialog" />
<menuSeparator />
<menuItem name="reloadDecls" caption="Reload Declarations" command="ReloadDecls" icon="decl.png" />
<menuItem name="reloadImages" caption="Reload Images" command="ReloadImages" icon="icon_texture.png" />
<menuItem name="refreshModels" caption="&amp;Reload Models" command="RefreshModels" icon="model16green.png" />
<menuItem name="refreshSelectedModels" caption="Reload Selected Models" command="RefreshSelectedModels" icon="model16green.png" />
<menuSeparator />
Expand Down
12 changes: 12 additions & 0 deletions radiantcore/shaders/MaterialManager.cpp
Expand Up @@ -5,6 +5,7 @@
#include "ideclmanager.h"

#include "iregistry.h"
#include "icommandsystem.h"
#include "ifilesystem.h"
#include "ifiletypes.h"
#include "igame.h"
Expand Down Expand Up @@ -276,6 +277,14 @@ ITableDefinition::Ptr MaterialManager::getTable(const std::string& name)
);
}

void MaterialManager::reloadImages()
{
_library->foreachShader([](const CShaderPtr& shader)
{
shader->refreshImageMaps();
});
}

const std::string& MaterialManager::getName() const
{
static std::string _name(MODULE_SHADERSYSTEM);
Expand All @@ -288,6 +297,7 @@ const StringSet& MaterialManager::getDependencies() const
{
MODULE_DECLMANAGER,
MODULE_VIRTUALFILESYSTEM,
MODULE_COMMANDSYSTEM,
MODULE_XMLREGISTRY,
MODULE_GAMEMANAGER,
MODULE_FILETYPES,
Expand All @@ -311,6 +321,8 @@ void MaterialManager::initialiseModule(const IApplicationContext& ctx)

// Register the mtr file extension
GlobalFiletypes().registerPattern("material", FileTypePattern(_("Material File"), "mtr", "*.mtr"));

GlobalCommandSystem().addCommand("ReloadImages", [this](const cmd::ArgumentList&) { reloadImages(); });
}

void MaterialManager::onMaterialDefsReloaded()
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/shaders/MaterialManager.h
Expand Up @@ -88,6 +88,8 @@ class MaterialManager :
// Look up a table def, return NULL if not found
ITableDefinition::Ptr getTable(const std::string& name) override;

void reloadImages() override;

public:
sigc::signal<void> signal_activeShadersChanged() const override;

Expand Down

0 comments on commit a90e50d

Please sign in to comment.