Changeset 11828

Show
Ignore:
Timestamp:
10/07/10 12:51:22 (4 years ago)
Author:
robert
Message:

Introduced new gluScaleImage function that uses a PixelStorageModes? structure to pass in details on image packing,
rather than relying upon glGet's to get the values.

Location:
OpenSceneGraph/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgphotoalbum/PhotoArchive.cpp

    r9343 r11828  
    3131const std::string FILE_IDENTIFER("osgphotoalbum photo archive"); 
    3232 
    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  
    7333PhotoArchive::PhotoArchive(const std::string& filename) 
    7434{ 
     
    207167    std::cout<<"Building photo archive containing "<<photoIndex.size()<<" pictures"<<std::endl; 
    208168 
    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 
    213170    osgDB::ofstream out(filename.c_str(), std::ios::out | std::ios::binary); 
    214171 
     
    259216            } 
    260217 
    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(), 
    265223                image->s(), 
    266224                image->t(), 
     
    325283            } 
    326284 
    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(), 
    331290                image->s(), 
    332291                image->t(), 
  • OpenSceneGraph/trunk/include/osg/GLU

    r11820 r11828  
    1717#include <osg/GL> 
    1818 
     19/* Pixel storage modes, used by gluScaleImage */ 
     20struct 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 
     50extern 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.*/ 
     56extern 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.*/ 
    1961extern 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 
    2163extern OSG_EXPORT GLint gluBuild1DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); 
    2264extern OSG_EXPORT GLint gluBuild1DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void *data); 
  • OpenSceneGraph/trunk/include/osg/Image

    r11821 r11828  
    173173 
    174174 
    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. */ 
    178176        void scaleImage(int s,int t,int r) { scaleImage(s,t,r, getDataType()); } 
    179177 
    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. */ 
    183179        virtual void scaleImage(int s,int t,int r, GLenum newDataType); 
    184180 
  • OpenSceneGraph/trunk/src/osg/Image.cpp

    r11817 r11828  
    937937    } 
    938938 
    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, 
    943944        _s, 
    944945        _t, 
     
    10011002    void* data_destination = data(s_offset,t_offset,r_offset); 
    10021003 
    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, 
    10091010        source->s(), 
    10101011        source->t(), 
  • OpenSceneGraph/trunk/src/osg/Texture.cpp

    r11817 r11828  
    16521652        else { OSG_NOTICE << "Scaling image from ("<<image->s()<<","<<image->t()<<") to ("<<inwidth<<","<<inheight<<")"<<std::endl; } 
    16531653 
     1654        PixelStorageModes psm; 
     1655        psm.pack_alignment = image->getPacking(); 
     1656        psm.unpack_alignment = image->getPacking(); 
     1657 
    16541658        // rescale the image to the correct size. 
    1655         glPixelStorei(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 
    16601664    } 
    16611665 
     
    18911895 
    18921896        // 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(), 
    18951902                      image->s(),image->t(),image->getDataType(),image->data(), 
    18961903                      inwidth,inheight,image->getDataType(), 
  • OpenSceneGraph/trunk/src/osg/glu/libutil/mipmap.cpp

    r11827 r11828  
    4949#include <limits.h>                /* UINT_MAX */ 
    5050#include <math.h> 
     51#include <osg/Notify> 
    5152 
    5253typedef union { 
     
    5960    float f; 
    6061} 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; 
    8262 
    8363static int gluBuild1DMipmapLevelsCore(GLenum, GLint, 
     
    259239                            GLint, GLint, GLint, GLushort *); 
    260240 
    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); 
     241PixelStorageModes::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; 
    276261} 
    277262 
    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); 
     263void 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 
     280void 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); 
    297299} 
    298300 
     
    35083510 
    35093511GLint GLAPIENTRY 
    3510 gluScaleImage(GLenum format, GLsizei widthin, GLsizei heightin, 
     3512gluScaleImage(PixelStorageModes* psm, GLenum format, GLsizei widthin, GLsizei heightin, 
    35113513                    GLenum typein, const void *datain, 
    35123514                    GLsizei widthout, GLsizei heightout, GLenum typeout, 
     
    35163518    GLushort *beforeImage; 
    35173519    GLushort *afterImage; 
    3518     PixelStorageModes psm; 
    3519  
    35203520    if (widthin == 0 || heightin == 0 || widthout == 0 || heightout == 0) { 
    35213521        return 0; 
     
    35433543    } 
    35443544 
    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), 
    35473546            datain, beforeImage); 
    35483547    components = elements_per_group(format, 0); 
    35493548    scale_internal(components, widthin, heightin, beforeImage, 
    35503549            widthout, heightout, afterImage); 
    3551     empty_image(&psm,widthout, heightout, format, typeout, 
     3550    empty_image(psm,widthout, heightout, format, typeout, 
    35523551            is_index(format), afterImage, dataout); 
    35533552    free((GLbyte *) beforeImage); 
     
    35553554 
    35563555    return 0; 
     3556} 
     3557 
     3558GLint GLAPIENTRY 
     3559gluScaleImage(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); 
    35573570} 
    35583571 
     
    35843597    levels+= userLevel; 
    35853598 
    3586     retrieveStoreModes(&psm); 
     3599    psm.retrieveStoreModes(); 
    35873600    newImage = (GLushort *) 
    35883601        malloc(image_size(width, 1, format, GL_UNSIGNED_SHORT)); 
     
    37213734    PixelStorageModes psm; 
    37223735 
    3723     retrieveStoreModes(&psm); 
     3736    psm.retrieveStoreModes(); 
    37243737 
    37253738#if 0 
     
    38513864    levels+= userLevel; 
    38523865 
    3853     retrieveStoreModes(&psm); 
     3866    psm.retrieveStoreModes(); 
    38543867    myswap_bytes = psm.unpack_swap_bytes; 
    38553868    cmpts = elements_per_group(format,type); 
     
    74117424       return GLU_OUT_OF_MEMORY; 
    74127425   } 
    7413    retrieveStoreModes3D(&psm); 
     7426   psm.retrieveStoreModes3D(); 
    74147427 
    74157428   fillImage3D(&psm,widthIn,heightIn,depthIn,format,typeIn, is_index(format), 
     
    77797792   levels+= userLevel; 
    77807793 
    7781    retrieveStoreModes3D(&psm); 
     7794   psm.retrieveStoreModes3D(); 
    77827795   myswapBytes = psm.unpack_swap_bytes; 
    77837796   cmpts = elements_per_group(format,type);