Torque3D Documentation / _generateds / afxRenderHighlightMgr.cpp

afxRenderHighlightMgr.cpp

Engine/source/afx/afxRenderHighlightMgr.cpp

More...

Detailed Description

Public Functions

IMPLEMENT_CONOBJECT(afxRenderHighlightMgr )

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 28// The afxRenderHighlightMgr class is adapted from the resource,
 29// "Silhoute selection via postFX for Torque3D" posted by Konrad Kiss.
 30// http://www.garagegames.com/community/resources/view/17821
 31// Supporting code mods in other areas of the engine are marked as
 32// "(selection-highlight)".
 33//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 34
 35#include "platform/platform.h"
 36#include "afxRenderHighlightMgr.h"
 37
 38#include "scene/sceneManager.h"
 39#include "scene/sceneRenderState.h"
 40#include "materials/sceneData.h"
 41#include "materials/matInstance.h"
 42//#include "materials/materialFeatureTypes.h"
 43#include "materials/processedMaterial.h"
 44#include "postFx/postEffect.h"
 45#include "gfx/gfxTransformSaver.h"
 46#include "gfx/gfxDebugEvent.h"
 47#include "math/util/matrixSet.h"
 48
 49IMPLEMENT_CONOBJECT( afxRenderHighlightMgr );
 50
 51afxRenderHighlightMgr::afxRenderHighlightMgr()
 52   : RenderTexTargetBinManager(  RenderPassManager::RIT_Mesh, 
 53                                 1.0f, 
 54                                 1.0f,
 55                                 GFXFormatR8G8B8A8,
 56                                 Point2I( 512, 512 ) )
 57{
 58   mNamedTarget.registerWithName( "highlight" );
 59   mTargetSizeType = WindowSize;
 60}
 61
 62afxRenderHighlightMgr::~afxRenderHighlightMgr()
 63{
 64}
 65
 66PostEffect* afxRenderHighlightMgr::getSelectionEffect()
 67{
 68   if ( !mSelectionEffect )
 69      mSelectionEffect = dynamic_cast<PostEffect*>( Sim::findObject( "afxHighlightPostFX" ) );
 70   
 71   return mSelectionEffect;
 72}
 73
 74bool afxRenderHighlightMgr::isSelectionEnabled()
 75{
 76   return getSelectionEffect() && getSelectionEffect()->isEnabled();
 77}
 78
 79void afxRenderHighlightMgr::addElement( RenderInst *inst )
 80{
 81   // Skip out if we don't have the selection post 
 82   // effect enabled at this time.
 83   if ( !isSelectionEnabled() )  
 84      return;
 85
 86   // Skip it if we don't have a selection material.
 87   BaseMatInstance *matInst = getMaterial( inst );
 88   if ( !matInst || !matInst->needsSelectionHighlighting() )   
 89      return;
 90
 91   internalAddElement(inst);
 92}
 93
 94void afxRenderHighlightMgr::render( SceneRenderState *state )  
 95{
 96   PROFILE_SCOPE( RenderSelectionMgr_Render );
 97   
 98   if ( !isSelectionEnabled() )
 99      return;
100
101   const U32 binSize = mElementList.size();
102
103   // If this is a non-diffuse pass or we have no objects to
104   // render then tell the effect to skip rendering.
105   if ( !state->isDiffusePass() || binSize == 0 )
106   {
107      getSelectionEffect()->setSkip( true );
108      return;
109   }
110
111   GFXDEBUGEVENT_SCOPE( RenderSelectionMgr_Render, ColorI::GREEN );
112
113   GFXTransformSaver saver;
114
115   // Tell the superclass we're about to render, preserve contents
116   const bool isRenderingToTarget = _onPreRender( state, true );
117
118   // Clear all the buffers to black.
119   //GFX->clear( GFXClearTarget, ColorI::BLACK, 1.0f, 0);
120   GFX->clear( GFXClearTarget, ColorI::ZERO, 1.0f, 0);
121
122   // Restore transforms
123   MatrixSet &matrixSet = getRenderPass()->getMatrixSet();
124   matrixSet.restoreSceneViewProjection();
125
126   // init loop data
127   SceneData sgData;
128   sgData.init( state, SceneData::HighlightBin );
129
130   for( U32 j=0; j<binSize; )
131   {
132      MeshRenderInst *ri = static_cast<MeshRenderInst*>(mElementList[j].inst);
133
134      setupSGData( ri, sgData );
135
136      BaseMatInstance *mat = ri->matInst;
137
138      U32 matListEnd = j;
139
140      while( mat && mat->setupPass( state, sgData ) )
141      {
142         U32 a;
143         for( a=j; a<binSize; a++ )
144         {
145            MeshRenderInst *passRI = static_cast<MeshRenderInst*>(mElementList[a].inst);
146
147            if ( newPassNeeded( ri, passRI ) )
148               break;
149
150            matrixSet.setWorld(*passRI->objectToWorld);
151            matrixSet.setView(*passRI->worldToCamera);
152            matrixSet.setProjection(*passRI->projection);
153            mat->setTransforms(matrixSet, state);
154
155            // Setup HW skinning transforms if applicable
156            if (mat->usesHardwareSkinning())
157            {
158               mat->setNodeTransforms(passRI->mNodeTransforms, passRI->mNodeTransformCount);
159            }
160
161            mat->setSceneInfo(state, sgData);
162            mat->setBuffers(passRI->vertBuff, passRI->primBuff);
163
164            if ( passRI->prim )
165               GFX->drawPrimitive( *passRI->prim );
166            else
167               GFX->drawPrimitive( passRI->primBuffIndex );
168         }
169         matListEnd = a;
170         setupSGData( ri, sgData );
171      }
172
173      // force increment if none happened, otherwise go to end of batch
174      j = ( j == matListEnd ) ? j+1 : matListEnd;
175   }
176
177   // Finish up.
178   if ( isRenderingToTarget )
179      _onPostRender();
180
181   // Make sure the effect is gonna render.
182   getSelectionEffect()->setSkip( false );
183}
184