Merge pull request #1343 from marauder2k9-torque/imageAsset_refactor_rev3

Image Asset Refactor - For 4.2
This commit is contained in:
Brian Roberts 2025-05-12 15:30:37 -05:00 committed by GitHub
commit 5aa67f680f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
133 changed files with 1717 additions and 2001 deletions

View file

@ -83,24 +83,17 @@ AccumulationVolume::AccumulationVolume()
mObjToWorld.identity();
mWorldToObj.identity();
// Accumulation Texture.
INIT_ASSET(Texture);
resetWorldBox();
}
AccumulationVolume::~AccumulationVolume()
{
mTexture = nullptr;
}
void AccumulationVolume::initPersistFields()
{
docsURL;
addProtectedField("textureAsset", TypeImageAssetId, Offset(mTextureAssetId, AccumulationVolume),
&_setTexture, &defaultProtectedGetFn, "Accumulation texture.");
addProtectedField( "texture", TypeStringFilename, Offset( mTextureName, AccumulationVolume ),
&_setTexture, &defaultProtectedGetFn, "Accumulation texture." );
INITPERSISTFIELD_IMAGEASSET(Texture, AccumulationVolume, "Accumulation texture.")
Parent::initPersistFields();
}
@ -236,7 +229,7 @@ U32 AccumulationVolume::packUpdate( NetConnection *connection, U32 mask, BitStre
if (stream->writeFlag(mask & InitialUpdateMask))
{
PACK_ASSET(connection, Texture);
PACK_ASSET_REFACTOR(connection, Texture);
}
return retMask;
@ -248,7 +241,7 @@ void AccumulationVolume::unpackUpdate( NetConnection *connection, BitStream *str
if (stream->readFlag())
{
UNPACK_ASSET(connection, Texture);
UNPACK_ASSET_REFACTOR(connection, Texture);
//setTexture(mTextureName);
}
}
@ -307,7 +300,7 @@ void AccumulationVolume::refreshVolumes()
if ( object.isNull() ) continue;
if ( volume->containsPoint(object->getPosition()) )
object->mAccuTex = volume->getTextureResource();
object->mAccuTex = volume->getTexture();
}
}
}
@ -341,6 +334,6 @@ void AccumulationVolume::updateObject(SceneObject* object)
if ( volume.isNull() ) continue;
if ( volume->containsPoint(object->getPosition()) )
object->mAccuTex = volume->getTextureResource();
object->mAccuTex = volume->getTexture();
}
}

View file

