예제 #1
0
 void GroupDataBufferedCombined::update( )
 {
   // dirty handling is managed by buffer manager
   DP_ASSERT( !"should never be called since");
 }
예제 #2
0
 bool AppTraverser::needsTraversal( const dp::sg::core::NodeSharedPtr & root ) const
 {
   DP_ASSERT( root );
   return( m_forcedTraversal );
 }
        bool TrackballTransformManipulator::rotate()
        {
          if ( ( getCurrentX() != getLastX() ) || ( getCurrentY() != getLastY() ) )
          {
            DP_ASSERT( getViewState()->getCamera().isPtrTo<FrustumCamera>() );
            TransformSharedPtr transform = m_transformPath->getTail().staticCast<Transform>();
            FrustumCameraSharedPtr const& camera = getViewState()->getCamera().staticCast<FrustumCamera>();
            if ( camera && transform )
            {
              unsigned int rtWidth    = getRenderTarget()->getWidth();
              unsigned int rtHeight   = getRenderTarget()->getHeight();
              Vec2f  camWinSize = camera->getWindowSize();
              if (    ( 0 < rtHeight ) && ( 0 < rtWidth )
                  &&  ( FLT_EPSILON < fabs( camWinSize[0] ) )
                  &&  ( FLT_EPSILON < fabs( camWinSize[1] ) ) )
              {
                //  get all the matrices needed here
                Mat44f m2w, w2m, w2v, v2w, v2s, m2v;
                m_transformPath->getModelToWorldMatrix( m2w, w2m ); // model->world and world->model
                w2v = camera->getWorldToViewMatrix();            // world->view
                v2w = camera->getViewToWorldMatrix();            // view->world
                v2s = camera->getProjection();                   // view->screen (normalized)
                m2v = m2w * w2v;

                const Sphere3f& bs = transform->getBoundingSphere();

                //  center of the object in view coordinates
                Vec4f centerV = Vec4f( bs.getCenter(), 1.0f ) * m2v;
                DP_ASSERT( fabs( centerV[3] - 1.0f ) < FLT_EPSILON );

                //  center of the object in normalized screen coordinates
                Vec4f centerNS = centerV * v2s;
                DP_ASSERT( centerNS[3] != 0.0f );
                centerNS /= centerNS[3];

                //  center of the object in screen space
                Vec2f centerS( rtWidth * ( 1 + centerNS[0] ) / 2, rtHeight * ( 1 - centerNS[1] ) / 2 );

                //  move the input points relative to the center 
                //  move the input points absolutely
                //Vec2f last( m_orbitCursor );
                Vec2f last( getLastCursorPosition() );
                Vec2f p0( last[0]    - centerS[0], centerS[1] - last[1] );
                Vec2f p1( getCurrentX() - centerS[0], centerS[1] - getCurrentY() );
                DP_ASSERT( p0[0] != p1[0] || p0[1] != p1[1] );

                //  get the scaling (from model to view)
                Vec3f scaling, translation;
                Quatf orientation, scaleOrientation;
                decompose( m2v, translation, orientation, scaling, scaleOrientation );
                float maxScale = std::max( scaling[0], std::max( scaling[1], scaling[2] ) );
                DP_ASSERT( FLT_EPSILON < fabs( maxScale ) );

                //  determine the radius in screen space (in the centers depth)
                Vec2f centerWindowSize = - centerV[2] / getViewState()->getTargetDistance() * camWinSize;
                float radius = bs.getRadius() * maxScale * rtWidth / centerWindowSize[0];

                //  with p0, p1, and the radius determine the axis and angle of rotation via the Trackball utility
                //  => axis is in view space then
                Vec3f axis;
                float angle;
                m_trackball.setSize( radius );
                m_trackball.apply( p0, p1, axis, angle );
        
                float dx = p1[0]-p0[0];
                float dy = p1[1]-p0[1];

                checkLockAxis(dx, dy);

                if ( m_activeLockAxis[static_cast<size_t>(Axis::X)] )
                {
                  if ( dx < 0 )
                    axis = Vec3f(0.f, -1.f, 0.f);
                  else if ( dx > 0)
                    axis = Vec3f(0.f, 1.f, 0.f);
                  else
                    return false;
                }
                else if ( m_activeLockAxis[static_cast<size_t>(Axis::Y)] )
                {
                  if ( dy < 0 ) 
                    axis = Vec3f(1.f, 0.f, 0.f);
                  else if ( dy > 0) 
                    axis = Vec3f(-1.f, 0.f, 0.f);
                  else 
                    return false;
                }

                // transform axis back into model space
                axis = Vec3f( Vec4f( axis, 0.0f ) * v2w * w2m );
                axis.normalize();

                //  create the rotation around the center (in model space)
                Trafo trafo;
                trafo.setCenter( bs.getCenter() );
                trafo.setOrientation( Quatf( axis, angle ) );

                //  concatenate this rotation with the current transformation
                trafo.setMatrix( transform->getTrafo().getMatrix() * trafo.getMatrix() );

                //  concatenate this rotation with the original transformation
                //trafo.setMatrix( m_matrix * trafo.getMatrix() );

                //  set the current transform
                transform->setTrafo( trafo );

                return true;
              }
            }
          }

          return false;
        }
