ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

glrenderer.cc
Go to the documentation of this file.
00001 /*
00002 ** License Applicability. Except to the extent portions of this file are
00003 ** made subject to an alternative license as permitted in the SGI Free
00004 ** Software License B, Version 1.1 (the "License"), the contents of this
00005 ** file are subject only to the provisions of the License. You may not use
00006 ** this file except in compliance with the License. You may obtain a copy
00007 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
00008 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
00009 **
00010 ** http://oss.sgi.com/projects/FreeB
00011 **
00012 ** Note that, as provided in the License, the Software is distributed on an
00013 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
00014 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
00015 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
00016 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
00017 **
00018 ** Original Code. The Original Code is: OpenGL Sample Implementation,
00019 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
00020 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
00021 ** Copyright in any portions created by third parties is as indicated
00022 ** elsewhere herein. All Rights Reserved.
00023 **
00024 ** Additional Notice Provisions: The application programming interfaces
00025 ** established by SGI in conjunction with the Original Code are The
00026 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
00027 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
00028 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
00029 ** Window System(R) (Version 1.3), released October 19, 1998. This software
00030 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
00031 ** published by SGI, but has not been independently verified as being
00032 ** compliant with the OpenGL(R) version 1.2.1 Specification.
00033 **
00034 */
00035 /*
00036 */
00037 
00038 #include "gluos.h"
00039 #include "glimports.h"
00040 #include "glrenderer.h"
00041 
00042 GLUnurbs::GLUnurbs()
00043     : NurbsTessellator(curveEvaluator, surfaceEvaluator)
00044 {
00045     redefineMaps();
00046     defineMap(GL_MAP2_NORMAL, 0, 3);
00047     defineMap(GL_MAP1_NORMAL, 0, 3);
00048     defineMap(GL_MAP2_TEXTURE_COORD_1, 0, 1);
00049     defineMap(GL_MAP1_TEXTURE_COORD_1, 0, 1);
00050     defineMap(GL_MAP2_TEXTURE_COORD_2, 0, 2);
00051     defineMap(GL_MAP1_TEXTURE_COORD_2, 0, 2);
00052     defineMap(GL_MAP2_TEXTURE_COORD_3, 0, 3);
00053     defineMap(GL_MAP1_TEXTURE_COORD_3, 0, 3);
00054     defineMap(GL_MAP2_TEXTURE_COORD_4, 1, 4);
00055     defineMap(GL_MAP1_TEXTURE_COORD_4, 1, 4);
00056     defineMap(GL_MAP2_VERTEX_4, 1, 4);
00057     defineMap(GL_MAP1_VERTEX_4, 1, 4);
00058     defineMap(GL_MAP2_VERTEX_3, 0, 3);
00059     defineMap(GL_MAP1_VERTEX_3, 0, 3);
00060     defineMap(GL_MAP2_COLOR_4, 0, 4);
00061     defineMap(GL_MAP1_COLOR_4, 0, 4);
00062     defineMap(GL_MAP2_INDEX, 0, 1);
00063     defineMap(GL_MAP1_INDEX, 0, 1);
00064 
00065     setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
00066     setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
00067     setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
00068     setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH);
00069 
00070     setnurbsproperty(GL_MAP1_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0);
00071     setnurbsproperty(GL_MAP1_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0);
00072     setnurbsproperty(GL_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0);
00073     setnurbsproperty(GL_MAP2_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0);
00074 
00075     setnurbsproperty(GL_MAP1_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50);
00076     setnurbsproperty(GL_MAP1_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50);
00077     setnurbsproperty(GL_MAP2_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50);
00078     setnurbsproperty(GL_MAP2_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50);
00079 
00080     setnurbsproperty(GL_MAP1_VERTEX_3, N_S_STEPS, (float) 100.0);
00081     setnurbsproperty(GL_MAP1_VERTEX_4, N_S_STEPS, (float) 100.0);
00082     setnurbsproperty(GL_MAP2_VERTEX_3, N_S_STEPS, (float) 100.0);
00083     setnurbsproperty(GL_MAP2_VERTEX_4, N_S_STEPS, (float) 100.0);
00084 
00085     //added for optimizing untrimmed case
00086     set_domain_distance_u_rate(100.0);
00087 
00088     setnurbsproperty(GL_MAP1_VERTEX_3, N_T_STEPS, (float) 100.0);
00089     setnurbsproperty(GL_MAP1_VERTEX_4, N_T_STEPS, (float) 100.0);
00090     setnurbsproperty(GL_MAP2_VERTEX_3, N_T_STEPS, (float) 100.0);
00091     setnurbsproperty(GL_MAP2_VERTEX_4, N_T_STEPS, (float) 100.0);
00092 
00093     //added for optimizing untrimmed case
00094     set_domain_distance_v_rate(100.0);
00095     set_is_domain_distance_sampling(0); //since the default is path_length
00096 
00097     //default autoloadmode is true
00098     autoloadmode = 1;
00099 
00100     //default callbackFlag is 0
00101     callbackFlag = 0;
00102 
00103     errorCallback = NULL;
00104 }
00105 
00106 void
00107 GLUnurbs::bgnrender(void)
00108 {
00109     if (autoloadmode) {
00110     loadGLMatrices();
00111     }
00112 }
00113 
00114 void
00115 GLUnurbs::endrender(void)
00116 {
00117 }
00118 
00119 void
00120 GLUnurbs::errorHandler(int i)
00121 {
00122     int gluError;
00123 
00124     gluError = i + (GLU_NURBS_ERROR1 - 1);
00125     postError( gluError );
00126 }
00127 
00128 void
00129 GLUnurbs::loadGLMatrices(void)
00130 {
00131     GLfloat vmat[4][4];
00132     GLint viewport[4];
00133 
00134     grabGLMatrix((GLfloat (*)[4]) vmat);
00135     loadCullingMatrix((GLfloat (*)[4]) vmat);
00136     ::glGetIntegerv((GLenum) GL_VIEWPORT, (GLint *) viewport);
00137     loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport);
00138 }
00139 
00140 void
00141 GLUnurbs::useGLMatrices(const GLfloat modelMatrix[16],
00142               const GLfloat projMatrix[16],
00143               const GLint viewport[4])
00144 {
00145     GLfloat vmat[4][4];
00146 
00147     multmatrix4d(vmat, (const GLfloat (*)[4]) modelMatrix,
00148         (const GLfloat (*)[4]) projMatrix);
00149     loadCullingMatrix((GLfloat (*)[4]) vmat);
00150     loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport);
00151 }
00152 
00153 /*--------------------------------------------------------------------------
00154  * grabGLMatrix
00155  *--------------------------------------------------------------------------
00156  */
00157 
00158 void
00159 GLUnurbs::grabGLMatrix(GLfloat vmat[4][4])
00160 {
00161     GLfloat m1[4][4], m2[4][4];
00162 
00163     ::glGetFloatv((GLenum) GL_MODELVIEW_MATRIX, (GLfloat *) &(m1[0][0]));
00164     ::glGetFloatv((GLenum) GL_PROJECTION_MATRIX, (GLfloat *) &(m2[0][0]));
00165     multmatrix4d((GLfloat (*)[4]) vmat,
00166         (const GLfloat (*)[4]) m1, (const GLfloat (*)[4]) m2);
00167 }
00168 
00169 //for object space tesselation: view independent
00170 void
00171 GLUnurbs::setSamplingMatrixIdentity( void )
00172 {
00173   INREAL smat[4][4] = {
00174     {1,0,0,0},
00175     {0,1,0,0},
00176     {0,0,1,0},
00177     {0,0,0,1}
00178   };
00179   const long rstride = sizeof(smat[0]) / sizeof(smat[0][0]);
00180   const long cstride = 1;
00181 
00182   setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
00183            cstride);
00184   setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
00185            cstride);
00186   setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
00187            cstride);
00188   setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
00189            cstride);
00190 }
00191 
00192 
00193 void
00194 GLUnurbs::loadSamplingMatrix(const GLfloat vmat[4][4],
00195                    const GLint viewport[4])
00196 {
00197 
00198     /* rescale the mapping to correspond to pixels in x/y */
00199     REAL xsize = 0.5 * (REAL) (viewport[2]);
00200     REAL ysize = 0.5 * (REAL) (viewport[3]);
00201 
00202     INREAL smat[4][4];
00203     smat[0][0] = vmat[0][0] * xsize;
00204     smat[1][0] = vmat[1][0] * xsize;
00205     smat[2][0] = vmat[2][0] * xsize;
00206     smat[3][0] = vmat[3][0] * xsize;
00207 
00208     smat[0][1] = vmat[0][1] * ysize;
00209     smat[1][1] = vmat[1][1] * ysize;
00210     smat[2][1] = vmat[2][1] * ysize;
00211     smat[3][1] = vmat[3][1] * ysize;
00212 
00213     smat[0][2] = 0.0;
00214     smat[1][2] = 0.0;
00215     smat[2][2] = 0.0;
00216     smat[3][2] = 0.0;
00217 
00218     smat[0][3] = vmat[0][3];
00219     smat[1][3] = vmat[1][3];
00220     smat[2][3] = vmat[2][3];
00221     smat[3][3] = vmat[3][3];
00222 
00223     const long rstride = sizeof(smat[0]) / sizeof(smat[0][0]);
00224     const long cstride = 1;
00225 
00226     setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
00227         cstride);
00228     setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
00229         cstride);
00230     setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
00231         cstride);
00232     setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
00233         cstride);
00234 }
00235 
00236 void
00237 GLUnurbs::loadCullingMatrix(GLfloat vmat[4][4])
00238 {
00239     INREAL cmat[4][4];
00240 
00241     cmat[0][0] = vmat[0][0];
00242     cmat[0][1] = vmat[0][1];
00243     cmat[0][2] = vmat[0][2];
00244     cmat[0][3] = vmat[0][3];
00245 
00246     cmat[1][0] = vmat[1][0];
00247     cmat[1][1] = vmat[1][1];
00248     cmat[1][2] = vmat[1][2];
00249     cmat[1][3] = vmat[1][3];
00250 
00251     cmat[2][0] = vmat[2][0];
00252     cmat[2][1] = vmat[2][1];
00253     cmat[2][2] = vmat[2][2];
00254     cmat[2][3] = vmat[2][3];
00255 
00256     cmat[3][0] = vmat[3][0];
00257     cmat[3][1] = vmat[3][1];
00258     cmat[3][2] = vmat[3][2];
00259     cmat[3][3] = vmat[3][3];
00260 
00261     const long rstride = sizeof(cmat[0]) / sizeof(cmat[0][0]);
00262     const long cstride = 1;
00263 
00264     setnurbsproperty(GL_MAP2_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride,
00265         cstride);
00266     setnurbsproperty(GL_MAP2_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride,
00267         cstride);
00268     //added for curves by zl
00269     setnurbsproperty(GL_MAP1_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride,
00270         cstride);
00271     setnurbsproperty(GL_MAP1_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride,
00272         cstride);
00273 }
00274 
00275 /*---------------------------------------------------------------------
00276  * A = B * MAT ; transform a 4d vector through a 4x4 matrix
00277  *---------------------------------------------------------------------
00278  */
00279 void
00280 GLUnurbs::transform4d(GLfloat A[4], GLfloat B[4], GLfloat mat[4][4])
00281 {
00282 
00283     A[0] = B[0]*mat[0][0] + B[1]*mat[1][0] + B[2]*mat[2][0] + B[3]*mat[3][0];
00284     A[1] = B[0]*mat[0][1] + B[1]*mat[1][1] + B[2]*mat[2][1] + B[3]*mat[3][1];
00285     A[2] = B[0]*mat[0][2] + B[1]*mat[1][2] + B[2]*mat[2][2] + B[3]*mat[3][2];
00286     A[3] = B[0]*mat[0][3] + B[1]*mat[1][3] + B[2]*mat[2][3] + B[3]*mat[3][3];
00287 }
00288 
00289 /*---------------------------------------------------------------------
00290  * new = [left][right] ; multiply two matrices together
00291  *---------------------------------------------------------------------
00292  */
00293 void
00294 GLUnurbs::multmatrix4d (GLfloat n[4][4], const GLfloat left[4][4],
00295          const GLfloat right[4][4])
00296 {
00297     transform4d ((GLfloat *) n[0],(GLfloat *) left[0],(GLfloat (*)[4]) right);
00298     transform4d ((GLfloat *) n[1],(GLfloat *) left[1],(GLfloat (*)[4]) right);
00299     transform4d ((GLfloat *) n[2],(GLfloat *) left[2],(GLfloat (*)[4]) right);
00300     transform4d ((GLfloat *) n[3],(GLfloat *) left[3],(GLfloat (*)[4]) right);
00301 }

Generated on Sat May 26 2012 04:22:14 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.