allow using an absolute %(dir) path
[AROS.git] / workbench / libs / mesa / src / glu / sgi / libnurbs / interface / glrenderer.cc
blob17123fbc614df143fadd402eebb22824683ac350
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
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.
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.
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.
38 #include "gluos.h"
39 #include "glimports.h"
40 #include "glrenderer.h"
42 GLUnurbs::GLUnurbs()
43 : NurbsTessellator(curveEvaluator, surfaceEvaluator)
45 redefineMaps();
46 defineMap(GL_MAP2_NORMAL, 0, 3);
47 defineMap(GL_MAP1_NORMAL, 0, 3);
48 defineMap(GL_MAP2_TEXTURE_COORD_1, 0, 1);
49 defineMap(GL_MAP1_TEXTURE_COORD_1, 0, 1);
50 defineMap(GL_MAP2_TEXTURE_COORD_2, 0, 2);
51 defineMap(GL_MAP1_TEXTURE_COORD_2, 0, 2);
52 defineMap(GL_MAP2_TEXTURE_COORD_3, 0, 3);
53 defineMap(GL_MAP1_TEXTURE_COORD_3, 0, 3);
54 defineMap(GL_MAP2_TEXTURE_COORD_4, 1, 4);
55 defineMap(GL_MAP1_TEXTURE_COORD_4, 1, 4);
56 defineMap(GL_MAP2_VERTEX_4, 1, 4);
57 defineMap(GL_MAP1_VERTEX_4, 1, 4);
58 defineMap(GL_MAP2_VERTEX_3, 0, 3);
59 defineMap(GL_MAP1_VERTEX_3, 0, 3);
60 defineMap(GL_MAP2_COLOR_4, 0, 4);
61 defineMap(GL_MAP1_COLOR_4, 0, 4);
62 defineMap(GL_MAP2_INDEX, 0, 1);
63 defineMap(GL_MAP1_INDEX, 0, 1);
65 setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
66 setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
67 setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
68 setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
70 setnurbsproperty(GL_MAP1_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0);
71 setnurbsproperty(GL_MAP1_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0);
72 setnurbsproperty(GL_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0);
73 setnurbsproperty(GL_MAP2_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0);
75 setnurbsproperty(GL_MAP1_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50);
76 setnurbsproperty(GL_MAP1_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50);
77 setnurbsproperty(GL_MAP2_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50);
78 setnurbsproperty(GL_MAP2_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50);
80 setnurbsproperty(GL_MAP1_VERTEX_3, N_S_STEPS, (float) 100.0);
81 setnurbsproperty(GL_MAP1_VERTEX_4, N_S_STEPS, (float) 100.0);
82 setnurbsproperty(GL_MAP2_VERTEX_3, N_S_STEPS, (float) 100.0);
83 setnurbsproperty(GL_MAP2_VERTEX_4, N_S_STEPS, (float) 100.0);
85 //added for optimizing untrimmed case
86 set_domain_distance_u_rate(100.0);
88 setnurbsproperty(GL_MAP1_VERTEX_3, N_T_STEPS, (float) 100.0);
89 setnurbsproperty(GL_MAP1_VERTEX_4, N_T_STEPS, (float) 100.0);
90 setnurbsproperty(GL_MAP2_VERTEX_3, N_T_STEPS, (float) 100.0);
91 setnurbsproperty(GL_MAP2_VERTEX_4, N_T_STEPS, (float) 100.0);
93 //added for optimizing untrimmed case
94 set_domain_distance_v_rate(100.0);
95 set_is_domain_distance_sampling(0); //since the default is path_length
97 //default autoloadmode is true
98 autoloadmode = 1;
100 //default callbackFlag is 0
101 callbackFlag = 0;
103 errorCallback = NULL;
106 void
107 GLUnurbs::bgnrender(void)
109 if (autoloadmode) {
110 loadGLMatrices();
114 void
115 GLUnurbs::endrender(void)
119 void
120 GLUnurbs::errorHandler(int i)
122 int gluError;
124 gluError = i + (GLU_NURBS_ERROR1 - 1);
125 postError( gluError );
128 void
129 GLUnurbs::loadGLMatrices(void)
131 GLfloat vmat[4][4];
132 GLint viewport[4];
134 grabGLMatrix((GLfloat (*)[4]) vmat);
135 loadCullingMatrix((GLfloat (*)[4]) vmat);
136 ::glGetIntegerv((GLenum) GL_VIEWPORT, (GLint *) viewport);
137 loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport);
140 void
141 GLUnurbs::useGLMatrices(const GLfloat modelMatrix[16],
142 const GLfloat projMatrix[16],
143 const GLint viewport[4])
145 GLfloat vmat[4][4];
147 multmatrix4d(vmat, (const GLfloat (*)[4]) modelMatrix,
148 (const GLfloat (*)[4]) projMatrix);
149 loadCullingMatrix((GLfloat (*)[4]) vmat);
150 loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport);
153 /*--------------------------------------------------------------------------
154 * grabGLMatrix
155 *--------------------------------------------------------------------------
158 void
159 GLUnurbs::grabGLMatrix(GLfloat vmat[4][4])
161 GLfloat m1[4][4], m2[4][4];
163 ::glGetFloatv((GLenum) GL_MODELVIEW_MATRIX, (GLfloat *) &(m1[0][0]));
164 ::glGetFloatv((GLenum) GL_PROJECTION_MATRIX, (GLfloat *) &(m2[0][0]));
165 multmatrix4d((GLfloat (*)[4]) vmat,
166 (const GLfloat (*)[4]) m1, (const GLfloat (*)[4]) m2);
169 //for object space tesselation: view independent
170 void
171 GLUnurbs::setSamplingMatrixIdentity( void )
173 INREAL smat[4][4] = {
174 {1,0,0,0},
175 {0,1,0,0},
176 {0,0,1,0},
177 {0,0,0,1}
179 const long rstride = sizeof(smat[0]) / sizeof(smat[0][0]);
180 const long cstride = 1;
182 setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
183 cstride);
184 setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
185 cstride);
186 setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
187 cstride);
188 setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
189 cstride);
193 void
194 GLUnurbs::loadSamplingMatrix(const GLfloat vmat[4][4],
195 const GLint viewport[4])
198 /* rescale the mapping to correspond to pixels in x/y */
199 REAL xsize = 0.5 * (REAL) (viewport[2]);
200 REAL ysize = 0.5 * (REAL) (viewport[3]);
202 INREAL smat[4][4];
203 smat[0][0] = vmat[0][0] * xsize;
204 smat[1][0] = vmat[1][0] * xsize;
205 smat[2][0] = vmat[2][0] * xsize;
206 smat[3][0] = vmat[3][0] * xsize;
208 smat[0][1] = vmat[0][1] * ysize;
209 smat[1][1] = vmat[1][1] * ysize;
210 smat[2][1] = vmat[2][1] * ysize;
211 smat[3][1] = vmat[3][1] * ysize;
213 smat[0][2] = 0.0;
214 smat[1][2] = 0.0;
215 smat[2][2] = 0.0;
216 smat[3][2] = 0.0;
218 smat[0][3] = vmat[0][3];
219 smat[1][3] = vmat[1][3];
220 smat[2][3] = vmat[2][3];
221 smat[3][3] = vmat[3][3];
223 const long rstride = sizeof(smat[0]) / sizeof(smat[0][0]);
224 const long cstride = 1;
226 setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
227 cstride);
228 setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
229 cstride);
230 setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
231 cstride);
232 setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
233 cstride);
236 void
237 GLUnurbs::loadCullingMatrix(GLfloat vmat[4][4])
239 INREAL cmat[4][4];
241 cmat[0][0] = vmat[0][0];
242 cmat[0][1] = vmat[0][1];
243 cmat[0][2] = vmat[0][2];
244 cmat[0][3] = vmat[0][3];
246 cmat[1][0] = vmat[1][0];
247 cmat[1][1] = vmat[1][1];
248 cmat[1][2] = vmat[1][2];
249 cmat[1][3] = vmat[1][3];
251 cmat[2][0] = vmat[2][0];
252 cmat[2][1] = vmat[2][1];
253 cmat[2][2] = vmat[2][2];
254 cmat[2][3] = vmat[2][3];
256 cmat[3][0] = vmat[3][0];
257 cmat[3][1] = vmat[3][1];
258 cmat[3][2] = vmat[3][2];
259 cmat[3][3] = vmat[3][3];
261 const long rstride = sizeof(cmat[0]) / sizeof(cmat[0][0]);
262 const long cstride = 1;
264 setnurbsproperty(GL_MAP2_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride,
265 cstride);
266 setnurbsproperty(GL_MAP2_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride,
267 cstride);
268 //added for curves by zl
269 setnurbsproperty(GL_MAP1_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride,
270 cstride);
271 setnurbsproperty(GL_MAP1_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride,
272 cstride);
275 /*---------------------------------------------------------------------
276 * A = B * MAT ; transform a 4d vector through a 4x4 matrix
277 *---------------------------------------------------------------------
279 void
280 GLUnurbs::transform4d(GLfloat A[4], GLfloat B[4], GLfloat mat[4][4])
283 A[0] = B[0]*mat[0][0] + B[1]*mat[1][0] + B[2]*mat[2][0] + B[3]*mat[3][0];
284 A[1] = B[0]*mat[0][1] + B[1]*mat[1][1] + B[2]*mat[2][1] + B[3]*mat[3][1];
285 A[2] = B[0]*mat[0][2] + B[1]*mat[1][2] + B[2]*mat[2][2] + B[3]*mat[3][2];
286 A[3] = B[0]*mat[0][3] + B[1]*mat[1][3] + B[2]*mat[2][3] + B[3]*mat[3][3];
289 /*---------------------------------------------------------------------
290 * new = [left][right] ; multiply two matrices together
291 *---------------------------------------------------------------------
293 void
294 GLUnurbs::multmatrix4d (GLfloat n[4][4], const GLfloat left[4][4],
295 const GLfloat right[4][4])
297 transform4d ((GLfloat *) n[0],(GLfloat *) left[0],(GLfloat (*)[4]) right);
298 transform4d ((GLfloat *) n[1],(GLfloat *) left[1],(GLfloat (*)[4]) right);
299 transform4d ((GLfloat *) n[2],(GLfloat *) left[2],(GLfloat (*)[4]) right);
300 transform4d ((GLfloat *) n[3],(GLfloat *) left[3],(GLfloat (*)[4]) right);