From d86962d1fdce64b06aee449c0f9fa3e8aa5dd34f Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Wed, 26 Mar 2025 14:31:11 +0000 Subject: [PATCH] requirements for postfx update to handle posteffects with image_asset_refactor --- Engine/source/T3D/assets/ImageAsset.cpp | 2 +- Engine/source/T3D/assets/ImageAsset.h | 3 +- Engine/source/postFx/postEffect.cpp | 62 +++++++++++++------------ Engine/source/postFx/postEffect.h | 6 +-- Engine/source/postFx/postEffectVis.cpp | 8 ++-- 5 files changed, 42 insertions(+), 39 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index f02e79db0..0004145bd 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -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; diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 02ec29c5b..9d7338644 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -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); \ diff --git a/Engine/source/postFx/postEffect.cpp b/Engine/source/postFx/postEffect.cpp index 8026dd392..8c87d601a 100644 --- a/Engine/source/postFx/postEffect.cpp +++ b/Engine/source/postFx/postEffect.cpp @@ -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(¯os); + if (texFilename.isNotEmpty() && texFilename[0] == '#') + { + NamedTexTarget* namedTarget = NamedTexTarget::find(texFilename.c_str() + 1); + if (!namedTarget) + { + return; + } + + // Grab the macros for shader initialization. + namedTarget->getShaderMacros(¯os); + } } } } diff --git a/Engine/source/postFx/postEffect.h b/Engine/source/postFx/postEffect.h index e485f14d2..4f9a1c2c8 100644 --- a/Engine/source/postFx/postEffect.h +++ b/Engine/source/postFx/postEffect.h @@ -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]; diff --git a/Engine/source/postFx/postEffectVis.cpp b/Engine/source/postFx/postEffectVis.cpp index a3ff66b9c..4a7442b72 100644 --- a/Engine/source/postFx/postEffectVis.cpp +++ b/Engine/source/postFx/postEffectVis.cpp @@ -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 ); }