mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 00:24:40 +00:00
fixes for reload and flush
This commit is contained in:
parent
f6dc694bd4
commit
1edfbcf447
7 changed files with 88 additions and 39 deletions
|
|
@ -377,12 +377,10 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
|
||||||
NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1);
|
NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1);
|
||||||
if (namedTarget.isValid() && namedTarget->getTexture())
|
if (namedTarget.isValid() && namedTarget->getTexture())
|
||||||
{
|
{
|
||||||
if (mNamedTarget == NULL) {
|
mNamedTarget = namedTarget;
|
||||||
mNamedTarget = namedTarget;
|
mIsValidImage = true;
|
||||||
mResourceMap.insert(requestedProfile, mNamedTarget->getTexture());
|
mResourceMap.insert(requestedProfile, mNamedTarget->getTexture());
|
||||||
mIsValidImage = true;
|
mChangeSignal.trigger();
|
||||||
mChangeSignal.trigger();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mNamedTarget == NULL)
|
if (mNamedTarget == NULL)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ public: \
|
||||||
else if(_in[0] == '$' || _in[0] == '#')\
|
else if(_in[0] == '$' || _in[0] == '#')\
|
||||||
{\
|
{\
|
||||||
m##name##Name = _in;\
|
m##name##Name = _in;\
|
||||||
m##name##AssetId = _in;\
|
m##name##AssetId = StringTable->EmptyString();\
|
||||||
m##name##Asset = NULL;\
|
m##name##Asset = NULL;\
|
||||||
m##name.free();\
|
m##name.free();\
|
||||||
m##name = NULL;\
|
m##name = NULL;\
|
||||||
|
|
@ -256,15 +256,9 @@ public: \
|
||||||
m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
|
m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
if (get##name()[0] == '$' || get##name()[0] == '#') {\
|
if (get##name()[0] != '$' && get##name()[0] != '#') {\
|
||||||
NamedTexTargetRef namedTarget = NamedTexTarget::find(get##name() + 1);\
|
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
||||||
if (namedTarget.isValid())\
|
|
||||||
{\
|
|
||||||
m##name = namedTarget->getTexture(0);\
|
|
||||||
}\
|
|
||||||
}\
|
}\
|
||||||
else\
|
|
||||||
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
|
||||||
}\
|
}\
|
||||||
else\
|
else\
|
||||||
{\
|
{\
|
||||||
|
|
@ -373,7 +367,7 @@ public: \
|
||||||
else if(_in[0] == '$' || _in[0] == '#')\
|
else if(_in[0] == '$' || _in[0] == '#')\
|
||||||
{\
|
{\
|
||||||
m##name##Name[index] = _in;\
|
m##name##Name[index] = _in;\
|
||||||
m##name##AssetId[index] = _in;\
|
m##name##AssetId[index] = StringTable->EmptyString();\
|
||||||
m##name##Asset[index] = NULL;\
|
m##name##Asset[index] = NULL;\
|
||||||
m##name[index].free();\
|
m##name[index].free();\
|
||||||
m##name[index] = NULL;\
|
m##name[index] = NULL;\
|
||||||
|
|
|
||||||
|
|
@ -243,6 +243,10 @@ Material::Material()
|
||||||
mReverbSoundOcclusion = 1.0;
|
mReverbSoundOcclusion = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Material::onImageAssetChanged()
|
||||||
|
{
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
void Material::initPersistFields()
|
void Material::initPersistFields()
|
||||||
{
|
{
|
||||||
|
|
@ -857,3 +861,4 @@ DEF_IMAGEASSET_ARRAY_BINDS(Material, AOMap);
|
||||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, MetalMap);
|
DEF_IMAGEASSET_ARRAY_BINDS(Material, MetalMap);
|
||||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, GlowMap);
|
DEF_IMAGEASSET_ARRAY_BINDS(Material, GlowMap);
|
||||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailNormalMap);
|
DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailNormalMap);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -208,9 +208,7 @@ public:
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// Data
|
// Data
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
void onImageAssetChanged() {
|
void onImageAssetChanged();
|
||||||
reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, MAX_STAGES, onImageAssetChanged);
|
DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, MAX_STAGES, onImageAssetChanged);
|
||||||
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DiffuseMap);
|
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DiffuseMap);
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,8 @@ MaterialManager::MaterialManager()
|
||||||
mLastTime = 0;
|
mLastTime = 0;
|
||||||
mDampness = 0.0f;
|
mDampness = 0.0f;
|
||||||
mWarningInst = NULL;
|
mWarningInst = NULL;
|
||||||
|
mMatDefToFlush = NULL;
|
||||||
|
mMatDefToReload = NULL;
|
||||||
|
|
||||||
GFXDevice::getDeviceEventSignal().notify( this, &MaterialManager::_handleGFXEvent );
|
GFXDevice::getDeviceEventSignal().notify( this, &MaterialManager::_handleGFXEvent );
|
||||||
|
|
||||||
|
|
@ -73,6 +75,8 @@ MaterialManager::MaterialManager()
|
||||||
mUsingDeferred = false;
|
mUsingDeferred = false;
|
||||||
|
|
||||||
mFlushAndReInit = false;
|
mFlushAndReInit = false;
|
||||||
|
mMatDefShouldFlush = false;
|
||||||
|
mMatDefShouldReload = false;
|
||||||
|
|
||||||
mDefaultAnisotropy = 1;
|
mDefaultAnisotropy = 1;
|
||||||
Con::addVariable( "$pref::Video::defaultAnisotropy", TypeS32, &mDefaultAnisotropy,
|
Con::addVariable( "$pref::Video::defaultAnisotropy", TypeS32, &mDefaultAnisotropy,
|
||||||
|
|
@ -324,6 +328,12 @@ String MaterialManager::getMapEntry(const String & textureName) const
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialManager::flushAndReInitInstances()
|
void MaterialManager::flushAndReInitInstances()
|
||||||
|
{
|
||||||
|
// delay flushes and reinits until the start of the next frame.
|
||||||
|
mFlushAndReInit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MaterialManager::_flushAndReInitInstances()
|
||||||
{
|
{
|
||||||
// Clear the flag if its set.
|
// Clear the flag if its set.
|
||||||
mFlushAndReInit = false;
|
mFlushAndReInit = false;
|
||||||
|
|
@ -359,8 +369,15 @@ void MaterialManager::flushAndReInitInstances()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used in the materialEditor. This flushes the material preview object so it can be reloaded easily.
|
// Used in the materialEditor. This flushes the material preview object so it can be reloaded easily.
|
||||||
void MaterialManager::flushInstance( BaseMaterialDefinition *target )
|
void MaterialManager::flushInstance(BaseMaterialDefinition* target)
|
||||||
{
|
{
|
||||||
|
mMatDefToFlush = target;
|
||||||
|
mMatDefShouldFlush = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MaterialManager::_flushInstance( BaseMaterialDefinition *target )
|
||||||
|
{
|
||||||
|
mMatDefShouldFlush = false;
|
||||||
Vector<BaseMatInstance*>::iterator iter = mMatInstanceList.begin();
|
Vector<BaseMatInstance*>::iterator iter = mMatInstanceList.begin();
|
||||||
while ( iter != mMatInstanceList.end() )
|
while ( iter != mMatInstanceList.end() )
|
||||||
{
|
{
|
||||||
|
|
@ -371,16 +388,26 @@ void MaterialManager::flushInstance( BaseMaterialDefinition *target )
|
||||||
}
|
}
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMatDefToFlush = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialManager::reInitInstance( BaseMaterialDefinition *target )
|
void MaterialManager::reInitInstance(BaseMaterialDefinition* target)
|
||||||
{
|
{
|
||||||
|
mMatDefToReload = target;
|
||||||
|
mMatDefShouldReload = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MaterialManager::_reInitInstance( BaseMaterialDefinition *target )
|
||||||
|
{
|
||||||
|
mMatDefShouldReload = false;
|
||||||
Vector<BaseMatInstance*>::iterator iter = mMatInstanceList.begin();
|
Vector<BaseMatInstance*>::iterator iter = mMatInstanceList.begin();
|
||||||
for ( ; iter != mMatInstanceList.end(); iter++ )
|
for ( ; iter != mMatInstanceList.end(); iter++ )
|
||||||
{
|
{
|
||||||
if ( (*iter)->getMaterial() == target )
|
if ( (*iter)->getMaterial() == target )
|
||||||
(*iter)->reInit();
|
(*iter)->reInit();
|
||||||
}
|
}
|
||||||
|
mMatDefToReload = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialManager::updateTime()
|
void MaterialManager::updateTime()
|
||||||
|
|
@ -499,7 +526,15 @@ bool MaterialManager::_handleGFXEvent( GFXDevice::GFXDeviceEventType event_ )
|
||||||
|
|
||||||
case GFXDevice::deStartOfFrame:
|
case GFXDevice::deStartOfFrame:
|
||||||
if ( mFlushAndReInit )
|
if ( mFlushAndReInit )
|
||||||
flushAndReInitInstances();
|
_flushAndReInitInstances();
|
||||||
|
if (mMatDefShouldFlush)
|
||||||
|
{
|
||||||
|
_flushInstance(mMatDefToFlush);
|
||||||
|
}
|
||||||
|
if (mMatDefShouldReload)
|
||||||
|
{
|
||||||
|
_reInitInstance(mMatDefToReload);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -116,11 +116,7 @@ public:
|
||||||
/// Returns the signal used to notify systems that the
|
/// Returns the signal used to notify systems that the
|
||||||
/// procedural shaders have been flushed.
|
/// procedural shaders have been flushed.
|
||||||
FlushSignal& getFlushSignal() { return mFlushSignal; }
|
FlushSignal& getFlushSignal() { return mFlushSignal; }
|
||||||
|
|
||||||
/// Flushes all the procedural shaders and re-initializes all
|
|
||||||
/// the active materials instances immediately.
|
|
||||||
void flushAndReInitInstances();
|
void flushAndReInitInstances();
|
||||||
|
|
||||||
// Flush the instance
|
// Flush the instance
|
||||||
void flushInstance( BaseMaterialDefinition *target );
|
void flushInstance( BaseMaterialDefinition *target );
|
||||||
|
|
||||||
|
|
@ -133,7 +129,14 @@ protected:
|
||||||
friend class MatInstance;
|
friend class MatInstance;
|
||||||
void _track(MatInstance*);
|
void _track(MatInstance*);
|
||||||
void _untrack(MatInstance*);
|
void _untrack(MatInstance*);
|
||||||
|
/// Flushes all the procedural shaders and re-initializes all
|
||||||
|
/// the active materials instances immediately.
|
||||||
|
void _flushAndReInitInstances();
|
||||||
|
// Flush the instance
|
||||||
|
void _flushInstance(BaseMaterialDefinition* target);
|
||||||
|
|
||||||
|
/// Re-initializes the material instances for a specific target material.
|
||||||
|
void _reInitInstance(BaseMaterialDefinition* target);
|
||||||
/// @see LightManager::smActivateSignal
|
/// @see LightManager::smActivateSignal
|
||||||
void _onLMActivate( const char *lm, bool activate );
|
void _onLMActivate( const char *lm, bool activate );
|
||||||
|
|
||||||
|
|
@ -155,6 +158,8 @@ protected:
|
||||||
/// If set we flush and reinitialize all materials at the
|
/// If set we flush and reinitialize all materials at the
|
||||||
/// start of the next rendered frame.
|
/// start of the next rendered frame.
|
||||||
bool mFlushAndReInit;
|
bool mFlushAndReInit;
|
||||||
|
bool mMatDefShouldReload;
|
||||||
|
bool mMatDefShouldFlush;
|
||||||
|
|
||||||
// material map
|
// material map
|
||||||
typedef Map<String, String> MaterialMap;
|
typedef Map<String, String> MaterialMap;
|
||||||
|
|
@ -169,6 +174,8 @@ protected:
|
||||||
F32 mDampness;
|
F32 mDampness;
|
||||||
|
|
||||||
BaseMatInstance* mWarningInst;
|
BaseMatInstance* mWarningInst;
|
||||||
|
BaseMaterialDefinition* mMatDefToFlush;
|
||||||
|
BaseMaterialDefinition* mMatDefToReload;
|
||||||
|
|
||||||
/// The default max anisotropy used in texture filtering.
|
/// The default max anisotropy used in texture filtering.
|
||||||
S32 mDefaultAnisotropy;
|
S32 mDefaultAnisotropy;
|
||||||
|
|
|
||||||
|
|
@ -395,30 +395,42 @@ void ProcessedMaterial::_setStageData()
|
||||||
if (mMaterial->mDiffuseMapAsset[i] && !mMaterial->mDiffuseMapAsset[i].isNull())
|
if (mMaterial->mDiffuseMapAsset[i] && !mMaterial->mDiffuseMapAsset[i].isNull())
|
||||||
{
|
{
|
||||||
mStages[i].setTex(MFT_DiffuseMap, mMaterial->getDiffuseMapResource(i));
|
mStages[i].setTex(MFT_DiffuseMap, mMaterial->getDiffuseMapResource(i));
|
||||||
//mStages[i].setTex(MFT_DiffuseMap, _createTexture(mMaterial->getDiffuseMap(i), &GFXStaticTextureSRGBProfile));
|
|
||||||
if (!mStages[i].getTex(MFT_DiffuseMap))
|
if (!mStages[i].getTex(MFT_DiffuseMap))
|
||||||
{
|
{
|
||||||
|
// If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass.
|
||||||
if (String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("#") || String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("$"))
|
if (String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("#") || String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("$"))
|
||||||
{
|
{
|
||||||
NamedTexTarget* namedTarget = NamedTexTarget::find(mMaterial->mDiffuseMapAsset[i]->getImageFileName() + 1);
|
mMaterial->logError("Named Target not ready %s for stage %i", mMaterial->mDiffuseMapAsset[i]->getImageFileName(), i);
|
||||||
if (namedTarget)
|
mHasSetStageData = false;
|
||||||
mStages[i].setTex(MFT_DiffuseMap, namedTarget->getTexture(0));
|
|
||||||
if (mStages[i].getTex(MFT_DiffuseMap))
|
|
||||||
{
|
|
||||||
mMaterial->mDiffuseMap[i] = namedTarget->getTexture(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mStages[i].getTex(MFT_DiffuseMap))
|
|
||||||
mHasSetStageData = false;
|
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
|
// Load a debug texture to make it clear to the user
|
||||||
|
// that the texture for this stage was missing.
|
||||||
|
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mMaterial->mDiffuseMapName[i] != StringTable->EmptyString())
|
||||||
|
{
|
||||||
|
mStages[i].setTex(MFT_DiffuseMap, _createTexture(mMaterial->mDiffuseMapName[i], &GFXStaticTextureSRGBProfile));
|
||||||
|
if (!mStages[i].getTex(MFT_DiffuseMap))
|
||||||
|
{
|
||||||
|
//If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass. So we'll
|
||||||
|
//pass on the error rather than spamming the console
|
||||||
|
if (String(mMaterial->mDiffuseMapName[i]).startsWith("#") || String(mMaterial->mDiffuseMapName[i]).startsWith("$"))
|
||||||
|
{
|
||||||
|
mMaterial->logError("Named Target not ready %s for stage %i", mMaterial->mDiffuseMapName[i], i);
|
||||||
|
mHasSetStageData = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Load a debug texture to make it clear to the user
|
// Load a debug texture to make it clear to the user
|
||||||
// that the texture for this stage was missing.
|
// that the texture for this stage was missing.
|
||||||
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
|
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OverlayMap
|
// OverlayMap
|
||||||
if (mMaterial->getOverlayMap(i) != StringTable->EmptyString())
|
if (mMaterial->getOverlayMap(i) != StringTable->EmptyString())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue