Changeset 11828
- Timestamp:
- 10/07/10 12:51:22 (3 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 6 modified
-
examples/osgphotoalbum/PhotoArchive.cpp (modified) (4 diffs)
-
include/osg/GLU (modified) (1 diff)
-
include/osg/Image (modified) (1 diff)
-
src/osg/Image.cpp (modified) (2 diffs)
-
src/osg/Texture.cpp (modified) (2 diffs)
-
src/osg/glu/libutil/mipmap.cpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgphotoalbum/PhotoArchive.cpp
r9343 r11828 31 31 const std::string FILE_IDENTIFER("osgphotoalbum photo archive"); 32 32 33 class MyGraphicsContext {34 public:35 MyGraphicsContext()36 {37 osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;38 traits->x = 0;39 traits->y = 0;40 traits->width = 1;41 traits->height = 1;42 traits->windowDecoration = false;43 traits->doubleBuffer = false;44 traits->sharedContext = 0;45 traits->pbuffer = true;46 47 _gc = osg::GraphicsContext::createGraphicsContext(traits.get());48 49 if (!_gc)50 {51 osg::notify(osg::NOTICE)<<"Failed to create pbuffer, failing back to normal graphics window."<<std::endl;52 53 traits->pbuffer = false;54 _gc = osg::GraphicsContext::createGraphicsContext(traits.get());55 }56 57 if (_gc.valid())58 59 60 {61 _gc->realize();62 _gc->makeCurrent();63 std::cout<<"Realized window"<<std::endl;64 }65 }66 67 bool valid() const { return _gc.valid() && _gc->isRealized(); }68 69 private:70 osg::ref_ptr<osg::GraphicsContext> _gc;71 };72 73 33 PhotoArchive::PhotoArchive(const std::string& filename) 74 34 { … … 207 167 std::cout<<"Building photo archive containing "<<photoIndex.size()<<" pictures"<<std::endl; 208 168 209 // create a graphics context so we can do data operations 210 MyGraphicsContext context; 211 212 // open up the archive for writing to 169 // open up the archive for writing to 213 170 osgDB::ofstream out(filename.c_str(), std::ios::out | std::ios::binary); 214 171 … … 259 216 } 260 217 261 glPixelStorei(GL_PACK_ALIGNMENT,image->getPacking()); 262 glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); 263 264 GLint status = gluScaleImage(image->getPixelFormat(), 218 PixelStorageModes psm; 219 psm.pack_alignment = image->getPacking(); 220 psm.unpack_alignment = image->getPacking(); 221 222 GLint status = gluScaleImage(&psm, image->getPixelFormat(), 265 223 image->s(), 266 224 image->t(), … … 325 283 } 326 284 327 glPixelStorei(GL_PACK_ALIGNMENT,image->getPacking()); 328 glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); 329 330 GLint status = gluScaleImage(image->getPixelFormat(), 285 PixelStorageModes psm; 286 psm.pack_alignment = image->getPacking(); 287 psm.unpack_alignment = image->getPacking(); 288 289 GLint status = gluScaleImage(&psm, image->getPixelFormat(), 331 290 image->s(), 332 291 image->t(), -
OpenSceneGraph/trunk/include/osg/GLU
r11820 r11828 17 17 #include <osg/GL> 18 18 19 /* Pixel storage modes, used by gluScaleImage */ 20 struct OSG_EXPORT PixelStorageModes 21 { 22 // sets defaults as per glGet docs in OpenGL red book 23 PixelStorageModes(); 24 25 // use glGet's to retrieve all the current settings 26 void retrieveStoreModes(); 27 28 // use glGet's to retrieve all the current 3D settings 29 void retrieveStoreModes3D(); 30 31 GLint pack_alignment; 32 GLint pack_row_length; 33 GLint pack_skip_rows; 34 GLint pack_skip_pixels; 35 GLint pack_lsb_first; 36 GLint pack_swap_bytes; 37 GLint pack_skip_images; 38 GLint pack_image_height; 39 40 GLint unpack_alignment; 41 GLint unpack_row_length; 42 GLint unpack_skip_rows; 43 GLint unpack_skip_pixels; 44 GLint unpack_lsb_first; 45 GLint unpack_swap_bytes; 46 GLint unpack_skip_images; 47 GLint unpack_image_height; 48 } ; 49 50 extern OSG_EXPORT const GLubyte * gluErrorString (GLenum error); 51 52 /** OSG specific gluScaleImage function that allows you to pass in the PixelStoreModes, which 53 * enables the code to avoid glGet's that are associated with the conventional gluScaleImage function. 54 * Avoiding glGet's allows this gluScaleImage function to be called at any time, from any thread, there 55 * is no need to have a graphics context current.*/ 56 extern OSG_EXPORT GLint gluScaleImage (PixelStorageModes* psm, GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void *dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid* dataOut); 57 58 /** Traditional GLU gluScaleImage function that sets up the PixelStoreModes automatically by doing glGets.; 59 * The use of glGet's means that you can only call this function from a thread with a valid graphics context. 60 * The use of glGet's will also result in lower performance due to the round trip to the OpenGL driver.*/ 19 61 extern OSG_EXPORT GLint gluScaleImage (GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void *dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid* dataOut); 20 extern OSG_EXPORT const GLubyte * gluErrorString (GLenum error); 62 21 63 extern OSG_EXPORT GLint gluBuild1DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); 22 64 extern OSG_EXPORT GLint gluBuild1DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void *data); -
OpenSceneGraph/trunk/include/osg/Image
r11821 r11828 173 173 174 174 175 /** Scale image to specified size. 176 * \warning The method uses gluScaleImage() and thus needs a valid rendering context. 177 */ 175 /** Scale image to specified size. */ 178 176 void scaleImage(int s,int t,int r) { scaleImage(s,t,r, getDataType()); } 179 177 180 /** Scale image to specified size and with specified data type. 181 * \warning The method uses gluScaleImage() and thus needs a valid rendering context. 182 */ 178 /** Scale image to specified size and with specified data type. */ 183 179 virtual void scaleImage(int s,int t,int r, GLenum newDataType); 184 180 -
OpenSceneGraph/trunk/src/osg/Image.cpp
r11817 r11828 937 937 } 938 938 939 glPixelStorei(GL_PACK_ALIGNMENT,_packing); 940 glPixelStorei(GL_UNPACK_ALIGNMENT,_packing); 941 942 GLint status = gluScaleImage(_pixelFormat, 939 PixelStorageModes psm; 940 psm.pack_alignment = _packing; 941 psm.unpack_alignment = _packing; 942 943 GLint status = gluScaleImage(&psm, _pixelFormat, 943 944 _s, 944 945 _t, … … 1001 1002 void* data_destination = data(s_offset,t_offset,r_offset); 1002 1003 1003 glPixelStorei(GL_PACK_ALIGNMENT,source->getPacking());1004 glPixelStorei(GL_PACK_ROW_LENGTH,_s);1005 1006 glPixelStorei(GL_UNPACK_ALIGNMENT,_packing);1007 1008 GLint status = gluScaleImage( _pixelFormat,1004 PixelStorageModes psm; 1005 psm.pack_alignment = _packing; 1006 psm.pack_row_length = _packing; 1007 psm.unpack_alignment = _packing; 1008 1009 GLint status = gluScaleImage(&psm, _pixelFormat, 1009 1010 source->s(), 1010 1011 source->t(), -
OpenSceneGraph/trunk/src/osg/Texture.cpp
r11817 r11828 1652 1652 else { OSG_NOTICE << "Scaling image from ("<<image->s()<<","<<image->t()<<") to ("<<inwidth<<","<<inheight<<")"<<std::endl; } 1653 1653 1654 PixelStorageModes psm; 1655 psm.pack_alignment = image->getPacking(); 1656 psm.unpack_alignment = image->getPacking(); 1657 1654 1658 // rescale the image to the correct size. 1655 gl PixelStorei(GL_PACK_ALIGNMENT,image->getPacking());1656 gluScaleImage(image->getPixelFormat(),1657 image->s(),image->t(),image->getDataType(),image->data(),1658 inwidth,inheight,image->getDataType(),1659 dataPtr); 1659 gluScaleImage(&psm, image->getPixelFormat(), 1660 image->s(),image->t(),image->getDataType(),image->data(), 1661 inwidth,inheight,image->getDataType(), 1662 dataPtr); 1663 1660 1664 } 1661 1665 … … 1891 1895 1892 1896 // rescale the image to the correct size. 1893 glPixelStorei(GL_PACK_ALIGNMENT,image->getPacking()); 1894 gluScaleImage(image->getPixelFormat(), 1897 PixelStorageModes psm; 1898 psm.pack_alignment = image->getPacking(); 1899 psm.unpack_alignment = image->getPacking(); 1900 1901 gluScaleImage(&psm, image->getPixelFormat(), 1895 1902 image->s(),image->t(),image->getDataType(),image->data(), 1896 1903 inwidth,inheight,image->getDataType(), -
OpenSceneGraph/trunk/src/osg/glu/libutil/mipmap.cpp
r11827 r11828 49 49 #include <limits.h> /* UINT_MAX */ 50 50 #include <math.h> 51 #include <osg/Notify> 51 52 52 53 typedef union { … … 59 60 float f; 60 61 } Type_Widget; 61 62 /* Pixel storage modes */63 typedef struct {64 GLint pack_alignment;65 GLint pack_row_length;66 GLint pack_skip_rows;67 GLint pack_skip_pixels;68 GLint pack_lsb_first;69 GLint pack_swap_bytes;70 GLint pack_skip_images;71 GLint pack_image_height;72 73 GLint unpack_alignment;74 GLint unpack_row_length;75 GLint unpack_skip_rows;76 GLint unpack_skip_pixels;77 GLint unpack_lsb_first;78 GLint unpack_swap_bytes;79 GLint unpack_skip_images;80 GLint unpack_image_height;81 } PixelStorageModes;82 62 83 63 static int gluBuild1DMipmapLevelsCore(GLenum, GLint, … … 259 239 GLint, GLint, GLint, GLushort *); 260 240 261 static void retrieveStoreModes(PixelStorageModes *psm) 262 { 263 glGetIntegerv(GL_UNPACK_ALIGNMENT, &psm->unpack_alignment); 264 glGetIntegerv(GL_UNPACK_ROW_LENGTH, &psm->unpack_row_length); 265 glGetIntegerv(GL_UNPACK_SKIP_ROWS, &psm->unpack_skip_rows); 266 glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &psm->unpack_skip_pixels); 267 glGetIntegerv(GL_UNPACK_LSB_FIRST, &psm->unpack_lsb_first); 268 glGetIntegerv(GL_UNPACK_SWAP_BYTES, &psm->unpack_swap_bytes); 269 270 glGetIntegerv(GL_PACK_ALIGNMENT, &psm->pack_alignment); 271 glGetIntegerv(GL_PACK_ROW_LENGTH, &psm->pack_row_length); 272 glGetIntegerv(GL_PACK_SKIP_ROWS, &psm->pack_skip_rows); 273 glGetIntegerv(GL_PACK_SKIP_PIXELS, &psm->pack_skip_pixels); 274 glGetIntegerv(GL_PACK_LSB_FIRST, &psm->pack_lsb_first); 275 glGetIntegerv(GL_PACK_SWAP_BYTES, &psm->pack_swap_bytes); 241 PixelStorageModes::PixelStorageModes() 242 { 243 // Default Settings set from values specified in glGet docs in the OpenGL red book. 244 pack_alignment = 4; 245 pack_row_length = 0; 246 pack_skip_rows = 0; 247 pack_skip_pixels = 0; 248 pack_lsb_first = GL_FALSE; 249 pack_swap_bytes = GL_FALSE; 250 pack_skip_images = 0; 251 pack_image_height = 0; 252 253 unpack_alignment = 4; 254 unpack_row_length = 0; 255 unpack_skip_rows = 0; 256 unpack_skip_pixels = 0; 257 unpack_lsb_first = GL_FALSE; 258 unpack_swap_bytes = GL_FALSE; 259 unpack_skip_images = 0; 260 unpack_image_height = 0; 276 261 } 277 262 278 static void retrieveStoreModes3D(PixelStorageModes *psm) 279 { 280 glGetIntegerv(GL_UNPACK_ALIGNMENT, &psm->unpack_alignment); 281 glGetIntegerv(GL_UNPACK_ROW_LENGTH, &psm->unpack_row_length); 282 glGetIntegerv(GL_UNPACK_SKIP_ROWS, &psm->unpack_skip_rows); 283 glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &psm->unpack_skip_pixels); 284 glGetIntegerv(GL_UNPACK_LSB_FIRST, &psm->unpack_lsb_first); 285 glGetIntegerv(GL_UNPACK_SWAP_BYTES, &psm->unpack_swap_bytes); 286 glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &psm->unpack_skip_images); 287 glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &psm->unpack_image_height); 288 289 glGetIntegerv(GL_PACK_ALIGNMENT, &psm->pack_alignment); 290 glGetIntegerv(GL_PACK_ROW_LENGTH, &psm->pack_row_length); 291 glGetIntegerv(GL_PACK_SKIP_ROWS, &psm->pack_skip_rows); 292 glGetIntegerv(GL_PACK_SKIP_PIXELS, &psm->pack_skip_pixels); 293 glGetIntegerv(GL_PACK_LSB_FIRST, &psm->pack_lsb_first); 294 glGetIntegerv(GL_PACK_SWAP_BYTES, &psm->pack_swap_bytes); 295 glGetIntegerv(GL_PACK_SKIP_IMAGES, &psm->pack_skip_images); 296 glGetIntegerv(GL_PACK_IMAGE_HEIGHT, &psm->pack_image_height); 263 void PixelStorageModes::retrieveStoreModes() 264 { 265 glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment); 266 glGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpack_row_length); 267 glGetIntegerv(GL_UNPACK_SKIP_ROWS, &unpack_skip_rows); 268 glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &unpack_skip_pixels); 269 glGetIntegerv(GL_UNPACK_LSB_FIRST, &unpack_lsb_first); 270 glGetIntegerv(GL_UNPACK_SWAP_BYTES, &unpack_swap_bytes); 271 272 glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); 273 glGetIntegerv(GL_PACK_ROW_LENGTH, &pack_row_length); 274 glGetIntegerv(GL_PACK_SKIP_ROWS, &pack_skip_rows); 275 glGetIntegerv(GL_PACK_SKIP_PIXELS, &pack_skip_pixels); 276 glGetIntegerv(GL_PACK_LSB_FIRST, &pack_lsb_first); 277 glGetIntegerv(GL_PACK_SWAP_BYTES, &pack_swap_bytes); 278 } 279 280 void PixelStorageModes::retrieveStoreModes3D() 281 { 282 glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment); 283 glGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpack_row_length); 284 glGetIntegerv(GL_UNPACK_SKIP_ROWS, &unpack_skip_rows); 285 glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &unpack_skip_pixels); 286 glGetIntegerv(GL_UNPACK_LSB_FIRST, &unpack_lsb_first); 287 glGetIntegerv(GL_UNPACK_SWAP_BYTES, &unpack_swap_bytes); 288 glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &unpack_skip_images); 289 glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &unpack_image_height); 290 291 glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); 292 glGetIntegerv(GL_PACK_ROW_LENGTH, &pack_row_length); 293 glGetIntegerv(GL_PACK_SKIP_ROWS, &pack_skip_rows); 294 glGetIntegerv(GL_PACK_SKIP_PIXELS, &pack_skip_pixels); 295 glGetIntegerv(GL_PACK_LSB_FIRST, &pack_lsb_first); 296 glGetIntegerv(GL_PACK_SWAP_BYTES, &pack_swap_bytes); 297 glGetIntegerv(GL_PACK_SKIP_IMAGES, &pack_skip_images); 298 glGetIntegerv(GL_PACK_IMAGE_HEIGHT, &pack_image_height); 297 299 } 298 300 … … 3508 3510 3509 3511 GLint GLAPIENTRY 3510 gluScaleImage( GLenum format, GLsizei widthin, GLsizei heightin,3512 gluScaleImage(PixelStorageModes* psm, GLenum format, GLsizei widthin, GLsizei heightin, 3511 3513 GLenum typein, const void *datain, 3512 3514 GLsizei widthout, GLsizei heightout, GLenum typeout, … … 3516 3518 GLushort *beforeImage; 3517 3519 GLushort *afterImage; 3518 PixelStorageModes psm;3519 3520 3520 if (widthin == 0 || heightin == 0 || widthout == 0 || heightout == 0) { 3521 3521 return 0; … … 3543 3543 } 3544 3544 3545 retrieveStoreModes(&psm); 3546 fill_image(&psm,widthin, heightin, format, typein, is_index(format), 3545 fill_image(psm,widthin, heightin, format, typein, is_index(format), 3547 3546 datain, beforeImage); 3548 3547 components = elements_per_group(format, 0); 3549 3548 scale_internal(components, widthin, heightin, beforeImage, 3550 3549 widthout, heightout, afterImage); 3551 empty_image( &psm,widthout, heightout, format, typeout,3550 empty_image(psm,widthout, heightout, format, typeout, 3552 3551 is_index(format), afterImage, dataout); 3553 3552 free((GLbyte *) beforeImage); … … 3555 3554 3556 3555 return 0; 3556 } 3557 3558 GLint GLAPIENTRY 3559 gluScaleImage(GLenum format, GLsizei widthin, GLsizei heightin, 3560 GLenum typein, const void *datain, 3561 GLsizei widthout, GLsizei heightout, GLenum typeout, 3562 void *dataout) 3563 { 3564 PixelStorageModes psm; 3565 psm.retrieveStoreModes(); 3566 return gluScaleImage(&psm, format, widthin, heightin, 3567 typein, datain, 3568 widthout, heightout, typeout, 3569 dataout); 3557 3570 } 3558 3571 … … 3584 3597 levels+= userLevel; 3585 3598 3586 retrieveStoreModes(&psm);3599 psm.retrieveStoreModes(); 3587 3600 newImage = (GLushort *) 3588 3601 malloc(image_size(width, 1, format, GL_UNSIGNED_SHORT)); … … 3721 3734 PixelStorageModes psm; 3722 3735 3723 retrieveStoreModes(&psm);3736 psm.retrieveStoreModes(); 3724 3737 3725 3738 #if 0 … … 3851 3864 levels+= userLevel; 3852 3865 3853 retrieveStoreModes(&psm);3866 psm.retrieveStoreModes(); 3854 3867 myswap_bytes = psm.unpack_swap_bytes; 3855 3868 cmpts = elements_per_group(format,type); … … 7411 7424 return GLU_OUT_OF_MEMORY; 7412 7425 } 7413 retrieveStoreModes3D(&psm);7426 psm.retrieveStoreModes3D(); 7414 7427 7415 7428 fillImage3D(&psm,widthIn,heightIn,depthIn,format,typeIn, is_index(format), … … 7779 7792 levels+= userLevel; 7780 7793 7781 retrieveStoreModes3D(&psm);7794 psm.retrieveStoreModes3D(); 7782 7795 myswapBytes = psm.unpack_swap_bytes; 7783 7796 cmpts = elements_per_group(format,type);
