Horde3D

Next-Generation Graphics Engine
It is currently 22.11.2024, 10:59

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Viewports in Horde
PostPosted: 15.12.2008, 12:00 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
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 );


Top
 Profile  
Reply with quote  
 Post subject: Re: Viewports in Horde
PostPosted: 16.12.2008, 01:11 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
As an alternative to the additional function we could of course add a parameter to resize, e.g. bool frameBufChanged.


Top
 Profile  
Reply with quote  
 Post subject: Re: Viewports in Horde
PostPosted: 16.12.2008, 02:47 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
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 );


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group