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

gl_view.H

Go to the documentation of this file.
00001 #ifndef GL_VIEW_H
00002 #define GL_VIEW_H
00003 
00004 #include "std/config.H"
00005 #include "disp/view.H"
00006 #include "geom/winsys.H"
00007 #include "geom/appear.H"
00008 #include "geom/gl_util.H"
00009 
00010 MAKE_PTR_SUBC(GL_VIEW, VIEW);
00011 typedef const GL_VIEWptr CGL_VIEWptr;
00012 //----------------------------------------------
00013 //
00014 //  GL_VIEW- is a GL-specific VIEW drawing implementation.
00015 //
00016 //----------------------------------------------
00017 class GL_VIEW: public VIEWimpl {
00018  public:
00019    GL_VIEW() :
00020       _paintResize(false),
00021       _resizePending(false),
00022       _focusPending(false),
00023       _resizeW(0),
00024       _resizeH(0),
00025       _resizeX(0),
00026       _resizeY(0) {}
00027 
00028    virtual         ~GL_VIEW()                     { }
00029     
00030    virtual void     set_size(int w, int h, int x, int y);
00031    virtual void     set_cursor(int i)             { _view->win()->set_cursor(i); }
00032    virtual int      get_cursor()                  { return _view->win()->get_cursor(); }
00033    virtual void     set_stereo(stereo_mode m)     { _view->win()->stereo(m); }
00034    virtual void     set_focus()                   { _focusPending = true; }
00035    virtual int      paint();
00036    virtual void     swap_buffers();
00037    virtual void     prepare_buf_read();
00038    virtual void     end_buf_read();
00039    virtual void     read_pixels(uchar *,bool alpha=false);
00040    virtual int      stencil_draw(STENCILCB *, GELlist *objs= 0);
00041 
00042    static  double   gl_version();
00043    static  bool     poly_ext_available();
00044    static  void     init_polygon_offset()
00045    {
00046       static float factor = (float) Config::get_var_dbl("BMESH_OFFSET_FACTOR", 1.0,true);
00047       static float units  = (float) Config::get_var_dbl("BMESH_OFFSET_UNITS", 1.0,true);
00048       GLenum mode  = GL_POLYGON_OFFSET_FILL;
00049       init_polygon_offset(factor,units,mode);
00050    }
00051    static  void     init_polygon_offset(float factor,float units,GLenum mode  = GL_POLYGON_OFFSET_FILL);
00052    static  void     end_polygon_offset();
00053 
00054    //******** ANTIALIASED POINTS AND LINES ********
00055 
00056    // The following turn on antialiasing for points and lines,
00057    // respectively, and set the point size or line width to the given
00058    // amount. They Call glPushAttrib() with needed bits. Caller can
00059    // have other attributes pushed by setting them in the 'mask'
00060    // parameter -- i.e. these functions can be used in place of calls
00061    // to glPushAttrib().
00062    //
00063    // In case the point size or line width is below the minimum value
00064    // supported by OpenGL, and a != NULL, they set *a to the fraction
00065    // size/min_size (or width/min_width). This can be used by the
00066    // caller to reduce the opacity of the point or line in lieu of
00067    // reducing the point size or line width (by setting alpha = *a).
00068    //
00069    // calls glPushAttrib with: mask |
00070    //   GL_ENABLE_BIT | GL_POINT_BIT | GL_HINT_BIT | GL_COLOR_BUFFER_BIT
00071    static  void init_point_smooth(GLfloat size, GLbitfield mask=0, GLfloat* a=0);
00072 
00073    // XXX - g++ 4.0 on Mac OS X insists that the following function
00074    // not be defined in the .C file (because then g++ "can't find" it).
00075    // So we jump thru a hoop and define it entirely in the .H file:
00076    //
00077    // calls glPushAttrib with: mask |
00078    //   GL_ENABLE_BIT | GL_LINE_BIT  | GL_HINT_BIT | GL_COLOR_BUFFER_BIT
00079    static  void init_line_smooth(GLfloat width, GLbitfield mask=0, GLfloat* a=0) {
00080       // Turns on antialiasing for lines and sets the line width to the
00081       // given amount. Calls glPushAttrib() with GL_ENABLE_BIT,
00082       // GL_LINE_BIT and GL_COLOR_BUFFER_BIT along with whatever bits
00083       // are passed in with 'mask'.
00084 
00085       check_line_widths();
00086 
00087       width = max(GLfloat(0), width);
00088 
00089       glPushAttrib(mask | GL_ENABLE_BIT | GL_LINE_BIT |
00090                    GL_HINT_BIT | GL_COLOR_BUFFER_BIT);
00091       glEnable(GL_LINE_SMOOTH);                          // GL_ENABLE_BIT
00092       glEnable(GL_BLEND);                                // GL_ENABLE_BIT
00093       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_COLOR_BUFFER_BIT
00094       glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);            // GL_HINT_BIT
00095       if (width > _max_line_width) {
00096          width = _max_line_width;
00097       } else if (width < _min_line_width) {
00098          if (a) {
00099             *a = (width/_min_line_width);
00100          }
00101          width = _min_line_width;
00102       }
00103 
00104       glLineWidth(width);                  // GL_LINE_BIT
00105    }
00106 
00107    // the following both call glPopAttrib():
00108    static  void end_point_smooth();
00109    static  void end_line_smooth();
00110 
00111    // Draws given points as disconnected dots w/ given
00112    // color, transparency and size. Assumes projection and
00113    // modelview matrices have been set as needed.
00114    static void draw_pts(
00115       mlib::CWpt_list&   pts,    // points to draw
00116       CCOLOR&      color,  // color to use
00117       double       alpha,  // transparency
00118       double       size    // width of points
00119       );
00120 
00121    // Draws a Wpt_list w/ given color, transparency and
00122    // width. If do_stipple is set to true, the Wpt_list is
00123    // drawn stippled. Assumes projection and modelview
00124    // matrices have been set as needed.
00125    static void draw_wpt_list(
00126       mlib::CWpt_list&     pts,        // polyline to draw
00127       CCOLOR&        color,      // color to use
00128       double         alpha,      // transparency
00129       double         width,      // width of points
00130       bool           do_stipple  // if true, draw tippled
00131       );
00132 
00133    // Draws given lines w/ given color, transparency and width. If
00134    // do_stipple is set to true, the lines are drawn stippled. Assumes
00135    // projection and modelview matrices have been set as needed.
00136    static void draw_lines(
00137       CARRAY<mlib::Wline>& lines,      // lines to draw
00138       CCOLOR&        color,      // color to use
00139       double         alpha,      // transparency
00140       double         width,      // width of points
00141       bool           do_stipple  // if true, draw tippled
00142       );
00143 
00144    static int depth_compare(const void *a, const void *b);
00145 
00146    // Draws the given bounding box:
00147    virtual void     draw_bb(mlib::CWpt_list &) const;
00148 
00149    //******** DIAGNOSTIC ********
00150    static  bool   print_gl_errors(Cstr_ptr&);
00151 
00152   protected:
00153    void            setup_light(int i);
00154 
00155    virtual void    setup_lights(CAMdata::eye=CAMdata::MIDDLE);
00156    virtual void    sort_blended_objects(CGELlist &);
00157 
00158    virtual void    clear_draw_buffer();
00159    virtual void    setup_stencil();
00160    virtual void    setup_scissor();
00161 
00162    virtual void    draw_setup();
00163    virtual int     draw_frame  (            CAMdata::eye = CAMdata::MIDDLE);
00164    virtual int     draw_objects(CGELlist &, CAMdata::eye = CAMdata::MIDDLE);
00165 
00166    virtual void    load_proj_mat(CAMdata::eye);
00167    virtual void    load_cam_mat (CAMdata::eye);
00168 
00169    static bool _checked_point_sizes;
00170    static bool _checked_line_widths;
00171    static GLfloat _min_point_size;
00172    static GLfloat _max_point_size;
00173    static GLfloat _min_line_width;
00174    static GLfloat _max_line_width;
00175 
00176    bool _paintResize;
00177    bool _resizePending;
00178    bool _focusPending;
00179    int  _resizeW, _resizeH, _resizeX, _resizeY;
00180    // For transparency sorting
00181    GELlist _opaque;
00182    GELlist _blended;
00183 
00184    static void check_point_sizes();
00185    static void check_line_widths();
00186 };
00187 
00188 #endif // GL_VIEW_H
00189 
00190 // end of file gl_view.H
00191 

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