Updates ImageAsset usage to utilize AssetRef, and standardizes the setter/getter functions and naming conventions, as well as the ability to use and bind named targets.

This commit is contained in:
JeffR 2026-06-16 17:39:30 -05:00
parent a858d8624e
commit 34e3f78a22
82 changed files with 1451 additions and 951 deletions

View file

@ -556,8 +556,15 @@ void PostEffect::initPersistFields()
addField( "targetViewport", TYPEID< PFXTargetViewport >(), Offset( mTargetViewport, PostEffect ),
"Specifies how the viewport should be set up for a target texture." );
addProtectedField("Texture", TypeImageFilename, Offset(mTextureAsset, PostEffect), _setTextureData, &defaultProtectedGetFn, NumTextures, "Input textures to this effect(samplers).\n", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET_ARRAY(Texture, NumTextures, PostEffect, "Input textures to this effect ( samplers ).\n"
ADD_FIELD("texture", TypeImageAssetRef, Offset(mTextureAssetRef, PostEffect))
.elements(NumTextures)
.withFlags(AbstractClassRep::FIELD_HideInInspectors | AbstractClassRep::FIELD_DontWriteToFile)
.doc("Input textures to this effect ( samplers ).\n"
"@see PFXTextureIdentifiers");
ADD_FIELD("textureAsset", TypeImageAssetRef, Offset(mTextureAssetRef, PostEffect))
.elements(NumTextures)
.doc("Input textures to this effect ( samplers ).\n"
"@see PFXTextureIdentifiers");
addField("textureSRGB", TypeBool, Offset(mTexSRGB, PostEffect), NumTextures,
@ -609,18 +616,16 @@ bool PostEffect::onAdd()
for (S32 i = 0; i < NumTextures; i++)
{
mTextureType[i] = NormalTextureType;
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;
StringTableEntry texAssetId = mTextureAssetRef[i].assetId;
mTextureProfile[i] = (mTexSRGB[i]) ? &PostFxTextureSRGBProfile : &PostFxTextureProfile;
_setTexture(texFilename, i);
}
// Skip empty stages or ones with variable or target names.
if (dStrIsEmpty(texAssetId) ||
texAssetId[0] == '$' ||
texAssetId[0] == '#')
continue;
mTextureProfile[i] = (mTexSRGB[i]) ? &PostFxTextureSRGBProfile : &PostFxTextureProfile;
}
// Is the target a named target?
@ -1149,7 +1154,7 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
void PostEffect::_setupTexture( U32 stage, GFXTexHandle &inputTex, const RectI *inTexViewport )
{
const String &texFilename = mTextureAsset[stage].notNull() ? mTextureAsset[stage]->getImageFile() : "";
const String texFilename = mTextureAssetRef[stage].assetId;
GFXTexHandle theTex;
NamedTexTarget *namedTarget = NULL;
@ -1188,8 +1193,8 @@ void PostEffect::_setupTexture( U32 stage, GFXTexHandle &inputTex, const RectI *
{
theTex = mTexture[stage];
if (!theTex && mTextureAsset[stage].notNull())
theTex = mTextureAsset[stage]->getTexture(mTextureProfile[stage]);
if (!theTex)
theTex = getTexture(stage, mTextureProfile[stage]);
if ( theTex )
viewport.set( 0, 0, theTex->getWidth(), theTex->getHeight() );
@ -1670,8 +1675,8 @@ void PostEffect::setTexture( U32 index, const String &texFilePath )
return;
mTextureProfile[index] = (mTexSRGB[index])? &PostFxTextureSRGBProfile : &PostFxTextureProfile;
_setTexture(texFilePath, index);
mTexture[index] = mTextureAsset[index]->getTexture(mTextureProfile[index]);
mTextureAssetRef[index] = texFilePath.c_str();
mTexture[index] = getTexture(index, mTextureProfile[index]);
mTextureType[index] = NormalTextureType;
}
@ -1866,21 +1871,18 @@ void PostEffect::_checkRequirements()
{
if (mTextureType[i] == NormalTextureType)
{
if (mTextureAsset[i].notNull())
StringTableEntry texAssetId = mTextureAssetRef[i].assetId;
if (!dStrIsEmpty(texAssetId) && texAssetId[0] == '#')
{
const String& texFilename = mTextureAsset[i]->getImageFile();
if (texFilename.isNotEmpty() && texFilename[0] == '#')
NamedTexTarget* namedTarget = NamedTexTarget::find(texAssetId + 1);
if (!namedTarget)
{
NamedTexTarget* namedTarget = NamedTexTarget::find(texFilename.c_str() + 1);
if (!namedTarget)
{
return;
}
// Grab the macros for shader initialization.
namedTarget->getShaderMacros(&macros);
return;
}
// Grab the macros for shader initialization.
namedTarget->getShaderMacros(&macros);
}
}
}

View file

@ -90,7 +90,8 @@ public:
protected:
DECLARE_IMAGEASSET_ARRAY(PostEffect, Texture, GFXStaticTextureSRGBProfile, NumTextures);
AssetRef<ImageAsset> mTextureAssetRef[NumTextures];
GFXTexHandle getTexture(const U32& index, GFXTextureProfile* profile) { return mTextureAssetRef[index].notNull() ? mTextureAssetRef[index].assetPtr->getTexture(profile) : GFXTexHandle(); }
GFXTextureProfile* mTextureProfile[NumTextures];
GFXTexHandle mTexture[NumTextures];
@ -440,6 +441,8 @@ public:
F32 getPriority() const { return mRenderPriority; }
StringTableEntry getTextureAssetId(const U32& index) const { return mTextureAssetRef[index].assetId; }
void setTexture( U32 index, const String &filePath );
void setTexture(U32 index, const GFXTexHandle& texHandle);
void setCubemapTexture(U32 index, const GFXCubemapHandle &cubemapHandle);

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->mTextureAsset[i-1].notNull() && pfx->mTextureAsset[i - 1]->getImageFile() == StringTable->EmptyString())
if ( pfx->getTextureAssetId(i - 1) == 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->mTextureAsset[i - 1].notNull() ? pfx->mTextureAsset[i - 1]->getImageFile() : "", tex->getWidth(), tex->getHeight());
dSprintf( caption, 256, "%s[%i] input%i - %s [ %ix%i ]", name, pfx->getId(), i-1, pfx->getTextureAssetId(i - 1), tex->getWidth(), tex->getHeight());
else
dSprintf( caption, 256, "%s[%i] input%i - %s", name, pfx->getId(), i-1, pfx->mTextureAsset[i - 1].notNull() ? pfx->mTextureAsset[i - 1]->getImageFile() : "");
dSprintf( caption, 256, "%s[%i] input%i - %s", name, pfx->getId(), i-1, pfx->getTextureAssetId(i - 1));
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->mTextureAsset[texIndex - 1].notNull() ? pfx->mTextureAsset[texIndex - 1]->getImageFile() : "");
dSprintf( caption, 256, "%s[%i] input%i - %s [NOT ENABLED]", name, pfx->getId(), texIndex-1, pfx->getTextureAssetId(texIndex - 1));
winCtrl->setDataField( StringTable->insert("text"), NULL, caption );
}