Win32 fixes, etc. (Gerk Huisma)
[mesa.git] / src / glu / sgi / libnurbs / interface / glsurfeval.h
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
33 */
34
35 /*
36 * glsurfeval.h
37 *
38 * $Date: 2001/08/07 17:34:11 $ $Revision: 1.4 $
39 * $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libnurbs/interface/glsurfeval.h,v 1.4 2001/08/07 17:34:11 brianp Exp $
40 */
41
42 #ifndef __gluglsurfeval_h_
43 #define __gluglsurfeval_h_
44
45 #include "basicsurfeval.h"
46 #include "bezierPatchMesh.h" //in case output triangles
47 #include <GL/gl.h>
48 #include <GL/glu.h>
49
50 class SurfaceMap;
51 class OpenGLSurfaceEvaluator;
52 class StoredVertex;
53
54 #define TYPECOORD 1
55 #define TYPEPOINT 2
56
57 /* Cache up to 3 vertices from tmeshes */
58 #define VERTEX_CACHE_SIZE 3
59
60 /*for internal evaluator callback stuff*/
61 #ifndef IN_MAX_BEZIER_ORDER
62 #define IN_MAX_BEZIER_ORDER 40 /*XXX should be bigger than machine order*/
63 #endif
64
65 #ifndef IN_MAX_DIMENSION
66 #define IN_MAX_DIMENSION 4
67 #endif
68
69 typedef struct surfEvalMachine{
70 REAL uprime;//cached previusly evaluated uprime.
71 REAL vprime;
72 int k; /*the dimension*/
73 REAL u1;
74 REAL u2;
75 int ustride;
76 int uorder;
77 REAL v1;
78 REAL v2;
79 int vstride;
80 int vorder;
81 REAL ctlPoints[IN_MAX_BEZIER_ORDER*IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION];
82 REAL ucoeff[IN_MAX_BEZIER_ORDER]; /*cache the polynomial values*/
83 REAL vcoeff[IN_MAX_BEZIER_ORDER];
84 REAL ucoeffDeriv[IN_MAX_BEZIER_ORDER]; /*cache the polynomial derivatives*/
85 REAL vcoeffDeriv[IN_MAX_BEZIER_ORDER];
86 } surfEvalMachine;
87
88
89
90 class StoredVertex {
91 public:
92 StoredVertex() { type = 0; }
93 ~StoredVertex(void) {}
94 void saveEvalCoord(REAL x, REAL y)
95 {coord[0] = x; coord[1] = y; type = TYPECOORD; }
96 void saveEvalPoint(long x, long y)
97 {point[0] = x; point[1] = y; type = TYPEPOINT; }
98 void invoke(OpenGLSurfaceEvaluator *eval);
99
100 private:
101 int type;
102 REAL coord[2];
103 long point[2];
104 };
105
106 class OpenGLSurfaceEvaluator : public BasicSurfaceEvaluator {
107 public:
108 OpenGLSurfaceEvaluator();
109 ~OpenGLSurfaceEvaluator( void );
110 void polymode( long style );
111 void range2f( long, REAL *, REAL * );
112 void domain2f( REAL, REAL, REAL, REAL );
113 void addMap( SurfaceMap * ) { }
114
115 void enable( long );
116 void disable( long );
117 void bgnmap2f( long );
118 void map2f( long, REAL, REAL, long, long,
119 REAL, REAL, long, long, REAL * );
120 void mapgrid2f( long, REAL, REAL, long, REAL, REAL );
121 void mapmesh2f( long, long, long, long, long );
122 void evalcoord2f( long, REAL, REAL );
123 void evalpoint2i( long, long );
124 void endmap2f( void );
125
126 void bgnline( void );
127 void endline( void );
128 void bgnclosedline( void );
129 void endclosedline( void );
130 void bgntmesh( void );
131 void swaptmesh( void );
132 void endtmesh( void );
133 void bgnqstrip( void );
134 void endqstrip( void );
135
136 void bgntfan( void );
137 void endtfan( void );
138 void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
139 int n_lower, REAL v_lower, REAL* lower_val);
140 void evalVStrip(int n_left, REAL u_left, REAL* left_val,
141 int n_right, REAL u_right, REAL* right_val);
142
143 void coord2f( REAL, REAL );
144 void point2i( long, long );
145
146 void newtmeshvert( REAL, REAL );
147 void newtmeshvert( long, long );
148
149 #ifdef _WIN32
150 void putCallBack(GLenum which, void (APIENTRY *fn)() );
151 #else
152 void putCallBack(GLenum which, _GLUfuncptr fn );
153 #endif
154
155 int get_vertices_call_back()
156 {
157 return output_triangles;
158 }
159 void put_vertices_call_back(int flag)
160 {
161 output_triangles = flag;
162 }
163
164 void put_callback_auto_normal(int flag)
165 {
166 callback_auto_normal = flag;
167 }
168
169 int get_callback_auto_normal()
170 {
171 return callback_auto_normal;
172 }
173
174 void set_callback_userData(void* data)
175 {
176 userData = data;
177 }
178
179 /**************begin for LOD_eval_list***********/
180 void LOD_eval_list(int level);
181
182
183
184
185 private:
186 StoredVertex *vertexCache[VERTEX_CACHE_SIZE];
187 int tmeshing;
188 int which;
189 int vcount;
190
191 GLint gl_polygon_mode[2];/*to save and restore so that
192 *no side effect
193 */
194 bezierPatchMesh *global_bpm; //for output triangles
195 int output_triangles; //true 1 or false 0
196
197
198
199 void (GLAPIENTRY *beginCallBackN) (GLenum type);
200 void (GLAPIENTRY *endCallBackN) (void);
201 void (GLAPIENTRY *vertexCallBackN) (const GLfloat *vert);
202 void (GLAPIENTRY *normalCallBackN) (const GLfloat *normal);
203 void (GLAPIENTRY *colorCallBackN) (const GLfloat *color);
204 void (GLAPIENTRY *texcoordCallBackN) (const GLfloat *texcoord);
205
206 void (GLAPIENTRY *beginCallBackData) (GLenum type, void* data);
207 void (GLAPIENTRY *endCallBackData) (void* data);
208 void (GLAPIENTRY *vertexCallBackData) (const GLfloat *vert, void* data);
209 void (GLAPIENTRY *normalCallBackData) (const GLfloat *normal, void* data);
210 void (GLAPIENTRY *colorCallBackData) (const GLfloat *color, void* data);
211 void (GLAPIENTRY *texcoordCallBackData) (const GLfloat *texcoord, void* data);
212
213 void beginCallBack (GLenum type, void* data);
214 void endCallBack (void* data);
215 void vertexCallBack (const GLfloat *vert, void* data);
216 void normalCallBack (const GLfloat *normal, void* data);
217 void colorCallBack (const GLfloat *color, void* data);
218 void texcoordCallBack (const GLfloat *texcoord, void* data);
219
220
221 void* userData; //the opaque pointer for Data callback functions.
222
223 /*LOD evaluation*/
224 void LOD_triangle(REAL A[2], REAL B[2], REAL C[2],
225 int level);
226 void LOD_eval(int num_vert, REAL* verts, int type, int level);
227
228 int LOD_eval_level; //set by LOD_eval_list()
229
230 /*************begin for internal evaluators*****************/
231
232 /*the following global variables are only defined in this file.
233 *They are used to cache the precomputed Bezier polynomial values.
234 *These calues may be used consecutively in which case we don't have
235 *recompute these values again.
236 */
237 int global_uorder; /*store the uorder in the previous evaluation*/
238 int global_vorder; /*store the vorder in the previous evaluation*/
239 REAL global_uprime;
240 REAL global_vprime;
241 REAL global_vprime_BV;
242 REAL global_uprime_BU;
243 int global_uorder_BV; /*store the uorder in the previous evaluation*/
244 int global_vorder_BV; /*store the vorder in the previous evaluation*/
245 int global_uorder_BU; /*store the uorder in the previous evaluation*/
246 int global_vorder_BU; /*store the vorder in the previous evaluation*/
247
248 REAL global_ucoeff[IN_MAX_BEZIER_ORDER]; /*cache the polynomial values*/
249 REAL global_vcoeff[IN_MAX_BEZIER_ORDER];
250 REAL global_ucoeffDeriv[IN_MAX_BEZIER_ORDER]; /*cache the polynomial derivatives*/
251 REAL global_vcoeffDeriv[IN_MAX_BEZIER_ORDER];
252
253 REAL global_BV[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
254 REAL global_PBV[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
255 REAL global_BU[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
256 REAL global_PBU[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
257 REAL* global_baseData;
258
259 int global_ev_k; /*the dimension*/
260 REAL global_ev_u1;
261 REAL global_ev_u2;
262 int global_ev_ustride;
263 int global_ev_uorder;
264 REAL global_ev_v1;
265 REAL global_ev_v2;
266 int global_ev_vstride;
267 int global_ev_vorder;
268 REAL global_ev_ctlPoints[IN_MAX_BEZIER_ORDER*IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION];
269
270 REAL global_grid_u0;
271 REAL global_grid_u1;
272 int global_grid_nu;
273 REAL global_grid_v0;
274 REAL global_grid_v1;
275 int global_grid_nv;
276
277 /*functions*/
278 void inDoDomain2WithDerivs(int k, REAL u, REAL v,
279 REAL u1, REAL u2, int uorder,
280 REAL v1, REAL v2, int vorder,
281 REAL *baseData,
282 REAL *retPoint, REAL *retdu, REAL *retdv);
283 void inPreEvaluate(int order, REAL vprime, REAL *coeff);
284 void inPreEvaluateWithDeriv(int order, REAL vprime, REAL *coeff, REAL *coeffDeriv);
285 void inComputeFirstPartials(REAL *p, REAL *pu, REAL *pv);
286 void inComputeNormal2(REAL *pu, REAL *pv, REAL *n);
287 void inDoEvalCoord2(REAL u, REAL v,
288 REAL *retPoint, REAL *retNormal);
289 void inDoEvalCoord2NOGE(REAL u, REAL v,
290 REAL *retPoint, REAL *retNormal);
291 void inMap2f(int k,
292 REAL ulower,
293 REAL uupper,
294 int ustride,
295 int uorder,
296 REAL vlower,
297 REAL vupper,
298 int vstride,
299 int vorder,
300 REAL *ctlPoints);
301
302 void inMapGrid2f(int nu, REAL u0, REAL u1,
303 int nv, REAL v0, REAL v1);
304
305 void inEvalMesh2(int lowU, int lowV, int highU, int highV);
306 void inEvalPoint2(int i, int j);
307 void inEvalCoord2f(REAL u, REAL v);
308
309 void inEvalULine(int n_points, REAL v, REAL* u_vals,
310 int stride, REAL ret_points[][3], REAL ret_normals[][3]);
311
312 void inEvalVLine(int n_points, REAL u, REAL* v_vals,
313 int stride, REAL ret_points[][3], REAL ret_normals[][3]);
314
315 void inEvalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
316 int n_lower, REAL v_lower, REAL* lower_val
317 );
318 void inEvalVStrip(int n_left, REAL u_left, REAL* left_val, int n_right, REAL u_right, REAL* right_val);
319
320 void inPreEvaluateBV(int k, int uorder, int vorder, REAL vprime, REAL *baseData);
321 void inPreEvaluateBU(int k, int uorder, int vorder, REAL uprime, REAL *baseData);
322 void inPreEvaluateBV_intfac(REAL v )
323 {
324 inPreEvaluateBV(global_ev_k, global_ev_uorder, global_ev_vorder, (v-global_ev_v1)/(global_ev_v2-global_ev_v1), global_ev_ctlPoints);
325 }
326
327 void inPreEvaluateBU_intfac(REAL u)
328 {
329 inPreEvaluateBU(global_ev_k, global_ev_uorder, global_ev_vorder, (u-global_ev_u1)/(global_ev_u2-global_ev_u1), global_ev_ctlPoints);
330 }
331
332 void inDoDomain2WithDerivsBV(int k, REAL u, REAL v,
333 REAL u1, REAL u2, int uorder,
334 REAL v1, REAL v2, int vorder,
335 REAL *baseData,
336 REAL *retPoint, REAL* retdu, REAL *retdv);
337
338 void inDoDomain2WithDerivsBU(int k, REAL u, REAL v,
339 REAL u1, REAL u2, int uorder,
340 REAL v1, REAL v2, int vorder,
341 REAL *baseData,
342 REAL *retPoint, REAL* retdu, REAL *retdv);
343
344
345 void inDoEvalCoord2NOGE_BV(REAL u, REAL v,
346 REAL *retPoint, REAL *retNormal);
347
348 void inDoEvalCoord2NOGE_BU(REAL u, REAL v,
349 REAL *retPoint, REAL *retNormal);
350
351 void inBPMEval(bezierPatchMesh* bpm);
352 void inBPMListEval(bezierPatchMesh* list);
353
354 /*-------------begin for surfEvalMachine -------------*/
355 surfEvalMachine em_vertex;
356 surfEvalMachine em_normal;
357 surfEvalMachine em_color;
358 surfEvalMachine em_texcoord;
359
360 int auto_normal_flag; //whether to output normla or not in callback
361 //determined by GL_AUTO_NORMAL and callback_auto_normal
362 int callback_auto_normal; //GLU_CALLBACK_AUTO_NORMAL_EXT
363 int vertex_flag;
364 int normal_flag;
365 int color_flag;
366 int texcoord_flag;
367
368 void inMap2fEM(int which, //0:vert,1:norm,2:color,3:tex
369 int dimension,
370 REAL ulower,
371 REAL uupper,
372 int ustride,
373 int uorder,
374 REAL vlower,
375 REAL vupper,
376 int vstride,
377 int vorder,
378 REAL *ctlPoints);
379
380 void inDoDomain2WithDerivsEM(surfEvalMachine *em, REAL u, REAL v,
381 REAL *retPoint, REAL *retdu, REAL *retdv);
382 void inDoDomain2EM(surfEvalMachine *em, REAL u, REAL v,
383 REAL *retPoint);
384 void inDoEvalCoord2EM(REAL u, REAL v);
385
386 void inBPMEvalEM(bezierPatchMesh* bpm);
387 void inBPMListEvalEM(bezierPatchMesh* list);
388
389 /*-------------end for surfEvalMachine -------------*/
390
391
392 /*************end for internal evaluators*****************/
393
394 };
395
396 inline void StoredVertex::invoke(OpenGLSurfaceEvaluator *eval)
397 {
398 switch(type) {
399 case TYPECOORD:
400 eval->coord2f(coord[0], coord[1]);
401 break;
402 case TYPEPOINT:
403 eval->point2i(point[0], point[1]);
404 break;
405 default:
406 break;
407 }
408 }
409
410 #endif /* __gluglsurfeval_h_ */