comparison libinterp/corefcn/gl-render.cc @ 17651:b0f529c3671d

gl-render.cc: Replace custom min function with std::min. * libinterp/corefcn/gl-render.cc(xmin): Delete custom function and replace calling occurrences with std::min. Use standard indent of 2 spaces for constructors.
author Rik <rik@octave.org>
date Mon, 14 Oct 2013 10:44:38 -0700
parents c0ce72efe5a8
children d449f4668b72
comparison
equal deleted inserted replaced
17649:a09511ebf7ef 17651:b0f529c3671d
41 // GLU callback functions. Define it to empty on 41 // GLU callback functions. Define it to empty on
42 // other platforms. 42 // other platforms.
43 #ifndef CALLBACK 43 #ifndef CALLBACK
44 #define CALLBACK 44 #define CALLBACK
45 #endif 45 #endif
46
47 static octave_idx_type
48 xmin (octave_idx_type x, octave_idx_type y)
49 {
50 return x < y ? x : y;
51 }
52 46
53 class 47 class
54 opengl_texture 48 opengl_texture
55 { 49 {
56 protected: 50 protected:
61 : id (), w (), h (), tw (), th (), tx (), ty (), 55 : id (), w (), h (), tw (), th (), tx (), ty (),
62 valid (false), count (1) 56 valid (false), count (1)
63 { } 57 { }
64 58
65 texture_rep (GLuint id_arg, int w_arg, int h_arg, int tw_arg, int th_arg) 59 texture_rep (GLuint id_arg, int w_arg, int h_arg, int tw_arg, int th_arg)
66 : id (id_arg), w (w_arg), h (h_arg), tw (tw_arg), th (th_arg), 60 : id (id_arg), w (w_arg), h (h_arg), tw (tw_arg), th (th_arg),
67 tx (double(w)/tw), ty (double(h)/th), valid (true), 61 tx (double(w)/tw), ty (double(h)/th), valid (true),
68 count (1) { } 62 count (1) { }
69 63
70 ~texture_rep (void) 64 ~texture_rep (void)
71 { 65 {
72 if (valid) 66 if (valid)
73 glDeleteTextures (1, &id); 67 glDeleteTextures (1, &id);
94 88
95 public: 89 public:
96 opengl_texture (void) : rep (new texture_rep ()) { } 90 opengl_texture (void) : rep (new texture_rep ()) { }
97 91
98 opengl_texture (const opengl_texture& tx) 92 opengl_texture (const opengl_texture& tx)
99 : rep (tx.rep) 93 : rep (tx.rep)
100 { 94 {
101 rep->count++; 95 rep->count++;
102 } 96 }
103 97
104 ~opengl_texture (void) 98 ~opengl_texture (void)
149 dim_vector dv (data.dims ()); 143 dim_vector dv (data.dims ());
150 144
151 // Expect RGB data 145 // Expect RGB data
152 if (dv.length () == 3 && dv(2) == 3) 146 if (dv.length () == 3 && dv(2) == 3)
153 { 147 {
154 // FIXME -- dim_vectors hold octave_idx_type values. Should we 148 // FIXME: dim_vectors hold octave_idx_type values.
155 // check for dimensions larger than intmax? 149 // Should we check for dimensions larger than intmax?
156 int h = dv(0), w = dv(1), tw, th; 150 int h = dv(0), w = dv(1), tw, th;
157 GLuint id; 151 GLuint id;
158 bool ok = true; 152 bool ok = true;
159 153
160 tw = next_power_of_2 (w); 154 tw = next_power_of_2 (w);
177 a[idx+1] = xdata(i,j,1); 171 a[idx+1] = xdata(i,j,1);
178 a[idx+2] = xdata(i,j,2); 172 a[idx+2] = xdata(i,j,2);
179 } 173 }
180 } 174 }
181 175
182 glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0, 176 glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0, GL_RGB, GL_FLOAT, a);
183 GL_RGB, GL_FLOAT, a);
184 } 177 }
185 else if (data.is_uint8_type ()) 178 else if (data.is_uint8_type ())
186 { 179 {
187 const uint8NDArray xdata = data.uint8_array_value (); 180 const uint8NDArray xdata = data.uint8_array_value ();
188 181
264 protected: 257 protected:
265 virtual void begin (GLenum /*type*/) { } 258 virtual void begin (GLenum /*type*/) { }
266 259
267 virtual void end (void) { } 260 virtual void end (void) { }
268 261
269 virtual void vertex (void */*data*/) { } 262 virtual void vertex (void * /*data*/) { }
270 263
271 virtual void combine (GLdouble /*c*/[3], void */*data*/[4], 264 virtual void combine (GLdouble [3] /*c*/, void * [4] /*data*/,
272 GLfloat /*w*/[4], void **/*out_data*/) { } 265 GLfloat [4] /*w*/, void ** /*out_data*/) { }
273 266
274 virtual void edge_flag (GLboolean /*flag*/) { } 267 virtual void edge_flag (GLboolean /*flag*/) { }
275 268
276 virtual void error (GLenum err) 269 virtual void error (GLenum err)
277 { ::error ("OpenGL tesselation error (%d)", err); } 270 { ::error ("OpenGL tesselation error (%d)", err); }
351 : coords (), color (), normal (), alpha (), 344 : coords (), color (), normal (), alpha (),
352 ambient (), diffuse (), specular (), specular_exp (),count (1) { } 345 ambient (), diffuse (), specular (), specular_exp (),count (1) { }
353 346
354 vertex_data_rep (const Matrix& c, const Matrix& col, const Matrix& n, 347 vertex_data_rep (const Matrix& c, const Matrix& col, const Matrix& n,
355 double a, float as, float ds, float ss, float se) 348 double a, float as, float ds, float ss, float se)
356 : coords (c), color (col), normal (n), alpha (a), 349 : coords (c), color (col), normal (n), alpha (a),
357 ambient (as), diffuse (ds), specular (ss), specular_exp (se), 350 ambient (as), diffuse (ds), specular (ss), specular_exp (se),
358 count (1) { } 351 count (1) { }
359 }; 352 };
360 353
361 private: 354 private:
362 vertex_data_rep *rep; 355 vertex_data_rep *rep;
363 356
375 vertex_data (const vertex_data& v) : rep (v.rep) 368 vertex_data (const vertex_data& v) : rep (v.rep)
376 { rep->count++; } 369 { rep->count++; }
377 370
378 vertex_data (const Matrix& c, const Matrix& col, const Matrix& n, 371 vertex_data (const Matrix& c, const Matrix& col, const Matrix& n,
379 double a, float as, float ds, float ss, float se) 372 double a, float as, float ds, float ss, float se)
380 : rep (new vertex_data_rep (c, col, n, a, as, ds, ss, se)) 373 : rep (new vertex_data_rep (c, col, n, a, as, ds, ss, se))
381 { } 374 { }
382 375
383 vertex_data (vertex_data_rep *new_rep) 376 vertex_data (vertex_data_rep *new_rep)
384 : rep (new_rep) { } 377 : rep (new_rep) { }
385 378
386 ~vertex_data (void) 379 ~vertex_data (void)
387 { 380 {
388 if (--rep->count == 0) 381 if (--rep->count == 0)
389 delete rep; 382 delete rep;
406 class 399 class
407 opengl_renderer::patch_tesselator : public opengl_tesselator 400 opengl_renderer::patch_tesselator : public opengl_tesselator
408 { 401 {
409 public: 402 public:
410 patch_tesselator (opengl_renderer *r, int cmode, int lmode, int idx = 0) 403 patch_tesselator (opengl_renderer *r, int cmode, int lmode, int idx = 0)
411 : opengl_tesselator (), renderer (r), 404 : opengl_tesselator (), renderer (r),
412 color_mode (cmode), light_mode (lmode), index (idx), 405 color_mode (cmode), light_mode (lmode), index (idx),
413 first (true), tmp_vdata () 406 first (true), tmp_vdata ()
414 { } 407 { }
415 408
416 protected: 409 protected:
417 void begin (GLenum type) 410 void begin (GLenum type)
418 { 411 {
1432 Matrix x = xform.xscale (props.get_xdata ().matrix_value ()); 1425 Matrix x = xform.xscale (props.get_xdata ().matrix_value ());
1433 Matrix y = xform.yscale (props.get_ydata ().matrix_value ()); 1426 Matrix y = xform.yscale (props.get_ydata ().matrix_value ());
1434 Matrix z = xform.zscale (props.get_zdata ().matrix_value ()); 1427 Matrix z = xform.zscale (props.get_zdata ().matrix_value ());
1435 1428
1436 bool has_z = (z.numel () > 0); 1429 bool has_z = (z.numel () > 0);
1437 int n = static_cast<int> (::xmin (::xmin (x.numel (), y.numel ()), (has_z ? z.numel () : std::numeric_limits<int>::max ()))); 1430 int n = static_cast<int> (std::min (std::min (x.numel (), y.numel ()), (has_z ? z.numel () : std::numeric_limits<int>::max ())));
1438 octave_uint8 clip_mask = (props.is_clipping () ? 0x7F : 0x40), clip_ok (0x40); 1431 octave_uint8 clip_mask = (props.is_clipping () ? 0x7F : 0x40), clip_ok (0x40);
1439 1432
1440 std::vector<octave_uint8> clip (n); 1433 std::vector<octave_uint8> clip (n);
1441 1434
1442 if (has_z) 1435 if (has_z)