Skip to content

Commit

Permalink
Merge pull request #1340 from marauder2k9-torque/ImageAsset-NamedTexT…
Browse files Browse the repository at this point in the history
…arget

NamedTexTargets as ImageAssets
  • Loading branch information
Azaezel authored Dec 23, 2024
2 parents 783f2a0 + 0458228 commit 69fa4b3
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 53 deletions.
65 changes: 54 additions & 11 deletions Engine/source/T3D/assets/ImageAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ U32 ImageAsset::load()
if (mLoadedState == AssetErrCode::Ok) return mLoadedState;
if (mImagePath)
{
// this is a target.
if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
{
NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1);
if (namedTarget) {
mLoadedState = Ok;
mIsValidImage = true;
return mLoadedState;
}
else
{
Con::errorf("ImageAsset::initializeAsset: Attempted find named target %s failed.", mImageFileName);
}
}
if (!Torque::FS::IsFile(mImagePath))
{
Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFileName);
Expand All @@ -295,12 +309,26 @@ void ImageAsset::initializeAsset()
{
ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);

mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
{
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
}
else
{
mImagePath = mImageFileName;
}
}

void ImageAsset::onAssetRefresh()
{
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
{
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
}
else
{
mImagePath = mImageFileName;
}

AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId);
// Iterate all dependencies.
Expand Down Expand Up @@ -334,28 +362,43 @@ void ImageAsset::setImageFileName(const char* pScriptFile)

GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
{
load();
if (mResourceMap.contains(requestedProfile))
{
mLoadedState = Ok;
return mResourceMap.find(requestedProfile)->value;
}
else
{
//If we don't have an existing map case to the requested format, we'll just create it and insert it in
GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, requestedProfile);
if (newTex)
// this is a target.
if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
{
mResourceMap.insert(requestedProfile, newTex);
mLoadedState = Ok;
return newTex;
NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1);
if (namedTarget.isValid() && namedTarget->getTexture())
{
mNamedTarget = namedTarget;
mIsValidImage = true;
mResourceMap.insert(requestedProfile, mNamedTarget->getTexture());
mChangeSignal.trigger();
return mNamedTarget->getTexture();
}
}
else
mLoadedState = BadFileReference;
{
//If we don't have an existing map case to the requested format, we'll just create it and insert it in
GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, requestedProfile);
if (newTex)
{
mResourceMap.insert(requestedProfile, newTex);
mLoadedState = Ok;
return newTex;
}
else
mLoadedState = BadFileReference;
}
}

//if (mTexture.isValid())
// return mTexture;

return nullptr;
}

Expand Down
34 changes: 27 additions & 7 deletions Engine/source/T3D/assets/ImageAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
#include "assetMacroHelpers.h"

#include "gfx/gfxDevice.h"

#ifndef _MATTEXTURETARGET_H_
#include "materials/matTextureTarget.h"
#endif

