renderBinManager.h
Engine/source/renderInstance/renderBinManager.h
Classes:
class
The RenderBinManager manages and renders lists of MainSortElem, which is a light wrapper around RenderInst.
Public Typedefs
MaterialOverrideDelegate
This delegate is used in derived RenderBinManager classes to allow material instances to be overriden.
Detailed Description
Public Typedefs
typedef Delegate< BaseMatInstance *(BaseMatInstance *)> MaterialOverrideDelegate
This delegate is used in derived RenderBinManager classes to allow material instances to be overriden.
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 _RENDERBINMANAGER_H_ 24#define _RENDERBINMANAGER_H_ 25 26#ifndef _CONSOLEOBJECT_H_ 27#include "console/consoleObject.h" 28#endif 29#ifndef _RENDERPASSMANAGER_H_ 30#include "renderInstance/renderPassManager.h" 31#endif 32#ifndef _BASEMATINSTANCE_H_ 33#include "materials/baseMatInstance.h" 34#endif 35#ifndef _UTIL_DELEGATE_H_ 36#include "core/util/delegate.h" 37#endif 38 39class SceneRenderState; 40 41 42/// This delegate is used in derived RenderBinManager classes 43/// to allow material instances to be overriden. 44typedef Delegate<BaseMatInstance*(BaseMatInstance*)> MaterialOverrideDelegate; 45 46 47/// The RenderBinManager manages and renders lists of MainSortElem, which 48/// is a light wrapper around RenderInst. 49class RenderBinManager : public SimObject 50{ 51 typedef SimObject Parent; 52 53 friend class RenderPassManager; 54 55public: 56 57 RenderBinManager( const RenderInstType& ritype = RenderInstType::Invalid, 58 F32 renderOrder = 1.0f, 59 F32 processAddOrder = 1.0f ); 60 virtual ~RenderBinManager() {} 61 62 // SimObject 63 void onRemove(); 64 65 virtual void addElement( RenderInst *inst ); 66 virtual void sort(); 67 virtual void render( SceneRenderState *state ) {} 68 virtual void clear(); 69 70 // Manager info 71 F32 getProcessAddOrder() const { return mProcessAddOrder; } 72 void setProcessAddOrder(F32 processAddOrder) { mProcessAddOrder = processAddOrder; } 73 F32 getRenderOrder() const { return mRenderOrder; } 74 void setRenderOrder(F32 renderOrder) { mRenderOrder = renderOrder; } 75 76 /// Returns the primary render instance type. 77 const RenderInstType& getRenderInstType() { return mRenderInstType; } 78 79 /// Returns the render pass this bin is registered to. 80 RenderPassManager* getRenderPass() const { return mRenderPass; } 81 82 /// QSort callback function 83 static S32 FN_CDECL cmpKeyFunc(const void* p1, const void* p2); 84 85 DECLARE_CONOBJECT(RenderBinManager); 86 static void initPersistFields(); 87 88 MaterialOverrideDelegate& getMatOverrideDelegate() { return mMatOverrideDelegate; } 89 90protected: 91 92 struct MainSortElem 93 { 94 RenderInst *inst; 95 U32 key; 96 U32 key2; 97 }; 98 99 void setRenderPass( RenderPassManager *rpm ); 100 101 /// Called from derived bins to add additional 102 /// render instance types to be notified about. 103 void notifyType( const RenderInstType &type ); 104 105 Vector< MainSortElem> mElementList; // List of our instances 106 F32 mProcessAddOrder; // Where in the list do we process RenderInstance additions? 107 F32 mRenderOrder; // Where in the list do we render? 108 109 /// The primary render instance type this bin supports. 110 RenderInstType mRenderInstType; 111 112 /// The list of additional render instance types 113 /// this bin wants to process. 114 Vector<RenderInstType> mOtherTypes; 115 116 /// The render pass manager this bin is registered with. 117 RenderPassManager *mRenderPass; 118 119 MaterialOverrideDelegate mMatOverrideDelegate; 120 121 virtual void setupSGData(MeshRenderInst *ri, SceneData &data ); 122 virtual void internalAddElement(RenderInst* inst); 123 124 /// A inlined helper method for testing if the next 125 /// MeshRenderInst requires a new batch/pass. 126 inline bool newPassNeeded( MeshRenderInst *ri, MeshRenderInst* nextRI ) const; 127 128 /// Inlined utility function which gets the material from the 129 /// RenderInst if available, otherwise, return NULL. 130 inline BaseMatInstance* getMaterial( RenderInst *inst ) const; 131 132 // Limits bin to rendering in basic lighting only. 133 bool mBasicOnly; 134}; 135 136 137inline bool RenderBinManager::newPassNeeded( MeshRenderInst *ri, MeshRenderInst* nextRI ) const 138{ 139 if ( ri == nextRI ) 140 return false; 141 142 // We can depend completely on the state hint to check 143 // for changes in the material as it uniquely identifies it. 144 if ( ri->matInst->getStateHint() != nextRI->matInst->getStateHint() ) 145 return true; 146 147 if ( ri->vertBuff != nextRI->vertBuff || 148 ri->primBuff != nextRI->primBuff || 149 ri->prim != nextRI->prim || 150 ri->primBuffIndex != nextRI->primBuffIndex || 151 152 // NOTE: Keep an eye on this... should we find a more 153 // optimal test for light set changes? 154 // 155 dMemcmp( ri->lights, nextRI->lights, sizeof( ri->lights ) ) != 0 ) 156 157 return true; 158 159 return false; 160} 161 162inline BaseMatInstance* RenderBinManager::getMaterial( RenderInst *inst ) const 163{ 164 if ( inst->type == RenderPassManager::RIT_Mesh || 165 inst->type == RenderPassManager::RIT_Decal || 166 inst->type == RenderPassManager::RIT_DecalRoad || 167 inst->type == RenderPassManager::RIT_Translucent ) 168 return static_cast<MeshRenderInst*>(inst)->matInst; 169 170 return NULL; 171} 172 173#endif // _RENDERBINMANAGER_H_ 174
