Torque3D Documentation / _generateds / conditionerFeature.h

conditionerFeature.h

Engine/source/shaderGen/conditionerFeature.h

More...

Classes:

Detailed Description

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