Show
Ignore:
Timestamp:
01/24/12 15:34:02 (2 years ago)
Author:
robert
Message:

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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgDB/OutputStream.cpp

    r12896 r12912  
    370370                // _data 
    371371                unsigned int size = img->getTotalSizeInBytesIncludingMipmaps(); 
    372                 writeSize(size); writeCharArray( (char*)img->data(), size ); 
     372                writeSize(size); 
     373 
     374                for(osg::Image::DataIterator img_itr(img); img_itr.valid(); ++img_itr) 
     375                { 
     376                    writeCharArray( (char*)img_itr.data(), img_itr.size() ); 
     377                } 
    373378 
    374379                // _mipmapData 
    375                 const osg::Image::MipmapDataType& levels = img->getMipmapLevels(); 
    376                 writeSize(levels.size()); 
    377                 for ( osg::Image::MipmapDataType::const_iterator itr=levels.begin(); 
    378                     itr!=levels.end(); ++itr ) 
     380                unsigned int numMipmaps = img->getNumMipmapLevels()-1; 
     381                writeSize(numMipmaps); 
     382                int s = img->s(); 
     383                int t = img->t(); 
     384                int r = img->r(); 
     385                unsigned int offset = 0; 
     386                for (unsigned int i=0; i<numMipmaps; ++i) 
    379387                { 
    380                     *this << *itr; 
     388                    unsigned int size = osg::Image::computeImageSizeInBytes(s,t,r,img->getPixelFormat(),img->getDataType(),img->getPacking()); 
     389                    offset += size; 
     390                     
     391                    *this << offset; 
     392 
     393                    s >>= 1; 
     394                    t >>= 1; 
     395                    r >>= 1; 
     396                    if (s<1) s=1; 
     397                    if (t<1) t=1; 
     398                    if (r<1) r=1;                     
    381399                } 
    382400            }