GRIM: Reload the shared materials with the new colormap. Fix #299
This commit is contained in:
parent
075c1cae7d
commit
cc4fcd3ffc
4 changed files with 22 additions and 4 deletions
|
@ -26,6 +26,7 @@
|
||||||
#include "engines/grim/material.h"
|
#include "engines/grim/material.h"
|
||||||
#include "engines/grim/gfx_base.h"
|
#include "engines/grim/gfx_base.h"
|
||||||
#include "engines/grim/colormap.h"
|
#include "engines/grim/colormap.h"
|
||||||
|
#include "engines/grim/resource.h"
|
||||||
|
|
||||||
namespace Grim {
|
namespace Grim {
|
||||||
|
|
||||||
|
@ -95,6 +96,20 @@ Material::Material(const Common::String &filename, const char *data, int len, CM
|
||||||
_data = MaterialData::getMaterialData(filename, data, len, cmap);
|
_data = MaterialData::getMaterialData(filename, data, len, cmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Material::reload(CMap *cmap) {
|
||||||
|
Common::String fname = _data->_fname;
|
||||||
|
--_data->_refCount;
|
||||||
|
if (_data->_refCount < 1) {
|
||||||
|
delete _data;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material *m = g_resourceloader->loadMaterial(fname, cmap);
|
||||||
|
// Steal the data from the new material and discard it.
|
||||||
|
_data = m->_data;
|
||||||
|
++_data->_refCount;
|
||||||
|
delete m;
|
||||||
|
}
|
||||||
|
|
||||||
void Material::select() const {
|
void Material::select() const {
|
||||||
if (_data->_width && _data->_height)
|
if (_data->_width && _data->_height)
|
||||||
g_driver->selectMaterial(this);
|
g_driver->selectMaterial(this);
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
// Load a texture from the given data.
|
// Load a texture from the given data.
|
||||||
Material(const Common::String &filename, const char *data, int len, CMap *cmap);
|
Material(const Common::String &filename, const char *data, int len, CMap *cmap);
|
||||||
|
|
||||||
|
void reload(CMap *cmap);
|
||||||
// Load this texture into the GL context
|
// Load this texture into the GL context
|
||||||
void select() const;
|
void select() const;
|
||||||
|
|
||||||
|
|
|
@ -242,13 +242,13 @@ void Model::loadMaterial(int index, CMap *cmap) {
|
||||||
}
|
}
|
||||||
_materials[index] = NULL;
|
_materials[index] = NULL;
|
||||||
if (_parent) {
|
if (_parent) {
|
||||||
_materials[index] = _parent->findMaterial(_materialNames[index]);
|
_materials[index] = _parent->findMaterial(_materialNames[index], cmap);
|
||||||
if (_materials[index]) {
|
if (_materials[index]) {
|
||||||
_materialsShared[index] = true;
|
_materialsShared[index] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!_materials[index]) {
|
if (!_materials[index]) {
|
||||||
if (mat && cmap == _cmap) {
|
if (mat && cmap->getFilename() == _cmap->getFilename()) {
|
||||||
_materials[index] = mat;
|
_materials[index] = mat;
|
||||||
} else {
|
} else {
|
||||||
_materials[index] = g_resourceloader->loadMaterial(_materialNames[index], cmap);
|
_materials[index] = g_resourceloader->loadMaterial(_materialNames[index], cmap);
|
||||||
|
@ -260,9 +260,11 @@ void Model::loadMaterial(int index, CMap *cmap) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Material *Model::findMaterial(const char *name) const {
|
Material *Model::findMaterial(const char *name, CMap *cmap) const {
|
||||||
for (int i = 0; i < _numMaterials; ++i) {
|
for (int i = 0; i < _numMaterials; ++i) {
|
||||||
if (scumm_stricmp(name, _materialNames[i]) == 0) {
|
if (scumm_stricmp(name, _materialNames[i]) == 0) {
|
||||||
|
if (cmap->getFilename() != _cmap->getFilename())
|
||||||
|
_materials[i]->reload(cmap);
|
||||||
return _materials[i];
|
return _materials[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
void loadEMI(Common::MemoryReadStream &ms);
|
void loadEMI(Common::MemoryReadStream &ms);
|
||||||
void reload(CMap *cmap);
|
void reload(CMap *cmap);
|
||||||
void draw() const;
|
void draw() const;
|
||||||
Material *findMaterial(const char *name) const;
|
Material *findMaterial(const char *name, CMap *cmap) const;
|
||||||
|
|
||||||
~Model();
|
~Model();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue