Changeset 7620

Show
Ignore:
Timestamp:
12/08/07 14:29:31 (7 years ago)
Author:
robert
Message:

From Robert Osfield and Richard Schmidt, made fixes inspired by an original submission from Richard which
highlighted problems with Light, ClipPlane? and Hint usage in osg::State's usage of cloneType
and reassignment of target/num in StateSet?/these StateAttributes?.

Location:
OpenSceneGraph/trunk
Files:
6 modified

Legend:

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

    r6311 r7620  
    2828 
    2929        ClipPlane(); 
     30        inline ClipPlane(unsigned int no) { setClipPlaneNum(no); } 
    3031        inline ClipPlane(unsigned int no,const Vec4d& plane)    { setClipPlaneNum(no); setClipPlane(plane); } 
    3132        inline ClipPlane(unsigned int no,const Plane& plane)   { setClipPlaneNum(no); setClipPlane(plane); } 
     
    4344        } 
    4445         
    45         META_StateAttribute(osg, ClipPlane, CLIPPLANE); 
     46        virtual osg::Object* cloneType() const { return new ClipPlane( _clipPlaneNum ); } 
     47        virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new ClipPlane(*this,copyop); } 
     48        virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ClipPlane *>(obj)!=NULL; } 
     49        virtual const char* libraryName() const { return "osg"; } 
     50        virtual const char* className() const { return "ClipPlane"; } 
     51        virtual Type getType() const { return CLIPPLANE; } 
    4652         
    4753        /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ 
  • OpenSceneGraph/trunk/include/osg/Hint

    r6824 r7620  
    2626        Hint(): 
    2727            _target(GL_NONE), 
    28             _mode(GL_NONE) {} 
     28            _mode(GL_DONT_CARE) {} 
    2929 
    3030        Hint(GLenum target, GLenum mode): 
     
    3838            _mode(hint._mode) {} 
    3939 
    40         META_StateAttribute(osg, Hint, HINT); 
     40        virtual osg::Object* cloneType() const { return new Hint( _target, GL_DONT_CARE ); } 
     41        virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Hint(*this,copyop); } 
     42        virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Hint *>(obj)!=NULL; } 
     43        virtual const char* libraryName() const { return "osg"; } 
     44        virtual const char* className() const { return "Light"; } 
     45        virtual Type getType() const { return HINT; } 
    4146 
    4247        virtual int compare(const StateAttribute& sa) const 
    4348        { 
    44             // check the types are equal and then create the rhs variable 
    45             // used by the COMPARE_StateAttribute_Parameter macro's below. 
    46             COMPARE_StateAttribute_Types(Hint,sa) 
     49        // check the types are equal and then create the rhs variable 
     50        // used by the COMPARE_StateAttribute_Parameter macro's below. 
     51        COMPARE_StateAttribute_Types(Hint,sa) 
    4752 
    4853            // compare each paramter in turn against the rhs. 
     
    5661        virtual unsigned int getMember() const { return static_cast<unsigned int>(_target); } 
    5762         
    58         inline void setTarget(GLenum target) { _target = target;  } 
     63        inline void setTarget(GLenum target); 
    5964        inline GLenum getTarget() const { return _target;  } 
    6065         
  • OpenSceneGraph/trunk/include/osg/Light

    r6311 r7620  
    2828        Light(); 
    2929 
     30        Light(unsigned int lightnum); 
     31 
    3032        /** Copy constructor using CopyOp to manage deep vs shallow copy. */ 
    3133        Light(const Light& light,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 
     
    4345            _spot_cutoff(light._spot_cutoff) {} 
    4446         
    45         META_StateAttribute(osg, Light, LIGHT); 
     47        virtual osg::Object* cloneType() const { return new Light(_lightnum); } 
     48        virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Light(*this,copyop); } 
     49        virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Light *>(obj)!=NULL; } 
     50        virtual const char* libraryName() const { return "osg"; } 
     51        virtual const char* className() const { return "Light"; } 
     52        virtual Type getType() const { return LIGHT; } 
    4653 
    4754        /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ 
     
    7986 
    8087        /** Set which OpenGL light to operate on. */ 
    81         void setLightNum(int num) { _lightnum = num; } 
     88        void setLightNum(int num); 
    8289         
    8390        /** Get which OpenGL light this osg::Light operates on. */ 
  • OpenSceneGraph/trunk/src/osg/ClipPlane.cpp

    r5328 r7620  
    1212*/ 
    1313#include <osg/ClipPlane> 
     14#include <osg/StateSet> 
    1415#include <osg/Notify> 
    1516 
     
    2930void ClipPlane::setClipPlaneNum(unsigned int num) 
    3031{ 
     32    if (_clipPlaneNum==num) return; 
     33 
     34    if (_parents.empty()) 
     35    { 
     36        _clipPlaneNum = num; 
     37        return; 
     38    } 
     39 
     40    // take a reference to this clip plane to prevent it from going out of scope 
     41    // when we remove it temporarily from its parents. 
     42    osg::ref_ptr<ClipPlane> clipPlaneRef = this; 
     43 
     44    // copy the parents as they _parents list will be changed by the subsequent removeAttributes. 
     45    ParentList parents = _parents; 
     46 
     47    // remove this attribute from its parents as its position is being changed 
     48    // and would no longer be valid. 
     49    ParentList::iterator itr; 
     50    for(itr = parents.begin(); 
     51        itr != parents.end(); 
     52        ++itr) 
     53    { 
     54        osg::StateSet* stateset = *itr; 
     55        stateset->removeAttribute(this); 
     56    } 
     57     
     58    // assign the clip plane number 
    3159    _clipPlaneNum = num; 
     60 
     61    // add this attribute back into its original parents with its new position 
     62    for(itr = parents.begin(); 
     63        itr != parents.end(); 
     64        ++itr) 
     65    { 
     66        osg::StateSet* stateset = *itr; 
     67        stateset->setAttribute(this); 
     68    } 
    3269} 
    3370 
  • OpenSceneGraph/trunk/src/osg/Hint.cpp

    r6824 r7620  
    1313 
    1414#include <osg/Hint> 
     15#include <osg/StateSet> 
    1516 
    1617using namespace osg; 
     
    2223    glHint(_target, _mode); 
    2324} 
     25 
     26void Hint::setTarget(GLenum target) 
     27{  
     28    if (_target==target) return; 
     29 
     30    if (_parents.empty()) 
     31    { 
     32        _target = target; 
     33        return; 
     34    } 
     35 
     36    // take a reference to this clip plane to prevent it from going out of scope 
     37    // when we remove it temporarily from its parents. 
     38    osg::ref_ptr<Hint> hintRef = this; 
     39 
     40    // copy the parents as they _parents list will be changed by the subsequent removeAttributes. 
     41    ParentList parents = _parents; 
     42 
     43    // remove this attribute from its parents as its position is being changed 
     44    // and would no longer be valid. 
     45    ParentList::iterator itr; 
     46    for(itr = parents.begin(); 
     47        itr != parents.end(); 
     48        ++itr) 
     49    { 
     50        osg::StateSet* stateset = *itr; 
     51        stateset->removeAttribute(this); 
     52    } 
     53     
     54    // assign the hint target 
     55    _target = target; 
     56 
     57    // add this attribute back into its original parents with its new position 
     58    for(itr = parents.begin(); 
     59        itr != parents.end(); 
     60        ++itr) 
     61    { 
     62        osg::StateSet* stateset = *itr; 
     63        stateset->setAttribute(this); 
     64    } 
     65} 
     66 
  • OpenSceneGraph/trunk/src/osg/Light.cpp

    r5328 r7620  
    1212*/ 
    1313#include <osg/Light> 
     14#include <osg/StateSet> 
    1415#include <osg/Notify> 
    1516 
     
    1920{ 
    2021    init(); 
    21  
    22     //     notify(DEBUG) << "_ambient "<<_ambient<<std::endl; 
    23     //     notify(DEBUG) << "_diffuse "<<_diffuse<<std::endl; 
    24     //     notify(DEBUG) << "_specular "<<_specular<<std::endl; 
    25     //     notify(DEBUG) << "_position "<<_position<<std::endl; 
    26     //     notify(DEBUG) << "_direction "<<_direction<<std::endl; 
    27     //     notify(DEBUG) << "_spot_exponent "<<_spot_exponent<<std::endl; 
    28     //     notify(DEBUG) << "_spot_cutoff "<<_spot_cutoff<<std::endl; 
    29     //     notify(DEBUG) << "_constant_attenuation "<<_constant_attenuation<<std::endl; 
    30     //     notify(DEBUG) << "_linear_attenuation "<<_linear_attenuation<<std::endl; 
    31     //     notify(DEBUG) << "_quadratic_attenuation "<<_quadratic_attenuation<<std::endl; 
    3222} 
    3323 
     24Light::Light(unsigned int lightnum) 
     25{ 
     26    init(); 
     27    _lightnum = lightnum; 
     28} 
    3429 
    3530Light::~Light( void ) 
     
    5146    _linear_attenuation = 0.0f; 
    5247    _quadratic_attenuation = 0.0f; 
     48 
     49    //     notify(DEBUG) << "_ambient "<<_ambient<<std::endl; 
     50    //     notify(DEBUG) << "_diffuse "<<_diffuse<<std::endl; 
     51    //     notify(DEBUG) << "_specular "<<_specular<<std::endl; 
     52    //     notify(DEBUG) << "_position "<<_position<<std::endl; 
     53    //     notify(DEBUG) << "_direction "<<_direction<<std::endl; 
     54    //     notify(DEBUG) << "_spot_exponent "<<_spot_exponent<<std::endl; 
     55    //     notify(DEBUG) << "_spot_cutoff "<<_spot_cutoff<<std::endl; 
     56    //     notify(DEBUG) << "_constant_attenuation "<<_constant_attenuation<<std::endl; 
     57    //     notify(DEBUG) << "_linear_attenuation "<<_linear_attenuation<<std::endl; 
     58    //     notify(DEBUG) << "_quadratic_attenuation "<<_quadratic_attenuation<<std::endl; 
    5359} 
     60 
     61void Light::setLightNum(int num)  
     62{ 
     63    if (_lightnum==num) return; 
     64 
     65    if (_parents.empty()) 
     66    { 
     67        _lightnum = num; 
     68        return; 
     69    } 
     70 
     71    // take a reference to this clip plane to prevent it from going out of scope 
     72    // when we remove it temporarily from its parents. 
     73    osg::ref_ptr<Light> lightRef = this; 
     74 
     75    // copy the parents as they _parents list will be changed by the subsequent removeAttributes. 
     76    ParentList parents = _parents; 
     77 
     78    // remove this attribute from its parents as its position is being changed 
     79    // and would no longer be valid. 
     80    ParentList::iterator itr; 
     81    for(itr = parents.begin(); 
     82        itr != parents.end(); 
     83        ++itr) 
     84    { 
     85        osg::StateSet* stateset = *itr; 
     86        stateset->removeAttribute(this); 
     87    } 
     88     
     89    // assign the hint target 
     90    _lightnum = num; 
     91 
     92    // add this attribute back into its original parents with its new position 
     93    for(itr = parents.begin(); 
     94        itr != parents.end(); 
     95        ++itr) 
     96    { 
     97        osg::StateSet* stateset = *itr; 
     98        stateset->setAttribute(this); 
     99    } 
     100} 
     101 
    54102 
    55103