Show
Ignore:
Timestamp:
11/08/05 16:52:21 (9 years ago)
Author:
robert
Message:

From Brad Colbert/Robert Osfield: added s/getSourceFormat and s/getSourceType to osg::Texture
along with support for this Texture1D, 2D, 3D, TextureCubeMap? and TextureRectangle?. The
new SourceFormat? and SourceType? parameters are only used when no osg::Image is assigned to
an osg::Texture, and main use is for render to texture effects.

Added support for --hdr option in osgprerender, which utilises the new Texture::setSourceFormat/Type() methods.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgprerender/osgprerender.cpp

    r4649 r4700  
    146146            _image->dirty(); 
    147147        } 
    148          
     148        else if (_image && _image->getPixelFormat()==GL_RGBA && _image->getDataType()==GL_FLOAT) 
     149        { 
     150            // we'll pick out the center 1/2 of the whole image, 
     151            int column_start = _image->s()/4; 
     152            int column_end = 3*column_start; 
     153             
     154            int row_start = _image->t()/4; 
     155            int row_end = 3*row_start; 
     156             
     157            // and then invert these pixels 
     158            for(int r=row_start; r<row_end; ++r) 
     159            { 
     160                float* data = (float*)_image->data(column_start, r); 
     161                for(int c=column_start; c<column_end; ++c) 
     162                { 
     163                    (*data) = 1.0f-(*data); ++data; 
     164                    (*data) = 1.0f-(*data); ++data; 
     165                    (*data) = 1.0f-(*data); ++data; 
     166                    (*data) = 1.0f; ++data; 
     167                } 
     168            } 
     169 
     170            // dirty the image (increments the modified count) so that any textures 
     171            // using the image can be informed that they need to update. 
     172            _image->dirty(); 
     173        } 
     174        
    149175    } 
    150176     
     
    153179 
    154180 
    155 osg::Node* createPreRenderSubGraph(osg::Node* subgraph, unsigned tex_width, unsigned tex_height, osg::CameraNode::RenderTargetImplementation renderImplementation, bool useImage, bool useTextureRectangle) 
     181osg::Node* createPreRenderSubGraph(osg::Node* subgraph, unsigned tex_width, unsigned tex_height, osg::CameraNode::RenderTargetImplementation renderImplementation, bool useImage, bool useTextureRectangle, bool useHDR) 
    156182{ 
    157183    if (!subgraph) return 0; 
     
    182208        texture = texture2D; 
    183209    }  
     210 
     211    if (useHDR) 
     212    { 
     213        texture->setInternalFormat(GL_RGBA16F_ARB); 
     214        texture->setSourceFormat(GL_RGBA); 
     215        texture->setSourceType(GL_FLOAT); 
     216    } 
    184217 
    185218    // first create the geometry of the flag of which to view. 
     
    299332        { 
    300333            osg::Image* image = new osg::Image; 
    301             image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_UNSIGNED_BYTE); 
     334            //image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_UNSIGNED_BYTE); 
     335            image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_FLOAT); 
    302336 
    303337            // attach the image so its copied on each frame. 
     
    386420    while (arguments.read("--texture-rectangle")) { useTextureRectangle = true; } 
    387421     
     422    bool useHDR = false; 
     423    while (arguments.read("--hdr")) { useHDR = true; } 
    388424 
    389425    // any option left unread are converted into errors to write out later. 
     
    419455 
    420456    osg::Group* rootNode = new osg::Group(); 
    421     rootNode->addChild(createPreRenderSubGraph(loadedModelTransform,tex_width,tex_height, renderImplementation, useImage, useTextureRectangle)); 
     457    rootNode->addChild(createPreRenderSubGraph(loadedModelTransform,tex_width,tex_height, renderImplementation, useImage, useTextureRectangle, useHDR)); 
    422458 
    423459 
     
    448484    return 0; 
    449485} 
     486