GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
gl-render.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2013 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_gl_render_h)
24 #define octave_gl_render_h 1
25 
26 #ifdef HAVE_WINDOWS_H
27 #define WIN32_LEAN_AND_MEAN
28 #include <windows.h>
29 #endif
30 
31 #ifdef HAVE_GL_GL_H
32 #include <GL/gl.h>
33 #elif defined HAVE_OPENGL_GL_H || defined HAVE_FRAMEWORK_OPENGL
34 #include <OpenGL/gl.h>
35 #endif
36 
37 #ifdef HAVE_GL_GLU_H
38 #include <GL/glu.h>
39 #elif defined HAVE_OPENGL_GLU_H || defined HAVE_FRAMEWORK_OPENGL
40 #include <OpenGL/glu.h>
41 #endif
42 
43 #include "graphics.h"
44 #include "txt-eng-ft.h"
45 
46 class
49 {
50 public:
52  : toolkit (), xform (), xmin (), xmax (), ymin (), ymax (),
53  zmin (), zmax (), xZ1 (), xZ2 (), marker_id (), filled_marker_id (),
54  camera_pos (), camera_dir ()
55 #if HAVE_FREETYPE
56  , text_renderer ()
57 #endif
58  { }
59 
60  virtual ~opengl_renderer (void) { }
61 
62  virtual void draw (const graphics_object& go, bool toplevel = true);
63 
64  virtual void draw (const Matrix& hlist, bool toplevel = false)
65  {
66  int len = hlist.length ();
67 
68  for (int i = len-1; i >= 0; i--)
69  {
70  graphics_object obj = gh_manager::get_object (hlist(i));
71 
72  if (obj)
73  draw (obj, toplevel);
74  }
75  }
76 
77  virtual void set_viewport (int w, int h);
78  virtual graphics_xform get_transform (void) const { return xform; }
79 
80 protected:
81  virtual void draw_figure (const figure::properties& props);
82  virtual void draw_axes (const axes::properties& props);
83  virtual void draw_line (const line::properties& props);
84  virtual void draw_surface (const surface::properties& props);
85  virtual void draw_patch (const patch::properties& props);
86  virtual void draw_hggroup (const hggroup::properties& props);
87  virtual void draw_text (const text::properties& props);
88  virtual void draw_image (const image::properties& props);
89  virtual void draw_uipanel (const uipanel::properties& props,
90  const graphics_object& go);
91 
92  virtual void init_gl_context (bool enhanced, const Matrix& backgroundColor);
93  virtual void setup_opengl_transformation (const axes::properties& props);
94 
95  virtual void set_color (const Matrix& c);
96  virtual void set_polygon_offset (bool on, double offset = 0.0);
97  virtual void set_linewidth (float w);
98  virtual void set_linestyle (const std::string& s, bool stipple = false);
99  virtual void set_clipbox (double x1, double x2, double y1, double y2,
100  double z1, double z2);
101  virtual void set_clipping (bool on);
102  virtual void set_font (const base_properties& props);
103 
104  virtual void init_marker (const std::string& m, double size, float width);
105  virtual void end_marker (void);
106  virtual void draw_marker (double x, double y, double z,
107  const Matrix& lc, const Matrix& fc);
108 
109  virtual void text_to_pixels (const std::string& txt,
110  uint8NDArray& pixels,
111  Matrix& bbox,
112  int halign = 0, int valign = 0,
113  double rotation = 0.0);
114 
115  virtual Matrix render_text (const std::string& txt,
116  double x, double y, double z,
117  int halign, int valign, double rotation = 0.0);
118 
119  virtual void draw_pixels (GLsizei w, GLsizei h, GLenum format,
120  GLenum type, const GLvoid *data);
121 
122  virtual void render_grid (const std::string& gridstyle, const Matrix& ticks,
123  double lim1, double lim2,
124  double p1, double p1N, double p2, double p2N,
125  int xyz, bool is_3D);
126 
127  virtual void render_tickmarks (const Matrix& ticks, double lim1, double lim2,
128  double p1, double p1N, double p2, double p2N,
129  double dx, double dy, double dz,
130  int xyz, bool doubleside);
131 
132  virtual void render_ticktexts (const Matrix& ticks,
133  const string_vector& ticklabels,
134  double lim1, double lim2,
135  double p1, double p2,
136  int xyz, int ha, int va,
137  int& wmax, int& hmax);
138 
139 private:
141  : toolkit (), xform (), xmin (), xmax (), ymin (), ymax (),
142  zmin (), zmax (), xZ1 (), xZ2 (), marker_id (), filled_marker_id (),
143  camera_pos (), camera_dir ()
144 #if HAVE_FREETYPE
145  , text_renderer ()
146 #endif
147  { }
148 
149  opengl_renderer& operator = (const opengl_renderer&)
150  { return *this; }
151 
152  bool is_nan_or_inf (double x, double y, double z) const
153  {
154  return (xisnan (x) || xisnan (y) || xisnan (z)
155  || xisinf (x) || xisinf (y) || xisinf (z));
156  }
157 
158  octave_uint8 clip_code (double x, double y, double z) const
159  {
160  return ((x < xmin ? 1 : 0)
161  | (x > xmax ? 1 : 0) << 1
162  | (y < ymin ? 1 : 0) << 2
163  | (y > ymax ? 1 : 0) << 3
164  | (z < zmin ? 1 : 0) << 4
165  | (z > zmax ? 1 : 0) << 5
166  | (is_nan_or_inf (x, y, z) ? 0 : 1) << 6);
167  }
168 
169  unsigned int make_marker_list (const std::string& m, double size,
170  bool filled) const;
171 
172  void draw_axes_planes (const axes::properties& props);
173  void draw_axes_boxes (const axes::properties& props);
174 
175  void draw_axes_x_grid (const axes::properties& props);
176  void draw_axes_y_grid (const axes::properties& props);
177  void draw_axes_z_grid (const axes::properties& props);
178 
179  void draw_axes_children (const axes::properties& props);
180 
181 private:
182  // The graphics toolkit associated with the figure being rendered.
184 
185  // axes transformation data
187 
188  // axis limits in model scaled coordinate
189  double xmin, xmax;
190  double ymin, ymax;
191  double zmin, zmax;
192 
193  // Z projection limits in windows coordinate
194  double xZ1, xZ2;
195 
196  // call lists identifiers for markers
197  unsigned int marker_id, filled_marker_id;
198 
199  // camera information for primitive sorting
201 
202 #if HAVE_FREETYPE
203  // freetype render, used for text rendering
205 #endif
206 
207 private:
208  class patch_tesselator;
209 };
210 
211 #endif