Torque3D Documentation / _generateds / forcedMaterialMeshMgr.cpp

forcedMaterialMeshMgr.cpp

Engine/source/renderInstance/forcedMaterialMeshMgr.cpp

More...

Public Functions

ConsoleDocClass(ForcedMaterialMeshMgr , "@brief Basically the same as RenderMeshMgr, but will override the material " "of the instance. Exists <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> backwards compatibility, not currently used, soon <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deprecated\n\n</a>" " @internal" )

Detailed Description

Public Functions

ConsoleDocClass(ForcedMaterialMeshMgr , "@brief Basically the same as RenderMeshMgr, but will override the material " "of the instance. Exists <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> backwards compatibility, not currently used, soon <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deprecated\n\n</a>" " @internal" )

IMPLEMENT_CONOBJECT(ForcedMaterialMeshMgr )

  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#include "renderInstance/forcedMaterialMeshMgr.h"
 24#include "gfx/gfxTransformSaver.h"
 25#include "gfx/gfxPrimitiveBuffer.h"
 26#include "gfx/gfxDebugEvent.h"
 27#include "materials/sceneData.h"
 28#include "materials/materialManager.h"
 29#include "materials/materialDefinition.h"
 30#include "console/consoleTypes.h"
 31#include "math/util/matrixSet.h"
 32
 33IMPLEMENT_CONOBJECT(ForcedMaterialMeshMgr);
 34
 35ConsoleDocClass( ForcedMaterialMeshMgr,
 36   "@brief Basically the same as RenderMeshMgr, but will override the material "
 37   "of the instance. Exists for backwards compatibility, not currently used, soon to be deprecated\n\n"
 38   "@internal"
 39);
 40
 41ForcedMaterialMeshMgr::ForcedMaterialMeshMgr()
 42{
 43   mOverrideInstance = NULL;
 44   mOverrideMaterial = NULL;
 45}
 46
 47ForcedMaterialMeshMgr::ForcedMaterialMeshMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder, BaseMatInstance* overrideMaterial)
 48: RenderMeshMgr(riType, renderOrder, processAddOrder)
 49{
 50   mOverrideInstance = overrideMaterial;
 51   mOverrideMaterial = NULL;
 52}
 53
 54void ForcedMaterialMeshMgr::setOverrideMaterial(BaseMatInstance* overrideMaterial)
 55{
 56   SAFE_DELETE(mOverrideInstance);
 57   mOverrideInstance = overrideMaterial;
 58}
 59
 60ForcedMaterialMeshMgr::~ForcedMaterialMeshMgr()
 61{
 62   setOverrideMaterial(NULL);
 63}
 64
 65void ForcedMaterialMeshMgr::initPersistFields()
 66{
 67   addProtectedField("material", TYPEID< Material >(), Offset(mOverrideMaterial, ForcedMaterialMeshMgr),
 68      &_setOverrideMat, &_getOverrideMat, "Material used to draw all meshes in the render bin.");
 69
 70   Parent::initPersistFields();
 71}
 72
 73void ForcedMaterialMeshMgr::render(SceneRenderState * state)
 74{
 75   PROFILE_SCOPE(ForcedMaterialMeshMgr_render);
 76
 77   if(!mOverrideInstance && mOverrideMaterial.isValid())
 78   {
 79      mOverrideInstance = mOverrideMaterial->createMatInstance();
 80      mOverrideInstance->init( MATMGR->getDefaultFeatures(), getGFXVertexFormat<GFXVertexPNTBT>() );
 81   }
 82
 83   // Early out if nothing to draw.
 84   if(!mElementList.size() || !mOverrideInstance)
 85      return;
 86
 87   GFXDEBUGEVENT_SCOPE(ForcedMaterialMeshMgr_Render, ColorI::RED);
 88
 89   // Automagically save & restore our viewport and transforms.
 90   GFXTransformSaver saver;
 91
 92   // init loop data
 93   SceneData sgData;
 94   sgData.init( state );
 95
 96   MeshRenderInst *ri = static_cast<MeshRenderInst*>(mElementList[0].inst);
 97   setupSGData( ri, sgData );
 98
 99   while (mOverrideInstance->setupPass(state, sgData))
100   {   
101      for( U32 j=0; j<mElementList.size(); j++)
102      {
103         MeshRenderInst* passRI = static_cast<MeshRenderInst*>(mElementList[j].inst);
104         if(passRI->primBuff->getPointer()->mPrimitiveArray[passRI->primBuffIndex].numVertices < 1)
105            continue;
106
107         getRenderPass()->getMatrixSet().setWorld(*passRI->objectToWorld);
108         getRenderPass()->getMatrixSet().setView(*passRI->worldToCamera);
109         getRenderPass()->getMatrixSet().setProjection(*passRI->projection);
110         mOverrideInstance->setTransforms(getRenderPass()->getMatrixSet(), state);
111
112         mOverrideInstance->setBuffers(passRI->vertBuff, passRI->primBuff);
113         GFX->drawPrimitive( passRI->primBuffIndex );                  
114      }
115   }
116}
117
118const char* ForcedMaterialMeshMgr::_getOverrideMat( void *object, const char *data )
119{
120   ForcedMaterialMeshMgr &mgr = *reinterpret_cast<ForcedMaterialMeshMgr *>( object );
121   if( mgr.mOverrideMaterial.isValid() )
122      return mgr.mOverrideMaterial->getIdString();
123   else
124      return "0";
125}
126
127bool ForcedMaterialMeshMgr::_setOverrideMat( void *object, const char *index, const char *data )
128{
129   ForcedMaterialMeshMgr &mgr = *reinterpret_cast<ForcedMaterialMeshMgr *>( object );   
130   Material* material;
131   Sim::findObject(data, material);
132   mgr.mOverrideMaterial = material;
133
134   return false;
135}
136
137