Torque3D Documentation / _generateds / PostEffectAsset.cpp

PostEffectAsset.cpp

Engine/source/T3D/assets/PostEffectAsset.cpp

More...

Public Functions

ConsoleSetType(TypePostEffectAssetPtr )
ConsoleType(PostEffectAssetPtr , TypePostEffectAssetPtr , PostEffectAsset , ASSET_ID_FIELD_PREFIX )

Detailed Description

Public Functions

ConsoleSetType(TypePostEffectAssetPtr )

ConsoleType(PostEffectAssetPtr , TypePostEffectAssetPtr , PostEffectAsset , ASSET_ID_FIELD_PREFIX )

IMPLEMENT_CONOBJECT(PostEffectAsset )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2013 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef POSTEFFECT_ASSET_H
 25#include "PostEffectAsset.h"
 26#endif
 27
 28#ifndef _ASSET_MANAGER_H_
 29#include "assets/assetManager.h"
 30#endif
 31
 32#ifndef _CONSOLETYPES_H_
 33#include "console/consoleTypes.h"
 34#endif
 35
 36#ifndef _TAML_
 37#include "persistence/taml/taml.h"
 38#endif
 39
 40#ifndef _ASSET_PTR_H_
 41#include "assets/assetPtr.h"
 42#endif
 43
 44// Debug Profiling.
 45#include "platform/profiler.h"
 46
 47//-----------------------------------------------------------------------------
 48
 49IMPLEMENT_CONOBJECT(PostEffectAsset);
 50
 51ConsoleType(PostEffectAssetPtr, TypePostEffectAssetPtr, PostEffectAsset, ASSET_ID_FIELD_PREFIX)
 52
 53//-----------------------------------------------------------------------------
 54
 55ConsoleGetType(TypePostEffectAssetPtr)
 56{
 57   // Fetch asset Id.
 58   return (*((AssetPtr<PostEffectAsset>*)dptr)).getAssetId();
 59}
 60
 61//-----------------------------------------------------------------------------
 62
 63ConsoleSetType(TypePostEffectAssetPtr)
 64{
 65   // Was a single argument specified?
 66   if (argc == 1)
 67   {
 68      // Yes, so fetch field value.
 69      const char* pFieldValue = argv[0];
 70
 71      // Fetch asset pointer.
 72      AssetPtr<PostEffectAsset>* pAssetPtr = dynamic_cast<AssetPtr<PostEffectAsset>*>((AssetPtrBase*)(dptr));
 73
 74      // Is the asset pointer the correct type?
 75      if (pAssetPtr == NULL)
 76      {
 77         // No, so fail.
 78         //Con::warnf("(TypePostEffectAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
 79         return;
 80      }
 81
 82      // Set asset.
 83      pAssetPtr->setAssetId(pFieldValue);
 84
 85      return;
 86   }
 87
 88   // Warn.
 89   Con::warnf("(TypePostEffectAssetPtr) - Cannot set multiple args to a single asset.");
 90}
 91
 92//-----------------------------------------------------------------------------
 93
 94PostEffectAsset::PostEffectAsset()
 95{
 96   mScriptFile = StringTable->EmptyString();
 97   mHLSLShaderFile = StringTable->EmptyString();
 98   mGLSLShaderFile = StringTable->EmptyString();
 99
100   mScriptPath = StringTable->EmptyString();
101   mHLSLShaderPath = StringTable->EmptyString();
102   mGLSLShaderPath = StringTable->EmptyString();
103}
104
105//-----------------------------------------------------------------------------
106
107PostEffectAsset::~PostEffectAsset()
108{
109}
110
111//-----------------------------------------------------------------------------
112
113void PostEffectAsset::initPersistFields()
114{
115   // Call parent.
116   Parent::initPersistFields();
117
118   addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, PostEffectAsset),
119      &setScriptFile, &getScriptFile, "Path to the script file.");
120   addProtectedField("hlslShader", TypeAssetLooseFilePath, Offset(mHLSLShaderFile, PostEffectAsset),
121      &setHLSLShaderFile, &getHLSLShaderFile, "Path to the hlsl shader file.");
122   addProtectedField("glslShader", TypeAssetLooseFilePath, Offset(mGLSLShaderFile, PostEffectAsset),
123      &setGLSLShaderFile, &getGLSLShaderFile, "Path to the glsl shader file.");
124}
125
126//------------------------------------------------------------------------------
127
128void PostEffectAsset::copyTo(SimObject* object)
129{
130   // Call to parent.
131   Parent::copyTo(object);
132}
133
134void PostEffectAsset::initializeAsset()
135{
136   mScriptPath = expandAssetFilePath(mScriptFile);
137   mHLSLShaderPath = expandAssetFilePath(mHLSLShaderFile);
138   mGLSLShaderPath = expandAssetFilePath(mGLSLShaderFile);
139
140   if (Platform::isFile(mScriptPath))
141      Con::executeFile(mScriptPath, false, false);
142}
143
144void PostEffectAsset::onAssetRefresh()
145{
146   mScriptPath = expandAssetFilePath(mScriptFile);
147   mHLSLShaderPath = expandAssetFilePath(mHLSLShaderFile);
148   mGLSLShaderPath = expandAssetFilePath(mGLSLShaderFile);
149
150   if (Platform::isFile(mScriptPath))
151      Con::executeFile(mScriptPath, false, false);
152}
153
154void PostEffectAsset::setScriptFile(const char* pScriptFile)
155{
156   // Sanity!
157   AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
158
159   // Fetch image file.
160   pScriptFile = StringTable->insert(pScriptFile);
161
162   // Ignore no change,
163   if (pScriptFile == mScriptFile)
164      return;
165
166   // Update.
167   mScriptFile = pScriptFile;
168
169   // Refresh the asset.
170   refreshAsset();
171}
172
173void PostEffectAsset::setHLSLShaderFile(const char* pShaderFile)
174{
175   // Sanity!
176   AssertFatal(pShaderFile != NULL, "Cannot use a NULL shader file.");
177
178   // Fetch image file.
179   pShaderFile = StringTable->insert(pShaderFile);
180
181   // Ignore no change,
182   if (pShaderFile == mHLSLShaderFile)
183      return;
184
185   // Update.
186   mHLSLShaderFile = pShaderFile;
187
188   // Refresh the asset.
189   refreshAsset();
190}
191
192void PostEffectAsset::setGLSLShaderFile(const char* pShaderFile)
193{
194   // Sanity!
195   AssertFatal(pShaderFile != NULL, "Cannot use a NULL shader file.");
196
197   // Fetch image file.
198   pShaderFile = StringTable->insert(pShaderFile);
199
200   // Ignore no change,
201   if (pShaderFile == mGLSLShaderFile)
202      return;
203
204   // Update.
205   mGLSLShaderFile = pShaderFile;
206
207   // Refresh the asset.
208   refreshAsset();
209}
210