baseMatInstance.h
Engine/source/materials/baseMatInstance.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 _BASEMATINSTANCE_H_ 24#define _BASEMATINSTANCE_H_ 25 26#ifndef _TSIGNAL_H_ 27#include "core/util/tSignal.h" 28#endif 29#ifndef _BASEMATERIALDEFINITION_H_ 30#include "materials/baseMaterialDefinition.h" 31#endif 32#ifndef _MATERIALPARAMETERS_H_ 33#include "materials/materialParameters.h" 34#endif 35#ifndef _MMATRIX_H_ 36#include "math/mMatrix.h" 37#endif 38#ifndef _GFXENUMS_H_ 39#include "gfx/gfxEnums.h" 40#endif 41#ifndef _GFXSHADER_H_ 42#include "gfx/gfxShader.h" 43#endif 44#ifndef _MATERIALFEATUREDATA_H_ 45#include "materials/materialFeatureData.h" 46#endif 47#ifndef _MATINSTANCEHOOK_H_ 48#include "materials/matInstanceHook.h" 49#endif 50#ifndef _MATSTATEHINT_H_ 51#include "materials/matStateHint.h" 52#endif 53 54struct RenderPassData; 55class GFXVertexBufferHandleBase; 56class GFXPrimitiveBufferHandle; 57struct SceneData; 58class SceneRenderState; 59struct GFXStateBlockDesc; 60class GFXVertexFormat; 61class MatrixSet; 62class ProcessedMaterial; 63 64 65/// 66class BaseMatInstance 67{ 68protected: 69 70 /// The array of active material hooks indexed 71 /// by a MatInstanceHookType. 72 Vector<MatInstanceHook*> mHooks; 73 74 /// 75 MatFeaturesDelegate mFeaturesDelegate; 76 77 /// Should be true if init has been called and it succeeded. 78 /// It is up to the derived class to set this variable appropriately. 79 bool mIsValid; 80 81 /// This is set by initialization and used by the prepass. 82 bool mHasNormalMaps; 83 84 /// This material makes use of bone transforms 85 bool mUsesHardwareSkinning; 86 87public: 88 89 virtual ~BaseMatInstance(); 90 91 /// @param features The features you want to allow for this material. 92 /// 93 /// @param vertexFormat The vertex format on which this material will be rendered. 94 /// 95 /// @see GFXVertexFormat 96 /// @see FeatureSet 97 virtual bool init( const FeatureSet &features, 98 const GFXVertexFormat *vertexFormat ) = 0; 99 100 /// Reinitializes the material using the previous 101 /// initialization parameters. 102 /// @see init 103 virtual bool reInit() = 0; 104 105 /// Returns true if init has been successfully called. 106 /// It is up to the derived class to set this value properly. 107 bool isValid() { return mIsValid; } 108 109 /// Adds this stateblock to the base state block 110 /// used during initialization. 111 /// @see init 112 virtual void addStateBlockDesc(const GFXStateBlockDesc& desc) = 0; 113 114 /// Updates the state blocks for this material. 115 virtual void updateStateBlocks() = 0; 116 117 /// Adds a shader macro which will be passed to the shader 118 /// during initialization. 119 /// @see init 120 virtual void addShaderMacro( const String &name, const String &value ) = 0; 121 122 /// Get a MaterialParameters block for this BaseMatInstance, 123 /// caller is responsible for freeing it. 124 virtual MaterialParameters* allocMaterialParameters() = 0; 125 126 /// Set the current parameters for this BaseMatInstance 127 virtual void setMaterialParameters(MaterialParameters* param) = 0; 128 129 /// Get the current parameters for this BaseMatInstance (BaseMatInstances are created with a default active 130 /// MaterialParameters which is managed by BaseMatInstance. 131 virtual MaterialParameters* getMaterialParameters() = 0; 132 133 /// Returns a MaterialParameterHandle for name. 134 virtual MaterialParameterHandle* getMaterialParameterHandle(const String& name) = 0; 135 136 /// Sets up the next rendering pass for this material. It is 137 /// typically called like so... 138 /// 139 ///@code 140 /// while( mat->setupPass( state, sgData ) ) 141 /// { 142 /// mat->setTransforms(...); 143 /// mat->setSceneInfo(...); 144 /// ... 145 /// GFX->drawPrimitive(); 146 /// } 147 ///@endcode 148 /// 149 virtual bool setupPass( SceneRenderState *state, const SceneData &sgData ) = 0; 150 151 /// This initializes the material transforms and should be 152 /// called after setupPass() within the pass loop. 153 /// @see setupPass 154 virtual void setTransforms( const MatrixSet &matrixSet, SceneRenderState *state ) = 0; 155 156 /// Sets node transforms for the current stage. Used for hardware skinning. 157 virtual void setNodeTransforms( const MatrixF *address, const U32 numTransforms ) = 0; 158 159 /// This initializes various material scene state settings and 160 /// should be called after setupPass() within the pass loop. 161 /// @see setupPass 162 virtual void setSceneInfo( SceneRenderState *state, const SceneData &sgData ) = 0; 163 164 /// This is normally called from within setupPass() automatically, so its 165 /// unnecessary to do so manually unless a texture stage has changed. If 166 /// so it should be called after setupPass() within the pass loop. 167 /// @see setupPass 168 virtual void setTextureStages(SceneRenderState *, const SceneData &sgData ) = 0; 169 170 /// Sets the vertex and primitive buffers as well as the instancing 171 /// stream buffer for the current material if the material is instanced. 172 virtual void setBuffers( GFXVertexBufferHandleBase *vertBuffer, GFXPrimitiveBufferHandle *primBuffer ) = 0; 173 174 /// Returns true if this material is instanced. 175 virtual bool isInstanced() const = 0; 176 177 /// Used to increment the instance buffer for this material. 178 virtual bool stepInstance() = 0; 179 180 /// Returns true if the material is forward lit and requires 181 /// a list of lights which affect it when rendering. 182 virtual bool isForwardLit() const = 0; 183 184 /// Sets a SimObject which will passed into ShaderFeature::createConstHandles. 185 /// Normal features do not make use of this, it is for special class specific 186 /// or user designed features. 187 virtual void setUserObject( SimObject *userObject ) = 0; 188 virtual SimObject* getUserObject() const = 0; 189 190 /// Returns the material this instance is based on. 191 virtual BaseMaterialDefinition* getMaterial() = 0; 192 193 // BTRTODO: This stuff below should probably not be in BaseMatInstance 194 virtual bool hasGlow() = 0; 195 virtual bool hasAccumulation() = 0; 196 197 virtual U32 getCurPass() = 0; 198 199 virtual U32 getCurStageNum() = 0; 200 201 virtual RenderPassData *getPass(U32 pass) = 0; 202 203 /// Returns the state hint which can be used for 204 /// sorting and fast comparisions of the equality 205 /// of a material instance. 206 virtual const MatStateHint& getStateHint() const = 0; 207 208 /// Returns the active features in use by this material. 209 /// @see getRequestedFeatures 210 virtual const FeatureSet& getFeatures() const = 0; 211 212 /// Returns the features that were requested at material 213 /// creation time which may differ from the active features. 214 /// @see getFeatures 215 virtual const FeatureSet& getRequestedFeatures() const = 0; 216 217 virtual const GFXVertexFormat* getVertexFormat() const = 0; 218 219 virtual void dumpShaderInfo() const = 0; 220 221 /// Fast test for use of normal maps in this material. 222 bool hasNormalMap() const { return mHasNormalMaps; } 223 224 bool usesHardwareSkinning() const { return mUsesHardwareSkinning; } 225 226 /// 227 MatFeaturesDelegate& getFeaturesDelegate() { return mFeaturesDelegate; } 228 229 /// Returns true if this MatInstance is built from a CustomMaterial. 230 virtual bool isCustomMaterial() const = 0; 231 232 /// @name Material Hook functions 233 /// @{ 234 235 /// 236 void addHook( MatInstanceHook *hook ); 237 238 /// Helper function for getting a hook. 239 /// @see getHook 240 template <class HOOK> 241 inline HOOK* getHook() { return (HOOK*)getHook( HOOK::Type ); } 242 243 /// 244 MatInstanceHook* getHook( const MatInstanceHookType &type ) const; 245 246 /// 247 void deleteHook( const MatInstanceHookType &type ); 248 249 /// 250 U32 deleteAllHooks(); 251 252 /// @} 253 254 virtual const GFXStateBlockDesc &getUserStateBlock() const = 0; 255 256}; 257 258#endif /// _BASEMATINSTANCE_H_ 259 260 261 262 263 264 265
