123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #ifndef _SHADEROP_H_
- #define _SHADEROP_H_
- #ifndef _LANG_ELEMENT_H_
- #include "shaderGen/langElement.h"
- #endif
- //**************************************************************************
- /*!
- This file contains "shader operation" classes. Originally they were
- to represent basic language operations like adding, assignment, etc.
- That proved to be far too verbose when implementing shader features,
- so they became more generalized helper classes. Along with LangElement
- classes, they are the building blocks for the procedurally generated
- shaders.
-
- Each shader is a linked list of LangElements. The list is generated
- when the features of the shader are processed. When all the features
- are processed, then ShaderGen prints them out by traversing the linked
- list of LangElement and calling their print() function.
- The ShaderOp classes are just extensions of LangElement.
- */
- //**************************************************************************
- ///**************************************************************************
- /// Shader operation base class
- ///**************************************************************************
- class ShaderOp : public LangElement
- {
- protected:
- LangElement * mInput[2];
- public:
- ShaderOp( LangElement *in1, LangElement *in2 );
- };
- //----------------------------------------------------------------------------
- /*!
- DecOp - Declaration Operation - Used when declaring a variable in a shader
- feature. It will automatically print the type of the variable and then
- the variable name. If a shader feature set up code like:
- @code
- Var *foo = new Var;
- foo->setType( "float" );
- foo->setName( "foo" );
- LangElement *fooDecl = new DecOp( foo );
- LangElement *statement = new GenOp( " @ = 8.0 * 5.0;", fooDecl );
- @endcode
- The output in the shader file would be:
-
- @code
- float foo = 8.0 * 5.0;
- @endcode
- */
- //----------------------------------------------------------------------------
- class DecOp : public ShaderOp
- {
- typedef ShaderOp Parent;
- public:
- DecOp( Var *in1 );
- virtual void print( Stream &stream );
- };
- //----------------------------------------------------------------------------
- /*!
- Like the name suggests, EchoOp merely echoes back whatever string it is
- assigned.
- */
- //----------------------------------------------------------------------------
- class EchoOp : public ShaderOp
- {
- typedef ShaderOp Parent;
- const char * mStatement;
- public:
- EchoOp( const char * statement );
- ~EchoOp();
- virtual void print( Stream &stream );
- };
- //----------------------------------------------------------------------------
- /*!
- Accesses the given index on the variable
- */
- //----------------------------------------------------------------------------
- class IndexOp : public ShaderOp
- {
- typedef ShaderOp Parent;
- U32 mIndex;
- public:
- IndexOp( Var* var, U32 index );
- virtual void print( Stream &stream );
- };
- //----------------------------------------------------------------------------
- /*!
- GenOp - General Operation - Very useful for combining several variables
- into one LangElement statement. It uses an elipses as a parameter, so it can
- take as many variables as you can throw at it. It takes a string and parses
- it for the '@' symbol which it replaces with passed in parameters. Similar
- to the C statement printf(). Here's an example:
-
- @code
- ( assuming three variables var1, var2, var3 exist and their assigned names
- are var1Name, var2Name, and var3Name )
-
- LangElement *statement = new GenOp( " @ = @ * @.x + @.y;", var1, var1, var2, var3 );
-
- @endcode
- The output in the shader file would be:
-
- @code
-
- var1Name = var1Name * var2Name.x + var3Name.y;
-
- @endcode
- */
- //----------------------------------------------------------------------------
- class GenOp : public ShaderOp
- {
- typedef ShaderOp Parent;
- Vector<LangElement *> mElemList;
- public:
- GenOp( const char * statement, ... );
- virtual void print( Stream &stream );
- };
- #endif // _SHADEROP_H_
|