requirements for postfx

update to handle posteffects with image_asset_refactor
This commit is contained in:
marauder2k7 2025-03-26 14:31:11 +00:00
parent e1a2a6d9f9
commit d86962d1fd
5 changed files with 42 additions and 39 deletions

View file

@ -387,7 +387,7 @@ void ImageAsset::setImageFile(StringTableEntry pImageFile)
if (mLoadedState == Ok)
Torque::FS::RemoveChangeNotification(mImageFile, this, &ImageAsset::_onFileChanged);
if (String(pImageFile).startsWith("#"))
if (String(pImageFile).startsWith("#") || String(pImageFile).startsWith("$"))
{
mImageFile = StringTable->insert(pImageFile);
mIsNamedTarget = true;

View file

@ -677,7 +677,6 @@ public:
void _set##name(StringTableEntry _in, const U32& index){ \
if(m##name##Asset[index].getAssetId() == _in) \
return; \
\
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry imageAssetId = StringTable->EmptyString(); \
@ -687,7 +686,7 @@ public:
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in)) \
else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
ImageAsset* privateImage = new ImageAsset(); \
privateImage->setImageFile(_in); \

View file

@ -508,10 +508,6 @@ PostEffect::PostEffect()
dMemset( mTexSizeSC, 0, sizeof( GFXShaderConstHandle* ) * NumTextures );
dMemset( mRenderTargetParamsSC, 0, sizeof( GFXShaderConstHandle* ) * NumTextures );
for (U32 i = 0; i < NumTextures; i++)
{
INIT_IMAGEASSET_ARRAY(Texture, PostFxTextureProfile, i);
}
}
PostEffect::~PostEffect()
@ -556,7 +552,8 @@ void PostEffect::initPersistFields()
addField( "targetViewport", TYPEID< PFXTargetViewport >(), Offset( mTargetViewport, PostEffect ),
"Specifies how the viewport should be set up for a target texture." );
INITPERSISTFIELD_IMAGEASSET_ARRAY(Texture, NumTextures, PostEffect, "Input textures to this effect ( samplers ).\n"
addProtectedField("Texture", TypeImageFilename, Offset(mTextureAsset, PostEffect), _setTextureData, &defaultProtectedGetFn, NumTextures, "Input textures to this effect(samplers).\n", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(Texture, NumTextures, PostEffect, "Input textures to this effect ( samplers ).\n"
"@see PFXTextureIdentifiers");
addField("textureSRGB", TypeBool, Offset(mTexSRGB, PostEffect), NumTextures,
@ -608,22 +605,24 @@ bool PostEffect::onAdd()
for (S32 i = 0; i < NumTextures; i++)
{
mTextureType[i] = NormalTextureType;
String texFilename = getTexture(i);
if (mTextureAsset[i].notNull()) {
String texFilename = mTextureAsset[i]->getImageFile();
// Skip empty stages or ones with variable or target names.
if (texFilename.isEmpty() ||
texFilename[0] == '$' ||
texFilename[0] == '#')
continue;
// Skip empty stages or ones with variable or target names.
if (texFilename.isEmpty() ||
texFilename[0] == '$' ||
texFilename[0] == '#')
continue;
mTextureProfile[i] = (mTexSRGB[i]) ? &PostFxTextureSRGBProfile : &PostFxTextureProfile;
_setTexture(texFilename, i);
mTextureProfile[i] = (mTexSRGB[i]) ? &PostFxTextureSRGBProfile : &PostFxTextureProfile;
_setTexture(texFilename, i);
}
}
// Is the target a named target?
if ( mTargetName.isNotEmpty() && mTargetName[0] == '#' )
{
mNamedTarget.registerWithName( mTargetName.substr( 1 ) );
mNamedTarget.registerWithName(mTargetName.substr(1));
mNamedTarget.getTextureDelegate().bind( this, &PostEffect::_getTargetTexture );
}
if ( mTargetDepthStencilName.isNotEmpty() && mTargetDepthStencilName[0] == '#' )
@ -1136,7 +1135,7 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
void PostEffect::_setupTexture( U32 stage, GFXTexHandle &inputTex, const RectI *inTexViewport )
{
const String &texFilename = getTexture( stage );
const String &texFilename = mTextureAsset[stage].notNull() ? mTextureAsset[stage]->getImageFile() : "";
GFXTexHandle theTex;
NamedTexTarget *namedTarget = NULL;
@ -1173,7 +1172,11 @@ void PostEffect::_setupTexture( U32 stage, GFXTexHandle &inputTex, const RectI *
}
else
{
theTex = mTexture[ stage ];
theTex = mTexture[stage];
if (!theTex && mTextureAsset[stage].notNull())
theTex = mTextureAsset[stage]->getTexture(mTextureProfile[stage]);
if ( theTex )
viewport.set( 0, 0, theTex->getWidth(), theTex->getHeight() );
}
@ -1640,7 +1643,6 @@ void PostEffect::reload()
void PostEffect::setTexture( U32 index, const String &texFilePath )
{
// Set the new texture name.
mTextureName[index] = texFilePath;
mTexture[index].free();
// Skip empty stages or ones with variable or target names.
@ -1651,14 +1653,13 @@ void PostEffect::setTexture( U32 index, const String &texFilePath )
mTextureProfile[index] = (mTexSRGB[index])? &PostFxTextureSRGBProfile : &PostFxTextureProfile;
_setTexture(texFilePath, index);
mTexture[index] = mTextureAsset[index]->getTexture(mTextureProfile[index]);
mTextureType[index] = NormalTextureType;
}
void PostEffect::setTexture(U32 index, const GFXTexHandle& texHandle)
{
// Set the new texture name.
mTextureName[index] = StringTable->EmptyString();
mTexture[index].free();
// Skip empty stages or ones with variable or target names.
@ -1847,18 +1848,21 @@ void PostEffect::_checkRequirements()
{
if (mTextureType[i] == NormalTextureType)
{
const String &texFilename = mTextureName[i];
if (texFilename.isNotEmpty() && texFilename[0] == '#')
if (mTextureAsset[i].notNull())
{
NamedTexTarget *namedTarget = NamedTexTarget::find(texFilename.c_str() + 1);
if (!namedTarget)
{
return;
}
const String& texFilename = mTextureAsset[i]->getImageFile();
// Grab the macros for shader initialization.
namedTarget->getShaderMacros(&macros);
if (texFilename.isNotEmpty() && texFilename[0] == '#')
{
NamedTexTarget* namedTarget = NamedTexTarget::find(texFilename.c_str() + 1);
if (!namedTarget)
{
return;
}
// Grab the macros for shader initialization.
namedTarget->getShaderMacros(&macros);
}
}
}
}

View file

@ -90,9 +90,9 @@ public:
protected:
DECLARE_IMAGEASSET_ARRAY(PostEffect, Texture, NumTextures, onTextureChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(PostEffect, Texture);
void onTextureChanged() {}
DECLARE_IMAGEASSET_ARRAY_REFACTOR(PostEffect, Texture, GFXStaticTextureSRGBProfile, NumTextures);
GFXTextureProfile* mTextureProfile[NumTextures];
GFXTexHandle mTexture[NumTextures];
bool mTexSRGB[NumTextures];

View file

@ -103,7 +103,7 @@ void PostEffectVis::open( PostEffect *pfx )
// Only allocate window/bitmaps for input textures that are actually used.
if ( i > Target )
{
if ( pfx->mTextureName[i-1] == StringTable->EmptyString())
if ( pfx->mTextureAsset[i-1].notNull() && pfx->mTextureAsset[i - 1]->getImageFile() == StringTable->EmptyString())
{
window.window[i] = NULL;
window.bmp[i] = NULL;
@ -275,9 +275,9 @@ void PostEffectVis::onPFXProcessed( PostEffect *pfx )
if ( tex )
dSprintf( caption, 256, "%s[%i] input%i - %s [ %ix%i ]", name, pfx->getId(), i-1, pfx->mTextureName[i-1], tex->getWidth(), tex->getHeight() );
dSprintf( caption, 256, "%s[%i] input%i - %s [ %ix%i ]", name, pfx->getId(), i-1, pfx->mTextureAsset[i - 1].notNull() ? pfx->mTextureAsset[i - 1]->getImageFile() : "", tex->getWidth(), tex->getHeight());
else
dSprintf( caption, 256, "%s[%i] input%i - %s", name, pfx->getId(), i-1, pfx->mTextureName[i-1] );
dSprintf( caption, 256, "%s[%i] input%i - %s", name, pfx->getId(), i-1, pfx->mTextureAsset[i - 1].notNull() ? pfx->mTextureAsset[i - 1]->getImageFile() : "");
pWinCtrl->setDataField( StringTable->insert("text"), NULL, caption );
}
@ -364,7 +364,7 @@ void PostEffectVis::_setDefaultCaption( VisWindow &vis, U32 texIndex )
else
dSprintf( name, 256, "%s", pfx->getName() );
dSprintf( caption, 256, "%s[%i] input%i - %s [NOT ENABLED]", name, pfx->getId(), texIndex-1, pfx->mTextureName[texIndex-1] );
dSprintf( caption, 256, "%s[%i] input%i - %s [NOT ENABLED]", name, pfx->getId(), texIndex-1, pfx->mTextureAsset[texIndex - 1].notNull() ? pfx->mTextureAsset[texIndex - 1]->getImageFile() : "");
winCtrl->setDataField( StringTable->insert("text"), NULL, caption );
}