conditionerFeature.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #ifndef _CONDITIONER_BASE_H_
  23. #define _CONDITIONER_BASE_H_
  24. #ifndef _SHADERFEATURE_H_
  25. #include "shaderGen/shaderFeature.h"
  26. #endif
  27. #ifndef _SHADER_DEPENDENCY_H_
  28. #include "shaderGen/shaderDependency.h"
  29. #endif
  30. class MultiLine;
  31. class ConditionerMethodDependency;
  32. class ConditionerFeature : public ShaderFeature
  33. {
  34. friend class ConditionerMethodDependency;
  35. typedef ShaderFeature Parent;
  36. public:
  37. enum MethodType
  38. {
  39. ConditionMethod = 0, ///< Method used to take unconditioned data, and turn it into a format that can be written to the conditioned buffer
  40. UnconditionMethod, ///< Method used to take conditioned data from a buffer, and extract what is stored
  41. NumMethodTypes,
  42. };
  43. ConditionerFeature( const GFXFormat bufferFormat );
  44. virtual ~ConditionerFeature();
  45. virtual Material::BlendOp getBlendOp()
  46. {
  47. return Material::None;
  48. }
  49. virtual GFXFormat getBufferFormat() const { return mBufferFormat; }
  50. virtual bool setBufferFormat(const GFXFormat bufferFormat) { bool ret = mBufferFormat == bufferFormat; mBufferFormat = bufferFormat; return ret; }
  51. // zero-out these methods
  52. virtual Var* getVertTexCoord( const String &name ) { AssertFatal( false, "don't use this." ); return NULL; }
  53. virtual LangElement *setupTexSpaceMat( Vector<ShaderComponent*> &componentList, Var **texSpaceMat ) { AssertFatal( false, "don't use this." ); return NULL; }
  54. virtual LangElement *expandNormalMap( LangElement *sampleNormalOp, LangElement *normalDecl, LangElement *normalVar, const MaterialFeatureData &fd ) { AssertFatal( false, "don't use this." ); return NULL; }
  55. virtual LangElement *assignColor( LangElement *elem, Material::BlendOp blend, LangElement *lerpElem = NULL, ShaderFeature::OutputTarget outputTarget = ShaderFeature::DefaultTarget ) { AssertFatal( false, "don't use this." ); return NULL; }
  56. // conditioned output
  57. virtual LangElement *assignOutput( Var *unconditionedOutput, ShaderFeature::OutputTarget outputTarget = ShaderFeature::DefaultTarget );
  58. // Get an HLSL/GLSL method name that will be available for the
  59. // shader to read or write data to a conditioned buffer.
  60. virtual const String &getShaderMethodName( MethodType methodType );
  61. // Get the Method Dependency for ShaderGen, for this conditioner
  62. virtual ConditionerMethodDependency *getConditionerMethodDependency( MethodType methodType );
  63. static const String ConditionerIncludeFileName;
  64. static void updateConditioners() { if ( smDirtyConditioners ) _updateConditioners(); }
  65. protected:
  66. static void _updateConditioners();
  67. static bool smDirtyConditioners;
  68. ConditionerMethodDependency *mMethodDependency[NumMethodTypes];
  69. static Vector<ConditionerFeature*> smConditioners;
  70. GFXFormat mBufferFormat;
  71. String mUnconditionMethodName;
  72. String mConditionMethodName;
  73. String mShaderIncludePath;
  74. void _print( Stream *stream );
  75. virtual Var *_conditionOutput( Var *unconditionedOutput, MultiLine *meta );
  76. virtual Var *_unconditionInput( Var *conditionedInput, MultiLine *meta );
  77. // Print method header, return primary parameter
  78. virtual Var *printMethodHeader( MethodType methodType, const String &methodName, Stream &stream, MultiLine *meta );
  79. virtual void printMethodFooter( MethodType methodType, Var *retVar, Stream &stream, MultiLine *meta );
  80. // Print comments
  81. virtual void printHeaderComment( MethodType methodType, const String &methodName, Stream &stream, MultiLine *meta );
  82. virtual void printFooterComment( MethodType methodType, const String &methodName, Stream &stream, MultiLine *meta );
  83. // print a HLSL/GLSL method to a stream, which can be used by a custom shader
  84. // to read conditioned data
  85. virtual void _printMethod( MethodType methodType, const String &methodName, Stream &stream );
  86. };
  87. //------------------------------------------------------------------------------
  88. // ShaderDependancy that allows shadergen features to add a dependency on a conditioner method
  89. class ConditionerMethodDependency : public ShaderDependency
  90. {
  91. protected:
  92. ConditionerFeature *mConditioner;
  93. ConditionerFeature::MethodType mMethodType;
  94. public:
  95. ConditionerMethodDependency( ConditionerFeature *conditioner, const ConditionerFeature::MethodType methodType ) :
  96. mConditioner(conditioner), mMethodType(methodType) {}
  97. virtual void print( Stream &s ) const;
  98. // Auto insert information into a macro
  99. virtual void createMethodMacro( const String &methodName, Vector<GFXShaderMacro> &macros );
  100. };
  101. #endif // _CONDITIONER_BASE_H_