customShaderFeature.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "shadergen/CustomShaderFeature.h"
  23. #include "shaderGen/HLSL/customFeatureHLSL.h"
  24. #include "math/mathIO.h"
  25. #include "scene/sceneRenderState.h"
  26. #include "core/stream/bitStream.h"
  27. #include "materials/sceneData.h"
  28. #include "gfx/gfxDebugEvent.h"
  29. #include "gfx/gfxTransformSaver.h"
  30. #include "renderInstance/renderPassManager.h"
  31. IMPLEMENT_CONOBJECT(CustomShaderFeatureData);
  32. ConsoleDocClass(CustomShaderFeatureData,
  33. "@brief An example scene object which renders using a callback.\n\n"
  34. "This class implements a basic SceneObject that can exist in the world at a "
  35. "3D position and render itself. Note that CustomShaderFeatureData handles its own "
  36. "rendering by submitting itself as an ObjectRenderInst (see "
  37. "renderInstance\renderPassmanager.h) along with a delegate for its render() "
  38. "function. However, the preffered rendering method in the engine is to submit "
  39. "a MeshRenderInst along with a Material, vertex buffer, primitive buffer, and "
  40. "transform and allow the RenderMeshMgr handle the actual rendering. You can "
  41. "see this implemented in RenderMeshExample.\n\n"
  42. "See the C++ code for implementation details.\n\n"
  43. "@ingroup Examples\n");
  44. //-----------------------------------------------------------------------------
  45. // Object setup and teardown
  46. //-----------------------------------------------------------------------------
  47. CustomShaderFeatureData::CustomShaderFeatureData()
  48. {
  49. }
  50. CustomShaderFeatureData::~CustomShaderFeatureData()
  51. {
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Object Editing
  55. //-----------------------------------------------------------------------------
  56. void CustomShaderFeatureData::initPersistFields()
  57. {
  58. // SceneObject already handles exposing the transform
  59. Parent::initPersistFields();
  60. }
  61. bool CustomShaderFeatureData::onAdd()
  62. {
  63. if (!Parent::onAdd())
  64. return false;
  65. mFeatureHLSL = new CustomFeatureHLSL();
  66. mFeatureHLSL->mOwner = this;
  67. return true;
  68. }
  69. void CustomShaderFeatureData::onRemove()
  70. {
  71. Parent::onRemove();
  72. }
  73. //Shadergen setup functions
  74. void CustomShaderFeatureData::addVariable(String name, String type, String defaultValue)
  75. {
  76. mFeatureHLSL->addVariable(name, type, defaultValue);
  77. }
  78. void CustomShaderFeatureData::writeLine(String format, S32 argc, ConsoleValueRef *argv)
  79. {
  80. /*mOnObject = onObject;
  81. mArgc = argc;
  82. mArgv = new ConsoleValueRef[argc];
  83. for (int i = 0; i<argc; i++)
  84. {
  85. mArgv[i].value = new ConsoleValue();
  86. mArgv[i].value->type = ConsoleValue::TypeInternalString;
  87. mArgv[i].value->init();
  88. if (argv)
  89. {
  90. mArgv[i].value->setStringValue((const char*)argv[i]);
  91. }
  92. }*/
  93. mFeatureHLSL->writeLine(format, argc, argv);
  94. }
  95. /*//Actual shader processing
  96. void CustomShaderFeatureData::processVert(Vector<ShaderComponent*> &componentList,
  97. const MaterialFeatureData &fd)
  98. {
  99. mFeatureHLSL.processVert(componentList, fd);
  100. }
  101. void CustomShaderFeatureData::processPix(Vector<ShaderComponent*> &componentList,
  102. const MaterialFeatureData &fd)
  103. {
  104. mFeatureHLSL.processPix(componentList, fd);
  105. }
  106. void CustomShaderFeatureData::setTexData(Material::StageData &stageDat,
  107. const MaterialFeatureData &fd,
  108. RenderPassData &passData,
  109. U32 &texIndex)
  110. {
  111. mFeatureHLSL.setTexData(stageDat, fd, passData, texIndex);
  112. }*/
  113. DefineEngineMethod(CustomShaderFeatureData, addVariable, void, (String name, String type, String defaultValue), ("", "", ""), "")
  114. {
  115. object->addVariable(name, type, defaultValue);
  116. }
  117. ConsoleMethod(CustomShaderFeatureData, writeLine, void, 3, 0, "( string format, string args... ) Dynamically call a method on an object.\n"
  118. "@param method Name of method to call.\n"
  119. "@param args Zero or more arguments for the method.\n"
  120. "@return The result of the method call.")
  121. {
  122. object->writeLine(argv[2], argc - 3, argv + 3);
  123. }