Changeset 10924

Show
Ignore:
Timestamp:
01/07/10 13:14:47 (3 years ago)
Author:
robert
Message:

Refactored the way that osg::Image/ImageSequence manages the update callback that needs to be attached to Textures to make it possible to use the Image::update() mechansim in other subclasses from osg::Image.
To enable the automatic attachment of the required update callback to call osg::Image::update(..) subclasses from osg::Image will
need to implement the osg::Image::requestUpdateCall() and return true, and implement the osg::Image::update(NodeVisitor?*) method to recieve the update call during the update traversal.

Location:
OpenSceneGraph/trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osg/Image

    r10866 r10924  
    2020#include <osg/Vec4> 
    2121#include <osg/FrameStamp> 
     22#include <osg/StateAttribute> 
    2223 
    2324#include <string> 
     
    321322        /** Get the const PixelBufferObject.*/ 
    322323        const PixelBufferObject* getPixelBufferObject() const { return dynamic_cast<const PixelBufferObject*>(_bufferObject.get()); } 
    323         
     324 
     325        /** return whether the update(NodeVisitor* nv) should be required on each frame to enable proper working of osg::Image.*/ 
     326        virtual bool requiresUpdateCall() const { return false; } 
     327 
     328        /** update method for osg::Image subclasses that update themselves during the update traversal.*/ 
    324329        virtual void update(NodeVisitor* /*nv*/) {} 
     330 
     331        /** convience update callback class that can be attached to StateAttribute (such as Textures) to ensure 
     332          * that the Image::update(NodeVisitor*) method is called during the update traversal.  This callback 
     333          * is automatically attached when Image::requiresUpdateCall() is true (it's false by default.) 
     334          */ 
     335        struct OSG_EXPORT UpdateCallback : public osg::StateAttributeCallback 
     336        { 
     337            virtual void operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv); 
     338        }; 
    325339 
    326340        /** method for sending pointer events to images that are acting as front ends to interactive surfaces such as a vnc or browser window.  Return true if handled. */ 
  • OpenSceneGraph/trunk/include/osg/ImageSequence

    r10671 r10924  
    1717#include <OpenThreads/Mutex> 
    1818#include <osg/ImageStream> 
    19 #include <osg/StateAttribute> 
    2019 
    2120#include <list> 
     
    102101        Images& getImages() { return _images; } 
    103102        const Images& getImages() const { return _images; } 
    104          
    105103 
     104        /** ImageSequence requires a call to update(NodeVisitor*) during the update traversal so return true.*/ 
     105        virtual bool requiresUpdateCall() const { return true; } 
     106 
     107        /** update method for osg::Image subclasses that update themselves during the update traversal.*/ 
    106108        virtual void update(NodeVisitor* nv); 
    107  
    108         struct OSG_EXPORT UpdateCallback : public osg::StateAttributeCallback 
    109         { 
    110             virtual void operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv); 
    111         }; 
    112109 
    113110    protected: 
  • OpenSceneGraph/trunk/src/osg/Image.cpp

    r10866 r10924  
    6363using namespace osg; 
    6464using namespace std; 
     65 
     66void Image::UpdateCallback::operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv) 
     67{ 
     68    osg::Texture* texture = attr ? attr->asTexture() : 0; 
     69 
     70    // osg::notify(osg::NOTICE)<<"ImageSequence::UpdateCallback::"<<texture<<std::endl; 
     71    if (texture) 
     72    { 
     73        for(unsigned int i=0; i<texture->getNumImages(); ++i) 
     74        { 
     75            texture->getImage(i)->update(nv); 
     76        } 
     77    } 
     78} 
    6579 
    6680Image::Image() 
  • OpenSceneGraph/trunk/src/osg/ImageSequence.cpp

    r9062 r10924  
    2323using namespace osg; 
    2424 
    25 void ImageSequence::UpdateCallback::operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv) 
    26 { 
    27     osg::Texture* texture = attr ? attr->asTexture() : 0; 
    28      
    29     // osg::notify(osg::NOTICE)<<"ImageSequence::UpdateCallback::"<<texture<<std::endl; 
    30     if (texture) 
    31     { 
    32         for(unsigned int i=0; i<texture->getNumImages(); ++i) 
    33         { 
    34             texture->getImage(i)->update(nv); 
    35         } 
    36     } 
    37 } 
    38  
    3925ImageSequence::ImageSequence() 
    4026{ 
  • OpenSceneGraph/trunk/src/osg/Texture1D.cpp

    r10867 r10924  
    1313#include <osg/GLExtensions> 
    1414#include <osg/Texture1D> 
    15 #include <osg/ImageSequence> 
    1615#include <osg/State> 
    1716#include <osg/GLU> 
     
    9897    if (_image == image) return; 
    9998 
    100     if (dynamic_cast<osg::ImageSequence*>(_image.get())) 
     99    if (_image.valid() && _image->requiresUpdateCall()) 
    101100    { 
    102101        setUpdateCallback(0); 
     
    110109    _modifiedCount.setAllElementsTo(0); 
    111110     
    112     if (dynamic_cast<osg::ImageSequence*>(_image.get())) 
    113     { 
    114         setUpdateCallback(new ImageSequence::UpdateCallback()); 
     111    if (_image.valid() && _image->requiresUpdateCall()) 
     112    { 
     113        setUpdateCallback(new Image::UpdateCallback()); 
    115114        setDataVariance(osg::Object::DYNAMIC); 
    116115    } 
  • OpenSceneGraph/trunk/src/osg/Texture2D.cpp

    r10865 r10924  
    1414#include <osg/GLExtensions> 
    1515#include <osg/Texture2D> 
    16 #include <osg/ImageSequence> 
    1716#include <osg/State> 
    1817#include <osg/Notify> 
     
    111110    if (_image == image) return; 
    112111 
    113     if (dynamic_cast<osg::ImageSequence*>(_image.get())) 
     112    if (_image.valid() && _image->requiresUpdateCall()) 
    114113    { 
    115114        setUpdateCallback(0); 
     
    119118    _image = image; 
    120119    _modifiedCount.setAllElementsTo(0); 
    121      
    122     if (dynamic_cast<osg::ImageSequence*>(_image.get())) 
    123     { 
    124         setUpdateCallback(new ImageSequence::UpdateCallback()); 
     120 
     121    if (_image.valid() && _image->requiresUpdateCall()) 
     122    { 
     123        setUpdateCallback(new Image::UpdateCallback()); 
    125124        setDataVariance(osg::Object::DYNAMIC); 
    126125    } 
  • OpenSceneGraph/trunk/src/osg/Texture2DArray.cpp

    r10867 r10924  
    1414#include <osg/Texture2DArray> 
    1515#include <osg/State> 
    16 #include <osg/ImageSequence> 
    1716#include <osg/Notify> 
    1817 
     
    114113    if (_images[layer] == image) return; 
    115114 
    116     unsigned numImageSequencesBefore = 0; 
     115    unsigned numImageRequireUpdateBefore = 0; 
    117116    for (unsigned int i=0; i<getNumImages(); ++i) 
    118117    { 
    119         osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(_images[i].get()); 
    120         if (is) ++numImageSequencesBefore; 
     118        if (_images[i].valid() && _images[i]->requiresUpdateCall()) ++numImageRequireUpdateBefore; 
    121119    } 
    122120 
     
    125123   _modifiedCount[layer].setAllElementsTo(0); 
    126124 
    127     // find out if we need to reset the update callback to handle the animation of ImageSequence 
    128     unsigned numImageSequencesAfter = 0; 
     125    // find out if we need to reset the update callback to handle the animation of image 
     126    unsigned numImageRequireUpdateAfter = 0; 
    129127    for (unsigned int i=0; i<getNumImages(); ++i) 
    130128    { 
    131         osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(_images[i].get()); 
    132         if (is) ++numImageSequencesAfter; 
    133     } 
    134  
    135     if (numImageSequencesBefore>0) 
    136     { 
    137         if (numImageSequencesAfter==0) 
     129        if (_images[i].valid() && _images[i]->requiresUpdateCall()) ++numImageRequireUpdateAfter; 
     130    } 
     131 
     132    if (numImageRequireUpdateBefore>0) 
     133    { 
     134        if (numImageRequireUpdateAfter==0) 
    138135        { 
    139136            setUpdateCallback(0); 
     
    141138        } 
    142139    } 
    143     else if (numImageSequencesAfter>0) 
    144     { 
    145         setUpdateCallback(new ImageSequence::UpdateCallback()); 
     140    else if (numImageRequireUpdateAfter>0) 
     141    { 
     142        setUpdateCallback(new Image::UpdateCallback()); 
    146143        setDataVariance(osg::Object::DYNAMIC); 
    147144    } 
  • OpenSceneGraph/trunk/src/osg/Texture3D.cpp

    r10867 r10924  
    1414#include <osg/Texture3D> 
    1515#include <osg/State> 
    16 #include <osg/ImageSequence> 
    1716#include <osg/GLU> 
    1817#include <osg/Notify> 
     
    110109    if (_image == image) return; 
    111110 
    112     if (dynamic_cast<osg::ImageSequence*>(_image.get())) 
     111    if (_image.valid() && _image->requiresUpdateCall()) 
    113112    { 
    114113        setUpdateCallback(0); 
     
    122121 
    123122    _image = image; 
    124      
    125     if (dynamic_cast<osg::ImageSequence*>(_image.get())) 
    126     { 
    127         setUpdateCallback(new ImageSequence::UpdateCallback()); 
     123 
     124    if (_image.valid() && _image->requiresUpdateCall()) 
     125    { 
     126        setUpdateCallback(new Image::UpdateCallback()); 
    128127        setDataVariance(osg::Object::DYNAMIC); 
    129128    } 
  • OpenSceneGraph/trunk/src/osg/TextureCubeMap.cpp

    r10867 r10924  
    1616#include <osg/State> 
    1717#include <osg/TextureCubeMap> 
    18 #include <osg/ImageSequence> 
    1918#include <osg/Notify> 
    2019 
     
    132131    if (_images[face] == image) return; 
    133132 
    134     unsigned numImageSequencesBefore = 0; 
     133    unsigned numImageRequireUpdateBefore = 0; 
    135134    for (unsigned int i=0; i<getNumImages(); ++i) 
    136135    { 
    137         osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(_images[i].get()); 
    138         if (is) ++numImageSequencesBefore; 
     136        if (_images[i].valid() && _images[i]->requiresUpdateCall()) ++numImageRequireUpdateBefore; 
    139137    } 
    140138 
     
    143141 
    144142 
    145     // find out if we need to reset the update callback to handle the animation of ImageSequence 
    146     unsigned numImageSequencesAfter = 0; 
     143    // find out if we need to reset the update callback to handle the animation of image 
     144    unsigned numImageRequireUpdateAfter = 0; 
    147145    for (unsigned int i=0; i<getNumImages(); ++i) 
    148146    { 
    149         osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(_images[i].get()); 
    150         if (is) ++numImageSequencesAfter; 
    151     } 
    152  
    153     if (numImageSequencesBefore>0) 
    154     { 
    155         if (numImageSequencesAfter==0) 
     147        if (_images[i].valid() && _images[i]->requiresUpdateCall()) ++numImageRequireUpdateAfter; 
     148    } 
     149 
     150    if (numImageRequireUpdateBefore>0) 
     151    { 
     152        if (numImageRequireUpdateAfter==0) 
    156153        { 
    157154            setUpdateCallback(0); 
     
    159156        } 
    160157    } 
    161     else if (numImageSequencesAfter>0) 
    162     { 
    163         setUpdateCallback(new ImageSequence::UpdateCallback()); 
     158    else if (numImageRequireUpdateAfter>0) 
     159    { 
     160        setUpdateCallback(new Image::UpdateCallback()); 
    164161        setDataVariance(osg::Object::DYNAMIC); 
    165162    } 
  • OpenSceneGraph/trunk/src/osg/TextureRectangle.cpp

    r10867 r10924  
    1414#include <osg/GLExtensions> 
    1515#include <osg/TextureRectangle> 
    16 #include <osg/ImageSequence> 
    1716#include <osg/State> 
    1817#include <osg/GLU> 
     
    127126    if (_image == image) return; 
    128127 
    129     if (dynamic_cast<osg::ImageSequence*>(_image.get())) 
     128    if (_image.valid() && _image->requiresUpdateCall()) 
    130129    { 
    131130        setUpdateCallback(0); 
     
    137136 
    138137    _image = image; 
    139      
    140     if (dynamic_cast<osg::ImageSequence*>(_image.get())) 
    141     { 
    142         setUpdateCallback(new ImageSequence::UpdateCallback()); 
     138 
     139    if (_image.valid() && _image->requiresUpdateCall()) 
     140    { 
     141        setUpdateCallback(new Image::UpdateCallback()); 
    143142        setDataVariance(osg::Object::DYNAMIC); 
    144143    } 
  • OpenSceneGraph/trunk/src/osgWrappers/osg/Image.cpp

    r10876 r10924  
    1717#include <osg/NodeVisitor> 
    1818#include <osg/Object> 
     19#include <osg/StateAttribute> 
    1920#include <osg/Vec2> 
    2021#include <osg/Vec3> 
     
    376377                  "Get the const PixelBufferObject. ", 
    377378                  ""); 
     379        I_Method0(bool, requiresUpdateCall, 
     380                  Properties::VIRTUAL, 
     381                  __bool__requiresUpdateCall, 
     382                  "return whether the update(NodeVisitor* nv) should be required on each frame to enable proper working of osg::Image. ", 
     383                  ""); 
    378384        I_Method1(void, update, IN, osg::NodeVisitor *, x, 
    379385                  Properties::VIRTUAL, 
    380386                  __void__update__NodeVisitor_P1, 
    381                   "", 
     387                  "update method for osg::Image subclasses that update themselves during the update traversal. ", 
    382388                  ""); 
    383389        I_Method3(bool, sendPointerEvent, IN, int, x, IN, int, x, IN, int, x, 
     
    499505END_REFLECTOR 
    500506 
     507BEGIN_OBJECT_REFLECTOR(osg::Image::UpdateCallback) 
     508        I_DeclaringFile("osg/Image"); 
     509        I_BaseType(osg::StateAttributeCallback); 
     510        I_Constructor0(____UpdateCallback, 
     511                       "", 
     512                       ""); 
     513END_REFLECTOR 
     514 
    501515STD_VECTOR_REFLECTOR(std::vector< unsigned int >) 
    502516 
  • OpenSceneGraph/trunk/src/osgWrappers/osg/ImageSequence.cpp

    r10863 r10924  
    1616#include <osg/NodeVisitor> 
    1717#include <osg/Object> 
    18 #include <osg/StateAttribute> 
    1918 
    2019// Must undefine IN and OUT macros defined in Windows headers 
     
    207206                  "", 
    208207                  ""); 
     208        I_Method0(bool, requiresUpdateCall, 
     209                  Properties::VIRTUAL, 
     210                  __bool__requiresUpdateCall, 
     211                  "ImageSequence requires a call to update(NodeVisitor*) during the update traversal so return true. ", 
     212                  ""); 
    209213        I_Method1(void, update, IN, osg::NodeVisitor *, nv, 
    210214                  Properties::VIRTUAL, 
    211215                  __void__update__NodeVisitor_P1, 
    212                   "", 
     216                  "update method for osg::Image subclasses that update themselves during the update traversal. ", 
    213217                  ""); 
    214218        I_ProtectedMethod0(void, applyLoopingMode, 
     
    270274END_REFLECTOR 
    271275 
    272 BEGIN_OBJECT_REFLECTOR(osg::ImageSequence::UpdateCallback) 
    273         I_DeclaringFile("osg/ImageSequence"); 
    274         I_BaseType(osg::StateAttributeCallback); 
    275         I_Constructor0(____UpdateCallback, 
    276                        "", 
    277                        ""); 
    278 END_REFLECTOR 
    279  
    280276BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osg::Image >) 
    281277        I_DeclaringFile("osg/ref_ptr");