Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygeneval.c
Go to the documentation of this file.
00001 00002 /* 00003 * Mesa 3-D graphics library 00004 * Version: 5.1 00005 * 00006 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a 00009 * copy of this software and associated documentation files (the "Software"), 00010 * to deal in the Software without restriction, including without limitation 00011 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00012 * and/or sell copies of the Software, and to permit persons to whom the 00013 * Software is furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included 00016 * in all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00019 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00021 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00022 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00023 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00024 */ 00025 00026 00027 /* 00028 * eval.c was written by 00029 * Bernd Barsuhn (bdbarsuh@cip.informatik.uni-erlangen.de) and 00030 * Volker Weiss (vrweiss@cip.informatik.uni-erlangen.de). 00031 * 00032 * My original implementation of evaluators was simplistic and didn't 00033 * compute surface normal vectors properly. Bernd and Volker applied 00034 * used more sophisticated methods to get better results. 00035 * 00036 * Thanks guys! 00037 */ 00038 00039 00040 #include "glheader.h" 00041 #include "imports.h" 00042 #include "colormac.h" 00043 #include "context.h" 00044 #include "eval.h" 00045 #include "macros.h" 00046 #include "mtypes.h" 00047 00048 00049 /* 00050 * Return the number of components per control point for any type of 00051 * evaluator. Return 0 if bad target. 00052 * See table 5.1 in the OpenGL 1.2 spec. 00053 */ 00054 GLuint _mesa_evaluator_components( GLenum target ) 00055 { 00056 switch (target) { 00057 case GL_MAP1_VERTEX_3: return 3; 00058 case GL_MAP1_VERTEX_4: return 4; 00059 case GL_MAP1_INDEX: return 1; 00060 case GL_MAP1_COLOR_4: return 4; 00061 case GL_MAP1_NORMAL: return 3; 00062 case GL_MAP1_TEXTURE_COORD_1: return 1; 00063 case GL_MAP1_TEXTURE_COORD_2: return 2; 00064 case GL_MAP1_TEXTURE_COORD_3: return 3; 00065 case GL_MAP1_TEXTURE_COORD_4: return 4; 00066 case GL_MAP2_VERTEX_3: return 3; 00067 case GL_MAP2_VERTEX_4: return 4; 00068 case GL_MAP2_INDEX: return 1; 00069 case GL_MAP2_COLOR_4: return 4; 00070 case GL_MAP2_NORMAL: return 3; 00071 case GL_MAP2_TEXTURE_COORD_1: return 1; 00072 case GL_MAP2_TEXTURE_COORD_2: return 2; 00073 case GL_MAP2_TEXTURE_COORD_3: return 3; 00074 case GL_MAP2_TEXTURE_COORD_4: return 4; 00075 default: break; 00076 } 00077 00078 /* XXX need to check for the vertex program extension 00079 if (!ctx->Extensions.NV_vertex_program) 00080 return 0; 00081 */ 00082 00083 if (target >= GL_MAP1_VERTEX_ATTRIB0_4_NV && 00084 target <= GL_MAP1_VERTEX_ATTRIB15_4_NV) 00085 return 4; 00086 00087 if (target >= GL_MAP2_VERTEX_ATTRIB0_4_NV && 00088 target <= GL_MAP2_VERTEX_ATTRIB15_4_NV) 00089 return 4; 00090 00091 return 0; 00092 } 00093 00094 00095 /* 00096 * Return pointer to the gl_1d_map struct for the named target. 00097 */ 00098 static struct gl_1d_map * 00099 get_1d_map( GLcontext *ctx, GLenum target ) 00100 { 00101 switch (target) { 00102 case GL_MAP1_VERTEX_3: 00103 return &ctx->EvalMap.Map1Vertex3; 00104 case GL_MAP1_VERTEX_4: 00105 return &ctx->EvalMap.Map1Vertex4; 00106 case GL_MAP1_INDEX: 00107 return &ctx->EvalMap.Map1Index; 00108 case GL_MAP1_COLOR_4: 00109 return &ctx->EvalMap.Map1Color4; 00110 case GL_MAP1_NORMAL: 00111 return &ctx->EvalMap.Map1Normal; 00112 case GL_MAP1_TEXTURE_COORD_1: 00113 return &ctx->EvalMap.Map1Texture1; 00114 case GL_MAP1_TEXTURE_COORD_2: 00115 return &ctx->EvalMap.Map1Texture2; 00116 case GL_MAP1_TEXTURE_COORD_3: 00117 return &ctx->EvalMap.Map1Texture3; 00118 case GL_MAP1_TEXTURE_COORD_4: 00119 return &ctx->EvalMap.Map1Texture4; 00120 case GL_MAP1_VERTEX_ATTRIB0_4_NV: 00121 case GL_MAP1_VERTEX_ATTRIB1_4_NV: 00122 case GL_MAP1_VERTEX_ATTRIB2_4_NV: 00123 case GL_MAP1_VERTEX_ATTRIB3_4_NV: 00124 case GL_MAP1_VERTEX_ATTRIB4_4_NV: 00125 case GL_MAP1_VERTEX_ATTRIB5_4_NV: 00126 case GL_MAP1_VERTEX_ATTRIB6_4_NV: 00127 case GL_MAP1_VERTEX_ATTRIB7_4_NV: 00128 case GL_MAP1_VERTEX_ATTRIB8_4_NV: 00129 case GL_MAP1_VERTEX_ATTRIB9_4_NV: 00130 case GL_MAP1_VERTEX_ATTRIB10_4_NV: 00131 case GL_MAP1_VERTEX_ATTRIB11_4_NV: 00132 case GL_MAP1_VERTEX_ATTRIB12_4_NV: 00133 case GL_MAP1_VERTEX_ATTRIB13_4_NV: 00134 case GL_MAP1_VERTEX_ATTRIB14_4_NV: 00135 case GL_MAP1_VERTEX_ATTRIB15_4_NV: 00136 if (!ctx->Extensions.NV_vertex_program) 00137 return NULL; 00138 return &ctx->EvalMap.Map1Attrib[target - GL_MAP1_VERTEX_ATTRIB0_4_NV]; 00139 default: 00140 return NULL; 00141 } 00142 } 00143 00144 00145 /* 00146 * Return pointer to the gl_2d_map struct for the named target. 00147 */ 00148 static struct gl_2d_map * 00149 get_2d_map( GLcontext *ctx, GLenum target ) 00150 { 00151 switch (target) { 00152 case GL_MAP2_VERTEX_3: 00153 return &ctx->EvalMap.Map2Vertex3; 00154 case GL_MAP2_VERTEX_4: 00155 return &ctx->EvalMap.Map2Vertex4; 00156 case GL_MAP2_INDEX: 00157 return &ctx->EvalMap.Map2Index; 00158 case GL_MAP2_COLOR_4: 00159 return &ctx->EvalMap.Map2Color4; 00160 case GL_MAP2_NORMAL: 00161 return &ctx->EvalMap.Map2Normal; 00162 case GL_MAP2_TEXTURE_COORD_1: 00163 return &ctx->EvalMap.Map2Texture1; 00164 case GL_MAP2_TEXTURE_COORD_2: 00165 return &ctx->EvalMap.Map2Texture2; 00166 case GL_MAP2_TEXTURE_COORD_3: 00167 return &ctx->EvalMap.Map2Texture3; 00168 case GL_MAP2_TEXTURE_COORD_4: 00169 return &ctx->EvalMap.Map2Texture4; 00170 case GL_MAP2_VERTEX_ATTRIB0_4_NV: 00171 case GL_MAP2_VERTEX_ATTRIB1_4_NV: 00172 case GL_MAP2_VERTEX_ATTRIB2_4_NV: 00173 case GL_MAP2_VERTEX_ATTRIB3_4_NV: 00174 case GL_MAP2_VERTEX_ATTRIB4_4_NV: 00175 case GL_MAP2_VERTEX_ATTRIB5_4_NV: 00176 case GL_MAP2_VERTEX_ATTRIB6_4_NV: 00177 case GL_MAP2_VERTEX_ATTRIB7_4_NV: 00178 case GL_MAP2_VERTEX_ATTRIB8_4_NV: 00179 case GL_MAP2_VERTEX_ATTRIB9_4_NV: 00180 case GL_MAP2_VERTEX_ATTRIB10_4_NV: 00181 case GL_MAP2_VERTEX_ATTRIB11_4_NV: 00182 case GL_MAP2_VERTEX_ATTRIB12_4_NV: 00183 case GL_MAP2_VERTEX_ATTRIB13_4_NV: 00184 case GL_MAP2_VERTEX_ATTRIB14_4_NV: 00185 case GL_MAP2_VERTEX_ATTRIB15_4_NV: 00186 if (!ctx->Extensions.NV_vertex_program) 00187 return NULL; 00188 return &ctx->EvalMap.Map2Attrib[target - GL_MAP2_VERTEX_ATTRIB0_4_NV]; 00189 default: 00190 return NULL; 00191 } 00192 } 00193 00194 00195 /**********************************************************************/ 00196 /*** Copy and deallocate control points ***/ 00197 /**********************************************************************/ 00198 00199 00200 /* 00201 * Copy 1-parametric evaluator control points from user-specified 00202 * memory space to a buffer of contiguous control points. 00203 * \param see glMap1f for details 00204 * \return pointer to buffer of contiguous control points or NULL if out 00205 * of memory. 00206 */ 00207 GLfloat *_mesa_copy_map_points1f( GLenum target, GLint ustride, GLint uorder, 00208 const GLfloat *points ) 00209 { 00210 GLfloat *buffer, *p; 00211 GLint i, k, size = _mesa_evaluator_components(target); 00212 00213 if (!points || !size) 00214 return NULL; 00215 00216 buffer = (GLfloat *) MALLOC(uorder * size * sizeof(GLfloat)); 00217 00218 if (buffer) 00219 for (i = 0, p = buffer; i < uorder; i++, points += ustride) 00220 for (k = 0; k < size; k++) 00221 *p++ = points[k]; 00222 00223 return buffer; 00224 } 00225 00226 00227 00228 /* 00229 * Same as above but convert doubles to floats. 00230 */ 00231 GLfloat *_mesa_copy_map_points1d( GLenum target, GLint ustride, GLint uorder, 00232 const GLdouble *points ) 00233 { 00234 GLfloat *buffer, *p; 00235 GLint i, k, size = _mesa_evaluator_components(target); 00236 00237 if (!points || !size) 00238 return NULL; 00239 00240 buffer = (GLfloat *) MALLOC(uorder * size * sizeof(GLfloat)); 00241 00242 if (buffer) 00243 for (i = 0, p = buffer; i < uorder; i++, points += ustride) 00244 for (k = 0; k < size; k++) 00245 *p++ = (GLfloat) points[k]; 00246 00247 return buffer; 00248 } 00249 00250 00251 00252 /* 00253 * Copy 2-parametric evaluator control points from user-specified 00254 * memory space to a buffer of contiguous control points. 00255 * Additional memory is allocated to be used by the horner and 00256 * de Casteljau evaluation schemes. 00257 * 00258 * \param see glMap2f for details 00259 * \return pointer to buffer of contiguous control points or NULL if out 00260 * of memory. 00261 */ 00262 GLfloat *_mesa_copy_map_points2f( GLenum target, 00263 GLint ustride, GLint uorder, 00264 GLint vstride, GLint vorder, 00265 const GLfloat *points ) 00266 { 00267 GLfloat *buffer, *p; 00268 GLint i, j, k, size, dsize, hsize; 00269 GLint uinc; 00270 00271 size = _mesa_evaluator_components(target); 00272 00273 if (!points || size==0) { 00274 return NULL; 00275 } 00276 00277 /* max(uorder, vorder) additional points are used in */ 00278 /* horner evaluation and uorder*vorder additional */ 00279 /* values are needed for de Casteljau */ 00280 dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder; 00281 hsize = (uorder > vorder ? uorder : vorder)*size; 00282 00283 if(hsize>dsize) 00284 buffer = (GLfloat *) MALLOC((uorder*vorder*size+hsize)*sizeof(GLfloat)); 00285 else 00286 buffer = (GLfloat *) MALLOC((uorder*vorder*size+dsize)*sizeof(GLfloat)); 00287 00288 /* compute the increment value for the u-loop */ 00289 uinc = ustride - vorder*vstride; 00290 00291 if (buffer) 00292 for (i=0, p=buffer; i<uorder; i++, points += uinc) 00293 for (j=0; j<vorder; j++, points += vstride) 00294 for (k=0; k<size; k++) 00295 *p++ = points[k]; 00296 00297 return buffer; 00298 } 00299 00300 00301 00302 /* 00303 * Same as above but convert doubles to floats. 00304 */ 00305 GLfloat *_mesa_copy_map_points2d(GLenum target, 00306 GLint ustride, GLint uorder, 00307 GLint vstride, GLint vorder, 00308 const GLdouble *points ) 00309 { 00310 GLfloat *buffer, *p; 00311 GLint i, j, k, size, hsize, dsize; 00312 GLint uinc; 00313 00314 size = _mesa_evaluator_components(target); 00315 00316 if (!points || size==0) { 00317 return NULL; 00318 } 00319 00320 /* max(uorder, vorder) additional points are used in */ 00321 /* horner evaluation and uorder*vorder additional */ 00322 /* values are needed for de Casteljau */ 00323 dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder; 00324 hsize = (uorder > vorder ? uorder : vorder)*size; 00325 00326 if(hsize>dsize) 00327 buffer = (GLfloat *) MALLOC((uorder*vorder*size+hsize)*sizeof(GLfloat)); 00328 else 00329 buffer = (GLfloat *) MALLOC((uorder*vorder*size+dsize)*sizeof(GLfloat)); 00330 00331 /* compute the increment value for the u-loop */ 00332 uinc = ustride - vorder*vstride; 00333 00334 if (buffer) 00335 for (i=0, p=buffer; i<uorder; i++, points += uinc) 00336 for (j=0; j<vorder; j++, points += vstride) 00337 for (k=0; k<size; k++) 00338 *p++ = (GLfloat) points[k]; 00339 00340 return buffer; 00341 } 00342 00343 00344 00345 00346 /**********************************************************************/ 00347 /*** API entry points ***/ 00348 /**********************************************************************/ 00349 00350 00351 /* 00352 * This does the work of glMap1[fd]. 00353 */ 00354 static void 00355 map1(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, 00356 GLint uorder, const GLvoid *points, GLenum type ) 00357 { 00358 GET_CURRENT_CONTEXT(ctx); 00359 GLint k; 00360 GLfloat *pnts; 00361 struct gl_1d_map *map = NULL; 00362 00363 ASSERT_OUTSIDE_BEGIN_END(ctx); 00364 ASSERT(type == GL_FLOAT || type == GL_DOUBLE); 00365 00366 if (u1 == u2) { 00367 _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(u1,u2)" ); 00368 return; 00369 } 00370 if (uorder < 1 || uorder > MAX_EVAL_ORDER) { 00371 _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(order)" ); 00372 return; 00373 } 00374 if (!points) { 00375 _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(points)" ); 00376 return; 00377 } 00378 00379 k = _mesa_evaluator_components( target ); 00380 if (k == 0) { 00381 _mesa_error( ctx, GL_INVALID_ENUM, "glMap1(target)" ); 00382 } 00383 00384 if (ustride < k) { 00385 _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(stride)" ); 00386 return; 00387 } 00388 00389 if (ctx->Texture.CurrentUnit != 0) { 00390 /* See OpenGL 1.2.1 spec, section F.2.13 */ 00391 _mesa_error( ctx, GL_INVALID_OPERATION, "glMap2(ACTIVE_TEXTURE != 0)" ); 00392 return; 00393 } 00394 00395 map = get_1d_map(ctx, target); 00396 if (!map) { 00397 _mesa_error( ctx, GL_INVALID_ENUM, "glMap1(target)" ); 00398 return; 00399 } 00400 00401 /* make copy of the control points */ 00402 if (type == GL_FLOAT) 00403 pnts = _mesa_copy_map_points1f(target, ustride, uorder, (GLfloat*) points); 00404 else 00405 pnts = _mesa_copy_map_points1d(target, ustride, uorder, (GLdouble*) points); 00406 00407 00408 FLUSH_VERTICES(ctx, _NEW_EVAL); 00409 map->Order = uorder; 00410 map->u1 = u1; 00411 map->u2 = u2; 00412 map->du = 1.0F / (u2 - u1); 00413 if (map->Points) 00414 FREE( map->Points ); 00415 map->Points = pnts; 00416 } 00417 00418 00419 00420 void GLAPIENTRY 00421 _mesa_Map1f( GLenum target, GLfloat u1, GLfloat u2, GLint stride, 00422 GLint order, const GLfloat *points ) 00423 { 00424 map1(target, u1, u2, stride, order, points, GL_FLOAT); 00425 } 00426 00427 00428 void GLAPIENTRY 00429 _mesa_Map1d( GLenum target, GLdouble u1, GLdouble u2, GLint stride, 00430 GLint order, const GLdouble *points ) 00431 { 00432 map1(target, (GLfloat) u1, (GLfloat) u2, stride, order, points, GL_DOUBLE); 00433 } 00434 00435 00436 static void 00437 map2( GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, 00438 GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, 00439 const GLvoid *points, GLenum type ) 00440 { 00441 GET_CURRENT_CONTEXT(ctx); 00442 GLint k; 00443 GLfloat *pnts; 00444 struct gl_2d_map *map = NULL; 00445 00446 ASSERT_OUTSIDE_BEGIN_END(ctx); 00447 ASSERT(type == GL_FLOAT || type == GL_DOUBLE); 00448 00449 if (u1==u2) { 00450 _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(u1,u2)" ); 00451 return; 00452 } 00453 00454 if (v1==v2) { 00455 _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(v1,v2)" ); 00456 return; 00457 } 00458 00459 if (uorder<1 || uorder>MAX_EVAL_ORDER) { 00460 _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(uorder)" ); 00461 return; 00462 } 00463 00464 if (vorder<1 || vorder>MAX_EVAL_ORDER) { 00465 _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(vorder)" ); 00466 return; 00467 } 00468 00469 k = _mesa_evaluator_components( target ); 00470 if (k==0) { 00471 _mesa_error( ctx, GL_INVALID_ENUM, "glMap2(target)" ); 00472 } 00473 00474 if (ustride < k) { 00475 _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(ustride)" ); 00476 return; 00477 } 00478 if (vstride < k) { 00479 _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(vstride)" ); 00480 return; 00481 } 00482 00483 if (ctx->Texture.CurrentUnit != 0) { 00484 /* See OpenGL 1.2.1 spec, section F.2.13 */ 00485 _mesa_error( ctx, GL_INVALID_OPERATION, "glMap2(ACTIVE_TEXTURE != 0)" ); 00486 return; 00487 } 00488 00489 map = get_2d_map(ctx, target); 00490 if (!map) { 00491 _mesa_error( ctx, GL_INVALID_ENUM, "glMap2(target)" ); 00492 return; 00493 } 00494 00495 /* make copy of the control points */ 00496 if (type == GL_FLOAT) 00497 pnts = _mesa_copy_map_points2f(target, ustride, uorder, 00498 vstride, vorder, (GLfloat*) points); 00499 else 00500 pnts = _mesa_copy_map_points2d(target, ustride, uorder, 00501 vstride, vorder, (GLdouble*) points); 00502 00503 00504 FLUSH_VERTICES(ctx, _NEW_EVAL); 00505 map->Uorder = uorder; 00506 map->u1 = u1; 00507 map->u2 = u2; 00508 map->du = 1.0F / (u2 - u1); 00509 map->Vorder = vorder; 00510 map->v1 = v1; 00511 map->v2 = v2; 00512 map->dv = 1.0F / (v2 - v1); 00513 if (map->Points) 00514 FREE( map->Points ); 00515 map->Points = pnts; 00516 } 00517 00518 00519 void GLAPIENTRY 00520 _mesa_Map2f( GLenum target, 00521 GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, 00522 GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, 00523 const GLfloat *points) 00524 { 00525 map2(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, 00526 points, GL_FLOAT); 00527 } 00528 00529 00530 void GLAPIENTRY 00531 _mesa_Map2d( GLenum target, 00532 GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, 00533 GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, 00534 const GLdouble *points ) 00535 { 00536 map2(target, (GLfloat) u1, (GLfloat) u2, ustride, uorder, 00537 (GLfloat) v1, (GLfloat) v2, vstride, vorder, points, GL_DOUBLE); 00538 } 00539 00540 00541 00542 void GLAPIENTRY 00543 _mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v ) 00544 { 00545 GET_CURRENT_CONTEXT(ctx); 00546 struct gl_1d_map *map1d; 00547 struct gl_2d_map *map2d; 00548 GLint i, n; 00549 GLfloat *data; 00550 GLuint comps; 00551 00552 ASSERT_OUTSIDE_BEGIN_END(ctx); 00553 00554 comps = _mesa_evaluator_components(target); 00555 if (!comps) { 00556 _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapdv(target)" ); 00557 return; 00558 } 00559 00560 map1d = get_1d_map(ctx, target); 00561 map2d = get_2d_map(ctx, target); 00562 ASSERT(map1d || map2d); 00563 00564 switch (query) { 00565 case GL_COEFF: 00566 if (map1d) { 00567 data = map1d->Points; 00568 n = map1d->Order * comps; 00569 } 00570 else { 00571 data = map2d->Points; 00572 n = map2d->Uorder * map2d->Vorder * comps; 00573 } 00574 if (data) { 00575 for (i=0;i<n;i++) { 00576 v[i] = data[i]; 00577 } 00578 } 00579 break; 00580 case GL_ORDER: 00581 if (map1d) { 00582 v[0] = (GLdouble) map1d->Order; 00583 } 00584 else { 00585 v[0] = (GLdouble) map2d->Uorder; 00586 v[1] = (GLdouble) map2d->Vorder; 00587 } 00588 break; 00589 case GL_DOMAIN: 00590 if (map1d) { 00591 v[0] = (GLdouble) map1d->u1; 00592 v[1] = (GLdouble) map1d->u2; 00593 } 00594 else { 00595 v[0] = (GLdouble) map2d->u1; 00596 v[1] = (GLdouble) map2d->u2; 00597 v[2] = (GLdouble) map2d->v1; 00598 v[3] = (GLdouble) map2d->v2; 00599 } 00600 break; 00601 default: 00602 _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapdv(query)" ); 00603 } 00604 } 00605 00606 00607 void GLAPIENTRY 00608 _mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v ) 00609 { 00610 GET_CURRENT_CONTEXT(ctx); 00611 struct gl_1d_map *map1d; 00612 struct gl_2d_map *map2d; 00613 GLint i, n; 00614 GLfloat *data; 00615 GLuint comps; 00616 00617 ASSERT_OUTSIDE_BEGIN_END(ctx); 00618 00619 comps = _mesa_evaluator_components(target); 00620 if (!comps) { 00621 _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapfv(target)" ); 00622 return; 00623 } 00624 00625 map1d = get_1d_map(ctx, target); 00626 map2d = get_2d_map(ctx, target); 00627 ASSERT(map1d || map2d); 00628 00629 switch (query) { 00630 case GL_COEFF: 00631 if (map1d) { 00632 data = map1d->Points; 00633 n = map1d->Order * comps; 00634 } 00635 else { 00636 data = map2d->Points; 00637 n = map2d->Uorder * map2d->Vorder * comps; 00638 } 00639 if (data) { 00640 for (i=0;i<n;i++) { 00641 v[i] = data[i]; 00642 } 00643 } 00644 break; 00645 case GL_ORDER: 00646 if (map1d) { 00647 v[0] = (GLfloat) map1d->Order; 00648 } 00649 else { 00650 v[0] = (GLfloat) map2d->Uorder; 00651 v[1] = (GLfloat) map2d->Vorder; 00652 } 00653 break; 00654 case GL_DOMAIN: 00655 if (map1d) { 00656 v[0] = map1d->u1; 00657 v[1] = map1d->u2; 00658 } 00659 else { 00660 v[0] = map2d->u1; 00661 v[1] = map2d->u2; 00662 v[2] = map2d->v1; 00663 v[3] = map2d->v2; 00664 } 00665 break; 00666 default: 00667 _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapfv(query)" ); 00668 } 00669 } 00670 00671 00672 void GLAPIENTRY 00673 _mesa_GetMapiv( GLenum target, GLenum query, GLint *v ) 00674 { 00675 GET_CURRENT_CONTEXT(ctx); 00676 struct gl_1d_map *map1d; 00677 struct gl_2d_map *map2d; 00678 GLuint i, n; 00679 GLfloat *data; 00680 GLuint comps; 00681 00682 ASSERT_OUTSIDE_BEGIN_END(ctx); 00683 00684 comps = _mesa_evaluator_components(target); 00685 if (!comps) { 00686 _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapiv(target)" ); 00687 return; 00688 } 00689 00690 map1d = get_1d_map(ctx, target); 00691 map2d = get_2d_map(ctx, target); 00692 ASSERT(map1d || map2d); 00693 00694 switch (query) { 00695 case GL_COEFF: 00696 if (map1d) { 00697 data = map1d->Points; 00698 n = map1d->Order * comps; 00699 } 00700 else { 00701 data = map2d->Points; 00702 n = map2d->Uorder * map2d->Vorder * comps; 00703 } 00704 if (data) { 00705 for (i=0;i<n;i++) { 00706 v[i] = IROUND(data[i]); 00707 } 00708 } 00709 break; 00710 case GL_ORDER: 00711 if (map1d) { 00712 v[0] = map1d->Order; 00713 } 00714 else { 00715 v[0] = map2d->Uorder; 00716 v[1] = map2d->Vorder; 00717 } 00718 break; 00719 case GL_DOMAIN: 00720 if (map1d) { 00721 v[0] = IROUND(map1d->u1); 00722 v[1] = IROUND(map1d->u2); 00723 } 00724 else { 00725 v[0] = IROUND(map2d->u1); 00726 v[1] = IROUND(map2d->u2); 00727 v[2] = IROUND(map2d->v1); 00728 v[3] = IROUND(map2d->v2); 00729 } 00730 break; 00731 default: 00732 _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapiv(query)" ); 00733 } 00734 } 00735 00736 00737 00738 void GLAPIENTRY 00739 _mesa_MapGrid1f( GLint un, GLfloat u1, GLfloat u2 ) 00740 { 00741 GET_CURRENT_CONTEXT(ctx); 00742 ASSERT_OUTSIDE_BEGIN_END(ctx); 00743 00744 if (un<1) { 00745 _mesa_error( ctx, GL_INVALID_VALUE, "glMapGrid1f" ); 00746 return; 00747 } 00748 FLUSH_VERTICES(ctx, _NEW_EVAL); 00749 ctx->Eval.MapGrid1un = un; 00750 ctx->Eval.MapGrid1u1 = u1; 00751 ctx->Eval.MapGrid1u2 = u2; 00752 ctx->Eval.MapGrid1du = (u2 - u1) / (GLfloat) un; 00753 } 00754 00755 00756 void GLAPIENTRY 00757 _mesa_MapGrid1d( GLint un, GLdouble u1, GLdouble u2 ) 00758 { 00759 _mesa_MapGrid1f( un, (GLfloat) u1, (GLfloat) u2 ); 00760 } 00761 00762 00763 void GLAPIENTRY 00764 _mesa_MapGrid2f( GLint un, GLfloat u1, GLfloat u2, 00765 GLint vn, GLfloat v1, GLfloat v2 ) 00766 { 00767 GET_CURRENT_CONTEXT(ctx); 00768 ASSERT_OUTSIDE_BEGIN_END(ctx); 00769 00770 if (un<1) { 00771 _mesa_error( ctx, GL_INVALID_VALUE, "glMapGrid2f(un)" ); 00772 return; 00773 } 00774 if (vn<1) { 00775 _mesa_error( ctx, GL_INVALID_VALUE, "glMapGrid2f(vn)" ); 00776 return; 00777 } 00778 00779 FLUSH_VERTICES(ctx, _NEW_EVAL); 00780 ctx->Eval.MapGrid2un = un; 00781 ctx->Eval.MapGrid2u1 = u1; 00782 ctx->Eval.MapGrid2u2 = u2; 00783 ctx->Eval.MapGrid2du = (u2 - u1) / (GLfloat) un; 00784 ctx->Eval.MapGrid2vn = vn; 00785 ctx->Eval.MapGrid2v1 = v1; 00786 ctx->Eval.MapGrid2v2 = v2; 00787 ctx->Eval.MapGrid2dv = (v2 - v1) / (GLfloat) vn; 00788 } 00789 00790 00791 void GLAPIENTRY 00792 _mesa_MapGrid2d( GLint un, GLdouble u1, GLdouble u2, 00793 GLint vn, GLdouble v1, GLdouble v2 ) 00794 { 00795 _mesa_MapGrid2f( un, (GLfloat) u1, (GLfloat) u2, 00796 vn, (GLfloat) v1, (GLfloat) v2 ); 00797 } 00798 00799 00800 00801 /**********************************************************************/ 00802 /***** Initialization *****/ 00803 /**********************************************************************/ 00804 00808 static void 00809 init_1d_map( struct gl_1d_map *map, int n, const float *initial ) 00810 { 00811 map->Order = 1; 00812 map->u1 = 0.0; 00813 map->u2 = 1.0; 00814 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat)); 00815 if (map->Points) { 00816 GLint i; 00817 for (i=0;i<n;i++) 00818 map->Points[i] = initial[i]; 00819 } 00820 } 00821 00822 00826 static void 00827 init_2d_map( struct gl_2d_map *map, int n, const float *initial ) 00828 { 00829 map->Uorder = 1; 00830 map->Vorder = 1; 00831 map->u1 = 0.0; 00832 map->u2 = 1.0; 00833 map->v1 = 0.0; 00834 map->v2 = 1.0; 00835 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat)); 00836 if (map->Points) { 00837 GLint i; 00838 for (i=0;i<n;i++) 00839 map->Points[i] = initial[i]; 00840 } 00841 } 00842 00843 00844 void _mesa_init_eval( GLcontext *ctx ) 00845 { 00846 int i; 00847 00848 /* Evaluators group */ 00849 ctx->Eval.Map1Color4 = GL_FALSE; 00850 ctx->Eval.Map1Index = GL_FALSE; 00851 ctx->Eval.Map1Normal = GL_FALSE; 00852 ctx->Eval.Map1TextureCoord1 = GL_FALSE; 00853 ctx->Eval.Map1TextureCoord2 = GL_FALSE; 00854 ctx->Eval.Map1TextureCoord3 = GL_FALSE; 00855 ctx->Eval.Map1TextureCoord4 = GL_FALSE; 00856 ctx->Eval.Map1Vertex3 = GL_FALSE; 00857 ctx->Eval.Map1Vertex4 = GL_FALSE; 00858 MEMSET(ctx->Eval.Map1Attrib, 0, sizeof(ctx->Eval.Map1Attrib)); 00859 ctx->Eval.Map2Color4 = GL_FALSE; 00860 ctx->Eval.Map2Index = GL_FALSE; 00861 ctx->Eval.Map2Normal = GL_FALSE; 00862 ctx->Eval.Map2TextureCoord1 = GL_FALSE; 00863 ctx->Eval.Map2TextureCoord2 = GL_FALSE; 00864 ctx->Eval.Map2TextureCoord3 = GL_FALSE; 00865 ctx->Eval.Map2TextureCoord4 = GL_FALSE; 00866 ctx->Eval.Map2Vertex3 = GL_FALSE; 00867 ctx->Eval.Map2Vertex4 = GL_FALSE; 00868 MEMSET(ctx->Eval.Map2Attrib, 0, sizeof(ctx->Eval.Map2Attrib)); 00869 ctx->Eval.AutoNormal = GL_FALSE; 00870 ctx->Eval.MapGrid1un = 1; 00871 ctx->Eval.MapGrid1u1 = 0.0; 00872 ctx->Eval.MapGrid1u2 = 1.0; 00873 ctx->Eval.MapGrid2un = 1; 00874 ctx->Eval.MapGrid2vn = 1; 00875 ctx->Eval.MapGrid2u1 = 0.0; 00876 ctx->Eval.MapGrid2u2 = 1.0; 00877 ctx->Eval.MapGrid2v1 = 0.0; 00878 ctx->Eval.MapGrid2v2 = 1.0; 00879 00880 /* Evaluator data */ 00881 { 00882 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 }; 00883 static GLfloat normal[3] = { 0.0, 0.0, 1.0 }; 00884 static GLfloat index[1] = { 1.0 }; 00885 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 }; 00886 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 }; 00887 static GLfloat attrib[4] = { 0.0, 0.0, 0.0, 1.0 }; 00888 00889 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex ); 00890 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex ); 00891 init_1d_map( &ctx->EvalMap.Map1Index, 1, index ); 00892 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color ); 00893 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal ); 00894 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord ); 00895 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord ); 00896 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord ); 00897 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord ); 00898 for (i = 0; i < 16; i++) 00899 init_1d_map( ctx->EvalMap.Map1Attrib + i, 4, attrib ); 00900 00901 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex ); 00902 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex ); 00903 init_2d_map( &ctx->EvalMap.Map2Index, 1, index ); 00904 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color ); 00905 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal ); 00906 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord ); 00907 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord ); 00908 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord ); 00909 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord ); 00910 for (i = 0; i < 16; i++) 00911 init_2d_map( ctx->EvalMap.Map2Attrib + i, 4, attrib ); 00912 } 00913 } 00914 00915 00916 void _mesa_free_eval_data( GLcontext *ctx ) 00917 { 00918 int i; 00919 00920 /* Free evaluator data */ 00921 if (ctx->EvalMap.Map1Vertex3.Points) 00922 FREE( ctx->EvalMap.Map1Vertex3.Points ); 00923 if (ctx->EvalMap.Map1Vertex4.Points) 00924 FREE( ctx->EvalMap.Map1Vertex4.Points ); 00925 if (ctx->EvalMap.Map1Index.Points) 00926 FREE( ctx->EvalMap.Map1Index.Points ); 00927 if (ctx->EvalMap.Map1Color4.Points) 00928 FREE( ctx->EvalMap.Map1Color4.Points ); 00929 if (ctx->EvalMap.Map1Normal.Points) 00930 FREE( ctx->EvalMap.Map1Normal.Points ); 00931 if (ctx->EvalMap.Map1Texture1.Points) 00932 FREE( ctx->EvalMap.Map1Texture1.Points ); 00933 if (ctx->EvalMap.Map1Texture2.Points) 00934 FREE( ctx->EvalMap.Map1Texture2.Points ); 00935 if (ctx->EvalMap.Map1Texture3.Points) 00936 FREE( ctx->EvalMap.Map1Texture3.Points ); 00937 if (ctx->EvalMap.Map1Texture4.Points) 00938 FREE( ctx->EvalMap.Map1Texture4.Points ); 00939 for (i = 0; i < 16; i++) 00940 FREE((ctx->EvalMap.Map1Attrib[i].Points)); 00941 00942 if (ctx->EvalMap.Map2Vertex3.Points) 00943 FREE( ctx->EvalMap.Map2Vertex3.Points ); 00944 if (ctx->EvalMap.Map2Vertex4.Points) 00945 FREE( ctx->EvalMap.Map2Vertex4.Points ); 00946 if (ctx->EvalMap.Map2Index.Points) 00947 FREE( ctx->EvalMap.Map2Index.Points ); 00948 if (ctx->EvalMap.Map2Color4.Points) 00949 FREE( ctx->EvalMap.Map2Color4.Points ); 00950 if (ctx->EvalMap.Map2Normal.Points) 00951 FREE( ctx->EvalMap.Map2Normal.Points ); 00952 if (ctx->EvalMap.Map2Texture1.Points) 00953 FREE( ctx->EvalMap.Map2Texture1.Points ); 00954 if (ctx->EvalMap.Map2Texture2.Points) 00955 FREE( ctx->EvalMap.Map2Texture2.Points ); 00956 if (ctx->EvalMap.Map2Texture3.Points) 00957 FREE( ctx->EvalMap.Map2Texture3.Points ); 00958 if (ctx->EvalMap.Map2Texture4.Points) 00959 FREE( ctx->EvalMap.Map2Texture4.Points ); 00960 for (i = 0; i < 16; i++) 00961 FREE((ctx->EvalMap.Map2Attrib[i].Points)); 00962 } Generated on Sun May 27 2012 04:20:16 for ReactOS by
1.7.6.1
|