shaderOp.h
Engine/source/shaderGen/shaderOp.h
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 _SHADEROP_H_ 24#define _SHADEROP_H_ 25 26#ifndef _LANG_ELEMENT_H_ 27#include "shaderGen/langElement.h" 28#endif 29 30//************************************************************************** 31/*! 32 This file contains "shader operation" classes. Originally they were 33 to represent basic language operations like adding, assignment, etc. 34 That proved to be far too verbose when implementing shader features, 35 so they became more generalized helper classes. Along with LangElement 36 classes, they are the building blocks for the procedurally generated 37 shaders. 38 39 Each shader is a linked list of LangElements. The list is generated 40 when the features of the shader are processed. When all the features 41 are processed, then ShaderGen prints them out by traversing the linked 42 list of LangElement and calling their print() function. 43 44 The ShaderOp classes are just extensions of LangElement. 45 46*/ 47//************************************************************************** 48 49 50 51///************************************************************************** 52/// Shader operation base class 53///************************************************************************** 54class ShaderOp : public LangElement 55{ 56protected: 57 LangElement * mInput[2]; 58 59public: 60 ShaderOp( LangElement *in1, LangElement *in2 ); 61}; 62 63//---------------------------------------------------------------------------- 64/*! 65 DecOp - Declaration Operation - Used when declaring a variable in a shader 66 feature. It will automatically print the type of the variable and then 67 the variable name. If a shader feature set up code like: 68 69 @code 70 71 Var *foo = new Var; 72 foo->setType( "float" ); 73 foo->setName( "foo" ); 74 LangElement *fooDecl = new DecOp( foo ); 75 76 LangElement *statement = new GenOp( " @ = 8.0 * 5.0;", fooDecl ); 77 78 @endcode 79 80 The output in the shader file would be: 81 82 @code 83 float foo = 8.0 * 5.0; 84 @endcode 85*/ 86//---------------------------------------------------------------------------- 87class DecOp : public ShaderOp 88{ 89 typedef ShaderOp Parent; 90 91public: 92 DecOp( Var *in1 ); 93 virtual void print( Stream &stream ); 94}; 95 96 97//---------------------------------------------------------------------------- 98/*! 99 Like the name suggests, EchoOp merely echoes back whatever string it is 100 assigned. 101*/ 102//---------------------------------------------------------------------------- 103class EchoOp : public ShaderOp 104{ 105 typedef ShaderOp Parent; 106 const char * mStatement; 107 108public: 109 EchoOp( const char * statement ); 110 ~EchoOp(); 111 virtual void print( Stream &stream ); 112}; 113 114//---------------------------------------------------------------------------- 115/*! 116 Accesses the given index on the variable 117*/ 118//---------------------------------------------------------------------------- 119class IndexOp : public ShaderOp 120{ 121 typedef ShaderOp Parent; 122 U32 mIndex; 123 124public: 125 IndexOp( Var* var, U32 index ); 126 virtual void print( Stream &stream ); 127}; 128 129 130//---------------------------------------------------------------------------- 131/*! 132 GenOp - General Operation - Very useful for combining several variables 133 into one LangElement statement. It uses an elipses as a parameter, so it can 134 take as many variables as you can throw at it. It takes a string and parses 135 it for the '@' symbol which it replaces with passed in parameters. Similar 136 to the C statement printf(). Here's an example: 137 138 @code 139 ( assuming three variables var1, var2, var3 exist and their assigned names 140 are var1Name, var2Name, and var3Name ) 141 142 LangElement *statement = new GenOp( " @ = @ * @.x + @.y;", var1, var1, var2, var3 ); 143 144 @endcode 145 146 The output in the shader file would be: 147 148 @code 149 150 var1Name = var1Name * var2Name.x + var3Name.y; 151 152 @endcode 153*/ 154//---------------------------------------------------------------------------- 155class GenOp : public ShaderOp 156{ 157 typedef ShaderOp Parent; 158 159 Vector<LangElement*> mElemList; 160 161public: 162 GenOp( const char * statement, ... ); 163 virtual void print( Stream &stream ); 164 165}; 166 167#endif // _SHADEROP_H_ 168