예제 #4
0
 void SceneTree::addLOD( LODSharedPtr const& lod, ObjectTreeIndex index )
 {
   DP_ASSERT( m_objectTree.m_LODs.find(index) == m_objectTree.m_LODs.end() );
   m_objectTree.m_LODs[index] = lod;
 }
 dp::fx::ParameterGroupLayout::ParameterInfoSharedPtr createParameterInfoShaderBufferLoad( unsigned int type, size_t& offset, size_t arraySize )
 {
   switch (type)
   {
     case PT_FLOAT32                : return std::make_shared<ParameterInfoVectorConversion<dp::Float32, dp::Float32, 1, 1>>( offset, arraySize );
     case PT_FLOAT32 | PT_VECTOR2   : return std::make_shared<ParameterInfoVectorConversion<dp::Float32, dp::Float32, 2, 2>>( offset, arraySize );
     case PT_FLOAT32 | PT_VECTOR3   : return std::make_shared<ParameterInfoVectorConversion<dp::Float32, dp::Float32, 3, 4>>( offset, arraySize );
     case PT_FLOAT32 | PT_VECTOR4   : return std::make_shared<ParameterInfoVectorConversion<dp::Float32, dp::Float32, 4, 4>>( offset, arraySize );
     case PT_INT8                   : return std::make_shared<ParameterInfoVectorConversion<int8_t     , int32_t    , 1, 1>>( offset, arraySize );
     case PT_INT8 | PT_VECTOR2      : return std::make_shared<ParameterInfoVectorConversion<int8_t     , int32_t    , 2, 2>>( offset, arraySize );
     case PT_INT8 | PT_VECTOR3      : return std::make_shared<ParameterInfoVectorConversion<int8_t     , int32_t    , 3, 4>>( offset, arraySize );
     case PT_INT8 | PT_VECTOR4      : return std::make_shared<ParameterInfoVectorConversion<int8_t     , int32_t    , 4, 4>>( offset, arraySize );
     case PT_INT16                  : return std::make_shared<ParameterInfoVectorConversion<int16_t    , int32_t    , 1, 1>>( offset, arraySize );
     case PT_INT16 | PT_VECTOR2     : return std::make_shared<ParameterInfoVectorConversion<int16_t    , int32_t    , 2, 2>>( offset, arraySize );
     case PT_INT16 | PT_VECTOR3     : return std::make_shared<ParameterInfoVectorConversion<int16_t    , int32_t    , 3, 4>>( offset, arraySize );
     case PT_INT16 | PT_VECTOR4     : return std::make_shared<ParameterInfoVectorConversion<int16_t    , int32_t    , 4, 4>>( offset, arraySize );
     case PT_INT32                  : return std::make_shared<ParameterInfoVectorConversion<int32_t    , int32_t    , 1, 1>>( offset, arraySize );
     case PT_INT32 | PT_VECTOR2     : return std::make_shared<ParameterInfoVectorConversion<int32_t    , int32_t    , 2, 2>>( offset, arraySize );
     case PT_INT32 | PT_VECTOR3     : return std::make_shared<ParameterInfoVectorConversion<int32_t    , int32_t    , 3, 4>>( offset, arraySize );
     case PT_INT32 | PT_VECTOR4     : return std::make_shared<ParameterInfoVectorConversion<int32_t    , int32_t    , 4, 4>>( offset, arraySize );
     case PT_INT64                  : return std::make_shared<ParameterInfoVectorConversion<int64_t    , int64_t    , 1, 1>>( offset, arraySize );
     case PT_INT64 | PT_VECTOR2     : return std::make_shared<ParameterInfoVectorConversion<int64_t    , int64_t    , 2, 2>>( offset, arraySize );
     case PT_INT64 | PT_VECTOR3     : return std::make_shared<ParameterInfoVectorConversion<int64_t    , int64_t    , 3, 4>>( offset, arraySize );
     case PT_INT64 | PT_VECTOR4     : return std::make_shared<ParameterInfoVectorConversion<int64_t    , int64_t    , 4, 4>>( offset, arraySize );
     case PT_UINT8                  : return std::make_shared<ParameterInfoVectorConversion<uint8_t    , uint32_t   , 1, 1>>( offset, arraySize );
     case PT_UINT8 | PT_VECTOR2     : return std::make_shared<ParameterInfoVectorConversion<uint8_t    , uint32_t   , 2, 2>>( offset, arraySize );
     case PT_UINT8 | PT_VECTOR3     : return std::make_shared<ParameterInfoVectorConversion<uint8_t    , uint32_t   , 3, 4>>( offset, arraySize );
     case PT_UINT8 | PT_VECTOR4     : return std::make_shared<ParameterInfoVectorConversion<uint8_t    , uint32_t   , 4, 4>>( offset, arraySize );
     case PT_UINT16                 : return std::make_shared<ParameterInfoVectorConversion<uint16_t   , uint32_t   , 1, 1>>( offset, arraySize );
     case PT_UINT16 | PT_VECTOR2    : return std::make_shared<ParameterInfoVectorConversion<uint16_t   , uint32_t   , 2, 2>>( offset, arraySize );
     case PT_UINT16 | PT_VECTOR3    : return std::make_shared<ParameterInfoVectorConversion<uint16_t   , uint32_t   , 3, 4>>( offset, arraySize );
     case PT_UINT16 | PT_VECTOR4    : return std::make_shared<ParameterInfoVectorConversion<uint16_t   , uint32_t   , 4, 4>>( offset, arraySize );
     case PT_UINT32                 : return std::make_shared<ParameterInfoVectorConversion<uint32_t   , uint32_t   , 1, 1>>( offset, arraySize );
     case PT_UINT32 | PT_VECTOR2    : return std::make_shared<ParameterInfoVectorConversion<uint32_t   , uint32_t   , 2, 2>>( offset, arraySize );
     case PT_UINT32 | PT_VECTOR3    : return std::make_shared<ParameterInfoVectorConversion<uint32_t   , uint32_t   , 3, 4>>( offset, arraySize );
     case PT_UINT32 | PT_VECTOR4    : return std::make_shared<ParameterInfoVectorConversion<uint32_t   , uint32_t   , 4, 4>>( offset, arraySize );
     case PT_UINT64                 : return std::make_shared<ParameterInfoVectorConversion<uint64_t   , uint64_t   , 1, 1>>( offset, arraySize );
     case PT_UINT64 | PT_VECTOR2    : return std::make_shared<ParameterInfoVectorConversion<uint64_t   , uint64_t   , 2, 2>>( offset, arraySize );
     case PT_UINT64 | PT_VECTOR3    : return std::make_shared<ParameterInfoVectorConversion<uint64_t   , uint64_t   , 3, 4>>( offset, arraySize );
     case PT_UINT64 | PT_VECTOR4    : return std::make_shared<ParameterInfoVectorConversion<uint64_t   , uint64_t   , 4, 4>>( offset, arraySize );
     case PT_BOOL                   : return std::make_shared<ParameterInfoVectorConversion<bool       , uint32_t   , 1, 1>>( offset, arraySize );
     case PT_BOOL | PT_VECTOR2      : return std::make_shared<ParameterInfoVectorConversion<bool       , uint32_t   , 2, 2>>( offset, arraySize );
     case PT_BOOL | PT_VECTOR3      : return std::make_shared<ParameterInfoVectorConversion<bool       , uint32_t   , 3, 4>>( offset, arraySize );
     case PT_BOOL | PT_VECTOR4      : return std::make_shared<ParameterInfoVectorConversion<bool       , uint32_t   , 4, 4>>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX2x2 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float32, dp::Float32, 2, 2, 2>>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX2x3 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float32, dp::Float32, 3, 4, 2>>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX2x4 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float32, dp::Float32, 4, 4, 2>>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX3x2 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float32, dp::Float32, 2, 2, 3>>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX3x3 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float32, dp::Float32, 3, 4, 3>>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX3x4 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float32, dp::Float32, 4, 4, 3>>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX4x2 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float32, dp::Float32, 2, 2, 4>>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX4x3 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float32, dp::Float32, 3, 4, 4>>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX4x4 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float32, dp::Float32, 4, 4, 4>>( offset, arraySize );
     case PT_FLOAT64                : return std::make_shared<ParameterInfoVectorConversion<dp::Float64, dp::Float64, 1, 1>>( offset, arraySize );
     case PT_FLOAT64 | PT_VECTOR2   : return std::make_shared<ParameterInfoVectorConversion<dp::Float64, dp::Float64, 2, 2>>( offset, arraySize );
     case PT_FLOAT64 | PT_VECTOR3   : return std::make_shared<ParameterInfoVectorConversion<dp::Float64, dp::Float64, 3, 4>>( offset, arraySize );
     case PT_FLOAT64 | PT_VECTOR4   : return std::make_shared<ParameterInfoVectorConversion<dp::Float64, dp::Float64, 4, 4>>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX2x2 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float64, dp::Float64, 2, 2, 2>>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX2x3 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float64, dp::Float64, 3, 4, 2>>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX2x4 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float64, dp::Float64, 4, 4, 2>>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX3x2 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float64, dp::Float64, 2, 2, 3>>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX3x3 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float64, dp::Float64, 3, 4, 3>>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX3x4 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float64, dp::Float64, 4, 4, 3>>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX4x2 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float64, dp::Float64, 2, 2, 4>>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX4x3 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float64, dp::Float64, 3, 4, 4>>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX4x4 : return std::make_shared<ParameterInfoMatrixConversion<dp::Float64, dp::Float64, 4, 4, 4>>( offset, arraySize );
     case PT_ENUM                   : return std::make_shared<ParameterInfoVectorConversion<dp::fx::EnumSpec::StorageType, int, 1, 1>>( offset, arraySize );
     default:
       DP_ASSERT( !"Unsupported parametertype" );
       return dp::fx::ParameterGroupLayout::ParameterInfoSharedPtr();
   }
 }
