I've been adding view-port support to my engine, but I've noticed that Horde isn't really designed to support view-ports. Specifically, whenever I set the view-port, Horde ends up calling
PipelineResource::createRenderTargets, because it assumes that the back-buffer has been resized.
I was wondering if anyone has any ideas of how to better support view-ports?
I'll probably add a new function
Horde3D::viewport (to supplement
Horde3D::resize), but I thought I'd see what other ideas you guys have.
------------------------------------------------------------------------
Here's the code from my engine (if anyone's interested) for rendering a hierarchy of viewports:
Code:
void CRenderer::Render( const CView& view )
{
Render( view, CRectf(0,1) );
}
void CRenderer::Render( const CView& view, const CRect& parentPort )
{
const CRect newView = view.Viewport() >> parentPort;
SetViewport( newView );
const PCameraNode& pCam = view.Camera();
NodeHandle cam = pCam ? pCam->GetID() : 0;
if( cam )
{
for( CView::node_iterator itScene = view.FirstScene(); itScene != view.EndScene(); ++itScene )
{
ActivateRoot( *itScene );
Horde3D::render( cam );
Horde3D::clearOverlays();
}
}
for( CView::view_iterator itChild = view.FirstChild(); itChild != view.EndChild(); ++itChild )
{
ASSERT( *itChild )
Render( **itChild, newView );
}
}
Supporting code:
Code:
void CRenderer::ActivateRoot( const CRootNode* pNewRoot )
{
for( SceneList::iterator i = m_Scenes.begin(); i != m_Scenes.end(); ++i )
{
CRootNode* p = *i;
p->Visible( p == pNewRoot );
}
}
void CRenderer::SetSize( uint width, uint height )
{
m_Width = width;
m_Height = height;
Resize();
}
void CRenderer::Resize()
{
int l = int(m_Viewport.Left () * m_Width );
int b = int(m_Viewport.Bottom() * m_Height);
int w = int(m_Viewport.Width () * m_Width );
int h = int(m_Viewport.Height() * m_Height);
Horde3D::resize( l, b, w, h );
}
void CRenderer::SetViewport( const CRect& view )
{
if( view != m_Viewport )
{
m_Viewport = view;
Resize();
}
}
template< class T >
TRect<T> TRect::operator>>( const TRect<T>& rhs ) const
{
T w = rhs.Width ();
T h = rhs.Height();
T x = w * LowerLeft().X()+rhs.LowerLeft().X();
T y = h * LowerLeft().Y()+rhs.LowerLeft().Y();
return TRect<T>( x,
y,
x + w * Width (),
y + h * Height() );
}
Example:
Code:
root = new CRootNode( renderer, "root" );
camera = new CCameraNode( *root, "Cam1", *pipeDefault );
camera->View(45, (float)appWidth/appHeight, 0.1f, 1000.0f);
m_View = new CView( camera, root );
PView view = new CView( camera, root );
view->Viewport() = CRect( 0.05f, 0.4f );
m_View->Add( *view );
view = new CView( camera, root );
view2->Viewport() = CRect( 0.15f, 0.5f );
m_View->Add( *view2 );