Ejemplo n.º 1
0
void combineVertexAttributes( dp::sg::ui::ViewStateSharedPtr const& viewState )
{
  DP_ASSERT( viewState && viewState->getScene() && viewState->getScene()->getRootNode() );
  std::vector<dp::sg::core::ObjectSharedPtr> results = dp::sg::algorithm::searchClass( viewState->getScene()->getRootNode(), "class::dp::sg::core::VertexAttributeSet" );
  for ( std::vector<dp::sg::core::ObjectSharedPtr>::iterator it = results.begin(); it != results.end(); ++it )
  {
    it->inplaceCast<dp::sg::core::VertexAttributeSet>()->combineBuffers();
  }
}
Ejemplo n.º 2
0
      bool saveScene( std::string const& filename, dp::sg::ui::ViewStateSharedPtr const& viewState, dp::util::PlugInCallback *callback )
      {
        bool result = false;
        // define a unique plug-interface ID for SceneLoader
        const dp::util::UPITID PITID_SCENE_SAVER(UPITID_SCENE_SAVER, UPITID_VERSION);

        dp::util::FileFinder fileFinder( dp::util::getCurrentPath() );
        fileFinder.addSearchPath( dp::util::getModulePath() );
#if defined(DP_OS_WINDOWS)
        fileFinder.addSearchPath( dp::util::getModulePath( reinterpret_cast<HMODULE>(&__ImageBase) ) );
#endif

        dp::util::UPIID piid = dp::util::UPIID(dp::util::getFileExtension( filename ).c_str(), PITID_SCENE_SAVER);

        {
          dp::util::PlugInSharedPtr plug;
          if ( getInterface( fileFinder, piid, plug ) )
          {
            SceneSaverSharedPtr ss = std::static_pointer_cast<SceneSaver>(plug);
            try
            {
              dp::sg::core::SceneSharedPtr scene( viewState->getScene() ); // DAR HACK Change SceneSaver interface later.
              result = ss->save( scene, viewState, filename );
            }
            catch(...) // catch all others
            {
            }
          }
        }

        // FIXME interface needs to be released since the cleanup order (first dp::sg::core, then dp::util) causes problems upon destruction.
        dp::util::releaseInterface(piid);

        return result;
      }
Ejemplo n.º 3
0
      bool saveScene( std::string const& filename, dp::sg::ui::ViewStateSharedPtr const& viewState, dp::util::PlugInCallback *callback )
      {
        bool result = false;
        // define a unique plug-interface ID for SceneLoader
        const dp::util::UPITID PITID_SCENE_SAVER(UPITID_SCENE_SAVER, UPITID_VERSION);

        vector<string> searchPaths;
        searchPaths.push_back( dp::util::getCurrentPath() );

        std::string modulePath = dp::util::getModulePath();
        if ( std::find( searchPaths.begin(), searchPaths.end(), modulePath ) == searchPaths.end() )
        {
          searchPaths.push_back( modulePath );
        }

#if defined(DP_OS_WINDOWS)
        modulePath = dp::util::getModulePath( reinterpret_cast<HMODULE>(&__ImageBase) );
        if ( std::find( searchPaths.begin(), searchPaths.end(), modulePath ) == searchPaths.end() )
        {
          searchPaths.push_back( modulePath );
        }
#endif

        dp::util::UPIID piid = dp::util::UPIID(dp::util::getFileExtension( filename ).c_str(), PITID_SCENE_SAVER);

        dp::util::PlugIn * plug;

        if ( getInterface( searchPaths, piid, plug ) )
        {
          SceneSaver *ss = reinterpret_cast<SceneSaver *>(plug);
          try
          {
            dp::sg::core::SceneSharedPtr scene( viewState->getScene() ); // DAR HACK Change SceneSaver interface later.
            result = ss->save( scene, viewState, filename );
          }
          catch(...) // catch all others
          {
          }
        }

        return result;
      }
Ejemplo n.º 4
0
void setLights( size_t counter = ~0 )
{
  if( !g_lightSources[0] )
  {
    dp::sg::core::GroupSharedPtr const& rootPtr = g_viewState->getScene()->getRootNode().staticCast<dp::sg::core::Group>();
    DP_ASSERT( rootPtr );

    // add own lights to the root node
    dp::math::Vec3f firstLightPos = g_viewState->getCamera()->getPosition();
    for( size_t i = 0; i < g_numLights; ++i )
    {
      g_lightSources[i] = dp::sg::core::createStandardPointLight( firstLightPos + dp::math::Vec3f( (float)2*i, 0.0f, 0.0f ) );
      rootPtr->addChild( g_lightSources[i] );
    }
  }

  for( size_t i = 0; i < g_numLights; ++i )
  {
    g_lightSources[i]->setEnabled( !!( counter & (1i64 << i) ) );
  }
}
Ejemplo n.º 5
0
void SceneRendererPipeline::doRenderHighlight(dp::sg::ui::ViewStateSharedPtr const& viewState, dp::ui::RenderTargetSharedPtr const& renderTarget)
{
  // only call this if objects need to be rendered highlighted
  DP_ASSERT(m_highlighting);

  // Highlight pass:
  // Match the size of the highlightFBO to the destination renderTarget.
  unsigned int width;
  unsigned int height;
  renderTarget->getSize(width, height);
  m_highlightFBO->setSize(width, height);

  unsigned int originalTraversalMask = viewState->getTraversalMask();
  viewState->setTraversalMask(2); // Render only the highlighted objects.

  glPushAttrib( GL_STENCIL_BUFFER_BIT );

  // If an object is highlighted, render the highlighted object into the stencil buffer of the FBO.

  // Setup the proper stencil state.
  // Write a 1 for every rendered fragment into the stencil buffer
  glStencilFunc(GL_NEVER, 1, ~0);
  glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
  glEnable(GL_STENCIL_TEST);

  // This is always using a SceneRendererGL2 to render the highlighted objects.
  m_highlightFBO->setClearMask( dp::gl::TBM_COLOR_BUFFER
                              | dp::gl::TBM_DEPTH_BUFFER
                              | dp::gl::TBM_STENCIL_BUFFER); // Clear all.

  // A SceneRenderer always uses the scene background color to clear. Temporarily change it to black here.
  dp::math::Vec4f backgroundColor = viewState->getScene()->getBackColor();
  viewState->getScene()->setBackColor( dp::math::Vec4f(0.0f, 0.0f, 0.0f, 0.0f) );

  m_sceneRendererHighlight->render(viewState, m_highlightFBO);

  viewState->getScene()->setBackColor(backgroundColor);

  viewState->setTraversalMask(originalTraversalMask); // Reset the traversal mask.

  // Highlight post-processing:
  // Migrate the stencil bit contents as white color into the texture rectangle.
  m_highlightFBO->setClearMask( dp::gl::TBM_COLOR_BUFFER ); // Do not clear the stencil! Don't care for depth.

  // set the stencil as needed for the stencil to color pass
  glStencilFunc( GL_EQUAL, 1, ~0 );
  glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );

  m_rendererStencilToColor->render();

  glPopAttrib();

  // Render the outline around the highlighted object onto the main renderTarget (framebuffer).
  dp::gl::RenderTargetSharedPtr const & renderTargetGL = renderTarget.inplaceCast<dp::gl::RenderTarget>();
  dp::gl::TargetBufferMask clearMask = renderTargetGL->getClearMask();

  // keep the following render call from clearing the previous rendered content
  renderTargetGL->setClearMask( 0 );
  m_rendererHighlight->render();
  // restore the clear mask
  renderTargetGL->setClearMask( clearMask );
}