2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
36 #ifndef __gluglsurfeval_h_
37 #define __gluglsurfeval_h_
39 #include "basicsurfeval.h"
40 #include "bezierPatchMesh.h" //in case output triangles
45 class OpenGLSurfaceEvaluator
;
51 /* Cache up to 3 vertices from tmeshes */
52 #define VERTEX_CACHE_SIZE 3
54 /*for internal evaluator callback stuff*/
55 #ifndef IN_MAX_BEZIER_ORDER
56 #define IN_MAX_BEZIER_ORDER 40 /*XXX should be bigger than machine order*/
59 #ifndef IN_MAX_DIMENSION
60 #define IN_MAX_DIMENSION 4
63 typedef struct surfEvalMachine
{
64 REAL uprime
;//cached previusly evaluated uprime.
66 int k
; /*the dimension*/
75 REAL ctlPoints
[IN_MAX_BEZIER_ORDER
*IN_MAX_BEZIER_ORDER
*IN_MAX_DIMENSION
];
76 REAL ucoeff
[IN_MAX_BEZIER_ORDER
]; /*cache the polynomial values*/
77 REAL vcoeff
[IN_MAX_BEZIER_ORDER
];
78 REAL ucoeffDeriv
[IN_MAX_BEZIER_ORDER
]; /*cache the polynomial derivatives*/
79 REAL vcoeffDeriv
[IN_MAX_BEZIER_ORDER
];
86 StoredVertex() { type
= 0; }
87 ~StoredVertex(void) {}
88 void saveEvalCoord(REAL x
, REAL y
)
89 {coord
[0] = x
; coord
[1] = y
; type
= TYPECOORD
; }
90 void saveEvalPoint(long x
, long y
)
91 {point
[0] = x
; point
[1] = y
; type
= TYPEPOINT
; }
92 void invoke(OpenGLSurfaceEvaluator
*eval
);
100 class OpenGLSurfaceEvaluator
: public BasicSurfaceEvaluator
{
102 OpenGLSurfaceEvaluator();
103 virtual ~OpenGLSurfaceEvaluator( void );
104 void polymode( long style
);
105 void range2f( long, REAL
*, REAL
* );
106 void domain2f( REAL
, REAL
, REAL
, REAL
);
107 void addMap( SurfaceMap
* ) { }
110 void disable( long );
111 void bgnmap2f( long );
112 void map2f( long, REAL
, REAL
, long, long,
113 REAL
, REAL
, long, long, REAL
* );
114 void mapgrid2f( long, REAL
, REAL
, long, REAL
, REAL
);
115 void mapmesh2f( long, long, long, long, long );
116 void evalcoord2f( long, REAL
, REAL
);
117 void evalpoint2i( long, long );
118 void endmap2f( void );
120 void bgnline( void );
121 void endline( void );
122 void bgnclosedline( void );
123 void endclosedline( void );
124 void bgntmesh( void );
125 void swaptmesh( void );
126 void endtmesh( void );
127 void bgnqstrip( void );
128 void endqstrip( void );
130 void bgntfan( void );
131 void endtfan( void );
132 void evalUStrip(int n_upper
, REAL v_upper
, REAL
* upper_val
,
133 int n_lower
, REAL v_lower
, REAL
* lower_val
);
134 void evalVStrip(int n_left
, REAL u_left
, REAL
* left_val
,
135 int n_right
, REAL u_right
, REAL
* right_val
);
137 void coord2f( REAL
, REAL
);
138 void point2i( long, long );
140 void newtmeshvert( REAL
, REAL
);
141 void newtmeshvert( long, long );
144 void putCallBack(GLenum which
, void (GLAPIENTRY
*fn
)() );
146 void putCallBack(GLenum which
, _GLUfuncptr fn
);
149 int get_vertices_call_back()
151 return output_triangles
;
153 void put_vertices_call_back(int flag
)
155 output_triangles
= flag
;
158 void put_callback_auto_normal(int flag
)
160 callback_auto_normal
= flag
;
163 int get_callback_auto_normal()
165 return callback_auto_normal
;
168 void set_callback_userData(void* data
)
173 /**************begin for LOD_eval_list***********/
174 void LOD_eval_list(int level
);
180 StoredVertex
*vertexCache
[VERTEX_CACHE_SIZE
];
185 GLint gl_polygon_mode
[2];/*to save and restore so that
188 bezierPatchMesh
*global_bpm
; //for output triangles
189 int output_triangles
; //true 1 or false 0
193 void (GLAPIENTRY
*beginCallBackN
) (GLenum type
);
194 void (GLAPIENTRY
*endCallBackN
) (void);
195 void (GLAPIENTRY
*vertexCallBackN
) (const GLfloat
*vert
);
196 void (GLAPIENTRY
*normalCallBackN
) (const GLfloat
*normal
);
197 void (GLAPIENTRY
*colorCallBackN
) (const GLfloat
*color
);
198 void (GLAPIENTRY
*texcoordCallBackN
) (const GLfloat
*texcoord
);
200 void (GLAPIENTRY
*beginCallBackData
) (GLenum type
, void* data
);
201 void (GLAPIENTRY
*endCallBackData
) (void* data
);
202 void (GLAPIENTRY
*vertexCallBackData
) (const GLfloat
*vert
, void* data
);
203 void (GLAPIENTRY
*normalCallBackData
) (const GLfloat
*normal
, void* data
);
204 void (GLAPIENTRY
*colorCallBackData
) (const GLfloat
*color
, void* data
);
205 void (GLAPIENTRY
*texcoordCallBackData
) (const GLfloat
*texcoord
, void* data
);
207 void beginCallBack (GLenum type
, void* data
);
208 void endCallBack (void* data
);
209 void vertexCallBack (const GLfloat
*vert
, void* data
);
210 void normalCallBack (const GLfloat
*normal
, void* data
);
211 void colorCallBack (const GLfloat
*color
, void* data
);
212 void texcoordCallBack (const GLfloat
*texcoord
, void* data
);
215 void* userData
; //the opaque pointer for Data callback functions.
218 void LOD_triangle(REAL A
[2], REAL B
[2], REAL C
[2],
220 void LOD_eval(int num_vert
, REAL
* verts
, int type
, int level
);
222 int LOD_eval_level
; //set by LOD_eval_list()
224 /*************begin for internal evaluators*****************/
226 /*the following global variables are only defined in this file.
227 *They are used to cache the precomputed Bezier polynomial values.
228 *These calues may be used consecutively in which case we don't have
229 *recompute these values again.
231 int global_uorder
; /*store the uorder in the previous evaluation*/
232 int global_vorder
; /*store the vorder in the previous evaluation*/
235 REAL global_vprime_BV
;
236 REAL global_uprime_BU
;
237 int global_uorder_BV
; /*store the uorder in the previous evaluation*/
238 int global_vorder_BV
; /*store the vorder in the previous evaluation*/
239 int global_uorder_BU
; /*store the uorder in the previous evaluation*/
240 int global_vorder_BU
; /*store the vorder in the previous evaluation*/
242 REAL global_ucoeff
[IN_MAX_BEZIER_ORDER
]; /*cache the polynomial values*/
243 REAL global_vcoeff
[IN_MAX_BEZIER_ORDER
];
244 REAL global_ucoeffDeriv
[IN_MAX_BEZIER_ORDER
]; /*cache the polynomial derivatives*/
245 REAL global_vcoeffDeriv
[IN_MAX_BEZIER_ORDER
];
247 REAL global_BV
[IN_MAX_BEZIER_ORDER
][IN_MAX_DIMENSION
];
248 REAL global_PBV
[IN_MAX_BEZIER_ORDER
][IN_MAX_DIMENSION
];
249 REAL global_BU
[IN_MAX_BEZIER_ORDER
][IN_MAX_DIMENSION
];
250 REAL global_PBU
[IN_MAX_BEZIER_ORDER
][IN_MAX_DIMENSION
];
251 REAL
* global_baseData
;
253 int global_ev_k
; /*the dimension*/
256 int global_ev_ustride
;
257 int global_ev_uorder
;
260 int global_ev_vstride
;
261 int global_ev_vorder
;
262 REAL global_ev_ctlPoints
[IN_MAX_BEZIER_ORDER
*IN_MAX_BEZIER_ORDER
*IN_MAX_DIMENSION
];
272 void inDoDomain2WithDerivs(int k
, REAL u
, REAL v
,
273 REAL u1
, REAL u2
, int uorder
,
274 REAL v1
, REAL v2
, int vorder
,
276 REAL
*retPoint
, REAL
*retdu
, REAL
*retdv
);
277 void inPreEvaluate(int order
, REAL vprime
, REAL
*coeff
);
278 void inPreEvaluateWithDeriv(int order
, REAL vprime
, REAL
*coeff
, REAL
*coeffDeriv
);
279 void inComputeFirstPartials(REAL
*p
, REAL
*pu
, REAL
*pv
);
280 void inComputeNormal2(REAL
*pu
, REAL
*pv
, REAL
*n
);
281 void inDoEvalCoord2(REAL u
, REAL v
,
282 REAL
*retPoint
, REAL
*retNormal
);
283 void inDoEvalCoord2NOGE(REAL u
, REAL v
,
284 REAL
*retPoint
, REAL
*retNormal
);
296 void inMapGrid2f(int nu
, REAL u0
, REAL u1
,
297 int nv
, REAL v0
, REAL v1
);
299 void inEvalMesh2(int lowU
, int lowV
, int highU
, int highV
);
300 void inEvalPoint2(int i
, int j
);
301 void inEvalCoord2f(REAL u
, REAL v
);
303 void inEvalULine(int n_points
, REAL v
, REAL
* u_vals
,
304 int stride
, REAL ret_points
[][3], REAL ret_normals
[][3]);
306 void inEvalVLine(int n_points
, REAL u
, REAL
* v_vals
,
307 int stride
, REAL ret_points
[][3], REAL ret_normals
[][3]);
309 void inEvalUStrip(int n_upper
, REAL v_upper
, REAL
* upper_val
,
310 int n_lower
, REAL v_lower
, REAL
* lower_val
312 void inEvalVStrip(int n_left
, REAL u_left
, REAL
* left_val
, int n_right
, REAL u_right
, REAL
* right_val
);
314 void inPreEvaluateBV(int k
, int uorder
, int vorder
, REAL vprime
, REAL
*baseData
);
315 void inPreEvaluateBU(int k
, int uorder
, int vorder
, REAL uprime
, REAL
*baseData
);
316 void inPreEvaluateBV_intfac(REAL v
)
318 inPreEvaluateBV(global_ev_k
, global_ev_uorder
, global_ev_vorder
, (v
-global_ev_v1
)/(global_ev_v2
-global_ev_v1
), global_ev_ctlPoints
);
321 void inPreEvaluateBU_intfac(REAL u
)
323 inPreEvaluateBU(global_ev_k
, global_ev_uorder
, global_ev_vorder
, (u
-global_ev_u1
)/(global_ev_u2
-global_ev_u1
), global_ev_ctlPoints
);
326 void inDoDomain2WithDerivsBV(int k
, REAL u
, REAL v
,
327 REAL u1
, REAL u2
, int uorder
,
328 REAL v1
, REAL v2
, int vorder
,
330 REAL
*retPoint
, REAL
* retdu
, REAL
*retdv
);
332 void inDoDomain2WithDerivsBU(int k
, REAL u
, REAL v
,
333 REAL u1
, REAL u2
, int uorder
,
334 REAL v1
, REAL v2
, int vorder
,
336 REAL
*retPoint
, REAL
* retdu
, REAL
*retdv
);
339 void inDoEvalCoord2NOGE_BV(REAL u
, REAL v
,
340 REAL
*retPoint
, REAL
*retNormal
);
342 void inDoEvalCoord2NOGE_BU(REAL u
, REAL v
,
343 REAL
*retPoint
, REAL
*retNormal
);
345 void inBPMEval(bezierPatchMesh
* bpm
);
346 void inBPMListEval(bezierPatchMesh
* list
);
348 /*-------------begin for surfEvalMachine -------------*/
349 surfEvalMachine em_vertex
;
350 surfEvalMachine em_normal
;
351 surfEvalMachine em_color
;
352 surfEvalMachine em_texcoord
;
354 int auto_normal_flag
; //whether to output normla or not in callback
355 //determined by GL_AUTO_NORMAL and callback_auto_normal
356 int callback_auto_normal
; //GLU_CALLBACK_AUTO_NORMAL_EXT
362 void inMap2fEM(int which
, //0:vert,1:norm,2:color,3:tex
374 void inDoDomain2WithDerivsEM(surfEvalMachine
*em
, REAL u
, REAL v
,
375 REAL
*retPoint
, REAL
*retdu
, REAL
*retdv
);
376 void inDoDomain2EM(surfEvalMachine
*em
, REAL u
, REAL v
,
378 void inDoEvalCoord2EM(REAL u
, REAL v
);
380 void inBPMEvalEM(bezierPatchMesh
* bpm
);
381 void inBPMListEvalEM(bezierPatchMesh
* list
);
383 /*-------------end for surfEvalMachine -------------*/
386 /*************end for internal evaluators*****************/
390 inline void StoredVertex::invoke(OpenGLSurfaceEvaluator
*eval
)
394 eval
->coord2f(coord
[0], coord
[1]);
397 eval
->point2i(point
[0], point
[1]);
404 #endif /* __gluglsurfeval_h_ */