~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/glu/mini/nurbscrv.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: nurbscrv.c,v 1.2 2003-08-22 20:11:43 brianp Exp $ */
2
 
 
3
 
/*
4
 
 * Mesa 3-D graphics library
5
 
 * Version:  3.3
6
 
 * Copyright (C) 1995-2000  Brian Paul
7
 
 *
8
 
 * This library is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU Library General Public
10
 
 * License as published by the Free Software Foundation; either
11
 
 * version 2 of the License, or (at your option) any later version.
12
 
 *
13
 
 * This library is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * Library General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU Library General Public
19
 
 * License along with this library; if not, write to the Free
20
 
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
 
 */
22
 
 
23
 
 
24
 
/*
25
 
 * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it)
26
 
 * See README2 for more info.
27
 
 */
28
 
 
29
 
 
30
 
#ifdef PC_HEADER
31
 
#include "all.h"
32
 
#else
33
 
#include <math.h>
34
 
#include <stdlib.h>
35
 
#include "gluP.h"
36
 
#include "nurbs.h"
37
 
#endif
38
 
 
39
 
 
40
 
 
41
 
/* main NURBS curve procedure */
42
 
void
43
 
do_nurbs_curve(GLUnurbsObj * nobj)
44
 
{
45
 
   GLint geom_order, color_order = 0, normal_order = 0, texture_order = 0;
46
 
   GLenum geom_type;
47
 
   GLint n_ctrl;
48
 
   GLfloat *new_geom_ctrl, *new_color_ctrl, *new_normal_ctrl,
49
 
      *new_texture_ctrl;
50
 
   GLfloat *geom_ctrl = 0, *color_ctrl = 0, *normal_ctrl = 0, *texture_ctrl = 0;
51
 
   GLint *factors;
52
 
   GLint i, j;
53
 
   GLint geom_dim, color_dim = 0, normal_dim = 0, texture_dim = 0;
54
 
 
55
 
   /* test the user supplied data */
56
 
   if (test_nurbs_curves(nobj) != GLU_NO_ERROR)
57
 
      return;
58
 
 
59
 
   if (convert_curves(nobj, &new_geom_ctrl, &n_ctrl, &new_color_ctrl,
60
 
                      &new_normal_ctrl, &new_texture_ctrl) != GLU_NO_ERROR)
61
 
      return;
62
 
 
63
 
   geom_order = nobj->curve.geom.order;
64
 
   geom_type = nobj->curve.geom.type;
65
 
   geom_dim = nobj->curve.geom.dim;
66
 
 
67
 
   if (glu_do_sampling_crv(nobj, new_geom_ctrl, n_ctrl, geom_order, geom_dim,
68
 
                           &factors) != GLU_NO_ERROR) {
69
 
      free(new_geom_ctrl);
70
 
      if (new_color_ctrl)
71
 
         free(new_color_ctrl);
72
 
      if (new_normal_ctrl)
73
 
         free(new_normal_ctrl);
74
 
      if (new_texture_ctrl)
75
 
         free(new_texture_ctrl);
76
 
      return;
77
 
   }
78
 
   glEnable(geom_type);
79
 
   if (new_color_ctrl) {
80
 
      glEnable(nobj->curve.color.type);
81
 
      color_dim = nobj->curve.color.dim;
82
 
      color_ctrl = new_color_ctrl;
83
 
      color_order = nobj->curve.color.order;
84
 
   }
85
 
   if (new_normal_ctrl) {
86
 
      glEnable(nobj->curve.normal.type);
87
 
      normal_dim = nobj->curve.normal.dim;
88
 
      normal_ctrl = new_normal_ctrl;
89
 
      normal_order = nobj->curve.normal.order;
90
 
   }
91
 
   if (new_texture_ctrl) {
92
 
      glEnable(nobj->curve.texture.type);
93
 
      texture_dim = nobj->curve.texture.dim;
94
 
      texture_ctrl = new_texture_ctrl;
95
 
      texture_order = nobj->curve.texture.order;
96
 
   }
97
 
   for (i = 0, j = 0, geom_ctrl = new_geom_ctrl;
98
 
        i < n_ctrl; i += geom_order, j++, geom_ctrl += geom_order * geom_dim) {
99
 
      if (fine_culling_test_2D
100
 
          (nobj, geom_ctrl, geom_order, geom_dim, geom_dim)) {
101
 
         color_ctrl += color_order * color_dim;
102
 
         normal_ctrl += normal_order * normal_dim;
103
 
         texture_ctrl += texture_order * texture_dim;
104
 
         continue;
105
 
      }
106
 
      glMap1f(geom_type, 0.0, 1.0, geom_dim, geom_order, geom_ctrl);
107
 
      if (new_color_ctrl) {
108
 
         glMap1f(nobj->curve.color.type, 0.0, 1.0, color_dim,
109
 
                 color_order, color_ctrl);
110
 
         color_ctrl += color_order * color_dim;
111
 
      }
112
 
      if (new_normal_ctrl) {
113
 
         glMap1f(nobj->curve.normal.type, 0.0, 1.0, normal_dim,
114
 
                 normal_order, normal_ctrl);
115
 
         normal_ctrl += normal_order * normal_dim;
116
 
      }
117
 
      if (new_texture_ctrl) {
118
 
         glMap1f(nobj->curve.texture.type, 0.0, 1.0, texture_dim,
119
 
                 texture_order, texture_ctrl);
120
 
         texture_ctrl += texture_order * texture_dim;
121
 
      }
122
 
      glMapGrid1f(factors[j], 0.0, 1.0);
123
 
      glEvalMesh1(GL_LINE, 0, factors[j]);
124
 
   }
125
 
   free(new_geom_ctrl);
126
 
   free(factors);
127
 
   if (new_color_ctrl)
128
 
      free(new_color_ctrl);
129
 
   if (new_normal_ctrl)
130
 
      free(new_normal_ctrl);
131
 
   if (new_texture_ctrl)
132
 
      free(new_texture_ctrl);
133
 
}