langElement.h
Engine/source/shaderGen/langElement.h
Classes:
Public Defines
define
WRITESTR(a) { stream.write( (), ); }
Public Enumerations
enum
ConstantSortPosition { cspUninit = 0 cspPrimitive cspPotentialPrimitive cspPass csp_Count }
Detailed Description
Public Defines
WRITESTR(a) { stream.write( (), ); }
Public Enumerations
ConstantSortPosition
Enumerator
- cspUninit = 0
Default / unset.
- cspPrimitive
Updated before every draw primitive call.
- cspPotentialPrimitive
Potentially updated every draw primitive call, but not necessarily (lights for example)
- cspPass
Updated one per pass.
- csp_Count
Count var, do not use.
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 _LANG_ELEMENT_H_ 24#define _LANG_ELEMENT_H_ 25 26#ifndef _TVECTOR_H_ 27#include "core/util/tVector.h" 28#endif 29 30#ifndef _STREAM_H_ 31#include "core/stream/stream.h" 32#endif 33 34#define WRITESTR( a ){ stream.write( dStrlen(a), a ); } 35 36 37//************************************************************************** 38/*! 39 The LangElement class is the base building block for procedurally 40 generated shader code. LangElement and its subclasses are strung 41 together using the static Vector 'elementList'. 42 When a shader needs to be written to disk, the elementList is 43 traversed and print() is called on each LangElement and the shader 44 is output. elementList is cleared after each shader is printed out. 45*/ 46//************************************************************************** 47 48 49//************************************************************************** 50// Language element 51//************************************************************************** 52struct LangElement 53{ 54 static Vector<LangElement*> elementList; 55 static LangElement * find( const char *name ); 56 static void deleteElements(); 57 58 U8 name[32]; 59 60 LangElement(); 61 virtual ~LangElement() {}; 62 virtual void print( Stream &stream ){}; 63 void setName(const char *newName ); 64 65}; 66 67enum ConstantSortPosition 68{ 69 /// Default / unset 70 cspUninit = 0, 71 /// Updated before every draw primitive call. 72 cspPrimitive, 73 /// Potentially updated every draw primitive call, but not necessarily (lights for example) 74 cspPotentialPrimitive, 75 /// Updated one per pass 76 cspPass, 77 /// Count var, do not use 78 csp_Count 79}; 80 81//---------------------------------------------------------------------------- 82/*! 83 Var - Variable - used to specify a variable to be used in a shader. 84 Var stores information such that when it is printed out, its context 85 can be identified and the proper information will automatically be printed. 86 For instance, if a variable is created with 'uniform' set to true, when the 87 shader function definition is printed, it will automatically add that 88 variable to the incoming parameters of the shader. There are several 89 similar cases such as when a new variable is declared within a shader. 90 91 example: 92 93 @code 94 95 Var *modelview = new Var; 96 modelview->setType( "float4x4" ); 97 modelview->setName( "modelview" ); 98 modelview->uniform = true; 99 modelview->constSortPos = cspPass; 100 101 @endcode 102 103 it prints out in the shader declaration as: 104 105 @code 106 ConnectData main( VertData IN, 107 uniform float4x4 modelview : register(C0) ) 108 @endcode 109 110*/ 111//---------------------------------------------------------------------------- 112struct Var : public LangElement 113{ 114 U8 type[32]; 115 U8 structName[32]; 116 char connectName[32]; 117 ConstantSortPosition constSortPos; // used to calculate constant number 118 U32 constNum; 119 U32 texCoordNum; 120 bool uniform; // argument passed in through constant registers 121 bool vertData; // argument coming from vertex data 122 bool connector; // variable that will be passed to pixel shader 123 bool sampler; // texture 124 bool texture; //for D3D11 texture variables 125 U32 arraySize; // 1 = no array, > 1 array of "type" 126 U32 rank; // optional rank system to assist in sorting vars if needed 127 128 static U32 texUnitCount; 129 static U32 getTexUnitNum(U32 numElements = 1); 130 static void reset(); 131 132 // Default 133 Var(); 134 Var( const char *name, const char *type ); 135 136 void setStructName(const char *newName ); 137 void setConnectName(const char *newName ); 138 void setType(const char *newType ); 139 140 virtual void print( Stream &stream ); 141 142 // Construct a uniform / shader const var 143 void setUniform(const String& constType, const String& constName, ConstantSortPosition sortPos); 144}; 145 146//---------------------------------------------------------------------------- 147/*! 148 MultiLine - Multi Line Statement - This class simply ties multiple 149 150 example: 151 152 @code 153 154 MultiLine *meta = new MultiLine; 155 meta->addStatement( new GenOp( "foo = true;\r\n" ) ); 156 meta->addStatement( new GenOp( "bar = false;\r\n ) ); 157 158 @endcode 159 160 it prints out in the shader declaration as: 161 162 @code 163 foo = true; 164 bar = false; 165 @endcode 166 167*/ 168//---------------------------------------------------------------------------- 169class MultiLine : public LangElement 170{ 171 Vector <LangElement*> mStatementList; 172 173public: 174 MultiLine() 175 { 176 VECTOR_SET_ASSOCIATION( mStatementList ); 177 } 178 179 void addStatement( LangElement *elem ); 180 virtual void print( Stream &stream ); 181}; 182 183 184 185#endif // _LANG_ELEMENT_H_ 186