TorqueGameEngineAdvanced/1 8 Beta/RenderDelegate
From TDN
[edit] ConceptRenderDelgate is a new component introduced by TGEA 1.8. The concept and functionality behind RenderDelgate gives you, the developer, a lot of flexibility when you are creating your own rendering objects.
[edit] Sky ExampleThe Sky object is a great example of a custom object that requires rendering. The class is derived from SceneObject, which does not have a rendering function. Open engine/source/terrain/sky.h. If you scroll through the Sky class, you will find the declaration of its RenderDelegate: ObjectRenderInst::RenderDelegate mRenderDelegate;
mRenderDelegate.bind(this, &Sky::renderObject);
mRenderDelegate.bind(this, &Sky::renderSky);
void Sky::renderObject(ObjectRenderInst *ri, BaseMatInstance* overrideMat)
{
if (overrideMat)
return;
SceneState* state = ri->state;
GFX->disableShaders();
...
As you can see, the SceneState information is passed in via an ObjectRenderInst pointer (*ri). Nifty, huh?
[edit] ShapeBase ExampleLet's talk about ShapeBase. The Sky class has shown us a great RenderDelegate example, but 2 is always better than one. The ShapeBase class contains two RenderDelegates. One is the standard mRenderDelegate, just like Sky has. The second one is mShadowRenderDelegate, which (you guessed it) is used for rendering a shape's shadow:
ObjectRenderInst::RenderDelegate mRenderDelegate; ObjectRenderInst::RenderDelegate mShadowRenderDelegate;
mRenderDelegate.bind(this, &ShapeBase::renderObject); mShadowRenderDelegate.bind(this, &ShapeBase::renderShadow);
if( renderSelf && mDataBlock->shadowEnable )
{
ObjectRenderInst *ri = gRenderInstManager->allocInst<ObjectRenderInst>();
ri->mRenderDelegate = mShadowRenderDelegate;
ri->state = state;
ri->type = RenderPassManager::RIT_Shadow;
gRenderInstManager->addInst(ri);
}
// Check the shapebase's datablock to see if we render a shadow
if( renderSelf && mDataBlock->shadowEnable )
{
// Datablock said we should render a shadow, so we are here...
// We must have a render instance before we can proceed.
// We'll use our global RenderPassManager, gRenderInstManager, which is the lead render manager for GFX
ObjectRenderInst *ri = gRenderInstManager->allocInst<ObjectRenderInst>();
// Now that we have an object render instance, let's assign the shadow render delegate
ri->mRenderDelegate = mShadowRenderDelegate;
// Assign the SceneState set up earlier in the function
ri->state = state;
// Assign the shadow render instance type (RIT_SHADOW)
// This will tell our RenderPassManager what kind of render instance we are
// working with, shadows as opposed to a mesh or sky
ri->type = RenderPassManager::RIT_Shadow;
// Add the new render instance to our global manager and move on.
gRenderInstManager->addInst(ri);
}
[edit] ConclusionThis goal of this document was to provide you with an introduction and specific examples of the new RenderDelegate system introduced by TGEA 1.8's GFX2. Should you decide to create your own custom classes which require rendering of objects, please refer back to this doc. Making use of RenderDelegates can make your code cleaner and more modular.
|



