123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- //-----------------------------------------------------------------------------
- // 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 _SHADERTDATA_H_
- #define _SHADERTDATA_H_
- #ifndef _SIMOBJECT_H_
- #include "console/simObject.h"
- #endif
- #ifndef _GFXSHADER_H_
- #include "gfx/gfxShader.h"
- #endif
- #ifndef _TDICTIONARY_H_
- #include "core/util/tDictionary.h"
- #endif
- class GFXShader;
- class ShaderData;
- struct GFXShaderMacro;
- ///
- class ShaderData : public SimObject
- {
- typedef SimObject Parent;
- protected:
- ///
- static Vector<ShaderData*> smAllShaderData;
- typedef HashTable<String,GFXShaderRef> ShaderCache;
- ShaderCache mShaders;
- bool mUseDevicePixVersion;
- F32 mPixVersion;
- StringTableEntry mDXVertexShaderName;
- StringTableEntry mDXPixelShaderName;
- StringTableEntry mOGLVertexShaderName;
- StringTableEntry mOGLPixelShaderName;
- /// A semicolon, tab, or newline delimited string of case
- /// sensitive defines that are passed to the shader compiler.
- ///
- /// For example:
- ///
- /// SAMPLE_TAPS=10;USE_TEXKILL;USE_TORQUE_FOG=1
- ///
- String mDefines;
- /// The shader macros built from mDefines.
- /// @see _getMacros()
- Vector<GFXShaderMacro> mShaderMacros;
- /// Returns the shader macros taking care to rebuild
- /// them if the content has changed.
- const Vector<GFXShaderMacro>& _getMacros();
- /// Helper for converting an array of macros
- /// into a formatted string.
- void _stringizeMacros( const Vector<GFXShaderMacro> ¯os,
- String *outString );
- /// Creates a new shader returning NULL on error.
- GFXShader* _createShader( const Vector<GFXShaderMacro> ¯os );
- /// @see LightManager::smActivateSignal
- static void _onLMActivate( const char *lm, bool activate );
- enum
- {
- NumTextures = 16
- };
- String mSamplerNames[NumTextures];
- bool mRTParams[NumTextures];
- bool _checkDefinition(GFXShader *shader);
- public:
- void setSamplerName(const String &name, int idx) { mSamplerNames[idx] = name; }
- String getSamplerName(int idx) const { return mSamplerNames[idx]; }
- bool hasSamplerDef(const String &samplerName, int &pos) const;
- bool hasRTParamsDef(const int pos) const { return mRTParams[pos]; }
- ShaderData();
- /// Returns an initialized shader instance or NULL
- /// if the shader failed to be created.
- GFXShader* getShader( const Vector<GFXShaderMacro> ¯os = Vector<GFXShaderMacro>() );
- /// Forces a reinitialization of all the instanced shaders.
- void reloadShaders();
- /// Forces a reinitialization of the instanced shaders for
- /// all loaded ShaderData objects in the system.
- static void reloadAllShaders();
- /// Returns the required pixel shader version for this shader.
- F32 getPixVersion() const { return mPixVersion; }
-
- // SimObject
- virtual bool onAdd();
- virtual void onRemove();
- // ConsoleObject
- static void initPersistFields();
- DECLARE_CONOBJECT(ShaderData);
- };
- #endif // _SHADERTDATA_H_
|