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
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
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 static void init_point_smooth(GLfloat size, GLbitfield mask=0, GLfloat* a=0);
00072
00073
00074
00075
00076
00077
00078
00079 static void init_line_smooth(GLfloat width, GLbitfield mask=0, GLfloat* a=0) {
00080
00081
00082
00083
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);
00092 glEnable(GL_BLEND);
00093 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00094 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
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);
00105 }
00106
00107
00108 static void end_point_smooth();
00109 static void end_line_smooth();
00110
00111
00112
00113
00114 static void draw_pts(
00115 mlib::CWpt_list& pts,
00116 CCOLOR& color,
00117 double alpha,
00118 double size
00119 );
00120
00121
00122
00123
00124
00125 static void draw_wpt_list(
00126 mlib::CWpt_list& pts,
00127 CCOLOR& color,
00128 double alpha,
00129 double width,
00130 bool do_stipple
00131 );
00132
00133
00134
00135
00136 static void draw_lines(
00137 CARRAY<mlib::Wline>& lines,
00138 CCOLOR& color,
00139 double alpha,
00140 double width,
00141 bool do_stipple
00142 );
00143
00144 static int depth_compare(const void *a, const void *b);
00145
00146
00147 virtual void draw_bb(mlib::CWpt_list &) const;
00148
00149
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
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
00191