예제 #6
0
파일: main.cpp 프로젝트: raedwulf/pipeline
int runApp( options::variables_map const& opts )
{
  // Create renderer
  std::string cullingEngine = opts["cullingengine"].as<std::string>();
  dp::culling::Mode cullingMode = dp::culling::MODE_AUTO;
  if ( cullingEngine == "cpu" )
  {
    cullingMode = dp::culling::MODE_CPU;
  }
  else if ( cullingEngine == "gl_compute" )
  {
    cullingMode = dp::culling::MODE_OPENGL_COMPUTE;
  }
  else if ( cullingEngine == "cuda" )
  {
    cullingMode = dp::culling::MODE_CUDA;
  }
  else if ( cullingEngine != "auto" )
  {
    std::cerr << "unknown culling engine, abort" << std::endl;
    return -1;
  }

  dp::sg::renderer::rix::gl::SceneRendererSharedPtr renderer = dp::sg::renderer::rix::gl::SceneRenderer::create
  (
      opts["renderengine"].as<std::string>().c_str()
    , getShaderManager( opts["shadermanager"].as<std::string>() )
    , cullingMode
    //, dp::sg::renderer::rix::gl::TM_NONE
  );
  renderer->setCullingEnabled( opts["culling"].as<bool>() );

  if ( !opts["effectlibrary"].empty() )
  {
    dp::fx::EffectLibrary::instance()->loadEffects( opts["effectlibrary"].as<std::string>() );
  }

  dp::sg::ui::ViewStateSharedPtr viewState = loadScene( opts["filename"].as<std::string>() );

  if ( opts.count("replace") )
  {
    // process replacements
    std::vector< std::string> replacementStrings = opts["replace"].as< std::vector<std::string > >();
    dp::sg::algorithm::ReplacementMapNames replacements;
    for ( std::vector<std::string>::iterator it = replacementStrings.begin(); it != replacementStrings.end(); ++it )
    {
      size_t equalChar = it->find_first_of(':');
      if ( equalChar != std::string::npos && equalChar < it->size() - 1)
      {
        std::string str1 = it->substr( 0, equalChar );
        std::string str2 = it->substr( equalChar + 1, it->size() - equalChar - 1);
        replacements[str1] = str2;
      }
      else
      {
        std::cerr << "invalid replacement token: " << *it << std::endl;
      }
    }
    dp::sg::algorithm::replaceEffectDatas( viewState->getScene(), replacements );
  }
  else if ( !opts["replaceAll"].empty() )
  {
    dp::sg::core::EffectDataSharedPtr replacement = dp::sg::core::EffectData::create( dp::fx::EffectLibrary::instance()->getEffectData( opts["replaceAll"].as<std::string>() ) );
    DP_ASSERT( replacement );

    dp::sg::algorithm::SearchTraverser searchTraverser;
    searchTraverser.setClassName( "class dp::sg::core::GeoNode" );
    searchTraverser.setBaseClassSearch( true );
    searchTraverser.apply( viewState->getScene() );
    const std::vector<dp::sg::core::ObjectSharedPtr> &vp = searchTraverser.getResults();
    for ( size_t i=0 ; i<vp.size() ; i++ )
    {
      vp[i].inplaceCast<dp::sg::core::GeoNode>()->setMaterialEffect( replacement );
    }
  }

  if ( opts.count("gridSize") )
  {
    DP_ASSERT( viewState && viewState->getScene() && viewState->getScene()->getRootNode() );

    std::vector<unsigned int> gridSizes = opts["gridSize"].as<std::vector<unsigned int> >();
    dp::math::Vec3ui gridSize;
    int i;
    for ( i=0 ; i<3 && i<gridSizes.size() ; i++ )
    {
      gridSize[i] = gridSizes[i];
    }
    for ( ; i<3 ; i++ )
    {
      gridSize[i] = 1;
    }

    dp::math::Vec3f gridSpacing = dp::math::Vec3f( 1.0f, 1.0f, 1.0f );
    if ( opts.count("gridSpacing") )
    {
      std::vector<float> gridSpacings = opts["gridSpacing"].as<std::vector<float> >();
      for ( int i=0 ; i<3 && i<gridSpacings.size() ; i++ )
      {
        gridSpacing[i] = gridSpacings[i];
      }
    }

    viewState->getScene()->setRootNode( dp::sg::generator::replicate( viewState->getScene()->getRootNode(), gridSize, gridSpacing, opts["gridClone"].as<bool>() ) );
  }

  if ( !opts["statistics"].empty() )
  {
    showStatistics( viewState );
  }

  dp::sg::ui::setupDefaultViewState( viewState );

  if ( !opts["combineVertexAttributes"].empty() )
  {
    combineVertexAttributes( viewState );
  }

  {
    // Replace MatrixCamera by PerspectiveCamera to get all manipulator features
    if ( viewState->getCamera()->getObjectCode() == dp::sg::core::OC_MATRIXCAMERA )
    {
      dp::sg::core::PerspectiveCameraSharedPtr perspectiveCamera = dp::sg::core::PerspectiveCamera::create();
      perspectiveCamera->setOrientation(viewState->getCamera()->getOrientation());
      perspectiveCamera->setDirection((viewState->getCamera()->getDirection()));
      perspectiveCamera->setPosition(viewState->getCamera()->getPosition());

      viewState->setAutoClipPlanes(true);
      viewState->setCamera(perspectiveCamera);
    }
  }

  if ( !opts["headlight"].empty() )
  {
    if ( viewState && viewState->getScene() && !dp::sg::algorithm::containsLight( viewState->getScene() )
      && viewState->getCamera() && ( viewState->getCamera()->getNumberOfHeadLights() == 0 ) )
    {
      // Use the defaults! Note that LightSource ambientColor is black.
      viewState->getCamera()->addHeadLight( dp::sg::core::createStandardPointLight() );
    }
  }

  if ( !opts["environment"].empty() )
  {
    dp::sg::core::TextureSharedPtr texture = dp::sg::core::TextureFile::create( opts["environment"].as<std::string>() );
    dp::sg::core::SamplerSharedPtr sampler = dp::sg::core::Sampler::create( texture );
    renderer->setEnvironmentSampler( sampler );
  }

  // Setup default OpenGL format descriptor
  // We need to create a default format first to be able to check if a stereo pixelformat is available later.
  // (An unfortunate RenderContextFormat.isAvailable() interface due to Linux.)
  dp::gl::RenderContextFormat format;

  // create a widget which shows the scene
  //dp::sg::ui::glut::SceneRendererWidget w( format );
  GLUTMinimal w;

  // TODO format is not yet supported
#if 0
  if (stereo)
  {
    format.setStereo( stereo );
    if ( !w.setFormat( format ) )  // This automatically checks if the format is available.
    {
      std::cout << "Warning: No stereo pixelformat available." << std::endl;
    }
  }
#endif

  viewState->setAutoClipPlanes( opts["autoclipplanes"].as<bool>() );

  //w.setNumberOfFrames( frames );
  w.setViewState( viewState );
  w.setSceneRenderer( renderer );
  if ( !opts["continuous"].empty() )
  {
    w.setContinuousUpdate( true );
    w.setShowFrameRate( true );
  }

  if( opts["frames"].as<int>() != -1 )
  {
    w.setNumberOfFrames( opts["frames"].as<int>() );
  }
  w.setDuration( opts["duration"].as<double>() );

  if ( opts["fullscreen"].empty() )
  {
    size_t width = 640;
    size_t height = 480;

    if ( opts.count("windowSize") )
    {
      std::vector<size_t> sizes = opts["windowSize"].as<std::vector<size_t> >();
      if ( 1 <= sizes.size() )
      {
        width = sizes[0];
        if ( 2 <= sizes.size() )
        {
          height = sizes[1];
        }
      }
    }

    w.setWindowSize( width, height );
  }
  else
  {
    w.setWindowFullScreen();
  }
  //w.show();

  // Keep only once reference to the renderer in the widget. This is necessary since the OpenGL resources
  // used by the renderer must be deleted before the window gets destroyed.
  renderer.reset();

  glutMainLoop();

  return w.getExitCode();
}
예제 #7
0
void TextureTransfer::transfer( size_t index
                              , dp::gl::Texture2DSharedPtr dstTexture
                              , dp::gl::Texture2DSharedPtr srcTexture )
{
#if 1

  if( !m_shadersInitialized )
  {
    constructComputeShaders();
  }
  size_t width  = dstTexture->getWidth();
  size_t height = dstTexture->getHeight();

  DP_ASSERT( width == srcTexture->getWidth() && height == srcTexture->getHeight() );

  size_t tilesX = (width  + m_tileWidth  - 1) / m_tileWidth;  // number of horizontal tiles
  size_t tilesY = (height + m_tileHeight - 1) / m_tileHeight; // number of vert1ical tiles
  size_t tilesXPerGpu = ( tilesX + m_maxIndex - 1 ) / m_maxIndex;

  dp::gl::RenderContextStack contextStack;

  contextStack.push( m_srcContext );

  if( m_srcContext == m_dstContext )
  {
    m_copyProgram->setImageUniform( "dstImg", dstTexture, GL_WRITE_ONLY );
    m_copyProgram->setImageUniform( "srcImg", srcTexture, GL_READ_ONLY );

    m_copyProgram->apply();
    glUniform1i( 0, dp::checked_cast<GLint>(m_maxIndex) );
    glUniform1i( 1, dp::checked_cast<GLint>(index) );

    glDispatchCompute( dp::checked_cast<GLuint>(tilesXPerGpu), dp::checked_cast<GLuint>(tilesY), 1 );
  }
  else
  {
    size_t tmpTexWidth  = m_tileWidth * tilesXPerGpu;
    size_t tmpTexHeight = height;

    // compress the image data into src tmp texture
    dp::gl::Texture2DSharedPtr srcTmpTexture = getTmpTexture( m_srcContext, tmpTexWidth, tmpTexHeight );
    m_compressProgram->setImageUniform( "tmp", srcTmpTexture, GL_WRITE_ONLY );
    m_compressProgram->setImageUniform( "srcImg", srcTexture, GL_READ_ONLY );

    m_compressProgram->apply();
    glUniform1i( 0, dp::checked_cast<GLint>(m_maxIndex) );
    glUniform1i( 1, dp::checked_cast<GLint>(index) );

    glDispatchCompute( dp::checked_cast<GLuint>(tilesXPerGpu), dp::checked_cast<GLuint>(tilesY), 1 );

    contextStack.pop();

    contextStack.push( m_dstContext );
    dp::gl::Texture2DSharedPtr dstTmpTexture = getTmpTexture( m_dstContext, tmpTexWidth, tmpTexHeight );

    // copy src into dst tmp texture
    GLuint idSrc = srcTmpTexture->getGLId();
    GLuint idDst = dstTmpTexture->getGLId();

    HGLRC hglrcSrc = m_srcContext->getHGLRC();
    HGLRC hglrcDst = m_dstContext->getHGLRC();


    {
      dp::util::ProfileEntry p("wglCopyImageSubDataNV");
      DP_VERIFY( wglCopyImageSubDataNV( hglrcSrc, idSrc, GL_TEXTURE_2D, 0, 0, 0, 0
        , hglrcDst, idDst, GL_TEXTURE_2D, 0, 0, 0, 0
        , dp::checked_cast<GLsizei>(tmpTexWidth)
        , dp::checked_cast<GLsizei>(tmpTexHeight)
        , 1 ) );
    }

    // decompress image data from dst tmp texture
    m_decompressProgram->setImageUniform( "dstImg", dstTexture, GL_WRITE_ONLY );
    m_decompressProgram->setImageUniform( "tmp", dstTmpTexture, GL_READ_ONLY );

    m_decompressProgram->apply();
    glUniform1i( 0, dp::checked_cast<GLint>(m_maxIndex) );
    glUniform1i( 1, dp::checked_cast<GLint>(index) );

    glDispatchCompute( dp::checked_cast<GLuint>(tilesXPerGpu), dp::checked_cast<GLuint>(tilesY), 1 );
  }

  contextStack.pop();

#else

  // just copy the image, don't take the pattern into account (debug code)
  size_t width  = dstTexture->getWidth();
  size_t height = dstTexture->getHeight();

  GLuint idSrc = srcTexture->getGLId();
  GLuint idDst = dstTexture->getGLId();

  HGLRC hglrcSrc = m_srcContext->getHGLRC();
  HGLRC hglrcDst = m_dstContext->getHGLRC();

  wglCopyImageSubDataNV( hglrcSrc, idSrc, GL_TEXTURE_2D, 0, 0, 0, 0
                       , hglrcDst, idDst, GL_TEXTURE_2D, 0, 0, 0, 0
                       , dp::checked_cast<GLsizei>(width)
                       , dp::checked_cast<GLsizei>(height)
                       , 1 );

#endif
}
예제 #8
0
 DP_MATH_API float _atof( const std::string &str )
 {
   int pre = 0;
   int post = 0;
   float divisor = 1.0f;
   bool negative = false;
   size_t i = 0;
   while ( ( i < str.length() ) && ( ( str[i] == ' ' ) || ( str[i] == '\t' ) ) )
   {
     i++;
   }
   if ( ( i < str.length() ) && ( ( str[i] == '+' ) || ( str[i] == '-' ) ) )
   {
     negative = ( str[i] == '-' );
     i++;
   }
   while ( ( i < str.length() ) && isdigit( str[i] ) )
   {
     pre = pre * 10 + ( str[i] - 0x30 );
     i++;
   }
   if ( ( i < str.length() ) && ( str[i] == '.' ) )
   {
     i++;
     while ( ( i < str.length() ) && isdigit( str[i] ) && ( post <= INT_MAX/10-9 ) )
     {
       post = post * 10 + ( str[i] - 0x30 );
       divisor *= 10;
       i++;
     }
     while ( ( i < str.length() ) && isdigit( str[i] ) )
     {
       i++;
     }
   }
   if ( negative )
   {
     pre = - pre;
     post = - post;
   }
   float f = post ? pre + post / divisor : (float)pre;
   if ( ( i < str.length() ) && ( ( str[i] == 'd' ) || ( str[i] == 'D' ) || ( str[i] == 'e' ) || ( str[i] == 'E' ) ) )
   {
     i++;
     negative = false;
     if ( ( i < str.length() ) && ( ( str[i] == '+' ) || ( str[i] == '-' ) ) )
     {
       negative = ( str[i] == '-' );
       i++;
     }
     int exponent = 0;
     while ( ( i < str.length() ) && isdigit( str[i] ) )
     {
       exponent = exponent * 10 + ( str[i] - 0x30 );
       i++;
     }
     if ( negative )
     {
       exponent = - exponent;
     }
     f *= pow( 10.0f, exponent );
   }
 #if !defined( NDEBUG )
   float z = (float)atof( str.c_str() );
   DP_ASSERT( fabsf( f - z ) < FLT_EPSILON * std::max( 1.0f, fabsf( z ) ) );
 #endif
   return( f );
 }
