LCOV - code coverage report
Current view: top level - seq - renderer.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 22 100 22.0 %
Date: 2017-12-16 05:07:20 Functions: 10 34 29.4 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2011-2017, 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 "detail/objectMap.h"
      24             : #include "detail/renderer.h"
      25             : #include "detail/window.h"
      26             : #include "viewData.h"
      27             : 
      28             : namespace seq
      29             : {
      30           2 : Renderer::Renderer(Application& application)
      31           2 :     : _impl(new detail::Renderer)
      32           4 :     , app_(application)
      33             : {
      34           2 : }
      35             : 
      36           4 : Renderer::~Renderer()
      37             : {
      38           2 :     delete _impl;
      39           2 : }
      40             : 
      41           5 : co::Object* Renderer::getFrameData()
      42             : {
      43           5 :     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           1 : ViewData* Renderer::createViewData(View& view)
      67             : {
      68           1 :     return new ViewData(view);
      69             : }
      70             : 
      71           1 : void Renderer::destroyViewData(ViewData* viewData)
      72             : {
      73           1 :     delete viewData;
      74           1 : }
      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           2 : bool Renderer::initContext(co::Object* /*initData*/)
     103             : {
     104           2 :     return _impl->initContext();
     105             : }
     106             : 
     107           2 : bool Renderer::exitContext()
     108             : {
     109           2 :     return _impl->exitContext();
     110             : }
     111             : 
     112           3 : void Renderer::clear(co::Object* /*frameData*/)
     113             : {
     114           3 :     _impl->clear();
     115           3 : }
     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();
     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 =
     134           0 :         translation - 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::updateNearFar(const AABBf& box)
     162             : {
     163           0 :     updateNearFar({box.getCenter(), box.getSize().length() * 0.5f});
     164           0 : }
     165             : 
     166           0 : void Renderer::setNearFar(const float nearPlane, const float farPlane)
     167             : {
     168           0 :     _impl->setNearFar(nearPlane, farPlane);
     169           0 : }
     170             : 
     171           0 : void Renderer::applyRenderContext()
     172             : {
     173           0 :     _impl->applyRenderContext();
     174           0 : }
     175             : 
     176           0 : void Renderer::bindDrawFrameBuffer()
     177             : {
     178           0 :     _impl->bindDrawFrameBuffer();
     179           0 : }
     180             : 
     181           0 : const RenderContext& Renderer::getRenderContext() const
     182             : {
     183           0 :     return _impl->getRenderContext();
     184             : }
     185             : 
     186           0 : void Renderer::applyModelMatrix()
     187             : {
     188           0 :     _impl->applyModelMatrix();
     189           0 : }
     190             : 
     191           0 : void Renderer::applyScreenFrustum()
     192             : {
     193           0 :     _impl->applyScreenFrustum();
     194           0 : }
     195             : 
     196           0 : void Renderer::applyPerspectiveFrustum()
     197             : {
     198           0 :     _impl->applyPerspectiveFrustum();
     199           0 : }
     200             : 
     201           0 : co::Object* Renderer::createObject(const uint32_t type)
     202             : {
     203           0 :     return app_.createObject(type);
     204             : }
     205             : 
     206           0 : void Renderer::destroyObject(co::Object* object, const uint32_t type)
     207             : {
     208           0 :     app_.destroyObject(object, type);
     209           0 : }
     210             : 
     211           0 : co::Object* Renderer::mapObject(const uint128_t& identifier,
     212             :                                 co::Object* instance)
     213             : {
     214           0 :     return _impl->mapObject(identifier, instance);
     215             : }
     216             : 
     217           0 : bool Renderer::unmap(co::Object* object)
     218             : {
     219           0 :     return _impl->unmap(object);
     220             : }
     221          30 : }

Generated by: LCOV version 1.11