named target functionality

This commit is contained in:
marauder2k7 2025-03-25 18:22:26 +00:00
parent 6640cae0d7
commit 987ff90467
3 changed files with 40 additions and 5 deletions

View file

@ -332,6 +332,9 @@ void ImageAsset::initializeAsset(void)
Parent::initializeAsset();
// Ensure the image-file is expanded.
if (isNamedTarget())
return;
mImageFile = expandAssetFilePath(mImageFile);
}
@ -378,6 +381,13 @@ void ImageAsset::setImageFile(StringTableEntry pImageFile)
if (mLoadedState == Ok)
Torque::FS::RemoveChangeNotification(mImageFile, this, &ImageAsset::_onFileChanged);
if (String(pImageFile).startsWith("#"))
{
mImageFile = StringTable->insert(pImageFile);
refreshAsset();
return;
}
mImageFile = getOwned() ? expandAssetFilePath(pImageFile) : StringTable->insert(pImageFile);
refreshAsset();
@ -411,6 +421,12 @@ U32 ImageAsset::load()
if (!Torque::FS::IsFile(mImageFile))
{
if (isNamedTarget())
{
mLoadedState = Ok;
return mLoadedState;
}
Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFile);
mLoadedState = BadFileReference;
return mLoadedState;
@ -428,6 +444,9 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
{
load();
if (isNamedTarget())
return getNamedTarget()->getTexture();
if (mLoadedState == Ok)
{
if (mResourceMap.contains(requestedProfile))
@ -554,6 +573,9 @@ void ImageAsset::onTamlPreWrite(void)
// Call parent.
Parent::onTamlPreWrite();
if (isNamedTarget())
return;
// Ensure the image-file is collapsed.
mImageFile = getOwned() ? collapseAssetFilePath(mImageFile) : mImageFile;
}
@ -563,6 +585,9 @@ void ImageAsset::onTamlPostWrite(void)
// Call parent.
Parent::onTamlPostWrite();
if (isNamedTarget())
return;
// Ensure the image-file is expanded.
mImageFile = getOwned() ? expandAssetFilePath(mImageFile) : mImageFile;
}

View file

@ -137,7 +137,6 @@ private:
GFXTexHandle mTextureHandle;
ImageTypes mImageType;
HashMap<GFXTextureProfile*, GFXTexHandle> mResourceMap;
void generateTexture(void);
public:
ImageAsset();
@ -189,6 +188,9 @@ public:
inline U32 getTextureBitmapDepth(void) const { return mTextureHandle->getBitmapDepth(); }
bool isAssetValid(void) const override { return !mTextureHandle.isNull(); }
bool isNamedTarget(void) const { return String(getImageFile()).startsWith("#"); }
NamedTexTargetRef getNamedTarget(void) const { return NamedTexTarget::find(mImageFile + 1); }
static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);

View file

@ -231,8 +231,7 @@ bool ProcessedShaderMaterial::init( const FeatureSet &features,
}
if (mMaterial && mMaterial->getDiffuseMapAsset(0).notNull() && String(mMaterial->getDiffuseMapAsset(0)->getImageFile()).startsWith("#"))
{
String texTargetBufferName = String(mMaterial->getDiffuseMapAsset(0)->getImageFile()).substr(1, (U32)strlen(mMaterial->getDiffuseMapAsset(0)->getImageFile()) - 1);
NamedTexTarget *texTarget = NamedTexTarget::find(texTargetBufferName);
NamedTexTarget *texTarget = mMaterial->getDiffuseMapAsset(0)->getNamedTarget();
RenderPassData* rpd = getPass(0);
if (rpd)
@ -878,8 +877,17 @@ void ProcessedShaderMaterial::setTextureStages( SceneRenderState *state, const S
texTarget = rpd->mTexSlot[i].texTarget;
if ( !texTarget )
{
GFX->setTexture( i, NULL );
break;
// try again.
texTarget = mMaterial->getDiffuseMapAsset(0)->getNamedTarget();
if (!texTarget)
{
GFX->setTexture(i, NULL);
break;
}
else
{
rpd->mTexSlot[i].texTarget = texTarget;
}
}
texObject = texTarget->getTexture();