diff --git a/include/osg/DrawPixels b/include/osg/DrawPixels index 6fea967d3..05a0fec2f 100644 --- a/include/osg/DrawPixels +++ b/include/osg/DrawPixels @@ -51,7 +51,7 @@ class SG_EXPORT DrawPixels : public Drawable bool getUseSubImage() const { return _useSubImage; } - virtual void drawImmediateMode(State& state); + virtual void drawImplementation(State& state) const; protected: diff --git a/include/osg/Drawable b/include/osg/Drawable index 1480a9495..0ec94bb37 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -163,7 +163,7 @@ class SG_EXPORT Drawable : public Object /** draw OpenGL primitives. * If the drawable has _useDisplayList set to true then use an OpenGL display * list, automatically compiling one if required. - * Otherwise call drawImmediateMode(). + * Otherwise call drawImplementation(). * Note, draw method should *not* be overridden in subclasses as it * manages the optional display list. */ @@ -208,14 +208,22 @@ class SG_EXPORT Drawable : public Object /** Callback attached to an Drawable which allows the users to customize the drawing of an exist Drawable object. - * The draw callback is implement as a replacement to the Drawable's own drawImmediateMode() method, if the - * the user intends to decorate the exist draw code then simple call the drawable->drawImmediateMode() from - * with the callbacks drawImmediateMode() method. This allows the users to do both pre and post callbacks + * The draw callback is implement as a replacement to the Drawable's own drawImplementation() method, if the + * the user intends to decorate the exist draw code then simple call the drawable->drawImplementation() from + * with the callbacks drawImplementation() method. This allows the users to do both pre and post callbacks * without fuss and can even diable the inner draw in required.*/ struct DrawCallback : public osg::Referenced { - /** do customized draw code.*/ - virtual void drawImmediateMode(State& state,osg::Drawable* drawable) const = 0; +#ifdef USE_DEPRECATED_API + // adapt old drawImmediateMode API into new API to keep things compiling on old code. + virtual void drawImplementation(State& state,const osg::Drawable* drawable) const { drawImmediateMode(state,const_cast(drawable)); } + + /** do customized draw code.*/ + virtual void drawImmediateMode(State& state,osg::Drawable* drawable) const = 0; +#else + /** do customized draw code.*/ + virtual void drawImplementation(State& state,const osg::Drawable* drawable) const = 0; +#endif }; /** Set the DrawCallback which allows users to attach customize the drawing of existing Drawable object.*/ @@ -228,13 +236,27 @@ class SG_EXPORT Drawable : public Object const DrawCallback* getDrawCallback() const { return _drawCallback.get(); } + +#ifdef USE_DEPRECATED_API + + // adapt old drawImmediateMode API into new API to keep things compiling on old code. + virtual void drawImplementation(State& state) const { (const_cast(this))->drawImmediateMode(state); } + /** draw directly ignoring an OpenGL display list which could be attached. * This is the internal draw method which does the drawing itself, * and is the method to override when deriving from Drawable. */ - virtual void drawImmediateMode(State& state) = 0; + virtual void drawImmediateMode(State&) {} +#else + /** draw directly ignoring an OpenGL display list which could be attached. + * This is the internal draw method which does the drawing itself, + * and is the method to override when deriving from Drawable. + */ + virtual void drawImplementation(State& state) const = 0; + +#endif /** use deleteDisplayList instead of glDeleteList to allow * OpenGL display list to cached until they can be deleted @@ -420,9 +442,9 @@ inline void Drawable::draw(State& state) globj = glGenLists( 1 ); glNewList( globj, GL_COMPILE ); if (_drawCallback.valid()) - _drawCallback->drawImmediateMode(state,this); + _drawCallback->drawImplementation(state,this); else - drawImmediateMode(state); + drawImplementation(state); glEndList(); glCallList( globj); @@ -430,9 +452,9 @@ inline void Drawable::draw(State& state) globj = glGenLists( 1 ); glNewList( globj, GL_COMPILE_AND_EXECUTE ); if (_drawCallback.valid()) - _drawCallback->drawImmediateMode(state,this); + _drawCallback->drawImplementation(state,this); else - drawImmediateMode(state); + drawImplementation(state); glEndList(); #endif } @@ -442,9 +464,9 @@ inline void Drawable::draw(State& state) { // draw object as nature intended.. if (_drawCallback.valid()) - _drawCallback->drawImmediateMode(state,this); + _drawCallback->drawImplementation(state,this); else - drawImmediateMode(state); + drawImplementation(state); } }; diff --git a/include/osg/GeoSet b/include/osg/GeoSet index 82b0efc62..40ef9f2f2 100644 --- a/include/osg/GeoSet +++ b/include/osg/GeoSet @@ -305,7 +305,7 @@ class SG_EXPORT GeoSet : public Drawable * This is the internal draw method which does the drawing itself, * and is the method to override when deriving from GeoSet for user-drawn objects. */ - virtual void drawImmediateMode(State& state); + virtual void drawImplementation(State& state) const; bool check() const; @@ -330,12 +330,21 @@ class SG_EXPORT GeoSet : public Drawable /** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/ const AttributeDeleteFunctor* getAttributeDeleteFunctor() const { return _adf.get(); } + /** return true, osg::GeoSet does support accept(AttributeFunctor&).*/ + virtual bool supports(AttributeFunctor&) const { return true; } + /** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/ virtual void accept(AttributeFunctor& af); + /** return true, osg::GeoSet does support accept(ConstAttributeFunctor&).*/ + virtual bool supports(ConstAttributeFunctor&) const { return true; } + /** accept an ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/ virtual void accept(ConstAttributeFunctor& af) const; + /** return true, osg::GeoSet does support accept(PrimitiveFunctor&) .*/ + virtual bool supports(PrimitiveFunctor&) const { return true; } + /** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/ virtual void accept(PrimitiveFunctor& pf) const; @@ -362,7 +371,7 @@ class SG_EXPORT GeoSet : public Drawable mutable int _numcoords; Vec3 *_coords; - IndexPointer _cindex; + mutable IndexPointer _cindex; BindingType _normal_binding; mutable int _numnormals; @@ -388,8 +397,8 @@ class SG_EXPORT GeoSet : public Drawable int _fast_path; void set_fast_path( void ); - void draw_fast_path( State& state ); - void draw_alternate_path( State& state ); + void draw_fast_path( State& state ) const; + void draw_alternate_path( State& state ) const; }; diff --git a/include/osg/Geometry b/include/osg/Geometry index a3c64658d..b579eed46 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -161,7 +161,7 @@ class SG_EXPORT Geometry : public Drawable * This is the internal draw method which does the drawing itself, * and is the method to override when deriving from Geometry for user-drawn objects. */ - virtual void drawImmediateMode(State& state); + virtual void drawImplementation(State& state) const; /** return true, osg::Geometry does support accept(AttributeFunctor&).*/ virtual bool supports(AttributeFunctor&) const { return true; } diff --git a/include/osg/ImpostorSprite b/include/osg/ImpostorSprite index f92b4a8b1..aff30807f 100644 --- a/include/osg/ImpostorSprite +++ b/include/osg/ImpostorSprite @@ -114,7 +114,7 @@ class SG_EXPORT ImpostorSprite : public Drawable int t() const { return _t; } /** draw ImpostorSprite directly. */ - virtual void drawImmediateMode(State& state); + virtual void drawImplementation(State& state) const; /** return true, osg::ImpostorSprite does support accept(AttributeFunctor&).*/ virtual bool supports(AttributeFunctor&) const { return true; } diff --git a/include/osg/ShapeDrawable b/include/osg/ShapeDrawable index e36665b97..638f7701e 100644 --- a/include/osg/ShapeDrawable +++ b/include/osg/ShapeDrawable @@ -124,7 +124,7 @@ class SG_EXPORT ShapeDrawable : public Drawable * This is the internal draw method which does the drawing itself, * and is the method to override when deriving from ShapeDrawable for user-drawn objects. */ - virtual void drawImmediateMode(State& state); + virtual void drawImplementation(State& state) const; /** return false, osg::ProceduralGeoemtry does not support accept(AttributeFunctor&).*/ virtual bool supports(AttributeFunctor&) const { return false; } diff --git a/include/osgParticle/Particle b/include/osgParticle/Particle index 82584a520..8d5fcef6d 100644 --- a/include/osgParticle/Particle +++ b/include/osgParticle/Particle @@ -164,13 +164,13 @@ namespace osgParticle bool update(double dt); /// Perform some pre-rendering tasks. Called automatically by particle systems. - inline void beginRender(); + inline void beginRender() const; /// Render the particle. Called automatically by particle systems. void render(const osg::Vec3 &xpos, const osg::Vec3 &px, const osg::Vec3 &py, float scale = 1.0f) const; /// Perform some post-rendering tasks. Called automatically by particle systems. - inline void endRender(); + inline void endRender() const; /// Get the current (interpolated) polygon size. Valid only after the first call to update(). inline float getCurrentSize() const; @@ -369,7 +369,7 @@ namespace osgParticle massinv_ = 1 / m; } - inline void Particle::beginRender() + inline void Particle::beginRender() const { switch (shape_) { @@ -383,7 +383,7 @@ namespace osgParticle } } - inline void Particle::endRender() + inline void Particle::endRender() const { switch (shape_) { diff --git a/include/osgParticle/ParticleSystem b/include/osgParticle/ParticleSystem index 845a12b6b..3efd0449e 100644 --- a/include/osgParticle/ParticleSystem +++ b/include/osgParticle/ParticleSystem @@ -149,9 +149,9 @@ namespace osgParticle ParticleSystem &operator=(const ParticleSystem &) { return *this; } inline virtual bool computeBound() const; - virtual void drawImmediateMode(osg::State &state); + virtual void drawImplementation(osg::State &state) const; inline void update_bounds(const osg::Vec3 &p, float r); - void single_pass_render(osg::State &state, const osg::Matrix &modelview); + void single_pass_render(osg::State &state, const osg::Matrix &modelview) const; private: typedef std::vector Particle_vector; @@ -176,11 +176,11 @@ namespace osgParticle bool bounds_computed_; Particle def_ptemp_; - int last_frame_; + mutable int last_frame_; bool freeze_on_cull_; int detail_; - int draw_count_; + mutable int draw_count_; }; diff --git a/include/osgText/Font b/include/osgText/Font index 7c6df525b..9f2445b95 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -73,7 +73,7 @@ class OSGTEXT_EXPORT Font : public osg::Object virtual bool create(osg::State& state,int pointSize, unsigned int res = 72 ); virtual bool create(osg::State& state); - virtual void output(osg::State& state,const char* text); + virtual void output(osg::State& state,const char* text) const; virtual bool isOk(void) const { return _init; } virtual bool isCreated(void) const { return isOk() && _created; } diff --git a/include/osgText/Text b/include/osgText/Text index eaa768be2..17d5026ee 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -101,9 +101,9 @@ class OSGTEXT_EXPORT Text : public osg::Drawable void setText(const std::string& text) { _text=text; _initAlignment=false; } const std::string& getText() const { return _text; } - virtual void drawImmediateMode(osg::State& state); - virtual void drawBoundingBox(void); - virtual void drawAlignment(void); + virtual void drawImplementation(osg::State& state) const; + virtual void drawBoundingBox(void) const; + virtual void drawAlignment(void) const; const osg::Vec3& getAlignmentPos() const { return _alignmentPos; }; diff --git a/src/Demos/osgcallback/osgcallback.cpp b/src/Demos/osgcallback/osgcallback.cpp index 45fece80f..26cf4bd62 100644 --- a/src/Demos/osgcallback/osgcallback.cpp +++ b/src/Demos/osgcallback/osgcallback.cpp @@ -71,11 +71,11 @@ class CullCallback : public osg::NodeCallback class DrawableDrawCallback : public osg::Drawable::DrawCallback { - virtual void drawImmediateMode(osg::State& state,osg::Drawable* drawable) const + virtual void drawImplementation(osg::State& state,const osg::Drawable* drawable) const { - std::cout<<"draw call back - pre drawImmediateMode"<drawImmediateMode(state); - std::cout<<"draw call back - post drawImmediateMode"<drawImplementation(state); + std::cout<<"draw call back - post drawImplementation"<drawImmediateMode(state,this); + _drawCallback->drawImplementation(state,this); else - drawImmediateMode(state); + drawImplementation(state); glEndList(); diff --git a/src/osg/GeoSet.cpp b/src/osg/GeoSet.cpp index ebd34710e..f52ffda40 100644 --- a/src/osg/GeoSet.cpp +++ b/src/osg/GeoSet.cpp @@ -247,7 +247,7 @@ void GeoSet::setTextureBinding( BindingType binding ) set_fast_path(); } -void GeoSet::drawImmediateMode(State& state) +void GeoSet::drawImplementation(State& state) const { if( _coords == (Vec3 *)0 && _iaformat == IA_OFF ) return; diff --git a/src/osg/GeoSet_ogl.cpp b/src/osg/GeoSet_ogl.cpp index 5156922cc..5e38ec580 100644 --- a/src/osg/GeoSet_ogl.cpp +++ b/src/osg/GeoSet_ogl.cpp @@ -81,7 +81,7 @@ void GeoSet::set_fast_path( void ) } -void GeoSet::draw_fast_path( State& state ) +void GeoSet::draw_fast_path( State& state ) const { IndexPointer ocindex = _cindex; @@ -264,7 +264,7 @@ void GeoSet::draw_fast_path( State& state ) } -void GeoSet::draw_alternate_path( State& state ) +void GeoSet::draw_alternate_path( State& state ) const { if( (_color_binding == BIND_PERVERTEX) && (_colindex.null() || _colindex ==_cindex) && (_flat_shaded_skip == 0) ) { diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 2fc7e5cc8..df46b67ae 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -360,7 +360,7 @@ bool Geometry::areFastPathsUsed() const return _fastPath; } -void Geometry::drawImmediateMode(State& state) +void Geometry::drawImplementation(State& state) const { if (!_vertexArray.valid() || _vertexArray->getNumElements()==0) return; if (_vertexIndices.valid() && _vertexIndices->getNumElements()==0) return; @@ -449,7 +449,7 @@ void Geometry::drawImmediateMode(State& state) unsigned int unit; for(unit=0;unit<_texCoordList.size();++unit) { - Array* array = _texCoordList[unit].first.get(); + const Array* array = _texCoordList[unit].first.get(); if (array) state.setTexCoordPointer(unit,array->getDataSize(),array->getDataType(),0,array->getDataPointer()); else @@ -472,7 +472,7 @@ void Geometry::drawImmediateMode(State& state) // // draw the primitives themselves. // - for(PrimitiveSetList::iterator itr=_primitives.begin(); + for(PrimitiveSetList::const_iterator itr=_primitives.begin(); itr!=_primitives.end(); ++itr) { @@ -590,7 +590,7 @@ void Geometry::drawImmediateMode(State& state) // // draw the primitives themselves. // - for(PrimitiveSetList::iterator itr=_primitives.begin(); + for(PrimitiveSetList::const_iterator itr=_primitives.begin(); itr!=_primitives.end(); ++itr) { @@ -599,7 +599,7 @@ void Geometry::drawImmediateMode(State& state) if (secondaryColorBinding==BIND_PER_PRIMITIVE_SET) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_PER_PRIMITIVE_SET) drawFogCoord(fogCoordIndex++); - PrimitiveSet* primitiveset = itr->get(); + const PrimitiveSet* primitiveset = itr->get(); GLenum mode=primitiveset->getMode(); unsigned int primLength; diff --git a/src/osg/ImpostorSprite.cpp b/src/osg/ImpostorSprite.cpp index 9d6073589..90a47feaa 100644 --- a/src/osg/ImpostorSprite.cpp +++ b/src/osg/ImpostorSprite.cpp @@ -61,7 +61,7 @@ float ImpostorSprite::calcPixelError(const Matrix& MVPW) const return sqrtf(max_error_sqrd); } -void ImpostorSprite::drawImmediateMode(State&) +void ImpostorSprite::drawImplementation(State&) const { // when the tex env is set to REPLACE, and the // texture is set up correctly the color has no effect. diff --git a/src/osg/ShapeDrawable.cpp b/src/osg/ShapeDrawable.cpp index 5c0ceb10c..7e82acd3a 100644 --- a/src/osg/ShapeDrawable.cpp +++ b/src/osg/ShapeDrawable.cpp @@ -1251,7 +1251,7 @@ ShapeDrawable::~ShapeDrawable() { } -void ShapeDrawable::drawImmediateMode(State& state) +void ShapeDrawable::drawImplementation(State& state) const { if (_shape.valid()) { diff --git a/src/osgGLUT/Window.cpp b/src/osgGLUT/Window.cpp index 45cb0dfc7..4f6f459fa 100644 --- a/src/osgGLUT/Window.cpp +++ b/src/osgGLUT/Window.cpp @@ -142,7 +142,7 @@ void Window::keyboardCB(unsigned char key, int x, int y) s_theWindow->check_if_exit(); } -void Window::specialCB(int key, int x, int y) +void Window::specialCB(int, int, int) { // s_theWindow->special(key,x,y); // s_theWindow->check_if_exit(); diff --git a/src/osgParticle/ParticleSystem.cpp b/src/osgParticle/ParticleSystem.cpp index 046363a85..a5faa04b3 100644 --- a/src/osgParticle/ParticleSystem.cpp +++ b/src/osgParticle/ParticleSystem.cpp @@ -87,7 +87,7 @@ void osgParticle::ParticleSystem::update(double dt) dirtyBound(); } -void osgParticle::ParticleSystem::drawImmediateMode(osg::State &state) +void osgParticle::ParticleSystem::drawImplementation(osg::State &state) const { // update the frame count, so other objects can detect when // this particle system is culled @@ -160,14 +160,14 @@ void osgParticle::ParticleSystem::setDefaultAttributes(const std::string &textur } -void osgParticle::ParticleSystem::single_pass_render(osg::State & /*state*/, const osg::Matrix &modelview) +void osgParticle::ParticleSystem::single_pass_render(osg::State & /*state*/, const osg::Matrix &modelview) const { draw_count_ = 0; if (particles_.size() <= 0) return; - Particle_vector::iterator i; - Particle_vector::iterator i0 = particles_.begin(); - Particle_vector::iterator end = particles_.end(); + Particle_vector::const_iterator i; + Particle_vector::const_iterator i0 = particles_.begin(); + Particle_vector::const_iterator end = particles_.end(); i0->beginRender(); diff --git a/src/osgPlugins/ac3d/ac3d.cpp b/src/osgPlugins/ac3d/ac3d.cpp index 912845e45..22a9ae829 100644 --- a/src/osgPlugins/ac3d/ac3d.cpp +++ b/src/osgPlugins/ac3d/ac3d.cpp @@ -602,10 +602,10 @@ osg::Group *ac_load_object(FILE *f,const ACObject *parent) (*vgeom).push_back((*vertpool)[i1]); (*tgeom).push_back((*tcs)[i]); } - GLenum poltype=osg::Primitive::POLYGON; - if (asurf.flags & SURFACE_TYPE_CLOSEDLINE) poltype=osg::Primitive::LINE_LOOP; - if (asurf.flags & SURFACE_TYPE_LINE) poltype=osg::Primitive::LINE_STRIP; - geom->addPrimitive(new osg::DrawArrays(poltype,nstart,asurf.num_vertref)); + GLenum poltype=osg::PrimitiveSet::POLYGON; + if (asurf.flags & SURFACE_TYPE_CLOSEDLINE) poltype=osg::PrimitiveSet::LINE_LOOP; + if (asurf.flags & SURFACE_TYPE_LINE) poltype=osg::PrimitiveSet::LINE_STRIP; + geom->addPrimitiveSet(new osg::DrawArrays(poltype,nstart,asurf.num_vertref)); if (asurf.flags & 0x10) needSmooth++; } } diff --git a/src/osgPlugins/geo/ReaderWriterGEO.cpp b/src/osgPlugins/geo/ReaderWriterGEO.cpp index a5c0f92da..42b97c63f 100644 --- a/src/osgPlugins/geo/ReaderWriterGEO.cpp +++ b/src/osgPlugins/geo/ReaderWriterGEO.cpp @@ -262,7 +262,7 @@ class ReaderWriterGEO : public ReaderWriter ia.push_back(txidx); // look up table for which texture corresponds to which geom } int nv=getprim((*itr)->getchildren(),vinf); - geom[igeom]->addPrimitive(new osg::DrawArrays(osg::Primitive::POLYGON,nstart,nv)); + geom[igeom]->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,nv)); nstart+=nv; } } diff --git a/src/osgPlugins/logos/ReaderWriterLOGO.cpp b/src/osgPlugins/logos/ReaderWriterLOGO.cpp index f18f8d14c..750f30da8 100644 --- a/src/osgPlugins/logos/ReaderWriterLOGO.cpp +++ b/src/osgPlugins/logos/ReaderWriterLOGO.cpp @@ -79,7 +79,7 @@ class Logos: public osg::Drawable virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } virtual const char* className() const { return "Logos"; } - virtual void drawImmediateMode( osg::State &state ) + virtual void drawImplementation(osg::State &state ) const { if( state.getContextID() != _contextID ) return; @@ -100,7 +100,7 @@ class Logos: public osg::Drawable glPushMatrix(); glLoadIdentity(); - std::vector ::iterator p; + std::vector ::const_iterator p; float th = 0.0; for( p = logos[Center].begin(); p != logos[Center].end(); p++ ) th += (*p)->t(); diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 748e085b9..5a0a73686 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -174,12 +174,17 @@ bool Font::create(osg::State& state) return false; } -void Font::output(osg::State& state,const char* text) +void Font::output(osg::State& state,const char* text) const { if(_created) _font->render(text,state.getContextID()); else - create(state,_pointSize); + { + // ahhhh, this is bit doddy, the draw is potentially + // modifying the text object, this isn't thread safe. + Font* this_non_const = const_cast(this); + this_non_const->create(state,_pointSize); + } } void Font::clear() diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 5e1ef1c9b..a2fb9f4ca 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -168,19 +168,23 @@ bool Text::computeBound() const return true; } -void Text::drawImmediateMode(State& state) +void Text::drawImplementation(State& state) const { if(!_init) return; + // ahhhh, this is bit doddy, the draw is potentially + // modifying the text object, this isn't thread safe. + Text* this_non_const = const_cast(this); + if(!_font->isCreated()) { - _font->create(state); - dirtyBound(); + this_non_const->_font->create(state); + this_non_const->dirtyBound(); } if(!_initAlignment) - initAlignment(); + this_non_const->initAlignment(); // we must disable all the vertex arrays to prevent any state // propagating into text. @@ -229,8 +233,7 @@ void Text::drawImmediateMode(State& state) } } -void Text:: -drawBoundingBox(void) +void Text::drawBoundingBox(void) const { if(!_init) return; @@ -247,8 +250,7 @@ drawBoundingBox(void) glPopAttrib(); } -void Text:: -drawAlignment(void) +void Text::drawAlignment(void) const { if(!_init) return;