1 /*
2  * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3  * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4  *
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:
11  *
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.
16  *
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
23  * SOFTWARE.
24  *
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.
29  */
30 
31 /*
32  * glcurveval.h
33  *
34  */
35 
36 #ifndef __gluglcurveval_h_
37 #define __gluglcurveval_h_
38 
39 #include "gluos.h"
40 #include <GL/gl.h>
41 #include <GL/glu.h>
42 #include "basiccrveval.h"
43 
44 class CurveMap;
45 
46 /*for internal evaluator callback stuff*/
47 #ifndef IN_MAX_BEZIER_ORDER
48 #define IN_MAX_BEZIER_ORDER 40 /*XXX should be bigger than machine order*/
49 #endif
50 
51 #ifndef IN_MAX_DIMENSION
52 #define IN_MAX_DIMENSION 4
53 #endif
54 
55 typedef struct curveEvalMachine{
56   REAL uprime; //cached previously evaluated uprime
57   int k; //the dimension
58   REAL u1;
59   REAL u2;
60   int ustride;
61   int uorder;
62   REAL ctlpoints[IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION];
63   REAL ucoeff[IN_MAX_BEZIER_ORDER];//cache the polynomial values
64 } curveEvalMachine;
65 
66 class OpenGLCurveEvaluator : public BasicCurveEvaluator  {
67 public:
68 			OpenGLCurveEvaluator(void);
69 			virtual ~OpenGLCurveEvaluator(void);
70     void		range1f(long, REAL *, REAL *);
71     void		domain1f(REAL, REAL);
72     void		addMap(CurveMap *);
73 
74     void		enable(long);
75     void		disable(long);
76     void		bgnmap1f(long);
77     void		map1f(long, REAL, REAL, long, long, REAL *);
78     void		mapgrid1f(long, REAL, REAL);
79     void		mapmesh1f(long, long, long);
80     void		evalpoint1i(long);
81     void		evalcoord1f(long, REAL);
82     void		endmap1f(void);
83 
84     void		bgnline(void);
85     void		endline(void);
86 
put_vertices_call_back(int flag)87     void                put_vertices_call_back(int flag)
88       {
89 	output_triangles = flag;
90       }
91 #ifdef _WIN32
92     void               putCallBack(GLenum which, void (GLAPIENTRY *fn)() );
93 #else
94     void               putCallBack(GLenum which, _GLUfuncptr fn );
95 #endif
set_callback_userData(void * data)96     void               set_callback_userData(void *data)
97       {
98 	userData = data;
99       }
100 
101 /*------------------begin for curveEvalMachine------------*/
102 curveEvalMachine em_vertex;
103 curveEvalMachine em_normal;
104 curveEvalMachine em_color;
105 curveEvalMachine em_texcoord;
106 int vertex_flag; //whether there is a vertex map or not
107 int normal_flag; //whether there is a normal map or not
108 int color_flag; //whether there is a color map or not
109 int texcoord_flag; //whether there is a texture map or not
110 
111 REAL global_grid_u0;
112 REAL global_grid_u1;
113 int global_grid_nu;
114 
115 void inMap1f(int which, //0: vert, 1: norm, 2: color, 3: tex
116 	     int dimension,
117 	     REAL ulower,
118 	     REAL uupper,
119 	     int ustride,
120 	     int uorder,
121 	     REAL *ctlpoints);
122 
123 void inPreEvaluate(int order, REAL vprime, REAL *coeff);
124 void inDoDomain1(curveEvalMachine *em, REAL u, REAL *retPoint);
125 void inDoEvalCoord1(REAL u);
126 void inMapMesh1f(int umin, int umax);
127 
128 void     (GLAPIENTRY *beginCallBackN) (GLenum type);
129 void     (GLAPIENTRY *endCallBackN)   (void);
130 void     (GLAPIENTRY *vertexCallBackN) (const GLfloat *vert);
131 void     (GLAPIENTRY *normalCallBackN) (const GLfloat *normal);
132 void     (GLAPIENTRY *colorCallBackN) (const GLfloat *color);
133 void     (GLAPIENTRY *texcoordCallBackN) (const GLfloat *texcoord);
134 
135 void     (GLAPIENTRY *beginCallBackData) (GLenum type, void* data);
136 void     (GLAPIENTRY *endCallBackData)   (void* data);
137 void     (GLAPIENTRY *vertexCallBackData) (const GLfloat *vert, void* data);
138 void     (GLAPIENTRY *normalCallBackData) (const GLfloat *normal, void* data);
139 void     (GLAPIENTRY *colorCallBackData) (const GLfloat *color, void* data);
140 void     (GLAPIENTRY *texcoordCallBackData) (const GLfloat *texcoord, void* data);
141 
142 void* userData; //the opaque pointer for Data callback functions
143 void  beginCallBack(GLenum type, void* data);
144 void endCallBack(void* data);
145 void vertexCallBack(const GLfloat *vert, void *data);
146 void normalCallBack(const GLfloat *normal, void* data);
147 void colorCallBack(const  GLfloat *color, void* data);
148 void texcoordCallBack(const GLfloat *texcoord, void* data);
149 
150 
151 /*------------------end   for curveEvalMachine------------*/
152 
153 private:
154     int output_triangles; //true 1; false 0
155 };
156 
157 #endif /* __gluglcurveval_h_ */
158