GNU Octave  4.0.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-2015 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 #ifdef HAVE_GL_GLEXT_H
44 #include <GL/glext.h>
45 #elif defined HAVE_OPENGL_GLEXT_H || defined HAVE_FRAMEWORK_OPENGL
46 #include <OpenGL/glext.h>
47 #endif
48 
49 #include "graphics.h"
50 #include "txt-eng-ft.h"
51 
52 #if defined (HAVE_OPENGL)
53 
54 class
57 {
58 public:
59  opengl_renderer (void)
60  : toolkit (), xform (), xmin (), xmax (), ymin (), ymax (),
61  zmin (), zmax (), xZ1 (), xZ2 (), marker_id (), filled_marker_id (),
62  camera_pos (), camera_dir ()
63 #if HAVE_FREETYPE
64  , text_renderer ()
65 #endif
66  { }
67 
68  virtual ~opengl_renderer (void) { }
69 
70  virtual void draw (const graphics_object& go, bool toplevel = true);
71 
72  virtual void draw (const Matrix& hlist, bool toplevel = false)
73  {
74  int len = hlist.length ();
75 
76  for (int i = len-1; i >= 0; i--)
77  {
78  graphics_object obj = gh_manager::get_object (hlist(i));
79 
80  if (obj)
81  draw (obj, toplevel);
82  }
83  }
84 
85  virtual void set_viewport (int w, int h);
86  virtual graphics_xform get_transform (void) const { return xform; }
87 
88 protected:
89  virtual void draw_figure (const figure::properties& props);
90  virtual void draw_axes (const axes::properties& props);
91  virtual void draw_line (const line::properties& props);
92  virtual void draw_surface (const surface::properties& props);
93  virtual void draw_patch (const patch::properties& props);
94  virtual void draw_hggroup (const hggroup::properties& props);
95  virtual void draw_text (const text::properties& props);
96  virtual void draw_image (const image::properties& props);
97  virtual void draw_uipanel (const uipanel::properties& props,
98  const graphics_object& go);
99 
100  virtual void init_gl_context (bool enhanced, const Matrix& backgroundColor);
101  virtual void setup_opengl_transformation (const axes::properties& props);
102 
103  virtual void set_color (const Matrix& c);
104  virtual void set_polygon_offset (bool on, float offset = 0.0f);
105  virtual void set_linewidth (float w);
106  virtual void set_linestyle (const std::string& s, bool stipple = false);
107  virtual void set_clipbox (double x1, double x2, double y1, double y2,
108  double z1, double z2);
109  virtual void set_clipping (bool on);
110  virtual void set_font (const base_properties& props);
111 
112  virtual void init_marker (const std::string& m, double size, float width);
113  virtual void end_marker (void);
114  virtual void draw_marker (double x, double y, double z,
115  const Matrix& lc, const Matrix& fc);
116 
117  virtual void text_to_pixels (const std::string& txt,
118  uint8NDArray& pixels,
119  Matrix& bbox,
120  int halign = 0, int valign = 0,
121  double rotation = 0.0);
122 
123  virtual Matrix render_text (const std::string& txt,
124  double x, double y, double z,
125  int halign, int valign, double rotation = 0.0);
126 
127  virtual void draw_pixels (GLsizei w, GLsizei h, GLenum format,
128  GLenum type, const GLvoid *data);
129 
130  virtual void render_grid (const std::string& gridstyle, const Matrix& ticks,
131  double lim1, double lim2,
132  double p1, double p1N, double p2, double p2N,
133  int xyz, bool is_3D);
134 
135  virtual void render_tickmarks (const Matrix& ticks, double lim1, double lim2,
136  double p1, double p1N, double p2, double p2N,
137  double dx, double dy, double dz,
138  int xyz, bool doubleside);
139 
140  virtual void render_ticktexts (const Matrix& ticks,
141  const string_vector& ticklabels,
142  double lim1, double lim2,
143  double p1, double p2,
144  int xyz, int ha, int va,
145  int& wmax, int& hmax);
146 
147 private:
149  : toolkit (), xform (), xmin (), xmax (), ymin (), ymax (),
150  zmin (), zmax (), xZ1 (), xZ2 (), marker_id (), filled_marker_id (),
151  camera_pos (), camera_dir ()
152 #if HAVE_FREETYPE
153  , text_renderer ()
154 #endif
155  { }
156 
157  opengl_renderer& operator = (const opengl_renderer&)
158  { return *this; }
159 
160  bool is_nan_or_inf (double x, double y, double z) const
161  {
162  return (xisnan (x) || xisnan (y) || xisnan (z)
163  || xisinf (x) || xisinf (y) || xisinf (z));
164  }
165 
166  octave_uint8 clip_code (double x, double y, double z) const
167  {
168  return ((x < xmin ? 1 : 0)
169  | (x > xmax ? 1 : 0) << 1
170  | (y < ymin ? 1 : 0) << 2
171  | (y > ymax ? 1 : 0) << 3
172  | (z < zmin ? 1 : 0) << 4
173  | (z > zmax ? 1 : 0) << 5
174  | (is_nan_or_inf (x, y, z) ? 0 : 1) << 6);
175  }
176 
177  unsigned int make_marker_list (const std::string& m, double size,
178  bool filled) const;
179 
180  void draw_axes_planes (const axes::properties& props);
181  void draw_axes_boxes (const axes::properties& props);
182 
183  void draw_axes_x_grid (const axes::properties& props);
184  void draw_axes_y_grid (const axes::properties& props);
185  void draw_axes_z_grid (const axes::properties& props);
186 
187  void draw_axes_children (const axes::properties& props);
188 
189 private:
190  // The graphics toolkit associated with the figure being rendered.
191  graphics_toolkit toolkit;
192 
193  // axes transformation data
195 
196  // axis limits in model scaled coordinate
197  double xmin, xmax;
198  double ymin, ymax;
199  double zmin, zmax;
200 
201  // Z projection limits in windows coordinate
202  double xZ1, xZ2;
203 
204  // call lists identifiers for markers
205  unsigned int marker_id, filled_marker_id;
206 
207  // camera information for primitive sorting
208  ColumnVector camera_pos, camera_dir;
209 
210 #if HAVE_FREETYPE
211  // FreeType render, used for text rendering
212  ft_render text_renderer;
213 #endif
214 
215 private:
216  class patch_tesselator;
217 };
218 
219 #endif
220 
221 #endif
bool xisnan(double x)
Definition: lo-mappers.cc:144
Complex xmax(const Complex &x, const Complex &y)
Definition: lo-mappers.cc:269
bool xisinf(double x)
Definition: lo-mappers.cc:160
Complex xmin(const Complex &x, const Complex &y)
Definition: lo-mappers.cc:263
F77_RET_T const double const double * f
#define OCTINTERP_API
Definition: mexproto.h:66
std::complex< double > w(std::complex< double > z, double relerr=0)
Definition: dMatrix.h:35
size_t size(T const (&)[z])
Definition: help.cc:103
static bool is_nan_or_inf(const octave_value &val)
Definition: oct-stream.cc:2424
octave_idx_type length(void) const
Number of elements in the array.
Definition: Array.h:267
static graphics_object get_object(double val)
Definition: graphics.h:13212
void xform(ColumnVector &v, const Matrix &m)
Definition: graphics.cc:5293
F77_RET_T const double * x