shaderData.h
Engine/source/materials/shaderData.h
Classes:
class
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 _SHADERTDATA_H_ 24#define _SHADERTDATA_H_ 25 26#ifndef _SIMOBJECT_H_ 27#include "console/simObject.h" 28#endif 29#ifndef _GFXSHADER_H_ 30#include "gfx/gfxShader.h" 31#endif 32#ifndef _TDICTIONARY_H_ 33#include "core/util/tDictionary.h" 34#endif 35 36class GFXShader; 37class ShaderData; 38struct GFXShaderMacro; 39 40 41/// 42class ShaderData : public SimObject 43{ 44 typedef SimObject Parent; 45 46protected: 47 48 /// 49 static Vector<ShaderData*> smAllShaderData; 50 51 typedef HashTable<String,GFXShaderRef> ShaderCache; 52 53 ShaderCache mShaders; 54 55 bool mUseDevicePixVersion; 56 57 F32 mPixVersion; 58 59 FileName mDXVertexShaderName; 60 61 FileName mDXPixelShaderName; 62 63 FileName mOGLVertexShaderName; 64 65 FileName mOGLPixelShaderName; 66 67 /// A semicolon, tab, or newline delimited string of case 68 /// sensitive defines that are passed to the shader compiler. 69 /// 70 /// For example: 71 /// 72 /// SAMPLE_TAPS=10;USE_TEXKILL;USE_TORQUE_FOG=1 73 /// 74 String mDefines; 75 76 /// The shader macros built from mDefines. 77 /// @see _getMacros() 78 Vector<GFXShaderMacro> mShaderMacros; 79 80 /// Returns the shader macros taking care to rebuild 81 /// them if the content has changed. 82 const Vector<GFXShaderMacro>& _getMacros(); 83 84 /// Helper for converting an array of macros 85 /// into a formatted string. 86 void _stringizeMacros( const Vector<GFXShaderMacro> ¯os, 87 String *outString ); 88 89 /// Creates a new shader returning NULL on error. 90 GFXShader* _createShader( const Vector<GFXShaderMacro> ¯os ); 91 92 /// @see LightManager::smActivateSignal 93 static void _onLMActivate( const char *lm, bool activate ); 94 95 enum 96 { 97 NumTextures = 8 98 }; 99 100 String mSamplerNames[NumTextures]; 101 bool mRTParams[NumTextures]; 102 103 bool _checkDefinition(GFXShader *shader); 104 105public: 106 107 void setSamplerName(const String &name, int idx) { mSamplerNames[idx] = name; } 108 String getSamplerName(int idx) const { return mSamplerNames[idx]; } 109 110 bool hasSamplerDef(const String &samplerName, int &pos) const; 111 bool hasRTParamsDef(const int pos) const { return mRTParams[pos]; } 112 113 ShaderData(); 114 115 /// Returns an initialized shader instance or NULL 116 /// if the shader failed to be created. 117 GFXShader* getShader( const Vector<GFXShaderMacro> ¯os = Vector<GFXShaderMacro>() ); 118 119 /// Forces a reinitialization of all the instanced shaders. 120 void reloadShaders(); 121 122 /// Forces a reinitialization of the instanced shaders for 123 /// all loaded ShaderData objects in the system. 124 static void reloadAllShaders(); 125 126 /// Returns the required pixel shader version for this shader. 127 F32 getPixVersion() const { return mPixVersion; } 128 129 // SimObject 130 virtual bool onAdd(); 131 virtual void onRemove(); 132 133 // ConsoleObject 134 static void initPersistFields(); 135 DECLARE_CONOBJECT(ShaderData); 136}; 137 138#endif // _SHADERTDATA_H_ 139