LCOV - code coverage report
Current view: top level - seq - renderer.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 1 97 1.0 %
Date: 2016-07-30 05:04:55 Functions: 2 33 6.1 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2011-2016, Stefan Eilemann <eile@eyescale.ch>
       3             :  *                          Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *                          Petros Kataras <petroskataras@gmail.com>
       5             :  *
       6             :  * This library is free software; you can redistribute it and/or modify it under
       7             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       8             :  * by the Free Software Foundation.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      12             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      17             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             :  */
      19             : 
      20             : #include "renderer.h"
      21             : 
      22             : #include "application.h"
      23             : #include "viewData.h"
      24             : #include "detail/objectMap.h"
      25             : #include "detail/renderer.h"
      26             : #include "detail/window.h"
      27             : 
      28             : namespace seq
      29             : {
      30           0 : Renderer::Renderer( Application& application )
      31           0 :     : _impl( new detail::Renderer )
      32           0 :     , app_( application )
      33             : {
      34           0 : }
      35             : 
      36           0 : Renderer::~Renderer()
      37             : {
      38           0 :     delete _impl;
      39           0 : }
      40             : 
      41           0 : co::Object* Renderer::getFrameData()
      42             : {
      43           0 :     return _impl->getFrameData();
      44             : }
      45             : 
      46           0 : const ObjectManager& Renderer::getObjectManager() const
      47             : {
      48           0 :     return _impl->getObjectManager();
      49             : }
      50             : 
      51           0 : ObjectManager& Renderer::getObjectManager()
      52             : {
      53           0 :     return _impl->getObjectManager();
      54             : }
      55             : 
      56           0 : const GLEWContext* Renderer::glewGetContext() const
      57             : {
      58           0 :     return _impl->glewGetContext();
      59             : }
      60             : 
      61           0 : const ViewData* Renderer::getViewData() const
      62             : {
      63           0 :     return _impl->getViewData();
      64             : }
      65             : 
      66           0 : ViewData* Renderer::createViewData( View& view )
      67             : {
      68           0 :     return new ViewData( view );
      69             : }
      70             : 
      71           0 : void Renderer::destroyViewData( ViewData* viewData )
      72             : {
      73           0 :     delete viewData;
      74           0 : }
      75             : 
      76           0 : const Frustumf& Renderer::getFrustum() const
      77             : {
      78           0 :     return _impl->getFrustum();
      79             : }
      80             : 
      81           0 : const Matrix4f& Renderer::getViewMatrix() const
      82             : {
      83           0 :     return _impl->getViewMatrix();
      84             : }
      85             : 
      86           0 : const Matrix4f& Renderer::getModelMatrix() const
      87             : {
      88           0 :     return _impl->getModelMatrix();
      89             : }
      90             : 
      91           0 : const PixelViewport& Renderer::getPixelViewport() const
      92             : {
      93           0 :     return _impl->getPixelViewport();
      94             : }
      95             : 
      96           0 : uint32_t Renderer::getWindowID() const
      97             : {
      98           0 :     const eq::Window* window = _impl->getWindow();
      99           0 :     return window ? window->getSerial() : CO_INSTANCE_INVALID;
     100             : }
     101             : 
     102           0 : bool Renderer::initContext( co::Object* /*initData*/ )
     103             : {
     104           0 :     return _impl->initContext();
     105             : }
     106             : 
     107           0 : bool Renderer::exitContext()
     108             : {
     109           0 :     return _impl->exitContext();
     110             : }
     111             : 
     112           0 : void Renderer::clear( co::Object* /*frameData*/ )
     113             : {
     114           0 :     _impl->clear();
     115           0 : }
     116             : 
     117           0 : void Renderer::requestRedraw()
     118             : {
     119           0 :     _impl->requestRedraw();
     120           0 : }
     121             : 
     122           0 : void Renderer::updateNearFar( const Vector4f& boundingSphere )
     123             : {
     124           0 :     const Matrix4f& view = getViewMatrix();
     125           0 :     const Matrix4f& viewInv = view.inverse();
     126           0 :     const Vector3f& zero  = viewInv * Vector3f::ZERO;
     127           0 :     Vector3f        front = viewInv * Vector3f( 0.0f, 0.0f, -1.0f );
     128           0 :     front -= zero;
     129           0 :     front.normalize();
     130           0 :     front *= boundingSphere.w();
     131             : 
     132           0 :     const Vector3f& translation = getModelMatrix().getTranslation();
     133             :     const Vector3f& center = translation -
     134           0 :                              boundingSphere.get_sub_vector< 3, 0 >();
     135           0 :     const Vector3f& nearPoint  = view * ( center - front );
     136           0 :     const Vector3f& farPoint   = view * ( center + front );
     137             : 
     138           0 :     if( _impl->useOrtho( ))
     139             :     {
     140           0 :         LBASSERTINFO( fabs( farPoint.z() - nearPoint.z() ) >
     141             :                       std::numeric_limits< float >::epsilon(),
     142             :                       nearPoint << " == " << farPoint );
     143           0 :         setNearFar( -nearPoint.z(), -farPoint.z() );
     144             :     }
     145             :     else
     146             :     {
     147             :         // estimate minimal value of near plane based on frustum size
     148           0 :         const eq::Frustumf& frustum = _impl->getFrustum();
     149           0 :         const float width  = fabs( frustum.right() - frustum.left() );
     150           0 :         const float height = fabs( frustum.top() - frustum.bottom() );
     151           0 :         const float size   = LB_MIN( width, height );
     152           0 :         const float minNear = frustum.nearPlane() / size * .001f;
     153             : 
     154           0 :         const float zNear = LB_MAX( minNear, -nearPoint.z() );
     155           0 :         const float zFar  = LB_MAX( zNear * 2.f, -farPoint.z() );
     156             : 
     157           0 :         setNearFar( zNear, zFar );
     158             :     }
     159           0 : }
     160             : 
     161           0 : void Renderer::setNearFar( const float nearPlane, const float farPlane )
     162             : {
     163           0 :     _impl->setNearFar( nearPlane, farPlane );
     164           0 : }
     165             : 
     166           0 : void Renderer::applyRenderContext()
     167             : {
     168           0 :     _impl->applyRenderContext();
     169           0 : }
     170             : 
     171           0 : void Renderer::bindDrawFrameBuffer()
     172             : {
     173           0 :     _impl->bindDrawFrameBuffer();
     174           0 : }
     175             : 
     176           0 : const RenderContext& Renderer::getRenderContext() const
     177             : {
     178           0 :     return _impl->getRenderContext();
     179             : }
     180             : 
     181           0 : void Renderer::applyModelMatrix()
     182             : {
     183           0 :     _impl->applyModelMatrix();
     184           0 : }
     185             : 
     186           0 : void Renderer::applyScreenFrustum()
     187             : {
     188           0 :     _impl->applyScreenFrustum();
     189           0 : }
     190             : 
     191           0 : void Renderer::applyPerspectiveFrustum()
     192             : {
     193           0 :     _impl->applyPerspectiveFrustum();
     194           0 : }
     195             : 
     196           0 : co::Object* Renderer::createObject( const uint32_t type )
     197             : {
     198           0 :     return app_.createObject( type );
     199             : }
     200             : 
     201           0 : void Renderer::destroyObject( co::Object* object, const uint32_t type )
     202             : {
     203           0 :     app_.destroyObject( object, type );
     204           0 : }
     205             : 
     206           0 : co::Object* Renderer::mapObject( const uint128_t& identifier,
     207             :                                  co::Object* instance )
     208             : {
     209           0 :    return _impl->mapObject( identifier, instance );
     210             : }
     211             : 
     212           0 : bool Renderer::unmap( co::Object* object )
     213             : {
     214           0 :    return _impl->unmap( object );
     215             : }
     216             : 
     217             : 
     218          42 : }

Generated by: LCOV version 1.11