Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

flat_shade.H

Go to the documentation of this file.
00001 #ifndef FLAT_SHADE_H_IS_INCLUDED
00002 #define FLAT_SHADE_H_IS_INCLUDED
00003 
00004 /*!
00005  *  \file flat_shade.H
00006  *  \brief Contains the definition of the FlatShadeTexture GTexture and related
00007  *  classes.
00008  *
00009  *  \sa flat_shade.C
00010  *
00011  */
00012 
00013 #include "basic_texture.H"
00014 #include "gl_sphir_tex_coord_gen.H"
00015 
00016 /*!
00017  *  \brief A callback class for rendering each face of a Patch with a flat
00018  *  shading style.
00019  *
00020  *  This is the GLStripCB for the FlatShadeTexture GTexture.
00021  *
00022  *  \sa FlatShadeTexture
00023  *
00024  */
00025 class FlatShadeStripCB : public GLStripCB {
00026    
00027    public:
00028    
00029       FlatShadeStripCB() : do_texcoords(false) 
00030      {
00031        auto_UV = new GLSphirTexCoordGen;
00032        auto_UV->setup();
00033        use_auto=false;
00034      }
00035 
00036      ~FlatShadeStripCB() 
00037      {
00038         delete auto_UV;
00039      }
00040       
00041       //! \name Accessor Functions
00042       //@{
00043       
00044       void enable_texcoords() { do_texcoords = true; }
00045       void disable_texcoords() { do_texcoords = false; }
00046       bool texcoords_enabled() { return do_texcoords; }
00047 
00048      void enable_autoUV() { use_auto = true; }
00049      void disable_autoUV() { use_auto =false; }
00050      bool autoUV_enabled() { return use_auto; }
00051       
00052       //@}
00053       
00054       //! \name Callback Hooks
00055       //@{
00056    
00057       virtual void faceCB(CBvert* v, CBface* f);
00058       
00059       //@}
00060       
00061    private:
00062    
00063       //! Should texture coordinates be sent to OpenGL with each vertex?
00064       bool do_texcoords;
00065      bool use_auto;
00066      TexCoordGen* auto_UV;
00067 
00068 };
00069 
00070 /*!
00071  *  \brief A GTexture that renders Patches in a flat shaded style.
00072  *
00073  */
00074 class FlatShadeTexture : public BasicTexture {
00075    
00076    public:
00077    
00078       FlatShadeTexture(Patch* patch = 0, StripCB* cb=0) :
00079          BasicTexture(patch, cb ? cb : new FlatShadeStripCB),
00080          _debug_uv_in_dl(false),
00081          _has_uv_coords(false),
00082          _check_uv_coords_stamp(0) {}
00083       
00084       virtual ~FlatShadeTexture();
00085       
00086       //! \name Run-Time Type Id
00087       //@{
00088             
00089       DEFINE_RTTI_METHODS3("Flat Shading", FlatShadeTexture*, BasicTexture, CDATA_ITEM*);
00090 
00091       
00092       //@}
00093       
00094       //! \name Statics
00095       //@{
00096       
00097       static void toggle_debug_uv() { _debug_uv = !_debug_uv; }
00098       static bool debug_uv()        { return _debug_uv; }
00099       
00100       //@}
00101       
00102       //! \name GTexture Virtual Methods
00103       //@{
00104       
00105       virtual int draw(CVIEWptr& v);
00106       
00107       //@}
00108       
00109       //! \name DATA_ITEM Virtual Methods
00110       //@{
00111       
00112       virtual DATA_ITEM  *dup() const { return new FlatShadeTexture; }
00113       
00114       //@}
00115 
00116    protected:
00117    
00118       //! True if "debug uv" calls are in current display list.
00119       bool         _debug_uv_in_dl;
00120       
00121       //! True if some faces have uv-coords.
00122       bool         _has_uv_coords;
00123       
00124       //! _patch->stamp() at last check for uv-coords.
00125       uint         _check_uv_coords_stamp;
00126       TEXTUREptr   _debug_uv_tex;   //!< texture image for revealing uv-coords
00127       str_ptr      _debug_tex_path; //!< path to above image
00128       
00129       //! Tells whether to make "debug uv" calls when rendering:
00130       static bool _debug_uv;
00131 
00132 };
00133 
00134 #endif // FLAT_SHADE_H_IS_INCLUDED
00135 
00136 /* end of file flat_shade.H */
00137 

Generated on Mon Sep 18 11:39:29 2006 for jot by  doxygen 1.4.4