Torque3D Documentation / _generateds / renderBinManager.cpp

renderBinManager.cpp

Engine/source/renderInstance/renderBinManager.cpp

More...

Public Functions

ConsoleDocClass(RenderBinManager , "@brief The abstract base <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> all <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bins.\n\n</a>" "The <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> bins are used by the engine as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> high level method <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> order and batch rendering " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">operations.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">RenderBin\n</a>" )
DefineEngineMethod(RenderBinManager , getBinType , const char * , () , "Returns the bin type string." )
DefineEngineMethod(RenderBinManager , getRenderOrder , F32 , () , "Returns the bin <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> order." )

Detailed Description

Public Functions

ConsoleDocClass(RenderBinManager , "@brief The abstract base <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> all <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bins.\n\n</a>" "The <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> bins are used by the engine as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> high level method <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> order and batch rendering " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">operations.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">RenderBin\n</a>" )

DefineEngineMethod(RenderBinManager , getBinType , const char * , () , "Returns the bin type string." )

DefineEngineMethod(RenderBinManager , getRenderOrder , F32 , () , "Returns the bin <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> order." )

IMPLEMENT_CONOBJECT(RenderBinManager )

  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
 24#include "platform/platform.h"
 25#include "renderInstance/renderBinManager.h"
 26
 27#include "console/consoleTypes.h"
 28#include "materials/matInstance.h"
 29#include "scene/sceneManager.h"
 30#include "console/engineAPI.h"
 31
 32
 33IMPLEMENT_CONOBJECT(RenderBinManager);
 34
 35
 36RenderBinManager::RenderBinManager( const RenderInstType& ritype, F32 renderOrder, F32 processAddOrder ) :
 37   mProcessAddOrder( processAddOrder ),
 38   mRenderOrder( renderOrder ),
 39   mRenderInstType( ritype ),  
 40   mRenderPass( NULL ),
 41   mBasicOnly ( false )
 42{
 43   VECTOR_SET_ASSOCIATION( mElementList );
 44   mElementList.reserve( 2048 );
 45}
 46
 47
 48ConsoleDocClass( RenderBinManager, 
 49   "@brief The abstract base for all render bins.\n\n"
 50   "The render bins are used by the engine as a high level method to order and batch rendering "
 51   "operations.\n"
 52   "@ingroup RenderBin\n" );
 53
 54void RenderBinManager::initPersistFields()
 55{
 56   addField( "binType", TypeRealString, Offset(mRenderInstType.mName, RenderBinManager),
 57      "Sets the render bin type which limits what render instances are added to this bin." );
 58
 59   addField("renderOrder", TypeF32, Offset(mRenderOrder, RenderBinManager),
 60      "Defines the order for rendering in relation to other bins." );
 61
 62   addField("processAddOrder", TypeF32, Offset(mProcessAddOrder, RenderBinManager),
 63      "Defines the order for adding instances in relation to other bins." );
 64
 65   addField( "basicOnly", TypeBool, Offset(mBasicOnly, RenderBinManager),
 66      "Limites the render bin to basic lighting only." );
 67
 68   Parent::initPersistFields();
 69}
 70
 71void RenderBinManager::onRemove()
 72{
 73   // Tell the render pass to remove us when 
 74   // we're being unregistered.
 75   if ( mRenderPass )
 76      mRenderPass->removeManager( this );
 77
 78   Parent::onRemove();
 79}
 80
 81void RenderBinManager::notifyType( const RenderInstType &type )
 82{
 83   // Avoid duplicate types.
 84   if (  !type.isValid() ||
 85         mRenderInstType == type ||
 86         mOtherTypes.contains( type ) )
 87      return;
 88
 89   mOtherTypes.push_back( type );
 90
 91   // Register for the signal if the pass
 92   // has already been assigned.
 93   if ( mRenderPass )
 94      mRenderPass->getAddSignal(type).notify( this, &RenderBinManager::addElement, mProcessAddOrder );
 95}
 96
 97void RenderBinManager::setRenderPass( RenderPassManager *rpm )
 98{
 99   if ( mRenderPass )
100   {
101      if ( mRenderInstType.isValid() )
102         mRenderPass->getAddSignal(mRenderInstType).remove( this, &RenderBinManager::addElement );
103
104      for ( U32 i=0; i < mOtherTypes.size(); i++ )
105         mRenderPass->getAddSignal(mOtherTypes[i]).remove( this, &RenderBinManager::addElement );         
106   }
107
108   mRenderPass = rpm;
109
110   if ( mRenderPass )
111   {
112      if ( mRenderInstType.isValid() )
113         mRenderPass->getAddSignal(mRenderInstType).notify( this, &RenderBinManager::addElement, mProcessAddOrder );
114
115      for ( U32 i=0; i < mOtherTypes.size(); i++ )
116         mRenderPass->getAddSignal(mOtherTypes[i]).notify( this, &RenderBinManager::addElement, mProcessAddOrder );
117   }
118}
119
120void RenderBinManager::addElement( RenderInst *inst )
121{   
122   internalAddElement(inst);
123}
124
125void RenderBinManager::internalAddElement(RenderInst* inst)
126{
127   mElementList.increment();
128   MainSortElem &elem = mElementList.last();
129   elem.inst = inst;
130
131   elem.key = inst->defaultKey;
132   elem.key2 = inst->defaultKey2;
133}
134
135void RenderBinManager::clear()
136{
137   mElementList.clear();
138}
139
140void RenderBinManager::sort()
141{
142   dQsort( mElementList.address(), mElementList.size(), sizeof(MainSortElem), cmpKeyFunc);
143}
144
145S32 FN_CDECL RenderBinManager::cmpKeyFunc(const void* p1, const void* p2)
146{
147   const MainSortElem* mse1 = (const MainSortElem*) p1;
148   const MainSortElem* mse2 = (const MainSortElem*) p2;
149
150   S32 test1 = S32(mse2->key) - S32(mse1->key);
151
152   return ( test1 == 0 ) ? S32(mse1->key2) - S32(mse2->key2) : test1;
153}
154
155void RenderBinManager::setupSGData(MeshRenderInst *ri, SceneData &data)
156{
157   PROFILE_SCOPE( RenderBinManager_setupSGData );
158
159   // NOTE: We do not reset or clear the scene state 
160   // here as the caller has initialized non-RI members 
161   // himself and we must preserve them.
162   //
163   // It also saves a bunch of CPU as this is called for
164   // every MeshRenderInst in every pass. 
165
166   dMemcpy( data.lights, ri->lights, sizeof( data.lights ) );
167   data.objTrans     = ri->objectToWorld;
168   data.backBuffTex  = ri->backBuffTex;
169   data.cubemap      = ri->cubemap;
170   data.miscTex      = ri->miscTex;
171   data.reflectTex   = ri->reflectTex;
172   data.accuTex      = ri->accuTex;
173   data.lightmap     = ri->lightmap;
174   data.visibility   = ri->visibility;
175   data.materialHint = ri->materialHint;
176   data.customShaderData.clear();
177   for (U32 i = 0; i < ri->mCustomShaderData.size(); i++)
178   {
179      data.customShaderData.push_back(&ri->mCustomShaderData[i]);
180   }
181}
182
183DefineEngineMethod( RenderBinManager, getBinType, const char*, (),,
184   "Returns the bin type string." )
185{
186   return object->getRenderInstType().getName();
187}
188
189DefineEngineMethod(RenderBinManager, getRenderOrder, F32, (), ,
190   "Returns the bin render order.")
191{
192   return object->getRenderOrder();
193}
194