Torque3D Documentation / _generateds / customShaderFeature.cpp

customShaderFeature.cpp

Engine/source/shaderGen/customShaderFeature.cpp

More...

Public Functions

ConsoleDocClass(CustomShaderFeatureData , "@brief A Shader Feature with custom <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">definitions.\n\n</a>" "This class allows <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the creation and implementation of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classshadergen/">ShaderGen</a> <a href="/coding/class/classshaderfeature/">ShaderFeature</a> " "Implemented either engine side or script, and facilitates passing along of per-instance " "ShaderData. " " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Examples\n</a>" )
DefineEngineMethod(CustomShaderFeatureData , addConnector , void , (String name, String type, String elementName) , ("", "", "") , "" )
DefineEngineMethod(CustomShaderFeatureData , addSampler , void , (String name, U32 arraySize) , ("", 0) , "" )
DefineEngineMethod(CustomShaderFeatureData , addTexture , void , (String name, String type, String samplerState, U32 arraySize) , ("", "", 0) , "" )
DefineEngineMethod(CustomShaderFeatureData , addUniform , void , (String name, String type, String defaultValue, U32 arraySize) , ("", "", "", 0) , "" )
DefineEngineMethod(CustomShaderFeatureData , addVariable , void , (String name, String type, String defaultValue) , ("", "", "") , "" )
DefineEngineMethod(CustomShaderFeatureData , addVertTexCoord , void , (String name) , ("") , "" )
DefineEngineMethod(CustomShaderFeatureData , hasFeature , bool , (String name) , ("") , "" )
DefineEngineStringlyVariadicMethod(CustomShaderFeatureData , writeLine , void , 3 , 0 , "( string format, string args... ) Dynamically call <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> method on an <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n</a>" "@param method Name of method <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">call.\n</a>" "@param args Zero or more arguments <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">method.\n</a>" "@return The result of the method call." )

Detailed Description

Public Functions

ConsoleDocClass(CustomShaderFeatureData , "@brief A Shader Feature with custom <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">definitions.\n\n</a>" "This class allows <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the creation and implementation of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classshadergen/">ShaderGen</a> <a href="/coding/class/classshaderfeature/">ShaderFeature</a> " "Implemented either engine side or script, and facilitates passing along of per-instance " "ShaderData. " " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Examples\n</a>" )

DefineEngineMethod(CustomShaderFeatureData , addConnector , void , (String name, String type, String elementName) , ("", "", "") , "" )

DefineEngineMethod(CustomShaderFeatureData , addSampler , void , (String name, U32 arraySize) , ("", 0) , "" )

DefineEngineMethod(CustomShaderFeatureData , addTexture , void , (String name, String type, String samplerState, U32 arraySize) , ("", "", 0) , "" )

DefineEngineMethod(CustomShaderFeatureData , addUniform , void , (String name, String type, String defaultValue, U32 arraySize) , ("", "", "", 0) , "" )

DefineEngineMethod(CustomShaderFeatureData , addVariable , void , (String name, String type, String defaultValue) , ("", "", "") , "" )

DefineEngineMethod(CustomShaderFeatureData , addVertTexCoord , void , (String name) , ("") , "" )

DefineEngineMethod(CustomShaderFeatureData , hasFeature , bool , (String name) , ("") , "" )

DefineEngineStringlyVariadicMethod(CustomShaderFeatureData , writeLine , void , 3 , 0 , "( string format, string args... ) Dynamically call <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> method on an <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n</a>" "@param method Name of method <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">call.\n</a>" "@param args Zero or more arguments <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">method.\n</a>" "@return The result of the method call." )

IMPLEMENT_CONOBJECT(CustomShaderFeatureData )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 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#include "shaderGen/customShaderFeature.h"
 25
 26#ifdef TORQUE_D3D11
 27#include "shaderGen/HLSL/customFeatureHLSL.h"
 28#endif
 29#ifdef TORQUE_OPENGL
 30#include "shaderGen/GLSL/customFeatureGLSL.h"
 31#endif
 32
 33#include "math/mathIO.h"
 34#include "scene/sceneRenderState.h"
 35#include "core/stream/bitStream.h"
 36#include "materials/sceneData.h"
 37#include "gfx/gfxDebugEvent.h"
 38#include "gfx/gfxTransformSaver.h"
 39#include "renderInstance/renderPassManager.h"
 40
 41
 42IMPLEMENT_CONOBJECT(CustomShaderFeatureData);
 43
 44ConsoleDocClass(CustomShaderFeatureData,
 45   "@brief A Shader Feature with custom definitions.\n\n"
 46   "This class allows for the creation and implementation of a ShaderGen ShaderFeature "
 47   "Implemented either engine side or script, and facilitates passing along of per-instance "
 48   "ShaderData. "
 49   "@ingroup Examples\n");
 50
 51//-----------------------------------------------------------------------------
 52// Object setup and teardown
 53//-----------------------------------------------------------------------------
 54CustomShaderFeatureData::CustomShaderFeatureData()
 55{
 56#ifdef TORQUE_D3D11
 57   mFeatureHLSL = nullptr;
 58#endif
 59#ifdef TORQUE_OPENGL
 60   mFeatureGLSL = nullptr;
 61#endif
 62}
 63
 64CustomShaderFeatureData::~CustomShaderFeatureData()
 65{
 66}
 67
 68//-----------------------------------------------------------------------------
 69// Object Editing
 70//-----------------------------------------------------------------------------
 71void CustomShaderFeatureData::initPersistFields()
 72{
 73   // SceneObject already handles exposing the transform
 74   Parent::initPersistFields();
 75}
 76
 77bool CustomShaderFeatureData::onAdd()
 78{
 79   if (!Parent::onAdd())
 80      return false;
 81
 82#ifdef TORQUE_D3D11
 83   if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
 84   {
 85      mFeatureHLSL = new CustomFeatureHLSL();
 86      mFeatureHLSL->mOwner = this;
 87   }
 88#endif
 89
 90#ifdef TORQUE_OPENGL
 91   if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
 92   {
 93      mFeatureGLSL = new CustomFeatureGLSL();
 94      mFeatureGLSL->mOwner = this;
 95   }
 96#endif
 97
 98   return true;
 99}