예제 #9
0
     Manager* Manager::create()
     {
 DP_ASSERT( !"Compiled without OpenGL 4.3 support" );
       return nullptr;
     }
예제 #10
0
 void addStage( const Stage& stage )
 {
   DP_ASSERT( std::find_if( m_stages.begin(), m_stages.end(), boost::bind( &Stage::domain, _1) == stage.domain ) == m_stages.end() );
   m_stages.push_back( stage );
 }
예제 #11
0
 void SceneObserver::onDestroyed( const dp::util::Subject& subject, dp::util::Payload* payload )
 {
   DP_ASSERT( !"should not happen" );
 }
예제 #12
0
 BufferSharedPtr const& ProgramInstance::getShaderStorageBuffer( size_t ssbIndex ) const
 {
   DP_ASSERT( m_unsetShaderStorageBlocks.find( ssbIndex ) == m_unsetShaderStorageBlocks.end() );
   DP_ASSERT( ssbIndex < m_shaderStorageBuffers.size() );
   return( m_shaderStorageBuffers[ssbIndex] );
 }
예제 #13
0
    Program::Program( std::vector<SmartShader> const& shaders, Parameters const& parameters )
      : m_activeAttributesCount(0)
      , m_activeAttributesMask(0)
      , m_shaders( shaders )
    {
#if !defined(NDEBUG)
      std::set<GLenum> types;
      for ( std::vector<SmartShader>::const_iterator it = m_shaders.begin() ; it != m_shaders.end() ; ++it )
      {
        DP_ASSERT( *it && types.insert( (*it)->getType() ).second );
      }
#endif

      GLuint id = glCreateProgram();
      setGLId( id );

      DP_ASSERT( glIsProgram( id ) && "failed to create program" );

      glProgramParameteri( id, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, parameters.m_binaryRetrievableHint );
      glProgramParameteri( id, GL_PROGRAM_SEPARABLE, parameters.m_separable );

      for ( std::vector<SmartShader>::const_iterator it = m_shaders.begin() ; it != m_shaders.end() ; ++it )
      {
        glAttachShader( id, (*it)->getGLId() );
      }
      glLinkProgram( id );

      GLint result;
      glGetProgramiv( id, GL_LINK_STATUS, &result );
      if ( !result )
      {
        GLint errorLen;
        glGetProgramiv( id, GL_INFO_LOG_LENGTH, &errorLen );

        std::string buffer;
        buffer.resize( errorLen, 0 );
        glGetProgramInfoLog( id, errorLen, NULL, &buffer[0] );

        std::ostringstream error;
        error << "failed to link program: " << std::endl << buffer << std::endl;
        throw std::runtime_error(error.str().c_str());
      }

      GLint activeUniformMaxLength = 0;
      glGetProgramiv( id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformMaxLength );
      std::vector<char> name( activeUniformMaxLength );

      GLint activeUniformsCount = 0;
      glGetProgramiv( id, GL_ACTIVE_UNIFORMS, &activeUniformsCount );
      m_uniforms.resize( activeUniformsCount );

      glUseProgram( id );
      for ( GLint i=0 ; i<activeUniformsCount ; i++ )
      {
        glGetActiveUniform( id, i, activeUniformMaxLength, nullptr, &m_uniforms[i].size, &m_uniforms[i].type, name.data() );
        m_uniforms[i].name = name.data();
        m_uniforms[i].location = glGetUniformLocation( id, m_uniforms[i].name.data() );

        if ( isSamplerType( m_uniforms[i].type ) )
        {
          DP_ASSERT( m_uniforms[i].size == 1 );
          glUniform1i( m_uniforms[i].location, dp::util::checked_cast<GLint>(m_samplerUniforms.size() ) );
          m_samplerUniforms.push_back( i );
        }
        else if ( isImageType( m_uniforms[i].type ) )
        {
          DP_ASSERT( m_uniforms[i].size == 1 );
          glUniform1i( m_uniforms[i].location, dp::util::checked_cast<GLint>(m_imageUniforms.size()) );
          m_imageUniforms.push_back( ImageData() );
          m_imageUniforms.back().index = i;
        }
      }
      glUseProgram( 0 );

      // build mask of active vertex attributes
      GLint activeAttributeMaxLength;
      glGetProgramiv( id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttributeMaxLength );
      name.resize( activeAttributeMaxLength );

      GLint activeAttributesCount;
      glGetProgramiv( id, GL_ACTIVE_ATTRIBUTES, &activeAttributesCount );

      // the driver reports 1 attribute while activeAttributeMaxLength is 0.
      // since attributes always have names? something strange is going on.
      if ( activeAttributeMaxLength == 0 )
      {
        //DP_ASSERT( false );
        activeAttributesCount = 0;
      }

      m_activeAttributesCount = activeAttributesCount;
      for ( GLint i=0 ; i<activeAttributesCount ; i++ )
      {
        GLint size;
        GLenum type;
        glGetActiveAttrib( id, i, activeAttributeMaxLength, nullptr, &size, &type, &name[0] );
        m_activeAttributesMask |= 1 << glGetAttribLocation( id, &name[0] );
      }
    }
예제 #14
0
 void GroupDataBufferedCombined::useContainers( dp::rix::core::RenderGroupSharedHandle const & renderGroup )
 {
   DP_ASSERT( dp::rix::core::handleIsTypeOf<BufferManagerImpl>( m_groupSpecInfo->m_bufferManager.get() ) );
   BufferManagerImpl* bufferManager = dp::rix::core::handleCast<BufferManagerImpl>(m_groupSpecInfo->m_bufferManager.get());
   bufferManager->useContainers( renderGroup, m_allocation.get() );
 }
예제 #15
0
 void ParameterntBuffer<n, T>::doUpdateConverted( void const* /*convertedData*/ ) const
 {
   DP_ASSERT( !"not supported");
 }
