| 1 | /* $Id: glrenderer.cpp,v 1.1 2000-02-09 08:49:01 jeroen Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | ** License Applicability. Except to the extent portions of this file are
|
|---|
| 4 | ** made subject to an alternative license as permitted in the SGI Free
|
|---|
| 5 | ** Software License B, Version 1.0 (the "License"), the contents of this
|
|---|
| 6 | ** file are subject only to the provisions of the License. You may not use
|
|---|
| 7 | ** this file except in compliance with the License. You may obtain a copy
|
|---|
| 8 | ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
|---|
| 9 | ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
|---|
| 10 | **
|
|---|
| 11 | ** http://oss.sgi.com/projects/FreeB
|
|---|
| 12 | **
|
|---|
| 13 | ** Note that, as provided in the License, the Software is distributed on an
|
|---|
| 14 | ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
|---|
| 15 | ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
|---|
| 16 | ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
|---|
| 17 | ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|---|
| 18 | **
|
|---|
| 19 | ** Original Code. The Original Code is: OpenGL Sample Implementation,
|
|---|
| 20 | ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
|---|
| 21 | ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
|---|
| 22 | ** Copyright in any portions created by third parties is as indicated
|
|---|
| 23 | ** elsewhere herein. All Rights Reserved.
|
|---|
| 24 | **
|
|---|
| 25 | ** Additional Notice Provisions: The application programming interfaces
|
|---|
| 26 | ** established by SGI in conjunction with the Original Code are The
|
|---|
| 27 | ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
|---|
| 28 | ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
|---|
| 29 | ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
|---|
| 30 | ** Window System(R) (Version 1.3), released October 19, 1998. This software
|
|---|
| 31 | ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
|---|
| 32 | ** published by SGI, but has not been independently verified as being
|
|---|
| 33 | ** compliant with the OpenGL(R) version 1.2.1 Specification.
|
|---|
| 34 | **
|
|---|
| 35 | ** $Date: 2000-02-09 08:49:01 $ $Revision: 1.1 $
|
|---|
| 36 | */
|
|---|
| 37 | /*
|
|---|
| 38 | ** $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/nurbs/interface/glrenderer.cpp,v 1.1 2000-02-09 08:49:01 jeroen Exp $
|
|---|
| 39 | */
|
|---|
| 40 |
|
|---|
| 41 | #include "gluos.h"
|
|---|
| 42 | #include "glimports.h"
|
|---|
| 43 | #include "glrenderer.h"
|
|---|
| 44 |
|
|---|
| 45 | GLUnurbs::GLUnurbs()
|
|---|
| 46 | : NurbsTessellator(curveEvaluator, surfaceEvaluator)
|
|---|
| 47 | {
|
|---|
| 48 | redefineMaps();
|
|---|
| 49 | defineMap(GL_MAP2_NORMAL, 0, 3);
|
|---|
| 50 | defineMap(GL_MAP1_NORMAL, 0, 3);
|
|---|
| 51 | defineMap(GL_MAP2_TEXTURE_COORD_1, 0, 1);
|
|---|
| 52 | defineMap(GL_MAP1_TEXTURE_COORD_1, 0, 1);
|
|---|
| 53 | defineMap(GL_MAP2_TEXTURE_COORD_2, 0, 2);
|
|---|
| 54 | defineMap(GL_MAP1_TEXTURE_COORD_2, 0, 2);
|
|---|
| 55 | defineMap(GL_MAP2_TEXTURE_COORD_3, 0, 3);
|
|---|
| 56 | defineMap(GL_MAP1_TEXTURE_COORD_3, 0, 3);
|
|---|
| 57 | defineMap(GL_MAP2_TEXTURE_COORD_4, 1, 4);
|
|---|
| 58 | defineMap(GL_MAP1_TEXTURE_COORD_4, 1, 4);
|
|---|
| 59 | defineMap(GL_MAP2_VERTEX_4, 1, 4);
|
|---|
| 60 | defineMap(GL_MAP1_VERTEX_4, 1, 4);
|
|---|
| 61 | defineMap(GL_MAP2_VERTEX_3, 0, 3);
|
|---|
| 62 | defineMap(GL_MAP1_VERTEX_3, 0, 3);
|
|---|
| 63 | defineMap(GL_MAP2_COLOR_4, 0, 4);
|
|---|
| 64 | defineMap(GL_MAP1_COLOR_4, 0, 4);
|
|---|
| 65 | defineMap(GL_MAP2_INDEX, 0, 1);
|
|---|
| 66 | defineMap(GL_MAP1_INDEX, 0, 1);
|
|---|
| 67 |
|
|---|
| 68 | setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
|
|---|
| 69 | setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
|
|---|
| 70 | setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
|
|---|
| 71 | setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
|
|---|
| 72 |
|
|---|
| 73 | setnurbsproperty(GL_MAP1_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0);
|
|---|
| 74 | setnurbsproperty(GL_MAP1_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0);
|
|---|
| 75 | setnurbsproperty(GL_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0);
|
|---|
| 76 | setnurbsproperty(GL_MAP2_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0);
|
|---|
| 77 |
|
|---|
| 78 | setnurbsproperty(GL_MAP1_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50);
|
|---|
| 79 | setnurbsproperty(GL_MAP1_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50);
|
|---|
| 80 | setnurbsproperty(GL_MAP2_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50);
|
|---|
| 81 | setnurbsproperty(GL_MAP2_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50);
|
|---|
| 82 |
|
|---|
| 83 | setnurbsproperty(GL_MAP1_VERTEX_3, N_S_STEPS, (float) 100.0);
|
|---|
| 84 | setnurbsproperty(GL_MAP1_VERTEX_4, N_S_STEPS, (float) 100.0);
|
|---|
| 85 | setnurbsproperty(GL_MAP2_VERTEX_3, N_S_STEPS, (float) 100.0);
|
|---|
| 86 | setnurbsproperty(GL_MAP2_VERTEX_4, N_S_STEPS, (float) 100.0);
|
|---|
| 87 |
|
|---|
| 88 | //added for optimizing untrimmed case
|
|---|
| 89 | set_domain_distance_u_rate(100.0);
|
|---|
| 90 |
|
|---|
| 91 | setnurbsproperty(GL_MAP1_VERTEX_3, N_T_STEPS, (float) 100.0);
|
|---|
| 92 | setnurbsproperty(GL_MAP1_VERTEX_4, N_T_STEPS, (float) 100.0);
|
|---|
| 93 | setnurbsproperty(GL_MAP2_VERTEX_3, N_T_STEPS, (float) 100.0);
|
|---|
| 94 | setnurbsproperty(GL_MAP2_VERTEX_4, N_T_STEPS, (float) 100.0);
|
|---|
| 95 |
|
|---|
| 96 | //added for optimizing untrimmed case
|
|---|
| 97 | set_domain_distance_v_rate(100.0);
|
|---|
| 98 | set_is_domain_distance_sampling(0); //since the default is path_length
|
|---|
| 99 |
|
|---|
| 100 | //default autoloadmode is true
|
|---|
| 101 | autoloadmode = 1;
|
|---|
| 102 |
|
|---|
| 103 | //default callbackFlag is 0
|
|---|
| 104 | callbackFlag = 0;
|
|---|
| 105 |
|
|---|
| 106 | errorCallback = NULL;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | void
|
|---|
| 110 | GLUnurbs::bgnrender(void)
|
|---|
| 111 | {
|
|---|
| 112 | if (autoloadmode) {
|
|---|
| 113 | loadGLMatrices();
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | void
|
|---|
| 118 | GLUnurbs::endrender(void)
|
|---|
| 119 | {
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | void
|
|---|
| 123 | GLUnurbs::errorHandler(int i)
|
|---|
| 124 | {
|
|---|
| 125 | int gluError;
|
|---|
| 126 |
|
|---|
| 127 | gluError = i + (GLU_NURBS_ERROR1 - 1);
|
|---|
| 128 | postError( gluError );
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | void
|
|---|
| 132 | GLUnurbs::loadGLMatrices(void)
|
|---|
| 133 | {
|
|---|
| 134 | GLfloat vmat[4][4];
|
|---|
| 135 | GLint viewport[4];
|
|---|
| 136 |
|
|---|
| 137 | grabGLMatrix((GLfloat (*)[4]) vmat);
|
|---|
| 138 | loadCullingMatrix((GLfloat (*)[4]) vmat);
|
|---|
| 139 | ::glGetIntegerv((GLenum) GL_VIEWPORT, (GLint *) viewport);
|
|---|
| 140 | loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | void
|
|---|
| 144 | GLUnurbs::useGLMatrices(const GLfloat modelMatrix[16],
|
|---|
| 145 | const GLfloat projMatrix[16],
|
|---|
| 146 | const GLint viewport[4])
|
|---|
| 147 | {
|
|---|
| 148 | GLfloat vmat[4][4];
|
|---|
| 149 |
|
|---|
| 150 | multmatrix4d((GLfloat (*)[4]) vmat, (GLfloat (*)[4]) modelMatrix,
|
|---|
| 151 | (GLfloat (*)[4]) projMatrix);
|
|---|
| 152 | loadCullingMatrix((GLfloat (*)[4]) vmat);
|
|---|
| 153 | loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport);
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | /*--------------------------------------------------------------------------
|
|---|
| 157 | * grabGLMatrix
|
|---|
| 158 | *--------------------------------------------------------------------------
|
|---|
| 159 | */
|
|---|
| 160 |
|
|---|
| 161 | void
|
|---|
| 162 | GLUnurbs::grabGLMatrix(GLfloat vmat[4][4])
|
|---|
| 163 | {
|
|---|
| 164 | GLfloat m1[4][4], m2[4][4];
|
|---|
| 165 |
|
|---|
| 166 | ::glGetFloatv((GLenum) GL_MODELVIEW_MATRIX, (GLfloat *) &(m1[0][0]));
|
|---|
| 167 | ::glGetFloatv((GLenum) GL_PROJECTION_MATRIX, (GLfloat *) &(m2[0][0]));
|
|---|
| 168 | multmatrix4d((GLfloat (*)[4]) vmat,
|
|---|
| 169 | (GLfloat (*)[4]) m1, (GLfloat (*)[4]) m2);
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | //for object space tesselation: view independent
|
|---|
| 173 | void
|
|---|
| 174 | GLUnurbs::setSamplingMatrixIdentity( void )
|
|---|
| 175 | {
|
|---|
| 176 | INREAL smat[4][4] = {
|
|---|
| 177 | {1,0,0,0},
|
|---|
| 178 | {0,1,0,0},
|
|---|
| 179 | {0,0,1,0},
|
|---|
| 180 | {0,0,0,1}
|
|---|
| 181 | };
|
|---|
| 182 | const long rstride = sizeof(smat[0]) / sizeof(smat[0][0]);
|
|---|
| 183 | const long cstride = 1;
|
|---|
| 184 |
|
|---|
| 185 | setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
|
|---|
| 186 | cstride);
|
|---|
| 187 | setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
|
|---|
| 188 | cstride);
|
|---|
| 189 | setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
|
|---|
| 190 | cstride);
|
|---|
| 191 | setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
|
|---|
| 192 | cstride);
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | void
|
|---|
| 197 | GLUnurbs::loadSamplingMatrix(const GLfloat vmat[4][4],
|
|---|
| 198 | const GLint viewport[4])
|
|---|
| 199 | {
|
|---|
| 200 |
|
|---|
| 201 | /* rescale the mapping to correspond to pixels in x/y */
|
|---|
| 202 | REAL xsize = 0.5 * (REAL) (viewport[2]);
|
|---|
| 203 | REAL ysize = 0.5 * (REAL) (viewport[3]);
|
|---|
| 204 |
|
|---|
| 205 | INREAL smat[4][4];
|
|---|
| 206 | smat[0][0] = vmat[0][0] * xsize;
|
|---|
| 207 | smat[1][0] = vmat[1][0] * xsize;
|
|---|
| 208 | smat[2][0] = vmat[2][0] * xsize;
|
|---|
| 209 | smat[3][0] = vmat[3][0] * xsize;
|
|---|
| 210 |
|
|---|
| 211 | smat[0][1] = vmat[0][1] * ysize;
|
|---|
| 212 | smat[1][1] = vmat[1][1] * ysize;
|
|---|
| 213 | smat[2][1] = vmat[2][1] * ysize;
|
|---|
| 214 | smat[3][1] = vmat[3][1] * ysize;
|
|---|
| 215 |
|
|---|
| 216 | smat[0][2] = 0.0;
|
|---|
| 217 | smat[1][2] = 0.0;
|
|---|
| 218 | smat[2][2] = 0.0;
|
|---|
| 219 | smat[3][2] = 0.0;
|
|---|
| 220 |
|
|---|
| 221 | smat[0][3] = vmat[0][3];
|
|---|
| 222 | smat[1][3] = vmat[1][3];
|
|---|
| 223 | smat[2][3] = vmat[2][3];
|
|---|
| 224 | smat[3][3] = vmat[3][3];
|
|---|
| 225 |
|
|---|
| 226 | const long rstride = sizeof(smat[0]) / sizeof(smat[0][0]);
|
|---|
| 227 | const long cstride = 1;
|
|---|
| 228 |
|
|---|
| 229 | setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
|
|---|
| 230 | cstride);
|
|---|
| 231 | setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
|
|---|
| 232 | cstride);
|
|---|
| 233 | setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
|
|---|
| 234 | cstride);
|
|---|
| 235 | setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
|
|---|
| 236 | cstride);
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | void
|
|---|
| 240 | GLUnurbs::loadCullingMatrix(GLfloat vmat[4][4])
|
|---|
| 241 | {
|
|---|
| 242 | INREAL cmat[4][4];
|
|---|
| 243 |
|
|---|
| 244 | cmat[0][0] = vmat[0][0];
|
|---|
| 245 | cmat[0][1] = vmat[0][1];
|
|---|
| 246 | cmat[0][2] = vmat[0][2];
|
|---|
| 247 | cmat[0][3] = vmat[0][3];
|
|---|
| 248 |
|
|---|
| 249 | cmat[1][0] = vmat[1][0];
|
|---|
| 250 | cmat[1][1] = vmat[1][1];
|
|---|
| 251 | cmat[1][2] = vmat[1][2];
|
|---|
| 252 | cmat[1][3] = vmat[1][3];
|
|---|
| 253 |
|
|---|
| 254 | cmat[2][0] = vmat[2][0];
|
|---|
| 255 | cmat[2][1] = vmat[2][1];
|
|---|
| 256 | cmat[2][2] = vmat[2][2];
|
|---|
| 257 | cmat[2][3] = vmat[2][3];
|
|---|
| 258 |
|
|---|
| 259 | cmat[3][0] = vmat[3][0];
|
|---|
| 260 | cmat[3][1] = vmat[3][1];
|
|---|
| 261 | cmat[3][2] = vmat[3][2];
|
|---|
| 262 | cmat[3][3] = vmat[3][3];
|
|---|
| 263 |
|
|---|
| 264 | const long rstride = sizeof(cmat[0]) / sizeof(cmat[0][0]);
|
|---|
| 265 | const long cstride = 1;
|
|---|
| 266 |
|
|---|
| 267 | setnurbsproperty(GL_MAP2_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride,
|
|---|
| 268 | cstride);
|
|---|
| 269 | setnurbsproperty(GL_MAP2_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride,
|
|---|
| 270 | cstride);
|
|---|
| 271 | //added for curves by zl
|
|---|
| 272 | setnurbsproperty(GL_MAP1_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride,
|
|---|
| 273 | cstride);
|
|---|
| 274 | setnurbsproperty(GL_MAP1_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride,
|
|---|
| 275 | cstride);
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | /*---------------------------------------------------------------------
|
|---|
| 279 | * A = B * MAT ; transform a 4d vector through a 4x4 matrix
|
|---|
| 280 | *---------------------------------------------------------------------
|
|---|
| 281 | */
|
|---|
| 282 | void
|
|---|
| 283 | GLUnurbs::transform4d(GLfloat A[4], GLfloat B[4], GLfloat mat[4][4])
|
|---|
| 284 | {
|
|---|
| 285 |
|
|---|
| 286 | A[0] = B[0]*mat[0][0] + B[1]*mat[1][0] + B[2]*mat[2][0] + B[3]*mat[3][0];
|
|---|
| 287 | A[1] = B[0]*mat[0][1] + B[1]*mat[1][1] + B[2]*mat[2][1] + B[3]*mat[3][1];
|
|---|
| 288 | A[2] = B[0]*mat[0][2] + B[1]*mat[1][2] + B[2]*mat[2][2] + B[3]*mat[3][2];
|
|---|
| 289 | A[3] = B[0]*mat[0][3] + B[1]*mat[1][3] + B[2]*mat[2][3] + B[3]*mat[3][3];
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | /*---------------------------------------------------------------------
|
|---|
| 293 | * new = [left][right] ; multiply two matrices together
|
|---|
| 294 | *---------------------------------------------------------------------
|
|---|
| 295 | */
|
|---|
| 296 | void
|
|---|
| 297 | GLUnurbs::multmatrix4d (GLfloat n[4][4], GLfloat left[4][4], GLfloat right[4][4])
|
|---|
| 298 | {
|
|---|
| 299 | transform4d ((GLfloat *) n[0],(GLfloat *) left[0],(GLfloat (*)[4]) right);
|
|---|
| 300 | transform4d ((GLfloat *) n[1],(GLfloat *) left[1],(GLfloat (*)[4]) right);
|
|---|
| 301 | transform4d ((GLfloat *) n[2],(GLfloat *) left[2],(GLfloat (*)[4]) right);
|
|---|
| 302 | transform4d ((GLfloat *) n[3],(GLfloat *) left[3],(GLfloat (*)[4]) right);
|
|---|
| 303 | }
|
|---|