//-----------------------------------------------------------------------------
class ImageAsset : public AssetBase
{
Expand Down Expand Up @@ -95,6 +100,7 @@ class ImageAsset : public AssetBase
protected:
StringTableEntry mImageFileName;
StringTableEntry mImagePath;
NamedTexTargetRef mNamedTarget;

bool mIsValidImage;
bool mUseMips;
Expand Down Expand Up @@ -205,7 +211,7 @@ public: \
}\
else if(_in[0] == '$' || _in[0] == '#')\
{\
m##name##Name = _in;\
m##name##Name = _in;\
m##name##AssetId = StringTable->EmptyString();\
m##name##Asset = NULL;\
m##name.free();\
Expand Down Expand Up @@ -250,7 +256,9 @@ public: \
m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
}\
\
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
if (get##name()[0] != '$' && get##name()[0] != '#') {\
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
}\
}\
else\
{\
Expand Down Expand Up @@ -278,7 +286,10 @@ public: \
const StringTableEntry get##name() const\
{\
if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\
return Platform::makeRelativePathName(m##name##Asset->getImagePath(), Platform::getMainDotCsDir());\
if (m##name##Asset->getImageFileName()[0] == '#' || m##name##Asset->getImageFileName()[0] == '$')\
return m##name##Asset->getImageFileName();\
else\
return Platform::makeRelativePathName(m##name##Asset->getImagePath(), Platform::getMainDotCsDir());\
else if (m##name##AssetId != StringTable->EmptyString())\
return m##name##AssetId;\
else if (m##name##Name != StringTable->EmptyString())\
Expand All @@ -288,6 +299,8 @@ public: \
}\
GFXTexHandle get##name##Resource() \
{\
if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\
return m##name##Asset->getTexture(m##name##Profile);\
return m##name;\
}\
bool name##Valid() {return (get##name() != StringTable->EmptyString() && m##name##Asset->getStatus() == AssetBase::Ok); }
Expand Down Expand Up @@ -323,7 +336,7 @@ if (m##name##AssetId != StringTable->EmptyString())\
#pragma region Arrayed Asset Macros

//Arrayed Assets
#define DECLARE_IMAGEASSET_ARRAY(className, name, max) public: \
#define DECLARE_IMAGEASSET_ARRAY(className, name, max, changeFunc) public: \
static const U32 sm##name##Count = max;\
GFXTexHandle m##name[max];\
StringTableEntry m##name##Name[max]; \
Expand Down Expand Up @@ -353,7 +366,7 @@ public: \
}\
else if(_in[0] == '$' || _in[0] == '#')\
{\
m##name##Name[index] = _in;\
m##name##Name[index] = _in;\
m##name##AssetId[index] = StringTable->EmptyString();\
m##name##Asset[index] = NULL;\
m##name[index].free();\
Expand Down Expand Up @@ -393,7 +406,9 @@ public: \
}\
if (get##name(index) != StringTable->EmptyString() && m##name##Name[index] != StringTable->insert("texhandle"))\
{\
m##name[index].set(get##name(index), m##name##Profile[index], avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
m##name##Asset[index]->getChangedSignal().notify(this, &className::changeFunc);\
if (get##name(index)[0] != '$' && get##name(index)[0] != '#')\
m##name[index].set(get##name(index), m##name##Profile[index], avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
}\
else\
{\
Expand Down Expand Up @@ -421,7 +436,10 @@ public: \
const StringTableEntry get##name(const U32& index) const\
{\
if (m##name##Asset[index] && (m##name##Asset[index]->getImageFileName() != StringTable->EmptyString()))\
return Platform::makeRelativePathName(m##name##Asset[index]->getImagePath(), Platform::getMainDotCsDir());\
if (m##name##Asset[index]->getImageFileName()[0] == '#' || m##name##Asset[index]->getImageFileName()[0] == '$')\
return m##name##Asset[index]->getImageFileName();\
else\
return Platform::makeRelativePathName(m##name##Asset[index]->getImagePath(), Platform::getMainDotCsDir());\
else if (m##name##AssetId[index] != StringTable->EmptyString())\
return m##name##AssetId[index];\
else if (m##name##Name[index] != StringTable->EmptyString())\
Expand All @@ -438,6 +456,8 @@ public: \
{\
if(index >= sm##name##Count || index < 0)\
return nullptr;\
if (m##name##Asset[index] && (m##name##Asset[index]->getImageFileName() != StringTable->EmptyString()))\
return m##name##Asset[index]->getTexture(m##name##Profile[index]);\
return m##name[index];\
}\
bool name##Valid(const U32& id) {return (get##name(id) != StringTable->EmptyString() && m##name##Asset[id]->getStatus() == AssetBase::Ok); }
Expand Down
3 changes: 2 additions & 1 deletion Engine/source/T3D/fx/splash.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ class SplashData : public GameBaseData
F32 times[ NUM_TIME_KEYS ];
LinearColorF colors[ NUM_TIME_KEYS ];

DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, NUM_TEX);
DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, NUM_TEX, onTextureChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(SplashData, Texture)
void onTextureChanged() {}

ExplosionData* explosion;
S32 explosionId;
Expand Down
4 changes: 2 additions & 2 deletions Engine/source/environment/basicClouds.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class BasicClouds : public SceneObject
static U32 smVertCount;
static U32 smTriangleCount;

DECLARE_IMAGEASSET_ARRAY(BasicClouds, Texture, TEX_COUNT);
DECLARE_IMAGEASSET_ARRAY(BasicClouds, Texture, TEX_COUNT, onTextureChanged);
DECLARE_IMAGEASSET_ARRAY_NET_SETGET(BasicClouds, Texture, -1);

void onTextureChanged() {}
GFXStateBlockRef mStateblock;

GFXShaderRef mShader;
Expand Down
3 changes: 2 additions & 1 deletion Engine/source/gfx/sim/cubemapData.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ class CubemapData : public SimObject
DECLARE_IMAGEASSET(CubemapData, CubeMap, onCubemapChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(CubemapData, CubeMap);

DECLARE_IMAGEASSET_ARRAY(CubemapData, CubeMapFace, 6);
DECLARE_IMAGEASSET_ARRAY(CubemapData, CubeMapFace, 6, onCubeMapFaceChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(CubemapData, CubeMapFace);

void onCubeMapFaceChanged() {}
GFXTexHandle mDepthBuff;
GFXTextureTargetRef mRenderTarget;

Expand Down
4 changes: 2 additions & 2 deletions Engine/source/gui/controls/guiPopUpCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ class GuiPopUpMenuCtrl : public GuiTextCtrl
NumBitmapModes = 2
};

DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrl, Bitmap, NumBitmapModes);
DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrl, Bitmap, NumBitmapModes, onBitmapChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(GuiPopUpMenuCtrl, Bitmap);

void onBitmapChanged() {}
Point2I mBitmapBounds; // Added
S32 mIdMax;

Expand Down
4 changes: 2 additions & 2 deletions Engine/source/gui/controls/guiPopUpCtrlEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ class GuiPopUpMenuCtrlEx : public GuiTextCtrl
NumBitmapModes = 2
};

DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrlEx, Bitmap, NumBitmapModes);
DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrlEx, Bitmap, NumBitmapModes, onBitmapChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(GuiPopUpMenuCtrlEx, Bitmap);

void onBitmapChanged() {}
Point2I mBitmapBounds; // Added

S32 mIdMax;
Expand Down
6 changes: 6 additions & 0 deletions Engine/source/materials/materialDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ Material::Material()
mReverbSoundOcclusion = 1.0;
}

void Material::onImageAssetChanged()
{
flush();
reload();
}

void Material::initPersistFields()
{
Expand Down Expand Up @@ -857,3 +862,4 @@ DEF_IMAGEASSET_ARRAY_BINDS(Material, AOMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, MetalMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, GlowMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailNormalMap);

26 changes: 14 additions & 12 deletions Engine/source/materials/materialDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,49 +208,51 @@ class Material : public BaseMaterialDefinition
//-----------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------
DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, MAX_STAGES);
void onImageAssetChanged();

DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DiffuseMap);

bool mDiffuseMapSRGB[MAX_STAGES]; // SRGB diffuse
DECLARE_IMAGEASSET_ARRAY(Material, OverlayMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, OverlayMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, OverlayMap);

DECLARE_IMAGEASSET_ARRAY(Material, LightMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, LightMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, LightMap);

DECLARE_IMAGEASSET_ARRAY(Material, ToneMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, ToneMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, ToneMap);

DECLARE_IMAGEASSET_ARRAY(Material, DetailMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, DetailMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DetailMap);

DECLARE_IMAGEASSET_ARRAY(Material, NormalMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, NormalMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, NormalMap);

DECLARE_IMAGEASSET_ARRAY(Material, ORMConfigMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, ORMConfigMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, ORMConfigMap);

bool mIsSRGb[MAX_STAGES];
DECLARE_IMAGEASSET_ARRAY(Material, AOMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, AOMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, AOMap);
F32 mAOChan[MAX_STAGES];

DECLARE_IMAGEASSET_ARRAY(Material, RoughMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, RoughMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, RoughMap);
bool mInvertRoughness[MAX_STAGES];
F32 mRoughnessChan[MAX_STAGES];

DECLARE_IMAGEASSET_ARRAY(Material, MetalMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, MetalMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, MetalMap);

F32 mMetalChan[MAX_STAGES];
DECLARE_IMAGEASSET_ARRAY(Material, GlowMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, GlowMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, GlowMap);

F32 mGlowMul[MAX_STAGES];
/// A second normal map which repeats at the detail map
/// scale and blended with the base normal map.
DECLARE_IMAGEASSET_ARRAY(Material, DetailNormalMap, MAX_STAGES);
DECLARE_IMAGEASSET_ARRAY(Material, DetailNormalMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DetailNormalMap);

/// The strength scalar for the detail normal map.
Expand Down
Loading

0 comments on commit 69fa4b3

Please sign in to comment.