Torque3D Documentation / _generateds / renderBinManager.h

renderBinManager.h

Engine/source/renderInstance/renderBinManager.h

More...

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
 90   struct MainSortElem
 91   {
 92      RenderInst *inst;
 93      U32 key;
 94      U32 key2;
 95   };
 96
 97protected:
 98   void setRenderPass( RenderPassManager *rpm );
 99
100   /// Called from derived bins to add additional
101   /// render instance types to be notified about.
102   void notifyType( const RenderInstType &type );
103
104   Vector< MainSortElem> mElementList; // List of our instances
105   F32 mProcessAddOrder;   // Where in the list do we process RenderInstance additions?
106   F32 mRenderOrder;       // Where in the list do we render?
107
108   /// The primary render instance type this bin supports.
109   RenderInstType mRenderInstType;
110
111   /// The list of additional render instance types 
112   /// this bin wants to process.
113   Vector<RenderInstType> mOtherTypes;
114
115   /// The render pass manager this bin is registered with.
116   RenderPassManager *mRenderPass;
117
118   MaterialOverrideDelegate mMatOverrideDelegate;
119
120   virtual void setupSGData(MeshRenderInst *ri, SceneData &data );
121   virtual void internalAddElement(RenderInst* inst);
122
123   /// A inlined helper method for testing if the next 
124   /// MeshRenderInst requires a new batch/pass.
125   inline bool newPassNeeded( MeshRenderInst *ri, MeshRenderInst* nextRI ) const;
126
127   /// Inlined utility function which gets the material from the 
128   /// RenderInst if available, otherwise, return NULL.
129   inline BaseMatInstance* getMaterial( RenderInst *inst ) const;
130
131   // Limits bin to rendering in basic lighting only.
132   bool mBasicOnly;
133};
134
135
136inline bool RenderBinManager::newPassNeeded( MeshRenderInst *ri, MeshRenderInst* nextRI ) const
137{
138   if ( ri == nextRI )
139      return false;
140
141   // We can depend completely on the state hint to check
142   // for changes in the material as it uniquely identifies it.
143   if ( ri->matInst->getStateHint() != nextRI->matInst->getStateHint() )
144      return true;
145
146   if (  ri->vertBuff != nextRI->vertBuff ||
147         ri->primBuff != nextRI->primBuff ||
148         ri->prim != nextRI->prim ||
149         ri->primBuffIndex != nextRI->primBuffIndex ||
150
151         // NOTE: Keep an eye on this... should we find a more
152         // optimal test for light set changes?
153         //
154         dMemcmp( ri->lights, nextRI->lights, sizeof( ri->lights ) ) != 0 )
155
156      return true;
157
158   return false;
159}
160
161inline BaseMatInstance* RenderBinManager::getMaterial( RenderInst *inst ) const
162{
163   if (  inst->type == RenderPassManager::RIT_Mesh || 
164         inst->type == RenderPassManager::RIT_Decal ||
165         inst->type == RenderPassManager::RIT_DecalRoad ||         
166         inst->type == RenderPassManager::RIT_Translucent )
167      return static_cast<MeshRenderInst*>(inst)->matInst;
168
169   return NULL;      
170}
171
172#endif // _RENDERBINMANAGER_H_
173