Torque3D Documentation / _generateds / matTextureTarget.h

matTextureTarget.h

Engine/source/materials/matTextureTarget.h

More...

Classes:

Public Typedefs

NamedTexTargetRef 

A weak reference to a texture target.

Detailed Description

Public Typedefs

typedef WeakRefPtr< NamedTexTarget > NamedTexTargetRef 

A weak reference to a texture target.

  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
 24#ifndef _MATTEXTURETARGET_H_
 25#define _MATTEXTURETARGET_H_
 26
 27#ifndef _TDICTIONARY_H_
 28#include "core/util/tDictionary.h"
 29#endif
 30#ifndef _REFBASE_H_
 31#include "core/util/refBase.h"
 32#endif
 33#ifndef _GFXTEXTUREHANDLE_H_
 34#include "gfx/gfxTextureHandle.h"
 35#endif
 36#ifndef _MRECT_H_
 37#include "math/mRect.h"
 38#endif
 39#ifndef _GFXSTATEBLOCK_H_
 40#include "gfx/gfxStateBlock.h"
 41#endif
 42#ifndef _UTIL_DELEGATE_H_
 43#include "core/util/delegate.h"
 44#endif
 45
 46struct GFXShaderMacro;
 47class ConditionerFeature;
 48
 49
 50///
 51class NamedTexTarget : public WeakRefBase
 52{
 53public:
 54   
 55   ///
 56   static NamedTexTarget* find( const String &name );
 57
 58   ///
 59   NamedTexTarget();
 60
 61   ///
 62   virtual ~NamedTexTarget();
 63   
 64   ///
 65   bool registerWithName( const String &name );
 66
 67   ///
 68   void unregister();
 69
 70   ///
 71   bool isRegistered() const { return mIsRegistered; }
 72
 73   /// Returns the target name we were registered with.
 74   const String& getName() const { return mName; }
 75
 76   // Register the passed texture with our name, unregistering "anyone"
 77   // priorly registered with that name.   
 78   // Pass NULL to only unregister.
 79   void setTexture( GFXTextureObject *tex ) { setTexture( 0, tex ); }
 80
 81   ///
 82   void setTexture( U32 index, GFXTextureObject *tex );   
 83
 84   ///
 85   GFXTextureObject* getTexture( U32 index = 0 ) const;
 86
 87   /// The delegate used to override the getTexture method.
 88   /// @see getTexture
 89   typedef Delegate<GFXTextureObject*(U32)> TexDelegate;
 90
 91   /// 
 92   /// @see getTexture
 93   TexDelegate& getTextureDelegate() { return mTexDelegate; }
 94   const TexDelegate& getTextureDelegate() const { return mTexDelegate; }
 95
 96   /// Release all the textures.
 97   void release();
 98
 99   // NOTE:
100   //
101   // The following members are here to support the existing conditioner
102   // and target system used for the deferred gbuffer and lighting.
103   //
104   // We will refactor that system as part of material2 removing the concept
105   // of conditioners from C++ (moving them to HLSL/GLSL) and make the shader
106   // features which use the texture responsible for setting the correct sampler
107   // states.
108   //
109   // It could be that at this time this class could completely
110   // be removed and instead these textures can be registered
111   // with the TEXMGR and looked up there exclusively.
112   //
113   void setViewport( const RectI &viewport ) { mViewport = viewport; }
114   const RectI& getViewport() const { return mViewport; }
115   void setSamplerState( const GFXSamplerStateDesc &desc ) { mSamplerDesc = desc; }
116   void setupSamplerState( GFXSamplerStateDesc *desc ) const  { *desc = mSamplerDesc; }
117   void setConditioner( ConditionerFeature *cond ) { mConditioner = cond; }
118   ConditionerFeature* getConditioner() const { return mConditioner; }
119   void getShaderMacros( Vector<GFXShaderMacro> *outMacros );
120
121   typedef Map<String, NamedTexTarget*> TargetMap;
122
123   static TargetMap getTargetMap() {
124      return smTargets;
125   }
126
127protected:
128
129   ///
130   static TargetMap smTargets;
131
132   ///
133   bool mIsRegistered;
134
135   /// The target name we were registered with.
136   String mName;
137
138   /// The held textures.
139   GFXTexHandle mTex[4];
140
141   ///
142   TexDelegate mTexDelegate;
143
144   ///
145   RectI mViewport; 
146
147   ///
148   GFXSamplerStateDesc mSamplerDesc;
149
150   ///
151   ConditionerFeature *mConditioner;
152};
153
154
155inline GFXTextureObject* NamedTexTarget::getTexture( U32 index ) const
156{
157   AssertFatal( index < 4, "NamedTexTarget::getTexture - Got invalid index!" );
158   if ( mTexDelegate.empty() )
159      return mTex[index];
160
161   return mTexDelegate( index );
162}
163
164
165/// A weak reference to a texture target.
166typedef WeakRefPtr<NamedTexTarget> NamedTexTargetRef;
167
168#endif // _MATTEXTURETARGET_H_
169