Exemplo n.º 1
0
void QtMinimalWidget::keyPressEvent( QKeyEvent *event )
{
  SceniXQGLWidget::keyPressEvent( event );

  if ( ( event->text().compare( " " ) == 0 ) && ! getContinuousUpdate() )
  {
    repaint();
  }
  else if ( event->text().compare( "d" ) == 0 )
  {
    dp::sg::renderer::rix::gl::SceneRendererSharedPtr const& renderer = getSceneRenderer().staticCast<dp::sg::renderer::rix::gl::SceneRenderer>();
    renderer->setDepthPass( ! renderer->getDepthPass() );
  }
  else if ( event->text().compare("s") == 0 )
  {
    screenshot();
  }
  else if ( event->text().compare( "o" ) == 0 )
  {
    dp::sg::algorithm::optimizeScene( getViewState()->getScene(), true, true
                                    , dp::sg::algorithm::CombineTraverser::CT_ALL_TARGETS_MASK
                                    , dp::sg::algorithm::EliminateTraverser::ET_ALL_TARGETS_MASK
                                    , dp::sg::algorithm::UnifyTraverser::UT_ALL_TARGETS_MASK
                                    , FLT_EPSILON );
  }
  else if ( event->text().compare("x") == 0 )
  {
    dp::gl::RenderContextFormat format = getFormat();
    format.setStereo( !format.isStereo() );
    setFormat( format );
  }
}
Exemplo n.º 2
0
void TerrainRenderer::paint()
{
  dp::sg::renderer::rix::gl::SceneRendererSharedPtr renderer = getSceneRenderer().staticCast<dp::sg::renderer::rix::gl::SceneRenderer>();
  if ( !m_renderEngine.empty() && renderer->getRenderEngine() != m_renderEngine )
  {
    std::cout << "Setting renderengine: " << m_renderEngine << std::endl;
    renderer->setRenderEngine( m_renderEngine );
  }

  renderer->setShaderManager( m_shaderManager);

  glPatchParameteri( GL_PATCH_VERTICES, 1 ); // TODO temporary, terrain patch has only 1 'virtual' vertex per patch
  //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

  dp::util::FrameProfiler::instance().beginFrame();
  if ( m_benchmarkFrames != ~0 || m_duration != 0.0 )
  {
    if ( m_renderedFrames == 1 )
    {
      m_benchmarkTimer.start();
      m_benchmarkProgressTimer.start();
    }

    SceneRendererWidget::paint();

    if ( m_benchmarkProgressTimer.getTime() > 1.0 )
    {
      m_benchmarkProgressTimer.restart();
      std::ostringstream os;
      os << "Benchmark Progress: ";
      if ( m_benchmarkFrames != ~0 )
      {
        os << m_renderedFrames << "/" << m_benchmarkFrames;
      }
      else
      {
        os << std::setprecision(2) << m_benchmarkTimer.getTime() << "/" << m_duration;
      }
      setWindowTitle( os.str() );
    }
    if ( (m_benchmarkFrames != ~0 && m_renderedFrames == m_benchmarkFrames) || (m_duration > 0.0 && m_benchmarkTimer.getTime() > m_duration) )
    {
      m_benchmarkTimer.stop();
      m_exitCode = int(double(m_renderedFrames) / m_benchmarkTimer.getTime());
      glutLeaveMainLoop();
    }

    // at the end since the first frame does not count
    ++m_renderedFrames;
  }
  else
  {
    SceneRendererWidget::paint();
  }
  dp::util::FrameProfiler::instance().endFrame();
}
Exemplo n.º 3
0
void GLUTMinimalCFR::onHIDEvent( dp::util::PropertyId propertyId )
{
  if ( propertyId == PID_Key_F1 )
  {
    if ( getValue<bool>( propertyId ) )
    {
      getSceneRenderer()->setCullingMode(dp::culling::Mode::CPU);
      std::cout << "culling: CPU" << std::endl;
    }
  }
  else if ( propertyId == PID_Key_F2 )
  {
    if ( getValue<bool>( propertyId ) )
    {
      getSceneRenderer()->setCullingMode(dp::culling::Mode::OPENGL_COMPUTE);
      std::cout << "culling: GL_COMPUTE" << std::endl;
    }
  }
  else if ( propertyId == PID_Key_F3 )
  {
    if ( getValue<bool>( propertyId ) )
    {
      getSceneRenderer()->setCullingMode(dp::culling::Mode::CUDA);
      std::cout << "culling: CUDA" << std::endl;
    }
  }
  else if ( propertyId == PID_Key_F4 )
  {
    if ( getValue<bool>( propertyId ) )
    {
      getSceneRenderer()->setCullingMode(dp::culling::Mode::AUTO);
      std::cout << "culling: AUTO" << std::endl;
    }
  }
  else if ( propertyId == PID_Key_C )
  {
    if ( getValue<bool>( propertyId) )
    {
      bool enabled = !getSceneRenderer()->isCullingEnabled();
      getSceneRenderer()->setCullingEnabled(enabled);
      std::cout << "culling " << (enabled ? "enabled" : "disabled") << std::endl;
    }
  }
  else if ( propertyId == PID_Key_B ) // Toggle Bindless
  {
    if ( getValue<bool>( propertyId ) )
    {
      m_engineBindless = !m_engineBindless;
      updateSceneRendererEngine();
    }
  }
  else if ( propertyId == PID_Key_G ) // attrib generic
  {
    if ( getValue<bool>( propertyId ) )
    {
      m_attributeType = AttributeType::GENERIC;
      updateSceneRendererEngine();
    }
  }

  else if ( propertyId == PID_Key_V ) // attrib VAO
  {
    if ( getValue<bool>( propertyId ) )
    {
      m_attributeType = AttributeType::VAO;
      updateSceneRendererEngine();
    }
  }

  else if ( propertyId == PID_Key_A ) // Toggle attrib VAB
  {
    if ( getValue<bool>( propertyId ) )
    {
      m_attributeType = AttributeType::VAB;
      updateSceneRendererEngine();
    }
  }
  else if ( propertyId == PID_Key_Escape )
  {
    if ( getValue<bool>( propertyId ) )
    {
      glutLeaveMainLoop();
    }
  }
  else if ( propertyId == PID_Key_F9 )
  {
    if ( getValue<bool>( propertyId ) )
    {
      std::cout << "Setting shadermanager: " << "uniform" << std::endl;
      m_shaderManager = dp::fx::Manager::UNIFORM;
    }
  }
  else if ( propertyId == PID_Key_F10 )
  {
    if ( getValue<bool>( propertyId ) )
    {
      std::cout << "Setting shadermanager: " << "uniform buffer object" << std::endl;
      m_shaderManager = dp::fx::Manager::UNIFORM_BUFFER_OBJECT_RIX;
    }
  }
  else if ( propertyId == PID_Key_F11 )
  {
    if ( getValue<bool>( propertyId ) )
    {
      std::cout << "Setting shadermanager: " << "shaderbufferload" << std::endl;
      m_shaderManager = dp::fx::Manager::SHADERBUFFER;
    }
  }
  else if ( propertyId == PID_Key_F12 )
  {
    if ( getValue<bool>( propertyId ) )
    {
      std::cout << "Setting shadermanager: " << "shader storage buffer object" << std::endl;
      m_shaderManager = dp::fx::Manager::SHADER_STORAGE_BUFFER_OBJECT;
    }
  }
  else if ( propertyId == PID_Key_P )
  {
    if ( getValue<bool>( propertyId ) )
    {
      dp::util::FrameProfiler::instance().setEnabled( !dp::util::FrameProfiler::instance().isEnabled() );
    }
  }
  else if ( propertyId == PID_Key_Space )
  {
    if ( getValue<bool>( propertyId ) )
    {
      paint();
    }
  }
}
Exemplo n.º 4
0
void GLUTMinimal::paint()
{
  try
  {
    dp::sg::renderer::rix::gl::SceneRendererSharedPtr renderer = getSceneRenderer().staticCast<dp::sg::renderer::rix::gl::SceneRenderer>();
    if ( !m_renderEngine.empty() && renderer->getRenderEngine() != m_renderEngine )
    {
      std::cout << "Setting renderengine: " << m_renderEngine << std::endl;
      renderer->setRenderEngine( m_renderEngine );
    }

    renderer->setShaderManager( m_shaderManager);

    dp::util::FrameProfiler::instance().beginFrame();
    if ( m_benchmarkFrames != ~0 || m_duration != 0.0 )
    {
      if ( m_renderedFrames == 1 )
      {
        m_benchmarkTimer.start();
        m_benchmarkProgressTimer.start();
      }

      SceneRendererWidget::paint();

      if ( m_benchmarkProgressTimer.getTime() > 1.0 )
      {
        m_benchmarkProgressTimer.restart();
        std::ostringstream os;
        os << "Benchmark Progress: ";
        if ( m_benchmarkFrames != ~0 )
        {
          os << m_renderedFrames << "/" << m_benchmarkFrames;
        }
        else
        {
          os << std::setprecision(2) << m_benchmarkTimer.getTime() << "/" << m_duration;
        }
        setWindowTitle( os.str() );
      }
      if ( (m_benchmarkFrames != ~0 && m_renderedFrames == m_benchmarkFrames) || (m_duration > 0.0 && m_benchmarkTimer.getTime() > m_duration) )
      {
        m_benchmarkTimer.stop();
        m_exitCode = int(double(m_renderedFrames) / m_benchmarkTimer.getTime());
        std::cout << "FPS: " << std::fixed << std::setprecision(2) << double(m_renderedFrames) / m_benchmarkTimer.getTime() << std::endl;
        glutLeaveMainLoop();
      }

      // at the end since the first frame does not count
      ++m_renderedFrames;
    }
    else
    {
      SceneRendererWidget::paint();
    }
    dp::util::FrameProfiler::instance().endFrame();
  }
  catch (std::exception &e)
  {
    std::cout << "caught exception: " << std::endl << e.what() << std::endl;
    glutLeaveMainLoop();
  }
  catch (...)
  {
    std::cout << "caught exception" << std::endl;
    glutLeaveMainLoop();
  }
}
Exemplo n.º 5
0
void QtMinimalWidget::onRenderTargetChanged( const dp::gl::RenderTargetSharedPtr &oldTarget, const dp::gl::RenderTargetSharedPtr &newTarget )
{
  dp::sg::renderer::rix::gl::SceneRendererSharedPtr sr = getSceneRenderer().dynamicCast<dp::sg::renderer::rix::gl::SceneRenderer>();
  setSceneRenderer( dp::sg::renderer::rix::gl::SceneRenderer::create( sr->getRenderEngine().c_str(), sr->getShaderManager(), sr->getCullingMode(), sr->getTransparencyMode(), newTarget ) );
}