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

View file

@ -137,7 +137,6 @@ private:
GFXTexHandle mTextureHandle; GFXTexHandle mTextureHandle;
ImageTypes mImageType; ImageTypes mImageType;
HashMap<GFXTextureProfile*, GFXTexHandle> mResourceMap; HashMap<GFXTextureProfile*, GFXTexHandle> mResourceMap;
void generateTexture(void); void generateTexture(void);
public: public:
ImageAsset(); ImageAsset();
@ -189,6 +188,9 @@ public:
inline U32 getTextureBitmapDepth(void) const { return mTextureHandle->getBitmapDepth(); } inline U32 getTextureBitmapDepth(void) const { return mTextureHandle->getBitmapDepth(); }
bool isAssetValid(void) const override { return !mTextureHandle.isNull(); } 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 U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName); static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset); 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("#")) 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 = mMaterial->getDiffuseMapAsset(0)->getNamedTarget();
NamedTexTarget *texTarget = NamedTexTarget::find(texTargetBufferName);
RenderPassData* rpd = getPass(0); RenderPassData* rpd = getPass(0);
if (rpd) if (rpd)
@ -878,8 +877,17 @@ void ProcessedShaderMaterial::setTextureStages( SceneRenderState *state, const S
texTarget = rpd->mTexSlot[i].texTarget; texTarget = rpd->mTexSlot[i].texTarget;
if ( !texTarget ) if ( !texTarget )
{ {
GFX->setTexture( i, NULL ); // try again.
break; texTarget = mMaterial->getDiffuseMapAsset(0)->getNamedTarget();
if (!texTarget)
{
GFX->setTexture(i, NULL);
break;
}
else
{
rpd->mTexSlot[i].texTarget = texTarget;
}
} }
texObject = texTarget->getTexture(); texObject = texTarget->getTexture();