Exemplo n.º 1
0
    bool loadTextureToGPU(const LODNode& lodNode, const DataSource& dataSource,
                          const TexturePool& texturePool,
                          const ConstDataObjectPtr& data) const
    {
#ifdef LIVRE_DEBUG_RENDERING
        std::cout << "Upload " << lodNode.getNodeId().getLevel() << ' '
                  << lodNode.getRelativePosition() << " to "
                  << _textureState.textureId << std::endl;
#endif
        const Vector3ui& overlap = dataSource.getVolumeInfo().overlap;
        const Vector3ui& voxSizeVec = lodNode.getBlockSize() + overlap * 2;
        _textureState.bind();

        glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, voxSizeVec[0], voxSizeVec[1],
                        voxSizeVec[2], texturePool.getFormat(),
                        texturePool.getTextureType(), data->getDataPtr());

        const GLenum glErr = glGetError();
        if (glErr != GL_NO_ERROR)
        {
            LBERROR << "Error loading the texture into GPU, error number : "
                    << glErr << std::endl;
            return false;
        }

        return true;
    }
Exemplo n.º 2
0
    void visit( const LODNode& lodNode, VisitState& state )
    {
        const Boxf& worldBox = lodNode.getWorldBox();
        if( !_frustum.isInFrustum( worldBox ) || _clipPlanes.isClipped( worldBox ))
        {
           state.setVisitChild( false );
           return;
        }

        Vector3f vmin, vmax;
        const Plane& nearPlane = _frustum.getNearPlane();

        worldBox.computeNearFar( nearPlane, vmin, vmax );

        Vector4f hVmin = vmin;
        hVmin[ 3 ] = 1.0f;

        Vector4f hVmax = vmax;
        hVmax[ 3 ] = 1.0f;

        // The bounding box intersects the plane
       if( _frustum.getNearPlane().dot( hVmin ) < 0 ||
           _frustum.getNearPlane().dot( hVmax ) < 0 )
       {
           // Where eye direction intersects with near plane
           vmin = _frustum.getEyePos() - _frustum.getViewDir() * _frustum.nearPlane();
       }

       const Vector3f& voxelBox = lodNode.getVoxelBox().getSize();
       const Vector3f& worldSpacePerVoxel = worldBox.getSize() / voxelBox;

       bool lodVisible = isLODVisible( vmin, worldSpacePerVoxel.find_min( ));

       const VolumeInformation& volInfo = _dataSource.getVolumeInfo();
       const uint32_t depth = volInfo.rootNode.getDepth();
       lodVisible = ( lodVisible && lodNode.getRefLevel() >= _minLOD )
                    || ( lodNode.getRefLevel() == _maxLOD )
                    || ( lodNode.getRefLevel() == depth - 1 );

       if( lodVisible )
           _visibles.push_back( lodNode.getNodeId( ));

       state.setVisitChild( !lodVisible );
    }
Exemplo n.º 3
0
    bool visit(const LODNode& lodNode)
    {
        const Boxf& worldBox = lodNode.getWorldBox();
        if (!_frustum.isInFrustum(worldBox) || _clipPlanes.isOutside(worldBox))
            return false;

        Vector3f vmin, vmax;
        const Plane& nearPlane = _frustum.getNearPlane();

        worldBox.computeNearFar(nearPlane, vmin, vmax);

        Vector4f hVmin = vmin;
        hVmin[3] = 1.0f;

        Vector4f hVmax = vmax;
        hVmax[3] = 1.0f;

        // The bounding box intersects the plane
        if (_frustum.getNearPlane().dot(hVmin) < 0 ||
            _frustum.getNearPlane().dot(hVmax) < 0)
        {
            // Where eye direction intersects with near plane
            vmin = _frustum.getEyePos() -
                   _frustum.getViewDir() * _frustum.nearPlane();
        }

        const Vector3f& voxelBox = lodNode.getVoxelBox().getSize();
        const Vector3f& worldSpacePerVoxel = worldBox.getSize() / voxelBox;
        const auto level = lodNode.getRefLevel();
        bool lodVisible = isLODVisible(vmin, worldSpacePerVoxel.find_min()) &&
                          level >= _minLOD;

        if (level == _maxLOD)
            lodVisible = true;

        if (lodVisible)
            _visibles.push_back(lodNode.getNodeId());

        return !lodVisible;
    }