예제 #16
0
      void SceneTree::updateTransformTree( dp::sg::ui::ViewStateSharedPtr const& vs )
      {
        //
        // first step: update node local information
        // 

        // update dirty transforms from transform observer
        {
          const TransformObserver::DirtyPayloads& cd = m_transformObserver->getDirtyPayloads();

          TransformObserver::DirtyPayloads::const_iterator it, it_end = cd.end();
          for( it = cd.begin(); it != it_end; ++it )
          {
            TransformTreeIndex index = (*it)->m_index;
            TransformTreeNode& node = m_transformTree[index];
            DP_ASSERT( node.m_transform != nullptr );

            const Trafo& t = node.m_transform->getTrafo();
            node.m_localMatrix = t.getMatrix();

            const Vec3f& s( t.getScaling() );
            node.setLocalBits( TransformTreeNode::ISMIRRORTRANSFORM, s[0]*s[1]*s[2] < 0.0f );

            m_transformTree.markDirty( index, TransformTreeNode::DEFAULT_DIRTY );

            // mark the transform's corresponding object tree node's bounding volume dirty
            DP_ASSERT( node.m_objectTreeIndex != ~0 );

            (*it)->m_dirty = false;
          }
          m_transformObserver->clearDirtyPayloads();
        }

        // update dynamic transforms
        {
          TransformTreeIndexSet::const_iterator it, it_end = m_dynamicTransformIndices.end();
          for( it=m_dynamicTransformIndices.begin(); it!=it_end; ++it )
          {
            TransformTreeIndex index = *it;
            TransformTreeNode& node = m_transformTree[index];

            if( node.m_transform )
            {
              Trafo t = node.m_transform->getTrafo();
              node.m_localMatrix = t.getMatrix();

              const Vec3f& s( t.getScaling() );
              node.setLocalBits( TransformTreeNode::ISMIRRORTRANSFORM, s[0]*s[1]*s[2] < 0.0f );
            }
            m_transformTree.markDirty( index, TransformTreeNode::DEFAULT_DIRTY );
          }
        }

        //
        // second step: update resulting node-world information
        // 

        m_changedTransforms.clear();
        UpdateTransformVisitor visitor( m_transformTree, *this, vs->getCamera(), m_changedTransforms );
        PreOrderTreeTraverser<TransformTree, UpdateTransformVisitor> traverser;

        traverser.processDirtyList( m_transformTree, visitor, TransformTreeNode::DEFAULT_DIRTY);
        m_transformTree.m_dirtyObjects.clear();
      }
 void *ParameterGroupDataPrivate::getValuePointer( dp::fx::ParameterGroupSpec::iterator it )
 {
   DP_ASSERT( it != m_parameterGroupSpec->endParameterSpecs() );
   return &m_data[it->second];
 }
예제 #18
0
 void SceneTree::drawableInstanceUpdate( ObjectTreeIndex index )
 {
   DP_ASSERT( m_objectTree[index].m_isDrawable );
   notify( EventObject( index, m_objectTree[index], EventObject::Changed) );
 }
예제 #19
0
    HGLRC RenderContext::createContext( HDC hdc, HGLRC shareContext )
    {
      HGLRC currentContext = wglGetCurrentContext();
      HDC currentDC = wglGetCurrentDC();

      HGLRC context = wglCreateContext( hdc );
      wglMakeCurrent( hdc, context );

      PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
      if ( context && wglGetExtensionsStringARB )
      {
        bool arbCreateContextSupported = false;
        std::istringstream is( wglGetExtensionsStringARB( hdc ) );
        while ( !is.eof() && !arbCreateContextSupported )
        {
          std::string extension;
          is >> extension;
          arbCreateContextSupported = extension == "WGL_ARB_create_context";
        }

        if ( arbCreateContextSupported )
        {

  #ifndef GLAPIENTRY
  #  if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)  /* Mimic <wglext.h> */
  #   define GLAPIENTRY __stdcall
  #  else
  #   define GLAPIENTRY
  #  endif
  #endif

          typedef HGLRC (GLAPIENTRY *PFNWGLCREATECONTEXTATTRIBSARB)(HDC hDC, HGLRC hShareContext, const int *attribList);
          PFNWGLCREATECONTEXTATTRIBSARB wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARB)wglGetProcAddress("wglCreateContextAttribsARB");
          DP_ASSERT( wglCreateContextAttribsARB );

  #if defined(NDEBUG)
          int attribs[] =
          {
            //WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
            0
          };
  #else
          int attribs[] =
          {
            //WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB | WGL_CONTEXT_DEBUG_BIT_ARB, // WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB not running on AMD
            WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
            0
          };
  #endif

          HGLRC hglrcNew = wglCreateContextAttribsARB( hdc, shareContext, attribs );
          wglMakeCurrent( NULL, NULL );
          wglDeleteContext( context );

          context = hglrcNew;
          DP_ASSERT( context );

          if ( shareContext )
          {
  #if 0
            nvgl::WGLNotifyShareLists( shareContext, context );
  #endif
          }
        }
        else
        {
          DP_ASSERT( false );
  #if 0
          nvgl::WGLAttachContext( hdc, context );
          // context construction failed
          if ( context && shareContext && !nvgl::WGLShareLists( shareContext, context) )
          {
            // Sharelists failed. Delete context and set return value to 0.
            nvgl::WGLDeleteContext( context );
            context = 0;
          }
  #endif
        }
      }
예제 #20
0
      void SceneTree::removeObjectTreeIndex( ObjectTreeIndex index )
      {
        // initialize the trafo index for the trafo search with the parent's trafo index
        DP_ASSERT( index != m_objectTreeSentinel && "cannot remove root node" );
        TransformTreeIndex trafoIndex = m_objectTree[m_objectTree[index].m_parentIndex].m_transformIndex;

        // vector for stack-simulation to eliminate overhead of std::stack
        m_objectIndexStack.resize( m_objectTree.size() );
        size_t begin = 0;
        size_t end   = 0;

        // start traversal at index
        m_objectIndexStack[end] = index;
        ++end;

        while( begin != end ) 
        {
          ObjectTreeIndex currentIndex = m_objectIndexStack[begin];
          ++begin;
          ObjectTreeNode& current = m_objectTree[currentIndex];

          if ( isPtrTo<LightSource>( m_objectTree[currentIndex].m_object ) )
          {
            DP_VERIFY( m_lightSources.erase( currentIndex ) == 1 );
          }

          drawableInstanceRemove( currentIndex );

          current.m_clipPlaneGroup.reset();

          // detach current index from object observer
          m_objectObserver->detach( currentIndex );

          // TODO: add observer flag to specify which observers must be detached?
          std::map< ObjectTreeIndex, SwitchWeakPtr >::iterator itSwitch = m_objectTree.m_switchNodes.find( currentIndex );
          if ( itSwitch != m_objectTree.m_switchNodes.end() )
          {
            m_switchObserver->detach( currentIndex );
            m_objectTree.m_switchNodes.erase( itSwitch );
          }

          std::map< ObjectTreeIndex, LODWeakPtr >::iterator itLod = m_objectTree.m_LODs.find( currentIndex );
          if ( itLod != m_objectTree.m_LODs.end() )
          {
            m_objectTree.m_LODs.erase( itLod );
          }

          // check if a transform needs to be removed
          DP_ASSERT( current.m_parentIndex != ~0 );
          const ObjectTreeNode& curParent = m_objectTree[current.m_parentIndex];
          // only remove the topmost transforms below or at index (so transforms are only removed once)
          if(  current.m_transformIndex != curParent.m_transformIndex // transform indices differ
            && curParent.m_transformIndex == trafoIndex )             // parent index is parent index of removal root
          {
            removeTransformTreeIndex( current.m_transformIndex );
          }

          current.m_object = nullptr;

          // insert all children into stack for further traversal
          ObjectTreeIndex child = current.m_firstChild;
          while( child != ~0 )
          {
            m_objectIndexStack[end] = child;
            ++end;
            child = m_objectTree[child].m_nextSibling;
          }
        }

        // delete the node and its children from the object tree
        m_objectTree.deleteNode( index );
      }
