Mercurial > octave-nkf
comparison src/graphics/opengl/gl-render.cc @ 7837:57095ca98533
Make OpenGL tessellation combine callback robust against NULL vertex data.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Thu, 21 Feb 2008 15:22:16 +0100 |
parents | caab78e7e377 |
children | 0a2ba0053fbd |
comparison
equal
deleted
inserted
replaced
7836:4fb2db9c87dd | 7837:57095ca98533 |
---|---|
452 } | 452 } |
453 | 453 |
454 void combine (GLdouble xyz[3], void *data[4], GLfloat w[4], | 454 void combine (GLdouble xyz[3], void *data[4], GLfloat w[4], |
455 void **out_data) | 455 void **out_data) |
456 { | 456 { |
457 vertex_data::vertex_data_rep *v0, *v1, *v2, *v3; | |
458 //printf("patch_tesselator::combine\n"); | 457 //printf("patch_tesselator::combine\n"); |
459 | 458 |
460 v0 = reinterpret_cast<vertex_data::vertex_data_rep *> (data[0]); | 459 vertex_data::vertex_data_rep *v[4]; |
461 v1 = reinterpret_cast<vertex_data::vertex_data_rep *> (data[1]); | 460 int vmax = 4; |
462 v2 = reinterpret_cast<vertex_data::vertex_data_rep *> (data[2]); | 461 |
463 v3 = reinterpret_cast<vertex_data::vertex_data_rep *> (data[3]); | 462 for (int i = 0; i < 4; i++) |
463 { | |
464 v[i] = reinterpret_cast<vertex_data::vertex_data_rep *> (data[i]); | |
465 | |
466 if (vmax == 4 && ! v[i]) | |
467 vmax = i; | |
468 } | |
464 | 469 |
465 Matrix vv (1, 3, 0.0); | 470 Matrix vv (1, 3, 0.0); |
466 Matrix cc; | 471 Matrix cc; |
467 Matrix nn (1, 3, 0.0); | 472 Matrix nn (1, 3, 0.0); |
468 double aa; | 473 double aa = 0.0; |
469 | 474 |
470 vv(0) = xyz[0]; | 475 vv(0) = xyz[0]; |
471 vv(1) = xyz[1]; | 476 vv(1) = xyz[1]; |
472 vv(2) = xyz[2]; | 477 vv(2) = xyz[2]; |
473 if (v0->color.numel () > 0 && v1->color.numel () > 0 && | 478 |
474 v2->color.numel () > 0 && v3->color.numel () > 0) | 479 if (v[0]->color.numel ()) |
475 { | 480 { |
476 cc.resize (1, 3, 0.0); | 481 cc.resize (1, 3, 0.0); |
477 cc(0) = w[0]*v0->color(0)+w[1]*v1->color(0)+w[2]*v2->color(0)+w[3]*v3->color(0); | 482 for (int ic = 0; ic < 3; ic++) |
478 cc(1) = w[0]*v0->color(1)+w[1]*v1->color(1)+w[2]*v2->color(1)+w[3]*v3->color(1); | 483 for (int iv = 0; iv < vmax; iv++) |
479 cc(2) = w[0]*v0->color(2)+w[1]*v1->color(2)+w[2]*v2->color(2)+w[3]*v3->color(2); | 484 cc(ic) += (w[iv] * v[iv]->color(ic)); |
480 } | 485 } |
481 nn(0) = w[0]*v0->normal(0)+w[1]*v1->normal(0)+w[2]*v2->normal(0)+w[3]*v3->normal(0); | 486 |
482 nn(1) = w[0]*v0->normal(1)+w[1]*v1->normal(1)+w[2]*v2->normal(1)+w[3]*v3->normal(1); | 487 if (v[0]->normal.numel () > 0) |
483 nn(2) = w[0]*v0->normal(2)+w[1]*v1->normal(2)+w[2]*v2->normal(2)+w[3]*v3->normal(2); | 488 { |
484 aa = w[0]*v0->alpha+w[1]*v1->alpha+w[2]*v2->alpha+w[3]*v3->alpha; | 489 for (int in = 0; in < 3; in++) |
485 | 490 for (int iv = 0; iv < vmax; iv++) |
486 vertex_data v (vv, cc, nn, aa, v0->ambient, v0->diffuse, | 491 nn(in) += (w[iv] * v[iv]->normal(in)); |
487 v0->specular, v0->specular_exp); | 492 } |
488 tmp_vdata.push_back (v); | 493 |
489 | 494 for (int iv = 0; iv < vmax; iv++) |
490 *out_data = v.get_rep (); | 495 aa += (w[iv] * v[iv]->alpha); |
496 | |
497 vertex_data new_v (vv, cc, nn, aa, v[0]->ambient, v[0]->diffuse, | |
498 v[0]->specular, v[0]->specular_exp); | |
499 tmp_vdata.push_back (new_v); | |
500 | |
501 *out_data = new_v.get_rep (); | |
491 } | 502 } |
492 | 503 |
493 private: | 504 private: |
494 opengl_renderer *renderer; | 505 opengl_renderer *renderer; |
495 int color_mode; // 0: uni, 1: flat, 2: interp | 506 int color_mode; // 0: uni, 1: flat, 2: interp |