Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
7.6 KiB

  1. #include <glos.h>
  2. #include <GL/gl.h>
  3. #include <GL/glu.h>
  4. #include "glimport.h"
  5. #include "glrender.h"
  6. GLUnurbs::GLUnurbs(void)
  7. : NurbsTessellator(curveEvaluator, surfaceEvaluator)
  8. {
  9. redefineMaps();
  10. defineMap(GL_MAP2_NORMAL, 0, 3);
  11. defineMap(GL_MAP1_NORMAL, 0, 3);
  12. defineMap(GL_MAP2_TEXTURE_COORD_1, 0, 1);
  13. defineMap(GL_MAP1_TEXTURE_COORD_1, 0, 1);
  14. defineMap(GL_MAP2_TEXTURE_COORD_2, 0, 2);
  15. defineMap(GL_MAP1_TEXTURE_COORD_2, 0, 2);
  16. defineMap(GL_MAP2_TEXTURE_COORD_3, 0, 3);
  17. defineMap(GL_MAP1_TEXTURE_COORD_3, 0, 3);
  18. defineMap(GL_MAP2_TEXTURE_COORD_4, 1, 4);
  19. defineMap(GL_MAP1_TEXTURE_COORD_4, 1, 4);
  20. defineMap(GL_MAP2_VERTEX_4, 1, 4);
  21. defineMap(GL_MAP1_VERTEX_4, 1, 4);
  22. defineMap(GL_MAP2_VERTEX_3, 0, 3);
  23. defineMap(GL_MAP1_VERTEX_3, 0, 3);
  24. defineMap(GL_MAP2_COLOR_4, 0, 4);
  25. defineMap(GL_MAP1_COLOR_4, 0, 4);
  26. defineMap(GL_MAP2_INDEX, 0, 1);
  27. defineMap(GL_MAP1_INDEX, 0, 1);
  28. setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
  29. setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
  30. setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
  31. setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
  32. setnurbsproperty(GL_MAP1_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0);
  33. setnurbsproperty(GL_MAP1_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0);
  34. setnurbsproperty(GL_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0);
  35. setnurbsproperty(GL_MAP2_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0);
  36. setnurbsproperty(GL_MAP1_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50);
  37. setnurbsproperty(GL_MAP1_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50);
  38. setnurbsproperty(GL_MAP2_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50);
  39. setnurbsproperty(GL_MAP2_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50);
  40. setnurbsproperty(GL_MAP1_VERTEX_3, N_S_STEPS, (float) 100.0);
  41. setnurbsproperty(GL_MAP1_VERTEX_4, N_S_STEPS, (float) 100.0);
  42. setnurbsproperty(GL_MAP2_VERTEX_3, N_S_STEPS, (float) 100.0);
  43. setnurbsproperty(GL_MAP2_VERTEX_4, N_S_STEPS, (float) 100.0);
  44. setnurbsproperty(GL_MAP1_VERTEX_3, N_T_STEPS, (float) 100.0);
  45. setnurbsproperty(GL_MAP1_VERTEX_4, N_T_STEPS, (float) 100.0);
  46. setnurbsproperty(GL_MAP2_VERTEX_3, N_T_STEPS, (float) 100.0);
  47. setnurbsproperty(GL_MAP2_VERTEX_4, N_T_STEPS, (float) 100.0);
  48. autoloadmode = 1;
  49. errorCallback = NULL;
  50. }
  51. void
  52. GLUnurbs::bgnrender(void)
  53. {
  54. if (autoloadmode) {
  55. loadGLMatrices();
  56. }
  57. }
  58. void
  59. GLUnurbs::endrender(void)
  60. {
  61. }
  62. void
  63. GLUnurbs::errorHandler(int i)
  64. {
  65. GLenum gluError;
  66. gluError = i + (GLU_NURBS_ERROR1 - 1);
  67. postError( gluError );
  68. }
  69. void
  70. GLUnurbs::loadGLMatrices(void)
  71. {
  72. GLfloat vmat[4][4];
  73. GLint viewport[4];
  74. grabGLMatrix((GLfloat (*)[4]) vmat);
  75. loadCullingMatrix((GLfloat (*)[4]) vmat);
  76. ::glGetIntegerv((GLenum) GL_VIEWPORT, (GLint *) viewport);
  77. loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport);
  78. }
  79. #ifdef NT
  80. void
  81. GLUnurbs::useGLMatrices(
  82. const GLfloat modelMatrix[4][4],
  83. const GLfloat projMatrix[4][4],
  84. const GLint viewport[4])
  85. {
  86. GLfloat vmat[4][4];
  87. multmatrix4d(vmat, modelMatrix, projMatrix);
  88. loadCullingMatrix(vmat);
  89. loadSamplingMatrix(vmat, viewport);
  90. }
  91. #else
  92. void
  93. GLUnurbs::useGLMatrices(const GLfloat modelMatrix[16],
  94. const GLfloat projMatrix[16],
  95. const GLint viewport[4])
  96. {
  97. GLfloat vmat[4][4];
  98. multmatrix4d((GLfloat (*)[4]) vmat, (GLfloat (*)[4]) modelMatrix,
  99. (GLfloat (*)[4]) projMatrix);
  100. loadCullingMatrix((GLfloat (*)[4]) vmat);
  101. loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport);
  102. }
  103. #endif
  104. /*--------------------------------------------------------------------------
  105. * grabGLMatrix
  106. *--------------------------------------------------------------------------
  107. */
  108. void
  109. GLUnurbs::grabGLMatrix(GLfloat vmat[4][4])
  110. {
  111. GLfloat m1[4][4], m2[4][4];
  112. ::glGetFloatv((GLenum) GL_MODELVIEW_MATRIX, (GLfloat *) &(m1[0][0]));
  113. ::glGetFloatv((GLenum) GL_PROJECTION_MATRIX, (GLfloat *) &(m2[0][0]));
  114. multmatrix4d((GLfloat (*)[4]) vmat,
  115. (GLfloat (*)[4]) m1, (GLfloat (*)[4]) m2);
  116. }
  117. void
  118. GLUnurbs::loadSamplingMatrix(const GLfloat vmat[4][4],
  119. const GLint viewport[4])
  120. {
  121. /* rescale the mapping to correspond to pixels in x/y */
  122. REAL xsize = 0.5 * (REAL) (viewport[2]);
  123. REAL ysize = 0.5 * (REAL) (viewport[3]);
  124. INREAL smat[4][4];
  125. smat[0][0] = vmat[0][0] * xsize;
  126. smat[1][0] = vmat[1][0] * xsize;
  127. smat[2][0] = vmat[2][0] * xsize;
  128. smat[3][0] = vmat[3][0] * xsize;
  129. smat[0][1] = vmat[0][1] * ysize;
  130. smat[1][1] = vmat[1][1] * ysize;
  131. smat[2][1] = vmat[2][1] * ysize;
  132. smat[3][1] = vmat[3][1] * ysize;
  133. smat[0][2] = 0.0;
  134. smat[1][2] = 0.0;
  135. smat[2][2] = 0.0;
  136. smat[3][2] = 0.0;
  137. smat[0][3] = vmat[0][3];
  138. smat[1][3] = vmat[1][3];
  139. smat[2][3] = vmat[2][3];
  140. smat[3][3] = vmat[3][3];
  141. const long rstride = sizeof(smat[0]) / sizeof(smat[0][0]);
  142. const long cstride = 1;
  143. setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
  144. cstride);
  145. setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
  146. cstride);
  147. setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
  148. cstride);
  149. setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
  150. cstride);
  151. }
  152. void
  153. GLUnurbs::loadCullingMatrix(GLfloat vmat[4][4])
  154. {
  155. INREAL cmat[4][4];
  156. cmat[0][0] = vmat[0][0];
  157. cmat[0][1] = vmat[0][1];
  158. cmat[0][2] = vmat[0][2];
  159. cmat[0][3] = vmat[0][3];
  160. cmat[1][0] = vmat[1][0];
  161. cmat[1][1] = vmat[1][1];
  162. cmat[1][2] = vmat[1][2];
  163. cmat[1][3] = vmat[1][3];
  164. cmat[2][0] = vmat[2][0];
  165. cmat[2][1] = vmat[2][1];
  166. cmat[2][2] = vmat[2][2];
  167. cmat[2][3] = vmat[2][3];
  168. cmat[3][0] = vmat[3][0];
  169. cmat[3][1] = vmat[3][1];
  170. cmat[3][2] = vmat[3][2];
  171. cmat[3][3] = vmat[3][3];
  172. const long rstride = sizeof(cmat[0]) / sizeof(cmat[0][0]);
  173. const long cstride = 1;
  174. setnurbsproperty(GL_MAP2_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride,
  175. cstride);
  176. setnurbsproperty(GL_MAP2_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride,
  177. cstride);
  178. }
  179. /*---------------------------------------------------------------------
  180. * A = B * MAT ; transform a 4d vector through a 4x4 matrix
  181. *---------------------------------------------------------------------
  182. */
  183. void
  184. GLUnurbs::transform4d(GLfloat A[4], GLfloat B[4], GLfloat mat[4][4])
  185. {
  186. A[0] = B[0]*mat[0][0] + B[1]*mat[1][0] + B[2]*mat[2][0] + B[3]*mat[3][0];
  187. A[1] = B[0]*mat[0][1] + B[1]*mat[1][1] + B[2]*mat[2][1] + B[3]*mat[3][1];
  188. A[2] = B[0]*mat[0][2] + B[1]*mat[1][2] + B[2]*mat[2][2] + B[3]*mat[3][2];
  189. A[3] = B[0]*mat[0][3] + B[1]*mat[1][3] + B[2]*mat[2][3] + B[3]*mat[3][3];
  190. }
  191. /*---------------------------------------------------------------------
  192. * new = [left][right] ; multiply two matrices together
  193. *---------------------------------------------------------------------
  194. */
  195. void
  196. GLUnurbs::multmatrix4d (GLfloat n[4][4], GLfloat left[4][4], GLfloat right[4][4])
  197. {
  198. transform4d ((GLfloat *) n[0],(GLfloat *) left[0],(GLfloat (*)[4]) right);
  199. transform4d ((GLfloat *) n[1],(GLfloat *) left[1],(GLfloat (*)[4]) right);
  200. transform4d ((GLfloat *) n[2],(GLfloat *) left[2],(GLfloat (*)[4]) right);
  201. transform4d ((GLfloat *) n[3],(GLfloat *) left[3],(GLfloat (*)[4]) right);
  202. }