예제 #21
0
      void SceneTree::updateObjectTree(dp::sg::core::CameraSharedPtr const& camera, float lodRangeScale)
      {
        //
        // first step: update node-local information
        //

        // update dirty object hints & masks
        {
          ObjectObserver::NewCacheData cd;
          m_objectObserver->popNewCacheData( cd );

          ObjectObserver::NewCacheData::const_iterator it, it_end = cd.end();
          for( it=cd.begin(); it!=it_end; ++it )
          {
            ObjectTreeNode& node = m_objectTree[ it->first ];
            node.m_localHints = it->second.m_hints;
            node.m_localMask = it->second.m_mask;

            m_objectTree.markDirty( it->first, ObjectTreeNode::DEFAULT_DIRTY );
          }
        }

        // update dirty switch information
        ObjectTreeIndexSet dirtySwitches;
        m_switchObserver->popDirtySwitches( dirtySwitches );
        if( !dirtySwitches.empty() )
        {
          ObjectTreeIndexSet::iterator it, it_end = dirtySwitches.end();
          for( it=dirtySwitches.begin(); it!=it_end; ++it )
          {
            ObjectTreeIndex index = *it;

            SwitchSharedPtr ssp = m_objectTree.m_switchNodes[ index ].lock();
            DP_ASSERT( ssp );

            ObjectTreeIndex childIndex = m_objectTree[index].m_firstChild;
            // counter for the i-th child
            size_t i = 0;

            while( childIndex != ~0 )
            {
              ObjectTreeNode& childNode = m_objectTree[childIndex];
              DP_ASSERT( childNode.m_parentIndex == index );

              bool newActive = ssp->isActive( dp::checked_cast<unsigned int>(i) );
              if ( childNode.m_localActive != newActive )
              {
                childNode.m_localActive = newActive;
                m_objectTree.markDirty( childIndex, ObjectTreeNode::DEFAULT_DIRTY );
              }

              childIndex = childNode.m_nextSibling;
              ++i;
            }
          }
        }

        // update all lods
        if( !m_objectTree.m_LODs.empty() )
        {
          const Mat44f& worldToView = camera->getWorldToViewMatrix();

          std::map< ObjectTreeIndex, LODWeakPtr >::iterator it, it_end = m_objectTree.m_LODs.end();
          for( it = m_objectTree.m_LODs.begin(); it != it_end; ++it )
          {
            ObjectTreeIndex index = it->first;
            const ObjectTreeNode& node = m_objectTree[ index ];

            Mat44f const & modelToWorld = m_transformTree.getWorldMatrix(node.m_transform);
            const Mat44f modelToView = modelToWorld * worldToView;
            ObjectTreeIndex activeIndex = it->second.lock()->getLODToUse( modelToView, lodRangeScale );

            ObjectTreeIndex childIndex = m_objectTree[index].m_firstChild;
            // counter for the i-th child
            size_t i = 0;

            while( childIndex != ~0 )
            {
              ObjectTreeNode& childNode = m_objectTree[childIndex];
              DP_ASSERT( childNode.m_parentIndex == index );

              bool newActive = activeIndex == i;
              if ( childNode.m_localActive != newActive )
              {
                childNode.m_localActive = newActive;
                m_objectTree.markDirty( childIndex, ObjectTreeNode::DEFAULT_DIRTY );
              }

              childIndex = childNode.m_nextSibling;
              ++i;
            }
          }
        }

        //
        // second step: update resulting node-world information
        //

        UpdateObjectVisitor objectVisitor( m_objectTree, this );
        PreOrderTreeTraverser<ObjectTree, UpdateObjectVisitor> objectTraverser;

        objectTraverser.processDirtyList( m_objectTree, objectVisitor, ObjectTreeNode::DEFAULT_DIRTY );
        m_objectTree.m_dirtyObjects.clear();
      }
 dp::fx::ParameterGroupLayout::SmartParameterInfo createParameterInfoShaderBufferLoad( unsigned int type, size_t& offset, size_t arraySize )
 {
   switch (type)
   {
     case PT_FLOAT32                : return new ParameterInfoVectorConversion<dp::util::Float32, dp::util::Float32, 1, 1>( offset, arraySize );
     case PT_FLOAT32 | PT_VECTOR2   : return new ParameterInfoVectorConversion<dp::util::Float32, dp::util::Float32, 2, 2>( offset, arraySize );
     case PT_FLOAT32 | PT_VECTOR3   : return new ParameterInfoVectorConversion<dp::util::Float32, dp::util::Float32, 3, 4>( offset, arraySize );
     case PT_FLOAT32 | PT_VECTOR4   : return new ParameterInfoVectorConversion<dp::util::Float32, dp::util::Float32, 4, 4>( offset, arraySize );
     case PT_INT8                   : return new ParameterInfoVectorConversion<dp::util::Int8   , dp::util::Int32  , 1, 1>( offset, arraySize );
     case PT_INT8 | PT_VECTOR2      : return new ParameterInfoVectorConversion<dp::util::Int8   , dp::util::Int32  , 2, 2>( offset, arraySize );
     case PT_INT8 | PT_VECTOR3      : return new ParameterInfoVectorConversion<dp::util::Int8   , dp::util::Int32  , 3, 4>( offset, arraySize );
     case PT_INT8 | PT_VECTOR4      : return new ParameterInfoVectorConversion<dp::util::Int8   , dp::util::Int32  , 4, 4>( offset, arraySize );
     case PT_INT16                  : return new ParameterInfoVectorConversion<dp::util::Int16  , dp::util::Int32  , 1, 1>( offset, arraySize );
     case PT_INT16 | PT_VECTOR2     : return new ParameterInfoVectorConversion<dp::util::Int16  , dp::util::Int32  , 2, 2>( offset, arraySize );
     case PT_INT16 | PT_VECTOR3     : return new ParameterInfoVectorConversion<dp::util::Int16  , dp::util::Int32  , 3, 4>( offset, arraySize );
     case PT_INT16 | PT_VECTOR4     : return new ParameterInfoVectorConversion<dp::util::Int16  , dp::util::Int32  , 4, 4>( offset, arraySize );
     case PT_INT32                  : return new ParameterInfoVectorConversion<dp::util::Int32  , dp::util::Int32  , 1, 1>( offset, arraySize );
     case PT_INT32 | PT_VECTOR2     : return new ParameterInfoVectorConversion<dp::util::Int32  , dp::util::Int32  , 2, 2>( offset, arraySize );
     case PT_INT32 | PT_VECTOR3     : return new ParameterInfoVectorConversion<dp::util::Int32  , dp::util::Int32  , 3, 4>( offset, arraySize );
     case PT_INT32 | PT_VECTOR4     : return new ParameterInfoVectorConversion<dp::util::Int32  , dp::util::Int32  , 4, 4>( offset, arraySize );
     case PT_INT64                  : return new ParameterInfoVectorConversion<dp::util::Int64  , dp::util::Int64  , 1, 1>( offset, arraySize );
     case PT_INT64 | PT_VECTOR2     : return new ParameterInfoVectorConversion<dp::util::Int64  , dp::util::Int64  , 2, 2>( offset, arraySize );
     case PT_INT64 | PT_VECTOR3     : return new ParameterInfoVectorConversion<dp::util::Int64  , dp::util::Int64  , 3, 4>( offset, arraySize );
     case PT_INT64 | PT_VECTOR4     : return new ParameterInfoVectorConversion<dp::util::Int64  , dp::util::Int64  , 4, 4>( offset, arraySize );
     case PT_UINT8                  : return new ParameterInfoVectorConversion<dp::util::Uint8  , dp::util::Uint32 , 1, 1>( offset, arraySize );
     case PT_UINT8 | PT_VECTOR2     : return new ParameterInfoVectorConversion<dp::util::Uint8  , dp::util::Uint32 , 2, 2>( offset, arraySize );
     case PT_UINT8 | PT_VECTOR3     : return new ParameterInfoVectorConversion<dp::util::Uint8  , dp::util::Uint32 , 3, 4>( offset, arraySize );
     case PT_UINT8 | PT_VECTOR4     : return new ParameterInfoVectorConversion<dp::util::Uint8  , dp::util::Uint32 , 4, 4>( offset, arraySize );
     case PT_UINT16                 : return new ParameterInfoVectorConversion<dp::util::Uint16 , dp::util::Uint32 , 1, 1>( offset, arraySize );
     case PT_UINT16 | PT_VECTOR2    : return new ParameterInfoVectorConversion<dp::util::Uint16 , dp::util::Uint32 , 2, 2>( offset, arraySize );
     case PT_UINT16 | PT_VECTOR3    : return new ParameterInfoVectorConversion<dp::util::Uint16 , dp::util::Uint32 , 3, 4>( offset, arraySize );
     case PT_UINT16 | PT_VECTOR4    : return new ParameterInfoVectorConversion<dp::util::Uint16 , dp::util::Uint32 , 4, 4>( offset, arraySize );
     case PT_UINT32                 : return new ParameterInfoVectorConversion<dp::util::Uint32 , dp::util::Uint32 , 1, 1>( offset, arraySize );
     case PT_UINT32 | PT_VECTOR2    : return new ParameterInfoVectorConversion<dp::util::Uint32 , dp::util::Uint32 , 2, 2>( offset, arraySize );
     case PT_UINT32 | PT_VECTOR3    : return new ParameterInfoVectorConversion<dp::util::Uint32 , dp::util::Uint32 , 3, 4>( offset, arraySize );
     case PT_UINT32 | PT_VECTOR4    : return new ParameterInfoVectorConversion<dp::util::Uint32 , dp::util::Uint32 , 4, 4>( offset, arraySize );
     case PT_UINT64                 : return new ParameterInfoVectorConversion<dp::util::Uint64 , dp::util::Uint64 , 1, 1>( offset, arraySize );
     case PT_UINT64 | PT_VECTOR2    : return new ParameterInfoVectorConversion<dp::util::Uint64 , dp::util::Uint64 , 2, 2>( offset, arraySize );
     case PT_UINT64 | PT_VECTOR3    : return new ParameterInfoVectorConversion<dp::util::Uint64 , dp::util::Uint64 , 3, 4>( offset, arraySize );
     case PT_UINT64 | PT_VECTOR4    : return new ParameterInfoVectorConversion<dp::util::Uint64 , dp::util::Uint64 , 4, 4>( offset, arraySize );
     case PT_BOOL                   : return new ParameterInfoVectorConversion<dp::util::Bool   , dp::util::Uint32 , 1, 1>( offset, arraySize );
     case PT_BOOL | PT_VECTOR2      : return new ParameterInfoVectorConversion<dp::util::Bool   , dp::util::Uint32 , 2, 2>( offset, arraySize );
     case PT_BOOL | PT_VECTOR3      : return new ParameterInfoVectorConversion<dp::util::Bool   , dp::util::Uint32 , 3, 4>( offset, arraySize );
     case PT_BOOL | PT_VECTOR4      : return new ParameterInfoVectorConversion<dp::util::Bool   , dp::util::Uint32 , 4, 4>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX2x2 : return new ParameterInfoMatrixConversion<dp::util::Float32, dp::util::Float32, 2, 2, 2>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX2x3 : return new ParameterInfoMatrixConversion<dp::util::Float32, dp::util::Float32, 3, 4, 2>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX2x4 : return new ParameterInfoMatrixConversion<dp::util::Float32, dp::util::Float32, 4, 4, 2>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX3x2 : return new ParameterInfoMatrixConversion<dp::util::Float32, dp::util::Float32, 2, 2, 3>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX3x3 : return new ParameterInfoMatrixConversion<dp::util::Float32, dp::util::Float32, 3, 4, 3>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX3x4 : return new ParameterInfoMatrixConversion<dp::util::Float32, dp::util::Float32, 4, 4, 3>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX4x2 : return new ParameterInfoMatrixConversion<dp::util::Float32, dp::util::Float32, 2, 2, 4>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX4x3 : return new ParameterInfoMatrixConversion<dp::util::Float32, dp::util::Float32, 3, 4, 4>( offset, arraySize );
     case PT_FLOAT32 | PT_MATRIX4x4 : return new ParameterInfoMatrixConversion<dp::util::Float32, dp::util::Float32, 4, 4, 4>( offset, arraySize );
     case PT_FLOAT64                : return new ParameterInfoVectorConversion<dp::util::Float64, dp::util::Float64, 1, 1>( offset, arraySize );
     case PT_FLOAT64 | PT_VECTOR2   : return new ParameterInfoVectorConversion<dp::util::Float64, dp::util::Float64, 2, 2>( offset, arraySize );
     case PT_FLOAT64 | PT_VECTOR3   : return new ParameterInfoVectorConversion<dp::util::Float64, dp::util::Float64, 3, 4>( offset, arraySize );
     case PT_FLOAT64 | PT_VECTOR4   : return new ParameterInfoVectorConversion<dp::util::Float64, dp::util::Float64, 4, 4>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX2x2 : return new ParameterInfoMatrixConversion<dp::util::Float64, dp::util::Float64, 2, 2, 2>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX2x3 : return new ParameterInfoMatrixConversion<dp::util::Float64, dp::util::Float64, 3, 4, 2>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX2x4 : return new ParameterInfoMatrixConversion<dp::util::Float64, dp::util::Float64, 4, 4, 2>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX3x2 : return new ParameterInfoMatrixConversion<dp::util::Float64, dp::util::Float64, 2, 2, 3>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX3x3 : return new ParameterInfoMatrixConversion<dp::util::Float64, dp::util::Float64, 3, 4, 3>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX3x4 : return new ParameterInfoMatrixConversion<dp::util::Float64, dp::util::Float64, 4, 4, 3>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX4x2 : return new ParameterInfoMatrixConversion<dp::util::Float64, dp::util::Float64, 2, 2, 4>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX4x3 : return new ParameterInfoMatrixConversion<dp::util::Float64, dp::util::Float64, 3, 4, 4>( offset, arraySize );
     case PT_FLOAT64 | PT_MATRIX4x4 : return new ParameterInfoMatrixConversion<dp::util::Float64, dp::util::Float64, 4, 4, 4>( offset, arraySize );
     case PT_ENUM                   : return new ParameterInfoVectorConversion<dp::fx::EnumSpec::StorageType, int, 1, 1>( offset, arraySize );
     default:
       DP_ASSERT( !"Unsupported parametertype" );
       return nullptr;
   }
 }
