diff --git a/Engine/source/T3D/accumulationVolume.cpp b/Engine/source/T3D/accumulationVolume.cpp index f7f98774d..682125ef5 100644 --- a/Engine/source/T3D/accumulationVolume.cpp +++ b/Engine/source/T3D/accumulationVolume.cpp @@ -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(); } } diff --git a/Engine/source/T3D/accumulationVolume.h b/Engine/source/T3D/accumulationVolume.h index 66b2c8a31..0c5fe4fe1 100644 --- a/Engine/source/T3D/accumulationVolume.h +++ b/Engine/source/T3D/accumulationVolume.h @@ -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: diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index 162626b84..5f234fc0b 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -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, AssetPtrImageAsset,, "") +END_IMPLEMENT_STRUCT + +ConsoleType(ImageAssetPtr, TypeImageAssetPtr, AssetPtr, ASSET_ID_FIELD_PREFIX) + ConsoleGetType(TypeImageAssetPtr) { // Fetch asset Id. - return *((const char**)(dptr)); + return (*((AssetPtr*)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* pAssetPtr = dynamic_cast*>((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) { AssetQuery query; @@ -227,7 +263,38 @@ StringTableEntry ImageAsset::getAssetIdByFilename(StringTableEntry fileName) } else { - AssetPtr 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 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 = imageAssetId; //ensures the fallback is loaded + } } return imageAssetId; @@ -262,168 +329,238 @@ U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr* 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(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(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 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(previewFilename); - previewFilename = previewAsset->getImagePath(); + previewFilename = previewAsset->getImageFile(); } } @@ -744,11 +1006,7 @@ void GuiInspectorTypeImageAssetPtr::updatePreviewImage() { if (AssetDatabase.isDeclaredAsset(previewImage)) { - ImageAsset* imgAsset = AssetDatabase.acquireAsset(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(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 diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 027dfbac1..6dc97f933 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -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 -#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 mResourceMap; + bool mIsNamedTarget; + S32 mImageWidth; + S32 mImageHeight; + S32 mImageDepth; + S32 mImageChannels; - typedef Signal ImageAssetChanged; - ImageAssetChanged mChangeSignal; - - typedef Signal 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); static StringTableEntry getAssetIdByFilename(StringTableEntry fileName); static U32 getAssetById(StringTableEntry assetId, AssetPtr* imageAsset); static U32 getAssetById(String assetId, AssetPtr* 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(obj)->setImageFileName(data); return false; } - static StringTableEntry getImageFileName(void* obj, StringTableEntry data) { return static_cast(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(obj)->setImageFile(data); return false; } + static const char* getImageFile(void* obj, StringTableEntry data) { return static_cast(obj)->getImageFile(); } + static bool writeImageFile(void* obj, StringTableEntry pFieldName) { return static_cast(obj)->getImageFile() != StringTable->EmptyString(); } + + // Gen mips? + static bool setGenMips(void* obj, StringTableEntry index, StringTableEntry data) { static_cast(obj)->setGenMips(dAtob(data)); return false; } + static bool writeGenMips(void* obj, StringTableEntry pFieldName) { return static_cast(obj)->getGenMips() == true; } + + // Texture Is Hdr? + static bool setTextureHDR(void* obj, StringTableEntry index, StringTableEntry data) { static_cast(obj)->setTextureHDR(dAtob(data)); return false; } + static bool writeTextureHDR(void* obj, StringTableEntry pFieldName) { return static_cast(obj)->getTextureHDR() == true; } }; -DefineConsoleType(TypeImageAssetPtr, ImageAsset) -DefineConsoleType(TypeImageAssetId, String) +DECLARE_STRUCT(AssetPtr) +DefineConsoleType(TypeImageAssetPtr, AssetPtr ) typedef ImageAsset::ImageTypes ImageAssetType; DefineEnumType(ImageAssetType); -#pragma region Singular Asset Macros +#pragma region Refactor Asset Macros -//Singular assets -/// -/// Declares an image asset -/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions -/// -#define DECLARE_IMAGEASSET(className, name, changeFunc, profile) public: \ - GFXTexHandle m##name = NULL;\ - StringTableEntry m##name##Name; \ - StringTableEntry m##name##AssetId;\ - AssetPtr 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 & get##name##Asset() const { return m##name##Asset; }\ - void set##name##Asset(const AssetPtr &_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 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 get##name##Asset(void) { return m##name##Asset; } \ + static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast(obj)->_set##name(_getStringTable()->insert(data)); return false;} -#pragma endregion +#define DECLARE_IMAGEASSET_NET(className, name, profile, mask) \ +private: \ + AssetPtr 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 get##name##Asset(void) { return m##name##Asset; } \ + static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast(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 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 & get##name##Asset(const U32& index) const { return m##name##Asset[index]; }\ - void set##name##Asset(const AssetPtr &_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(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(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 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 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(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 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 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(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 - - diff --git a/Engine/source/T3D/assets/LevelAsset.cpp b/Engine/source/T3D/assets/LevelAsset.cpp index 2cb2febe4..067a71121 100644 --- a/Engine/source/T3D/assets/LevelAsset.cpp +++ b/Engine/source/T3D/assets/LevelAsset.cpp @@ -229,7 +229,7 @@ StringTableEntry LevelAsset::getPreviewImagePath(void) const { if (mPreviewImageAsset.notNull() && mPreviewImageAsset->isAssetValid()) { - return mPreviewImageAsset->getImagePath(); + return mPreviewImageAsset->getImageFile(); } return StringTable->EmptyString(); diff --git a/Engine/source/T3D/assets/MaterialAsset.cpp b/Engine/source/T3D/assets/MaterialAsset.cpp index abedd6204..9bb30145d 100644 --- a/Engine/source/T3D/assets/MaterialAsset.cpp +++ b/Engine/source/T3D/assets/MaterialAsset.cpp @@ -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(assetId); - dependent->refreshAsset(); + load(); } } @@ -644,7 +626,7 @@ void GuiInspectorTypeMaterialAssetPtr::updatePreviewImage() MaterialAsset* matAsset = AssetDatabase.acquireAsset(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(assetId); if (matAsset && matAsset->getMaterialDefinition()) { - mPreviewImage->_setBitmap(matAsset->getMaterialDefinition()->mDiffuseMapAssetId[0]); + mPreviewImage->_setBitmap(matAsset->getMaterialDefinition()->_getDiffuseMap(0)); } } } diff --git a/Engine/source/T3D/assets/assetImporter.cpp b/Engine/source/T3D/assets/assetImporter.cpp index ae179e195..8fbdc85f9 100644 --- a/Engine/source/T3D/assets/assetImporter.cpp +++ b/Engine/source/T3D/assets/assetImporter.cpp @@ -1884,7 +1884,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem) { //got a match! ImageAsset* foundImageAsset = AssetDatabase.acquireAsset(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(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; } } diff --git a/Engine/source/T3D/assets/assetMacroHelpers.h b/Engine/source/T3D/assets/assetMacroHelpers.h index ef37cd7d5..ebe777bf0 100644 --- a/Engine/source/T3D/assets/assetMacroHelpers.h +++ b/Engine/source/T3D/assets/assetMacroHelpers.h @@ -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)\ diff --git a/Engine/source/T3D/fx/groundCover.cpp b/Engine/source/T3D/fx/groundCover.cpp index 072ef6463..3f4343184 100644 --- a/Engine/source/T3D/fx/groundCover.cpp +++ b/Engine/source/T3D/fx/groundCover.cpp @@ -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()) { diff --git a/Engine/source/T3D/fx/particle.cpp b/Engine/source/T3D/fx/particle.cpp index a41aa13e2..b2457dfea 100644 --- a/Engine/source/T3D/fx/particle.cpp +++ b/Engine/source/T3D/fx/particle.cpp @@ -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 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; diff --git a/Engine/source/T3D/fx/particleEmitter.cpp b/Engine/source/T3D/fx/particleEmitter.cpp index 00470eb8a..e6559b612 100644 --- a/Engine/source/T3D/fx/particleEmitter.cpp +++ b/Engine/source/T3D/fx/particleEmitter.cpp @@ -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; diff --git a/Engine/source/T3D/fx/precipitation.cpp b/Engine/source/T3D/fx/precipitation.cpp index b56893ea1..6ac3c75c9 100644 --- a/Engine/source/T3D/fx/precipitation.cpp +++ b/Engine/source/T3D/fx/precipitation.cpp @@ -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 ) { diff --git a/Engine/source/T3D/fx/precipitation.h b/Engine/source/T3D/fx/precipitation.h index a3ca97c40..96fe3844e 100644 --- a/Engine/source/T3D/fx/precipitation.h +++ b/Engine/source/T3D/fx/precipitation.h @@ -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 diff --git a/Engine/source/T3D/fx/splash.cpp b/Engine/source/T3D/fx/splash.cpp index 77edaae76..d9be0cddb 100644 --- a/Engine/source/T3D/fx/splash.cpp +++ b/Engine/source/T3D/fx/splash.cpp @@ -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; iwriteRangedU32(explosion->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast); } + PACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX); + S32 i; for( i=0; iwrite( times[i] ); } - - for( i=0; ireadRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast ); } + UNPACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX); + U32 i; for( i=0; iread( ×[i] ); } - - for( i=0; i* outGameModes); - void previewChange() {} - DECLARE_CALLBACK(void, onActivated, ()); DECLARE_CALLBACK(void, onDeactivated, ()); DECLARE_CALLBACK(void, onSceneLoaded, ()); diff --git a/Engine/source/T3D/levelInfo.cpp b/Engine/source/T3D/levelInfo.cpp index f583e2515..82d3b55c5 100644 --- a/Engine/source/T3D/levelInfo.cpp +++ b/Engine/source/T3D/levelInfo.cpp @@ -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(); } diff --git a/Engine/source/T3D/levelInfo.h b/Engine/source/T3D/levelInfo.h index 91da71791..593910dd4 100644 --- a/Engine/source/T3D/levelInfo.h +++ b/Engine/source/T3D/levelInfo.h @@ -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(); /// @} }; diff --git a/Engine/source/T3D/lightFlareData.cpp b/Engine/source/T3D/lightFlareData.cpp index ad1daa5d9..0ee3821d6 100644 --- a/Engine/source/T3D/lightFlareData.cpp +++ b/Engine/source/T3D/lightFlareData.cpp @@ -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. diff --git a/Engine/source/T3D/lightFlareData.h b/Engine/source/T3D/lightFlareData.h index baa74c39b..e31c8c752 100644 --- a/Engine/source/T3D/lightFlareData.h +++ b/Engine/source/T3D/lightFlareData.h @@ -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; diff --git a/Engine/source/T3D/lighting/reflectionProbe.cpp b/Engine/source/T3D/lighting/reflectionProbe.cpp index 793f7dd1d..b4a10342f 100644 --- a/Engine/source/T3D/lighting/reflectionProbe.cpp +++ b/Engine/source/T3D/lighting/reflectionProbe.cpp @@ -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; } diff --git a/Engine/source/afx/afxZodiacGroundPlaneRenderer_T3D.cpp b/Engine/source/afx/afxZodiacGroundPlaneRenderer_T3D.cpp index 0aff99e6c..e138789ad 100644 --- a/Engine/source/afx/afxZodiacGroundPlaneRenderer_T3D.cpp +++ b/Engine/source/afx/afxZodiacGroundPlaneRenderer_T3D.cpp @@ -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); diff --git a/Engine/source/afx/afxZodiacMeshRoadRenderer_T3D.cpp b/Engine/source/afx/afxZodiacMeshRoadRenderer_T3D.cpp index cb8fabfc5..6f6eb1b80 100644 --- a/Engine/source/afx/afxZodiacMeshRoadRenderer_T3D.cpp +++ b/Engine/source/afx/afxZodiacMeshRoadRenderer_T3D.cpp @@ -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); diff --git a/Engine/source/afx/afxZodiacPolysoupRenderer_T3D.cpp b/Engine/source/afx/afxZodiacPolysoupRenderer_T3D.cpp index 2e100332a..629228974 100644 --- a/Engine/source/afx/afxZodiacPolysoupRenderer_T3D.cpp +++ b/Engine/source/afx/afxZodiacPolysoupRenderer_T3D.cpp @@ -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); diff --git a/Engine/source/afx/afxZodiacTerrainRenderer_T3D.cpp b/Engine/source/afx/afxZodiacTerrainRenderer_T3D.cpp index 04c54f667..cf4b8d8b2 100644 --- a/Engine/source/afx/afxZodiacTerrainRenderer_T3D.cpp +++ b/Engine/source/afx/afxZodiacTerrainRenderer_T3D.cpp @@ -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); diff --git a/Engine/source/afx/ce/afxBillboard.cpp b/Engine/source/afx/ce/afxBillboard.cpp index ce541f4b1..9134c0354 100644 --- a/Engine/source/afx/ce/afxBillboard.cpp +++ b/Engine/source/afx/ce/afxBillboard.cpp @@ -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]); diff --git a/Engine/source/afx/ce/afxBillboard.h b/Engine/source/afx/ce/afxBillboard.h index 81542f716..34e278206 100644 --- a/Engine/source/afx/ce/afxBillboard.h +++ b/Engine/source/afx/ce/afxBillboard.h @@ -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); }; diff --git a/Engine/source/afx/ce/afxBillboard_T3D.cpp b/Engine/source/afx/ce/afxBillboard_T3D.cpp index 366a867aa..20d5b9abc 100644 --- a/Engine/source/afx/ce/afxBillboard_T3D.cpp +++ b/Engine/source/afx/ce/afxBillboard_T3D.cpp @@ -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(); diff --git a/Engine/source/afx/ce/afxZodiac.cpp b/Engine/source/afx/ce/afxZodiac.cpp index 70767b54c..2df200230 100644 --- a/Engine/source/afx/ce/afxZodiac.cpp +++ b/Engine/source/afx/ce/afxZodiac.cpp @@ -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(); } } diff --git a/Engine/source/afx/ce/afxZodiac.h b/Engine/source/afx/ce/afxZodiac.h index 16f4a8d79..501dfc034 100644 --- a/Engine/source/afx/ce/afxZodiac.h +++ b/Engine/source/afx/ce/afxZodiac.h @@ -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; diff --git a/Engine/source/afx/ce/afxZodiacMgr.cpp b/Engine/source/afx/ce/afxZodiacMgr.cpp index fe9924128..ecac36afa 100644 --- a/Engine/source/afx/ce/afxZodiacMgr.cpp +++ b/Engine/source/afx/ce/afxZodiacMgr.cpp @@ -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; diff --git a/Engine/source/afx/ce/afxZodiacMgr.h b/Engine/source/afx/ce/afxZodiacMgr.h index 0141b3ed4..a243482ba 100644 --- a/Engine/source/afx/ce/afxZodiacMgr.h +++ b/Engine/source/afx/ce/afxZodiacMgr.h @@ -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; diff --git a/Engine/source/afx/ce/afxZodiacPlane.cpp b/Engine/source/afx/ce/afxZodiacPlane.cpp index c4b525511..c57eeda05 100644 --- a/Engine/source/afx/ce/afxZodiacPlane.cpp +++ b/Engine/source/afx/ce/afxZodiacPlane.cpp @@ -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); diff --git a/Engine/source/afx/ce/afxZodiacPlane.h b/Engine/source/afx/ce/afxZodiacPlane.h index a32a14d26..9e7cef512 100644 --- a/Engine/source/afx/ce/afxZodiacPlane.h +++ b/Engine/source/afx/ce/afxZodiacPlane.h @@ -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; diff --git a/Engine/source/afx/ce/afxZodiacPlane_T3D.cpp b/Engine/source/afx/ce/afxZodiacPlane_T3D.cpp index 22cb949b3..f55af2a00 100644 --- a/Engine/source/afx/ce/afxZodiacPlane_T3D.cpp +++ b/Engine/source/afx/ce/afxZodiacPlane_T3D.cpp @@ -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); { diff --git a/Engine/source/afx/util/afxParticlePool_T3D.cpp b/Engine/source/afx/util/afxParticlePool_T3D.cpp index c8cc7c9ed..4ad24e68a 100644 --- a/Engine/source/afx/util/afxParticlePool_T3D.cpp +++ b/Engine/source/afx/util/afxParticlePool_T3D.cpp @@ -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; diff --git a/Engine/source/assets/assetManager.cpp b/Engine/source/assets/assetManager.cpp index e2c6d1133..0b166a238 100644 --- a/Engine/source/assets/assetManager.cpp +++ b/Engine/source/assets/assetManager.cpp @@ -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 ); } diff --git a/Engine/source/environment/VolumetricFog.cpp b/Engine/source/environment/VolumetricFog.cpp index 1d3593b2b..05ee73da0 100644 --- a/Engine/source/environment/VolumetricFog.cpp +++ b/Engine/source/environment/VolumetricFog.cpp @@ -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); } } diff --git a/Engine/source/environment/VolumetricFog.h b/Engine/source/environment/VolumetricFog.h index a85ef1665..42f085eab 100644 --- a/Engine/source/environment/VolumetricFog.h +++ b/Engine/source/environment/VolumetricFog.h @@ -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(); diff --git a/Engine/source/environment/basicClouds.cpp b/Engine/source/environment/basicClouds.cpp index 755486a03..02286bccc 100644 --- a/Engine/source/environment/basicClouds.cpp +++ b/Engine/source/environment/basicClouds.cpp @@ -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); } } diff --git a/Engine/source/environment/basicClouds.h b/Engine/source/environment/basicClouds.h index bd67d1362..1fb2d06e0 100644 --- a/Engine/source/environment/basicClouds.h +++ b/Engine/source/environment/basicClouds.h @@ -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; diff --git a/Engine/source/environment/cloudLayer.cpp b/Engine/source/environment/cloudLayer.cpp index fe71d9f68..f65782c12 100644 --- a/Engine/source/environment/cloudLayer.cpp +++ b/Engine/source/environment/cloudLayer.cpp @@ -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 ); diff --git a/Engine/source/environment/cloudLayer.h b/Engine/source/environment/cloudLayer.h index ba8110c39..3f7dca6b4 100644 --- a/Engine/source/environment/cloudLayer.h +++ b/Engine/source/environment/cloudLayer.h @@ -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; diff --git a/Engine/source/environment/waterObject.cpp b/Engine/source/environment/waterObject.cpp index dba34615a..a98861d32 100644 --- a/Engine/source/environment/waterObject.cpp +++ b/Engine/source/environment/waterObject.cpp @@ -260,10 +260,6 @@ WaterObject::WaterObject() mMatrixSet = reinterpret_cast(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 ¶mHandles ) { // 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 ); diff --git a/Engine/source/environment/waterObject.h b/Engine/source/environment/waterObject.h index 09f3e1eaa..c925f4a07 100644 --- a/Engine/source/environment/waterObject.h +++ b/Engine/source/environment/waterObject.h @@ -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; diff --git a/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp b/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp index 7a763cd27..710977acd 100644 --- a/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp +++ b/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp @@ -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 diff --git a/Engine/source/gfx/sim/cubemapData.cpp b/Engine/source/gfx/sim/cubemapData.cpp index 0e7d7686e..d257027b2 100644 --- a/Engine/source/gfx/sim/cubemapData.cpp +++ b/Engine/source/gfx/sim/cubemapData.cpp @@ -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, (),, diff --git a/Engine/source/gfx/sim/cubemapData.h b/Engine/source/gfx/sim/cubemapData.h index c79dd4289..2d2385deb 100644 --- a/Engine/source/gfx/sim/cubemapData.h +++ b/Engine/source/gfx/sim/cubemapData.h @@ -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 diff --git a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp index e2ef9d344..e6f063428 100644 --- a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp @@ -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) diff --git a/Engine/source/gui/buttons/guiBitmapButtonCtrl.h b/Engine/source/gui/buttons/guiBitmapButtonCtrl.h index 8674432ec..1194809d7 100644 --- a/Engine/source/gui/buttons/guiBitmapButtonCtrl.h +++ b/Engine/source/gui/buttons/guiBitmapButtonCtrl.h @@ -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 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 getBitmapAsset(void) { + return mBitmapAsset; +} static bool _setBitmapData(void* obj, const char* index, const char* data) { + static_cast(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(obj); - object->setBitmap(StringTable->insert(data)); - return false; - } }; typedef GuiBitmapButtonCtrl::BitmapMode GuiBitmapMode; diff --git a/Engine/source/gui/buttons/guiCheckBoxCtrl.cpp b/Engine/source/gui/buttons/guiCheckBoxCtrl.cpp index 93e51168b..ffb63dfb9 100644 --- a/Engine/source/gui/buttons/guiCheckBoxCtrl.cpp +++ b/Engine/source/gui/buttons/guiCheckBoxCtrl.cpp @@ -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') diff --git a/Engine/source/gui/buttons/guiIconButtonCtrl.cpp b/Engine/source/gui/buttons/guiIconButtonCtrl.cpp index b05fd6e0b..9d0093802 100644 --- a/Engine/source/gui/buttons/guiIconButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiIconButtonCtrl.cpp @@ -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) diff --git a/Engine/source/gui/buttons/guiIconButtonCtrl.h b/Engine/source/gui/buttons/guiIconButtonCtrl.h index d4b00bfbc..786997bb1 100644 --- a/Engine/source/gui/buttons/guiIconButtonCtrl.h +++ b/Engine/source/gui/buttons/guiIconButtonCtrl.h @@ -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; diff --git a/Engine/source/gui/buttons/guiToolboxButtonCtrl.cpp b/Engine/source/gui/buttons/guiToolboxButtonCtrl.cpp index dc2c92d61..a2b711956 100644 --- a/Engine/source/gui/buttons/guiToolboxButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiToolboxButtonCtrl.cpp @@ -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) diff --git a/Engine/source/gui/buttons/guiToolboxButtonCtrl.h b/Engine/source/gui/buttons/guiToolboxButtonCtrl.h index 9d56308ad..893fc156d 100644 --- a/Engine/source/gui/buttons/guiToolboxButtonCtrl.h +++ b/Engine/source/gui/buttons/guiToolboxButtonCtrl.h @@ -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); diff --git a/Engine/source/gui/containers/guiFormCtrl.cpp b/Engine/source/gui/containers/guiFormCtrl.cpp index 3bf3289f4..8fd333071 100644 --- a/Engine/source/gui/containers/guiFormCtrl.cpp +++ b/Engine/source/gui/containers/guiFormCtrl.cpp @@ -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)); diff --git a/Engine/source/gui/containers/guiPaneCtrl.cpp b/Engine/source/gui/containers/guiPaneCtrl.cpp index d646e2f44..e5d3d70fa 100644 --- a/Engine/source/gui/containers/guiPaneCtrl.cpp +++ b/Engine/source/gui/containers/guiPaneCtrl.cpp @@ -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] ); diff --git a/Engine/source/gui/containers/guiScrollCtrl.cpp b/Engine/source/gui/containers/guiScrollCtrl.cpp index 5928d7abc..79d363f62 100644 --- a/Engine/source/gui/containers/guiScrollCtrl.cpp +++ b/Engine/source/gui/containers/guiScrollCtrl.cpp @@ -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(); diff --git a/Engine/source/gui/containers/guiWindowCtrl.cpp b/Engine/source/gui/containers/guiWindowCtrl.cpp index 68f04c708..e4b7d80e6 100644 --- a/Engine/source/gui/containers/guiWindowCtrl.cpp +++ b/Engine/source/gui/containers/guiWindowCtrl.cpp @@ -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; diff --git a/Engine/source/gui/controls/guiBitmapBorderCtrl.cpp b/Engine/source/gui/controls/guiBitmapBorderCtrl.cpp index 05d0fea47..e0997215c 100644 --- a/Engine/source/gui/controls/guiBitmapBorderCtrl.cpp +++ b/Engine/source/gui/controls/guiBitmapBorderCtrl.cpp @@ -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 diff --git a/Engine/source/gui/controls/guiBitmapCtrl.cpp b/Engine/source/gui/controls/guiBitmapCtrl.cpp index 04f17e16b..bcf667361 100644 --- a/Engine/source/gui/controls/guiBitmapCtrl.cpp +++ b/Engine/source/gui/controls/guiBitmapCtrl.cpp @@ -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( 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 diff --git a/Engine/source/gui/controls/guiBitmapCtrl.h b/Engine/source/gui/controls/guiBitmapCtrl.h index b641fd5a2..adf6f5322 100644 --- a/Engine/source/gui/controls/guiBitmapCtrl.h +++ b/Engine/source/gui/controls/guiBitmapCtrl.h @@ -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 diff --git a/Engine/source/gui/controls/guiGameListMenuCtrl.cpp b/Engine/source/gui/controls/guiGameListMenuCtrl.cpp index 1c71b17ac..ec7c8df5f 100644 --- a/Engine/source/gui/controls/guiGameListMenuCtrl.cpp +++ b/Engine/source/gui/controls/guiGameListMenuCtrl.cpp @@ -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() ); diff --git a/Engine/source/gui/controls/guiGameListOptionsCtrl.cpp b/Engine/source/gui/controls/guiGameListOptionsCtrl.cpp index 52d5bd006..b277d584d 100644 --- a/Engine/source/gui/controls/guiGameListOptionsCtrl.cpp +++ b/Engine/source/gui/controls/guiGameListOptionsCtrl.cpp @@ -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 diff --git a/Engine/source/gui/controls/guiGameSettingsCtrl.cpp b/Engine/source/gui/controls/guiGameSettingsCtrl.cpp index 0ee7cb91f..b782f3024 100644 --- a/Engine/source/gui/controls/guiGameSettingsCtrl.cpp +++ b/Engine/source/gui/controls/guiGameSettingsCtrl.cpp @@ -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(); } diff --git a/Engine/source/gui/controls/guiGameSettingsCtrl.h b/Engine/source/gui/controls/guiGameSettingsCtrl.h index 737761745..6c2f69d70 100644 --- a/Engine/source/gui/controls/guiGameSettingsCtrl.h +++ b/Engine/source/gui/controls/guiGameSettingsCtrl.h @@ -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(); diff --git a/Engine/source/gui/controls/guiPopUpCtrl.cpp b/Engine/source/gui/controls/guiPopUpCtrl.cpp index fb325dd4e..9ec981352 100644 --- a/Engine/source/gui/controls/guiPopUpCtrl.cpp +++ b/Engine/source/gui/controls/guiPopUpCtrl.cpp @@ -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? diff --git a/Engine/source/gui/controls/guiPopUpCtrl.h b/Engine/source/gui/controls/guiPopUpCtrl.h index 12568d2c6..0528612ea 100644 --- a/Engine/source/gui/controls/guiPopUpCtrl.h +++ b/Engine/source/gui/controls/guiPopUpCtrl.h @@ -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; diff --git a/Engine/source/gui/controls/guiPopUpCtrlEx.cpp b/Engine/source/gui/controls/guiPopUpCtrlEx.cpp index 1005780b5..7e99f20d9 100644 --- a/Engine/source/gui/controls/guiPopUpCtrlEx.cpp +++ b/Engine/source/gui/controls/guiPopUpCtrlEx.cpp @@ -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(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(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? diff --git a/Engine/source/gui/controls/guiPopUpCtrlEx.h b/Engine/source/gui/controls/guiPopUpCtrlEx.h index f389de3e7..b6501d991 100644 --- a/Engine/source/gui/controls/guiPopUpCtrlEx.h +++ b/Engine/source/gui/controls/guiPopUpCtrlEx.h @@ -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; diff --git a/Engine/source/gui/controls/guiSliderCtrl.cpp b/Engine/source/gui/controls/guiSliderCtrl.cpp index c5f4a90b6..4ab0d6850 100644 --- a/Engine/source/gui/controls/guiSliderCtrl.cpp +++ b/Engine/source/gui/controls/guiSliderCtrl.cpp @@ -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()) diff --git a/Engine/source/gui/controls/guiTreeViewCtrl.cpp b/Engine/source/gui/controls/guiTreeViewCtrl.cpp index 2e6a1e8b8..568e2e205 100644 --- a/Engine/source/gui/controls/guiTreeViewCtrl.cpp +++ b/Engine/source/gui/controls/guiTreeViewCtrl.cpp @@ -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; } diff --git a/Engine/source/gui/core/guiDefaultControlRender.cpp b/Engine/source/gui/core/guiDefaultControlRender.cpp index f5389968e..ff4bc1071 100644 --- a/Engine/source/gui/core/guiDefaultControlRender.cpp +++ b/Engine/source/gui/core/guiDefaultControlRender.cpp @@ -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 } diff --git a/Engine/source/gui/core/guiTypes.cpp b/Engine/source/gui/core/guiTypes.cpp index 09e88659a..5bccfce36 100644 --- a/Engine/source/gui/core/guiTypes.cpp +++ b/Engine/source/gui/core/guiTypes.cpp @@ -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)); } //----------------------------------------------------------------------------- diff --git a/Engine/source/gui/core/guiTypes.h b/Engine/source/gui/core/guiTypes.h index a96dd92f1..9c21e54de 100644 --- a/Engine/source/gui/core/guiTypes.h +++ b/Engine/source/gui/core/guiTypes.h @@ -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 mBitmapAsset; - GFXTextureProfile* mBitmapProfile = &GFXDefaultGUIProfile; -public: - const StringTableEntry getBitmapFile() const { return mBitmapName; } - void setBitmapFile(const FileName& _in) { mBitmapName = StringTable->insert(_in.c_str()); } - const AssetPtr& getBitmapAsset() const { return mBitmapAsset; } - void setBitmapAsset(const AssetPtr& _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 mBitmapArrayRects; ///< Used for controls which use an array of bitmaps such as checkboxes diff --git a/Engine/source/gui/editor/guiMenuBar.cpp b/Engine/source/gui/editor/guiMenuBar.cpp index b33079799..e1bba7390 100644 --- a/Engine/source/gui/editor/guiMenuBar.cpp +++ b/Engine/source/gui/editor/guiMenuBar.cpp @@ -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(pObject); + PopupMenu* menu = nullptr; + if (pObject != nullptr) + { + menu = dynamic_cast(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(pObject); + PopupMenu* menu = nullptr; + if (pObject != nullptr) + { + menu = dynamic_cast(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; } diff --git a/Engine/source/gui/editor/guiPopupMenuCtrl.cpp b/Engine/source/gui/editor/guiPopupMenuCtrl.cpp index e9a9fcf33..ccb8eacbb 100644 --- a/Engine/source/gui/editor/guiPopupMenuCtrl.cpp +++ b/Engine/source/gui/editor/guiPopupMenuCtrl.cpp @@ -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); } } diff --git a/Engine/source/gui/editor/inspector/dynamicField.cpp b/Engine/source/gui/editor/inspector/dynamicField.cpp index fbf61314c..137384971 100644 --- a/Engine/source/gui/editor/inspector/dynamicField.cpp +++ b/Engine/source/gui/editor/inspector/dynamicField.cpp @@ -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 ); diff --git a/Engine/source/gui/editor/inspector/group.cpp b/Engine/source/gui/editor/inspector/group.cpp index 38070feed..6bd243d60 100644 --- a/Engine/source/gui/editor/inspector/group.cpp +++ b/Engine/source/gui/editor/inspector/group.cpp @@ -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")) diff --git a/Engine/source/gui/editor/inspector/variableInspector.cpp b/Engine/source/gui/editor/inspector/variableInspector.cpp index c856c8b1a..41a165d32 100644 --- a/Engine/source/gui/editor/inspector/variableInspector.cpp +++ b/Engine/source/gui/editor/inspector/variableInspector.cpp @@ -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")) diff --git a/Engine/source/gui/game/guiChunkedBitmapCtrl.cpp b/Engine/source/gui/game/guiChunkedBitmapCtrl.cpp index 4aab2a247..b926205f9 100644 --- a/Engine/source/gui/game/guiChunkedBitmapCtrl.cpp +++ b/Engine/source/gui/game/guiChunkedBitmapCtrl.cpp @@ -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); diff --git a/Engine/source/gui/game/guiChunkedBitmapCtrl.h b/Engine/source/gui/game/guiChunkedBitmapCtrl.h index 08db54166..e12e0c4c1 100644 --- a/Engine/source/gui/game/guiChunkedBitmapCtrl.h +++ b/Engine/source/gui/game/guiChunkedBitmapCtrl.h @@ -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() {} }; diff --git a/Engine/source/gui/game/guiProgressBitmapCtrl.cpp b/Engine/source/gui/game/guiProgressBitmapCtrl.cpp index 0d85213e1..4689d70c5 100644 --- a/Engine/source/gui/game/guiProgressBitmapCtrl.cpp +++ b/Engine/source/gui/game/guiProgressBitmapCtrl.cpp @@ -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 diff --git a/Engine/source/gui/game/guiProgressBitmapCtrl.h b/Engine/source/gui/game/guiProgressBitmapCtrl.h index 54c702f19..c134ae1a8 100644 --- a/Engine/source/gui/game/guiProgressBitmapCtrl.h +++ b/Engine/source/gui/game/guiProgressBitmapCtrl.h @@ -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: diff --git a/Engine/source/gui/worldEditor/guiMissionArea.cpp b/Engine/source/gui/worldEditor/guiMissionArea.cpp index 9302c12b0..8963911da 100644 --- a/Engine/source/gui/worldEditor/guiMissionArea.cpp +++ b/Engine/source/gui/worldEditor/guiMissionArea.cpp @@ -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) diff --git a/Engine/source/gui/worldEditor/guiMissionArea.h b/Engine/source/gui/worldEditor/guiMissionArea.h index 97c9013c5..302bda930 100644 --- a/Engine/source/gui/worldEditor/guiMissionArea.h +++ b/Engine/source/gui/worldEditor/guiMissionArea.h @@ -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(); diff --git a/Engine/source/gui/worldEditor/worldEditor.cpp b/Engine/source/gui/worldEditor/worldEditor.cpp index 706ee2b8f..d4008a95b 100644 --- a/Engine/source/gui/worldEditor/worldEditor.cpp +++ b/Engine/source/gui/worldEditor/worldEditor.cpp @@ -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; diff --git a/Engine/source/gui/worldEditor/worldEditor.h b/Engine/source/gui/worldEditor/worldEditor.h index 3cac2d0ce..40cc888a1 100644 --- a/Engine/source/gui/worldEditor/worldEditor.h +++ b/Engine/source/gui/worldEditor/worldEditor.h @@ -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; diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index 02f15ea57..cd175fd80 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -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) diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index 815c77b90..b76aadd6f 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -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]; diff --git a/Engine/source/materials/materialManager.cpp b/Engine/source/materials/materialManager.cpp index 87ce2bef2..97dd0b848 100644 --- a/Engine/source/materials/materialManager.cpp +++ b/Engine/source/materials/materialManager.cpp @@ -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::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::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: diff --git a/Engine/source/materials/materialManager.h b/Engine/source/materials/materialManager.h index 2d983da7a..6d0fbdd53 100644 --- a/Engine/source/materials/materialManager.h +++ b/Engine/source/materials/materialManager.h @@ -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 MaterialMap; @@ -174,8 +169,6 @@ protected: F32 mDampness; BaseMatInstance* mWarningInst; - BaseMaterialDefinition* mMatDefToFlush; - BaseMaterialDefinition* mMatDefToReload; /// The default max anisotropy used in texture filtering. S32 mDefaultAnisotropy; diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index a4841ac6d..ea2a0aa86 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -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); } } diff --git a/Engine/source/materials/processedShaderMaterial.cpp b/Engine/source/materials/processedShaderMaterial.cpp index 17768ef38..605e9dc6c 100644 --- a/Engine/source/materials/processedShaderMaterial.cpp +++ b/Engine/source/materials/processedShaderMaterial.cpp @@ -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 &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) diff --git a/Engine/source/math/mMathFn.h b/Engine/source/math/mMathFn.h index 1c65604a1..9f84b37df 100644 --- a/Engine/source/math/mMathFn.h +++ b/Engine/source/math/mMathFn.h @@ -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_ diff --git a/Engine/source/postFx/postEffect.cpp b/Engine/source/postFx/postEffect.cpp index 8026dd392..ef9ef2fa6 100644 --- a/Engine/source/postFx/postEffect.cpp +++ b/Engine/source/postFx/postEffect.cpp @@ -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(¯os); + if (texFilename.isNotEmpty() && texFilename[0] == '#') + { + NamedTexTarget* namedTarget = NamedTexTarget::find(texFilename.c_str() + 1); + if (!namedTarget) + { + return; + } + + // Grab the macros for shader initialization. + namedTarget->getShaderMacros(¯os); + } } } } diff --git a/Engine/source/postFx/postEffect.h b/Engine/source/postFx/postEffect.h index e485f14d2..456b7578d 100644 --- a/Engine/source/postFx/postEffect.h +++ b/Engine/source/postFx/postEffect.h @@ -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]; diff --git a/Engine/source/postFx/postEffectVis.cpp b/Engine/source/postFx/postEffectVis.cpp index a3ff66b9c..4a7442b72 100644 --- a/Engine/source/postFx/postEffectVis.cpp +++ b/Engine/source/postFx/postEffectVis.cpp @@ -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 ); } diff --git a/Engine/source/renderInstance/renderDeferredMgr.cpp b/Engine/source/renderInstance/renderDeferredMgr.cpp index 65276a111..e7fd4f907 100644 --- a/Engine/source/renderInstance/renderDeferredMgr.cpp +++ b/Engine/source/renderInstance/renderDeferredMgr.cpp @@ -883,11 +883,10 @@ bool DeferredMatInstance::init( const FeatureSet &features, { bool vaild = Parent::init(features, vertexFormat); - if (mMaterial && mMaterial->getDiffuseMap(0) != StringTable->EmptyString() && String(mMaterial->getDiffuseMap(0)).startsWith("#")) + if (mMaterial && mMaterial->getDiffuseMapAsset(0).notNull() && String(mMaterial->getDiffuseMapAsset(0)->getImageFile()).startsWith("#")) { - String difName = mMaterial->getDiffuseMap(0); - String texTargetBufferName = difName.substr(1, difName.length() - 1); - NamedTexTarget *texTarget = NamedTexTarget::find(texTargetBufferName); + String texTargetBufferName = String(mMaterial->getDiffuseMapAsset(0)->getImageFile()).substr(1, (U32)strlen(mMaterial->getDiffuseMapAsset(0)->getImageFile()) - 1); + NamedTexTarget* texTarget = NamedTexTarget::find(texTargetBufferName); RenderPassData* rpd = getPass(0); if (rpd) diff --git a/Engine/source/terrain/terrCellMaterial.cpp b/Engine/source/terrain/terrCellMaterial.cpp index 5c7756c00..7ea7ea69c 100644 --- a/Engine/source/terrain/terrCellMaterial.cpp +++ b/Engine/source/terrain/terrCellMaterial.cpp @@ -374,7 +374,7 @@ bool TerrainCellMaterial::_initShader(bool deferredMat, // We only include materials that // have more than a base texture. - if (!(mat->DetailMapValid() && mat->getDetailSize() > 0 && mat->getDetailDistance()>0)) + if (!(mat->getDetailMap() && mat->getDetailSize() > 0 && mat->getDetailDistance()>0)) continue; if (deferredMat) @@ -382,12 +382,12 @@ bool TerrainCellMaterial::_initShader(bool deferredMat, features.addFeature(MFT_TerrainDetailMap, featureIndex); // check for macro detail texture - if (mat->MacroMapValid() && mat->getMacroSize() > 0 && mat->getMacroDistance() > 0) + if (mat->getMacroMap() && mat->getMacroSize() > 0 && mat->getMacroDistance() > 0) { features.addFeature(MFT_TerrainMacroMap, featureIndex); } - if (mat->ORMConfigMapValid()) + if (mat->getORMConfigMap()) { features.addFeature(MFT_TerrainORMMap, featureIndex); } @@ -401,12 +401,12 @@ bool TerrainCellMaterial::_initShader(bool deferredMat, // Skip normal maps if we need to. - if (!disableNormalMaps && mat->NormalMapValid()) + if (!disableNormalMaps && mat->getNormalMap()) { normalMaps.increment(); features.addFeature(MFT_TerrainNormalMap, featureIndex); - normalMaps.last() = mat->getNormalMapResource(); + normalMaps.last() = mat->getNormalMap(); GFXFormat normalFmt = normalMaps.last().getFormat(); if (normalFmt == GFXFormatBC3) @@ -632,7 +632,7 @@ bool TerrainCellMaterial::_initShader(bool deferredMat, // We only include materials that // have more than a base texture. - if (!(mat->DetailMapValid() && mat->getDetailSize() > 0 && mat->getDetailDistance() > 0)) + if (!(mat->getDetailMap() && mat->getDetailSize() > 0 && mat->getDetailDistance() > 0)) continue; mMaterialInfos[i]->mBlendDepthConst = mShader->getShaderConstHandle(avar("$blendDepth%d", i)); @@ -676,7 +676,7 @@ void TerrainCellMaterial::_updateMaterialConsts( ) if (mat == NULL) continue; - if (!(mat->DetailMapValid() && mat->getDetailSize() > 0 && mat->getDetailDistance() > 0)) + if (!(mat->getDetailMap() && mat->getDetailSize() > 0 && mat->getDetailDistance() > 0)) continue; detailMatCount++; @@ -704,7 +704,7 @@ void TerrainCellMaterial::_updateMaterialConsts( ) if (mat == NULL) continue; - if (!(mat->DetailMapValid() && mat->getDetailSize() > 0 && mat->getDetailDistance() > 0)) + if (!(mat->getDetailMap() && mat->getDetailSize() > 0 && mat->getDetailDistance() > 0)) continue; F32 detailSize = matInfo->mat->getDetailSize(); diff --git a/Engine/source/terrain/terrMaterial.cpp b/Engine/source/terrain/terrMaterial.cpp index 85d3f4812..33e625f99 100644 --- a/Engine/source/terrain/terrMaterial.cpp +++ b/Engine/source/terrain/terrMaterial.cpp @@ -81,11 +81,6 @@ TerrainMaterial::TerrainMaterial() mIsSRGB(false), mInvertRoughness(false) { - INIT_ASSET(DiffuseMap); - INIT_ASSET(NormalMap); - INIT_ASSET(DetailMap); - INIT_ASSET(ORMConfigMap); - INIT_ASSET(MacroMap); } TerrainMaterial::~TerrainMaterial() @@ -102,6 +97,7 @@ void TerrainMaterial::initPersistFields() INITPERSISTFIELD_IMAGEASSET(NormalMap, TerrainMaterial,"NormalMap"); addFieldV( "parallaxScale", TypeRangedF32, Offset( mParallaxScale, TerrainMaterial ), &CommonValidators::PositiveFloat, "Used to scale the height from the normal map to give some self " + "occlusion effect (aka parallax) to the terrain material" ); addFieldV("blendHeightBase", TypeRangedF32, Offset(mBlendDepth, TerrainMaterial), &CommonValidators::PositiveFloat, "A fixed value to add while blending using heightmap-based blending." @@ -117,11 +113,11 @@ void TerrainMaterial::initPersistFields() addFieldV( "detailSize", TypeRangedF32, Offset( mDetailSize, TerrainMaterial ), &CommonValidators::PositiveFloat, "Used to scale the detail map to the material square" ); addFieldV( "detailStrength", TypeRangedF32, Offset( mDetailStrength, TerrainMaterial ), &CommonValidators::PositiveFloat, "Exponentially sharpens or lightens the detail map rendering on the material" ); addFieldV( "detailDistance", TypeRangedF32, Offset( mDetailDistance, TerrainMaterial ), &CommonValidators::PositiveFloat, "Changes how far camera can see the detail map rendering on the material" ); - /* addField( "useSideProjection", TypeBool, Offset( mSideProjection, TerrainMaterial ),"Makes that terrain material project along the sides of steep " "slopes instead of projected downwards"); - */ + INITPERSISTFIELD_IMAGEASSET(ORMConfigMap, TerrainMaterial, "AO|Roughness|metalness map (uses DetailMap UV Coords)"); + addField("isSRGB", TypeBool, Offset(mIsSRGB, TerrainMaterial), "Is the PBR Config map's image in sRGB format?"); addField("invertRoughness", TypeBool, Offset(mInvertRoughness, TerrainMaterial), "Should the roughness channel of the PBR Config map be inverted?"); @@ -131,6 +127,7 @@ void TerrainMaterial::initPersistFields() addFieldV( "macroStrength", TypeRangedF32, Offset( mMacroStrength, TerrainMaterial ), &CommonValidators::PositiveFloat, "Exponentially sharpens or lightens the Macro map rendering on the material" ); addFieldV( "macroDistance", TypeRangedF32, Offset( mMacroDistance, TerrainMaterial ), &CommonValidators::PositiveFloat, "Changes how far camera can see the Macro map rendering on the material" ); + Parent::initPersistFields(); // Gotta call this at least once or it won't get created! @@ -228,8 +225,8 @@ TerrainMaterial* TerrainMaterial::findOrCreate( const char *nameOrPath ) //material.getDiffuseMap(); //returns the raw file referenced //material.getDiffuseMapAsset(); //returns the asset id //material.setDiffuseMap(%texture); //tries to set the asset and failing that attempts a flat file reference -DEF_ASSET_BINDS(TerrainMaterial, DiffuseMap); -DEF_ASSET_BINDS(TerrainMaterial, NormalMap); -DEF_ASSET_BINDS(TerrainMaterial, DetailMap); -DEF_ASSET_BINDS(TerrainMaterial, ORMConfigMap); -DEF_ASSET_BINDS(TerrainMaterial, MacroMap); +DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, DiffuseMap) +DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, NormalMap) +DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, DetailMap) +DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, ORMConfigMap) +DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, MacroMap) diff --git a/Engine/source/terrain/terrMaterial.h b/Engine/source/terrain/terrMaterial.h index 501ab29d3..19c712128 100644 --- a/Engine/source/terrain/terrMaterial.h +++ b/Engine/source/terrain/terrMaterial.h @@ -38,24 +38,17 @@ class TerrainMaterial : public SimObject protected: /// - //FileName mDiffuseMap; - - //AssetPtr mDiffuseAsset; - - DECLARE_IMAGEASSET(TerrainMaterial, DiffuseMap, onDiffuseMapChanged, GFXStaticTextureSRGBProfile); - DECLARE_ASSET_SETGET(TerrainMaterial, DiffuseMap); + DECLARE_IMAGEASSET(TerrainMaterial, DiffuseMap, GFXStaticTextureSRGBProfile) /// The size of the diffuse base map in meters /// used to generate its texture coordinates. F32 mDiffuseSize; /// - DECLARE_IMAGEASSET(TerrainMaterial, NormalMap, onNormalMapChanged, GFXNormalMapProfile); - DECLARE_ASSET_SETGET(TerrainMaterial, NormalMap); + DECLARE_IMAGEASSET(TerrainMaterial, NormalMap, GFXNormalMapProfile) /// - DECLARE_IMAGEASSET(TerrainMaterial, DetailMap, onDetailMapChanged, GFXStaticTextureProfile); - DECLARE_ASSET_SETGET(TerrainMaterial, DetailMap); + DECLARE_IMAGEASSET(TerrainMaterial, DetailMap, GFXStaticTextureProfile) /// The size of the detail map in meters used /// to generate the texture coordinates for the @@ -69,8 +62,7 @@ protected: F32 mDetailDistance; /// - DECLARE_IMAGEASSET(TerrainMaterial, ORMConfigMap, onORMConfigMapChanged, GFXStaticTextureProfile); - DECLARE_ASSET_SETGET(TerrainMaterial, ORMConfigMap); + DECLARE_IMAGEASSET(TerrainMaterial, ORMConfigMap, GFXStaticTextureProfile) bool mIsSRGB; bool mInvertRoughness; @@ -81,8 +73,8 @@ protected: /// planes. bool mSideProjection; - DECLARE_IMAGEASSET(TerrainMaterial, MacroMap, onMacroMapChanged, GFXStaticTextureProfile); - DECLARE_ASSET_SETGET(TerrainMaterial, MacroMap); + DECLARE_IMAGEASSET(TerrainMaterial, MacroMap, GFXStaticTextureProfile) + F32 mMacroSize; F32 mMacroStrength; F32 mMacroDistance; @@ -146,12 +138,6 @@ public: bool getInvertRoughness() const { return mInvertRoughness; } - void onDiffuseMapChanged() {} - void onNormalMapChanged() {} - void onDetailMapChanged() {} - void onORMConfigMapChanged() {} - void onMacroMapChanged() {} - }; #endif // _TERRMATERIAL_H_ diff --git a/Engine/source/terrain/terrRender.cpp b/Engine/source/terrain/terrRender.cpp index 45d61fbff..0fc77aafc 100644 --- a/Engine/source/terrain/terrRender.cpp +++ b/Engine/source/terrain/terrRender.cpp @@ -96,19 +96,19 @@ void TerrainBlock::_updateMaterials() { TerrainMaterial *mat = mFile->mMaterials[i]; - if (mat->getDiffuseMap() != StringTable->EmptyString()) + if (mat->getDiffuseMapAsset().notNull()) { - mBaseTextures[i] = mat->getDiffuseMapResource(); + mBaseTextures[i] = mat->getDiffuseMap(); } else mBaseTextures[ i ] = GFXTexHandle(); // Find the maximum detail distance. - if ( mat->getDetailMap() != StringTable->EmptyString() && + if ( mat->getDetailMapAsset().notNull() && mat->getDetailDistance() > mMaxDetailDistance ) mMaxDetailDistance = mat->getDetailDistance(); - if ( mat->getMacroMap() != StringTable->EmptyString() && + if ( mat->getMacroMapAsset().notNull() && mat->getMacroDistance() > mMaxDetailDistance ) mMaxDetailDistance = mat->getMacroDistance(); } @@ -126,19 +126,19 @@ void TerrainBlock::_updateMaterials() { TerrainMaterial* mat = mFile->mMaterials[i]; - if (mat->getDetailMap() != StringTable->EmptyString()) - detailTexArray[i] = mat->getDetailMapResource(); - if (mat->getMacroMap() != StringTable->EmptyString()) - macroTexArray[i] = mat->getMacroMapResource(); - if (mat->getNormalMap() != StringTable->EmptyString()) - normalTexArray[i] = mat->getNormalMapResource(); + if (mat->getDetailMapAsset().notNull()) + detailTexArray[i] = mat->getDetailMap(); + if (mat->getMacroMapAsset().notNull()) + macroTexArray[i] = mat->getMacroMap(); + if (mat->getNormalMapAsset().notNull()) + normalTexArray[i] = mat->getNormalMap(); //depending on creation method this may or may not have been shoved into srgb space eroneously GFXTextureProfile* profile = &GFXStaticTextureProfile; if (mat->getIsSRGB()) profile = &GFXStaticTextureSRGBProfile; - if (mat->getORMConfigMap() != StringTable->EmptyString()) - ormTexArray[i] = TEXMGR->createTexture(mat->getORMConfigMap(), profile); + if (mat->getORMConfigMapAsset().notNull()) + ormTexArray[i] = mat->getORMConfigMapAsset()->getTexture(profile); } if (mDetailTextureArray.isNull()) diff --git a/Engine/source/ts/assimp/assimpAppMaterial.cpp b/Engine/source/ts/assimp/assimpAppMaterial.cpp index cf62d6cbb..d761f1a18 100644 --- a/Engine/source/ts/assimp/assimpAppMaterial.cpp +++ b/Engine/source/ts/assimp/assimpAppMaterial.cpp @@ -170,14 +170,14 @@ void AssimpAppMaterial::initMaterial(const Torque::Path& path, Material* mat) co { torquePath = texName.C_Str(); if (!torquePath.isEmpty()) - mat->mDiffuseMapName[0] = cleanTextureName(torquePath, cleanFile, path, false); + mat->_setDiffuseMap(cleanTextureName(torquePath, cleanFile, path, false), 0); } if (AI_SUCCESS == mAIMat->Get(AI_MATKEY_TEXTURE(aiTextureType_NORMALS, 0), texName)) { torquePath = texName.C_Str(); if (!torquePath.isEmpty()) - mat->mNormalMapName[0] = cleanTextureName(torquePath, cleanFile, path, false); + mat->_setNormalMap(cleanTextureName(torquePath, cleanFile, path, false), 0); } #ifdef TORQUE_PBR_MATERIALS @@ -194,20 +194,20 @@ void AssimpAppMaterial::initMaterial(const Torque::Path& path, Material* mat) co { // If we have either map, fill all three slots if (rmName.isNotEmpty()) { - mat->mRoughMapName[0] = cleanTextureName(rmName, cleanFile, path, false); // Roughness + mat->_setRoughMap(cleanTextureName(rmName, cleanFile, path, false), 0); // Roughness mat->mRoughnessChan[0] = 1.0f; mat->mInvertRoughness[0] = (floatVal == 1.0f); - mat->mMetalMapName[0] = cleanTextureName(rmName, cleanFile, path, false); // Metallic + mat->_setMetalMap(cleanTextureName(rmName, cleanFile, path, false), 0); // Metallic mat->mMetalChan[0] = 2.0f; } if (aoName.isNotEmpty()) { - mat->mAOMapName[0] = cleanTextureName(aoName, cleanFile, path, false); // occlusion + mat->_setAOMap(cleanTextureName(aoName, cleanFile, path, false), 0); // occlusion mat->mAOChan[0] = 0.0f; } else { - mat->mAOMapName[0] = cleanTextureName(rmName, cleanFile, path, false); // occlusion + mat->_setAOMap(cleanTextureName(aoName, cleanFile, path, false), 0); // occlusion mat->mAOChan[0] = 0.0f; } } diff --git a/Engine/source/ts/collada/colladaAppMaterial.cpp b/Engine/source/ts/collada/colladaAppMaterial.cpp index 81eafc1e3..6c53915ff 100644 --- a/Engine/source/ts/collada/colladaAppMaterial.cpp +++ b/Engine/source/ts/collada/colladaAppMaterial.cpp @@ -208,8 +208,8 @@ Material *ColladaAppMaterial::createMaterial(const Torque::Path& path) const Material *newMat = MATMGR->allocateAndRegister( cleanName, getName() ); Con::setVariable("$Con::File", oldScriptFile); // restore script path - newMat->mDiffuseMapName[0] = diffuseMap; - newMat->mNormalMapName[0] = normalMap; + newMat->_setDiffuseMap(diffuseMap, 0); + newMat->_setNormalMap(normalMap, 0); newMat->mDiffuse[0] = diffuseColor; newMat->mRoughness[0] = roughness; diff --git a/Engine/source/ts/collada/colladaUtils.cpp b/Engine/source/ts/collada/colladaUtils.cpp index 6563bbd2c..dc91b26f8 100644 --- a/Engine/source/ts/collada/colladaUtils.cpp +++ b/Engine/source/ts/collada/colladaUtils.cpp @@ -1030,8 +1030,8 @@ void ColladaUtils::exportColladaMaterials(tinyxml2::XMLElement* rootNode, const { Torque::Path diffusePath; - if (mat->mDiffuseMapName[0] != StringTable->EmptyString()) - diffusePath = Torque::Path(mat->mDiffuseMapName[0]); + if (mat->getDiffuseMapAsset(0).notNull()) + diffusePath = Torque::Path(mat->getDiffuseMapAsset(0)->getImageFile()); else diffusePath = String("warningMat"); @@ -1040,8 +1040,8 @@ void ColladaUtils::exportColladaMaterials(tinyxml2::XMLElement* rootNode, const } else { - if (mat->mDiffuseMapName[0] != StringTable->EmptyString()) - diffuseMap += Torque::Path(mat->mDiffuseMapName[0]); + if (mat->getDiffuseMapAsset(0).notNull()) + diffuseMap += Torque::Path(mat->getDiffuseMapAsset(0)->getImageFile()); else diffuseMap += "warningMat"; } @@ -1316,8 +1316,8 @@ void ColladaUtils::exportColladaMaterials(tinyxml2::XMLElement* rootNode, const { Torque::Path diffusePath; - if (mat->mDiffuseMapName[0] != StringTable->EmptyString()) - diffusePath = Torque::Path(mat->mDiffuseMapName[0]); + if (mat->getDiffuseMapAsset(0).notNull()) + diffusePath = Torque::Path(mat->getDiffuseMapAsset(0)->getImageFile()); else diffusePath = String("warningMat"); @@ -1326,8 +1326,8 @@ void ColladaUtils::exportColladaMaterials(tinyxml2::XMLElement* rootNode, const } else { - if (mat->mDiffuseMapName[0] != StringTable->EmptyString()) - diffuseMap += Torque::Path(mat->mDiffuseMapName[0]); + if (mat->getDiffuseMapAsset(0).notNull()) + diffuseMap += Torque::Path(mat->getDiffuseMapAsset(0)->getImageFile()); else diffuseMap += "warningMat"; } diff --git a/Engine/source/ts/tsLastDetail.cpp b/Engine/source/ts/tsLastDetail.cpp index a65a22851..df9c2f29f 100644 --- a/Engine/source/ts/tsLastDetail.cpp +++ b/Engine/source/ts/tsLastDetail.cpp @@ -252,8 +252,8 @@ void TSLastDetail::update( bool forceUpdate ) // Setup the material for this imposter. mMaterial = MATMGR->allocateAndRegister( String::EmptyString ); mMaterial->mAutoGenerated = true; - mMaterial->setDiffuseMapFile(diffuseMapPath, 0); - mMaterial->setNormalMapFile(_getNormalMapPath(), 0); + mMaterial->_setDiffuseMap(diffuseMapPath, 0); + mMaterial->_setNormalMap(_getNormalMapPath(), 0); mMaterial->mImposterLimits.set( (mNumPolarSteps * 2) + 1, mNumEquatorSteps, mPolarAngle, mIncludePoles ); mMaterial->mTranslucent = true; diff --git a/Templates/BaseGame/game/core/rendering/Core_Rendering.tscript b/Templates/BaseGame/game/core/rendering/Core_Rendering.tscript index 1051ee621..8675e3168 100644 --- a/Templates/BaseGame/game/core/rendering/Core_Rendering.tscript +++ b/Templates/BaseGame/game/core/rendering/Core_Rendering.tscript @@ -9,6 +9,7 @@ function Core_Rendering::onCreate(%this) $Core::WetnessTexture = "core/rendering/images/wetMap.png"; $Core::NoImageAssetFallback = "Core_Rendering:missingTexture_image"; + $Core::NamedTargetFallback = "Core_Rendering:namedTarget_image"; $Core::NoMaterialAssetFallback = "Core_Rendering:noMaterial"; $Core::NoShapeAssetFallback = "Core_Rendering:noShape"; diff --git a/Templates/BaseGame/game/core/rendering/images/namedTarget.png b/Templates/BaseGame/game/core/rendering/images/namedTarget.png new file mode 100644 index 000000000..4d2656a5f Binary files /dev/null and b/Templates/BaseGame/game/core/rendering/images/namedTarget.png differ diff --git a/Templates/BaseGame/game/core/rendering/images/namedTarget_image.asset.taml b/Templates/BaseGame/game/core/rendering/images/namedTarget_image.asset.taml new file mode 100644 index 000000000..7cd23509a --- /dev/null +++ b/Templates/BaseGame/game/core/rendering/images/namedTarget_image.asset.taml @@ -0,0 +1,3 @@ + diff --git a/Templates/BaseGame/game/data/gameUI/GUIs/playGui.gui b/Templates/BaseGame/game/data/gameUI/GUIs/playGui.gui index 4783b51a7..faeea23b5 100644 --- a/Templates/BaseGame/game/data/gameUI/GUIs/playGui.gui +++ b/Templates/BaseGame/game/data/gameUI/GUIs/playGui.gui @@ -28,7 +28,7 @@ $guiContent = new GameTSCtrl(PlayGui) { noCursor = "1"; new GuiBitmapCtrl(LagIcon) { - bitmap = "data/ui/art/lagIcon.png"; + bitmapAsset = "UI:lagIcon_image"; color = "255 255 255 255"; wrap = "0"; position = "572 3"; diff --git a/Templates/BaseGame/game/tools/assetBrowser/guis/assetPreviewButtonsTemplate.gui b/Templates/BaseGame/game/tools/assetBrowser/guis/assetPreviewButtonsTemplate.gui index 803f71ba5..53dc12dcb 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/guis/assetPreviewButtonsTemplate.gui +++ b/Templates/BaseGame/game/tools/assetBrowser/guis/assetPreviewButtonsTemplate.gui @@ -68,7 +68,7 @@ $guiContent = new GuiControl(AssetPreviewButtonsTemplate) { canSaveDynamicFields = "0"; new GuiBitmapButtonCtrl() { - bitmap = "tools/materialEditor/gui/cubemapBtnBorder"; + bitmapAsset = "ToolsModule:cubemapBtnBorder_n_image"; bitmapMode = "Stretched"; autoFitExtents = "0"; useModifiers = "0"; @@ -163,7 +163,7 @@ $guiContent = new GuiControl(AssetPreviewButtonsTemplate) { canSaveDynamicFields = "0"; new GuiBitmapButtonCtrl() { - bitmap = "Data/Blockout_Basics/Walls/WallGrid2x2_Albedo.png"; + bitmapAsset = "Data/Blockout_Basics/Walls/WallGrid2x2_Albedo.png"; bitmapMode = "Stretched"; autoFitExtents = "0"; useModifiers = "0"; @@ -188,7 +188,7 @@ $guiContent = new GuiControl(AssetPreviewButtonsTemplate) { canSaveDynamicFields = "0"; new GuiBitmapButtonCtrl() { - bitmap = "tools/materialEditor/gui/cubemapBtnBorder"; + bitmapAsset = "ToolsModule:cubemapBtnBorder_n_image"; bitmapMode = "Stretched"; autoFitExtents = "0"; useModifiers = "0"; diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript index 6cc4acea6..9dcd48e63 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript @@ -2765,7 +2765,6 @@ function getAssetPreviewImage(%asset) %moduleName = AssetDatabase.getAssetModule(%asset).ModuleId; %assetName = AssetDatabase.getAssetName(%asset); %previewAssetName = "ToolsModule:" @ %moduleName @ "_" @ %assetName @ "_PreviewImage"; - if(AssetDatabase.isDeclaredAsset(%previewAssetName)) { %previewDef = AssetDatabase.acquireAsset(%previewAssetName); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript index 98af1c509..26f093dd0 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript @@ -4,8 +4,8 @@ function ImageAsset::buildBrowserElement(%this, %previewData) { //%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%assetDef.getImagePath()))); - %previewData.previewImage = "ToolsModule:genericAssetIcon_image"; - %previewData.previewLoaded = false; //this marks it for loading progressively later + %previewData.previewImage = %assetDef.isNamedTarget() ? "Core_Rendering:namedTarget_image" : "ToolsModule:genericAssetIcon_image"; + %previewData.previewLoaded = %assetDef.isNamedTarget() ? true : false; //if image target we are loaded, else mark for loading later. %previewData.assetName = %this.assetName; %previewData.assetPath = %this.scriptFile; @@ -59,13 +59,13 @@ function ImageAsset::generatePreviewImage(%this, %previewButton, %forceRegenerat { assetName = %previewAssetName; versionId = 1; - imageFile = fileName(%previewFilePath); + imageFile = makeFullPath(%previewFilePath); }; - + %previewAssetName = "ToolsModule:" @ %previewAssetName; %previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml"; + %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); - %toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1); %success = AssetDatabase.addDeclaredAsset(%toolsModuleDef, %previewImgAssetPath); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript index 0a7f0a6ff..05cada34d 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript @@ -148,25 +148,25 @@ function MaterialAsset::generatePreviewImage(%this, %previewButton, %forceRegene { assetName = %previewAssetName; versionId = 1; - imageFile = fileName(%previewFilePath); + imageFile = makeFullPath(%previewFilePath); }; %previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml"; - %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); + %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); %toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1); - + %success = AssetDatabase.addDeclaredAsset(%toolsModuleDef, %previewImgAssetPath); if(!%success) { return false; //failed to register the preview image for some reason? + } } - } %previewButton.bitmapAsset = "ToolsModule:" @ %previewAssetName; return true; - } + } } else { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript index 7330738ad..6749c688f 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript @@ -121,20 +121,20 @@ function ShapeAsset::generatePreviewImage(%this, %previewButton, %forceRegenerat { assetName = %previewAssetName; versionId = 1; - imageFile = fileName(%previewFilePath); + imageFile = makeFullPath(%previewFilePath); }; %previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml"; - %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); + %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); %toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1); - + %success = AssetDatabase.addDeclaredAsset(%toolsModuleDef, %previewImgAssetPath); - + if(!%success) { return false; //failed to register the preview image for some reason? - } + } } %previewButton.bitmapAsset = "ToolsModule:" @ %previewAssetName; diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/terrainMaterial.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/terrainMaterial.tscript index 5b73b94ac..a69cb0e10 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/terrainMaterial.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/terrainMaterial.tscript @@ -144,14 +144,14 @@ function TerrainAssetMaterial::generatePreviewImage(%this, %previewButton, %forc { assetName = %previewAssetName; versionId = 1; - imageFile = fileName(%previewFilePath); + imageFile = makeFullPath(%previewFilePath); }; %previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml"; - %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); + %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); %toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1); - + %success = AssetDatabase.addDeclaredAsset(%toolsModuleDef, %previewImgAssetPath); if(!%success) diff --git a/Templates/BaseGame/game/tools/gui/materialSelector.ed.gui b/Templates/BaseGame/game/tools/gui/materialSelector.ed.gui index a1e263b2a..3575f4148 100644 --- a/Templates/BaseGame/game/tools/gui/materialSelector.ed.gui +++ b/Templates/BaseGame/game/tools/gui/materialSelector.ed.gui @@ -136,7 +136,7 @@ new GuiControl(MaterialSelectorOverlay, EditorGuiGroup) { Command = "MaterialSelector.createNewMaterial();"; hovertime = "1000"; tooltip = "Create New Unmapped Material"; - bitmap = "tools/gui/images/new"; + bitmapAsset = "ToolsModule:new_n_image"; groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; @@ -1649,7 +1649,7 @@ function MaterialSelector::createNewMaterial( %this ) position = "7 4"; extent = "64 64"; buttonType = "PushButton"; - bitmap = "core/images/warnmat"; + bitmapAsset = "CoreModule:warnMat_image"; Command = ""; text = "Loading..."; useStates = false; diff --git a/Templates/BaseGame/game/tools/gui/profiles.ed.tscript b/Templates/BaseGame/game/tools/gui/profiles.ed.tscript index 17390ad0f..6bbac1cea 100644 --- a/Templates/BaseGame/game/tools/gui/profiles.ed.tscript +++ b/Templates/BaseGame/game/tools/gui/profiles.ed.tscript @@ -1415,7 +1415,7 @@ singleton GuiControlProfile( ToolsGuiMenuBarProfile ) singleton GuiControlProfile( ToolsMenubarProfile : ToolsGuiDefaultProfile ) { - bitmap = "./menubar"; + bitmaAsset = "ToolsModule:menubar_image"; category = "Editor"; opaque = true; @@ -1433,7 +1433,7 @@ singleton GuiControlProfile (menubarProfile) border = -2; category = "Editor"; - bitmap = "./menubar"; + bitmaAsset = "ToolsModule:menubar_image"; category = "Editor"; fillColor = EditorSettings.value("Theme/windowBackgroundColor"); @@ -1447,35 +1447,35 @@ singleton GuiControlProfile (editorMenubarProfile) { border = -2; category = "Editor"; - bitmap = "./editor-menubar"; + bitmaAsset = "ToolsModule:editor_menubar_image"; category = "Editor"; }; singleton GuiControlProfile (editorMenu_wBorderProfile) { border = -2; category = "Editor"; - bitmap = "./menu-fullborder"; + bitmaAsset = "ToolsModule:menu_fullborder_image"; category = "Editor"; }; singleton GuiControlProfile (inspectorStyleRolloutProfile) { border = -2; category = "Editor"; - bitmap = "./inspector-style-rollout"; + bitmaAsset = "ToolsModule:inspector_style_rollout_image"; category = "Editor"; }; singleton GuiControlProfile (inspectorStyleRolloutListProfile) { border = -2; category = "Editor"; - bitmap = "./inspector-style-rollout-list"; + bitmaAsset = "ToolsModule:inspector_style_rollout_list_image"; category = "Editor"; }; singleton GuiControlProfile (inspectorStyleRolloutDarkProfile) { border = -2; category = "Editor"; - bitmap = "./inspector-style-rollout-dark"; + bitmaAsset = "ToolsModule:inspector_style_rollout_dark_image"; fillColor = EditorSettings.value("Theme/windowBackgroundColor"); fontColor = EditorSettings.value("Theme/headerTextColor"); @@ -1486,14 +1486,14 @@ singleton GuiControlProfile (inspectorStyleRolloutInnerProfile) { border = -2; category = "Editor"; - bitmap = "./inspector-style-rollout_inner"; + bitmaAsset = "ToolsModule:inspector_style_rollout_inner_image"; category = "Editor"; }; singleton GuiControlProfile (inspectorStyleRolloutNoHeaderProfile) { border = -2; category = "Editor"; - bitmap = "./inspector-style-rollout-noheader"; + bitmaAsset = "ToolsModule:inspector_style_rollout_noheader_image"; category = "Editor"; }; singleton GuiControlProfile (IconDropdownProfile) @@ -1502,7 +1502,6 @@ singleton GuiControlProfile (IconDropdownProfile) opaque = true; border = true; category = "Editor"; - //bitmap = "./icon-dropdownbar"; fillColor = EditorSettings.value("Theme/headerColor"); }; diff --git a/Templates/BaseGame/game/tools/guiEditor/gui/EditorChooseGUI.ed.gui b/Templates/BaseGame/game/tools/guiEditor/gui/EditorChooseGUI.ed.gui index 212cbf94a..80a2f75f1 100644 --- a/Templates/BaseGame/game/tools/guiEditor/gui/EditorChooseGUI.ed.gui +++ b/Templates/BaseGame/game/tools/guiEditor/gui/EditorChooseGUI.ed.gui @@ -13,7 +13,7 @@ $guiContent = new GuiChunkedBitmapCtrl(EditorChooseGUI, EditorGuiGroup) { Visible = "1"; tooltipprofile = "ToolsGuiToolTipProfile"; hovertime = "1000"; - bitmap = "data/ui/images/background.png"; + bitmapAsset = "UI:background_image"; useVariable = "0"; tile = "0"; diff --git a/Templates/BaseGame/game/tools/levels/DefaultEditorLevel/probes/289ad401-3140-11ed-aae8-c0cb519281fc_Irradiance.dds b/Templates/BaseGame/game/tools/levels/DefaultEditorLevel/probes/289ad401-3140-11ed-aae8-c0cb519281fc_Irradiance.dds index 73e2e246e..095d2ec14 100644 Binary files a/Templates/BaseGame/game/tools/levels/DefaultEditorLevel/probes/289ad401-3140-11ed-aae8-c0cb519281fc_Irradiance.dds and b/Templates/BaseGame/game/tools/levels/DefaultEditorLevel/probes/289ad401-3140-11ed-aae8-c0cb519281fc_Irradiance.dds differ diff --git a/Templates/BaseGame/game/tools/levels/DefaultEditorLevel/probes/289ad401-3140-11ed-aae8-c0cb519281fc_Prefilter.dds b/Templates/BaseGame/game/tools/levels/DefaultEditorLevel/probes/289ad401-3140-11ed-aae8-c0cb519281fc_Prefilter.dds index 8aa59ceb1..77855072e 100644 Binary files a/Templates/BaseGame/game/tools/levels/DefaultEditorLevel/probes/289ad401-3140-11ed-aae8-c0cb519281fc_Prefilter.dds and b/Templates/BaseGame/game/tools/levels/DefaultEditorLevel/probes/289ad401-3140-11ed-aae8-c0cb519281fc_Prefilter.dds differ diff --git a/Templates/BaseGame/game/tools/materialEditor/gui/Profiles.ed.tscript b/Templates/BaseGame/game/tools/materialEditor/gui/Profiles.ed.tscript index a9f67ad6a..a8d2eb36e 100644 --- a/Templates/BaseGame/game/tools/materialEditor/gui/Profiles.ed.tscript +++ b/Templates/BaseGame/game/tools/materialEditor/gui/Profiles.ed.tscript @@ -24,7 +24,7 @@ singleton GuiControlProfile (GuiMatEdSliderProfile) { - bitmap = "./matEdSlider"; + bitmapAsset = "ToolsModule:slider_image"; category = "Editor"; }; @@ -47,9 +47,7 @@ singleton GuiControlProfile(GuiMatEdPopUpMenuProfile) mouseOverSelected = true; textOffset = "3 3"; border = 1; - /*borderThickness = 1;*/ fixedExtent = true; - //bitmap = "./images/scrollbar"; bitmapAsset = "ToolsModule:scroll_image"; hasBitmapArray = true; profileForChildren = GuiControlListPopupProfile; diff --git a/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui b/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui index 953da034f..0404faebe 100644 --- a/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui +++ b/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui @@ -4821,7 +4821,7 @@ $guiContent = new GuiControl(MaterialEditorGui,EditorGuiGroup) { tooltipprofile = "ToolsGuiToolTipProfile"; buttonType = "PushButton"; useMouseEvents = "0"; - bitmap = "ToolsModule:new_n_image"; + bitmapAsset = "ToolsModule:new_n_image"; }; // Save Button new GuiBitmapButtonCtrl() { diff --git a/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui.orig b/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui.orig index f7365bbc4..5f02923f1 100644 --- a/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui.orig +++ b/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui.orig @@ -4846,7 +4846,7 @@ $guiContent = new GuiControl(MaterialEditorGui,EditorGuiGroup) { tooltipprofile = "ToolsGuiToolTipProfile"; buttonType = "PushButton"; useMouseEvents = "0"; - bitmap = "ToolsModule:new_n_image"; + bitmapAsset = "ToolsModule:new_n_image"; }; // Save Button new GuiBitmapButtonCtrl() { diff --git a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript index a0919e915..ba638b509 100644 --- a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript +++ b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript @@ -747,8 +747,8 @@ function MaterialEditorGui::setActiveMaterial( %this, %material ) // we create or recreate a material to hold in a pristine state // or, this crashes the ap. fix properly - BJR -// if(isObject(notDirtyMaterial)) -// notDirtyMaterial.delete(); + //if(isObject(notDirtyMaterial)) + // notDirtyMaterial.delete(); singleton Material(notDirtyMaterial) { @@ -860,16 +860,28 @@ function MaterialEditorGui::convertTextureFields(%this) } function MaterialEditorGui::convertMaterialTextureField(%this, %material, %mapName) - { +{ for(%index = 0; %index < 4; %index++) { %mapFile = %material.call("get" @ %mapName, %index); - if(%mapFile !$= "" && !isFile(%mapFile)) - { - //see if we can't go finding it - %mapFile = MaterialEditorGui.searchForTexture(MaterialEditorGui.currentMaterial, %mapFile); - MaterialEditorGui.currentMaterial.call("set" @ %mapName, %mapFile, %index); - } + if(%mapFile !$= "") + { + if(isFile(%mapFile)) + { + //see if we can't go finding it + %mapFile = MaterialEditorGui.searchForTexture(MaterialEditorGui.currentMaterial, %mapFile); + MaterialEditorGui.currentMaterial.call("set" @ %mapName, %mapFile, %index); + } + else + { + %firstChar = getSubStr( %mapFile, 0, 1 ); + if(%firstChar $= "#" || %firstChar $= "$" ) // we are a named target + { + %assetPtr = %material.call("get" @ %mapName @ "Asset", %index); + MaterialEditorGui.currentMaterial.call("set" @ %mapName, %assetPtr, %index); + } + } + } } } @@ -1089,7 +1101,7 @@ function MaterialEditorGui::guiSync( %this, %material ) %diffuseMap = (%material).getDiffuseMap(%layer); %diffuseMapText = %diffuseMap !$= "" && %diffuseMap !$=$MaterialEditor::emptyMaterialImage ? (%material).getDiffuseMapAsset(%layer) : "None"; MaterialEditorPropertiesWindow-->diffuseMapNameText.setText( %diffuseMapText ); - MaterialEditorPropertiesWindow-->diffuseMapDisplayBitmap.setBitmap( getAssetPreviewImage(%diffuseMap) ); + MaterialEditorPropertiesWindow-->diffuseMapDisplayBitmap.setBitmap( getAssetPreviewImage(%diffuseMapText) ); //Normal %normalMap = (%material).getNormalMap(%layer); diff --git a/Templates/BaseGame/game/tools/navEditor/NavEditorToolbar.gui b/Templates/BaseGame/game/tools/navEditor/NavEditorToolbar.gui index cdee55fb9..38c86f678 100644 --- a/Templates/BaseGame/game/tools/navEditor/NavEditorToolbar.gui +++ b/Templates/BaseGame/game/tools/navEditor/NavEditorToolbar.gui @@ -40,7 +40,7 @@ $guiContent = new GuiControl(NavEditorToolbar,EditorGuiGroup) { canSaveDynamicFields = "0"; }; new GuiBitmapCtrl() { - bitmap = "core/gui/images/separator-h.png"; + bitmapAsset = "ToolsModule:separator_h_image"; wrap = "0"; position = "90 3"; extent = "2 26"; diff --git a/Templates/BaseGame/game/tools/riverEditor/riverEditorGui.tscript b/Templates/BaseGame/game/tools/riverEditor/riverEditorGui.tscript index e0093acd1..f38f3b877 100644 --- a/Templates/BaseGame/game/tools/riverEditor/riverEditorGui.tscript +++ b/Templates/BaseGame/game/tools/riverEditor/riverEditorGui.tscript @@ -338,9 +338,9 @@ function RiverEditorGui::createRiver( %this ) baseColor = "45 108 171 255"; - rippleTex = "Core_Rendering:ripple_image"; - foamTex = "Core_Rendering:foam_image"; - depthGradientTex = "Core_Rendering:depthcolor_ramp_image"; + RippleTexAsset = "Core_Rendering:ripple_image"; + FoamTexAsset = "Core_Rendering:foam_image"; + DepthGradientTexAsset = "Core_Rendering:depthcolor_ramp_image"; }; return %river; diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/EditorChooseLevelGui.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/EditorChooseLevelGui.ed.gui index 6ca9dd503..a7e7b2626 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/EditorChooseLevelGui.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/EditorChooseLevelGui.ed.gui @@ -28,7 +28,7 @@ $guiContent = new GuiContainer(EditorChooseLevelGui, EditorGuiGroup) { Visible = "1"; tooltipprofile = "ToolsGuiToolTipProfile"; hovertime = "1000"; - bitmap = "data/ui/images/background.png"; + bitmapAsset = "UI:background_image"; useVariable = "0"; tile = "0"; }; diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/EditorGui.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/EditorGui.ed.gui index 1e932ba7f..810a923d4 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/EditorGui.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/EditorGui.ed.gui @@ -115,8 +115,8 @@ $guiContent = new GuiContainer(EditorGui,EditorGuiGroup) { selectionBoxColor = "255 255 0 255"; selectionLocked = "0"; toggleIgnoreList = "0"; - selectHandle = "ToolsModule:SelectHandle_image"; - defaultHandle = "ToolsModule:DefaultHandle_image"; + selectHandleAsset = "ToolsModule:SelectHandle_image"; + defaultHandleAsset = "ToolsModule:DefaultHandle_image"; lockedHandleAsset = "ToolsModule:LockedHandle_image"; }; new TerrainEditor(ETerrainEditor) { @@ -1534,7 +1534,7 @@ $guiContent = new GuiContainer(EditorGui,EditorGuiGroup) { internalName = "slider"; position = "9 17"; extent = "129 15"; - bitmap = "tools/gui/images/separator-h.png"; + bitmapAsset = "ToolsModule:separator_h_image"; HorizSizing = "width"; VertSizing = "bottom"; range = "1 200"; diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui index 655348e4f..c84636946 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui @@ -1282,9 +1282,9 @@ function ObjectBuilderGui::addWaterObjectFields(%this) %this.addField("waveSpeed[2]", "TypeFloat", "Wave Speed", "1"); %this.addField("overallWaveMagnitude", "TypeFloat", "Overall Wave Magnitude", "1.0"); - %this.addField("rippleTex", "TypeImageAsset", "Ripple Texture", "Core_Rendering:ripple_image" ); - %this.addField("depthGradientTex", "TypeImageAsset", "Depth Gradient Texture", "Core_Rendering:depthcolor_ramp_image" ); - %this.addField("foamTex", "TypeImageAsset", "Foam Texture", "Core_Rendering:foam_image" ); + %this.addField("RippleTexAsset", "TypeImageAssetPtr", "Ripple Texture", "Core_Rendering:ripple_image" ); + %this.addField("DepthGradientTexAsset", "TypeImageAssetPtr", "Depth Gradient Texture", "Core_Rendering:depthcolor_ramp_image" ); + %this.addField("FoamTexAsset", "TypeImageAssetPtr", "Foam Texture", "Core_Rendering:foam_image" ); } function ObjectBuilderGui::buildWaterBlock(%this)