renderPassManager.h
Engine/source/renderInstance/renderPassManager.h
Classes:
class
class
class
A special render instance for occlusion tests.
class
A special render instance for particles.
class
class
A a tiny wrapper around String that exposes a U32 operator so that we can assign the RIT to RenderInst::type field.
class
Public Enumerations
enum
ParticleSystemState { PSS_AwaitingHighResDraw = 0 PSS_AwaitingOffscreenDraw PSS_AwaitingCompositeDraw PSS_AwaitingMixedResDraw PSS_DrawComplete }
Public Typedefs
RenderInstTypeHash
A RenderInstType hash value.
Detailed Description
Public Enumerations
ParticleSystemState
Enumerator
- PSS_AwaitingHighResDraw = 0
- PSS_AwaitingOffscreenDraw
- PSS_AwaitingCompositeDraw
- PSS_AwaitingMixedResDraw
- PSS_DrawComplete
Public Typedefs
typedef U32 RenderInstTypeHash
A RenderInstType hash value.
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 _RENDERPASSMANAGER_H_ 24#define _RENDERPASSMANAGER_H_ 25 26#ifndef _GFXDEVICE_H_ 27#include "gfx/gfxDevice.h" 28#endif 29#ifndef _SCENEOBJECT_H_ 30#include "scene/sceneObject.h" 31#endif 32#ifndef _SIMOBJECT_H_ 33#include "console/simObject.h" 34#endif 35#ifndef _DATACHUNKER_H_ 36#include "core/dataChunker.h" 37#endif 38#ifndef _SCENEMANAGER_H_ 39#include "scene/sceneManager.h" 40#endif 41#ifndef _SCENEMANAGER_H_ 42#include "scene/sceneManager.h" 43#endif 44#ifndef _CUBEMAPDATA_H_ 45#include "gfx/sim/cubemapData.h" 46#endif 47#ifndef _GFXPRIMITIVEBUFFER_H_ 48#include "gfx/gfxPrimitiveBuffer.h" 49#endif 50 51class SceneRenderState; 52class ISceneObject; 53class BaseMatInstance; 54struct SceneData; 55class ShaderData; 56class RenderBinManager; 57class LightInfo; 58struct RenderInst; 59class MatrixSet; 60class GFXPrimitiveBufferHandle; 61class CustomShaderBindingData; 62 63/// A RenderInstType hash value. 64typedef U32 RenderInstTypeHash; 65 66/// A a tiny wrapper around String that exposes a U32 operator so 67/// that we can assign the RIT to RenderInst::type field. 68class RenderInstType 69{ 70 /// For direct access to mName. 71 friend class RenderBinManager; 72 73protected: 74 75 String mName; 76 77public: 78 79 RenderInstType() 80 : mName( Invalid.mName ) 81 { 82 } 83 84 RenderInstType( const RenderInstType &type ) 85 : mName( type.mName ) 86 { 87 } 88 89 RenderInstType( const String &name ) 90 : mName( name ) 91 { 92 } 93 94 ~RenderInstType() {} 95 96 operator RenderInstTypeHash() const { return (RenderInstTypeHash)mName.getHashCaseInsensitive(); } 97 98 const String& getName() const { return mName; } 99 100 bool isValid() const { return (RenderInstTypeHash)*this != (RenderInstTypeHash)Invalid; } 101 102 static const RenderInstType Invalid; 103}; 104 105 106/// 107class RenderPassManager : public SimObject 108{ 109 typedef SimObject Parent; 110 111public: 112 113 // Default bin types. Not necessarily the only bin types in the system. 114 // RIT = "R"ender "I"nstance "T"ype 115 static const RenderInstType RIT_Mesh; 116 static const RenderInstType RIT_Shadow; 117 static const RenderInstType RIT_Sky; 118 static const RenderInstType RIT_Terrain; 119 static const RenderInstType RIT_Object; // objects that do their own rendering 120 static const RenderInstType RIT_ObjectTranslucent;// self rendering; but sorted with static const RenderInstType RIT_Translucent 121 static const RenderInstType RIT_Decal; 122 static const RenderInstType RIT_DecalRoad; 123 static const RenderInstType RIT_Water; 124 static const RenderInstType RIT_Foliage; 125 static const RenderInstType RIT_VolumetricFog; 126 static const RenderInstType RIT_Translucent; 127 static const RenderInstType RIT_Begin; 128 static const RenderInstType RIT_Custom; 129 static const RenderInstType RIT_Particle; 130 static const RenderInstType RIT_Occluder; 131 static const RenderInstType RIT_Editor; 132 static const RenderInstType RIT_Probes; 133 134public: 135 136 RenderPassManager(); 137 virtual ~RenderPassManager(); 138 139 /// @name Allocation interface 140 /// @{ 141 142 /// Allocate a render instance, use like so: MyRenderInstType* t = gRenderInstMgr->allocInst<MyRenderInstType>(); 143 /// Valid until ::clear called. 144 template <typename T> 145 T* allocInst() 146 { 147 T* inst = mChunker.alloc<T>(); 148 inst->clear(); 149 return inst; 150 } 151 152 /// Allocate a matrix, valid until ::clear called. 153 MatrixF* allocUniqueXform(const MatrixF& data) 154 { 155 MatrixF *r = mChunker.alloc<MatrixF>(); 156 *r = data; 157 return r; 158 } 159 160 enum SharedTransformType 161 { 162 View, 163 Projection, 164 }; 165 166 const MatrixF* allocSharedXform(SharedTransformType stt); 167 168 void assignSharedXform(SharedTransformType stt, const MatrixF &xfm); 169 170 MatrixSet &getMatrixSet() { return *mMatrixSet; } 171 172 /// Allocate a GFXPrimitive object which will remain valid 173 /// until the pass manager is cleared. 174 GFXPrimitive* allocPrim() { return mChunker.alloc<GFXPrimitive>(); } 175 /// @} 176 177 /// Add a RenderInstance to the list 178 virtual void addInst( RenderInst *inst ); 179 180 /// Sorts the list of RenderInst's per bin. (Normally, one should just call renderPass) 181 void sort(); 182 183 /// Renders the list of RenderInsts (Normally, one should just call renderPass) 184 void render( SceneRenderState *state ); 185 186 /// Resets our allocated RenderInstances and Matrices. (Normally, one should just call renderPass) 187 void clear(); 188 189 // Calls sort, render, and clear 190 void renderPass( SceneRenderState *state ); 191 192 /// Returns the active depth buffer for this pass (NOTE: This value may be GFXTextureTarget::sDefaultDepthStencil) 193 GFXTextureObject *getDepthTargetTexture(); 194 195 /// Assigns the value for the above method 196 void setDepthTargetTexture(GFXTextureObject *zTarget); 197 198 /// @name RenderBinManager interface 199 /// @{ 200 201 /// Add a render bin manager to the list of render bin manager, this SceneRenderPassManager now owns the render bin manager and will free it when needed. 202 /// @param mgr Render manager to add 203 /// @param processAddOrder Where to add the manager in the addInst list, set to NO_PROCESSADD to skip processing 204 /// this is in place for RenderManagers that will bypass the main ::addInst interface and doesn't want to process 205 /// them. 206 /// @param renderOrder Where to add the manager in the render list. 207 void addManager(RenderBinManager* mgr); 208 209 /// Removes a manager from render and process add lists 210 /// @param mgr Render bin manager to remove, the caller is now responsible for freeing the mgr. 211 void removeManager(RenderBinManager* mgr); 212 213 /// How many render bin managers do we have? 214 U32 getManagerCount() const { return mRenderBins.size(); } 215 216 /// Get the render manager at i 217 RenderBinManager* getManager( S32 i ) const; 218 219 /// @} 220 221 /// Get scene manager which this render pass belongs to. 222 SceneManager* getSceneManager() 223 { 224 if ( !mSceneManager ) 225 mSceneManager = gClientSceneGraph; 226 227 return mSceneManager; 228 } 229 230 /// This signal is triggered when a render bin is about to be rendered. 231 /// 232 /// @param bin The render bin we're signaling. 233 /// @param state The current scene state. 234 /// @params preRender If true it is before the bin is rendered, else its 235 /// after being rendered. 236 /// 237 typedef Signal <void ( RenderBinManager *bin, 238 const SceneRenderState *state, 239 bool preRender )> RenderBinEventSignal; 240 241 /// @see RenderBinEventSignal 242 static RenderBinEventSignal& getRenderBinSignal(); 243 244 245 typedef Signal<void(RenderInst *inst)> AddInstSignal; 246 247 AddInstSignal& getAddSignal( RenderInstTypeHash type ) 248 { 249 return mAddInstSignals.findOrInsert( type )->value; 250 } 251 252 // ConsoleObject interface 253 static void initPersistFields(); 254 DECLARE_CONOBJECT(RenderPassManager); 255 256protected: 257 258 MultiTypedChunker mChunker; 259 260 Vector< RenderBinManager*> mRenderBins; 261 262 263 typedef HashTable<RenderInstTypeHash,AddInstSignal> AddInstTable; 264 265 AddInstTable mAddInstSignals; 266 267 SceneManager * mSceneManager; 268 GFXTexHandle mDepthBuff; 269 MatrixSet *mMatrixSet; 270 271 /// Do a sorted insert into a vector, renderOrder bool controls which test we run for insertion. 272 void _insertSort(Vector<RenderBinManager*>& list, RenderBinManager* mgr, bool renderOrder); 273}; 274 275//************************************************************************** 276// Render Instance 277//************************************************************************** 278struct RenderInst 279{ 280 /// The type of render instance this is. 281 RenderInstTypeHash type; 282 283 /// This should be true if the object needs to be sorted 284 /// back to front with other translucent instances. 285 /// @see sortDistSq 286 bool translucentSort; 287 288 /// The reference squared distance from the camera used for 289 /// back to front sorting of the instances. 290 /// @see translucentSort 291 F32 sortDistSq; 292 293 /// The default key used by render managers for 294 /// internal sorting. 295 U32 defaultKey; 296 297 /// The secondary key used by render managers for 298 /// internal sorting. 299 U32 defaultKey2; 300 301 /// Does a memset to clear the render instance. 302 void clear(); 303}; 304 305struct ObjectRenderInst : public RenderInst 306{ 307 /// This is a delegate specific index which is usually 308 /// used to define a mounted object. 309 S32 objectIndex; 310 311 /// Extra data to be used within the render callback. 312 /// ObjectRenderInst does not own or cleanup this data. 313 void *userData; 314 315 /// The delegate callback function to call to render 316 /// this object instance. 317 /// 318 /// @param ri The ObjectRenderInst that called the delegate. 319 /// 320 /// @param state The scene state we're rendering. 321 /// 322 /// @param overrideMat An alternative material to use during rendering... usually 323 /// used for special renders like shadows. If the object doesn't 324 /// support override materials it shouldn't render at all. 325 Delegate<void( ObjectRenderInst *ri, 326 SceneRenderState *state, 327 BaseMatInstance *overrideMat )> renderDelegate; 328 329 // Clear this instance. 330 void clear(); 331}; 332 333struct MeshRenderInst : public RenderInst 334{ 335 //// 336 GFXVertexBufferHandleBase *vertBuff; 337 338 //// 339 GFXPrimitiveBufferHandle *primBuff; 340 341 /// If not NULL it is used to draw the primitive, else 342 /// the primBuffIndex is used. 343 /// @see primBuffIndex 344 GFXPrimitive *prim; 345 346 /// If prim is NULL then this index is used to draw the 347 /// indexed primitive from the primitive buffer. 348 /// @see prim 349 U32 primBuffIndex; 350 351 /// The material to setup when drawing this instance. 352 BaseMatInstance *matInst; 353 354 /// The object to world transform (world transform in most API's). 355 const MatrixF *objectToWorld; 356 357 /// The worldToCamera (view transform in most API's). 358 const MatrixF* worldToCamera; 359 360 /// The projection matrix. 361 const MatrixF* projection; 362 363 // misc render states 364 U8 transFlags; 365 bool reflective; 366 F32 visibility; 367 368 /// A generic hint value passed from the game 369 /// code down to the material for use by shader 370 /// features. 371 void *materialHint; 372 373 /// The lights we pass to the material for this 374 /// mesh in order light importance. 375 LightInfo* lights[8]; 376 377 // textures 378 GFXTextureObject *lightmap; 379 GFXTextureObject *fogTex; 380 GFXTextureObject *backBuffTex; 381 GFXTextureObject *reflectTex; 382 GFXTextureObject *miscTex; 383 GFXTextureObject *accuTex; 384 GFXCubemap *cubemap; 385 386 /// @name Hardware Skinning 387 /// { 388 MatrixF *mNodeTransforms; 389 U32 mNodeTransformCount; 390 /// } 391 392#ifdef TORQUE_ENABLE_GFXDEBUGEVENTS 393 const char *meshName; 394 const char *objectName; 395#endif 396 397 //Custom Shader data 398 Vector<CustomShaderBindingData> mCustomShaderData; 399 400 void clear(); 401}; 402 403enum ParticleSystemState 404{ 405 PSS_AwaitingHighResDraw = 0, // Keep this as first element so that if the offscreen manager rejects a particle system it will get drawn high-res 406 PSS_AwaitingOffscreenDraw, 407 PSS_AwaitingCompositeDraw, 408 PSS_AwaitingMixedResDraw, 409 PSS_DrawComplete, 410}; 411 412/// A special render instance for particles. 413struct ParticleRenderInst : public RenderInst 414{ 415 /// The vertex buffer. 416 GFXVertexBufferHandleBase *vertBuff; 417 418 /// The primitive buffer. 419 GFXPrimitiveBufferHandle *primBuff; 420 421 /// The total particle count to render. 422 S32 count; 423 424 bool glow; 425 426 /// The combined model, camera, and projection transform. 427 const MatrixF *modelViewProj; 428 429 /// Blend style for the particle system 430 enum BlendStyle { 431 BlendUndefined = 0, 432 BlendNormal, 433 BlendAdditive, 434 BlendSubtractive, 435 BlendPremultAlpha, 436 BlendGreyscale, 437 BlendStyle_COUNT, 438 }; 439 U8 blendStyle; 440 441 /// For the offscreen particle manager 442 U8 targetIndex; 443 444 /// State for the particle system 445 ParticleSystemState systemState; 446 447 /// The soft particle fade distance in meters. 448 F32 softnessDistance; 449 450 /// Bounding box render transform 451 const MatrixF *bbModelViewProj; 452 453 Point3F wsPosition; 454 455 /// The particle texture. 456 GFXTextureObject *diffuseTex; 457 458 void clear(); 459}; 460 461class GFXOcclusionQuery; 462class SceneObject; 463 464/// A special render instance for occlusion tests. 465struct OccluderRenderInst : public RenderInst 466{ 467 Point3F scale; 468 Point3F position; 469 const MatrixF *orientation; 470 GFXOcclusionQuery *query; 471 472 // This optional query will have all pixels rendered. 473 // Its purpose is to return to the user the full pixel count for comparison 474 // with the other query. 475 GFXOcclusionQuery *query2; 476 477 /// Render a sphere or a box. 478 bool isSphere; 479 480 void clear(); 481}; 482 483#endif // _RENDERPASSMANAGER_H_ 484