diff --git a/include/osg/Image b/include/osg/Image index 062de484c..b8c4f5f33 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -131,7 +131,6 @@ class OSG_EXPORT Image : public Object */ void copySubImage(int s_offset,int t_offset,int r_offset,osg::Image* source); - /** Width of image. */ inline int s() const { return _s; } @@ -166,6 +165,9 @@ class OSG_EXPORT Image : public Object /** Return the number of bytes the whole row/image/volume of pixels occupies, including all mip maps if included. */ unsigned int getTotalSizeInBytesIncludingMipmaps() const; + /** Return true if the Image represent a valid and usable imagery.*/ + bool valid() const { return _s!=0 && _t!=0 && _r!=0 && _data!=0 && _dataType!=0; } + /** Raw image data. */ inline unsigned char *data() { return _data; } diff --git a/src/osg/BufferObject.cpp b/src/osg/BufferObject.cpp index b1dd08e6c..51accb847 100644 --- a/src/osg/BufferObject.cpp +++ b/src/osg/BufferObject.cpp @@ -323,23 +323,28 @@ void PixelBufferObject::compileBuffer(State& state) const unsigned int contextID = state.getContextID(); if (!needsCompile(contextID)) return; - Extensions* extensions = getExtensions(contextID,true); - osg::Image* image = _bufferEntryImagePair.second; - + + _bufferEntryImagePair.first.modifiedCount[contextID] = image->getModifiedCount(); + if (!image->valid()) return; + + Extensions* extensions = getExtensions(contextID,true); GLuint& pbo = buffer(contextID); if (pbo==0) { // building for the first time. - extensions->glGenBuffers(1, &pbo); - - extensions->glBindBuffer(_target, pbo); _totalSize = image->getTotalSizeInBytes(); + // don't generate buffer if size is zero. + if (_totalSize==0) return; + + extensions->glGenBuffers(1, &pbo); + extensions->glBindBuffer(_target, pbo); extensions->glBufferData(_target, _totalSize, NULL, _usage); + } else { @@ -347,6 +352,7 @@ void PixelBufferObject::compileBuffer(State& state) const if (_totalSize != image->getTotalSizeInBytes()) { + _totalSize = image->getTotalSizeInBytes(); extensions->glBufferData(_target, _totalSize, NULL, _usage);