@ -61,10 +61,7 @@ class AccumulationVolume : public ScenePolyhedralSpace
// SceneSpace.
void _renderObject( ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat ) override;
DECLARE_IMAGEASSET(AccumulationVolume, Texture, onTextureChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_NET_SETGET(AccumulationVolume, Texture, -1);
void onTextureChanged() {}
DECLARE_IMAGEASSET_NET(AccumulationVolume, Texture, GFXStaticTextureSRGBProfile, -1)
public:

View file

@ -49,34 +49,65 @@
#include "T3D/assets/assetImporter.h"
#include "gfx/gfxDrawUtil.h"
#include "gfx/bitmap/ddsFile.h"
#ifdef __clang__
#define STBIWDEF static inline
#endif
#pragma warning( push )
#pragma warning( disable : 4505 ) // unreferenced function removed.
#ifndef STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_STATIC
#include "stb_image.h"
#endif
#pragma warning(pop)
//-----------------------------------------------------------------------------
StringTableEntry ImageAsset::smNoImageAssetFallback = NULL;
StringTableEntry ImageAsset::smNamedTargetAssetFallback = NULL;
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(ImageAsset);
ConsoleType(ImageAssetPtr, TypeImageAssetPtr, const char*, "")
//-----------------------------------------------------------------------------
// REFACTOR
//-----------------------------------------------------------------------------
IMPLEMENT_STRUCT(AssetPtr<ImageAsset>, AssetPtrImageAsset,, "")
END_IMPLEMENT_STRUCT
ConsoleType(ImageAssetPtr, TypeImageAssetPtr, AssetPtr<ImageAsset>, ASSET_ID_FIELD_PREFIX)
ConsoleGetType(TypeImageAssetPtr)
{
// Fetch asset Id.
return *((const char**)(dptr));
return (*((AssetPtr<ImageAsset>*)dptr)).getAssetId();
}
//-----------------------------------------------------------------------------
ConsoleSetType(TypeImageAssetPtr)
{
// Was a single argument specified?
if (argc == 1)
{
// Yes, so fetch field value.
*((const char**)dptr) = StringTable->insert(argv[0]);
const char* pFieldValue = argv[0];
// Fetch asset pointer.
AssetPtr<ImageAsset>* pAssetPtr = dynamic_cast<AssetPtr<ImageAsset>*>((AssetPtrBase*)(dptr));
// Is the asset pointer the correct type?
if (pAssetPtr == NULL)
{
Con::warnf("(TypeImageAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
return;
}
// Set asset.
pAssetPtr->setAssetId(pFieldValue);
return;
}
@ -85,27 +116,8 @@ ConsoleSetType(TypeImageAssetPtr)
Con::warnf("(TypeImageAssetPtr) - Cannot set multiple args to a single asset.");
}
ConsoleType(assetIdString, TypeImageAssetId, const char*, "")
ConsoleGetType(TypeImageAssetId)
{
// Fetch asset Id.
return *((const char**)(dptr));
}
ConsoleSetType(TypeImageAssetId)
{
// Was a single argument specified?
if (argc == 1)
{
*((const char**)dptr) = StringTable->insert(argv[0]);
return;
}
// Warn.
Con::warnf("(TypeImageAssetId) - Cannot set multiple args to a single asset.");
}
//-----------------------------------------------------------------------------
// REFACTOR END
//-----------------------------------------------------------------------------
ImplementEnumType(ImageAssetType,
@ -131,12 +143,20 @@ const String ImageAsset::mErrCodeStrings[] =
"UnKnown"
};
//-----------------------------------------------------------------------------
ImageAsset::ImageAsset() : AssetBase(), mIsValidImage(false), mUseMips(true), mIsHDRImage(false), mImageType(Albedo)
ImageAsset::ImageAsset() :
mImageFile(StringTable->EmptyString()),
mUseMips(true),
mIsHDRImage(false),
mImageType(Albedo),
mTextureHandle(NULL),
mIsNamedTarget(false),
mImageWidth(-1),
mImageHeight(-1),
mImageDepth(-1),
mImageChannels(-1)
{
mImageFileName = StringTable->EmptyString();
mImagePath = StringTable->EmptyString();
mLoadedState = AssetErrCode::NotLoaded;
mChangeSignal.notify(this, &ImageAsset::onAssetRefresh);
}
//-----------------------------------------------------------------------------
@ -153,7 +173,12 @@ void ImageAsset::consoleInit()
"The assetId of the texture to display when the requested image asset is missing.\n"
"@ingroup GFX\n");
Con::addVariable("$Core::NamedTargetFallback", TypeString, &smNamedTargetAssetFallback,
"The assetId of the texture to display when the requested image asset is named target.\n"
"@ingroup GFX\n");
smNoImageAssetFallback = StringTable->insert(Con::getVariable("$Core::NoImageAssetFallback"));
smNamedTargetAssetFallback = StringTable->insert(Con::getVariable("$Core::NamedTargetFallback"));
}
//-----------------------------------------------------------------------------
@ -164,17 +189,28 @@ void ImageAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addProtectedField("imageFile", TypeAssetLooseFilePath, Offset(mImageFileName, ImageAsset),
&setImageFileName, &getImageFileName, "Path to the image file.");
addProtectedField("imageFile", TypeAssetLooseFilePath, Offset(mImageFile, ImageAsset), &setImageFile, &getImageFile, &writeImageFile, "Path to the image file.");
addField("useMips", TypeBool, Offset(mUseMips, ImageAsset), "Should the image use mips? (Currently unused).");
addField("isHDRImage", TypeBool, Offset(mIsHDRImage, ImageAsset), "Is the image in an HDR format? (Currently unused)");
addProtectedField("useMips", TypeBool, Offset(mUseMips, ImageAsset), &setGenMips, &defaultProtectedGetFn, &writeGenMips, "Generate mip maps?");
addProtectedField("isHDRImage", TypeBool, Offset(mIsHDRImage, ImageAsset), &setTextureHDR, &defaultProtectedGetFn, &writeTextureHDR, "HDR Image?");
addField("imageType", TypeImageAssetType, Offset(mImageType, ImageAsset), "What the main use-case for the image is for.");
}
bool ImageAsset::onAdd()
{
// Call Parent.
if (!Parent::onAdd())
return false;
return true;
}
void ImageAsset::onRemove()
{
// Call Parent.
Parent::onRemove();
}
//------------------------------------------------------------------------------
//Utility function to 'fill out' bindings and resources with a matching asset if one exists
U32 ImageAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset)
{
AssetQuery query;
@ -227,7 +263,38 @@ StringTableEntry ImageAsset::getAssetIdByFilename(StringTableEntry fileName)
}
else
{
AssetPtr<ImageAsset> imageAsset = imageAssetId; //ensures the fallback is loaded
foundAssetcount = AssetDatabase.findAssetType(&query, "ImageAsset");
if (foundAssetcount != 0)
{
// loop all image assets and see if we can find one
// using the same image file/named target.
for (auto imgAsset : query.mAssetList)
{
AssetPtr<ImageAsset> temp = imgAsset;
if (temp.notNull())
{
if (temp->getImageFile() == fileName)
{
return imgAsset;
}
else
{
Torque::Path temp1 = temp->getImageFile();
Torque::Path temp2 = fileName;
if (temp1.getFileName() == temp2.getFileName())
{
return imgAsset;
}
}
}
}
}
else
{
AssetPtr<ImageAsset> imageAsset = imageAssetId; //ensures the fallback is loaded
}
}
return imageAssetId;
@ -262,168 +329,238 @@ U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* ima
}
}
void ImageAsset::initializeAsset(void)
{
// Call parent.
Parent::initializeAsset();
// Ensure the image-file is expanded.
if (isNamedTarget())
return;
mImageFile = expandAssetFilePath(mImageFile);
}
void ImageAsset::onAssetRefresh(void)
{
// Ignore if not yet added to the sim.
if (!isProperlyAdded())
return;
// Call parent.
Parent::onAssetRefresh();
}
//------------------------------------------------------------------------------
void ImageAsset::copyTo(SimObject* object)
{
// Call to parent.
Parent::copyTo(object);
ImageAsset* pAsset = static_cast<ImageAsset*>(object);
// Sanity!
AssertFatal(pAsset != NULL, "ImageAsset::copyTo() - Object is not the correct type.");
pAsset->setImageFile(getImageFile());
pAsset->setGenMips(getGenMips());
pAsset->setTextureHDR(getTextureHDR());
}
void ImageAsset::setImageFile(StringTableEntry pImageFile)
{
// Sanity!
AssertFatal(pImageFile != NULL, "Cannot use a NULL image file.");
pImageFile = StringTable->insert(pImageFile);
if (pImageFile == mImageFile)
return;
if (String(pImageFile).startsWith("#") || String(pImageFile).startsWith("$"))
{
mImageFile = StringTable->insert(pImageFile);
mIsNamedTarget = true;
refreshAsset();
return;
}
mImageFile = getOwned() ? expandAssetFilePath(pImageFile) : StringTable->insert(pImageFile);
if (Torque::FS::IsFile(mImageFile))
{
if (dStrEndsWith(mImageFile, ".dds"))
{
DDSFile* tempFile = new DDSFile();
FileStream* ddsFs;
if ((ddsFs = FileStream::createAndOpen(mImageFile, Torque::FS::File::Read)) == NULL)
{
Con::errorf("ImageAsset::setImageFile Failed to open ddsfile: %s", mImageFile);
}
if (!tempFile->readHeader(*ddsFs))
{
Con::errorf("ImageAsset::setImageFile Failed to read header of ddsfile: %s", mImageFile);
}
else
{
mImageWidth = tempFile->mWidth;
mImageHeight = tempFile->mHeight;
}
ddsFs->close();
delete tempFile;
}
else
{
if (!stbi_info(mImageFile, &mImageWidth, &mImageHeight, &mImageChannels))
{
StringTableEntry stbErr = stbi_failure_reason();
if (stbErr == StringTable->EmptyString())
stbErr = "ImageAsset::Unkown Error!";
Con::errorf("ImageAsset::setImageFile STB Get file info failed: %s", stbErr);
}
}
// we only support 2d textures..... for no ;)
mImageDepth = 1;
}
refreshAsset();
}
void ImageAsset::setGenMips(const bool pGenMips)
{
if (pGenMips == mUseMips)
return;
mUseMips = pGenMips;
refreshAsset();
}
void ImageAsset::setTextureHDR(const bool pIsHDR)
{
if (pIsHDR == mIsHDRImage)
return;
mIsHDRImage = pIsHDR;
refreshAsset();
}
U32 ImageAsset::load()
{
if (mLoadedState == AssetErrCode::Ok) return mLoadedState;
if (mImagePath)
if (mLoadedState == Ok)
return mLoadedState;
if (!Torque::FS::IsFile(mImageFile))
{
// this is a target.
if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
if (isNamedTarget())
{
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);
mLoadedState = BadFileReference;
mLoadedState = Ok;
return mLoadedState;
}
mLoadedState = Ok;
mIsValidImage = true;
Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFile);
mLoadedState = BadFileReference;
return mLoadedState;
}
mLoadedState = BadFileReference;
else
{
mLoadedState = Ok;
}
mIsValidImage = false;
return mLoadedState;
}
void ImageAsset::initializeAsset()
{
ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);
if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
{
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
}
else
{
mImagePath = mImageFileName;
}
}
void ImageAsset::onAssetRefresh()
{
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.
while (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end() && assetDependenciesItr->key == mpAssetDefinition->mAssetId)
{
StringTableEntry assetId = assetDependenciesItr->value;
AssetBase* dependent = AssetDatabase.acquireAsset<AssetBase>(assetId);
dependent->refreshAsset();
}
}
void ImageAsset::_onResourceChanged(const Torque::Path& path)
{
if (path != Torque::Path(mImagePath))
return;
refreshAsset();
}
void ImageAsset::setImageFileName(const char* pScriptFile)
{
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL image file.");
// Update.
mImageFileName = StringTable->insert(pScriptFile, true);
// Refresh the asset.
refreshAsset();
}
GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
{
load();
if (mResourceMap.contains(requestedProfile))
if (isNamedTarget())
{
mLoadedState = Ok;
return mResourceMap.find(requestedProfile)->value;
}
else
{
// this is a target.
if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
GFXTexHandle tex;
AssetPtr<ImageAsset> fallbackAsset;
ImageAsset::getAssetById(smNamedTargetAssetFallback, &fallbackAsset);
if (getNamedTarget().isValid())
{
mLoadedState = Ok;
NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1);
if (namedTarget.isValid() && namedTarget->getTexture())
tex = getNamedTarget()->getTexture();
if (tex.isNull())
{
mNamedTarget = namedTarget;
mIsValidImage = true;
mResourceMap.insert(requestedProfile, mNamedTarget->getTexture());
mChangeSignal.trigger();
return mNamedTarget->getTexture();
return fallbackAsset->getTexture();
}
return tex;
}
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)
{
mResourceMap.insert(requestedProfile, newTex);
mLoadedState = Ok;
return newTex;
}
else
mLoadedState = BadFileReference;
return fallbackAsset->getTexture();
}
}
if (mLoadedState == Ok)
{
if (mResourceMap.contains(requestedProfile))
{
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;
newTex.set(mImageFile, requestedProfile, avar("%s %s() - mTextureObject (line %d)", mImageFile, __FUNCTION__, __LINE__));
if (newTex)
{
mLoadedState = AssetErrCode::Ok;
mResourceMap.insert(requestedProfile, newTex);
return newTex;
}
}
}
mLoadedState = AssetErrCode::Failed;
return nullptr;
}
const char* ImageAsset::getImageInfo()
void ImageAsset::generateTexture(void)
{
if (mIsValidImage)
// already have a generated texture, get out.
if (mTextureHandle.isValid())
return;
// implement some defaults, eventually SRGB should be optional.
U32 flags = GFXTextureProfile::Static | GFXTextureProfile::SRGB;
// dont want mips?
if (!mUseMips)
{
static const U32 bufSize = 2048;
char* returnBuffer = Con::getReturnBuffer(bufSize);
GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, &GFXStaticTextureSRGBProfile);
if (newTex)
{
dSprintf(returnBuffer, bufSize, "%s %d %d %d", GFXStringTextureFormat[newTex->getFormat()], newTex->getHeight(), newTex->getWidth(), newTex->getDepth());
newTex = nullptr;
}
else
{
dSprintf(returnBuffer, bufSize, "ImageAsset::getImageInfo() - Failed to get image info for %s", getAssetId());
}
return returnBuffer;
flags |= GFXTextureProfile::NoMipmap;
}
return "";
GFXTextureProfile::Types type = GFXTextureProfile::Types::DiffuseMap;
if (mImageType == ImageTypes::Normal) {
type = GFXTextureProfile::Types::NormalMap;
}
GFXTextureProfile* genProfile = new GFXTextureProfile("ImageAssetGennedProfile", type, flags);
mTextureHandle.set(mImageFile, genProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
mResourceMap.insert(genProfile, mTextureHandle);
if (mTextureHandle.isValid())
mLoadedState = AssetErrCode::Ok;
else
mLoadedState = AssetErrCode::Failed;
ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);
}
const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
@ -452,7 +589,7 @@ const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
return _names[type];
}
ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(const char* name)
ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(StringTableEntry name)
{
if (dStrIsEmpty(name))
{
@ -475,11 +612,128 @@ ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(const char* name)
return (ImageTypes)ret;
}
void ImageAsset::_onResourceChanged(const Torque::Path& path)
{
if (path != Torque::Path(mImageFile))
return;
refreshAsset();
}
void ImageAsset::onTamlPreWrite(void)
{
// Call parent.
Parent::onTamlPreWrite();
if (isNamedTarget())
return;
// Ensure the image-file is collapsed.
mImageFile = collapseAssetFilePath(mImageFile);
}
void ImageAsset::onTamlPostWrite(void)
{
// Call parent.
Parent::onTamlPostWrite();
if (isNamedTarget())
return;
// Ensure the image-file is expanded.
mImageFile = expandAssetFilePath(mImageFile);
}
void ImageAsset::onTamlCustomWrite(TamlCustomNodes& customNodes)
{
// Debug Profiling.
PROFILE_SCOPE(ImageAsset_OnTamlCustomWrite);
// Call parent.
Parent::onTamlCustomWrite(customNodes);
TamlCustomNode* pImageMetaData = customNodes.addNode(StringTable->insert("ImageMetadata"));
TamlCustomNode* pImageInfoNode = pImageMetaData->addNode(StringTable->insert("ImageInfo"));
pImageInfoNode->addField(StringTable->insert("ImageWidth"), mImageWidth);
pImageInfoNode->addField(StringTable->insert("ImageHeight"), mImageHeight);
pImageInfoNode->addField(StringTable->insert("ImageDepth"), mImageDepth);
}
void ImageAsset::onTamlCustomRead(const TamlCustomNodes& customNodes)
{
// Debug Profiling.
PROFILE_SCOPE(ImageAsset_OnTamlCustomRead);
// Call parent.
Parent::onTamlCustomRead(customNodes);
const TamlCustomNode* pImageMetaDataNode = customNodes.findNode(StringTable->insert("ImageMetadata"));
if (pImageMetaDataNode != NULL)
{
const TamlCustomNode* pImageInfoNode = pImageMetaDataNode->findNode(StringTable->insert("ImageInfo"));
// Fetch fields.
const TamlCustomFieldVector& fields = pImageInfoNode->getFields();
// Iterate property fields.
for (TamlCustomFieldVector::const_iterator fieldItr = fields.begin(); fieldItr != fields.end(); ++fieldItr)
{
// Fetch field.
const TamlCustomField* pField = *fieldItr;
// Fetch field name.
StringTableEntry fieldName = pField->getFieldName();
if (fieldName == StringTable->insert("ImageWidth"))
{
pField->getFieldValue(mImageWidth);
}
else if (fieldName == StringTable->insert("ImageHeight"))
{
pField->getFieldValue(mImageHeight);
}
else if (fieldName == StringTable->insert("ImageDepth"))
{
pField->getFieldValue(mImageDepth);
}
else
{
// Unknown name so warn.
Con::warnf("ImageAsset::onTamlCustomRead() - Encountered an unknown custom field name of '%s'.", fieldName);
continue;
}
}
}
}
const char* ImageAsset::getImageInfo()
{
if (isAssetValid())
{
static const U32 bufSize = 2048;
char* returnBuffer = Con::getReturnBuffer(bufSize);
GFXTexHandle newTex = TEXMGR->createTexture(mImageFile, &GFXStaticTextureSRGBProfile);
if (newTex)
{
dSprintf(returnBuffer, bufSize, "%s %d %d %d", GFXStringTextureFormat[newTex->getFormat()], newTex->getHeight(), newTex->getWidth(), newTex->getDepth());
newTex = nullptr;
}
else
{
dSprintf(returnBuffer, bufSize, "ImageAsset::getImageInfo() - Failed to get image info for %s", getAssetId());
}
return returnBuffer;
}
return "";
}
DefineEngineMethod(ImageAsset, getImagePath, const char*, (), ,
"Gets the image filepath of this asset.\n"
"@return File path of the image file.")
{
return object->getImagePath();
return object->getImageFile();
}
DefineEngineMethod(ImageAsset, getImageInfo, const char*, (), ,
@ -489,6 +743,14 @@ DefineEngineMethod(ImageAsset, getImageInfo, const char*, (), ,
return object->getImageInfo();
}
DefineEngineMethod(ImageAsset, isNamedTarget, bool, (), ,
"Gets whether this image is a named target.\n"
"@return bool for isNamedTarget.")
{
return object->isNamedTarget();
}
#ifdef TORQUE_TOOLS
DefineEngineStaticMethod(ImageAsset, getAssetIdByFilename, const char*, (const char* filePath), (""),
"Queries the Asset Database to see if any asset exists that is associated with the provided file path.\n"
@ -496,7 +758,7 @@ DefineEngineStaticMethod(ImageAsset, getAssetIdByFilename, const char*, (const c
{
return ImageAsset::getAssetIdByFilename(StringTable->insert(filePath));
}
#endif
//-----------------------------------------------------------------------------
// GuiInspectorTypeAssetId
//-----------------------------------------------------------------------------
@ -652,7 +914,7 @@ bool GuiInspectorTypeImageAssetPtr::renderTooltip(const Point2I& hoverPos, const
if (imgAsset == NULL || assetState == ImageAsset::Failed)
return false;
StringTableEntry filename = imgAsset->getImagePath();
StringTableEntry filename = imgAsset->getImageFile();
if (!filename || !filename[0])
return false;
@ -665,7 +927,7 @@ bool GuiInspectorTypeImageAssetPtr::renderTooltip(const Point2I& hoverPos, const
if (AssetDatabase.isDeclaredAsset(previewFilename))
{
ImageAsset* previewAsset = AssetDatabase.acquireAsset<ImageAsset>(previewFilename);
previewFilename = previewAsset->getImagePath();
previewFilename = previewAsset->getImageFile();
}
}
@ -744,11 +1006,7 @@ void GuiInspectorTypeImageAssetPtr::updatePreviewImage()
{
if (AssetDatabase.isDeclaredAsset(previewImage))
{
ImageAsset* imgAsset = AssetDatabase.acquireAsset<ImageAsset>(previewImage);
if (imgAsset && imgAsset->isAssetValid())
{
mPreviewImage->_setBitmap(imgAsset->getAssetId());
}
mPreviewImage->_setBitmap(previewImage);
}
}
@ -776,31 +1034,10 @@ void GuiInspectorTypeImageAssetPtr::setPreviewImage(StringTableEntry assetId)
{
if (AssetDatabase.isDeclaredAsset(assetId))
{
ImageAsset* imgAsset = AssetDatabase.acquireAsset<ImageAsset>(assetId);
if (imgAsset && imgAsset->isAssetValid())
{
mPreviewImage->_setBitmap(imgAsset->getAssetId());
}
mPreviewImage->_setBitmap(assetId);
}
}
if (mPreviewImage->getBitmapAsset().isNull())
mPreviewImage->_setBitmap(StringTable->insert("ToolsModule:genericAssetIcon_image"));
}
IMPLEMENT_CONOBJECT(GuiInspectorTypeImageAssetId);
ConsoleDocClass(GuiInspectorTypeImageAssetId,
"@brief Inspector field type for Images\n\n"
"Editor use only.\n\n"
"@internal"
);
void GuiInspectorTypeImageAssetId::consoleInit()
{
Parent::consoleInit();
ConsoleBaseType::getType(TypeImageAssetId)->setInspectorFieldType("GuiInspectorTypeImageAssetId");
}
#endif

View file

@ -25,36 +25,36 @@
#ifndef _ASSET_BASE_H_
#include "assets/assetBase.h"
#endif
#ifndef _ASSET_DEFINITION_H_
#include "assets/assetDefinition.h"
#endif
#ifndef _STRINGUNIT_H_
#include "string/stringUnit.h"
#endif
#ifndef _ASSET_FIELD_TYPES_H_
#include "assets/assetFieldTypes.h"
#endif
#ifndef _ASSET_PTR_H_
#include "assets/assetPtr.h"
#endif
#ifndef _GBITMAP_H_
#include "gfx/bitmap/gBitmap.h"
#endif
#ifndef _GFXTEXTUREHANDLE_H_
#include "gfx/gfxTextureHandle.h"
#endif
#ifndef _NETCONNECTION_H_
#include "sim/netConnection.h"
#include <string>
#include "assetMacroHelpers.h"
#endif
#ifndef _GFXDEVICE_H_
#include "gfx/gfxDevice.h"
#endif
#ifndef _MATTEXTURETARGET_H_
#include "materials/matTextureTarget.h"
#endif
#include "assetMacroHelpers.h"
//-----------------------------------------------------------------------------
class ImageAsset : public AssetBase
{
@ -79,7 +79,41 @@ public:
ImageTypeCount = 11
};
class Frame
{
public:
Frame(const S32 pixelOffsetX, const S32 pixelOffsetY,
const U32 pixelWidth, const U32 pixelHeight,
const F32 texelWidthScale, const F32 texelHeightScale,
StringTableEntry inRegionName = StringTable->EmptyString())
: regionName(inRegionName)
{
pixelOffset.set(pixelOffsetY, pixelOffsetY);
pixelSize.set(pixelWidth, pixelHeight);
texelLower.set(pixelOffsetX * texelWidthScale, pixelOffsetY * texelHeightScale);
texelSize.set(pixelWidth * texelWidthScale, pixelHeight * texelHeightScale);
texelUpper.set(texelLower.x + texelSize.x, texelLower.y + texelSize.y);
}
void setFlip(bool flipX, bool flipY)
{
if (flipX) mSwap(texelLower.x, texelUpper.x);
if (flipY) mSwap(texelLower.y, texelUpper.y);
}
Point2I pixelOffset;
Point2I pixelSize;
Point2F texelLower;
Point2F texelUpper;
Point2F texelSize;
StringTableEntry regionName;
};
static StringTableEntry smNoImageAssetFallback;
static StringTableEntry smNamedTargetAssetFallback;
enum ImageAssetErrCode
{
@ -96,26 +130,21 @@ public:
if (errCode > ImageAssetErrCode::Extended) return "undefined error";
return mErrCodeStrings[errCode - Parent::Extended];
};
private:
protected:
StringTableEntry mImageFileName;
StringTableEntry mImagePath;
NamedTexTargetRef mNamedTarget;
bool mIsValidImage;
bool mUseMips;
bool mIsHDRImage;
ImageTypes mImageType;
StringTableEntry mImageFile;
bool mUseMips;
bool mIsHDRImage;
GFXTexHandle mTextureHandle;
ImageTypes mImageType;
HashMap<GFXTextureProfile*, GFXTexHandle> mResourceMap;
bool mIsNamedTarget;
S32 mImageWidth;
S32 mImageHeight;
S32 mImageDepth;
S32 mImageChannels;
typedef Signal<void()> ImageAssetChanged;
ImageAssetChanged mChangeSignal;
typedef Signal<void(S32 index)> ImageAssetArrayChanged;
ImageAssetArrayChanged mChangeArraySignal;
void generateTexture(void);
public:
ImageAsset();
virtual ~ImageAsset();
@ -125,6 +154,10 @@ public:
/// Engine.
static void initPersistFields();
/// Sim
bool onAdd() override;
void onRemove() override;
void copyTo(SimObject* object) override;
/// Declare Console Object.
@ -132,414 +165,288 @@ public:
void _onResourceChanged(const Torque::Path& path);
ImageAssetChanged& getChangedSignal() { return mChangeSignal; }
ImageAssetArrayChanged& getChangedArraySignal() { return mChangeArraySignal; }
// asset Base load
U32 load() override;
void setImageFileName(StringTableEntry pScriptFile);
inline StringTableEntry getImageFileName(void) const { return mImageFileName; };
void setImageFile(StringTableEntry pImageFile);
inline StringTableEntry getImageFile(void) const { return mImageFile; };
inline StringTableEntry getRelativeImageFile(void) const { return collapseAssetFilePath(mImageFile); };
inline StringTableEntry getImagePath(void) const { return mImagePath; };
void setGenMips(const bool pGenMips);
inline bool getGenMips(void) const { return mUseMips; };
bool isValid() { return mIsValidImage; }
void setTextureHDR(const bool pIsHDR);
inline bool getTextureHDR(void) const { return mIsHDRImage; };
GFXTexHandle getTexture(GFXTextureProfile* requestedProfile);
StringTableEntry getImageInfo();
inline GFXTexHandle& getTexture(void) { load(); generateTexture(); return mTextureHandle; }
GFXTexHandle getTexture(GFXTextureProfile* requestedProfile);
static StringTableEntry getImageTypeNameFromType(ImageTypes type);
static ImageTypes getImageTypeFromName(StringTableEntry name);
static ImageTypes getImageTypeFromName(StringTableEntry name);
void setImageType(ImageTypes type) { mImageType = type; }
ImageTypes getImageType() { return mImageType; }
void setImageType(ImageTypes type) { mImageType = type; }
ImageTypes getImageType() { return mImageType; }
inline U32 getTextureWidth(void) const { return isAssetValid() ? mTextureHandle->getWidth() : 0; }
inline U32 getTextureHeight(void) const { return isAssetValid() ? mTextureHandle->getHeight() : 0; }
inline U32 getTextureDepth(void) const { return isAssetValid() ? mTextureHandle->getDepth() : 0; }
inline U32 getTextureBitmapWidth(void) const { return mImageWidth; }
inline U32 getTextureBitmapHeight(void) const { return mImageHeight; }
inline U32 getTextureBitmapDepth(void) const { return mImageDepth; }
bool isAssetValid(void) const override { return !mTextureHandle.isNull(); }
bool isNamedTarget(void) const { return mIsNamedTarget; }
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);
static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
U32 load() override;
const char* getImageInfo();
protected:
void initializeAsset(void) override;
void onAssetRefresh(void) override;
// Asset Base callback
void initializeAsset(void) override;
void onAssetRefresh(void) override;
static bool setImageFileName(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setImageFileName(data); return false; }
static StringTableEntry getImageFileName(void* obj, StringTableEntry data) { return static_cast<ImageAsset*>(obj)->getImageFileName(); }
/// Taml callbacks.
void onTamlPreWrite(void) override;
void onTamlPostWrite(void) override;
void onTamlCustomWrite(TamlCustomNodes& customNodes) override;
void onTamlCustomRead(const TamlCustomNodes& customNodes) override;
protected:
// Texture file
static bool setImageFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setImageFile(data); return false; }
static const char* getImageFile(void* obj, StringTableEntry data) { return static_cast<ImageAsset*>(obj)->getImageFile(); }
static bool writeImageFile(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getImageFile() != StringTable->EmptyString(); }
// Gen mips?
static bool setGenMips(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setGenMips(dAtob(data)); return false; }
static bool writeGenMips(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getGenMips() == true; }
// Texture Is Hdr?
static bool setTextureHDR(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setTextureHDR(dAtob(data)); return false; }
static bool writeTextureHDR(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getTextureHDR() == true; }
};
DefineConsoleType(TypeImageAssetPtr, ImageAsset)
DefineConsoleType(TypeImageAssetId, String)
DECLARE_STRUCT(AssetPtr<ImageAsset>)
DefineConsoleType(TypeImageAssetPtr, AssetPtr<ImageAsset> )
typedef ImageAsset::ImageTypes ImageAssetType;
DefineEnumType(ImageAssetType);
#pragma region Singular Asset Macros
#pragma region Refactor Asset Macros
//Singular assets
/// <Summary>
/// Declares an image asset
/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
/// </Summary>
#define DECLARE_IMAGEASSET(className, name, changeFunc, profile) public: \
GFXTexHandle m##name = NULL;\
StringTableEntry m##name##Name; \
StringTableEntry m##name##AssetId;\
AssetPtr<ImageAsset> m##name##Asset;\
GFXTextureProfile* m##name##Profile = &profile;\
public: \
const StringTableEntry get##name##File() const { return m##name##Name; }\
void set##name##File(const FileName &_in) { m##name##Name = StringTable->insert(_in.c_str());}\
const AssetPtr<ImageAsset> & get##name##Asset() const { return m##name##Asset; }\
void set##name##Asset(const AssetPtr<ImageAsset> &_in) { m##name##Asset = _in;}\
\
bool _set##name(StringTableEntry _in)\
{\
if(m##name##AssetId != _in || m##name##Name != _in)\
{\
if (m##name##Asset.notNull())\
{\
m##name##Asset->getChangedSignal().remove(this, &className::changeFunc);\
}\
if (_in == NULL || _in == StringTable->EmptyString())\
{\
m##name##Name = StringTable->EmptyString();\
m##name##AssetId = StringTable->EmptyString();\
m##name##Asset = NULL;\
m##name.free();\
m##name = NULL;\
return true;\
}\
else if(_in[0] == '$' || _in[0] == '#')\
{\
m##name##Name = _in;\
m##name##AssetId = StringTable->EmptyString();\
m##name##Asset = NULL;\
m##name.free();\
m##name = NULL;\
return true;\
}\
\
if (AssetDatabase.isDeclaredAsset(_in))\
{\
m##name##AssetId = _in;\
\
U32 assetState = ImageAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
\
if (ImageAsset::Ok == assetState)\
{\
m##name##Name = StringTable->EmptyString();\
}\
}\
else\
{\
StringTableEntry assetId = ImageAsset::getAssetIdByFilename(_in);\
if (assetId != StringTable->EmptyString())\
{\
m##name##AssetId = assetId;\
if (ImageAsset::getAssetById(m##name##AssetId, &m##name##Asset) == ImageAsset::Ok)\
{\
m##name##Name = StringTable->EmptyString();\
}\
}\
else\
{\
m##name##Name = _in;\
m##name##AssetId = StringTable->EmptyString();\
m##name##Asset = NULL;\
}\
}\
}\
if (get##name() != StringTable->EmptyString() && m##name##Name != StringTable->insert("texhandle"))\
{\
if (m##name##Asset.notNull())\
{\
m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
}\
\
if (get##name()[0] != '$' && get##name()[0] != '#') {\
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
}\
}\
else\
{\
m##name.free();\
m##name = NULL;\
}\
\
if(get##name() == StringTable->EmptyString())\
return true;\
\
if (m##name##Asset.notNull() && m##name##Asset->getStatus() != ImageAsset::Ok)\
{\
Con::errorf("%s(%s)::_set%s() - image asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name), _in, ImageAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
return false; \
}\
else if (!m##name)\
{\
if (GFX->getAdapterType() != NullDevice)\
Con::errorf("%s(%s)::_set%s() - Couldn't load image \"%s\"", macroText(className), getName(), macroText(name), _in);\
return false;\
}\
return true;\
}\
\
const StringTableEntry get##name() const\
{\
if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\
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())\
return StringTable->insert(Platform::makeRelativePathName(m##name##Name, Platform::getMainDotCsDir()));\
else\
return StringTable->EmptyString();\
}\
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); }
#ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
#define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \
addProtectedField(#name, TypeImageFilename, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, docs)); \
addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
#else
#define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \
addProtectedField(#name, TypeImageFilename, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
#endif // SHOW_LEGACY_FILE_FIELDS
#define LOAD_IMAGEASSET(name)\
if (m##name##AssetId != StringTable->EmptyString())\
{\
S32 assetState = ImageAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
if (assetState == ImageAsset::Ok )\
{\
m##name##Name = StringTable->EmptyString();\
}\
else Con::warnf("Warning: %s::LOAD_IMAGEASSET(%s)-%s", mClassName, m##name##AssetId, ImageAsset::getAssetErrstrn(assetState).c_str());\
}
#define DECLARE_IMAGEASSET(className, name, profile) \
private: \
AssetPtr<ImageAsset> m##name##Asset; \
public: \
void _set##name(StringTableEntry _in){ \
if(m##name##Asset.getAssetId() == _in) \
return; \
\
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry imageAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
imageAssetId = ImageAsset::getAssetIdByFilename(_in); \
if (imageAssetId == ImageAsset::smNoImageAssetFallback) \
{ \
ImageAsset* privateImage = new ImageAsset(); \
privateImage->setImageFile(_in); \
imageAssetId = AssetDatabase.addPrivateAsset(privateImage); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
imageAssetId = ImageAsset::smNoImageAssetFallback; \
} \
m##name##Asset = imageAssetId; \
} \
else \
{ \
m##name##Asset = _in; \
} \
}; \
\
inline StringTableEntry _get##name(void) const { return m##name##Asset.getAssetId(); } \
GFXTexHandle get##name() { return m##name##Asset.notNull() ? m##name##Asset->getTexture(&profile) : NULL; } \
AssetPtr<ImageAsset> get##name##Asset(void) { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false;}
#pragma endregion
#define DECLARE_IMAGEASSET_NET(className, name, profile, mask) \
private: \
AssetPtr<ImageAsset> m##name##Asset; \
public: \
void _set##name(StringTableEntry _in){ \
if(m##name##Asset.getAssetId() == _in) \
return; \
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry imageAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
imageAssetId = ImageAsset::getAssetIdByFilename(_in); \
if (imageAssetId == ImageAsset::smNoImageAssetFallback) \
{ \
ImageAsset* privateImage = new ImageAsset(); \
privateImage->setImageFile(_in); \
imageAssetId = AssetDatabase.addPrivateAsset(privateImage); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
imageAssetId = ImageAsset::smNoImageAssetFallback; \
} \
m##name##Asset = imageAssetId; \
} \
else \
{ \
m##name##Asset = _in; \
} \
setMaskBits(mask); \
}; \
\
inline StringTableEntry _get##name(void) const { return m##name##Asset.getAssetId(); } \
GFXTexHandle get##name() { return m##name##Asset.notNull() ? m##name##Asset->getTexture(&profile) : NULL; } \
AssetPtr<ImageAsset> get##name##Asset(void) { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false;}
#pragma region Arrayed Asset Macros
//Arrayed Assets
#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]; \
StringTableEntry m##name##AssetId[max];\
AssetPtr<ImageAsset> m##name##Asset[max];\
GFXTextureProfile * m##name##Profile[max];\
public: \
const StringTableEntry get##name##File(const U32& index) const { return m##name##Name[index]; }\
void set##name##File(const FileName &_in, const U32& index) { m##name##Name[index] = StringTable->insert(_in.c_str());}\
const AssetPtr<ImageAsset> & get##name##Asset(const U32& index) const { return m##name##Asset[index]; }\
void set##name##Asset(const AssetPtr<ImageAsset> &_in, const U32& index) { m##name##Asset[index] = _in;}\
\
bool _set##name(StringTableEntry _in, const U32& index)\
{\
if(m##name##AssetId[index] != _in || m##name##Name[index] != _in)\
{\
if(index >= sm##name##Count || index < 0)\
return false;\
if (_in == NULL || _in == StringTable->EmptyString())\
{\
m##name##Name[index] = StringTable->EmptyString();\
m##name##AssetId[index] = StringTable->EmptyString();\
m##name##Asset[index] = NULL;\
m##name[index].free();\
m##name[index] = NULL;\
return true;\
}\
else if(_in[0] == '$' || _in[0] == '#')\
{\
m##name##Name[index] = _in;\
m##name##AssetId[index] = StringTable->EmptyString();\
m##name##Asset[index] = NULL;\
m##name[index].free();\
m##name[index] = NULL;\
return true;\
}\
\
if (AssetDatabase.isDeclaredAsset(_in))\
{\
m##name##AssetId[index] = _in;\
\
U32 assetState = ImageAsset::getAssetById(m##name##AssetId[index], &m##name##Asset[index]);\
\
if (ImageAsset::Ok == assetState)\
{\
m##name##Name[index] = StringTable->EmptyString();\
}\
}\
else\
{\
StringTableEntry assetId = ImageAsset::getAssetIdByFilename(_in);\
if (assetId != StringTable->EmptyString())\
{\
m##name##AssetId[index] = assetId;\
if (ImageAsset::getAssetById(m##name##AssetId[index], &m##name##Asset[index]) == ImageAsset::Ok)\
{\
m##name##Name[index] = StringTable->EmptyString();\
}\
}\
else\
{\
m##name##Name[index] = _in;\
m##name##AssetId[index] = StringTable->EmptyString();\
m##name##Asset[index] = NULL;\
}\
}\
}\
if (get##name(index) != StringTable->EmptyString() && m##name##Name[index] != StringTable->insert("texhandle"))\
{\
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\
{\
m##name[index].free();\
m##name[index] = NULL;\
}\
\
if(get##name(index) == StringTable->EmptyString())\
return true;\
\
if (m##name##Asset[index].notNull() && m##name##Asset[index]->getStatus() != ImageAsset::Ok)\
{\
Con::errorf("%s(%s)::_set%s(%i) - image asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name), index, _in, ImageAsset::getAssetErrstrn(m##name##Asset[index]->getStatus()).c_str());\
return false; \
}\
else if (!m##name[index])\
{\
if (GFX->getAdapterType() != NullDevice)\
Con::errorf("%s(%s)::_set%s(%i) - Couldn't load image \"%s\"", macroText(className), getName(), macroText(name), index, _in);\
return false; \
}\
return true;\
}\
\
const StringTableEntry get##name(const U32& index) const\
{\
if (m##name##Asset[index] && (m##name##Asset[index]->getImageFileName() != StringTable->EmptyString()))\
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())\
{\
if (String(m##name##Name[index]).startsWith("#") || String(m##name##Name[index]).startsWith("$"))\
return StringTable->insert(m##name##Name[index]);\
else\
return StringTable->insert(Platform::makeRelativePathName(m##name##Name[index], Platform::getMainDotCsDir()));\
}\
else\
return StringTable->EmptyString();\
}\
GFXTexHandle get##name##Resource(const U32& index) \
{\
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); }
#define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeImageAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
#define DECLARE_IMAGEASSET_ARRAY_SETGET(className, name)\
static bool _set##name##Data(void* obj, const char* index, const char* data)\
{\
if (!index) return false;\
U32 idx = dAtoi(index);\
if (idx >= sm##name##Count)\
return false;\
bool ret = false;\
className* object = static_cast<className*>(obj);\
ret = object->_set##name(StringTable->insert(data),idx);\
return ret;\
}
#define DECLARE_IMAGEASSET_ARRAY_NET_SETGET(className, name, bitmask)\
static bool _set##name##Data(void* obj, const char* index, const char* data)\
{\
if (!index) return false;\
U32 idx = dAtoi(index);\
if (idx >= sm##name##Count)\
return false;\
bool ret = false;\
className* object = static_cast<className*>(obj);\
ret = object->_set##name(StringTable->insert(data),idx);\
if(ret)\
object->setMaskBits(bitmask);\
return ret;\
}
#define DECLARE_IMAGEASSET_ARRAY(className, name, profile, max) \
private: \
AssetPtr<ImageAsset> m##name##Asset[max]; \
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(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
imageAssetId = ImageAsset::getAssetIdByFilename(_in); \
if (imageAssetId == ImageAsset::smNoImageAssetFallback) \
{ \
ImageAsset* privateImage = new ImageAsset(); \
privateImage->setImageFile(_in); \
imageAssetId = AssetDatabase.addPrivateAsset(privateImage); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
imageAssetId = ImageAsset::smNoImageAssetFallback; \
} \
m##name##Asset[index] = imageAssetId; \
} \
else \
{ \
m##name##Asset[index] = _in; \
} \
}; \
\
inline StringTableEntry _get##name(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
GFXTexHandle get##name(const U32& index) { return get##name(&profile, index); } \
GFXTexHandle get##name(GFXTextureProfile* requestedProfile, const U32& index) { return m##name##Asset[index].notNull() ? m##name##Asset[index]->getTexture(requestedProfile) : NULL; }\
AssetPtr<ImageAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}
#define INIT_IMAGEASSET_ARRAY(name, profile, index) \
{\
m##name##Name[index] = StringTable->EmptyString(); \
m##name##AssetId[index] = StringTable->EmptyString(); \
m##name##Asset[index] = NULL;\
m##name[index] = NULL;\
m##name##Profile[index] = &profile;\
}
#define DEF_IMAGEASSET_ARRAY_BINDS(className,name)\
#define DECLARE_IMAGEASSET_ARRAY_NET(className, name, profile, max, mask) \
private: \
AssetPtr<ImageAsset> m##name##Asset[max]; \
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(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
imageAssetId = ImageAsset::getAssetIdByFilename(_in); \
if (imageAssetId == ImageAsset::smNoImageAssetFallback) \
{ \
ImageAsset* privateImage = new ImageAsset(); \
privateImage->setImageFile(_in); \
imageAssetId = AssetDatabase.addPrivateAsset(privateImage); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
imageAssetId = ImageAsset::smNoImageAssetFallback; \
} \
m##name##Asset[index] = imageAssetId; \
} \
else \
{ \
m##name##Asset[index] = _in; \
} \
setMaskBits(mask); \
}; \
\
inline StringTableEntry _get##name(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
GFXTexHandle get##name(const U32& index) { return m##name##Asset[index].notNull() ? m##name##Asset[index]->getTexture(&profile) : NULL; } \
GFXTexHandle get##name(GFXTextureProfile* requestedProfile, const U32& index) { return m##name##Asset[index].notNull() ? m##name##Asset[index]->getTexture(requestedProfile) : NULL; }\
AssetPtr<ImageAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}
#define INITPERSISTFIELD_IMAGEASSET_ARRAY(name, arraySize, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeImageAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));
#define DEF_IMAGEASSET_ARRAY_BINDS(className,name, max)\
DefineEngineMethod(className, get##name, const char*, (S32 index), , "get name")\
{\
return object->get##name(index); \
return object->get##name##Asset(index).notNull() ? object->get##name##Asset(index)->getImageFile() : ""; \
}\
DefineEngineMethod(className, get##name##Asset, const char*, (S32 index), , assetText(name, asset reference))\
{\
if(index >= className::sm##name##Count || index < 0)\
if(index >= max || index < 0)\
return "";\
return object->m##name##AssetId[index]; \
return object->_get##name(index); \
}\
DefineEngineMethod(className, set##name, bool, (const char* map, S32 index), , assetText(name,assignment. first tries asset then flat file.))\
DefineEngineMethod(className, set##name, void, (const char* map, S32 index), , assetText(name,assignment. first tries asset then flat file.))\
{\
return object->_set##name(StringTable->insert(map), index);\
}
#ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
#define INITPERSISTFIELD_IMAGEASSET_ARRAY(name, arraySize, consoleClass, docs) \
addProtectedField(#name, TypeImageFilename, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, docs)); \
addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));
#else
#define INITPERSISTFIELD_IMAGEASSET_ARRAY(name, arraySize, consoleClass, docs) \
addProtectedField(#name, TypeImageFilename, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));
#endif
#define LOAD_IMAGEASSET_ARRAY(name, index)\
if (m##name##AssetId[index] != StringTable->EmptyString())\
{\
S32 assetState = ImageAsset::getAssetById(m##name##AssetId[index], &m##name##Asset[index]);\
if (assetState == ImageAsset::Ok )\
{\
m##name##Name[index] = StringTable->EmptyString();\
}\
else Con::warnf("Warning: %s::LOAD_IMAGEASSET(%s)-%s", mClassName, m##name##AssetId[index], ImageAsset::getAssetErrstrn(assetState).c_str());\
object->_set##name(StringTable->insert(map), index);\
}
#pragma endregion

View file

@ -229,7 +229,7 @@ StringTableEntry LevelAsset::getPreviewImagePath(void) const
{
if (mPreviewImageAsset.notNull() && mPreviewImageAsset->isAssetValid())
{
return mPreviewImageAsset->getImagePath();
return mPreviewImageAsset->getImageFile();
}
return StringTable->EmptyString();

View file

@ -211,39 +211,21 @@ void MaterialAsset::initializeAsset()
void MaterialAsset::onAssetRefresh()
{
mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath;
if (mMatDefinitionName == StringTable->EmptyString())
{
mLoadedState = Failed;
// Ignore if not yet added to the sim.
if (!isProperlyAdded())
return;
}
if (Con::isScriptFile(mScriptPath))
// Call parent.
Parent::onAssetRefresh();
if (mMaterialDefinition)
{
//Since we're refreshing, we can assume that the file we're executing WILL have an existing definition.
//But that definition, whatever it is, is the 'correct' one, so we enable the Replace Existing behavior
//when the engine encounters a named object conflict.
String redefineBehaviorPrev = Con::getVariable("$Con::redefineBehavior");
Con::setVariable("$Con::redefineBehavior", "replaceExisting");
if (Con::executeFile(mScriptPath, false, false))
mLoadedState = ScriptLoaded;
else
mLoadedState = Failed;
//And now that we've executed, switch back to the prior behavior
Con::setVariable("$Con::redefineBehavior", redefineBehaviorPrev.c_str());
mMaterialDefinition->flush();
mMaterialDefinition->reload();
}
load();
AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId);
// Iterate all dependencies.
while (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end() && assetDependenciesItr->key == mpAssetDefinition->mAssetId)
else
{
StringTableEntry assetId = assetDependenciesItr->value;
AssetBase* dependent = AssetDatabase.acquireAsset<AssetBase>(assetId);
dependent->refreshAsset();
load();
}
}
@ -644,7 +626,7 @@ void GuiInspectorTypeMaterialAssetPtr::updatePreviewImage()
MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(previewImage);
if (matAsset && matAsset->getMaterialDefinition())
{
mPreviewImage->_setBitmap(matAsset->getMaterialDefinition()->mDiffuseMapAssetId[0]);
mPreviewImage->_setBitmap(matAsset->getMaterialDefinition()->_getDiffuseMap(0));
}
}
}
@ -676,7 +658,7 @@ void GuiInspectorTypeMaterialAssetPtr::setPreviewImage(StringTableEntry assetId)
MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(assetId);
if (matAsset && matAsset->getMaterialDefinition())
{
mPreviewImage->_setBitmap(matAsset->getMaterialDefinition()->mDiffuseMapAssetId[0]);
mPreviewImage->_setBitmap(matAsset->getMaterialDefinition()->_getDiffuseMap(0));
}
}
}

View file

@ -1884,7 +1884,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
{
//got a match!
ImageAsset* foundImageAsset = AssetDatabase.acquireAsset<ImageAsset>(testAssetId.c_str());
imagePath = foundImageAsset->getImagePath();
imagePath = foundImageAsset->getImageFile();
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
@ -1928,7 +1928,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
{
//got a match!
ImageAsset* foundImageAsset = AssetDatabase.acquireAsset<ImageAsset>(testAssetId.c_str());
imagePath = foundImageAsset->getImagePath();
imagePath = foundImageAsset->getImageFile();
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
@ -2824,7 +2824,7 @@ Torque::Path AssetImporter::importImageAsset(AssetImportObject* assetItem)
StringTableEntry assetName = StringTable->insert(assetItem->assetName.c_str());
String imageFileName = assetItem->filePath.getFileName() + "." + assetItem->filePath.getExtension();
String imageFileName = assetItem->filePath.getFullPath();
String assetPath = targetPath + "/" + imageFileName;
String tamlPath = targetPath + "/" + assetName + ".asset.taml";
String originalPath = assetItem->filePath.getFullPath().c_str();
@ -2841,7 +2841,7 @@ Torque::Path AssetImporter::importImageAsset(AssetImportObject* assetItem)
#endif
newAsset->setAssetName(assetName);
newAsset->setImageFileName(imageFileName.c_str());
newAsset->setImageFile(imageFileName.c_str());
//If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original
//file path for reimporting support later
@ -2995,27 +2995,27 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
if (imageType == ImageAsset::ImageTypes::Albedo || childItem->imageSuffixType.isEmpty())
{
newMat->mDiffuseMapAssetId[0] = assetMapFillInStr;
newMat->_setDiffuseMap(assetMapFillInStr,0);
}
else if (imageType == ImageAsset::ImageTypes::Normal)
{
newMat->mNormalMapAssetId[0] = assetMapFillInStr;
newMat->_setNormalMap(assetMapFillInStr, 0);
}
else if (imageType == ImageAsset::ImageTypes::ORMConfig)
{
newMat->mORMConfigMapAssetId[0] = assetMapFillInStr;
newMat->_setORMConfigMap(assetMapFillInStr, 0);
}
else if (imageType == ImageAsset::ImageTypes::Metalness)
{
newMat->mMetalMapAssetId[0] = assetMapFillInStr;
newMat->_setMetalMap(assetMapFillInStr, 0);
}
else if (imageType == ImageAsset::ImageTypes::AO)
{
newMat->mAOMapAssetId[0] = assetMapFillInStr;
newMat->_setAOMap(assetMapFillInStr, 0);
}
else if (imageType == ImageAsset::ImageTypes::Roughness)
{
newMat->mRoughMapAssetId[0] = assetMapFillInStr;
newMat->_setRoughMap(assetMapFillInStr, 0);
hasRoughness = true;
}
}

View file

@ -53,6 +53,93 @@ if (m##name##AssetId != StringTable->EmptyString())\
m##name##Asset = other.m##name##Asset;\
m##name = other.m##name
// copy constructor refactor
#define CLONE_ASSET_REFACTOR(name) \
m##name##Asset = other.m##name##Asset;\
//network send - datablock refactor
#define PACKDATA_ASSET_REFACTOR(name)\
if (stream->writeFlag(m##name##Asset.notNull()))\
{\
stream->writeString(m##name##Asset.getAssetId());\
}
//network recieve - datablock
#define UNPACKDATA_ASSET_REFACTOR(name)\
if (stream->readFlag())\
{\
_set##name(stream->readSTString());\
}
//network send - object-instance
#define PACK_ASSET_REFACTOR(netconn, name)\
if (stream->writeFlag(m##name##Asset.notNull()))\
{\
NetStringHandle assetIdStr = m##name##Asset.getAssetId();\
netconn->packNetStringHandleU(stream, assetIdStr);\
}
//network recieve - object-instance
#define UNPACK_ASSET_REFACTOR(netconn, name)\
if (stream->readFlag())\
{\
_set##name(netconn->unpackNetStringHandleU(stream).getString());\
}
//network send - datablock
#define PACKDATA_ASSET_ARRAY_REFACTOR(name, max)\
for (U32 i = 0; i < max; i++)\
{\
if (stream->writeFlag(m##name##Asset[i].notNull()))\
{\
stream->writeString(m##name##Asset[i].getAssetId()); \
}\
}
//network recieve - datablock
#define UNPACKDATA_ASSET_ARRAY_REFACTOR(name, max)\
for (U32 i = 0; i < max; i++)\
{\
if (stream->readFlag())\
{\
m##name##Asset[i] = stream->readSTString();\
}\
}
//network send - object-instance
#define PACK_ASSET_ARRAY_REFACTOR(netconn, name, max)\
for (U32 i = 0; i < max; i++)\
{\
if (stream->writeFlag(m##name##Asset[i].notNull()))\
{\
NetStringHandle assetIdStr = m##name##Asset[i].getAssetId();\
netconn->packNetStringHandleU(stream, assetIdStr);\
}\
}
//network recieve - object-instance
#define UNPACK_ASSET_ARRAY_REFACTOR(netconn, name, max)\
for (U32 i = 0; i < max; i++)\
{\
if (stream->readFlag())\
{\
m##name##Asset[i] = StringTable->insert(netconn->unpackNetStringHandleU(stream).getString());\
}\
}
#define DEF_ASSET_BINDS_REFACTOR(className,name)\
DefineEngineMethod(className, get##name, StringTableEntry, (), , "get name")\
{\
return object->get##name##Asset()->getImageFile(); \
}\
DefineEngineMethod(className, get##name##Asset, StringTableEntry, (), , assetText(name, asset reference))\
{\
return object->_get##name(); \
}\
DefineEngineMethod(className, set##name, void, (const char* assetName), , assetText(name,assignment. first tries asset then flat file.))\
{\
object->_set##name(StringTable->insert(assetName));\
}
// addProtectedField acessors
#define DECLARE_ASSET_SETGET(className, name)\
static bool _set##name##Data(void* obj, const char* index, const char* data)\

View file

@ -972,10 +972,10 @@ void GroundCover::_initialize( U32 cellCount, U32 cellPlacementCount )
if(mat)
{
GFXTexHandle tex;
if (mat->getDiffuseMapResource(0))
tex = mat->getDiffuseMapResource(0);
else if (mat->getDiffuseMap(0) != StringTable->EmptyString())
tex = GFXTexHandle(mat->getDiffuseMap(0), &GFXStaticTextureSRGBProfile, "GroundCover texture aspect ratio check");
if (mat->getDiffuseMap(0))
tex = mat->getDiffuseMap(0);
else if (mat->getDiffuseMapAsset(0).notNull())
tex = mat->getDiffuseMap(0);
if(tex.isValid())
{

View file

@ -122,9 +122,6 @@ ParticleData::ParticleData()
animTexFramesString = NULL; // string of animation frame indices
animTexUVs = NULL; // array of tile vertex UVs
INIT_ASSET(Texture);
INIT_ASSET(TextureExt);
constrain_pos = false;
start_angle = 0.0f;
angle_variance = 0.0f;
@ -151,11 +148,6 @@ void ParticleData::initPersistFields()
{
docsURL;
addGroup("Basic");
addProtectedField("textureName", TYPEID< StringTableEntry >(), Offset(mTextureName, ParticleData), _setTextureData, defaultProtectedGetFn,
"Texture file to use for this particle.", AbstractClassRep::FIELD_HideInInspectors);
addField("animTexName", TYPEID< StringTableEntry >(), Offset(mTextureName, ParticleData),
"@brief Texture file to use for this particle if animateTexture is true.\n\n"
"Deprecated. Use textureName instead.", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET(Texture, ParticleData, "Texture to use for this particle.");
addField("useInvAlpha", TYPEID< bool >(), Offset(useInvAlpha, ParticleData),
"@brief Controls how particles blend with the scene.\n\n"
@ -241,7 +233,6 @@ void ParticleData::initPersistFields()
endGroup("Over Time");
addGroup("AFX");
addProtectedField("textureExtName", TypeFilename, Offset(mTextureExtName, ParticleData), _setTextureExtData, &defaultProtectedGetFn, "", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET(TextureExt, ParticleData, "");
addField("constrainPos", TypeBool, Offset(constrain_pos, ParticleData));
addFieldV("angle", TypeRangedF32, Offset(start_angle, ParticleData), &CommonValidators::DegreeRange);
@ -307,7 +298,7 @@ void ParticleData::packData(BitStream* stream)
stream->writeFloat( times[i], 8);
}
PACKDATA_ASSET(Texture);
PACKDATA_ASSET_REFACTOR(Texture);
for (i = 0; i < 4; i++)
mathWrite(*stream, texCoords[i]);
@ -321,7 +312,7 @@ void ParticleData::packData(BitStream* stream)
stream->writeInt(framesPerSec, 8);
}
PACKDATA_ASSET(TextureExt);
PACKDATA_ASSET_REFACTOR(TextureExt);
stream->writeFlag(constrain_pos);
stream->writeFloat(start_angle/360.0f, 11);
@ -392,7 +383,7 @@ void ParticleData::unpackData(BitStream* stream)
times[i] = stream->readFloat(8);
}
UNPACKDATA_ASSET(Texture);
UNPACKDATA_ASSET_REFACTOR(Texture);
for (i = 0; i < 4; i++)
mathRead(*stream, &texCoords[i]);
@ -405,7 +396,7 @@ void ParticleData::unpackData(BitStream* stream)
framesPerSec = stream->readInt(8);
}
UNPACKDATA_ASSET(TextureExt);
UNPACKDATA_ASSET_REFACTOR(TextureExt);
constrain_pos = stream->readFlag();
start_angle = 360.0f*stream->readFloat(11);
@ -711,13 +702,6 @@ bool ParticleData::reload(char errorBuffer[256])
{
bool error = false;
StringTableEntry particleTex = getTexture();
if (!_setTexture(particleTex))
{
dSprintf(errorBuffer, 256, "Missing particle texture: %s", particleTex);
}
/*
numFrames = 0;
for( S32 i=0; i<PDC_MAX_TEX; i++ )
@ -788,12 +772,12 @@ ParticleData::ParticleData(const ParticleData& other, bool temp_clone) : SimData
animTexFramesString = other.animTexFramesString;
animTexFrames = other.animTexFrames; // -- parsed from animTexFramesString
CLONE_ASSET(Texture);
CLONE_ASSET_REFACTOR(Texture);
spinBias = other.spinBias;
randomizeSpinDir = other.randomizeSpinDir;
CLONE_ASSET(TextureExt);
CLONE_ASSET_REFACTOR(TextureExt);
constrain_pos = other.constrain_pos;
start_angle = other.start_angle;
@ -829,4 +813,4 @@ void ParticleData::onPerformSubstitutions()
reload(errorBuffer);
}
DEF_ASSET_BINDS(ParticleData, Texture);
DEF_ASSET_BINDS_REFACTOR(ParticleData, Texture);

View file

@ -86,17 +86,11 @@ class ParticleData : public SimDataBlock
StringTableEntry animTexFramesString;
Vector<U8> animTexFrames;
DECLARE_IMAGEASSET(ParticleData, Texture, onImageChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(ParticleData, Texture);
DECLARE_IMAGEASSET(ParticleData, Texture, GFXStaticTextureSRGBProfile)
static bool protectedSetSizes(void* object, const char* index, const char* data);
static bool protectedSetTimes(void* object, const char* index, const char* data);
void onImageChanged()
{
reloadOnLocalClient();
}
public:
ParticleData();
~ParticleData();
@ -120,8 +114,7 @@ public:
F32 spinBias;
bool randomizeSpinDir;
public:
DECLARE_IMAGEASSET(ParticleData, TextureExt, onImageChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(ParticleData, TextureExt);
DECLARE_IMAGEASSET(ParticleData, TextureExt,GFXStaticTextureSRGBProfile)
bool constrain_pos;
F32 start_angle;

View file

@ -740,16 +740,19 @@ bool ParticleEmitterData::preload(bool server, String &errorStr)
// otherwise, check that all particles refer to the same texture
else if (particleDataBlocks.size() > 1)
{
StringTableEntry txr_name = particleDataBlocks[0]->getTexture();
for (S32 i = 1; i < particleDataBlocks.size(); i++)
{
// warn if particle textures are inconsistent
if (particleDataBlocks[i]->getTexture() != txr_name)
{
Con::warnf(ConsoleLogEntry::General, "ParticleEmitterData(%s) particles reference different textures.", getName());
break;
}
}
if (particleDataBlocks[0]->getTextureAsset().notNull())
{
StringTableEntry txr_name = particleDataBlocks[0]->getTextureAsset()->getImageFile();
for (S32 i = 1; i < particleDataBlocks.size(); i++)
{
// warn if particle textures are inconsistent
if (particleDataBlocks[i]->getTextureAsset()->getImageFile() != txr_name)
{
Con::warnf(ConsoleLogEntry::General, "ParticleEmitterData(%s) particles reference different textures.", getName());
break;
}
}
}
}
}
@ -1225,7 +1228,7 @@ void ParticleEmitter::prepRenderImage(SceneRenderState* state)
if (mDataBlock->textureHandle)
ri->diffuseTex = &*(mDataBlock->textureHandle);
else
ri->diffuseTex = &*(part_list_head.next->dataBlock->getTextureResource());
ri->diffuseTex = &*(part_list_head.next->dataBlock->getTexture());
ri->softnessDistance = mDataBlock->softnessDistance;

View file

@ -129,12 +129,8 @@ PrecipitationData::PrecipitationData()
{
INIT_ASSET(Sound);
INIT_ASSET(Drop);
mDropShaderName = StringTable->EmptyString();
INIT_ASSET(Splash);
mSplashShaderName = StringTable->EmptyString();
mDropsPerSide = 4;
@ -145,12 +141,6 @@ void PrecipitationData::initPersistFields()
{
docsURL;
INITPERSISTFIELD_SOUNDASSET(Sound, PrecipitationData, "Looping SFXProfile effect to play while Precipitation is active.");
addProtectedField( "dropTexture", TypeFilename, Offset(mDropName, PrecipitationData), &_setDropData, &defaultProtectedGetFn,
"@brief Texture filename for drop particles.\n\n"
"The drop texture can contain several different drop sub-textures "
"arranged in a grid. There must be the same number of rows as columns. A "
"random frame will be chosen for each drop.", AbstractClassRep::FIELD_HideInInspectors );
INITPERSISTFIELD_IMAGEASSET(Drop, PrecipitationData, "@brief Texture for drop particles.\n\n"
"The drop texture can contain several different drop sub-textures "
@ -160,12 +150,6 @@ void PrecipitationData::initPersistFields()
addField( "dropShader", TypeString, Offset(mDropShaderName, PrecipitationData),
"The name of the shader used for raindrops." );
addProtectedField("splashTexture", TypeFilename, Offset(mSplashName, PrecipitationData), &_setSplashData, &defaultProtectedGetFn,
"@brief Texture filename for splash particles.\n\n"
"The splash texture can contain several different splash sub-textures "
"arranged in a grid. There must be the same number of rows as columns. A "
"random frame will be chosen for each splash.", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET(Splash, PrecipitationData, "@brief Texture for splash particles.\n\n"
"The splash texture can contain several different splash sub-textures "
"arranged in a grid. There must be the same number of rows as columns. A "
@ -206,11 +190,11 @@ void PrecipitationData::packData(BitStream* stream)
PACKDATA_ASSET(Sound);
PACKDATA_ASSET(Drop);
PACKDATA_ASSET_REFACTOR(Drop);
stream->writeString(mDropShaderName);
PACKDATA_ASSET(Splash);
PACKDATA_ASSET_REFACTOR(Splash);
stream->writeString(mSplashShaderName);
stream->write(mDropsPerSide);
@ -223,11 +207,11 @@ void PrecipitationData::unpackData(BitStream* stream)
UNPACKDATA_ASSET(Sound);
UNPACKDATA_ASSET(Drop);
UNPACKDATA_ASSET_REFACTOR(Drop);
mDropShaderName = stream->readSTString();
UNPACKDATA_ASSET(Splash);
UNPACKDATA_ASSET_REFACTOR(Splash);
mSplashShaderName = stream->readSTString();
stream->read(&mDropsPerSide);
@ -632,10 +616,10 @@ void Precipitation::initMaterials()
mDropShader = NULL;
mSplashShader = NULL;
if(pd->mDrop.isNull())
Con::warnf("Precipitation::initMaterials - failed to locate texture '%s'!", pd->getDrop());
if(pd->getDropAsset().isNull())
Con::warnf("Precipitation::initMaterials - failed to locate texture '%s'!", pd->getDropAsset().getAssetId());
else
mDropHandle = pd->mDrop;
mDropHandle = pd->getDrop();
if ( dStrlen(pd->mDropShaderName) > 0 )
{
@ -655,10 +639,10 @@ void Precipitation::initMaterials()
}
}
if (pd->mSplash.isNull())
Con::warnf("Precipitation::initMaterials - failed to locate texture '%s'!", pd->getSplash());
if (pd->getSplashAsset().isNull())
Con::warnf("Precipitation::initMaterials - failed to locate texture '%s'!", pd->getSplashAsset().getAssetId());
else
mSplashHandle = pd->mSplash;
mSplashHandle = pd->getSplash();
if ( dStrlen(pd->mSplashShaderName) > 0 )
{

View file

@ -49,13 +49,11 @@ class PrecipitationData : public GameBaseData
DECLARE_SOUNDASSET(PrecipitationData, Sound);
DECLARE_ASSET_SETGET(PrecipitationData, Sound);
DECLARE_IMAGEASSET(PrecipitationData, Drop, onDropChanged, GFXStaticTextureSRGBProfile); ///< Texture for drop particles
DECLARE_ASSET_SETGET(PrecipitationData, Drop);
DECLARE_IMAGEASSET(PrecipitationData, Drop, GFXStaticTextureSRGBProfile) ///< Texture for drop particles
StringTableEntry mDropShaderName; ///< The name of the shader used for raindrops
DECLARE_IMAGEASSET(PrecipitationData, Splash, onSplashChanged, GFXStaticTextureSRGBProfile); ///< Texture for splash particles
DECLARE_ASSET_SETGET(PrecipitationData, Splash);
DECLARE_IMAGEASSET(PrecipitationData, Splash, GFXStaticTextureSRGBProfile) ///< Texture for splash particles
StringTableEntry mSplashShaderName; ///< The name of the shader used for raindrops
@ -68,15 +66,6 @@ class PrecipitationData : public GameBaseData
static void initPersistFields();
void packData(BitStream* stream) override;
void unpackData(BitStream* stream) override;
void onDropChanged()
{
reloadOnLocalClient();
}
void onSplashChanged()
{
reloadOnLocalClient();
}
};
struct Raindrop

View file

@ -96,11 +96,6 @@ SplashData::SplashData()
explosionId = 0;
U32 i;
for (i = 0; i < NUM_TEX; i++)
{
INIT_IMAGEASSET_ARRAY(Texture, GFXStaticTextureSRGBProfile, i);
}
for( i=0; i<NUM_TIME_KEYS; i++ )
times[i] = 1.0;
@ -188,6 +183,8 @@ void SplashData::packData(BitStream* stream)
stream->writeRangedU32(explosion->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast);
}
PACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX);
S32 i;
for( i=0; i<NUM_EMITTERS; i++ )
{
@ -206,11 +203,6 @@ void SplashData::packData(BitStream* stream)
{
stream->write( times[i] );
}
for( i=0; i<NUM_TEX; i++ )
{
PACKDATA_ASSET_ARRAY(Texture, i);
}
}
//--------------------------------------------------------------------------
@ -244,6 +236,8 @@ void SplashData::unpackData(BitStream* stream)
explosionId = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast );
}
UNPACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX);
U32 i;
for( i=0; i<NUM_EMITTERS; i++ )
{
@ -262,11 +256,6 @@ void SplashData::unpackData(BitStream* stream)
{
stream->read( &times[i] );
}
for( i=0; i<NUM_TEX; i++ )
{
UNPACKDATA_ASSET_ARRAY(Texture, i);
}
}
//--------------------------------------------------------------------------
@ -299,9 +288,9 @@ bool SplashData::preload(bool server, String &errorStr)
for( i=0; i<NUM_TEX; i++ )
{
if (mTexture[i].isNull())
if (mTextureAsset[i].isNull())
{
_setTexture(getTexture(i), i);
_setTexture(_getTexture(i), i);
}
}
}

View file

@ -122,12 +122,7 @@ public:
F32 times[ NUM_TIME_KEYS ];
LinearColorF colors[ NUM_TIME_KEYS ];
DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, NUM_TEX, onTextureChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(SplashData, Texture)
void onTextureChanged()
{
reloadOnLocalClient();
}
DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, GFXStaticTextureSRGBProfile, NUM_TEX)
ExplosionData* explosion;
S32 explosionId;

View file

@ -53,7 +53,6 @@ GameMode::GameMode() :
mIsActive(false),
mIsAlwaysActive(false)
{
INIT_ASSET(PreviewImage);
}
void GameMode::initPersistFields()

View file

@ -21,8 +21,7 @@ private:
StringTableEntry mGameModeName;
StringTableEntry mGameModeDesc;
DECLARE_IMAGEASSET(GameMode, PreviewImage, previewChange, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(GameMode, PreviewImage);
DECLARE_IMAGEASSET(GameMode, PreviewImage, GFXStaticTextureSRGBProfile)
bool mIsActive;
bool mIsAlwaysActive;
@ -45,8 +44,6 @@ public:
static void findGameModes(const char* gameModeList, Vector<GameMode*>* outGameModes);
void previewChange() {}
DECLARE_CALLBACK(void, onActivated, ());
DECLARE_CALLBACK(void, onDeactivated, ());
DECLARE_CALLBACK(void, onSceneLoaded, ());

View file

@ -102,8 +102,6 @@ LevelInfo::LevelInfo()
mAdvancedLightmapSupport = true;
INIT_ASSET(AccuTexture);
// Register with the light manager activation signal, and we need to do it first
// so the advanced light bin manager can be instructed about MRT lightmaps
LightManager::smActivateSignal.notify(this, &LevelInfo::_onLMActivate, 0.01f);
@ -114,9 +112,8 @@ LevelInfo::LevelInfo()
LevelInfo::~LevelInfo()
{
LightManager::smActivateSignal.remove(this, &LevelInfo::_onLMActivate);
if (!mAccuTexture.isNull())
if (!mAccuTextureAsset.isNull())
{
mAccuTexture.free();
gLevelAccuMap.free();
}
}
@ -222,7 +219,7 @@ U32 LevelInfo::packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
sfxWrite( stream, mSoundAmbience );
stream->writeInt( mSoundDistanceModel, 1 );
PACK_ASSET(conn, AccuTexture);
PACK_ASSET_REFACTOR(conn, AccuTexture);
return retMask;
}
@ -271,8 +268,8 @@ void LevelInfo::unpackUpdate(NetConnection *conn, BitStream *stream)
SFX->setDistanceModel( mSoundDistanceModel );
}
UNPACK_ASSET(conn, AccuTexture);
setLevelAccuTexture(getAccuTexture());
UNPACK_ASSET_REFACTOR(conn, AccuTexture);
setLevelAccuTexture();
}
//-----------------------------------------------------------------------------
@ -368,24 +365,12 @@ void LevelInfo::_onLMActivate(const char *lm, bool enable)
#endif
}
bool LevelInfo::_setLevelAccuTexture(void *object, const char *index, const char *data)
void LevelInfo::setLevelAccuTexture()
{
LevelInfo* volume = reinterpret_cast< LevelInfo* >(object);
volume->setLevelAccuTexture(StringTable->insert(data));
return false;
}
void LevelInfo::setLevelAccuTexture(StringTableEntry name)
{
_setAccuTexture(name);
if (isClientObject() && getAccuTexture() != StringTable->EmptyString())
if (isClientObject() && mAccuTextureAsset.notNull())
{
if (mAccuTexture.isNull())
Con::warnf("AccumulationVolume::setTexture - Unable to load texture: %s", getAccuTexture());
else
gLevelAccuMap = mAccuTexture;
gLevelAccuMap = getAccuTexture();
}
AccumulationVolume::refreshVolumes();
}

View file

@ -106,10 +106,7 @@ class LevelInfo : public NetObject
void _onLMActivate(const char *lm, bool enable);
protected:
DECLARE_IMAGEASSET(LevelInfo, AccuTexture, onAccuTextureChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(LevelInfo, AccuTexture);
void onAccuTextureChanged() {}
DECLARE_IMAGEASSET(LevelInfo, AccuTexture, GFXStaticTextureSRGBProfile)
public:
@ -146,8 +143,7 @@ class LevelInfo : public NetObject
U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ) override;
void unpackUpdate( NetConnection *conn, BitStream *stream ) override;
static bool _setLevelAccuTexture(void *object, const char *index, const char *data);
void setLevelAccuTexture(StringTableEntry name);
void setLevelAccuTexture();
/// @}
};

View file

@ -132,8 +132,6 @@ LightFlareData::LightFlareData()
for ( U32 i = 0; i < MAX_ELEMENTS; i++ )
mElementDist[i] = -1.0f;
INIT_ASSET(FlareTexture);
}
LightFlareData::~LightFlareData()
@ -220,7 +218,7 @@ void LightFlareData::packData( BitStream *stream )
stream->writeFlag( mFlareEnabled );
PACKDATA_ASSET(FlareTexture);
PACKDATA_ASSET_REFACTOR(FlareTexture);
stream->write( mScale );
stream->write( mOcclusionRadius );
@ -245,7 +243,7 @@ void LightFlareData::unpackData( BitStream *stream )
mFlareEnabled = stream->readFlag();
UNPACKDATA_ASSET(FlareTexture);
UNPACKDATA_ASSET_REFACTOR(FlareTexture);
stream->read( &mScale );
stream->read( &mOcclusionRadius );
@ -540,7 +538,7 @@ void LightFlareData::prepRender(SceneRenderState *state, LightFlareState *flareS
GFXVertexPCT *vert = flareState->vertBuffer.lock();
const Point2F oneOverTexSize( 1.0f / (F32)mFlareTexture.getWidth(), 1.0f / (F32)mFlareTexture.getHeight() );
const Point2F oneOverTexSize( 1.0f / (F32)getFlareTexture().getWidth(), 1.0f / (F32)getFlareTexture().getHeight());
for ( U32 i = 0; i < mElementCount; i++ )
{
@ -614,7 +612,7 @@ void LightFlareData::prepRender(SceneRenderState *state, LightFlareState *flareS
ri->bbModelViewProj = &MatrixF::Identity;
ri->count = elementCount;
ri->blendStyle = ParticleRenderInst::BlendGreyscale;
ri->diffuseTex = mFlareTexture;
ri->diffuseTex = getFlareTexture();
ri->softnessDistance = 1.0f;
ri->defaultKey = ri->diffuseTex ? (uintptr_t)ri->diffuseTex : (uintptr_t)ri->vertBuff; // Sort by texture too.

View file

@ -106,11 +106,6 @@ protected:
void _makePrimBuffer( GFXPrimitiveBufferHandle *pb, U32 count );
void _renderCorona( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
void onImageChanged()
{
reloadOnLocalClient();
}
protected:
static const U32 LosMask;
@ -123,8 +118,7 @@ protected:
F32 mScale;
bool mFlareEnabled;
DECLARE_IMAGEASSET(LightFlareData, FlareTexture, onImageChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(LightFlareData, FlareTexture);
DECLARE_IMAGEASSET(LightFlareData, FlareTexture, GFXStaticTextureSRGBProfile)
F32 mOcclusionRadius;
bool mRenderReflectPass;

View file

@ -605,7 +605,7 @@ void ReflectionProbe::processBakedCubemap()
if (mIrridianceMap == nullptr || mIrridianceMap->mCubemap.isNull())
{
Con::errorf("ReflectionProbe::processDynamicCubemap() - Unable to load baked irradiance map at %s", getIrradianceMapPath().c_str());
Con::errorf("ReflectionProbe::processBakedCubemap() - Unable to load baked irradiance map at %s", getIrradianceMapPath().c_str());
return;
}
@ -618,7 +618,7 @@ void ReflectionProbe::processBakedCubemap()
if (mPrefilterMap == nullptr || mPrefilterMap->mCubemap.isNull())
{
Con::errorf("ReflectionProbe::processDynamicCubemap() - Unable to load baked prefilter map at %s", getPrefilterMapPath().c_str());
Con::errorf("ReflectionProbe::processBakedCubemap() - Unable to load baked prefilter map at %s", getPrefilterMapPath().c_str());
return;
}

View file

@ -264,7 +264,7 @@ void afxZodiacGroundPlaneRenderer::render(SceneRenderState* state)
GFX->setShaderConstBuffer(shader_consts);
// set the texture
GFX->setTexture(0, *zode->txr);
GFX->setTexture(0, zode->txr);
LinearColorF zode_color = (LinearColorF)zode->color;
zode_color.alpha *= fadebias;
shader_consts->set(color_sc, zode_color);

View file

@ -266,7 +266,7 @@ void afxZodiacMeshRoadRenderer::render(SceneRenderState* state)
GFX->setShaderConstBuffer(shader_consts);
// set the texture
GFX->setTexture(0, *zode->txr);
GFX->setTexture(0, zode->txr);
LinearColorF zode_color = (LinearColorF)zode->color;
zode_color.alpha *= fadebias;
shader_consts->set(color_sc, zode_color);

View file

@ -266,7 +266,7 @@ void afxZodiacPolysoupRenderer::render(SceneRenderState* state)
GFX->setShaderConstBuffer(shader_consts);
// set the texture
GFX->setTexture(0, *zode->txr);
GFX->setTexture(0, zode->txr);
LinearColorF zode_color = (LinearColorF)zode->color;
zode_color.alpha *= fadebias;
shader_consts->set(color_sc, zode_color);

View file

@ -279,7 +279,7 @@ void afxZodiacTerrainRenderer::render(SceneRenderState* state)
GFX->setShaderConstBuffer(shader_consts);
// set the texture
GFX->setTexture(0, *zode->txr);
GFX->setTexture(0, zode->txr);
LinearColorF zode_color = (LinearColorF)zode->color;
zode_color.alpha *= fadebias;
shader_consts->set(color_sc, zode_color);

View file

@ -51,7 +51,6 @@ ConsoleDocClass( afxBillboardData,
afxBillboardData::afxBillboardData()
{
color.set(1.0f, 1.0f, 1.0f, 1.0f);
INIT_ASSET(Texture);
dimensions.set(1.0f, 1.0f);
texCoords[0].set(0.0f, 0.0f);
texCoords[1].set(0.0f, 1.0f);
@ -66,7 +65,7 @@ afxBillboardData::afxBillboardData(const afxBillboardData& other, bool temp_clon
: GameBaseData(other, temp_clone)
{
color = other.color;
CLONE_ASSET(Texture);
CLONE_ASSET_REFACTOR(Texture);
dimensions = other.dimensions;
texCoords[0] = other.texCoords[0];
texCoords[1] = other.texCoords[1];
@ -124,7 +123,7 @@ void afxBillboardData::packData(BitStream* stream)
Parent::packData(stream);
stream->write(color);
PACKDATA_ASSET(Texture);
PACKDATA_ASSET_REFACTOR(Texture);
mathWrite(*stream, dimensions);
mathWrite(*stream, texCoords[0]);
@ -141,7 +140,7 @@ void afxBillboardData::unpackData(BitStream* stream)
Parent::unpackData(stream);
stream->read(&color);
UNPACKDATA_ASSET(Texture);
UNPACKDATA_ASSET_REFACTOR(Texture);
mathRead(*stream, &dimensions);
mathRead(*stream, &texCoords[0]);
mathRead(*stream, &texCoords[1]);

View file

@ -47,8 +47,7 @@ public:
};
public:
DECLARE_IMAGEASSET(afxBillboardData, Texture, onChangeTexture, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(afxBillboardData, Texture);
DECLARE_IMAGEASSET(afxBillboardData, Texture, GFXStaticTextureSRGBProfile)
LinearColorF color;
@ -71,11 +70,6 @@ public:
static void initPersistFields();
void onChangeTexture()
{
reloadOnLocalClient();
}
DECLARE_CONOBJECT(afxBillboardData);
};

View file

@ -86,7 +86,7 @@ void afxBillboard::_renderBillboard(ObjectRenderInst *ri, SceneRenderState* stat
GFXTransformSaver saver;
GFX->multWorld(getRenderTransform());
GFX->setTexture(0, mDataBlock->mTexture);
GFX->setTexture(0, mDataBlock->getTexture());
MatrixF worldmod = GFX->getWorldMatrix();
MatrixF viewmod = GFX->getViewMatrix();

View file

@ -78,8 +78,6 @@ bool afxZodiacData::sPreferDestinationGradients = false;
afxZodiacData::afxZodiacData()
{
INIT_ASSET(Texture);
radius_xy = 1;
vert_range.set(0.0f, 0.0f);
start_ang = 0;
@ -120,7 +118,7 @@ afxZodiacData::afxZodiacData()
afxZodiacData::afxZodiacData(const afxZodiacData& other, bool temp_clone) : GameBaseData(other, temp_clone)
{
CLONE_ASSET(Texture);
CLONE_ASSET_REFACTOR(Texture);
radius_xy = other.radius_xy;
vert_range = other.vert_range;
@ -158,7 +156,7 @@ void afxZodiacData::initPersistFields()
{
docsURL;
INITPERSISTFIELD_IMAGEASSET(Texture, afxZodiacData, "An image to use as the zodiac's texture.");
addFieldV("radius", TypeRangedF32, Offset(radius_xy, afxZodiacData), &CommonValidators::PositiveFloat,
addField("radius", TypeF32, Offset(radius_xy, afxZodiacData),
"The zodiac's radius in scene units.");
addField("verticalRange", TypePoint2F, Offset(vert_range, afxZodiacData),
"For interior zodiacs only, verticalRange specifies distances above and below the "
@ -270,7 +268,7 @@ void afxZodiacData::packData(BitStream* stream)
merge_zflags();
PACKDATA_ASSET(Texture);
PACKDATA_ASSET_REFACTOR(Texture);
stream->write(radius_xy);
stream->write(vert_range.x);
stream->write(vert_range.y);
@ -295,7 +293,7 @@ void afxZodiacData::unpackData(BitStream* stream)
{
Parent::unpackData(stream);
UNPACKDATA_ASSET(Texture);
UNPACKDATA_ASSET_REFACTOR(Texture);
stream->read(&radius_xy);
stream->read(&vert_range.x);
stream->read(&vert_range.y);
@ -326,22 +324,11 @@ bool afxZodiacData::preload(bool server, String &errorStr)
if (vert_range.x == 0.0f && vert_range.y == 0.0f)
vert_range.x = vert_range.y = radius_xy;
if (mTextureAssetId != StringTable->EmptyString())
if (mTextureAsset.notNull())
{
mTextureAsset = mTextureAssetId;
if (mTextureAsset.notNull())
{
if (getTexture() != StringTable->EmptyString() && mTextureName != StringTable->insert("texhandle"))
{
if (mTextureAsset.notNull())
{
mTextureAsset->getChangedSignal().notify(this, &afxZodiacData::onImageChanged);
}
mTexture.set(getTexture(), mTextureProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
}
}
getTexture();
}
return true;
}
@ -358,21 +345,9 @@ void afxZodiacData::onStaticModified(const char* slot, const char* newValue)
void afxZodiacData::onPerformSubstitutions()
{
if (mTextureAssetId != StringTable->EmptyString())
if (mTextureAsset.notNull())
{
mTextureAsset = mTextureAssetId;
if (mTextureAsset.notNull())
{
if (getTexture() != StringTable->EmptyString() && mTextureName != StringTable->insert("texhandle"))
{
if (mTextureAsset.notNull())
{
mTextureAsset->getChangedSignal().notify(this, &afxZodiacData::onImageChanged);
}
mTexture.set(getTexture(), mTextureProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
}
}
getTexture();
}
}

View file

@ -56,14 +56,8 @@ public:
static void convertGradientRangeFromDegrees(Point2F& gradrange, const Point2F& gradrange_deg);
void onImageChanged()
{
reloadOnLocalClient();
}
public:
DECLARE_IMAGEASSET(afxZodiacData, Texture, onImageChanged, AFX_GFXZodiacTextureProfile);
DECLARE_ASSET_SETGET(afxZodiacData, Texture);
DECLARE_IMAGEASSET(afxZodiacData, Texture, AFX_GFXZodiacTextureProfile)
F32 radius_xy;
Point2F vert_range;

View file

@ -61,7 +61,7 @@ void afxZodiacMgr::addTerrainZodiac(Point3F& pos, F32 radius, LinearColorF& colo
z.color = color.toColorI();
z.angle = mDegToRad(angle);
z.zflags = zode->zflags;
z.txr = &zode->mTexture;
z.txr = zode->getTexture();
z.distance_max = zode->distance_max*zode->distance_max;
z.distance_falloff = zode->distance_falloff*zode->distance_falloff;
@ -84,7 +84,7 @@ void afxZodiacMgr::addInteriorZodiac(Point3F& pos, F32 radius, Point2F& vert_ran
z.color = color.toColorI();
z.angle = mDegToRad(angle);
z.zflags = zode->zflags;
z.txr = &zode->mTexture;
z.txr = zode->getTexture();
z.distance_max = zode->distance_max*zode->distance_max;
z.distance_falloff = zode->distance_falloff*zode->distance_falloff;

View file

@ -67,7 +67,7 @@ private:
ColorI color; // 4// color of zodiac
F32 angle; // 4// angle in radians
U32 zflags; // 4// 0=normal,1=additive,2=subtractive
GFXTexHandle* txr; // 4// zodiac texture
GFXTexHandle txr; // 4// zodiac texture
F32 distance_max;
F32 distance_falloff;

View file

@ -51,8 +51,6 @@ ConsoleDocClass( afxZodiacPlaneData,
afxZodiacPlaneData::afxZodiacPlaneData()
{
INIT_ASSET(Texture);
radius_xy = 1;
start_ang = 0;
ang_per_sec = 0;
@ -71,7 +69,7 @@ afxZodiacPlaneData::afxZodiacPlaneData()
afxZodiacPlaneData::afxZodiacPlaneData(const afxZodiacPlaneData& other, bool temp_clone)
: GameBaseData(other, temp_clone)
{
CLONE_ASSET(Texture);
CLONE_ASSET_REFACTOR(Texture);
radius_xy = other.radius_xy;
start_ang = other.start_ang;
@ -166,7 +164,7 @@ void afxZodiacPlaneData::packData(BitStream* stream)
merge_zflags();
PACKDATA_ASSET(Texture);
PACKDATA_ASSET_REFACTOR(Texture);
stream->write(radius_xy);
stream->write(start_ang);
@ -185,7 +183,7 @@ void afxZodiacPlaneData::unpackData(BitStream* stream)
{
Parent::unpackData(stream);
UNPACKDATA_ASSET(Texture);
UNPACKDATA_ASSET_REFACTOR(Texture);
stream->read(&radius_xy);
stream->read(&start_ang);

View file

@ -56,14 +56,8 @@ public:
FACES_BITS = 3
};
void onImageChanged()
{
reloadOnLocalClient();
}
public:
DECLARE_IMAGEASSET(afxZodiacPlaneData, Texture, onImageChanged, AFX_GFXZodiacTextureProfile);
DECLARE_ASSET_SETGET(afxZodiacPlaneData, Texture);
DECLARE_IMAGEASSET(afxZodiacPlaneData, Texture, AFX_GFXZodiacTextureProfile)
F32 radius_xy;
F32 start_ang;

View file

@ -207,7 +207,7 @@ void afxZodiacPlane::_renderZodiacPlane(ObjectRenderInst *ri, SceneRenderState*
GFXTransformSaver saver;
GFX->multWorld(getRenderTransform());
GFX->setTexture(0, mDataBlock->mTexture);
GFX->setTexture(0, mDataBlock->getTexture());
PrimBuild::begin(GFXTriangleStrip, 4);
{

View file

@ -146,7 +146,7 @@ void afxParticlePool::pool_renderObject_Normal(RenderPassManager *renderManager,
if (main_emitter_data->textureHandle)
ri->diffuseTex = &*(main_emitter_data->textureHandle);
else
ri->diffuseTex = &*(main_emitter_data->particleDataBlocks[0]->getTextureResource());
ri->diffuseTex = &*(main_emitter_data->particleDataBlocks[0]->getTexture());
ri->softnessDistance = main_emitter_data->softnessDistance;
@ -277,7 +277,7 @@ void afxParticlePool::pool_renderObject_TwoPass(RenderPassManager *renderManager
//if (main_emitter_data->textureHandle)
// ri->diffuseTex = &*(main_emitter_data->textureHandle);
//else
ri->diffuseTex = &*(main_emitter_data->particleDataBlocks[0]->getTextureExtResource());
ri->diffuseTex = &*(main_emitter_data->particleDataBlocks[0]->getTextureExt());
F32 save_sort_dist = ri->sortDistSq;
@ -481,7 +481,7 @@ void afxParticlePool::pool_renderObject_TwoPass(RenderPassManager *renderManager
if (main_emitter_data->textureHandle)
ri->diffuseTex = &*(main_emitter_data->textureHandle);
else
ri->diffuseTex = &*(main_emitter_data->particleDataBlocks[0]->getTextureResource());
ri->diffuseTex = &*(main_emitter_data->particleDataBlocks[0]->getTexture());
ri->softnessDistance = main_emitter_data->softnessDistance;

View file

@ -1660,8 +1660,8 @@ void AssetManager::dumpDeclaredAssets( void ) const
pAssetDefinition->mAssetInternal,
pAssetDefinition->mAssetPrivate,
pAssetDefinition->mAssetType,
pAssetDefinition->mpModuleDefinition->getModuleId(),
pAssetDefinition->mpModuleDefinition->getVersionId(),
pAssetDefinition->mAssetPrivate ? "Private" : pAssetDefinition->mpModuleDefinition->getModuleId(),
pAssetDefinition->mAssetPrivate ? 0 : pAssetDefinition->mpModuleDefinition->getVersionId(),
pAssetDefinition->mAssetBaseFilePath );
}

View file

@ -105,7 +105,6 @@ VolumetricFog::VolumetricFog()
mFrontBufferTarget = NULL;
z_buf = NULL;
mTexture = NULL;
mIsVBDirty = false;
mIsPBDirty = false;
@ -138,7 +137,6 @@ VolumetricFog::VolumetricFog()
mSpeed2.set(0.1f, 0.1f);
INIT_ASSET(Shape);
INIT_ASSET(Texture);
}
VolumetricFog::~VolumetricFog()
@ -159,8 +157,6 @@ VolumetricFog::~VolumetricFog()
z_buf = NULL;
if (!mTexture.isNull())
mTexture.free();
}
void VolumetricFog::initPersistFields()
@ -330,8 +326,10 @@ void VolumetricFog::handleResize(VolumetricFogRTManager *RTM, bool resize)
F32 width = (F32)mPlatformWindow->getClientExtent().x;
F32 height = (F32)mPlatformWindow->getClientExtent().y;
mTexScale.x = 2.0f - ((F32)mTexture.getWidth() / width);
mTexScale.y = 2.0f - ((F32)mTexture.getHeight() / height);
// load texture.
getTexture();
mTexScale.x = 2.0f - ((F32)mTextureAsset->getTextureWidth() / width);
mTexScale.y = 2.0f - ((F32)mTextureAsset->getTextureHeight() / height);
}
UpdateBuffers(0,true);
@ -545,7 +543,7 @@ U32 VolumetricFog::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
stream->write(mFogDensity);
if (stream->writeFlag(mask & FogModulationMask))
{
PACK_ASSET(con, Texture);
PACK_ASSET_REFACTOR(con, Texture);
mTexTiles = mFabs(mTexTiles);
stream->write(mTexTiles);
stream->write(mStrength);
@ -597,7 +595,7 @@ void VolumetricFog::unpackUpdate(NetConnection *con, BitStream *stream)
MatrixF mat;
VectorF scale;
VectorF mOldScale = getScale();
StringTableEntry oldTextureName = mTextureAssetId;
StringTableEntry oldTextureName = mTextureAsset.getAssetId();
StringTableEntry oldShapeAsset = mShapeAssetId;
StringTableEntry oldShape = mShapeName;
@ -615,7 +613,7 @@ void VolumetricFog::unpackUpdate(NetConnection *con, BitStream *stream)
}
if (stream->readFlag())// Fog Modulation
{
UNPACK_ASSET(con, Texture);
UNPACK_ASSET_REFACTOR(con, Texture);
stream->read(&mTexTiles);
mTexTiles = mFabs(mTexTiles);
stream->read(&mStrength);
@ -625,12 +623,11 @@ void VolumetricFog::unpackUpdate(NetConnection *con, BitStream *stream)
if (isProperlyAdded())
{
if (oldTextureName != mTextureAssetId)
if (oldTextureName != mTextureAsset.getAssetId())
InitTexture();
if (oldTextureName != StringTable->EmptyString() && mTextureAssetId == StringTable->EmptyString())
if (oldTextureName != StringTable->EmptyString() && mTextureAsset.isNull())
{
mIsTextured = false;
mTexture.free();
}
}
}
@ -1149,7 +1146,7 @@ void VolumetricFog::render(ObjectRenderInst *ri, SceneRenderState *state, BaseMa
if (mIsTextured && mStrength > 0.0f)
{
GFX->setTexture(3, mTexture);
GFX->setTexture(3, getTexture());
mShaderConsts->setSafe(mIsTexturedSC, 1.0f);
}
else
@ -1222,15 +1219,16 @@ void VolumetricFog::InitTexture()
{
return;
}
if (!mTexture.isNull())
if (!mTextureAsset.isNull())
{
mIsTextured = true;
// load asset.
getTexture();
F32 width = (F32)mPlatformWindow->getClientExtent().x;
F32 height = (F32)mPlatformWindow->getClientExtent().y;
mTexScale.x = 2.0f - ((F32)mTexture.getWidth() / width);
mTexScale.y = 2.0f - ((F32)mTexture.getHeight() / height);
mTexScale.x = 2.0f - ((F32)mTextureAsset->getTextureWidth() / width);
mTexScale.y = 2.0f - ((F32)mTextureAsset->getTextureHeight() / height);
}
}

View file

@ -162,8 +162,7 @@ class VolumetricFog : public SceneObject
F32 mInvScale;
// Fog Modulation data
DECLARE_IMAGEASSET(VolumetricFog, Texture, onImageChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_NET_SETGET(VolumetricFog, Texture, FogModulationMask);
DECLARE_IMAGEASSET_NET(VolumetricFog, Texture, GFXStaticTextureSRGBProfile, FogModulationMask)
bool mIsTextured;
F32 mTexTiles;
@ -221,8 +220,6 @@ class VolumetricFog : public SceneObject
static bool _setShapeAsset(void* obj, const char* index, const char* data);
void onImageChanged() {}
public:
// Public methods
VolumetricFog();

View file

@ -98,9 +98,6 @@ BasicClouds::BasicClouds()
mTexOffset[0].set( 0.5f, 0.5f );
mTexOffset[1].set( 0.5f, 0.5f );
mTexOffset[2].set( 0.5f, 0.5f );
for (U32 i=0; i< TEX_COUNT;i++)
INIT_IMAGEASSET_ARRAY(Texture, GFXStaticTextureSRGBProfile, i);
}
IMPLEMENT_CO_NETOBJECT_V1( BasicClouds );
@ -215,12 +212,11 @@ U32 BasicClouds::packUpdate( NetConnection *conn, U32 mask, BitStream *stream )
{
U32 retMask = Parent::packUpdate( conn, mask, stream );
PACK_ASSET_ARRAY_REFACTOR(conn, Texture, TEX_COUNT)
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
stream->writeFlag( mLayerEnabled[i] );
PACK_ASSET_ARRAY(conn, Texture, i);
stream->write( mTexScale[i] );
mathWrite( *stream, mTexDirection[i] );
stream->write( mTexSpeed[i] );
@ -236,12 +232,11 @@ void BasicClouds::unpackUpdate( NetConnection *conn, BitStream *stream )
{
Parent::unpackUpdate( conn, stream );
UNPACK_ASSET_ARRAY_REFACTOR(conn, Texture, TEX_COUNT)
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
mLayerEnabled[i] = stream->readFlag();
UNPACK_ASSET_ARRAY(conn, Texture, i);
stream->read( &mTexScale[i] );
mathRead( *stream, &mTexDirection[i] );
stream->read( &mTexSpeed[i] );
@ -315,14 +310,14 @@ void BasicClouds::renderObject( ObjectRenderInst *ri, SceneRenderState *state, B
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
if ( !mLayerEnabled[i] )
if ( !mLayerEnabled[i] || mTextureAsset[i].isNull())
continue;
mShaderConsts->setSafe( mTexScaleSC, mTexScale[i] );
mShaderConsts->setSafe( mTexDirectionSC, mTexDirection[i] * mTexSpeed[i] );
mShaderConsts->setSafe( mTexOffsetSC, mTexOffset[i] );
GFX->setTexture( mDiffuseMapSC->getSamplerRegister(), mTexture[i] );
GFX->setTexture( mDiffuseMapSC->getSamplerRegister(), getTexture(i) );
GFX->setVertexBuffer( mVB[i] );
GFX->drawIndexedPrimitive( GFXTriangleList, 0, 0, smVertCount, 0, smTriangleCount );
@ -337,13 +332,11 @@ void BasicClouds::_initTexture()
{
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
if ( !mLayerEnabled[i] )
if ( mLayerEnabled[i] && mTextureAsset[i].notNull())
{
mTexture[i] = NULL;
continue;
// load the resource.
getTexture(i);
}
_setTexture(getTexture(i), i);
}
}

View file

@ -94,9 +94,8 @@ protected:
static U32 smVertCount;
static U32 smTriangleCount;
DECLARE_IMAGEASSET_ARRAY(BasicClouds, Texture, TEX_COUNT, onTextureChanged);
DECLARE_IMAGEASSET_ARRAY_NET_SETGET(BasicClouds, Texture, -1);
void onTextureChanged() {}
DECLARE_IMAGEASSET_ARRAY_NET(BasicClouds, Texture, GFXStaticTextureSRGBProfile, TEX_COUNT, -1)
GFXStateBlockRef mStateblock;
GFXShaderRef mShader;

View file

@ -112,8 +112,6 @@ CloudLayer::CloudLayer()
mTexOffset[0] = mTexOffset[1] = mTexOffset[2] = Point2F::Zero;
mHeight = 4.0f;
INIT_ASSET(Texture);
}
IMPLEMENT_CO_NETOBJECT_V1( CloudLayer );
@ -131,8 +129,6 @@ bool CloudLayer::onAdd()
addToScene();
LOAD_IMAGEASSET(Texture);
if ( isClientObject() )
{
_initBuffers();
@ -194,8 +190,8 @@ void CloudLayer::initPersistFields()
docsURL;
addGroup( "CloudLayer" );
INITPERSISTFIELD_IMAGEASSET(Texture, CloudLayer, "An RGBA texture which should contain normals and opacity (density).");
INITPERSISTFIELD_IMAGEASSET(Texture, CloudLayer, "An RGBA texture which should contain normals and opacity (density).")
addArray( "Textures", TEX_COUNT );
addFieldV( "texScale", TypeRangedF32, Offset( mTexScale, CloudLayer ), &CommonValidators::PositiveFloat, TEX_COUNT,
@ -243,7 +239,9 @@ U32 CloudLayer::packUpdate( NetConnection *conn, U32 mask, BitStream *stream )
{
U32 retMask = Parent::packUpdate( conn, mask, stream );
PACK_ASSET(conn, Texture);
if (stream->writeFlag(mTextureAsset.notNull())) {
NetStringHandle assetIdStr = mTextureAsset.getAssetId(); conn->packNetStringHandleU(stream, assetIdStr);
}
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
@ -265,10 +263,9 @@ void CloudLayer::unpackUpdate( NetConnection *conn, BitStream *stream )
{
Parent::unpackUpdate( conn, stream );
UNPACK_ASSET(conn, Texture);
if(mTextureAssetId != StringTable->EmptyString())
mTextureAsset = mTextureAssetId;
if (stream->readFlag()) {
mTextureAsset.setAssetId(_getStringTable()->insert(conn->unpackNetStringHandleU(stream).getString()));
}
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
@ -334,7 +331,7 @@ void CloudLayer::renderObject( ObjectRenderInst *ri, SceneRenderState *state, Ba
{
GFXTransformSaver saver;
if (!mTextureAsset || !mTextureAsset->isAssetValid())
if (!mTextureAsset)
return;
const Point3F &camPos = state->getCameraPosition();
@ -385,7 +382,7 @@ void CloudLayer::renderObject( ObjectRenderInst *ri, SceneRenderState *state, Ba
mShaderConsts->setSafe( mExposureSC, mExposure );
GFX->setTexture( mNormalHeightMapSC->getSamplerRegister(), getTextureResource());
GFX->setTexture( mNormalHeightMapSC->getSamplerRegister(), mTextureAsset->getTexture(&GFXStaticTextureSRGBProfile));
GFX->setVertexBuffer( mVB );
GFX->setPrimitiveBuffer( mPB );

View file

@ -61,7 +61,6 @@ class CloudLayer : public SceneObject
};
#define TEX_COUNT 3
public:
CloudLayer();
@ -97,8 +96,9 @@ protected:
static U32 smVertCount;
static U32 smTriangleCount;
DECLARE_IMAGEASSET(CloudLayer, Texture, onImageChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_NET_SETGET(CloudLayer, Texture, CloudLayerMask);
public:
DECLARE_IMAGEASSET_NET(CloudLayer,Texture, GFXStaticTextureSRGBProfile, CloudLayerMask)
GFXShaderRef mShader;

View file

@ -260,10 +260,6 @@ WaterObject::WaterObject()
mMatrixSet = reinterpret_cast<MatrixSet *>(dMalloc_aligned(sizeof(MatrixSet), 16));
constructInPlace(mMatrixSet);
INIT_ASSET(RippleTex);
INIT_ASSET(FoamTex);
INIT_ASSET(DepthGradientTex);
mCubemapName = StringTable->EmptyString();
}
@ -547,9 +543,9 @@ U32 WaterObject::packUpdate( NetConnection * conn, U32 mask, BitStream *stream )
if ( stream->writeFlag( mask & TextureMask ) )
{
PACK_ASSET(conn, RippleTex);
PACK_ASSET(conn, DepthGradientTex);
PACK_ASSET(conn, FoamTex);
PACK_ASSET_REFACTOR(conn, RippleTex);
PACK_ASSET_REFACTOR(conn, DepthGradientTex);
PACK_ASSET_REFACTOR(conn, FoamTex);
stream->writeString( mCubemapName );
}
@ -669,9 +665,9 @@ void WaterObject::unpackUpdate( NetConnection * conn, BitStream *stream )
// TextureMask
if ( stream->readFlag() )
{
UNPACK_ASSET(conn, RippleTex);
UNPACK_ASSET(conn, DepthGradientTex);
UNPACK_ASSET(conn, FoamTex);
UNPACK_ASSET_REFACTOR(conn, RippleTex);
UNPACK_ASSET_REFACTOR(conn, DepthGradientTex);
UNPACK_ASSET_REFACTOR(conn, FoamTex);
mCubemapName = stream->readSTString();
@ -767,13 +763,13 @@ void WaterObject::renderObject( ObjectRenderInst *ri, SceneRenderState *state, B
void WaterObject::setCustomTextures( S32 matIdx, U32 pass, const WaterMatParams &paramHandles )
{
// Always use the ripple texture.
GFX->setTexture( paramHandles.mRippleSamplerSC->getSamplerRegister(pass), mRippleTex );
GFX->setTexture( paramHandles.mRippleSamplerSC->getSamplerRegister(pass), getRippleTex() );
// Only above-water in advanced-lighting uses the foam texture.
if ( matIdx == WaterMat )
{
GFX->setTexture( paramHandles.mFoamSamplerSC->getSamplerRegister(pass), mFoamTex );
GFX->setTexture( paramHandles.mDepthGradSamplerSC->getSamplerRegister(pass), mDepthGradientTex );
GFX->setTexture( paramHandles.mFoamSamplerSC->getSamplerRegister(pass), getFoamTex() );
GFX->setTexture( paramHandles.mDepthGradSamplerSC->getSamplerRegister(pass), getDepthGradientTex() );
}
if ( ( matIdx == WaterMat || matIdx == BasicWaterMat ) && mCubemap )
@ -1118,7 +1114,7 @@ void WaterObject::updateUnderwaterEffect( SceneRenderState *state )
// be fetched by the effect when it renders.
if ( !mNamedDepthGradTex.isRegistered() )
mNamedDepthGradTex.registerWithName( "waterDepthGradMap" );
mNamedDepthGradTex.setTexture( mDepthGradientTex );
mNamedDepthGradTex.setTexture( getDepthGradientTex() );
}
else
effect->disable();
@ -1172,7 +1168,7 @@ bool WaterObject::initMaterial( S32 idx )
void WaterObject::initTextures()
{
if ( mNamedDepthGradTex.isRegistered() )
mNamedDepthGradTex.setTexture( mDepthGradientTex );
mNamedDepthGradTex.setTexture( getDepthGradientTex() );
if ( mCubemapName != StringTable->EmptyString() )
Sim::findObject( mCubemapName, mCubemap );

View file

@ -203,10 +203,6 @@ protected:
/// Callback used internally when smEnableTrueReflections changes.
void _onEnableTrueReflections();
void onRippleTexChanged() {}
void onFoamTexChanged() {}
void onDepthGradientTexChanged() {}
protected:
static bool _setFullReflect( void *object, const char *index, const char *data );
@ -273,12 +269,9 @@ protected:
F32 mDepthGradientMax;
// Other textures
DECLARE_IMAGEASSET(WaterObject, RippleTex, onRippleTexChanged, GFXStaticTextureProfile);
DECLARE_ASSET_NET_SETGET(WaterObject, RippleTex, TextureMask);
DECLARE_IMAGEASSET(WaterObject, FoamTex, onFoamTexChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_NET_SETGET(WaterObject, FoamTex, TextureMask);
DECLARE_IMAGEASSET(WaterObject, DepthGradientTex, onDepthGradientTexChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_NET_SETGET(WaterObject, DepthGradientTex, TextureMask);
DECLARE_IMAGEASSET_NET(WaterObject, RippleTex, GFXStaticTextureProfile, TextureMask)
DECLARE_IMAGEASSET_NET(WaterObject, FoamTex, GFXStaticTextureSRGBProfile, TextureMask)
DECLARE_IMAGEASSET_NET(WaterObject, DepthGradientTex, GFXStaticTextureSRGBProfile, TextureMask)
StringTableEntry mCubemapName;

View file

@ -37,9 +37,11 @@
#pragma warning( push )
#pragma warning( disable : 4505 ) // unreferenced function removed.
#ifndef STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_STATIC
#include "stb_image.h"
#endif
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define STB_IMAGE_WRITE_STATIC

View file

@ -41,13 +41,6 @@ IMPLEMENT_CONOBJECT( CubemapData );
CubemapData::CubemapData()
{
mCubemap = NULL;
for (U32 i = 0; i < 6; i++)
{
INIT_IMAGEASSET_ARRAY(CubeMapFace, GFXStaticTextureSRGBProfile, i);
}
INIT_ASSET(CubeMap);
}
CubemapData::~CubemapData()
@ -77,16 +70,6 @@ ConsoleDocClass( CubemapData,
void CubemapData::initPersistFields()
{
docsURL;
addProtectedField( "cubeFace", TypeStringFilename, Offset(mCubeMapFaceName, CubemapData), _setCubeMapFaceData, defaultProtectedGetFn, 6,
"@brief The 6 cubemap face textures for a static cubemap.\n\n"
"They are in the following order:\n"
" - cubeFace[0] is -X\n"
" - cubeFace[1] is +X\n"
" - cubeFace[2] is -Z\n"
" - cubeFace[3] is +Z\n"
" - cubeFace[4] is -Y\n"
" - cubeFace[5] is +Y\n", AbstractClassRep::FIELD_HideInInspectors );
INITPERSISTFIELD_IMAGEASSET_ARRAY(CubeMapFace, 6, CubemapData, "@brief The 6 cubemap face textures for a static cubemap.\n\n"
"They are in the following order:\n"
" - cubeFace[0] is -X\n"
@ -116,19 +99,26 @@ void CubemapData::createMap()
{
bool initSuccess = true;
//check mCubeMapFile first
if (getCubeMap() != StringTable->EmptyString())
if (mCubeMapAsset.notNull())
{
mCubemap = TEXMGR->createCubemap(getCubeMap());
mCubemap = TEXMGR->createCubemap(mCubeMapAsset->getImageFile());
return;
}
else
{
for (U32 i = 0; i < 6; i++)
{
if (!_setCubeMapFace(getCubeMapFace(i), i))
if (mCubeMapFaceAsset[i].notNull())
{
Con::errorf("CubemapData::createMap - Failed to load texture '%s'", getCubeMapFace(i));
initSuccess = false;
if (!getCubeMapFace(i))
{
Con::errorf("CubemapData::createMap - Failed to load texture '%s'", mCubeMapFaceAsset[i]->getImageFile());
initSuccess = false;
}
else
{
mCubeMapFaceTex[i] = getCubeMapFace(i);
}
}
}
}
@ -136,9 +126,10 @@ void CubemapData::createMap()
if( initSuccess )
{
mCubemap = GFX->createCubemap();
if (!mCubeMapFace || mCubeMapFace->isNull())
if (mCubeMapFaceAsset->isNull())
return;
mCubemap->initStatic(mCubeMapFace);
mCubemap->initStatic(mCubeMapFaceTex);
}
}
}
@ -147,20 +138,27 @@ void CubemapData::updateFaces()
{
bool initSuccess = true;
for( U32 i=0; i<6; i++ )
//check mCubeMapFile first
if (mCubeMapAsset.notNull())
{
//check mCubeMapFile first
if (getCubeMap() != StringTable->EmptyString())
mCubemap = TEXMGR->createCubemap(mCubeMapAsset->getImageFile());
return;
}
else
{
for (U32 i = 0; i < 6; i++)
{
mCubemap = TEXMGR->createCubemap(getCubeMap());
return;
}
else
{
if (!_setCubeMapFace(getCubeMapFace(i), i))
if (mCubeMapFaceAsset[i].notNull())
{
Con::errorf("CubemapData::createMap - Failed to load texture '%s'", getCubeMapFace(i));
initSuccess = false;
if (!getCubeMapFace(i))
{
Con::errorf("CubemapData::createMap - Failed to load texture '%s'", mCubeMapFaceAsset[i]->getImageFile());
initSuccess = false;
}
else
{
mCubeMapFaceTex[i] = getCubeMapFace(i);
}
}
}
}
@ -169,14 +167,16 @@ void CubemapData::updateFaces()
{
mCubemap = NULL;
mCubemap = GFX->createCubemap();
if (mCubeMapFaceAsset->isNull())
return;
mCubemap->initStatic( mCubeMapFace );
mCubemap->initStatic(mCubeMapFaceTex);
}
}
void CubemapData::setCubemapFile(FileName newCubemapFile)
{
mCubeMapName = newCubemapFile;
_setCubeMap(newCubemapFile);
}
void CubemapData::setCubeFaceFile(U32 index, FileName newFaceFile)
@ -184,7 +184,7 @@ void CubemapData::setCubeFaceFile(U32 index, FileName newFaceFile)
if (index >= 6)
return;
mCubeMapFaceName[index] = newFaceFile;
_setCubeMapFace(newFaceFile, index);
}
void CubemapData::setCubeFaceTexture(U32 index, GFXTexHandle newFaceTexture)
@ -192,7 +192,7 @@ void CubemapData::setCubeFaceTexture(U32 index, GFXTexHandle newFaceTexture)
if (index >= 6)
return;
mCubeMapFace[index] = newFaceTexture;
mCubeMapFaceTex[index] = newFaceTexture;
}
DefineEngineMethod( CubemapData, updateFaces, void, (),,

View file

@ -70,20 +70,16 @@ public:
void setCubeFaceTexture(U32 index, GFXTexHandle newFaceTexture);
GFXTexHandle* getCubeFaceTexture(U32 faceIdx) { return &mCubeMapFace[faceIdx]; }
GFXTexHandle* getCubeFaceTexture(U32 faceIdx) { return &mCubeMapFaceTex[faceIdx]; }
protected:
DECLARE_IMAGEASSET(CubemapData, CubeMap, onCubemapChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(CubemapData, CubeMap);
DECLARE_IMAGEASSET(CubemapData, CubeMap, GFXStaticTextureSRGBProfile);
DECLARE_IMAGEASSET_ARRAY(CubemapData, CubeMapFace, 6, onCubeMapFaceChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(CubemapData, CubeMapFace);
DECLARE_IMAGEASSET_ARRAY(CubemapData, CubeMapFace, GFXStaticTextureSRGBProfile, 6);
void onCubeMapFaceChanged() {}
GFXTexHandle mCubeMapFaceTex[6];
GFXTexHandle mDepthBuff;
GFXTextureTargetRef mRenderTarget;
void onCubemapChanged() {}
};
#endif // CUBEMAPDATA

View file

@ -129,7 +129,9 @@ GuiBitmapButtonCtrl::GuiBitmapButtonCtrl()
setExtent( 140, 30 );
mMasked = false;
mColor = ColorI::WHITE;
INIT_ASSET(Bitmap);
mBitmapName = StringTable->EmptyString();
mBitmap = NULL;
mBitmapAsset.registerRefreshNotify(this);
}
//-----------------------------------------------------------------------------
@ -139,14 +141,10 @@ void GuiBitmapButtonCtrl::initPersistFields()
docsURL;
addGroup( "Bitmap" );
addProtectedField("Bitmap", TypeImageFilename, Offset(mBitmapName, GuiBitmapButtonCtrl), _setBitmapFieldData, &defaultProtectedGetFn, "Texture file to display on this button.\n"
INITPERSISTFIELD_IMAGEASSET(Bitmap, GuiBitmapButtonCtrl,"Texture file to display on this button.\n"
"If useStates is false, this will be the file that renders on the control. Otherwise, this will "
"specify the default texture name to which the various state and modifier suffixes are appended "
"to find the per-state and per-modifier (if enabled) textures.", AbstractClassRep::FIELD_HideInInspectors); \
addProtectedField("BitmapAsset", TypeImageAssetId, Offset(mBitmapAssetId, GuiBitmapButtonCtrl), _setBitmapFieldData, &defaultProtectedGetFn, "Texture file to display on this button.\n"
"If useStates is false, this will be the file that renders on the control. Otherwise, this will "
"specify the default texture name to which the various state and modifier suffixes are appended "
"to find the per-state and per-modifier (if enabled) textures.");
"to find the per-state and per-modifier (if enabled) textures.")
addField("color", TypeColorI, Offset(mColor, GuiBitmapButtonCtrl), "color mul");
@ -184,7 +182,7 @@ bool GuiBitmapButtonCtrl::onWake()
return false;
setActive( true );
setBitmap( getBitmap() );
setBitmap( mBitmapName );
return true;
}
@ -242,7 +240,7 @@ void GuiBitmapButtonCtrl::inspectPostApply()
{
Parent::inspectPostApply();
setBitmap(getBitmap());
setBitmap(mBitmapName);
// if the extent is set to (0,0) in the gui editor and appy hit, this control will
// set it's extent to be exactly the size of the normal bitmap (if present)
@ -274,7 +272,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
if( mBitmapAsset.notNull())
{
if( dStricmp( getBitmap(), "texhandle" ) != 0 )
if( dStricmp( mBitmapName, "texhandle" ) != 0 )
{
const U32 count = mUseModifiers ? NumModifiers : 1;
for( U32 i = 0; i < count; ++ i )
@ -292,7 +290,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
static String s_h[2] = { "_h", "_h_image" };
static String s_i[2] = { "_i", "_i_image" };
String baseName = mBitmapAssetId;
String baseName = mBitmapAsset.getAssetId();
//strip any pre-assigned suffix, just in case
baseName = baseName.replace("_n_image", "");
@ -301,7 +299,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
if( mUseModifiers )
baseName += modifiers[ i ];
mTextures[ i ].mTextureNormal = GFXTexHandle( mBitmapAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__));
mTextures[i].mTextureNormal = getBitmap();
if( mUseStates )
{
@ -323,7 +321,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
mTextures[i].mTextureNormalAsset->load();
if (mTextures[i].mTextureNormalAsset->getStatus() == AssetBase::Ok)
{
mTextures[i].mTextureNormal = GFXTexHandle(mTextures[i].mTextureNormalAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
mTextures[i].mTextureNormal = mTextures[i].mTextureNormalAsset->getTexture(&GFXDefaultGUIProfile);
break;
}
}
@ -345,7 +343,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
mTextures[i].mTextureHilightAsset->load();
if (mTextures[i].mTextureHilightAsset->getStatus() == AssetBase::Ok)
{
mTextures[i].mTextureHilight = GFXTexHandle(mTextures[i].mTextureHilightAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
mTextures[i].mTextureHilight = mTextures[i].mTextureHilightAsset->getTexture(&GFXDefaultGUIProfile);
break;
}
}
@ -369,7 +367,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
mTextures[i].mTextureDepressedAsset->load();
if (mTextures[i].mTextureDepressedAsset->getStatus() == AssetBase::Ok)
{
mTextures[i].mTextureDepressed = GFXTexHandle(mTextures[i].mTextureDepressedAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
mTextures[i].mTextureDepressed = mTextures[i].mTextureDepressedAsset->getTexture(&GFXDefaultGUIProfile);
break;
}
}
@ -393,7 +391,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
mTextures[i].mTextureInactiveAsset->load();
if (mTextures[i].mTextureInactiveAsset->getStatus() == AssetBase::Ok)
{
mTextures[i].mTextureInactive = GFXTexHandle(mTextures[i].mTextureInactiveAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
mTextures[i].mTextureInactive = mTextures[i].mTextureInactiveAsset->getTexture(&GFXDefaultGUIProfile);
break;
}
}
@ -670,4 +668,4 @@ bool GuiBitmapButtonCtrl::pointInControl(const Point2I& parentCoordPoint)
return Parent::pointInControl(parentCoordPoint);
}
DEF_ASSET_BINDS(GuiBitmapButtonCtrl, Bitmap);
DEF_ASSET_BINDS_REFACTOR(GuiBitmapButtonCtrl, Bitmap)

View file

@ -49,7 +49,7 @@
/// To implement different handlers for the modifier states, use the "onDefaultClick",
/// "onCtrlClick", "onAltClick", and "onShiftClick" methods.
///
class GuiBitmapButtonCtrl : public GuiButtonCtrl
class GuiBitmapButtonCtrl : public GuiButtonCtrl, protected AssetPtrCallback
{
public:
@ -118,9 +118,35 @@ class GuiBitmapButtonCtrl : public GuiButtonCtrl
///
BitmapMode mBitmapMode;
DECLARE_IMAGEASSET(GuiBitmapButtonCtrl, Bitmap, onBitmapChange, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiBitmapButtonCtrl, Bitmap);
private: AssetPtr<ImageAsset> mBitmapAsset; public: void _setBitmap(StringTableEntry _in) {
if (mBitmapAsset.getAssetId() == _in) return; if (!AssetDatabase.isDeclaredAsset(_in)) {
StringTableEntry imageAssetId = ImageAsset::smNoImageAssetFallback; AssetQuery query; S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); if (foundAssetcount != 0) {
imageAssetId = query.mAssetList[0];
} mBitmapAsset = imageAssetId;
}
else {
mBitmapAsset = _in;
mBitmapName = _in;
mBitmap = getBitmap();
}
}; inline StringTableEntry _getBitmap(void) const {
return mBitmapAsset.getAssetId();
} GFXTexHandle getBitmap() {
return mBitmapAsset.notNull() ? mBitmapAsset->getTexture(&GFXDefaultGUIProfile) : 0;
} AssetPtr<ImageAsset> getBitmapAsset(void) {
return mBitmapAsset;
} static bool _setBitmapData(void* obj, const char* index, const char* data) {
static_cast<GuiBitmapButtonCtrl*>(obj)->_setBitmap(_getStringTable()->insert(data)); return false;
}
protected:
void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
{
setBitmap(mBitmapName);
}
GFXTexHandle mBitmap;
StringTableEntry mBitmapName;
/// alpha masking
bool mMasked;
@ -158,11 +184,6 @@ class GuiBitmapButtonCtrl : public GuiButtonCtrl
/// @}
void onBitmapChange()
{
setBitmap(getBitmap());
}
public:
GuiBitmapButtonCtrl();
@ -185,14 +206,6 @@ class GuiBitmapButtonCtrl : public GuiButtonCtrl
DECLARE_CONOBJECT(GuiBitmapButtonCtrl);
DECLARE_DESCRIPTION( "A button control rendered entirely from bitmaps.\n"
"The individual button states are represented with separate bitmaps." );
//Basically a wrapper function to do our special state handling setup when the fields change
static bool _setBitmapFieldData(void* obj, const char* index, const char* data)
{
GuiBitmapButtonCtrl* object = static_cast<GuiBitmapButtonCtrl*>(obj);
object->setBitmap(StringTable->insert(data));
return false;
}
};
typedef GuiBitmapButtonCtrl::BitmapMode GuiBitmapMode;

View file

@ -134,7 +134,7 @@ void GuiCheckBoxCtrl::onRender(Point2I offset, const RectI &updateRect)
}
xOffset = mProfile->mBitmapArrayRects[0].extent.x + 2 + mIndent;
S32 y = (getHeight() - mProfile->mBitmapArrayRects[0].extent.y) / 2;
GFX->getDrawUtil()->drawBitmapSR(mProfile->getBitmapResource(), offset + Point2I(mIndent, y), mProfile->mBitmapArrayRects[index]);
GFX->getDrawUtil()->drawBitmapSR(mProfile->getBitmap(), offset + Point2I(mIndent, y), mProfile->mBitmapArrayRects[index]);
}
if(mButtonText[0] != '\0')

View file

@ -86,7 +86,6 @@ ConsoleDocClass( GuiIconButtonCtrl,
GuiIconButtonCtrl::GuiIconButtonCtrl()
{
INIT_ASSET(Bitmap);
mTextLocation = TextLocLeft;
mIconLocation = IconLocLeft;
mTextMargin = 4;
@ -127,7 +126,7 @@ void GuiIconButtonCtrl::initPersistFields()
docsURL;
addField( "buttonMargin", TypePoint2I, Offset( mButtonMargin, GuiIconButtonCtrl ),"Margin area around the button.\n");
addProtectedField( "iconBitmap", TypeImageFilename, Offset( mBitmapName, GuiIconButtonCtrl ), &_setBitmapData, &defaultProtectedGetFn, "Bitmap file for the icon to display on the button.\n", AbstractClassRep::FIELD_HideInInspectors);
addProtectedField( "iconBitmap", TypeImageFilename, Offset( mBitmapAsset, GuiIconButtonCtrl ), &_setBitmapData, &defaultProtectedGetFn, "Bitmap file for the icon to display on the button.\n", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET(Bitmap, GuiIconButtonCtrl, "Bitmap file for the icon to display on the button.\n");
addField( "iconLocation", TYPEID< IconLocation >(), Offset( mIconLocation, GuiIconButtonCtrl ),"Where to place the icon on the control. Options are 0 (None), 1 (Left), 2 (Right), 3 (Center).\n");
@ -148,8 +147,6 @@ bool GuiIconButtonCtrl::onWake()
return false;
setActive(true);
setBitmap(mBitmapName);
if( mProfile )
mProfile->constructBitmapArray();
@ -181,8 +178,8 @@ bool GuiIconButtonCtrl::resize(const Point2I &newPosition, const Point2I &newExt
if ( mIconLocation != IconLocNone )
{
autoExtent.y = mBitmap.getHeight() + mButtonMargin.y * 2;
autoExtent.x = mBitmap.getWidth() + mButtonMargin.x * 2;
autoExtent.y = getBitmap().getHeight() + mButtonMargin.y * 2;
autoExtent.x = getBitmap().getWidth() + mButtonMargin.x * 2;
}
if ( mTextLocation != TextLocNone && mButtonText && mButtonText[0] )
@ -209,7 +206,7 @@ void GuiIconButtonCtrl::setBitmap(const char *name)
if(!isAwake())
return;
_setBitmap(getBitmap());
_setBitmap(name);
// So that extent is recalculated if autoSize is set.
resize( getPosition(), getExtent() );
@ -299,13 +296,13 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
RectI iconRect( 0, 0, 0, 0 );
// Render the icon
if ( mBitmap && mIconLocation != GuiIconButtonCtrl::IconLocNone )
if ( mBitmapAsset.notNull() && mIconLocation != GuiIconButtonCtrl::IconLocNone)
{
// Render the normal bitmap
drawer->clearBitmapModulation();
// Size of the bitmap
Point2I textureSize(mBitmap->getWidth(), mBitmap->getHeight());
Point2I textureSize(getBitmap()->getWidth(), getBitmap()->getHeight());
// Reduce the size with the margin (if set)
textureSize.x = textureSize.x - (mBitmapMargin * 2);
@ -332,7 +329,7 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
iconRect.point.y = offset.y + ( getHeight() - textureSize.y ) / 2;
}
drawer->drawBitmapStretch(mBitmap, iconRect );
drawer->drawBitmapStretch(getBitmap(), iconRect );
}
else
@ -366,7 +363,7 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
iconRect.point.y = offset.y + (getHeight() / 2) - (iconRect.extent.y / 2) + mButtonMargin.y;
}
drawer->drawBitmapStretch( mBitmap, iconRect );
drawer->drawBitmapStretch(getBitmap(), iconRect );
}
}
@ -383,7 +380,7 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
if ( mTextLocation == TextLocRight )
{
Point2I start( mTextMargin, ( getHeight() - mProfile->mFont->getHeight() ) / 2 );
if (mBitmap && mIconLocation != IconLocNone )
if (mBitmapAsset.notNull() && mIconLocation != IconLocNone)
{
start.x = iconRect.extent.x + mButtonMargin.x + mTextMargin;
}
@ -403,7 +400,7 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
if ( mTextLocation == TextLocCenter )
{
Point2I start;
if (mBitmap && mIconLocation == IconLocLeft )
if (mBitmapAsset.notNull() && mIconLocation == IconLocLeft )
{
start.set( ( getWidth() - textWidth - iconRect.extent.x ) / 2 + iconRect.extent.x,
( getHeight() - mProfile->mFont->getHeight() ) / 2 );
@ -468,4 +465,4 @@ void GuiIconButtonCtrl::renderBitmapArray(RectI &bounds, S32 state)
}
}
DEF_ASSET_BINDS(GuiIconButtonCtrl, Bitmap);
DEF_ASSET_BINDS_REFACTOR(GuiIconButtonCtrl, Bitmap)

View file

@ -42,8 +42,7 @@ private:
protected:
DECLARE_IMAGEASSET(GuiIconButtonCtrl, Bitmap, onImageChanged, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiIconButtonCtrl, Bitmap);
DECLARE_IMAGEASSET(GuiIconButtonCtrl, Bitmap, GFXDefaultGUIProfile)
S32 mIconLocation;
S32 mTextLocation;

View file

@ -43,10 +43,6 @@ ConsoleDocClass( GuiToolboxButtonCtrl,
//-------------------------------------
GuiToolboxButtonCtrl::GuiToolboxButtonCtrl()
{
INIT_ASSET(NormalBitmap);
INIT_ASSET(LoweredBitmap);
INIT_ASSET(HoverBitmap);
setMinExtent(Point2I(16,16));
setExtent(48, 48);
mButtonType = ButtonTypeRadio;
@ -75,10 +71,6 @@ bool GuiToolboxButtonCtrl::onWake()
setActive( true );
setNormalBitmap( getNormalBitmap() );
setLoweredBitmap( getLoweredBitmap() );
setHoverBitmap( getHoverBitmap() );
return true;
}
@ -96,9 +88,9 @@ void GuiToolboxButtonCtrl::inspectPostApply()
// set it's extent to be exactly the size of the normal bitmap (if present)
Parent::inspectPostApply();
if ((getWidth() == 0) && (getHeight() == 0) && mNormalBitmap)
if ((getWidth() == 0) && (getHeight() == 0) && mNormalBitmapAsset.notNull())
{
setExtent(mNormalBitmap->getWidth(), mNormalBitmap->getHeight());
setExtent(getNormalBitmap()->getWidth(), getNormalBitmap()->getHeight());
}
}
@ -144,15 +136,15 @@ void GuiToolboxButtonCtrl::onRender(Point2I offset, const RectI& updateRect)
{
RectI r(offset, getExtent());
if ( mDepressed || mStateOn )
renderStateRect( mLoweredBitmap , r );
renderStateRect( getLoweredBitmap(), r);
else if ( mHighlighted )
renderStateRect( mHoverBitmap , r );
renderStateRect( getHoverBitmap(), r);
}
// Now render the image
if( mNormalBitmap )
if( mNormalBitmapAsset.notNull() )
{
renderButton(mNormalBitmap, offset, updateRect );
renderButton(getNormalBitmap(), offset, updateRect );
return;
}
@ -168,7 +160,7 @@ void GuiToolboxButtonCtrl::onRender(Point2I offset, const RectI& updateRect)
}
void GuiToolboxButtonCtrl::renderStateRect( GFXTexHandle &texture, const RectI& rect )
void GuiToolboxButtonCtrl::renderStateRect( GFXTexHandle texture, const RectI& rect )
{
if (texture)
{
@ -179,7 +171,7 @@ void GuiToolboxButtonCtrl::renderStateRect( GFXTexHandle &texture, const RectI&
//------------------------------------------------------------------------------
void GuiToolboxButtonCtrl::renderButton(GFXTexHandle &texture, Point2I &offset, const RectI& updateRect)
void GuiToolboxButtonCtrl::renderButton(GFXTexHandle texture, Point2I &offset, const RectI& updateRect)
{
if (texture)
{
@ -194,6 +186,6 @@ void GuiToolboxButtonCtrl::renderButton(GFXTexHandle &texture, Point2I &offset,
}
}
DEF_ASSET_BINDS(GuiToolboxButtonCtrl, NormalBitmap);
DEF_ASSET_BINDS(GuiToolboxButtonCtrl, LoweredBitmap);
DEF_ASSET_BINDS(GuiToolboxButtonCtrl, HoverBitmap);
DEF_ASSET_BINDS_REFACTOR(GuiToolboxButtonCtrl, NormalBitmap)
DEF_ASSET_BINDS_REFACTOR(GuiToolboxButtonCtrl, LoweredBitmap)
DEF_ASSET_BINDS_REFACTOR(GuiToolboxButtonCtrl, HoverBitmap)

View file

@ -39,19 +39,12 @@ private:
protected:
DECLARE_IMAGEASSET(GuiToolboxButtonCtrl, NormalBitmap, onNormalImageChanged, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiToolboxButtonCtrl, NormalBitmap);
DECLARE_IMAGEASSET(GuiToolboxButtonCtrl, LoweredBitmap, onLoweredImageChanged, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiToolboxButtonCtrl, LoweredBitmap);
DECLARE_IMAGEASSET(GuiToolboxButtonCtrl, HoverBitmap, onHoverImageChanged, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiToolboxButtonCtrl, HoverBitmap);
DECLARE_IMAGEASSET(GuiToolboxButtonCtrl, NormalBitmap, GFXDefaultGUIProfile)
DECLARE_IMAGEASSET(GuiToolboxButtonCtrl, LoweredBitmap, GFXDefaultGUIProfile)
DECLARE_IMAGEASSET(GuiToolboxButtonCtrl, HoverBitmap, GFXDefaultGUIProfile)
void renderButton(GFXTexHandle &texture, Point2I &offset, const RectI& updateRect);
void renderStateRect( GFXTexHandle &texture, const RectI& rect );
void onNormalImageChanged() {}
void onLoweredImageChanged() {}
void onHoverImageChanged() {}
void renderButton(GFXTexHandle texture, Point2I &offset, const RectI& updateRect);
void renderStateRect( GFXTexHandle texture, const RectI& rect );
public:
DECLARE_CONOBJECT(GuiToolboxButtonCtrl);

View file

@ -277,7 +277,7 @@ void GuiFormCtrl::onRender(Point2I offset, const RectI &updateRect)
Point2I barOffset(barStart, barTop);
// Draw the start of the bar...
GFX->getDrawUtil()->drawBitmapStretchSR(mProfile->getBitmapResource(),RectI(barOffset, mProfile->mBitmapArrayRects[2].extent), mProfile->mBitmapArrayRects[2] );
GFX->getDrawUtil()->drawBitmapStretchSR(mProfile->getBitmap(),RectI(barOffset, mProfile->mBitmapArrayRects[2].extent), mProfile->mBitmapArrayRects[2] );
// Now draw the middle...
barOffset.x += mProfile->mBitmapArrayRects[2].extent.x;
@ -291,7 +291,7 @@ void GuiFormCtrl::onRender(Point2I offset, const RectI &updateRect)
foo.inset(1,0);
GFX->getDrawUtil()->drawBitmapStretchSR(
mProfile->getBitmapResource(),
mProfile->getBitmap(),
RectI(barOffset, Point2I(barMiddleSize, mProfile->mBitmapArrayRects[3].extent.y)),
foo
);
@ -300,7 +300,7 @@ void GuiFormCtrl::onRender(Point2I offset, const RectI &updateRect)
// And the end
barOffset.x += barMiddleSize;
GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->getBitmapResource(), RectI(barOffset, mProfile->mBitmapArrayRects[4].extent),
GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->getBitmap(), RectI(barOffset, mProfile->mBitmapArrayRects[4].extent),
mProfile->mBitmapArrayRects[4]);
GFX->getDrawUtil()->setBitmapModulation((mMouseOver ? mProfile->mFontColorHL : mProfile->mFontColor));

View file

@ -193,7 +193,7 @@ void GuiPaneControl::onRender(Point2I offset, const RectI &updateRect)
GFX->getDrawUtil()->clearBitmapModulation();
GFX->getDrawUtil()->drawBitmapStretchSR(
mProfile->getBitmapResource(),
mProfile->getBitmap(),
RectI(offset, mProfile->mBitmapArrayRects[idx].extent),
mProfile->mBitmapArrayRects[idx]
);
@ -226,7 +226,7 @@ void GuiPaneControl::onRender(Point2I offset, const RectI &updateRect)
// Draw the start of the bar...
GFX->getDrawUtil()->drawBitmapStretchSR(
mProfile->getBitmapResource(),
mProfile->getBitmap(),
RectI(barOffset, mProfile->mBitmapArrayRects[2].extent),
mProfile->mBitmapArrayRects[2]
);
@ -243,7 +243,7 @@ void GuiPaneControl::onRender(Point2I offset, const RectI &updateRect)
foo.inset(1,0);
GFX->getDrawUtil()->drawBitmapStretchSR(
mProfile->getBitmapResource(),
mProfile->getBitmap(),
RectI(barOffset, Point2I(barMiddleSize, mProfile->mBitmapArrayRects[3].extent.y)),
foo
);
@ -253,7 +253,7 @@ void GuiPaneControl::onRender(Point2I offset, const RectI &updateRect)
barOffset.x += barMiddleSize;
GFX->getDrawUtil()->drawBitmapStretchSR(
mProfile->getBitmapResource(),
mProfile->getBitmap(),
RectI(barOffset, mProfile->mBitmapArrayRects[4].extent),
mProfile->mBitmapArrayRects[4]
);

View file

@ -148,7 +148,7 @@ bool GuiScrollCtrl::onWake()
if (! Parent::onWake())
return false;
mTextureObject = mProfile->getBitmapResource();
mTextureObject = mProfile->getBitmap();
if (mTextureObject && (mProfile->constructBitmapArray() >= (U32)BmpStates * (U32)BmpCount))
{
mBitmapBounds = mProfile->mBitmapArrayRects.address();

View file

@ -696,7 +696,7 @@ bool GuiWindowCtrl::onWake()
return false;
}
mTextureObject = mProfile->getBitmapResource();
mTextureObject = mProfile->getBitmap();
mBitmapBounds = mProfile->mBitmapArrayRects.address();
S32 buttonHeight = mBitmapBounds[(U32)BmpStates * (U32)BmpClose].extent.y;

View file

@ -132,7 +132,7 @@ bool GuiBitmapBorderCtrl::onWake()
//get the texture for the close, minimize, and maximize buttons
mBitmapBounds = NULL;
mTextureObject = mProfile->getBitmapResource();
mTextureObject = mProfile->getBitmap();
if( mProfile->constructBitmapArray() >= NumBitmaps )
mBitmapBounds = mProfile->mBitmapArrayRects.address();
else

View file

@ -34,15 +34,15 @@
IMPLEMENT_CONOBJECT(GuiBitmapCtrl);
ConsoleDocClass( GuiBitmapCtrl,
ConsoleDocClass(GuiBitmapCtrl,
"@brief A gui control that is used to display an image.\n\n"
"The image is stretched to the constraints of the control by default. However, the control can also\n"
"tile the image as well.\n\n"
"The image itself is stored inside the GuiBitmapCtrl::bitmap field. The boolean value that decides\n"
"whether the image is stretched or tiled is stored inside the GuiBitmapCtrl::wrap field.\n"
"@tsexample\n"
"// Create a tiling GuiBitmapCtrl that displays \"myImage.png\"\n"
"%bitmapCtrl = new GuiBitmapCtrl()\n"
@ -51,45 +51,30 @@ ConsoleDocClass( GuiBitmapCtrl,
" wrap = \"true\";\n"
"};\n"
"@endtsexample\n\n"
"@ingroup GuiControls"
);
GuiBitmapCtrl::GuiBitmapCtrl(void)
: mStartPoint( 0, 0 ),
: mStartPoint(0, 0),
mColor(ColorI::WHITE),
mAngle(0),
mWrap( false )
mWrap(false),
mBitmap(NULL),
mBitmapName(StringTable->EmptyString())
{
INIT_ASSET(Bitmap);
}
bool GuiBitmapCtrl::setBitmapName( void *object, const char *index, const char *data )
{
// Prior to this, you couldn't do bitmap.bitmap = "foo.jpg" and have it work.
// With protected console types you can now call the setBitmap function and
// make it load the image.
static_cast<GuiBitmapCtrl *>( object )->setBitmap( data );
// Return false because the setBitmap method will assign 'mBitmapName' to the
// argument we are specifying in the call.
return false;
}
void GuiBitmapCtrl::initPersistFields()
{
docsURL;
addGroup( "Bitmap" );
addGroup("Bitmap");
addField("Bitmap", TypeImageFilename, Offset(mBitmapName, GuiBitmapCtrl), assetDoc(Bitmap, docs), AbstractClassRep::FIELD_HideInInspectors);
addField("BitmapAsset", TypeImageAssetId, Offset(mBitmapAssetId, GuiBitmapCtrl), assetDoc(Bitmap, asset docs.));
INITPERSISTFIELD_IMAGEASSET(Bitmap, GuiBitmapCtrl, "The bitmap to render in this BitmapCtrl.")
addField("color", TypeColorI, Offset(mColor, GuiBitmapCtrl),"color mul");
addField( "wrap", TypeBool, Offset( mWrap, GuiBitmapCtrl ),
"If true, the bitmap is tiled inside the control rather than stretched to fit." );
addFieldV("angle", TypeRangedF32, Offset(mAngle, GuiBitmapCtrl), &CommonValidators::DegreeRange, "rotation");
addField("color", TypeColorI, Offset(mColor, GuiBitmapCtrl), "color mul");
addField("wrap", TypeBool, Offset(mWrap, GuiBitmapCtrl), "If true, the bitmap is tiled inside the control rather than stretched to fit.");
addFieldV("angle", TypeRangedF32, Offset(mAngle, GuiBitmapCtrl), &CommonValidators::DegreeRange, "rotation");
endGroup( "Bitmap" );
Parent::initPersistFields();
@ -97,55 +82,53 @@ void GuiBitmapCtrl::initPersistFields()
bool GuiBitmapCtrl::onWake()
{
if (! Parent::onWake())
if (!Parent::onWake())
return false;
setActive(true);
if (mBitmapName != StringTable->insert("texhandle"))
setBitmap(getBitmap());
return true;
}
void GuiBitmapCtrl::onSleep()
{
if ( mBitmapName != StringTable->insert("texhandle") )
mBitmap = NULL;
Parent::onSleep();
}
//-------------------------------------
void GuiBitmapCtrl::inspectPostApply()
{
//This is a little bit of a 'special case' handling for this class
//Because we don't do the normal protectedField setup for the bitmapName/bitmapAsset fields
//which would automatically update the internal values and bound content, we'll do it here manually
//to ensure it's updated before we force a refresh, which would thrash the new values
if (mBitmapName != StringTable->insert("texhandle"))
{
_setBitmap(mBitmapAssetId);
}
else
{
setBitmap(getBitmap());
}
// if the extent is set to (0,0) in the gui editor and appy hit, this control will
// set it's extent to be exactly the size of the bitmap (if present)
Parent::inspectPostApply();
if (!mWrap && (getExtent().x == 0) && (getExtent().y == 0) && mBitmap)
if (!mWrap && (getExtent().x == 0) && (getExtent().y == 0) && mBitmapAsset.notNull())
{
setExtent( mBitmap->getWidth(), mBitmap->getHeight());
setExtent(mBitmap->getWidth(), mBitmap->getHeight());
}
}
void GuiBitmapCtrl::setBitmap( const char *name, bool resize )
void GuiBitmapCtrl::setBitmap(const char* name, bool resize)
{
_setBitmap(StringTable->insert(name));
if (mBitmap && resize)
// coming in here we are probably getting a filename.
if (AssetDatabase.isDeclaredAsset(name))
{
_setBitmap(StringTable->insert(name));
}
else
{
StringTableEntry assetId = ImageAsset::getAssetIdByFilename(StringTable->insert(name));
if (assetId != StringTable->EmptyString())
_setBitmap(assetId);
else
return;
}
mBitmap = mBitmapAsset->getTexture(&GFXDefaultGUIProfile);
if (mBitmapAsset.notNull() && resize)
{
setExtent(mBitmap->getWidth(), mBitmap->getHeight());
updateSizing();
}
@ -153,15 +136,6 @@ void GuiBitmapCtrl::setBitmap( const char *name, bool resize )
setUpdate();
}
void GuiBitmapCtrl::updateSizing()
{
if(!getParent())
return;
// updates our bounds according to our horizSizing and verSizing rules
RectI fakeBounds( getPosition(), getParent()->getExtent());
parentResized( fakeBounds, fakeBounds);
}
void GuiBitmapCtrl::setBitmapHandle(GFXTexHandle handle, bool resize)
{
mBitmap = handle;
@ -169,46 +143,58 @@ void GuiBitmapCtrl::setBitmapHandle(GFXTexHandle handle, bool resize)
mBitmapName = StringTable->insert("texhandle");
// Resize the control to fit the bitmap
if (resize)
if (resize)
{
setExtent(mBitmap->getWidth(), mBitmap->getHeight());
updateSizing();
}
}
void GuiBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
void GuiBitmapCtrl::updateSizing()
{
if (!getParent())
return;
// updates our bounds according to our horizSizing and verSizing rules
RectI fakeBounds(getPosition(), getParent()->getExtent());
parentResized(fakeBounds, fakeBounds);
}
void GuiBitmapCtrl::onRender(Point2I offset, const RectI& updateRect)
{
if (mBitmap.isNull() && mBitmapAsset.notNull())
mBitmap = getBitmap();
if (mBitmap)
{
GFX->getDrawUtil()->clearBitmapModulation();
GFX->getDrawUtil()->setBitmapModulation(mColor);
if(mWrap)
{
if (mWrap)
{
// We manually draw each repeat because non power of two textures will
// not tile correctly when rendered with GFX->drawBitmapTile(). The non POT
// bitmap will be padded by the hardware, and we'll see lots of slack
// in the texture. So... lets do what we must: draw each repeat by itself:
GFXTextureObject* texture = mBitmap;
RectI srcRegion;
RectI dstRegion;
F32 xdone = ((F32)getExtent().x/(F32)texture->mBitmapSize.x)+1;
F32 ydone = ((F32)getExtent().y/(F32)texture->mBitmapSize.y)+1;
GFXTextureObject* texture = mBitmap;
RectI srcRegion;
RectI dstRegion;
F32 xdone = ((F32)getExtent().x / (F32)texture->mBitmapSize.x) + 1;
F32 ydone = ((F32)getExtent().y / (F32)texture->mBitmapSize.y) + 1;
S32 xshift = mStartPoint.x%texture->mBitmapSize.x;
S32 yshift = mStartPoint.y%texture->mBitmapSize.y;
for(S32 y = 0; y < ydone; ++y)
for(S32 x = 0; x < xdone; ++x)
{
srcRegion.set(0,0,texture->mBitmapSize.x,texture->mBitmapSize.y);
dstRegion.set( ((texture->mBitmapSize.x*x)+offset.x)-xshift,
((texture->mBitmapSize.y*y)+offset.y)-yshift,
texture->mBitmapSize.x,
texture->mBitmapSize.y);
S32 xshift = mStartPoint.x % texture->mBitmapSize.x;
S32 yshift = mStartPoint.y % texture->mBitmapSize.y;
for (S32 y = 0; y < ydone; ++y)
for (S32 x = 0; x < xdone; ++x)
{
srcRegion.set(0, 0, texture->mBitmapSize.x, texture->mBitmapSize.y);
dstRegion.set(((texture->mBitmapSize.x * x) + offset.x) - xshift,
((texture->mBitmapSize.y * y) + offset.y) - yshift,
texture->mBitmapSize.x,
texture->mBitmapSize.y);
GFX->getDrawUtil()->drawBitmapStretchSR(texture, dstRegion, srcRegion, GFXBitmapFlip_None, GFXTextureFilterLinear, mAngle);
}
}
}
else
}
else
{
RectI rect(offset, getExtent());
GFX->getDrawUtil()->drawBitmapStretch(mBitmap, rect, GFXBitmapFlip_None, GFXTextureFilterLinear, false, mAngle);
@ -226,21 +212,21 @@ void GuiBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
void GuiBitmapCtrl::setValue(S32 x, S32 y)
{
if (mBitmap)
if (mBitmapAsset.notNull())
{
x += mBitmap->getWidth() / 2;
y += mBitmap->getHeight() / 2;
}
while (x < 0)
x += 256;
mStartPoint.x = x % 256;
x += mBitmapAsset->getTextureBitmapWidth() / 2;
y += mBitmapAsset->getTextureBitmapHeight() / 2;
}
while (x < 0)
x += 256;
mStartPoint.x = x % 256;
while (y < 0)
y += 256;
mStartPoint.y = y % 256;
while (y < 0)
y += 256;
mStartPoint.y = y % 256;
}
DefineEngineMethod( GuiBitmapCtrl, setValue, void, ( S32 x, S32 y ),,
DefineEngineMethod(GuiBitmapCtrl, setValue, void, (S32 x, S32 y), ,
"Set the offset of the bitmap within the control.\n"
"@param x The x-axis offset of the image.\n"
"@param y The y-axis offset of the image.\n")
@ -257,7 +243,7 @@ static ConsoleDocFragment _sGuiBitmapCtrlSetBitmap1(
"@param filename The filename of the image.\n"
"@param resize Optional parameter. If true, the GUI will resize to fit the image.",
"GuiBitmapCtrl", // The class to place the method in; use NULL for functions.
"void setBitmap( String filename, bool resize );" ); // The definition string.
"void setBitmap( String filename, bool resize );"); // The definition string.
static ConsoleDocFragment _sGuiBitmapCtrlSetBitmap2(
"@brief Assign an image to the control.\n\n"
@ -265,42 +251,42 @@ static ConsoleDocFragment _sGuiBitmapCtrlSetBitmap2(
"@param filename The filename of the image.\n"
"@param resize A boolean value that decides whether the ctrl refreshes or not.",
"GuiBitmapCtrl", // The class to place the method in; use NULL for functions.
"void setBitmap( String filename );" ); // The definition string.
"void setBitmap( String filename );"); // The definition string.
//"Set the bitmap displayed in the control. Note that it is limited in size, to 256x256."
DefineEngineMethod( GuiBitmapCtrl, setBitmap, void, ( const char * fileRoot, bool resize), ( false),
DefineEngineMethod(GuiBitmapCtrl, setBitmap, void, (const char* fileRoot, bool resize), (false),
"( String filename | String filename, bool resize ) Assign an image to the control.\n\n"
"@hide" )
"@hide")
{
char filename[1024];
Con::expandScriptFilename(filename, sizeof(filename), fileRoot);
object->setBitmap(filename, resize );
object->setBitmap(filename, resize);
}
DefineEngineMethod(GuiBitmapCtrl, getBitmap, const char*, (),,
DefineEngineMethod(GuiBitmapCtrl, getBitmap, const char*, (), ,
"Gets the current bitmap set for this control.\n\n"
"@hide")
{
return object->getBitmap();
return object->_getBitmap();
}
DefineEngineMethod( GuiBitmapCtrl, setNamedTexture, bool, (String namedtexture),,
DefineEngineMethod(GuiBitmapCtrl, setNamedTexture, bool, (String namedtexture), ,
"@brief Set a texture as the image.\n\n"
"@param namedtexture The name of the texture (NamedTexTarget).\n"
"@return true if the texture exists." )
"@return true if the texture exists.")
{
GFXTexHandle theTex;
NamedTexTarget *namedTarget = NULL;
NamedTexTarget* namedTarget = NULL;
namedTarget = NamedTexTarget::find(namedtexture.c_str());
if ( namedTarget )
if (namedTarget)
{
theTex = namedTarget->getTexture( 0 );
theTex = namedTarget->getTexture(0);
}
if ( theTex.isValid() )
if (theTex.isValid())
{
object->setBitmapHandle( theTex , false );
object->setBitmapHandle(theTex, false);
return true; //a new texture was set correctly
}
return false; //we couldn't change the texture

View file

@ -31,51 +31,47 @@
/// Renders a bitmap.
class GuiBitmapCtrl : public GuiControl
{
public:
typedef GuiControl Parent;
public:
protected:
/// Name of the bitmap file. If this is 'texhandle' the bitmap is not loaded
/// from a file but rather set explicitly on the control.
DECLARE_IMAGEASSET(GuiBitmapCtrl, Bitmap, onImageChanged, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiBitmapCtrl, Bitmap);
Point2I mStartPoint;
ColorI mColor;
F32 mAngle;
typedef GuiControl Parent;
/// If true, bitmap tiles inside control. Otherwise stretches.
bool mWrap;
protected:
static bool setBitmapName( void *object, const char *index, const char *data );
static const char *getBitmapName( void *obj, const char *data );
/// Name of the bitmap file. If this is 'texhandle' the bitmap is not loaded
/// from a file but rather set explicitly on the control.
DECLARE_IMAGEASSET(GuiBitmapCtrl, Bitmap, GFXDefaultGUIProfile)
void onImageChanged() {}
Point2I mStartPoint;
ColorI mColor;
F32 mAngle;
public:
GuiBitmapCtrl();
static void initPersistFields();
/// If true, bitmap tiles inside control. Otherwise stretches.
bool mWrap;
void setBitmap(const char *name,bool resize = false);
void setBitmapHandle(GFXTexHandle handle, bool resize = false);
public:
GFXTexHandle mBitmap;
StringTableEntry mBitmapName;
// GuiControl.
bool onWake() override;
void onSleep() override;
void inspectPostApply() override;
GuiBitmapCtrl();
static void initPersistFields();
void updateSizing();
// GuiControl.
bool onWake() override;
void onSleep() override;
void inspectPostApply() override;
void onRender(Point2I offset, const RectI &updateRect) override;
void setValue(S32 x, S32 y);
void setBitmap(const char* name, bool resize = true);
void setBitmapHandle(GFXTexHandle handle, bool resize = false);
DECLARE_CONOBJECT( GuiBitmapCtrl );
DECLARE_CATEGORY( "Gui Images" );
DECLARE_DESCRIPTION( "A control that displays a single, static image from a file.n"
"The bitmap can either be tiled or stretched inside the control." );
void updateSizing();
void onRender(Point2I offset, const RectI& updateRect) override;
void setValue(S32 x, S32 y);
DECLARE_CONOBJECT(GuiBitmapCtrl);
DECLARE_CATEGORY("Gui Images");
DECLARE_DESCRIPTION("A control that displays a single, static image from a file.n"
"The bitmap can either be tiled or stretched inside the control.");
};
#endif

View file

@ -206,7 +206,7 @@ void GuiGameListMenuCtrl::onRenderListOption(Row* row, Point2I currentOffset)
arrowOffset.y = currentOffset.y + arrowOffsetY;
drawer->clearBitmapModulation();
drawer->drawBitmapStretchSR(profile->getBitmapResource(), RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex));
drawer->drawBitmapStretchSR(profile->getBitmap(), RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex));
// render the right arrow
bool arrowOnR = (isRowSelected || isRowHighlighted) && (row->mWrapOptions || (row->mSelectedOption < row->mOptions.size() - 1));
@ -215,7 +215,7 @@ void GuiGameListMenuCtrl::onRenderListOption(Row* row, Point2I currentOffset)
arrowOffset.y = currentOffset.y + arrowOffsetY;
drawer->clearBitmapModulation();
drawer->drawBitmapStretchSR(profile->getBitmapResource(), RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex));
drawer->drawBitmapStretchSR(profile->getBitmap(), RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex));
}
// get the appropriate font color
@ -1759,7 +1759,7 @@ bool GuiGameListMenuProfile::onAdd()
// We can't call enforceConstraints() here because incRefCount initializes
// some of the things to enforce. Do a basic sanity check here instead.
U32 assetStatus = ImageAsset::getAssetErrCode(mBitmapAsset);
U32 assetStatus = ImageAsset::getAssetErrCode(getBitmapAsset());
if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback)
{
Con::errorf( "GuiGameListMenuProfile: %s can't be created without a bitmap. Please add a 'Bitmap' property to the object definition.", getName() );

View file

@ -111,7 +111,7 @@ void GuiGameListOptionsCtrl::onRender(Point2I offset, const RectI &updateRect)
arrowOffset.y = currentOffset.y + arrowOffsetY;
drawer->clearBitmapModulation();
drawer->drawBitmapStretchSR(profile->getBitmapResource(), RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex));
drawer->drawBitmapStretchSR(profile->getBitmap(), RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex));
// render the right arrow
bool arrowOnR = (isRowSelected || isRowHighlighted) && (myRow->mWrapOptions || (myRow->mSelectedOption < myRow->mOptions.size() - 1));
@ -120,7 +120,7 @@ void GuiGameListOptionsCtrl::onRender(Point2I offset, const RectI &updateRect)
arrowOffset.y = currentOffset.y + arrowOffsetY;
drawer->clearBitmapModulation();
drawer->drawBitmapStretchSR(profile->getBitmapResource(), RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex));
drawer->drawBitmapStretchSR(profile->getBitmap(), RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex));
}
// get the appropriate font color

View file

@ -60,10 +60,6 @@ GuiGameSettingsCtrl::GuiGameSettingsCtrl() :
mCallbackOnB = mCallbackOnA;
mCallbackOnX = mCallbackOnA;
mCallbackOnY = mCallbackOnA;
INIT_ASSET(KeybindBitmap);
INIT_ASSET(PreviousBitmap);
INIT_ASSET(NextBitmap);
}
GuiGameSettingsCtrl::~GuiGameSettingsCtrl()
@ -194,7 +190,7 @@ void GuiGameSettingsCtrl::onRenderListOption(Point2I currentOffset)
arrowOffset.y = currentOffset.y + arrowOffsetY;
drawer->clearBitmapModulation();
drawer->drawBitmapStretch(mPreviousBitmap, RectI(arrowOffset, Point2I(mArrowSize, mArrowSize)), GFXBitmapFlip_None, GFXTextureFilterLinear, false);
drawer->drawBitmapStretch(getPreviousBitmap(), RectI(arrowOffset, Point2I(mArrowSize, mArrowSize)), GFXBitmapFlip_None, GFXTextureFilterLinear, false);
}
else
{
@ -215,7 +211,7 @@ void GuiGameSettingsCtrl::onRenderListOption(Point2I currentOffset)
arrowOffset.y = currentOffset.y + arrowOffsetY;
drawer->clearBitmapModulation();
drawer->drawBitmapStretch(mNextBitmap, RectI(arrowOffset, Point2I(mArrowSize, mArrowSize)), GFXBitmapFlip_None, GFXTextureFilterLinear, false);
drawer->drawBitmapStretch(getNextBitmap(), RectI(arrowOffset, Point2I(mArrowSize, mArrowSize)), GFXBitmapFlip_None, GFXTextureFilterLinear, false);
}
else
{
@ -377,7 +373,7 @@ void GuiGameSettingsCtrl::onRenderKeybindOption(Point2I currentOffset)
{
RectI rect(button, buttonSize);
drawer->clearBitmapModulation();
drawer->drawBitmapStretch(mKeybindBitmap, rect, GFXBitmapFlip_None, GFXTextureFilterLinear, false);
drawer->drawBitmapStretch(getKeybindBitmap(), rect, GFXBitmapFlip_None, GFXTextureFilterLinear, false);
}
//drawer->drawRectFill(button, ColorI::BLUE);
@ -455,22 +451,11 @@ bool GuiGameSettingsCtrl::onWake()
if( !Parent::onWake() )
return false;
_setNextBitmap(getNextBitmap());
_setPreviousBitmap(getPreviousBitmap());
_setKeybindBitmap(getKeybindBitmap());
return true;
}
void GuiGameSettingsCtrl::onSleep()
{
if (mNextBitmapAsset.notNull())
mNextBitmap = NULL;
if (mPreviousBitmapAsset.notNull())
mPreviousBitmap = NULL;
if (mKeybindBitmapAsset.notNull())
mKeybindBitmap = NULL;
Parent::onSleep();
}

View file

@ -72,14 +72,9 @@ protected:
Point2F mRange; ///< When working as a slider, this sets our min/max range
//Keybind option
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, KeybindBitmap, changeBitmap, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiGameSettingsCtrl, KeybindBitmap);
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, PreviousBitmap, changeBitmap, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiGameSettingsCtrl, PreviousBitmap);
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, NextBitmap, changeBitmap, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiGameSettingsCtrl, NextBitmap);
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, KeybindBitmap, GFXDefaultGUIProfile)
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, PreviousBitmap, GFXDefaultGUIProfile)
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, NextBitmap, GFXDefaultGUIProfile)
S32 mArrowSize;
S32 mColumnSplit; //Padding between the leftmost edge of the control, and the left side of the 'option'.
@ -89,8 +84,6 @@ protected:
bool mSelected;
public:
void changeBitmap() {}
/// Sets the control as selected . Only controls that are enabled can be selected.
virtual void setSelected();

View file

@ -278,9 +278,6 @@ GuiPopUpMenuCtrl::GuiPopUpMenuCtrl(void)
mBackgroundCancel = false; // Added
mReverseTextList = false; // Added - Don't reverse text list if displaying up
INIT_IMAGEASSET_ARRAY(Bitmap, GFXDefaultGUIProfile, 0);
INIT_IMAGEASSET_ARRAY(Bitmap, GFXDefaultGUIProfile, 1);
mBitmapBounds.set(16, 16); // Added
mIdMax = -1;
mBackground = NULL;
@ -302,8 +299,7 @@ void GuiPopUpMenuCtrl::initPersistFields(void)
addField("sbUsesNAColor", TypeBool, Offset(mRenderScrollInNA, GuiPopUpMenuCtrl));
addField("reverseTextList", TypeBool, Offset(mReverseTextList, GuiPopUpMenuCtrl));
addProtectedField("bitmap", TypeImageFilename, Offset(mBitmapName, GuiPopUpMenuCtrl), _setBitmaps, defaultProtectedGetFn, "");
addProtectedField("bitmapAsset", TypeImageAssetId, Offset(mBitmapAssetId, GuiPopUpMenuCtrl), _setBitmaps, defaultProtectedGetFn, "");
addProtectedField("BitmapAsset", TypeImageAssetPtr, Offset(mBitmapAsset, GuiPopUpMenuCtrl), _setBitmaps, &defaultProtectedGetFn, "@brief ""Bitmap"" ""asset \"\".");
addField("bitmapBounds", TypePoint2I, Offset(mBitmapBounds, GuiPopUpMenuCtrl));
@ -473,9 +469,6 @@ bool GuiPopUpMenuCtrl::onWake()
if ( !Parent::onWake() )
return false;
// Set the bitmap for the popup.
setBitmap(getBitmap(Normal));
// Now update the Form Control's bitmap array, and possibly the child's too
mProfile->constructBitmapArray();
@ -592,8 +585,8 @@ void GuiPopUpMenuCtrl::setBitmap( const char *name )
dStrcpy(p, "_d", pLen);
_setBitmap((StringTableEntry)buffer, Depressed);
if ( !mBitmap[Depressed] )
mBitmap[Depressed] = mBitmap[Normal];
if ( mBitmapAsset[Depressed].isNull() )
mBitmapAsset[Depressed] = mBitmapAsset[Normal];
}
else
{
@ -898,17 +891,17 @@ void GuiPopUpMenuCtrl::onRender( Point2I offset, const RectI &updateRect )
}
// Draw a bitmap over the background?
if ( mBitmap[Depressed] )
if ( mBitmapAsset[Depressed].notNull() )
{
RectI rect(offset, mBitmapBounds);
drawUtil->clearBitmapModulation();
drawUtil->drawBitmapStretch( mBitmap[Depressed], rect );
drawUtil->drawBitmapStretch( getBitmap(Depressed), rect );
}
else if ( mBitmap[Normal] )
else if ( mBitmapAsset[Normal].notNull() )
{
RectI rect(offset, mBitmapBounds);
drawUtil->clearBitmapModulation();
drawUtil->drawBitmapStretch( mBitmap[Normal], rect );
drawUtil->drawBitmapStretch(getBitmap(Normal), rect );
}
// Do we render a bitmap border or lines?
@ -948,11 +941,11 @@ void GuiPopUpMenuCtrl::onRender( Point2I offset, const RectI &updateRect )
}
// Draw a bitmap over the background?
if ( mBitmap[Normal] )
if ( mBitmapAsset[Normal].notNull() )
{
RectI rect( offset, mBitmapBounds );
drawUtil->clearBitmapModulation();
drawUtil->drawBitmapStretch( mBitmap[Normal], rect );
drawUtil->drawBitmapStretch(getBitmap(Normal) , rect);
}
// Do we render a bitmap border or lines?
@ -984,11 +977,11 @@ void GuiPopUpMenuCtrl::onRender( Point2I offset, const RectI &updateRect )
}
// Draw a bitmap over the background?
if ( mBitmap[Normal] )
if (mBitmapAsset[Normal].notNull())
{
RectI rect(offset, mBitmapBounds);
drawUtil->clearBitmapModulation();
drawUtil->drawBitmapStretch( mBitmap[Normal], rect );
drawUtil->drawBitmapStretch( getBitmap(Normal), rect);
}
// Do we render a bitmap border or lines?

View file

@ -126,9 +126,8 @@ protected:
NumBitmapModes = 2
};
DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrl, Bitmap, NumBitmapModes, onBitmapChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(GuiPopUpMenuCtrl, Bitmap);
void onBitmapChanged() {}
DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrl, Bitmap, GFXDefaultGUIProfile, NumBitmapModes)
Point2I mBitmapBounds; // Added
S32 mIdMax;

View file

@ -330,9 +330,6 @@ GuiPopUpMenuCtrlEx::GuiPopUpMenuCtrlEx(void)
mBackgroundCancel = false; // Added
mReverseTextList = false; // Added - Don't reverse text list if displaying up
INIT_IMAGEASSET_ARRAY(Bitmap, GFXDefaultGUIProfile, Normal);
INIT_IMAGEASSET_ARRAY(Bitmap, GFXDefaultGUIProfile, Depressed);
mBitmapBounds.set(16, 16); // Added
mHotTrackItems = false;
mIdMax = -1;
@ -357,8 +354,7 @@ void GuiPopUpMenuCtrlEx::initPersistFields(void)
addField("sbUsesNAColor", TypeBool, Offset(mRenderScrollInNA, GuiPopUpMenuCtrlEx), "Deprecated" "@internal");
addField("reverseTextList", TypeBool, Offset(mReverseTextList, GuiPopUpMenuCtrlEx), "Reverses text list if popup extends up, instead of down");
addProtectedField("bitmap", TypeImageFilename, Offset(mBitmapName, GuiPopUpMenuCtrlEx), _setBitmaps, &defaultProtectedGetFn, "File name of bitmap to use");
addProtectedField("bitmapAsset", TypeImageAssetId, Offset(mBitmapAssetId, GuiPopUpMenuCtrlEx), _setBitmaps, &defaultProtectedGetFn, "Name of bitmap asset to use");
addProtectedField("BitmapAsset", TypeImageAssetPtr, Offset(mBitmapAsset, GuiPopUpMenuCtrlEx), _setBitmaps, &defaultProtectedGetFn, "@brief ""Bitmap"" ""asset \"Name of bitmap asset to use\".");
addField("bitmapBounds", TypePoint2I, Offset(mBitmapBounds, GuiPopUpMenuCtrlEx), "Boundaries of bitmap displayed");
addField("hotTrackCallback", TypeBool, Offset(mHotTrackItems, GuiPopUpMenuCtrlEx),
@ -369,14 +365,6 @@ void GuiPopUpMenuCtrlEx::initPersistFields(void)
Parent::initPersistFields();
}
bool GuiPopUpMenuCtrlEx::_setBitmaps(void* obj, const char* index, const char* data)
{
GuiPopUpMenuCtrlEx* object = static_cast<GuiPopUpMenuCtrlEx*>(obj);
object->setBitmap(data);
return true;
}
//------------------------------------------------------------------------------
ConsoleDocFragment _GuiPopUpMenuCtrlExAdd(
"@brief Adds an entry to the list\n\n"
@ -691,9 +679,6 @@ bool GuiPopUpMenuCtrlEx::onWake()
if ( !Parent::onWake() )
return false;
// Set the bitmap for the popup.
setBitmap(getBitmap(Normal));
// Now update the Form Control's bitmap array, and possibly the child's too
mProfile->constructBitmapArray();
@ -796,7 +781,15 @@ static S32 QSORT_CALLBACK idCompare(const void *a,const void *b)
GuiPopUpMenuCtrlEx::Entry *ea = (GuiPopUpMenuCtrlEx::Entry *) (a);
GuiPopUpMenuCtrlEx::Entry *eb = (GuiPopUpMenuCtrlEx::Entry *) (b);
return ( (ea->id < eb->id) ? -1 : ((ea->id > eb->id) ? 1 : 0) );
}
}
bool GuiPopUpMenuCtrlEx::_setBitmaps(void* obj, const char* index, const char* data)
{
GuiPopUpMenuCtrlEx* object = static_cast<GuiPopUpMenuCtrlEx*>(obj);
object->setBitmap(data);
return true;
}
//------------------------------------------------------------------------------
// Added
@ -819,8 +812,8 @@ void GuiPopUpMenuCtrlEx::setBitmap(const char *name)
dStrcpy(p, "_d", pLen);
_setBitmap((StringTableEntry)buffer, Depressed);
if (!mBitmap[Depressed])
mBitmap[Depressed] = mBitmap[Normal];
if (mBitmapAsset[Depressed].isNull())
mBitmapAsset[Depressed] = mBitmapAsset[Normal];
}
else
{
@ -1097,17 +1090,17 @@ void GuiPopUpMenuCtrlEx::onRender(Point2I offset, const RectI &updateRect)
}
// Draw a bitmap over the background?
if ( mBitmap[Depressed] )
if ( mBitmapAsset[Depressed].notNull() )
{
RectI rect(offset, mBitmapBounds);
drawUtil->clearBitmapModulation();
drawUtil->drawBitmapStretch(mBitmap[Depressed], rect );
drawUtil->drawBitmapStretch(getBitmap(Depressed), rect );
}
else if (mBitmap[Normal])
else if (mBitmapAsset[Normal].notNull())
{
RectI rect(offset, mBitmapBounds);
drawUtil->clearBitmapModulation();
drawUtil->drawBitmapStretch(mBitmap[Normal], rect );
drawUtil->drawBitmapStretch(getBitmap(Normal), rect );
}
// Do we render a bitmap border or lines?
@ -1141,11 +1134,11 @@ void GuiPopUpMenuCtrlEx::onRender(Point2I offset, const RectI &updateRect)
}
// Draw a bitmap over the background?
if (mBitmap[Normal])
if (mBitmapAsset[Normal].notNull())
{
RectI rect( offset, mBitmapBounds );
drawUtil->clearBitmapModulation();
drawUtil->drawBitmapStretch(mBitmap[Normal], rect );
drawUtil->drawBitmapStretch(getBitmap(Normal), rect );
}
// Do we render a bitmap border or lines?
@ -1171,11 +1164,11 @@ void GuiPopUpMenuCtrlEx::onRender(Point2I offset, const RectI &updateRect)
}
// Draw a bitmap over the background?
if (mBitmap[Normal])
if (mBitmapAsset[Normal].notNull())
{
RectI rect(offset, mBitmapBounds);
drawUtil->clearBitmapModulation();
drawUtil->drawBitmapStretch(mBitmap[Normal], rect );
drawUtil->drawBitmapStretch(getBitmap(Normal), rect );
}
// Do we render a bitmap border or lines?

View file

@ -131,9 +131,8 @@ class GuiPopUpMenuCtrlEx : public GuiTextCtrl
NumBitmapModes = 2
};
DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrlEx, Bitmap, NumBitmapModes, onBitmapChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(GuiPopUpMenuCtrlEx, Bitmap);
void onBitmapChanged() {}
DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrlEx, Bitmap, GFXDefaultGUIProfile, NumBitmapModes)
Point2I mBitmapBounds; // Added
S32 mIdMax;

View file

@ -432,9 +432,9 @@ void GuiSliderCtrl::onRender(Point2I offset, const RectI &updateRect)
drawUtil->clearBitmapModulation();
//left border
drawUtil->drawBitmapSR(mProfile->getBitmapResource(), Point2I(offset.x,offset.y), mBitmapBounds[SliderLineLeft]);
drawUtil->drawBitmapSR(mProfile->getBitmap(), Point2I(offset.x,offset.y), mBitmapBounds[SliderLineLeft]);
//right border
drawUtil->drawBitmapSR(mProfile->getBitmapResource(), Point2I(offset.x + getWidth() - mBitmapBounds[SliderLineRight].extent.x, offset.y), mBitmapBounds[SliderLineRight]);
drawUtil->drawBitmapSR(mProfile->getBitmap(), Point2I(offset.x + getWidth() - mBitmapBounds[SliderLineRight].extent.x, offset.y), mBitmapBounds[SliderLineRight]);
//draw our center piece to our slider control's border and stretch it
@ -448,11 +448,11 @@ void GuiSliderCtrl::onRender(Point2I offset, const RectI &updateRect)
stretchRect = mBitmapBounds[SliderLineCenter];
stretchRect.inset(1,0);
drawUtil->drawBitmapStretchSR(mProfile->getBitmapResource(), destRect, stretchRect);
drawUtil->drawBitmapStretchSR(mProfile->getBitmap(), destRect, stretchRect);
//draw our control slider button
thumb.point += pos;
drawUtil->drawBitmapSR(mProfile->getBitmapResource(),Point2I(thumb.point.x,offset.y ),mBitmapBounds[index]);
drawUtil->drawBitmapSR(mProfile->getBitmap(),Point2I(thumb.point.x,offset.y ),mBitmapBounds[index]);
}
else if (getWidth() >= getHeight())

View file

@ -3781,7 +3781,7 @@ void GuiTreeViewCtrl::onRenderCell(Point2I offset, Point2I cell, bool, bool )
if( ( bitmap >= 0 ) && ( bitmap < mProfile->mBitmapArrayRects.size() ) )
{
if( drawBitmap )
drawer->drawBitmapSR( mProfile->getBitmapResource(), drawRect.point, mProfile->mBitmapArrayRects[bitmap] );
drawer->drawBitmapSR( mProfile->getBitmap(), drawRect.point, mProfile->mBitmapArrayRects[bitmap] );
newOffset = mProfile->mBitmapArrayRects[bitmap].extent.x;
}

View file

@ -173,14 +173,14 @@ void renderBorder( const RectI &bounds, GuiControlProfile *profile )
// Draw all corners first.
//top left border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[BorderTopLeft]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[BorderTopLeft]);
//top right border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[BorderTopRight].extent.x,bounds.point.y),mBitmapBounds[BorderTopRight]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[BorderTopRight].extent.x,bounds.point.y),mBitmapBounds[BorderTopRight]);
//bottom left border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[BorderBottomLeft].extent.y),mBitmapBounds[BorderBottomLeft]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[BorderBottomLeft].extent.y),mBitmapBounds[BorderBottomLeft]);
//bottom right border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(
drawer->drawBitmapSR(profile->getBitmap(),Point2I(
bounds.point.x + bounds.extent.x - mBitmapBounds[BorderBottomRight].extent.x,
bounds.point.y + bounds.extent.y - mBitmapBounds[BorderBottomRight].extent.y),
mBitmapBounds[BorderBottomRight]);
@ -198,7 +198,7 @@ void renderBorder( const RectI &bounds, GuiControlProfile *profile )
stretchRect = mBitmapBounds[BorderTop];
stretchRect.inset(1,0);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//bottom line stretch
destRect.point.x = bounds.point.x + mBitmapBounds[BorderBottomLeft].extent.x;
destRect.extent.x = bounds.extent.x - mBitmapBounds[BorderBottomRight].extent.x - mBitmapBounds[BorderBottomLeft].extent.x;
@ -208,7 +208,7 @@ void renderBorder( const RectI &bounds, GuiControlProfile *profile )
stretchRect = mBitmapBounds[BorderBottom];
stretchRect.inset(1,0);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//left line stretch
destRect.point.x = bounds.point.x;
destRect.extent.x = mBitmapBounds[BorderLeft].extent.x;
@ -218,7 +218,7 @@ void renderBorder( const RectI &bounds, GuiControlProfile *profile )
stretchRect = mBitmapBounds[BorderLeft];
stretchRect.inset(0,1);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//right line stretch
destRect.point.x = bounds.point.x + bounds.extent.x - mBitmapBounds[BorderRight].extent.x;
destRect.extent.x = mBitmapBounds[BorderRight].extent.x;
@ -228,7 +228,7 @@ void renderBorder( const RectI &bounds, GuiControlProfile *profile )
stretchRect = mBitmapBounds[BorderRight];
stretchRect.inset(0,1);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
// End drawing sides and top stretched borders
break;
@ -288,14 +288,14 @@ void renderSizableBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier,
// Draw all corners first.
//top left border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderTopLeft]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderTopLeft]);
//top right border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderTopRight].extent.x,bounds.point.y),mBitmapBounds[borderTopRight]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderTopRight].extent.x,bounds.point.y),mBitmapBounds[borderTopRight]);
//bottom left border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomLeft].extent.y),mBitmapBounds[borderBottomLeft]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomLeft].extent.y),mBitmapBounds[borderBottomLeft]);
//bottom right border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(
drawer->drawBitmapSR(profile->getBitmap(),Point2I(
bounds.point.x + bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x,
bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomRight].extent.y),
mBitmapBounds[borderBottomRight]);
@ -313,7 +313,7 @@ void renderSizableBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier,
stretchRect = mBitmapBounds[borderTop];
stretchRect.inset(1,0);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//bottom line stretch
destRect.point.x = bounds.point.x + mBitmapBounds[borderBottomLeft].extent.x;
destRect.extent.x = bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x - mBitmapBounds[borderBottomLeft].extent.x;
@ -323,7 +323,7 @@ void renderSizableBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier,
stretchRect = mBitmapBounds[borderBottom];
stretchRect.inset(1,0);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//left line stretch
destRect.point.x = bounds.point.x;
destRect.extent.x = mBitmapBounds[borderLeft].extent.x;
@ -333,7 +333,7 @@ void renderSizableBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier,
stretchRect = mBitmapBounds[borderLeft];
stretchRect.inset(0,1);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//right line stretch
destRect.point.x = bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x;
destRect.extent.x = mBitmapBounds[borderRight].extent.x;
@ -343,7 +343,7 @@ void renderSizableBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier,
stretchRect = mBitmapBounds[borderRight];
stretchRect.inset(0,1);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//fill stretch
destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
@ -353,7 +353,7 @@ void renderSizableBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier,
stretchRect = mBitmapBounds[fill];
stretchRect.inset(1,1);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
// End drawing sides and top stretched borders
}
@ -388,14 +388,14 @@ void renderSizableBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex,
// Draw all corners first.
//top left border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderTopLeft]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderTopLeft]);
//top right border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderTopRight].extent.x,bounds.point.y),mBitmapBounds[borderTopRight]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderTopRight].extent.x,bounds.point.y),mBitmapBounds[borderTopRight]);
//bottom left border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomLeft].extent.y),mBitmapBounds[borderBottomLeft]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomLeft].extent.y),mBitmapBounds[borderBottomLeft]);
//bottom right border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(
drawer->drawBitmapSR(profile->getBitmap(),Point2I(
bounds.point.x + bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x,
bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomRight].extent.y),
mBitmapBounds[borderBottomRight]);
@ -413,7 +413,7 @@ void renderSizableBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex,
stretchRect = mBitmapBounds[borderTop];
stretchRect.inset(1,0);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//bottom line stretch
destRect.point.x = bounds.point.x + mBitmapBounds[borderBottomLeft].extent.x;
destRect.extent.x = bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x - mBitmapBounds[borderBottomLeft].extent.x;
@ -423,7 +423,7 @@ void renderSizableBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex,
stretchRect = mBitmapBounds[borderBottom];
stretchRect.inset(1,0);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//left line stretch
destRect.point.x = bounds.point.x;
destRect.extent.x = mBitmapBounds[borderLeft].extent.x;
@ -433,7 +433,7 @@ void renderSizableBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex,
stretchRect = mBitmapBounds[borderLeft];
stretchRect.inset(0,1);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//left line stretch
destRect.point.x = bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x;
destRect.extent.x = mBitmapBounds[borderRight].extent.x;
@ -443,7 +443,7 @@ void renderSizableBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex,
stretchRect = mBitmapBounds[borderRight];
stretchRect.inset(0,1);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
//fill stretch
destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
@ -453,7 +453,7 @@ void renderSizableBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex,
stretchRect = mBitmapBounds[fill];
stretchRect.inset(1,1);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
// End drawing sides and top stretched borders
}
@ -484,9 +484,9 @@ void renderFixedBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier, Gu
// Draw all corners first.
//left border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderLeft]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderLeft]);
//right border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x,bounds.point.y),mBitmapBounds[borderRight]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x,bounds.point.y),mBitmapBounds[borderRight]);
// End drawing corners
@ -501,7 +501,7 @@ void renderFixedBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier, Gu
stretchRect = mBitmapBounds[fill];
stretchRect.inset(1,0);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
// End drawing fill
}
@ -529,9 +529,9 @@ void renderFixedBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex, G
// Draw all corners first.
//left border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderLeft]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderLeft]);
//right border
drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x,bounds.point.y),mBitmapBounds[borderRight]);
drawer->drawBitmapSR(profile->getBitmap(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x,bounds.point.y),mBitmapBounds[borderRight]);
// End drawing corners
@ -546,7 +546,7 @@ void renderFixedBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex, G
stretchRect = mBitmapBounds[fill];
stretchRect.inset(1,0);
//draw it
drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
drawer->drawBitmapStretchSR(profile->getBitmap(),destRect,stretchRect);
// End drawing fill
}

View file

@ -79,8 +79,6 @@ GuiCursor::GuiCursor()
mHotSpot.set(0,0);
mRenderOffset.set(0.0f,0.0f);
mExtent.set(1,1);
INIT_ASSET(Bitmap);
}
GuiCursor::~GuiCursor()
@ -93,7 +91,6 @@ void GuiCursor::initPersistFields()
addField("hotSpot", TypePoint2I, Offset(mHotSpot, GuiCursor), "The location of the cursor's hot spot (which pixel carries the click).");
addField("renderOffset",TypePoint2F, Offset(mRenderOffset, GuiCursor), "Offset of the bitmap, where 0 signifies left edge of the bitmap, 1, the right. Similarly for the Y-component.");
addProtectedField("bitmapName", TypeImageFilename, Offset(mBitmapName, GuiCursor), _setBitmapData, &defaultProtectedGetFn, "File name of the bitmap for the cursor.");
INITPERSISTFIELD_IMAGEASSET(Bitmap, GuiCursor, "name of the bitmap for the cursor.");
Parent::initPersistFields();
}
@ -115,21 +112,21 @@ void GuiCursor::onRemove()
void GuiCursor::render(const Point2I &pos)
{
if (mBitmap)
if (mBitmapAsset.notNull())
{
mExtent.set(mBitmap->getWidth(), mBitmap->getHeight());
mExtent.set(getBitmap()->getWidth(), getBitmap()->getHeight());
}
// Render the cursor centered according to dimensions of texture
S32 texWidth = mBitmap.getWidth();
S32 texHeight = mBitmap.getHeight();
S32 texWidth = getBitmap()->getWidth();
S32 texHeight = getBitmap()->getHeight();
Point2I renderPos = pos;
renderPos.x -= (S32)( texWidth * mRenderOffset.x );
renderPos.y -= (S32)( texHeight * mRenderOffset.y );
GFX->getDrawUtil()->clearBitmapModulation();
GFX->getDrawUtil()->drawBitmap(mBitmap, renderPos);
GFX->getDrawUtil()->drawBitmap(getBitmap(), renderPos);
}
//------------------------------------------------------------------------------
@ -183,7 +180,7 @@ void GuiControlProfile::setBitmapHandle(GFXTexHandle handle)
{
mBitmap = handle;
_setBitmap(StringTable->insert("texhandle"));
mBitmapName = "texhandle";
}
bool GuiControlProfile::protectedSetBitmap( void *object, const char *index, const char *data )
@ -200,16 +197,17 @@ bool GuiControlProfile::protectedSetBitmap( void *object, const char *index, con
profile->mBitmapArrayRects.clear();
profile->mBitmap = nullptr;
if (profile->getBitmap() != StringTable->EmptyString())
if (profile->mBitmapName != StringTable->EmptyString())
{
if (profile->mBitmapAsset.notNull() && profile->getBitmap() != StringTable->insert("texHandle"))
if (profile->mBitmapAsset.notNull() && profile->mBitmapName != StringTable->insert("texHandle"))
{
profile->mBitmap.set(profile->mBitmapAsset->getImagePath(), profile->mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
profile->mBitmap = profile->getBitmap();
profile->mBitmapName = profile->mBitmapAsset->getImageFile();
}
//verify the bitmap
if (!profile->mBitmap)
Con::errorf("(%s) - Failed to load profile bitmap (%s)", profile->getName(), profile->getBitmap());
Con::errorf("(%s) - Failed to load profile bitmap (%s)", profile->getName(), profile->getBitmapAsset().getAssetId());
// If we've got a special border, make sure it's usable.
//if( profile->mBorder == -1 || profile->mBorder == -2 )
@ -275,7 +273,9 @@ GuiControlProfile::GuiControlProfile(void) :
mMouseOverSelected = false;
// bitmap members
INIT_ASSET(Bitmap);
mBitmap = NULL;
mBitmapName = StringTable->EmptyString();
mUseBitmapArray = false;
mChildrenProfileName = NULL;
@ -442,7 +442,7 @@ void GuiControlProfile::initPersistFields()
"Texture to use for rendering control.", AbstractClassRep::FIELD_HideInInspectors);
#endif
addProtectedField("bitmapAsset", TypeImageAssetId, Offset(mBitmapAssetId, GuiControlProfile),
addProtectedField("bitmapAsset", TypeImageAssetPtr, Offset(mBitmapAsset, GuiControlProfile),
&GuiControlProfile::protectedSetBitmap, &defaultProtectedGetFn,
"Texture to use for rendering control.");
@ -550,15 +550,12 @@ S32 GuiControlProfile::constructBitmapArray()
if( mBitmap.isNull() )
{
if (!_setBitmap(getBitmap()))
return 0;
if (getBitmap() != StringTable->EmptyString() && mBitmapName != StringTable->insert("texhandle"))
if (mBitmapAsset.notNull() && mBitmapName != StringTable->insert("texhandle"))
{
mBitmap.set(getBitmap(), mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
mBitmap = getBitmap();
}
if (getBitmap() == StringTable->EmptyString() || mBitmap.isNull())
if (mBitmapAsset.isNull() || mBitmap.isNull())
return 0;
}
@ -568,8 +565,8 @@ S32 GuiControlProfile::constructBitmapArray()
ColorI sepColor;
if ( !bmp || !bmp->getColor( 0, 0, sepColor ) )
{
Con::errorf("Failed to create bitmap array from %s for profile %s - couldn't ascertain seperator color!", getBitmap(), getName());
AssertFatal( false, avar("Failed to create bitmap array from %s for profile %s - couldn't ascertain seperator color!", getBitmap(), getName()));
Con::errorf("Failed to create bitmap array from %s for profile %s - couldn't ascertain seperator color!", getBitmapAsset().getAssetId(), getName());
AssertFatal( false, avar("Failed to create bitmap array from %s for profile %s - couldn't ascertain seperator color!", getBitmapAsset().getAssetId(), getName()));
return 0;
}
@ -644,17 +641,13 @@ void GuiControlProfile::incLoadCount()
if( mFont == NULL )
loadFont();
//
if (getBitmap() != StringTable->EmptyString())
if (mBitmapAsset.notNull() && mBitmapName != StringTable->insert("texHandle"))
{
if (mBitmapAsset.notNull() && getBitmap() != StringTable->insert("texHandle"))
{
mBitmap.set(mBitmapAsset->getImagePath(), mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
}
mBitmap = getBitmap();
//verify the bitmap
if (!mBitmap)
Con::errorf("(%s) - Failed to load profile bitmap (%s)", getName(), getBitmap());
Con::errorf("(%s) - Failed to load profile bitmap (%s)", getName(), getBitmapAsset().getAssetId());
constructBitmapArray();
}
@ -680,7 +673,7 @@ void GuiControlProfile::decLoadCount()
getId(), getClassName(), getName(), getInternalName() );
#endif
StringTableEntry bitmapName = getBitmap();
StringTableEntry bitmapName = getBitmapAsset().getAssetId();
if(bitmapName == StringTable->EmptyString() || bitmapName == StringTable->insert("texhandle"))
mBitmap = NULL;
}
@ -708,15 +701,15 @@ DefineEngineMethod( GuiControlProfile, getStringWidth, S32, (const char* string)
DefineEngineMethod(GuiControlProfile, getBitmap, const char*, (), , "get name")
{
return object->getBitmap();
return object->getBitmapAsset()->getImageFile();
}
DefineEngineMethod(GuiControlProfile, getBitmapAsset, const char*, (), , "")
{
return object->mBitmapAssetId;
return object->getBitmapAsset().getAssetId();
}
DefineEngineMethod(GuiControlProfile, setBitmap, bool, (const char* map), , "")
DefineEngineMethod(GuiControlProfile, setBitmap, void, (const char* map), , "")
{
return object->_setBitmap(StringTable->insert(map));
object->_setBitmap(StringTable->insert(map));
}
//-----------------------------------------------------------------------------

View file

@ -348,8 +348,7 @@ class GuiCursor : public SimObject
private:
typedef SimObject Parent;
DECLARE_IMAGEASSET(GuiCursor, Bitmap, onImageChanged, GFXGuiCursorProfile);
DECLARE_ASSET_SETGET(GuiCursor, Bitmap);
DECLARE_IMAGEASSET(GuiCursor, Bitmap, GFXGuiCursorProfile)
Point2I mHotSpot;
Point2F mRenderOffset;
@ -367,8 +366,6 @@ public:
bool onAdd(void) override;
void onRemove() override;
void render(const Point2I &pos);
void onImageChanged() {}
};
/// A GuiControlProfile is used by every GuiObject and is akin to a
@ -460,113 +457,11 @@ public:
///< Bitmap for the bitmap of the control
///
public:
GFXTexHandle mBitmap = NULL;
StringTableEntry mBitmapName;
StringTableEntry mBitmapAssetId;
AssetPtr<ImageAsset> mBitmapAsset;
GFXTextureProfile* mBitmapProfile = &GFXDefaultGUIProfile;
public:
const StringTableEntry getBitmapFile() const { return mBitmapName; }
void setBitmapFile(const FileName& _in) { mBitmapName = StringTable->insert(_in.c_str()); }
const AssetPtr<ImageAsset>& getBitmapAsset() const { return mBitmapAsset; }
void setBitmapAsset(const AssetPtr<ImageAsset>& _in) { mBitmapAsset = _in; }
bool _setBitmap(StringTableEntry _in)
{
if (mBitmapAssetId != _in || mBitmapName != _in)
{
if (mBitmapAsset.notNull())
{
mBitmapAsset->getChangedSignal().remove(this, &GuiControlProfile::onBitmapChanged);
}
if (_in == StringTable->EmptyString())
{
mBitmapName = StringTable->EmptyString();
mBitmapAssetId = StringTable->EmptyString();
mBitmapAsset = NULL;
mBitmap.free();
mBitmap = NULL;
return true;
}
else if (_in[0] == '$' || _in[0] == '#')
{
mBitmapName = _in;
mBitmapAssetId = StringTable->EmptyString();
mBitmapAsset = NULL;
mBitmap.free();
mBitmap = NULL;
return true;
}
if (AssetDatabase.isDeclaredAsset(_in))
{
mBitmapAssetId = _in;
U32 assetState = ImageAsset::getAssetById(mBitmapAssetId, &mBitmapAsset);
if (ImageAsset::Ok == assetState)
{
mBitmapName = StringTable->EmptyString();
}
}
else
{
StringTableEntry assetId = ImageAsset::getAssetIdByFilename(_in);
if (assetId != StringTable->EmptyString())
{
mBitmapAssetId = assetId;
if (ImageAsset::getAssetById(mBitmapAssetId, &mBitmapAsset) == ImageAsset::Ok)
{
mBitmapName = StringTable->EmptyString();
}
}
else
{
mBitmapName = _in;
mBitmapAssetId = StringTable->EmptyString();
mBitmapAsset = NULL;
}
}
}
if (getBitmap() != StringTable->EmptyString() && mBitmapName != StringTable->insert("texhandle"))
{
if (mBitmapAsset.notNull())
{
mBitmapAsset->getChangedSignal().notify(this, &GuiControlProfile::onBitmapChanged);
}
}
else
{
mBitmap.free();
mBitmap = NULL;
}
if (getBitmap() != StringTable->EmptyString() && mBitmapAsset.notNull() && mBitmapAsset->getStatus() != ImageAsset::Ok)
{
Con::errorf("%s(%s)::_set%s() - image asset failure \"%s\" due to [%s]", macroText(className), getName(), macroText(name), _in, ImageAsset::getAssetErrstrn(mBitmapAsset->getStatus()).c_str());
return false;
}
return true;
}
const StringTableEntry getBitmap() const
{
if (mBitmapAsset && (mBitmapAsset->getImageFileName() != StringTable->EmptyString()))
return Platform::makeRelativePathName(mBitmapAsset->getImagePath(), Platform::getMainDotCsDir());
else if (mBitmapAssetId != StringTable->EmptyString())
return mBitmapAssetId;
else if (mBitmapName != StringTable->EmptyString())
return StringTable->insert(Platform::makeRelativePathName(mBitmapName, Platform::getMainDotCsDir()));
else
return StringTable->EmptyString();
}
GFXTexHandle getBitmapResource()
{
return mBitmap;
}
DECLARE_ASSET_SETGET(GuiControlProfile, Bitmap);
void onBitmapChanged() {}
DECLARE_IMAGEASSET(GuiControlProfile, Bitmap, GFXDefaultGUIProfile)
GFXTexHandle mBitmap;
StringTableEntry mBitmapName;
bool mUseBitmapArray; ///< Flag to use the bitmap array or to fallback to non-array rendering
Vector<RectI> mBitmapArrayRects; ///< Used for controls which use an array of bitmaps such as checkboxes

View file

@ -410,7 +410,7 @@ void GuiMenuBar::onRender(Point2I offset, const RectI &updateRect)
bitmapstart.y = mMenuList[i].bounds.point.y + (mMenuList[i].bounds.extent.y - rect.extent.y) / 2;
drawUtil->clearBitmapModulation();
drawUtil->drawBitmapSR(mProfile->getBitmapResource(), offset + bitmapstart, rect);
drawUtil->drawBitmapSR(mProfile->getBitmap(), offset + bitmapstart, rect);
// Should we also draw the text?
if (!mMenuList[i].drawBitmapOnly)
@ -526,10 +526,22 @@ void GuiMenuBar::processTick()
void GuiMenuBar::insert(SimObject* pObject, S32 pos)
{
PopupMenu* menu = dynamic_cast<PopupMenu*>(pObject);
PopupMenu* menu = nullptr;
if (pObject != nullptr)
{
menu = dynamic_cast<PopupMenu*>(pObject);
}
if (menu == nullptr)
{
Con::errorf("GuiMenuBar::insert() - attempted to insert non-popupMenu object: %d", pObject->getId());
if (pObject != nullptr)
{
Con::errorf("GuiMenuBar::insert() - attempted to insert non-popupMenu object: %d", pObject->getId());
}
else
{
Con::errorf("GuiMenuBar::insert() - attempted to insert a nullptr object.");
}
return;
}
@ -552,10 +564,22 @@ void GuiMenuBar::insert(SimObject* pObject, S32 pos)
void GuiMenuBar::remove(SimObject* pObject)
{
PopupMenu* menu = dynamic_cast<PopupMenu*>(pObject);
PopupMenu* menu = nullptr;
if (pObject != nullptr)
{
menu = dynamic_cast<PopupMenu*>(pObject);
}
if (menu == nullptr)
{
Con::errorf("GuiMenuBar::remove() - attempted to remove non-popupMenu object: %d", pObject->getId());
if (pObject != nullptr)
{
Con::errorf("GuiMenuBar::insert() - attempted to insert non-popupMenu object: %d", pObject->getId());
}
else
{
Con::errorf("GuiMenuBar::insert() - attempted to insert a nullptr object.");
}
return;
}

View file

@ -142,7 +142,7 @@ void GuiPopupMenuTextListCtrl::onRenderCell(Point2I offset, Point2I cell, bool s
Point2I bitPos = Point2I(offset.x + mCellSize.y / 2, offset.y + mCellSize.y / 2);
GFX->getDrawUtil()->clearBitmapModulation();
GFX->getDrawUtil()->drawBitmapSR(mProfile->getBitmapResource(), bitPos + off, rect);
GFX->getDrawUtil()->drawBitmapSR(mProfile->getBitmap(), bitPos + off, rect);
}
}

View file

@ -258,7 +258,7 @@ bool GuiInspectorDynamicField::onAdd()
mParent->getId() );
// FIXME Hardcoded image
mDeleteButton->setField( "Bitmap", "ToolsModule:iconDelete_image" );
mDeleteButton->_setBitmap("ToolsModule:iconDelete_image");
mDeleteButton->setField( "Text", "X" );
mDeleteButton->setField( "Command", szBuffer );
mDeleteButton->setSizing( horizResizeLeft, vertResizeCenter );

View file

@ -663,7 +663,7 @@ void GuiInspectorGroup::addInspectorField(StringTableEntry name, StringTableEntr
else if (typeName == StringTable->insert("material"))
fieldType = TypeMaterialAssetId;
else if (typeName == StringTable->insert("image"))
fieldType = TypeImageAssetId;
fieldType = TypeImageAssetPtr;
else if (typeName == StringTable->insert("shape"))
fieldType = TypeShapeAssetId;
else if (typeName == StringTable->insert("sound"))

View file

@ -203,7 +203,7 @@ void GuiVariableInspector::addField(const char* name, const char* label, const c
else if (newField->mFieldTypeName == StringTable->insert("material"))
fieldTypeMask = TypeMaterialAssetId;
else if (newField->mFieldTypeName == StringTable->insert("image"))
fieldTypeMask = TypeImageAssetId;
fieldTypeMask = TypeImageAssetPtr;
else if (newField->mFieldTypeName == StringTable->insert("shape"))
fieldTypeMask = TypeShapeAssetId;
else if (newField->mFieldTypeName == StringTable->insert("bool"))

View file

@ -88,8 +88,6 @@ DefineEngineMethod( GuiChunkedBitmapCtrl, setBitmap, void, (const char* filename
GuiChunkedBitmapCtrl::GuiChunkedBitmapCtrl()
{
INIT_ASSET(Bitmap);
mUseVariable = false;
mTile = false;
}
@ -112,16 +110,6 @@ bool GuiChunkedBitmapCtrl::onWake()
if(!Parent::onWake())
return false;
if( !mBitmap
&& ( ( mBitmapName && mBitmapName[ 0 ] )
|| ( mUseVariable && mConsoleVariable && mConsoleVariable[ 0 ] ) ) )
{
if ( mUseVariable )
mBitmap.set( Con::getVariable( mConsoleVariable ), &GFXDefaultGUIProfile, avar("%s() - mTexHandle (line %d)", __FUNCTION__, __LINE__) );
else
mBitmap.set( mBitmapName, &GFXDefaultGUIProfile, avar("%s() - mTexHandle (line %d)", __FUNCTION__, __LINE__) );
}
return true;
}
@ -167,10 +155,10 @@ void GuiChunkedBitmapCtrl::renderRegion(const Point2I &offset, const Point2I &ex
void GuiChunkedBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
{
if( mBitmap )
if( mBitmapAsset.notNull() )
{
RectI boundsRect( offset, getExtent());
GFX->getDrawUtil()->drawBitmapStretch(mBitmap, boundsRect, GFXBitmapFlip_None, GFXTextureFilterLinear );
GFX->getDrawUtil()->drawBitmapStretch(getBitmap(), boundsRect, GFXBitmapFlip_None, GFXTextureFilterLinear);
}
renderChildControls(offset, updateRect);

View file

@ -17,8 +17,7 @@ private:
protected:
DECLARE_IMAGEASSET(GuiChunkedBitmapCtrl, Bitmap, onImageChanged, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiChunkedBitmapCtrl, Bitmap);
DECLARE_IMAGEASSET(GuiChunkedBitmapCtrl, Bitmap, GFXDefaultGUIProfile)
bool mUseVariable;
bool mTile;
@ -38,6 +37,4 @@ public:
void setBitmap(const char *name);
void onRender(Point2I offset, const RectI &updateRect) override;
void onImageChanged() {}
};

View file

@ -124,7 +124,6 @@ GuiProgressBitmapCtrl::GuiProgressBitmapCtrl()
mNumberOfBitmaps(0),
mDim(0)
{
INIT_ASSET(Bitmap);
}
//-----------------------------------------------------------------------------
@ -221,14 +220,14 @@ void GuiProgressBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
//drawing stretch bitmap
RectI progressRect = ctrlRect;
progressRect.extent.x = width;
drawUtil->drawBitmapStretchSR(mProfile->getBitmapResource(), progressRect, mProfile->mBitmapArrayRects[0]);
drawUtil->drawBitmapStretchSR(mProfile->getBitmap(), progressRect, mProfile->mBitmapArrayRects[0]);
}
}
else if(mNumberOfBitmaps >= 3)
{
//drawing left-end bitmap
RectI progressRectLeft(ctrlRect.point.x, ctrlRect.point.y, mDim, mDim);
drawUtil->drawBitmapStretchSR(mProfile->getBitmapResource(), progressRectLeft, mProfile->mBitmapArrayRects[0]);
drawUtil->drawBitmapStretchSR(mProfile->getBitmap(), progressRectLeft, mProfile->mBitmapArrayRects[0]);
//draw the progress with image
S32 width = (S32)((F32)(getWidth()) * mProgress);
@ -240,11 +239,11 @@ void GuiProgressBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
progressRect.extent.x = (width - mDim - mDim);
if (progressRect.extent.x < 0)
progressRect.extent.x = 0;
drawUtil->drawBitmapStretchSR(mProfile->getBitmapResource(), progressRect, mProfile->mBitmapArrayRects[1]);
drawUtil->drawBitmapStretchSR(mProfile->getBitmap(), progressRect, mProfile->mBitmapArrayRects[1]);
//drawing right-end bitmap
RectI progressRectRight(progressRect.point.x + progressRect.extent.x, ctrlRect.point.y, mDim, mDim );
drawUtil->drawBitmapStretchSR(mProfile->getBitmapResource(), progressRectRight, mProfile->mBitmapArrayRects[2]);
drawUtil->drawBitmapStretchSR(mProfile->getBitmap(), progressRectRight, mProfile->mBitmapArrayRects[2]);
}
}
else

View file

@ -47,21 +47,12 @@ class GuiProgressBitmapCtrl : public GuiTextCtrl
F32 mProgress;
DECLARE_IMAGEASSET(GuiProgressBitmapCtrl, Bitmap, onImageChanged, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiProgressBitmapCtrl, Bitmap);
DECLARE_IMAGEASSET(GuiProgressBitmapCtrl, Bitmap, GFXDefaultGUIProfile)
bool mUseVariable;
bool mTile;
S32 mNumberOfBitmaps;
S32 mDim;
static bool _setBitmap( void* object, const char* index, const char* data )
{
static_cast< GuiProgressBitmapCtrl* >( object )->setBitmap( data );
return false;
}
void onImageChanged() {}
public:

View file

@ -59,8 +59,6 @@ ConsoleDocClass( GuiMissionAreaCtrl,
GuiMissionAreaCtrl::GuiMissionAreaCtrl()
{
INIT_ASSET(HandleBitmap);
mHandleTextureSize = Point2I::Zero;
mHandleTextureHalfSize = Point2F::Zero;
@ -114,9 +112,9 @@ bool GuiMissionAreaCtrl::onAdd()
desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
mBlendStateBlock = GFX->createStateBlock( desc );
if (!mHandleBitmap.isNull())
if (!mHandleBitmapAsset.isNull())
{
mHandleTextureSize = Point2I(mHandleBitmap->getWidth(), mHandleBitmap->getHeight() );
mHandleTextureSize = Point2I(getHandleBitmap()->getWidth(), getHandleBitmap()->getHeight());
mHandleTextureHalfSize = Point2F(mHandleTextureSize.x, mHandleTextureSize.y) * 0.5f;
}
else
@ -418,7 +416,7 @@ void GuiMissionAreaCtrl::setArea(const RectI & area)
void GuiMissionAreaCtrl::drawHandle(const Point2F & pos)
{
Point2F pnt(pos.x-mHandleTextureHalfSize.x, pos.y-mHandleTextureHalfSize.y);
GFX->getDrawUtil()->drawBitmap(mHandleBitmap, pnt);
GFX->getDrawUtil()->drawBitmap(getHandleBitmap(), pnt);
}
void GuiMissionAreaCtrl::drawHandles(RectI & box)

View file

@ -63,8 +63,7 @@ protected:
GFXStateBlockRef mBlendStateBlock;
GFXStateBlockRef mSolidStateBlock;
DECLARE_IMAGEASSET(GuiMissionAreaCtrl, HandleBitmap, onHandleBitmapChanged, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiMissionAreaCtrl, HandleBitmap);
DECLARE_IMAGEASSET(GuiMissionAreaCtrl, HandleBitmap, GFXDefaultGUIProfile)
Point2I mHandleTextureSize;
Point2F mHandleTextureHalfSize;
@ -110,8 +109,6 @@ protected:
bool testWithinHandle(const Point2I & testPoint, S32 handleX, S32 handleY);
S32 getHitHandles(const Point2I & mousePnt, const RectI & box);
void onHandleBitmapChanged() {}
public:
GuiMissionAreaCtrl();
virtual ~GuiMissionAreaCtrl();

View file

@ -1817,9 +1817,9 @@ WorldEditor::WorldEditor()
mPopupBackgroundColor.set(100,100,100);
mPopupTextColor.set(255,255,0);
mSelectHandleAssetId = StringTable->insert("ToolsModule:SelectHandle");
mDefaultHandleAssetId = StringTable->insert("ToolsModule:DefaultHandle");
mLockedHandleAssetId = StringTable->insert("ToolsModule:LockedHandle");
mSelectHandleAsset = StringTable->insert("ToolsModule:SelectHandle_image");
mDefaultHandleAsset = StringTable->insert("ToolsModule:DefaultHandle_image");
mLockedHandleAsset = StringTable->insert("ToolsModule:LockedHandle_image");
mObjectTextColor.set(255,255,255);
mObjectsUseBoxCenter = true;
@ -1905,9 +1905,9 @@ bool WorldEditor::onAdd()
// create the default class entry
mDefaultClassEntry.mName = 0;
mDefaultClassEntry.mIgnoreCollision = false;
mDefaultClassEntry.mDefaultHandle = mDefaultHandle;
mDefaultClassEntry.mSelectHandle = mSelectHandle;
mDefaultClassEntry.mLockedHandle = mLockedHandle;
mDefaultClassEntry.mDefaultHandle = getDefaultHandle();
mDefaultClassEntry.mSelectHandle = getSelectHandle();
mDefaultClassEntry.mLockedHandle = getLockedHandle();
if(!(mDefaultClassEntry.mDefaultHandle && mDefaultClassEntry.mSelectHandle && mDefaultClassEntry.mLockedHandle))
return false;

View file

@ -328,12 +328,9 @@ class WorldEditor : public EditTSCtrl
ColorI mPopupBackgroundColor;
ColorI mPopupTextColor;
DECLARE_IMAGEASSET(WorldEditor, SelectHandle, onSelectHandleChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(WorldEditor, SelectHandle);
DECLARE_IMAGEASSET(WorldEditor, DefaultHandle, onDefaultHandleChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(WorldEditor, DefaultHandle);
DECLARE_IMAGEASSET(WorldEditor, LockedHandle, onLockedHandleChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(WorldEditor, LockedHandle);
DECLARE_IMAGEASSET(WorldEditor, SelectHandle, GFXStaticTextureSRGBProfile)
DECLARE_IMAGEASSET(WorldEditor, DefaultHandle, GFXStaticTextureSRGBProfile)
DECLARE_IMAGEASSET(WorldEditor, LockedHandle, GFXStaticTextureSRGBProfile)
ColorI mObjectTextColor;
bool mObjectsUseBoxCenter;
@ -425,10 +422,6 @@ class WorldEditor : public EditTSCtrl
void setEditorTool(EditorTool*);
EditorTool* getActiveEditorTool() { return mActiveEditorTool; }
void onSelectHandleChanged() {}
void onDefaultHandleChanged() {}
void onLockedHandleChanged() {}
};
typedef WorldEditor::DropType WorldEditorDropType;

View file

@ -139,19 +139,6 @@ Material::Material()
mAccuCoverage[i] = 0.9f;
mAccuSpecular[i] = 16.0f;
INIT_IMAGEASSET_ARRAY(DiffuseMap, GFXStaticTextureSRGBProfile, i);
INIT_IMAGEASSET_ARRAY(OverlayMap, GFXStaticTextureProfile, i);
INIT_IMAGEASSET_ARRAY(LightMap, GFXStaticTextureProfile, i);
INIT_IMAGEASSET_ARRAY(ToneMap, GFXStaticTextureProfile, i);
INIT_IMAGEASSET_ARRAY(DetailMap, GFXStaticTextureProfile, i);
INIT_IMAGEASSET_ARRAY(NormalMap, GFXNormalMapProfile, i);
INIT_IMAGEASSET_ARRAY(ORMConfigMap, GFXStaticTextureProfile, i);
INIT_IMAGEASSET_ARRAY(RoughMap, GFXStaticTextureProfile, i);
INIT_IMAGEASSET_ARRAY(AOMap, GFXStaticTextureProfile, i);
INIT_IMAGEASSET_ARRAY(MetalMap, GFXStaticTextureProfile, i);
INIT_IMAGEASSET_ARRAY(GlowMap, GFXStaticTextureProfile, i);
INIT_IMAGEASSET_ARRAY(DetailNormalMap, GFXNormalMapProfile, i);
mParallaxScale[i] = 0.0f;
mVertLit[i] = false;
@ -245,11 +232,6 @@ FRangeValidator glowMulRange(0.0f, 20.0f);
FRangeValidator parallaxScaleRange(0.0f, 4.0f);
FRangeValidator scrollSpeedRange(0.0f, 10.0f);
FRangeValidator waveFreqRange(0.0f, 10.0f);
void Material::onImageAssetChanged()
{
flush();
reload();
}
void Material::initPersistFields()
{
@ -279,21 +261,20 @@ void Material::initPersistFields()
"Treat Roughness as Roughness");
INITPERSISTFIELD_IMAGEASSET_ARRAY(AOMap, MAX_STAGES, Material, "AOMap");
INITPERSISTFIELD_IMAGEASSET_ARRAY(RoughMap, MAX_STAGES, Material, "RoughMap (also needs MetalMap)");
INITPERSISTFIELD_IMAGEASSET_ARRAY(MetalMap, MAX_STAGES, Material, "MetalMap (also needs RoughMap)");
INITPERSISTFIELD_IMAGEASSET_ARRAY(GlowMap, MAX_STAGES, Material, "GlowMap (needs Albedo)");
addFieldV("AOChan", TypeRangedS32, Offset(mAOChan, Material), &bmpChanRange, MAX_STAGES,
"The input channel AO maps use.");
INITPERSISTFIELD_IMAGEASSET_ARRAY(RoughMap, MAX_STAGES, Material, "RoughMap (also needs MetalMap)");
addFieldV("roughness", TypeRangedF32, Offset(mRoughness, Material), &CommonValidators::F32_8BitPercent,MAX_STAGES,
"The degree of roughness when not using a ORMConfigMap.");
addFieldV("roughnessChan", TypeRangedS32, Offset(mRoughnessChan, Material), &bmpChanRange, MAX_STAGES,
"The input channel roughness maps use.");
INITPERSISTFIELD_IMAGEASSET_ARRAY(MetalMap, MAX_STAGES, Material, "MetalMap (also needs RoughMap)");
addFieldV("metalness", TypeRangedF32, Offset(mMetalness, Material), &CommonValidators::F32_8BitPercent, MAX_STAGES,
"The degree of Metalness when not using a ORMConfigMap.");
addFieldV("metalChan", TypeRangedS32, Offset(mMetalChan, Material), &bmpChanRange, MAX_STAGES,
"The input channel metalness maps use.");
INITPERSISTFIELD_IMAGEASSET_ARRAY(GlowMap, MAX_STAGES, Material, "GlowMap (needs Albedo)");
addFieldV("glowMul", TypeRangedF32, Offset(mGlowMul, Material),&glowMulRange, MAX_STAGES,
"glow mask multiplier");
@ -306,6 +287,7 @@ void Material::initPersistFields()
INITPERSISTFIELD_IMAGEASSET_ARRAY(DetailNormalMap, MAX_STAGES, Material, "DetailNormalMap");
addFieldV("detailNormalMapStrength", TypeRangedF32, Offset(mDetailNormalMapStrength, Material), &CommonValidators::PositiveFloat, MAX_STAGES,
"Used to scale the strength of the detail normal map when blended with the base normal map.");
INITPERSISTFIELD_IMAGEASSET_ARRAY(OverlayMap, MAX_STAGES, Material, "Overlay");
@ -508,18 +490,6 @@ void Material::initPersistFields()
// They point at the new 'map' fields, but reads always return
// an empty string and writes only apply if the value is not empty.
//
addProtectedField("baseTex", TypeImageFilename, Offset(mDiffuseMapName, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see diffuseMap\n", AbstractClassRep::FIELD_HideInInspectors);
addProtectedField("detailTex", TypeImageFilename, Offset(mDetailMapName, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see detailMap\n", AbstractClassRep::FIELD_HideInInspectors);
addProtectedField("overlayTex", TypeImageFilename, Offset(mOverlayMapName, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see overlayMap\n", AbstractClassRep::FIELD_HideInInspectors);
addProtectedField("bumpTex", TypeImageFilename, Offset(mNormalMapName, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see normalMap\n", AbstractClassRep::FIELD_HideInInspectors);
addProtectedField("colorMultiply", TypeColorF, Offset(mDiffuse, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see diffuseColor\n", AbstractClassRep::FIELD_HideInInspectors);
@ -625,7 +595,7 @@ bool Material::isLightmapped() const
{
bool ret = false;
for (U32 i = 0; i < MAX_STAGES; i++)
ret |= mLightMapName[i] != StringTable->EmptyString() || mToneMapName[i] != StringTable->EmptyString() || mVertLit[i];
ret |= mLightMapAsset[i].notNull() || mToneMapAsset[i].notNull() || mVertLit[i];
return ret;
}
@ -658,26 +628,11 @@ void Material::_mapMaterial()
// If mapTo not defined in script, try to use the base texture name instead
if (mMapTo.isEmpty())
{
if (mDiffuseMapName[0] == StringTable->EmptyString() && mDiffuseMapAsset->isNull())
if (mDiffuseMapAsset->isNull())
return;
else
else if (mDiffuseMapAsset->notNull())
{
// extract filename from base texture
if (mDiffuseMapName[0] != StringTable->EmptyString())
{
U32 slashPos = String(mDiffuseMapName[0]).find('/', 0, String::Right);
if (slashPos == String::NPos)
// no '/' character, must be no path, just the filename
mMapTo = mDiffuseMapName[0];
else
// use everything after the last slash
mMapTo = String(mDiffuseMapName[0]).substr(slashPos + 1, (U32)strlen(mDiffuseMapName[0]) - slashPos - 1);
}
else if (!mDiffuseMapAsset->isNull())
{
mMapTo = mDiffuseMapAsset[0]->getImageFileName();
}
mMapTo = mDiffuseMapAsset[0]->getImageFile();
}
}
@ -852,16 +807,15 @@ bool Material::_setAccuEnabled(void* object, const char* index, const char* data
//material.getDiffuseMap(%layer); //returns the raw file referenced
//material.getDiffuseMapAsset(%layer); //returns the asset id
//material.setDiffuseMap(%texture, %layer); //tries to set the asset and failing that attempts a flat file reference
DEF_IMAGEASSET_ARRAY_BINDS(Material, DiffuseMap)
DEF_IMAGEASSET_ARRAY_BINDS(Material, OverlayMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, LightMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, ToneMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, NormalMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, ORMConfigMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, RoughMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, AOMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, MetalMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, GlowMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailNormalMap);
DEF_IMAGEASSET_ARRAY_BINDS(Material, DiffuseMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, NormalMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailNormalMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, OverlayMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, LightMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, ToneMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, ORMConfigMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, RoughMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, AOMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, MetalMap, Material::Constants::MAX_STAGES)
DEF_IMAGEASSET_ARRAY_BINDS(Material, GlowMap, Material::Constants::MAX_STAGES)

View file

@ -208,56 +208,29 @@ public:
//-----------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------
void onImageAssetChanged();
DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DiffuseMap);
DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, GFXStaticTextureSRGBProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, NormalMap, GFXNormalMapProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, DetailNormalMap, GFXNormalMapProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, OverlayMap, GFXStaticTextureProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, LightMap, GFXStaticTextureProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, ToneMap, GFXStaticTextureProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, DetailMap, GFXStaticTextureProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, ORMConfigMap, GFXStaticTextureProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, AOMap, GFXStaticTextureProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, RoughMap, GFXStaticTextureProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, MetalMap, GFXStaticTextureProfile, MAX_STAGES)
DECLARE_IMAGEASSET_ARRAY(Material, GlowMap, GFXStaticTextureProfile, MAX_STAGES)
bool mDiffuseMapSRGB[MAX_STAGES]; // SRGB diffuse
DECLARE_IMAGEASSET_ARRAY(Material, OverlayMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, OverlayMap);
DECLARE_IMAGEASSET_ARRAY(Material, LightMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, LightMap);
DECLARE_IMAGEASSET_ARRAY(Material, ToneMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, ToneMap);
DECLARE_IMAGEASSET_ARRAY(Material, DetailMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DetailMap);
DECLARE_IMAGEASSET_ARRAY(Material, NormalMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, NormalMap);
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, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, AOMap);
S32 mAOChan[MAX_STAGES];
DECLARE_IMAGEASSET_ARRAY(Material, RoughMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, RoughMap);
bool mIsSRGb[MAX_STAGES]; // SRGB ORM
F32 mAOChan[MAX_STAGES];
bool mInvertRoughness[MAX_STAGES];
S32 mRoughnessChan[MAX_STAGES];
DECLARE_IMAGEASSET_ARRAY(Material, MetalMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, MetalMap);
S32 mMetalChan[MAX_STAGES];
DECLARE_IMAGEASSET_ARRAY(Material, GlowMap, MAX_STAGES, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, GlowMap);
F32 mRoughnessChan[MAX_STAGES];
F32 mMetalChan[MAX_STAGES];
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, onImageAssetChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DetailNormalMap);
/// The strength scalar for the detail normal map.
F32 mDetailNormalMapStrength[MAX_STAGES];
F32 mDetailNormalMapStrength[MAX_STAGES];
bool mAccuEnabled[MAX_STAGES];
F32 mAccuScale[MAX_STAGES];
F32 mAccuDirection[MAX_STAGES];

View file

@ -61,8 +61,6 @@ MaterialManager::MaterialManager()
mLastTime = 0;
mDampness = 0.0f;
mWarningInst = NULL;
mMatDefToFlush = NULL;
mMatDefToReload = NULL;
GFXDevice::getDeviceEventSignal().notify( this, &MaterialManager::_handleGFXEvent );
@ -75,8 +73,6 @@ MaterialManager::MaterialManager()
mUsingDeferred = false;
mFlushAndReInit = false;
mMatDefShouldFlush = false;
mMatDefShouldReload = false;
mDefaultAnisotropy = 1;
Con::addVariable( "$pref::Video::defaultAnisotropy", TypeS32, &mDefaultAnisotropy,
@ -328,12 +324,6 @@ String MaterialManager::getMapEntry(const String & textureName) const
}
void MaterialManager::flushAndReInitInstances()
{
// delay flushes and reinits until the start of the next frame.
mFlushAndReInit = true;
}
void MaterialManager::_flushAndReInitInstances()
{
// Clear the flag if its set.
mFlushAndReInit = false;
@ -368,16 +358,8 @@ void MaterialManager::_flushAndReInitInstances()
(*iter)->reInit();
}
// Used in the materialEditor. This flushes the material preview object so it can be reloaded easily.
void MaterialManager::flushInstance(BaseMaterialDefinition* target)
void MaterialManager::flushInstance( BaseMaterialDefinition *target )
{
mMatDefToFlush = target;
mMatDefShouldFlush = true;
}
void MaterialManager::_flushInstance( BaseMaterialDefinition *target )
{
mMatDefShouldFlush = false;
Vector<BaseMatInstance*>::iterator iter = mMatInstanceList.begin();
while ( iter != mMatInstanceList.end() )
{
@ -388,26 +370,16 @@ void MaterialManager::_flushInstance( BaseMaterialDefinition *target )
}
iter++;
}
mMatDefToFlush = NULL;
}
void MaterialManager::reInitInstance(BaseMaterialDefinition* target)
void MaterialManager::reInitInstance( BaseMaterialDefinition *target )
{
mMatDefToReload = target;
mMatDefShouldReload = true;
}
void MaterialManager::_reInitInstance( BaseMaterialDefinition *target )
{
mMatDefShouldReload = false;
Vector<BaseMatInstance*>::iterator iter = mMatInstanceList.begin();
for ( ; iter != mMatInstanceList.end(); iter++ )
{
if ( (*iter)->getMaterial() == target )
(*iter)->reInit();
}
mMatDefToReload = NULL;
}
void MaterialManager::updateTime()
@ -526,15 +498,7 @@ bool MaterialManager::_handleGFXEvent( GFXDevice::GFXDeviceEventType event_ )
case GFXDevice::deStartOfFrame:
if ( mFlushAndReInit )
_flushAndReInitInstances();
if (mMatDefShouldFlush)
{
_flushInstance(mMatDefToFlush);
}
if (mMatDefShouldReload)
{
_reInitInstance(mMatDefToReload);
}
flushAndReInitInstances();
break;
default:

View file

@ -116,12 +116,16 @@ public:
/// Returns the signal used to notify systems that the
/// procedural shaders have been flushed.
FlushSignal& getFlushSignal() { return mFlushSignal; }
/// Flushes all the procedural shaders and re-initializes all
/// the active materials instances immediately.
void flushAndReInitInstances();
// Flush the instance
void flushInstance( BaseMaterialDefinition *target );
void flushInstance(BaseMaterialDefinition* target);
/// Re-initializes the material instances for a specific target material.
void reInitInstance( BaseMaterialDefinition *target );
void reInitInstance(BaseMaterialDefinition* target);
protected:
@ -129,14 +133,7 @@ protected:
friend class MatInstance;
void _track(MatInstance*);
void _untrack(MatInstance*);
/// Flushes all the procedural shaders and re-initializes all
/// the active materials instances immediately.
void _flushAndReInitInstances();
// Flush the instance
void _flushInstance(BaseMaterialDefinition* target);
/// Re-initializes the material instances for a specific target material.
void _reInitInstance(BaseMaterialDefinition* target);
/// @see LightManager::smActivateSignal
void _onLMActivate( const char *lm, bool activate );
@ -158,8 +155,6 @@ protected:
/// If set we flush and reinitialize all materials at the
/// start of the next rendered frame.
bool mFlushAndReInit;
bool mMatDefShouldReload;
bool mMatDefShouldFlush;
// material map
typedef Map<String, String> MaterialMap;
@ -174,8 +169,6 @@ protected:
F32 mDampness;
BaseMatInstance* mWarningInst;
BaseMaterialDefinition* mMatDefToFlush;
BaseMaterialDefinition* mMatDefToReload;
/// The default max anisotropy used in texture filtering.
S32 mDefaultAnisotropy;

View file

@ -392,69 +392,54 @@ void ProcessedMaterial::_setStageData()
for (i = 0; i < Material::MAX_STAGES; i++)
{
// DiffuseMap
if (mMaterial->mDiffuseMapAsset[i] && !mMaterial->mDiffuseMapAsset[i].isNull())
if (mMaterial->getDiffuseMapAsset(i).notNull())
{
mStages[i].setTex(MFT_DiffuseMap, mMaterial->getDiffuseMapResource(i));
mStages[i].setTex(MFT_DiffuseMap, mMaterial->getDiffuseMap(i));
if (!mStages[i].getTex(MFT_DiffuseMap))
{
// If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass.
if (!String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("#") && !String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("$"))
mMaterial->logError("Failed to load diffuse map %s for stage %i", mMaterial->mDiffuseMapAsset[i]->getImageFileName(), i);
if (!mMaterial->getDiffuseMapAsset(i)->isNamedTarget())
mMaterial->logError("Failed to load diffuse map %s for stage %i", mMaterial->getDiffuseMapAsset(i)->getImageFile(), i);
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
}
}
else if (mMaterial->mDiffuseMapName[i] != StringTable->EmptyString())
{
mStages[i].setTex(MFT_DiffuseMap, _createTexture(mMaterial->mDiffuseMapName[i], &GFXStaticTextureSRGBProfile));
if (!mStages[i].getTex(MFT_DiffuseMap))
{
//If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass.
if (!String(mMaterial->mDiffuseMapName[i]).startsWith("#") && !String(mMaterial->mDiffuseMapName[i]).startsWith("$"))
mMaterial->logError("Failed to load diffuse map %s for stage %i", mMaterial->mDiffuseMapName[i], i);
// Load a debug texture to make it clear to the user
// that the texture for this stage was missing.
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
}
}
// OverlayMap
if (mMaterial->getOverlayMap(i) != StringTable->EmptyString())
if (mMaterial->getOverlayMapAsset(i).notNull())
{
mStages[i].setTex(MFT_OverlayMap, mMaterial->getOverlayMapResource(i));
mStages[i].setTex(MFT_OverlayMap, mMaterial->getOverlayMap(i));
if (!mStages[i].getTex(MFT_OverlayMap))
mMaterial->logError("Failed to load overlay map %s for stage %i", mMaterial->getOverlayMap(i), i);
mMaterial->logError("Failed to load overlay map %s for stage %i", mMaterial->_getOverlayMap(i), i);
}
// LightMap
if (mMaterial->getLightMap(i) != StringTable->EmptyString())
if (mMaterial->getLightMapAsset(i).notNull())
{
mStages[i].setTex(MFT_LightMap, mMaterial->getLightMapResource(i));
mStages[i].setTex(MFT_LightMap, mMaterial->getLightMap(i));
if (!mStages[i].getTex(MFT_LightMap))
mMaterial->logError("Failed to load light map %s for stage %i", mMaterial->getLightMap(i), i);
mMaterial->logError("Failed to load light map %s for stage %i", mMaterial->_getLightMap(i), i);
}
// ToneMap
if (mMaterial->getToneMap(i) != StringTable->EmptyString())
if (mMaterial->getToneMapAsset(i).notNull())
{
mStages[i].setTex(MFT_ToneMap, mMaterial->getToneMapResource(i));
mStages[i].setTex(MFT_ToneMap, mMaterial->getToneMap(i));
if (!mStages[i].getTex(MFT_ToneMap))
mMaterial->logError("Failed to load tone map %s for stage %i", mMaterial->getToneMap(i), i);
mMaterial->logError("Failed to load tone map %s for stage %i", mMaterial->_getToneMap(i), i);
}
// DetailMap
if (mMaterial->getDetailMap(i) != StringTable->EmptyString())
if (mMaterial->getDetailMapAsset(i).notNull())
{
mStages[i].setTex(MFT_DetailMap, mMaterial->getDetailMapResource(i));
mStages[i].setTex(MFT_DetailMap, mMaterial->getDetailMap(i));
if (!mStages[i].getTex(MFT_DetailMap))
mMaterial->logError("Failed to load detail map %s for stage %i", mMaterial->getDetailMap(i), i);
mMaterial->logError("Failed to load detail map %s for stage %i", mMaterial->_getDetailMap(i), i);
}
// NormalMap
if (mMaterial->mNormalMapAsset[i] && !mMaterial->mNormalMapAsset[i].isNull())
if (mMaterial->getNormalMapAsset(i).notNull())
{
mStages[i].setTex(MFT_NormalMap, mMaterial->getNormalMapResource(i));
//mStages[i].setTex(MFT_DiffuseMap, _createTexture(mMaterial->getDiffuseMap(i), &GFXStaticTextureSRGBProfile));
mStages[i].setTex(MFT_NormalMap, mMaterial->getNormalMap(i));
if (!mStages[i].getTex(MFT_NormalMap))
{
// Load a debug texture to make it clear to the user
@ -462,24 +447,13 @@ void ProcessedMaterial::_setStageData()
mStages[i].setTex(MFT_NormalMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXNormalMapProfile));
}
}
else if (mMaterial->mNormalMapName[i] != StringTable->EmptyString())
{
mStages[i].setTex(MFT_NormalMap, _createTexture(mMaterial->mNormalMapName[i], &GFXNormalMapProfile));
if (!mStages[i].getTex(MFT_NormalMap))
{
//If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass. So we'll
//pass on the error rather than spamming the console
if (!String(mMaterial->mNormalMapName[i]).startsWith("#"))
mMaterial->logError("Failed to load normal map %s for stage %i", mMaterial->mNormalMapName[i], i);
}
}
// Detail Normal Map
if (mMaterial->getDetailNormalMap(i) != StringTable->EmptyString())
if (mMaterial->getDetailNormalMapAsset(i).notNull())
{
mStages[i].setTex(MFT_DetailNormalMap, mMaterial->getDetailNormalMapResource(i));
mStages[i].setTex(MFT_DetailNormalMap, mMaterial->getDetailNormalMap(i));
if (!mStages[i].getTex(MFT_DetailNormalMap))
mMaterial->logError("Failed to load normal map %s for stage %i", mMaterial->getDetailNormalMap(i), i);
mMaterial->logError("Failed to load normal map %s for stage %i", mMaterial->_getDetailNormalMap(i), i);
}
//depending on creation method this may or may not have been shoved into srgb space eroneously
@ -488,33 +462,33 @@ void ProcessedMaterial::_setStageData()
profile = &GFXStaticTextureSRGBProfile;
// ORMConfig
if (mMaterial->getORMConfigMap(i) != StringTable->EmptyString())
if (mMaterial->getORMConfigMapAsset(i).notNull())
{
mStages[i].setTex(MFT_OrmMap, _createTexture(mMaterial->getORMConfigMap(i), profile));
mStages[i].setTex(MFT_OrmMap, mMaterial->getORMConfigMap(profile, i));
if (!mStages[i].getTex(MFT_OrmMap))
mMaterial->logError("Failed to load PBR Config map %s for stage %i", mMaterial->getORMConfigMap(i), i);
mMaterial->logError("Failed to load PBR Config map %s for stage %i", mMaterial->_getORMConfigMap(i), i);
}
else
{
if ((mMaterial->getAOMap(i) != StringTable->EmptyString()) || (mMaterial->getRoughMap(i) != StringTable->EmptyString()) || (mMaterial->getMetalMap(i) != StringTable->EmptyString()))
if ((mMaterial->getAOMapAsset(i).notNull()) || (mMaterial->getRoughMapAsset(i).notNull()) || (mMaterial->getMetalMapAsset(i).notNull()))
{
U32 inputKey[4];
inputKey[0] = mMaterial->mAOChan[i];
inputKey[1] = mMaterial->mRoughnessChan[i];
inputKey[2] = mMaterial->mMetalChan[i];
inputKey[3] = 0;
mStages[i].setTex(MFT_OrmMap, _createCompositeTexture( mMaterial->getAOMap(i), mMaterial->getRoughMap(i),
mMaterial->getMetalMap(i), "",
mStages[i].setTex(MFT_OrmMap, _createCompositeTexture( mMaterial->getAOMapAsset(i)->getImageFile(), mMaterial->getRoughMapAsset(i)->getImageFile(),
mMaterial->getMetalMapAsset(i)->getImageFile(), "",
inputKey, profile));
if (!mStages[i].getTex(MFT_OrmMap))
mMaterial->logError("Failed to dynamically create ORM Config map for stage %i", i);
}
}
if (mMaterial->getGlowMap(i) != StringTable->EmptyString())
if (mMaterial->getGlowMapAsset(i).notNull())
{
mStages[i].setTex(MFT_GlowMap, mMaterial->getGlowMapResource(i));
mStages[i].setTex(MFT_GlowMap, mMaterial->getGlowMap(i));
if (!mStages[i].getTex(MFT_GlowMap))
mMaterial->logError("Failed to load glow map %s for stage %i", mMaterial->getGlowMap(i), i);
mMaterial->logError("Failed to load glow map %s for stage %i", mMaterial->_getGlowMap(i), i);
}
}

View file

@ -229,10 +229,9 @@ bool ProcessedShaderMaterial::init( const FeatureSet &features,
mInstancingState = new InstancingState();
mInstancingState->setFormat( _getRPD( 0 )->shader->getInstancingFormat(), mVertexFormat );
}
if (mMaterial && mMaterial->mDiffuseMapName[0] != StringTable->EmptyString() && String(mMaterial->mDiffuseMapName[0]).startsWith("#"))
if (mMaterial && mMaterial->getDiffuseMapAsset(0).notNull() && mMaterial->getDiffuseMapAsset(0)->isNamedTarget())
{
String texTargetBufferName = String(mMaterial->mDiffuseMapName[0]).substr(1, (U32)strlen(mMaterial->mDiffuseMapName[0]) - 1);
NamedTexTarget *texTarget = NamedTexTarget::find(texTargetBufferName);
NamedTexTarget *texTarget = mMaterial->getDiffuseMapAsset(0)->getNamedTarget();
RenderPassData* rpd = getPass(0);
if (rpd)
@ -876,13 +875,27 @@ void ProcessedShaderMaterial::setTextureStages( SceneRenderState *state, const S
case Material::TexTarget:
{
texTarget = rpd->mTexSlot[i].texTarget;
if ( !texTarget )
if (!mMaterial->getDiffuseMapAsset(0).notNull())
{
GFX->setTexture( i, NULL );
GFX->setTexture(i, NULL);
break;
}
texObject = texTarget->getTexture();
texObject = mMaterial->getDiffuseMapAsset(0)->getTexture(&GFXStaticTextureSRGBProfile);
if ( !texTarget )
{
// try again.
texTarget = mMaterial->getDiffuseMapAsset(0)->getNamedTarget();
if (!texTarget)
{
GFX->setTexture(i, texObject);
break;
}
else
{
rpd->mTexSlot[i].texTarget = texTarget;
}
}
// If no texture is available then map the default 2x2
// black texture to it. This at least will ensure that
@ -1271,35 +1284,35 @@ void ProcessedShaderMaterial::setNodeTransforms(const MatrixF *transforms, const
void ProcessedShaderMaterial::setCustomShaderData(Vector<CustomShaderBindingData> &shaderData, const U32 pass)
{
PROFILE_SCOPE(ProcessedShaderMaterial_setCustomShaderData);
PROFILE_SCOPE(ProcessedShaderMaterial_setCustomShaderData);
GFXShaderConstBuffer* shaderConsts = _getShaderConstBuffer(pass);
ShaderConstHandles* handles = _getShaderConstHandles(pass);
GFXShaderConstBuffer* shaderConsts = _getShaderConstBuffer(pass);
ShaderConstHandles* handles = _getShaderConstHandles(pass);
for (U32 i = 0; i < shaderData.size(); i++)
{
//roll through and try setting our data!
for (U32 h = 0; h < handles->mCustomHandles.size(); ++h)
{
if (handles->mCustomHandles[h].handleName == shaderData[i].getHandleName())
{
if (handles->mCustomHandles[h].handle->isValid())
{
CustomShaderBindingData::UniformType type = shaderData[i].getType();
for (U32 i = 0; i < shaderData.size(); i++)
{
//roll through and try setting our data!
for (U32 h = 0; h < handles->mCustomHandles.size(); ++h)
{
if (handles->mCustomHandles[h].handleName == shaderData[i].getHandleName())
{
if (handles->mCustomHandles[h].handle->isValid())
{
CustomShaderBindingData::UniformType type = shaderData[i].getType();
if (type == CustomShaderBindingData::Float)
shaderConsts->setSafe(handles->mCustomHandles[h].handle, shaderData[i].getFloat());
else if (type == CustomShaderBindingData::Float2)
shaderConsts->setSafe(handles->mCustomHandles[h].handle, shaderData[i].getFloat2());
else if (type == CustomShaderBindingData::Float3)
shaderConsts->setSafe(handles->mCustomHandles[h].handle, shaderData[i].getFloat3());
else if (type == CustomShaderBindingData::Float4)
shaderConsts->setSafe(handles->mCustomHandles[h].handle, shaderData[i].getFloat4());
break;
}
}
}
}
if (type == CustomShaderBindingData::Float)
shaderConsts->setSafe(handles->mCustomHandles[h].handle, shaderData[i].getFloat());
else if (type == CustomShaderBindingData::Float2)
shaderConsts->setSafe(handles->mCustomHandles[h].handle, shaderData[i].getFloat2());
else if (type == CustomShaderBindingData::Float3)
shaderConsts->setSafe(handles->mCustomHandles[h].handle, shaderData[i].getFloat3());
else if (type == CustomShaderBindingData::Float4)
shaderConsts->setSafe(handles->mCustomHandles[h].handle, shaderData[i].getFloat4());
break;
}
}
}
}
}
void ProcessedShaderMaterial::setSceneInfo(SceneRenderState * state, const SceneData& sgData, U32 pass)

View file

@ -531,5 +531,7 @@ inline F64 mSquared( F64 n )
return n * n;
}
template< typename T >
inline void mSwap(T& a, T& b) { T temp = b; b = a; a = temp; }
#endif //_MMATHFN_H_

View file

@ -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,6 +552,7 @@ 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"
"@see PFXTextureIdentifiers");
@ -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(&macros);
if (texFilename.isNotEmpty() && texFilename[0] == '#')
{
NamedTexTarget* namedTarget = NamedTexTarget::find(texFilename.c_str() + 1);
if (!namedTarget)
{
return;
}
// Grab the macros for shader initialization.
namedTarget->getShaderMacros(&macros);
}
}
}
}

View file

@ -90,9 +90,9 @@ public:
protected:
DECLARE_IMAGEASSET_ARRAY(PostEffect, Texture, NumTextures, onTextureChanged);
DECLARE_IMAGEASSET_ARRAY_SETGET(PostEffect, Texture);
void onTextureChanged() {}
DECLARE_IMAGEASSET_ARRAY(PostEffect, Texture, GFXStaticTextureSRGBProfile, NumTextures);
GFXTextureProfile* mTextureProfile[NumTextures];
GFXTexHandle mTexture[NumTextures];
bool mTexSRGB[NumTextures];

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->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 );
}

Some files were not shown because too many files have changed in this diff Show more