100
101void CustomShaderFeatureData::onRemove()
102{
103   Parent::onRemove();
104}
105
106//Shadergen setup functions
107void CustomShaderFeatureData::addVariable(String name, String type, String defaultValue)
108{
109#ifdef TORQUE_D3D11
110   if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
111      mFeatureHLSL->addVariable(name, type, defaultValue);
112#endif
113#ifdef TORQUE_OPENGL
114   if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
115      mFeatureGLSL->addVariable(name, type, defaultValue);
116#endif
117}
118
119void CustomShaderFeatureData::addUniform(String name, String type, String defaultValue, U32 arraySize)
120{
121#ifdef TORQUE_D3D11
122   if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
123      mFeatureHLSL->addUniform(name, type, defaultValue, arraySize);
124#endif
125#ifdef TORQUE_OPENGL
126   if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
127      mFeatureGLSL->addUniform(name, type, defaultValue, arraySize);
128#endif
129}
130
131void CustomShaderFeatureData::addSampler(String name, String type, U32 arraySize)
132{
133#ifdef TORQUE_D3D11
134   if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
135      mFeatureHLSL->addSampler(name, type, arraySize);
136#endif
137#ifdef TORQUE_OPENGL
138   if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
139      mFeatureGLSL->addSampler(name, type, arraySize);
140#endif
141}
142
143void CustomShaderFeatureData::addTexture(String name, String type, String samplerState, U32 arraySize)
144{
145#ifdef TORQUE_D3D11
146   if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
147      mFeatureHLSL->addTexture(name, type, samplerState, arraySize);
148#endif
149#ifdef TORQUE_OPENGL
150   if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
151      mFeatureGLSL->addTexture(name, type, samplerState, arraySize);
152#endif
153}
154
155void CustomShaderFeatureData::addConnector(String name, String type, String elementName)
156{
157#ifdef TORQUE_D3D11
158   if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
159      mFeatureHLSL->addConnector(name, type, elementName);
160#endif
161#ifdef TORQUE_OPENGL
162   if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
163      mFeatureGLSL->addConnector(name, type, elementName);
164#endif
165}
166
167void CustomShaderFeatureData::addVertTexCoord(String name)
168{
169#ifdef TORQUE_D3D11
170   if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
171      mFeatureHLSL->addVertTexCoord(name);
172#endif
173#ifdef TORQUE_OPENGL
174   if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
175      mFeatureGLSL->addVertTexCoord(name);
176#endif
177}
178
179bool CustomShaderFeatureData::hasFeature(String name)
180{
181#ifdef TORQUE_D3D11
182   if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
183      return mFeatureHLSL->hasFeature(name);
184#endif
185#ifdef TORQUE_OPENGL
186   if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
187      return mFeatureGLSL->hasFeature(name);
188#endif
189
190   return false;
191}
192
193void CustomShaderFeatureData::writeLine(String format, S32 argc, ConsoleValueRef* argv)
194{
195#ifdef TORQUE_D3D11
196   if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
197      mFeatureHLSL->writeLine(format, argc, argv);
198#endif
199#ifdef TORQUE_OPENGL
200   if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
201      mFeatureGLSL->writeLine(format, argc, argv);
202#endif
203}
204
205DefineEngineMethod(CustomShaderFeatureData, addVariable, void, (String name, String type, String defaultValue), ("", "", ""), "")
206{
207   object->addVariable(name, type, defaultValue);
208}
209
210DefineEngineMethod(CustomShaderFeatureData, addUniform, void, (String name, String type, String defaultValue, U32 arraySize), ("", "", "", 0), "")
211{
212   object->addUniform(name, type, defaultValue, arraySize);
213}
214
215DefineEngineMethod(CustomShaderFeatureData, addSampler, void, (String name, U32 arraySize), ("", 0), "")
216{
217   object->addSampler(name, "", arraySize);
218}
219
220DefineEngineMethod(CustomShaderFeatureData, addTexture, void, (String name, String type, String samplerState, U32 arraySize), ("", "", 0), "")
221{
222   object->addTexture(name, type, samplerState, arraySize);
223}
224
225DefineEngineMethod(CustomShaderFeatureData, addConnector, void, (String name, String type, String elementName), ("", "", ""), "")
226{
227   object->addConnector(name, type, elementName);
228}
229
230DefineEngineMethod(CustomShaderFeatureData, addVertTexCoord, void, (String name), (""), "")
231{
232   object->addVertTexCoord(name);
233}
234
235DefineEngineStringlyVariadicMethod(CustomShaderFeatureData, writeLine, void, 3, 0, "( string format, string args... ) Dynamically call a method on an object.\n"
236   "@param method Name of method to call.\n"
237   "@param args Zero or more arguments for the method.\n"
238   "@return The result of the method call.")
239{
240   object->writeLine(argv[2], argc - 3, argv + 3);
241}
242
243DefineEngineMethod(CustomShaderFeatureData, hasFeature, bool, (String name), (""), "")
244{
245   return object->hasFeature(name);
246}
247