예제 #23
0
      void SceneTree::removeObjectTreeIndex( ObjectTreeIndex index )
      {
        // initialize the trafo index for the trafo search with the parent's trafo index
        DP_ASSERT( index != m_objectTreeSentinel && "cannot remove root node" );

        // vector for stack-simulation to eliminate overhead of std::stack
        m_objectIndexStack.resize( m_objectTree.size() );
        size_t begin = 0;
        size_t end   = 0;

        // start traversal at index
        m_objectIndexStack[end] = index;
        ++end;

        while( begin != end )
        {
          ObjectTreeIndex currentIndex = m_objectIndexStack[begin];
          ++begin;
          ObjectTreeNode& current = m_objectTree[currentIndex];

          if ( std::dynamic_pointer_cast<dp::sg::core::LightSource>(m_objectTree[currentIndex].m_object) )
          {
            DP_VERIFY( m_lightSources.erase( currentIndex ) == 1 );
          }

          if ( m_objectTree[currentIndex].m_isDrawable )
          {
            notify( Event( currentIndex, m_objectTree[currentIndex], Event::Type::REMOVED) );
            m_objectTree[index].m_isDrawable = false;
          }

          current.m_clipPlaneGroup.reset();

          // detach current index from object observer
          m_objectObserver->detach( currentIndex );

          // TODO: add observer flag to specify which observers must be detached?
          std::map< ObjectTreeIndex, SwitchWeakPtr >::iterator itSwitch = m_objectTree.m_switchNodes.find( currentIndex );
          if ( itSwitch != m_objectTree.m_switchNodes.end() )
          {
            m_switchObserver->detach( currentIndex );
            m_objectTree.m_switchNodes.erase( itSwitch );
          }

          std::map< ObjectTreeIndex, LODWeakPtr >::iterator itLod = m_objectTree.m_LODs.find( currentIndex );
          if ( itLod != m_objectTree.m_LODs.end() )
          {
            m_objectTree.m_LODs.erase( itLod );
          }

          // check if a transform needs to be removed
          DP_ASSERT( current.m_parentIndex != ~0 );
          const ObjectTreeNode& curParent = m_objectTree[current.m_parentIndex];

          // only remove the topmost transforms below or at index (so transforms are only removed once)
          if (current.m_isTransform)
          {
            m_transformTree.removeTransform(current.m_transform);
          }
          else if (current.m_isBillboard)
          {
            m_transformTree.removeBillboard(current.m_transform);
          }

          current.m_object.reset();

          // insert all children into stack for further traversal
          ObjectTreeIndex child = current.m_firstChild;
          while( child != ~0 )
          {
            m_objectIndexStack[end] = child;
            ++end;
            child = m_objectTree[child].m_nextSibling;
          }
        }

        // delete the node and its children from the object tree
        m_objectTree.deleteNode( index );
      }
예제 #24
0
 void ParameterntBufferConversion<n, T, SourceType>::update(const void * /*data*/)
 {
   DP_ASSERT( !"not supported");
 }
