Torque3D/Engine/source/renderInstance/renderBinManager.h

172 lines
5.8 KiB
C
Raw Normal View History

2012-09-19 15:15:01 +00:00
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _RENDERBINMANAGER_H_
#define _RENDERBINMANAGER_H_
#ifndef _CONSOLEOBJECT_H_
#include "console/consoleObject.h"
#endif
#ifndef _RENDERPASSMANAGER_H_
#include "renderInstance/renderPassManager.h"
#endif
#ifndef _BASEMATINSTANCE_H_
#include "materials/baseMatInstance.h"
#endif
#ifndef _UTIL_DELEGATE_H_
#include "core/util/delegate.h"
#endif
class SceneRenderState;
/// This delegate is used in derived RenderBinManager classes
/// to allow material instances to be overriden.
typedef Delegate<BaseMatInstance*(BaseMatInstance*)> MaterialOverrideDelegate;
/// The RenderBinManager manages and renders lists of MainSortElem, which
/// is a light wrapper around RenderInst.
class RenderBinManager : public SimObject
{
typedef SimObject Parent;
friend class RenderPassManager;
public:
RenderBinManager( const RenderInstType& ritype = RenderInstType::Invalid,
F32 renderOrder = 1.0f,
F32 processAddOrder = 1.0f );
virtual ~RenderBinManager() {}
// SimObject
void onRemove() override;
2012-09-19 15:15:01 +00:00
virtual void addElement( RenderInst *inst );
virtual void sort();
virtual void render( SceneRenderState *state ) {}
virtual void clear();
// Manager info
F32 getProcessAddOrder() const { return mProcessAddOrder; }
void setProcessAddOrder(F32 processAddOrder) { mProcessAddOrder = processAddOrder; }
F32 getRenderOrder() const { return mRenderOrder; }
void setRenderOrder(F32 renderOrder) { mRenderOrder = renderOrder; }
/// Returns the primary render instance type.
const RenderInstType& getRenderInstType() { return mRenderInstType; }
/// Returns the render pass this bin is registered to.
RenderPassManager* getRenderPass() const { return mRenderPass; }
/// QSort callback function
static S32 FN_CDECL cmpKeyFunc(const void* p1, const void* p2);
DECLARE_CONOBJECT(RenderBinManager);
static void initPersistFields();
MaterialOverrideDelegate& getMatOverrideDelegate() { return mMatOverrideDelegate; }
struct MainSortElem
{
RenderInst *inst;
U32 key;
U32 key2;
};
protected:
2012-09-19 15:15:01 +00:00
void setRenderPass( RenderPassManager *rpm );
/// Called from derived bins to add additional
/// render instance types to be notified about.
void notifyType( const RenderInstType &type );
Vector< MainSortElem > mElementList; // List of our instances
F32 mProcessAddOrder; // Where in the list do we process RenderInstance additions?
F32 mRenderOrder; // Where in the list do we render?
/// The primary render instance type this bin supports.
RenderInstType mRenderInstType;
/// The list of additional render instance types
/// this bin wants to process.
Vector<RenderInstType> mOtherTypes;
/// The render pass manager this bin is registered with.
RenderPassManager *mRenderPass;
MaterialOverrideDelegate mMatOverrideDelegate;
virtual void setupSGData(MeshRenderInst *ri, SceneData &data );
virtual void internalAddElement(RenderInst* inst);
/// A inlined helper method for testing if the next
/// MeshRenderInst requires a new batch/pass.
inline bool newPassNeeded( MeshRenderInst *ri, MeshRenderInst* nextRI ) const;
/// Inlined utility function which gets the material from the
/// RenderInst if available, otherwise, return NULL.
inline BaseMatInstance* getMaterial( RenderInst *inst ) const;
The final step (barring any overlooked missing bits, requested refactors, and of course, rolling in dependencies already submitted as PRs) consists of: renderPrePassMgr.cpp related: A) shifting .addFeature( MFT_XYZ); calls from ProcessedShaderMaterial::_determineFeatures to ProcessedPrePassMaterial::_determineFeatures B) mimicking the "// set the XXX if different" entries from RenderMeshMgr::render in RenderPrePassMgr::render C) fleshing out ProcessedPrePassMaterial::getNumStages() so that it shares a 1:1 correlation with ProcessedShaderMaterial::getNumStages() D) causing inline void Swizzle<T, mapLength>::ToBuffer( void *destination, const void *source, const dsize_t size ) to silently fail rather than fatally assert if a source or destination buffer is not yet ready to be filled. (support for #customTarget scripted render targets) Reflections: A) removing reflectRenderState.disableAdvancedLightingBins(true); entries. this would otherwise early out from prepass and provide no color data whatsoever. B) removing the fd.features.addFeature( MFT_ForwardShading ); entry forcing all materials to be forward lit when reflected. C) 2 things best described bluntly as working hacks: C1) when reflected, a scattersky is rotated PI along it's z then x axis in order to draw properly. C2) along similar lines, in terraincellmaterial, we shut off culling if it's a prepass material. Skies: scattersky is given a pair of rotations for reflection purposes, all sky objects are given a z value for depth testing.
2016-02-16 08:50:49 +00:00
// Limits bin to rendering in basic lighting only.
bool mBasicOnly;
2012-09-19 15:15:01 +00:00
};
inline bool RenderBinManager::newPassNeeded( MeshRenderInst *ri, MeshRenderInst* nextRI ) const
{
if ( ri == nextRI )
return false;
// We can depend completely on the state hint to check
// for changes in the material as it uniquely identifies it.
if ( ri->matInst->getStateHint() != nextRI->matInst->getStateHint() )
return true;
if ( ri->vertBuff != nextRI->vertBuff ||
ri->primBuff != nextRI->primBuff ||
ri->prim != nextRI->prim ||
ri->primBuffIndex != nextRI->primBuffIndex ||
// NOTE: Keep an eye on this... should we find a more
// optimal test for light set changes?
//
dMemcmp( ri->lights, nextRI->lights, sizeof( ri->lights ) ) != 0 )
return true;
return false;
}
inline BaseMatInstance* RenderBinManager::getMaterial( RenderInst *inst ) const
{
if ( inst->type == RenderPassManager::RIT_Mesh ||
inst->type == RenderPassManager::RIT_Decal ||
The final step (barring any overlooked missing bits, requested refactors, and of course, rolling in dependencies already submitted as PRs) consists of: renderPrePassMgr.cpp related: A) shifting .addFeature( MFT_XYZ); calls from ProcessedShaderMaterial::_determineFeatures to ProcessedPrePassMaterial::_determineFeatures B) mimicking the "// set the XXX if different" entries from RenderMeshMgr::render in RenderPrePassMgr::render C) fleshing out ProcessedPrePassMaterial::getNumStages() so that it shares a 1:1 correlation with ProcessedShaderMaterial::getNumStages() D) causing inline void Swizzle<T, mapLength>::ToBuffer( void *destination, const void *source, const dsize_t size ) to silently fail rather than fatally assert if a source or destination buffer is not yet ready to be filled. (support for #customTarget scripted render targets) Reflections: A) removing reflectRenderState.disableAdvancedLightingBins(true); entries. this would otherwise early out from prepass and provide no color data whatsoever. B) removing the fd.features.addFeature( MFT_ForwardShading ); entry forcing all materials to be forward lit when reflected. C) 2 things best described bluntly as working hacks: C1) when reflected, a scattersky is rotated PI along it's z then x axis in order to draw properly. C2) along similar lines, in terraincellmaterial, we shut off culling if it's a prepass material. Skies: scattersky is given a pair of rotations for reflection purposes, all sky objects are given a z value for depth testing.
2016-02-16 08:50:49 +00:00
inst->type == RenderPassManager::RIT_DecalRoad ||
2012-09-19 15:15:01 +00:00
inst->type == RenderPassManager::RIT_Translucent )
return static_cast<MeshRenderInst*>(inst)->matInst;
return NULL;
}
#endif // _RENDERBINMANAGER_H_