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