Horde3D
http://horde3d.org/forums/

Viewports in Horde
http://horde3d.org/forums/viewtopic.php?f=8&t=582
Page 1 of 1

Author:  DarkAngel [ 15.12.2008, 12:00 ]
Post subject:  Viewports in Horde

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:
Image
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 );

Author:  marciano [ 16.12.2008, 01:11 ]
Post subject:  Re: Viewports in Horde

As an alternative to the additional function we could of course add a parameter to resize, e.g. bool frameBufChanged.

Author:  DarkAngel [ 16.12.2008, 02:47 ]
Post subject:  Re: Viewports in Horde

marciano wrote:
As an alternative to the additional function we could of course add a parameter to resize, e.g. bool frameBufChanged.
Good idea :D

I made the following changes and my sample increased from 9fps to 14fps.
egMain.cpp
Code:
-   DLLEXP void resize( int x, int y, int width, int height )
+   DLLEXP void resize( int x, int y, int width, int height, bool frameBufChanged )
    {
       if( !initialized ) return;
       
       Modules::renderer().resize( x, y, width, height );
 
+      if( !frameBufChanged ) return;
+
       // Update pipeline resources
       for( uint32 i = 0; i < Modules::resMan().getResources().size(); ++i )
       {
Horde3D.h
Code:
-   DLL void resize( int x, int y, int width, int height );
+   DLL void resize( int x, int y, int width, int height, bool frameBufChanged = false );

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/