Name change and const change of Drawable::drawImmediateMode(State&) to

Drawable::drawImplementation(State&) const.   Various updates to the
rest of the OSG to accomodate this.
This commit is contained in:
Robert Osfield
2002-11-06 15:43:11 +00:00
parent e34ecafb1e
commit 3bd400130c
26 changed files with 112 additions and 74 deletions

View File

@@ -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:

View File

@@ -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*>(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<Drawable*>(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);
}
};

View File

@@ -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;
};

View File

@@ -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; }

View File

@@ -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; }

View File

@@ -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; }

View File

@@ -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_)
{

View File

@@ -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> 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_;
};

View File

@@ -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; }

View File

@@ -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; };

View File

@@ -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"<<drawable<<std::endl;
drawable->drawImmediateMode(state);
std::cout<<"draw call back - post drawImmediateMode"<<drawable<<std::endl;
std::cout<<"draw call back - pre drawImplementation"<<drawable<<std::endl;
drawable->drawImplementation(state);
std::cout<<"draw call back - post drawImplementation"<<drawable<<std::endl;
}
};

View File

@@ -218,7 +218,7 @@ class Teapot : public osg::Drawable
// the draw immediate mode method is where the OSG wraps up the drawing of
// of OpenGL primitives.
virtual void drawImmediateMode(osg::State&)
virtual void drawImplementation(osg::State&) const
{
// teapot(..) doens't use vertex arrays at all so we don't need to toggle their state
// if we did we'd need to something like following call

View File

@@ -77,7 +77,7 @@ bool DrawPixels::computeBound() const
return true;
}
void DrawPixels::drawImmediateMode(State&)
void DrawPixels::drawImplementation(State&) const
{
glRasterPos3f(_position.x(),_position.y(),_position.z());

View File

@@ -112,9 +112,9 @@ void Drawable::compile(State& state)
glNewList( globj, GL_COMPILE );
if (_drawCallback.valid())
_drawCallback->drawImmediateMode(state,this);
_drawCallback->drawImplementation(state,this);
else
drawImmediateMode(state);
drawImplementation(state);
glEndList();

View File

@@ -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;

View File

@@ -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) )
{

View File

@@ -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;

View File

@@ -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.

View File

@@ -1251,7 +1251,7 @@ ShapeDrawable::~ShapeDrawable()
{
}
void ShapeDrawable::drawImmediateMode(State& state)
void ShapeDrawable::drawImplementation(State& state) const
{
if (_shape.valid())
{

View File

@@ -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();

View File

@@ -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();

View File

@@ -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++;
}
}

View File

@@ -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;
}
}

View File

@@ -79,7 +79,7 @@ class Logos: public osg::Drawable
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Logos*>(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 <osg::Image *>::iterator p;
std::vector <osg::Image *>::const_iterator p;
float th = 0.0;
for( p = logos[Center].begin(); p != logos[Center].end(); p++ )
th += (*p)->t();

View File

@@ -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<Font*>(this);
this_non_const->create(state,_pointSize);
}
}
void Font::clear()

View File

@@ -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<Text*>(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;