예제 #25
0
void CameraAnimator::initCameraMoveToLight( const dp::sg::core::LightSourceWeakPtr & targetLight )   // should be a dp::sg::core::LightSourceWeakPtr
{
    DP_ASSERT( m_viewState->getCamera().isPtrTo<dp::sg::core::FrustumCamera>() );
    m_cameraMoveStart = m_viewState->getCamera().clone().staticCast<dp::sg::core::FrustumCamera>();

    m_cameraMoveTarget = m_cameraMoveStart.clone();

    dp::sg::core::LightSourceSharedPtr lsh( targetLight->getSharedPtr<dp::sg::core::LightSource>() );
    {
        DP_ASSERT( lsh->getLightEffect() );
        dp::sg::core::EffectDataSharedPtr const& le = lsh->getLightEffect();
        const dp::fx::SmartEffectSpec & es = le->getEffectSpec();
        for ( dp::fx::EffectSpec::iterator it = es->beginParameterGroupSpecs() ; it != es->endParameterGroupSpecs() ; ++it )
        {
            const dp::sg::core::ParameterGroupDataSharedPtr & parameterGroupData = le->getParameterGroupData( it );
            if ( parameterGroupData )
            {
                std::string name = (*it)->getName();
                if ( ( name == "standardDirectedLightParameters" )
                        || ( name == "standardPointLightParameters" )
                        || ( name == "standardSpotLightParameters" ) )
                {
                    const dp::fx::SmartParameterGroupSpec & pgs = parameterGroupData->getParameterGroupSpec();
                    if ( name == "standardDirectedLightParameters" )
                    {
                        m_cameraMoveTarget->setDirection( parameterGroupData->getParameter<dp::math::Vec3f>( pgs->findParameterSpec( "direction" ) ) );
                    }
                    else if ( name == "standardPointLightParameters" )
                    {
                        dp::math::Vec3f position = parameterGroupData->getParameter<dp::math::Vec3f>( pgs->findParameterSpec( "position" ) );
                        m_cameraMoveTarget->setPosition( position );

                        // point us in the direction of the scene center..
                        if ( m_viewState->getScene()->getRootNode() )
                        {
                            dp::math::Vec3f forward = m_viewState->getScene()->getRootNode()->getBoundingSphere().getCenter() - position;
                            dp::math::Vec3f worldup( 0.f, 1.f, 0.f ); //pc->getUpVector();

                            dp::math::Vec3f right = forward ^ worldup;
                            dp::math::Vec3f up = right ^ forward;

                            normalize( forward );
                            normalize( right );
                            normalize( up );

                            // X east, Y up, -Z north
                            dp::math::Mat33f lookat( dp::util::makeArray(   right[0],    right[1],    right[2],
                                                     up[0],       up[1],       up[2],
                                                     -forward[0], -forward[1], -forward[2] ) );

                            dp::math::Quatf ori( lookat );
                            m_cameraMoveTarget->setOrientation( ori );
                        }
                    }
                    else
                    {
                        m_cameraMoveTarget->setPosition( parameterGroupData->getParameter<dp::math::Vec3f>( pgs->findParameterSpec( "position" ) ) );
                        m_cameraMoveTarget->setDirection( parameterGroupData->getParameter<dp::math::Vec3f>( pgs->findParameterSpec( "direction" ) ) );
                    }
                    break;
                }
            }
        }
    }

    cameraMoveDurationFactor( determineDurationFactor() );
}
예제 #26
0
 void ParameterntBufferConversion<n, T, SourceType>::doUpdateConverted( void const * /*convertedData*/ ) const
 {
   DP_ASSERT( !"not supported");
 }
        bool  TrackballTransformManipulator::pan()
        {
          int dxScreen = getCurrentX() - getLastX();
          int dyScreen = getLastY() - getCurrentY();
          if ( dxScreen || dyScreen )
          {
            DP_ASSERT( getViewState()->getCamera().isPtrTo<FrustumCamera>() );
            TransformSharedPtr transform = m_transformPath->getTail().staticCast<Transform>();
            FrustumCameraSharedPtr const& camera = getViewState()->getCamera().staticCast<FrustumCamera>();
            if ( camera && transform )
            {
              unsigned int rtWidth = getRenderTarget()->getWidth();
              unsigned int rtHeight = getRenderTarget()->getHeight();
              Vec2f  camWinSize = camera->getWindowSize();
              if (    ( 0 < rtHeight ) && ( 0 < rtWidth )
                  &&  ( FLT_EPSILON < fabs( camWinSize[0] ) )
                  &&  ( FLT_EPSILON < fabs( camWinSize[1] ) ) )
              {
                //  get all the matrices needed here
                Mat44f m2w, w2m;
                m_transformPath->getModelToWorldMatrix(m2w, w2m); // model->world and world->model
                Mat44f w2v = camera->getWorldToViewMatrix();   // world->view
                Mat44f v2w = camera->getViewToWorldMatrix();   // view->world

                //  center of the object in view coordinates
                Vec4f center = Vec4f( transform->getBoundingSphere().getCenter(), 1.0f ) * m2w * w2v;

                //  window size at distance of the center of the object
                Vec2f centerWindowSize = - center[2] / getViewState()->getTargetDistance() * camWinSize;

                checkLockAxis(dxScreen, dyScreen);
                if ( m_activeLockAxis[static_cast<size_t>(Axis::X)] )
                {
                  if ( dxScreen != 0 )
                  {
                    dyScreen = 0;
                  }
                  else 
                  {
                    return false;
                  }
                }
                else if ( m_activeLockAxis[static_cast<size_t>(Axis::Y)] )
                {
                  if ( dyScreen != 0)
                  {
                    dxScreen = 0;
                  }
                  else
                  {
                    return false;
                  }
                }

                //  delta in model coordinates
                Vec4f viewCenter( centerWindowSize[0] * dxScreen / rtWidth
                                , centerWindowSize[1] * dyScreen / rtHeight, 0.f, 0.f );
                Vec4f modelDelta = viewCenter * v2w * w2m;
        
                // add the delta to the translation of the transform
                Trafo trafo = transform->getTrafo();
                trafo.setTranslation( trafo.getTranslation() + Vec3f( modelDelta ) );
                transform->setTrafo( trafo );

                return true;  
              }
            }
          }
          return false;
        }
예제 #28
0
 void ParameterntBuffer<n, T>::update(const void * /*data*/ )
 {
   DP_ASSERT( !"not supported");
 }
예제 #29
0
파일: Event.cpp 프로젝트: raedwulf/pipeline
 Event::Event( unsigned int flags )
   : m_flags( flags )
 {
   DP_ASSERT( ( m_flags & ~( cudaEventDefault | cudaEventBlockingSync | cudaEventDisableTiming | cudaEventInterprocess ) ) == 0 )
   CUDA_VERIFY( cudaEventCreateWithFlags( &m_event, m_flags ) );
 }
예제 #30
0
    std::vector<uint8_t> RenderTarget::getImagePixels( GLenum mode, dp::PixelFormat pixelFormat, dp::DataType pixelDataType )
    {
      // FIXME use C++ object for current/noncurrent for exception safety
      makeCurrent();

      size_t components = 0;
      size_t bytesPerComponent = 0;

      // set up alignments
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
      glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
      glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
      glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
      glPixelStorei(GL_PACK_ALIGNMENT, 1);
      glPixelStorei(GL_PACK_ROW_LENGTH, 0);
      glPixelStorei(GL_PACK_SKIP_ROWS, 0);
      glPixelStorei(GL_PACK_SKIP_PIXELS, 0);

      // determine OpenGL format
      GLenum format = ~0;
      switch (pixelFormat)
      {
      case dp::PixelFormat::RGB:
        format = GL_RGB;
        components = 3;
        break;
      case dp::PixelFormat::RGBA:
        format = GL_RGBA;
        components = 4;
        break;
      case dp::PixelFormat::BGR:
        format = GL_BGR;
        components = 3;
        break;
      case dp::PixelFormat::BGRA:
        format = GL_BGRA;
        components = 4;
        break;
      case dp::PixelFormat::LUMINANCE:
        format = GL_LUMINANCE;
        components = 1;
        break;
      case dp::PixelFormat::ALPHA:
        format = GL_ALPHA;
        components = 1;
        break;
      case dp::PixelFormat::LUMINANCE_ALPHA:
        format = GL_LUMINANCE_ALPHA;
        components = 2;
        break;
      case dp::PixelFormat::DEPTH_COMPONENT:
        format = GL_DEPTH_COMPONENT;
        components = 1;
        break;
      case dp::PixelFormat::DEPTH_STENCIL:
        format = GL_DEPTH_STENCIL;
        components = 1;
        break;
      case dp::PixelFormat::STENCIL_INDEX:
        format = GL_STENCIL_INDEX;
        components = 1;
        break;
      default:
        DP_ASSERT(0 && "unsupported PixelFormat");
      };

      GLenum dataType = ~0;
      switch (pixelDataType)
      {
      case dp::DataType::INT_8:
        dataType = GL_BYTE;
        bytesPerComponent = 1;
        break;
      case dp::DataType::UNSIGNED_INT_8:
        dataType = GL_UNSIGNED_BYTE;
        bytesPerComponent = 1;
        break;
      case dp::DataType::INT_16:
        dataType = GL_SHORT;
        bytesPerComponent = 2;
        break;
      case dp::DataType::UNSIGNED_INT_16:
        dataType = GL_UNSIGNED_SHORT;
        bytesPerComponent = 2;
        break;
      case dp::DataType::INT_32:
        dataType = GL_INT;
        bytesPerComponent = 4;
        break;
      case dp::DataType::UNSIGNED_INT_32:
        dataType = GL_UNSIGNED_INT;
        bytesPerComponent = 4;
        break;
      case dp::DataType::FLOAT_32:
        dataType = GL_FLOAT;
        bytesPerComponent = 4;
        break;
      case dp::DataType::FLOAT_16:
        dataType = GL_HALF_FLOAT;
        bytesPerComponent = 2;
        break;
      default:
        DP_ASSERT(0 && "unsupported PixelDataType");
      }

      size_t imageSizeInBytes = m_width * m_height * components * bytesPerComponent;
      std::vector<uint8_t> output(imageSizeInBytes);

      if ( imageSizeInBytes )
      {
        // read the pixels
        glWindowPos2i(0,0);
        glReadBuffer( mode );

        glReadPixels(0, 0, m_width, m_height, format, dataType, &output[0]);
      }

      makeNoncurrent();

      return output;
    }