01/24/12 15:34:02 (6 years ago)

Added support for using GL_UNPACK_ROW_LENGTH in conjunction with texture's + osg::Image via new RowLength?
parameter in osg::Image. To support this Image::setData(..) now has a new optional rowLength parameter which
defaults to 0, which provides the original behaviour, Image::setRowLength(int) and int Image::getRowLength() are also provided.

With the introduction of RowLength? support in osg::Image it is now possible to create a sub image where
the t size of the image are smaller than the row length, useful for when you have a large image on the CPU
and which to use a small portion of it on the GPU. However, when these sub images are created the data
within the image is no longer contiguous so data access can no longer assume that all the data is in
one block. The new method Image::isDataContiguous() enables the user to check whether the data is contiguous,
and if not one can either access the data row by row using Image::data(column,row,image) accessor, or use the
new Image::DataIterator? for stepping through each block on memory assocatied with the image.

To support the possibility of non contiguous osg::Image usage of image objects has had to be updated to
check DataContiguous? and handle the case or use access via the DataIerator? or by row by row. To achieve
this a relatively large number of files has had to be modified, in particular the texture classes and
image plugins that doing writing.

1 modified


  • OpenSceneGraph/trunk/examples/osgtexture2D/osgtexture2D.cpp

    r9636 r12912  
    537537    { 
     539#if 1         
     540        osg::ref_ptr<osg::Image> originalImage = osgDB::readImageFile("Images/dog_left_eye.jpg"); 
     542        osg::ref_ptr<osg::Image> subImage = new osg::Image; 
     543        subImage->setUserData(originalImage.get()); // attach the originalImage as user data to prevent it being deleted. 
     545        // now assign the appropriate portion data from the originalImage 
     546        subImage->setImage(originalImage->s()/2, originalImage->t()/2, originalImage->r(), // half the width and height 
     547                           originalImage->getInternalTextureFormat(), // same internal texture format 
     548                           originalImage->getPixelFormat(),originalImage->getDataType(), // same pixel foramt and data type 
     549                           originalImage->data(originalImage->s()/4,originalImage->t()/4), // offset teh start point to 1/4 into the image 
     550                           osg::Image::NO_DELETE, // don't attempt to delete the image data, leave this to the originalImage 
     551                           originalImage->getPacking(), // use the the same packing 
     552                           originalImage->s()); // use the width of the original image as the row width 
     555        subImage->setPixelBufferObject(new osg::PixelBufferObject(subImage.get())); 
     557#if 0 
     558        OSG_NOTICE<<"orignalImage iterator"<<std::endl; 
     559        for(osg::Image::DataIterator itr(originalImage.get()); itr.valid(); ++itr) 
     560        { 
     561            OSG_NOTICE<<"  "<<(void*)<<", "<<itr.size()<<std::endl; 
     562        } 
     564        OSG_NOTICE<<"subImage iterator, size "<<subImage->s()<<", "<<subImage->t()<<std::endl; 
     565        unsigned int i=0; 
     566        for(osg::Image::DataIterator itr(subImage.get()); itr.valid(); ++itr, ++i) 
     567        { 
     568            OSG_NOTICE<<"  "<<i<<", "<<(void*)<<", "<<itr.size()<<std::endl; 
     570            for(unsigned char* d=const_cast<unsigned char*>(; d<(; ++d) 
     571            { 
     572                *d = 255-*d; 
     573            } 
     574        } 
     578        _imageList.push_back(subImage.get()); 
    540581        _imageList.push_back(osgDB::readImageFile("Images/dog_left_eye.jpg")); 
    541583        _textList.push_back("Subloaded Image 1 - dog_left_eye.jpg"); 
    587630    typedef std::vector< osg::ref_ptr<osg::Image> > ImageList; 
    588631    typedef std::vector<std::string>                TextList;