Pārlūkot izejas kodu

named target functionality

marauder2k7 6 mēneši atpakaļ
vecāks
revīzija
987ff90467

+ 25 - 0
Engine/source/T3D/assets/ImageAsset.cpp

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

+ 3 - 1
Engine/source/T3D/assets/ImageAsset.h

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

+ 12 - 4
Engine/source/materials/processedShaderMaterial.cpp

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