reshuffling of dlls
[reactos.git] / reactos / dll / win32 / glu32 / 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 */
39
40 #ifndef __gluglsurfeval_h_
41 #define __gluglsurfeval_h_
42
43 #include "basicsurfeval.h"
44 #include "bezierPatchMesh.h" //in case output triangles
45 #include <GL/gl.h>
46 #include <GL/glu.h>
47
48 class SurfaceMap;
49 class OpenGLSurfaceEvaluator;
50 class StoredVertex;
51
52 #define TYPECOORD 1
53 #define TYPEPOINT 2
54
55 /* Cache up to 3 vertices from tmeshes */
56 #define VERTEX_CACHE_SIZE 3
57
58 /*for internal evaluator callback stuff*/
59 #ifndef IN_MAX_BEZIER_ORDER
60 #define IN_MAX_BEZIER_ORDER 40 /*XXX should be bigger than machine order*/
61 #endif
62
63 #ifndef IN_MAX_DIMENSION
64 #define IN_MAX_DIMENSION 4
65 #endif
66
67 typedef struct surfEvalMachine{
68 REAL uprime;//cached previusly evaluated uprime.
69 REAL vprime;
70 int k; /*the dimension*/
71 REAL u1;
72 REAL u2;
73 int ustride;
74 int uorder;
75 REAL v1;
76 REAL v2;
77 int vstride;
78 int vorder;
79 REAL ctlPoints[IN_MAX_BEZIER_ORDER*IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION];
80 REAL ucoeff[IN_MAX_BEZIER_ORDER]; /*cache the polynomial values*/
81 REAL vcoeff[IN_MAX_BEZIER_ORDER];
82 REAL ucoeffDeriv[IN_MAX_BEZIER_ORDER]; /*cache the polynomial derivatives*/
83 REAL vcoeffDeriv[IN_MAX_BEZIER_ORDER];
84 } surfEvalMachine;
85
86
87
88 class StoredVertex {
89 public:
90 StoredVertex() { type = 0; }
91 ~StoredVertex(void) {}
92 void saveEvalCoord(REAL x, REAL y)
93 {coord[0] = x; coord[1] = y; type = TYPECOORD; }
94 void saveEvalPoint(long x, long y)
95 {point[0] = x; point[1] = y; type = TYPEPOINT; }
96 void invoke(OpenGLSurfaceEvaluator *eval);
97
98 private:
99 int type;
100 REAL coord[2];
101 long point[2];
102 };
103
104 class OpenGLSurfaceEvaluator : public BasicSurfaceEvaluator {
105 public:
106 OpenGLSurfaceEvaluator();
107 virtual ~OpenGLSurfaceEvaluator( void );
108 void polymode( long style );
109 void range2f( long, REAL *, REAL * );
110 void domain2f( REAL, REAL, REAL, REAL );
111 void addMap( SurfaceMap * ) { }
112
113 void enable( long );
114 void disable( long );
115 void bgnmap2f( long );
116 void map2f( long, REAL, REAL, long, long,
117 REAL, REAL, long, long, REAL * );
118 void mapgrid2f( long, REAL, REAL, long, REAL, REAL );
119 void mapmesh2f( long, long, long, long, long );
120 void evalcoord2f( long, REAL, REAL );
121 void evalpoint2i( long, long );
122 void endmap2f( void );
123
124 void bgnline( void );
125 void endline( void );
126 void bgnclosedline( void );
127 void endclosedline( void );
128 void bgntmesh( void );
129 void swaptmesh( void );
130 void endtmesh( void );
131 void bgnqstrip( void );
132 void endqstrip( void );
133
134 void bgntfan( void );
135 void endtfan( void );
136 void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
137 int n_lower, REAL v_lower, REAL* lower_val);
138 void evalVStrip(int n_left, REAL u_left, REAL* left_val,
139 int n_right, REAL u_right, REAL* right_val);
140
141 void coord2f( REAL, REAL );
142 void point2i( long, long );
143
144 void newtmeshvert( REAL, REAL );
145 void newtmeshvert( long, long );
146
147 #ifdef _WIN32
148 void putCallBack(GLenum which, void (APIENTRY *fn)() );
149 #else
150 void putCallBack(GLenum which, _GLUfuncptr fn );
151 #endif
152
153 int get_vertices_call_back()
154 {
155 return output_triangles;
156 }
157 void put_vertices_call_back(int flag)
158 {
159 output_triangles = flag;
160 }
161
162 void put_callback_auto_normal(int flag)
163 {
164 callback_auto_normal = flag;
165 }
166
167 int get_callback_auto_normal()
168 {
169 return callback_auto_normal;
170 }
171
172 void set_callback_userData(void* data)
173 {
174 userData = data;
175 }
176
177 /**************begin for LOD_eval_list***********/
178 void LOD_eval_list(int level);
179
180
181
182
183 private:
184 StoredVertex *vertexCache[VERTEX_CACHE_SIZE];
185 int tmeshing;
186 int which;
187 int vcount;
188
189 GLint gl_polygon_mode[2];/*to save and restore so that
190 *no side effect
191 */
192 bezierPatchMesh *global_bpm; //for output triangles
193 int output_triangles; //true 1 or false 0
194
195
196
197 void (GLAPIENTRY *beginCallBackN) (GLenum type);
198 void (GLAPIENTRY *endCallBackN) (void);
199 void (GLAPIENTRY *vertexCallBackN) (const GLfloat *vert);
200 void (GLAPIENTRY *normalCallBackN) (const GLfloat *normal);
201 void (GLAPIENTRY *colorCallBackN) (const GLfloat *color);
202 void (GLAPIENTRY *texcoordCallBackN) (const GLfloat *texcoord);
203
204 void (GLAPIENTRY *beginCallBackData) (GLenum type, void* data);
205 void (GLAPIENTRY *endCallBackData) (void* data);
206 void (GLAPIENTRY *vertexCallBackData) (const GLfloat *vert, void* data);
207 void (GLAPIENTRY *normalCallBackData) (const GLfloat *normal, void* data);
208 void (GLAPIENTRY *colorCallBackData) (const GLfloat *color, void* data);
209 void (GLAPIENTRY *texcoordCallBackData) (const GLfloat *texcoord, void* data);
210
211 void beginCallBack (GLenum type, void* data);
212 void endCallBack (void* data);
213 void vertexCallBack (const GLfloat *vert, void* data);
214 void normalCallBack (const GLfloat *normal, void* data);
215 void colorCallBack (const GLfloat *color, void* data);
216 void texcoordCallBack (const GLfloat *texcoord, void* data);
217
218
219 void* userData; //the opaque pointer for Data callback functions.
220
221 /*LOD evaluation*/
222 void LOD_triangle(REAL A[2], REAL B[2], REAL C[2],
223 int level);
224 void LOD_eval(int num_vert, REAL* verts, int type, int level);
225
226 int LOD_eval_level; //set by LOD_eval_list()
227
228 /*************begin for internal evaluators*****************/
229
230 /*the following global variables are only defined in this file.
231 *They are used to cache the precomputed Bezier polynomial values.
232 *These calues may be used consecutively in which case we don't have
233 *recompute these values again.
234 */
235 int global_uorder; /*store the uorder in the previous evaluation*/
236 int global_vorder; /*store the vorder in the previous evaluation*/
237 REAL global_uprime;
238 REAL global_vprime;
239 REAL global_vprime_BV;
240 REAL global_uprime_BU;
241 int global_uorder_BV; /*store the uorder in the previous evaluation*/
242 int global_vorder_BV; /*store the vorder in the previous evaluation*/
243 int global_uorder_BU; /*store the uorder in the previous evaluation*/
244 int global_vorder_BU; /*store the vorder in the previous evaluation*/
245
246 REAL global_ucoeff[IN_MAX_BEZIER_ORDER]; /*cache the polynomial values*/
247 REAL global_vcoeff[IN_MAX_BEZIER_ORDER];
248 REAL global_ucoeffDeriv[IN_MAX_BEZIER_ORDER]; /*cache the polynomial derivatives*/
249 REAL global_vcoeffDeriv[IN_MAX_BEZIER_ORDER];
250
251 REAL global_BV[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
252 REAL global_PBV[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
253 REAL global_BU[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
254 REAL global_PBU[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
255 REAL* global_baseData;
256
257 int global_ev_k; /*the dimension*/
258 REAL global_ev_u1;
259 REAL global_ev_u2;
260 int global_ev_ustride;
261 int global_ev_uorder;
262 REAL global_ev_v1;
263 REAL global_ev_v2;
264 int global_ev_vstride;
265 int global_ev_vorder;
266 REAL global_ev_ctlPoints[IN_MAX_BEZIER_ORDER*IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION];
267
268 REAL global_grid_u0;
269 REAL global_grid_u1;
270 int global_grid_nu;
271 REAL global_grid_v0;
272 REAL global_grid_v1;
273 int global_grid_nv;
274
275 /*functions*/
276 void inDoDomain2WithDerivs(int k, REAL u, REAL v,
277 REAL u1, REAL u2, int uorder,
278 REAL v1, REAL v2, int vorder,
279 REAL *baseData,
280 REAL *retPoint, REAL *retdu, REAL *retdv);
281 void inPreEvaluate(int order, REAL vprime, REAL *coeff);
282 void inPreEvaluateWithDeriv(int order, REAL vprime, REAL *coeff, REAL *coeffDeriv);
283 void inComputeFirstPartials(REAL *p, REAL *pu, REAL *pv);
284 void inComputeNormal2(REAL *pu, REAL *pv, REAL *n);
285 void inDoEvalCoord2(REAL u, REAL v,
286 REAL *retPoint, REAL *retNormal);
287 void inDoEvalCoord2NOGE(REAL u, REAL v,
288 REAL *retPoint, REAL *retNormal);
289 void inMap2f(int k,
290 REAL ulower,
291 REAL uupper,
292 int ustride,
293 int uorder,
294 REAL vlower,
295 REAL vupper,
296 int vstride,
297 int vorder,
298 REAL *ctlPoints);
299
300 void inMapGrid2f(int nu, REAL u0, REAL u1,
301 int nv, REAL v0, REAL v1);
302
303 void inEvalMesh2(int lowU, int lowV, int highU, int highV);
304 void inEvalPoint2(int i, int j);
305 void inEvalCoord2f(REAL u, REAL v);
306
307 void inEvalULine(int n_points, REAL v, REAL* u_vals,
308 int stride, REAL ret_points[][3], REAL ret_normals[][3]);
309
310 void inEvalVLine(int n_points, REAL u, REAL* v_vals,
311 int stride, REAL ret_points[][3], REAL ret_normals[][3]);
312
313 void inEvalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
314 int n_lower, REAL v_lower, REAL* lower_val
315 );
316 void inEvalVStrip(int n_left, REAL u_left, REAL* left_val, int n_right, REAL u_right, REAL* right_val);
317
318 void inPreEvaluateBV(int k, int uorder, int vorder, REAL vprime, REAL *baseData);
319 void inPreEvaluateBU(int k, int uorder, int vorder, REAL uprime, REAL *baseData);
320 void inPreEvaluateBV_intfac(REAL v )
321 {
322 inPreEvaluateBV(global_ev_k, global_ev_uorder, global_ev_vorder, (v-global_ev_v1)/(global_ev_v2-global_ev_v1), global_ev_ctlPoints);
323 }
324
325 void inPreEvaluateBU_intfac(REAL u)
326 {
327 inPreEvaluateBU(global_ev_k, global_ev_uorder, global_ev_vorder, (u-global_ev_u1)/(global_ev_u2-global_ev_u1), global_ev_ctlPoints);
328 }
329
330 void inDoDomain2WithDerivsBV(int k, REAL u, REAL v,
331 REAL u1, REAL u2, int uorder,
332 REAL v1, REAL v2, int vorder,
333 REAL *baseData,
334 REAL *retPoint, REAL* retdu, REAL *retdv);
335
336 void inDoDomain2WithDerivsBU(int k, REAL u, REAL v,
337 REAL u1, REAL u2, int uorder,
338 REAL v1, REAL v2, int vorder,
339 REAL *baseData,
340 REAL *retPoint, REAL* retdu, REAL *retdv);
341
342
343 void inDoEvalCoord2NOGE_BV(REAL u, REAL v,
344 REAL *retPoint, REAL *retNormal);
345
346 void inDoEvalCoord2NOGE_BU(REAL u, REAL v,
347 REAL *retPoint, REAL *retNormal);
348
349 void inBPMEval(bezierPatchMesh* bpm);
350 void inBPMListEval(bezierPatchMesh* list);
351
352 /*-------------begin for surfEvalMachine -------------*/
353 surfEvalMachine em_vertex;
354 surfEvalMachine em_normal;
355 surfEvalMachine em_color;
356 surfEvalMachine em_texcoord;
357
358 int auto_normal_flag; //whether to output normla or not in callback
359 //determined by GL_AUTO_NORMAL and callback_auto_normal
360 int callback_auto_normal; //GLU_CALLBACK_AUTO_NORMAL_EXT
361 int vertex_flag;
362 int normal_flag;
363 int color_flag;
364 int texcoord_flag;
365
366 void inMap2fEM(int which, //0:vert,1:norm,2:color,3:tex
367 int dimension,
368 REAL ulower,
369 REAL uupper,
370 int ustride,
371 int uorder,
372 REAL vlower,
373 REAL vupper,
374 int vstride,
375 int vorder,
376 REAL *ctlPoints);
377
378 void inDoDomain2WithDerivsEM(surfEvalMachine *em, REAL u, REAL v,
379 REAL *retPoint, REAL *retdu, REAL *retdv);
380 void inDoDomain2EM(surfEvalMachine *em, REAL u, REAL v,
381 REAL *retPoint);
382 void inDoEvalCoord2EM(REAL u, REAL v);
383
384 void inBPMEvalEM(bezierPatchMesh* bpm);
385 void inBPMListEvalEM(bezierPatchMesh* list);
386
387 /*-------------end for surfEvalMachine -------------*/
388
389
390 /*************end for internal evaluators*****************/
391
392 };
393
394 inline void StoredVertex::invoke(OpenGLSurfaceEvaluator *eval)
395 {
396 switch(type) {
397 case TYPECOORD:
398 eval->coord2f(coord[0], coord[1]);
399 break;
400 case TYPEPOINT:
401 eval->point2i(point[0], point[1]);
402 break;
403 default:
404 break;
405 }
406 }
407
408 #endif /* __gluglsurfeval_h_ */