Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentexenv.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 7.1 00004 * 00005 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a 00008 * copy of this software and associated documentation files (the "Software"), 00009 * to deal in the Software without restriction, including without limitation 00010 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 * and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00018 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00021 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00032 #include "main/glheader.h" 00033 #include "main/context.h" 00034 #include "main/enums.h" 00035 #include "main/macros.h" 00036 #include "main/texenv.h" 00037 #include "math/m_xform.h" 00038 00039 00040 00041 void GLAPIENTRY 00042 _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param ) 00043 { 00044 GLuint maxUnit; 00045 GET_CURRENT_CONTEXT(ctx); 00046 struct gl_texture_unit *texUnit; 00047 ASSERT_OUTSIDE_BEGIN_END(ctx); 00048 00049 maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV) 00050 ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxTextureImageUnits; 00051 if (ctx->Texture.CurrentUnit >= maxUnit) { 00052 _mesa_error(ctx, GL_INVALID_OPERATION, "glTexEnvfv(current unit)"); 00053 return; 00054 } 00055 00056 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 00057 00058 #define TE_ERROR(errCode, msg, value) \ 00059 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value)); 00060 00061 if (target == GL_TEXTURE_ENV) { 00062 switch (pname) { 00063 case GL_TEXTURE_ENV_MODE: 00064 { 00065 GLenum mode = (GLenum) (GLint) *param; 00066 if (mode == GL_REPLACE_EXT) 00067 mode = GL_REPLACE; 00068 if (texUnit->EnvMode == mode) 00069 return; 00070 if (mode == GL_MODULATE || 00071 mode == GL_BLEND || 00072 mode == GL_DECAL || 00073 mode == GL_REPLACE || 00074 (mode == GL_ADD && ctx->Extensions.EXT_texture_env_add) || 00075 (mode == GL_COMBINE && 00076 (ctx->Extensions.EXT_texture_env_combine || 00077 ctx->Extensions.ARB_texture_env_combine))) { 00078 /* legal */ 00079 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00080 texUnit->EnvMode = mode; 00081 } 00082 else { 00083 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 00084 return; 00085 } 00086 } 00087 break; 00088 case GL_TEXTURE_ENV_COLOR: 00089 { 00090 GLfloat tmp[4]; 00091 tmp[0] = CLAMP( param[0], 0.0F, 1.0F ); 00092 tmp[1] = CLAMP( param[1], 0.0F, 1.0F ); 00093 tmp[2] = CLAMP( param[2], 0.0F, 1.0F ); 00094 tmp[3] = CLAMP( param[3], 0.0F, 1.0F ); 00095 if (TEST_EQ_4V(tmp, texUnit->EnvColor)) 00096 return; 00097 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00098 COPY_4FV(texUnit->EnvColor, tmp); 00099 } 00100 break; 00101 case GL_COMBINE_RGB: 00102 if (ctx->Extensions.EXT_texture_env_combine || 00103 ctx->Extensions.ARB_texture_env_combine) { 00104 const GLenum mode = (GLenum) (GLint) *param; 00105 if (texUnit->Combine.ModeRGB == mode) 00106 return; 00107 switch (mode) { 00108 case GL_REPLACE: 00109 case GL_MODULATE: 00110 case GL_ADD: 00111 case GL_ADD_SIGNED: 00112 case GL_INTERPOLATE: 00113 /* OK */ 00114 break; 00115 case GL_SUBTRACT: 00116 if (!ctx->Extensions.ARB_texture_env_combine) { 00117 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 00118 return; 00119 } 00120 break; 00121 case GL_DOT3_RGB_EXT: 00122 case GL_DOT3_RGBA_EXT: 00123 if (!ctx->Extensions.EXT_texture_env_dot3) { 00124 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 00125 return; 00126 } 00127 break; 00128 case GL_DOT3_RGB: 00129 case GL_DOT3_RGBA: 00130 if (!ctx->Extensions.ARB_texture_env_dot3) { 00131 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 00132 return; 00133 } 00134 break; 00135 case GL_MODULATE_ADD_ATI: 00136 case GL_MODULATE_SIGNED_ADD_ATI: 00137 case GL_MODULATE_SUBTRACT_ATI: 00138 if (!ctx->Extensions.ATI_texture_env_combine3) { 00139 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 00140 return; 00141 } 00142 break; 00143 default: 00144 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 00145 return; 00146 } 00147 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00148 texUnit->Combine.ModeRGB = mode; 00149 } 00150 else { 00151 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00152 return; 00153 } 00154 break; 00155 case GL_COMBINE_ALPHA: 00156 if (ctx->Extensions.EXT_texture_env_combine || 00157 ctx->Extensions.ARB_texture_env_combine) { 00158 const GLenum mode = (GLenum) (GLint) *param; 00159 if (texUnit->Combine.ModeA == mode) 00160 return; 00161 switch (mode) { 00162 case GL_REPLACE: 00163 case GL_MODULATE: 00164 case GL_ADD: 00165 case GL_ADD_SIGNED: 00166 case GL_INTERPOLATE: 00167 /* OK */ 00168 break; 00169 case GL_SUBTRACT: 00170 if (!ctx->Extensions.ARB_texture_env_combine) { 00171 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 00172 return; 00173 } 00174 break; 00175 case GL_MODULATE_ADD_ATI: 00176 case GL_MODULATE_SIGNED_ADD_ATI: 00177 case GL_MODULATE_SUBTRACT_ATI: 00178 if (!ctx->Extensions.ATI_texture_env_combine3) { 00179 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 00180 return; 00181 } 00182 break; 00183 default: 00184 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 00185 return; 00186 } 00187 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00188 texUnit->Combine.ModeA = mode; 00189 } 00190 else { 00191 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00192 return; 00193 } 00194 break; 00195 case GL_SOURCE0_RGB: 00196 case GL_SOURCE1_RGB: 00197 case GL_SOURCE2_RGB: 00198 if (ctx->Extensions.EXT_texture_env_combine || 00199 ctx->Extensions.ARB_texture_env_combine) { 00200 const GLenum source = (GLenum) (GLint) *param; 00201 const GLuint s = pname - GL_SOURCE0_RGB; 00202 if (texUnit->Combine.SourceRGB[s] == source) 00203 return; 00204 if (source == GL_TEXTURE || 00205 source == GL_CONSTANT || 00206 source == GL_PRIMARY_COLOR || 00207 source == GL_PREVIOUS || 00208 (ctx->Extensions.ARB_texture_env_crossbar && 00209 source >= GL_TEXTURE0 && 00210 source < GL_TEXTURE0 + ctx->Const.MaxTextureUnits) || 00211 (ctx->Extensions.ATI_texture_env_combine3 && 00212 (source == GL_ZERO || source == GL_ONE))) { 00213 /* legal */ 00214 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00215 texUnit->Combine.SourceRGB[s] = source; 00216 } 00217 else { 00218 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", source); 00219 return; 00220 } 00221 } 00222 else { 00223 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00224 return; 00225 } 00226 break; 00227 case GL_SOURCE0_ALPHA: 00228 case GL_SOURCE1_ALPHA: 00229 case GL_SOURCE2_ALPHA: 00230 if (ctx->Extensions.EXT_texture_env_combine || 00231 ctx->Extensions.ARB_texture_env_combine) { 00232 const GLenum source = (GLenum) (GLint) *param; 00233 const GLuint s = pname - GL_SOURCE0_ALPHA; 00234 if (texUnit->Combine.SourceA[s] == source) 00235 return; 00236 if (source == GL_TEXTURE || 00237 source == GL_CONSTANT || 00238 source == GL_PRIMARY_COLOR || 00239 source == GL_PREVIOUS || 00240 (ctx->Extensions.ARB_texture_env_crossbar && 00241 source >= GL_TEXTURE0 && 00242 source < GL_TEXTURE0 + ctx->Const.MaxTextureUnits) || 00243 (ctx->Extensions.ATI_texture_env_combine3 && 00244 (source == GL_ZERO || source == GL_ONE))) { 00245 /* legal */ 00246 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00247 texUnit->Combine.SourceA[s] = source; 00248 } 00249 else { 00250 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", source); 00251 return; 00252 } 00253 } 00254 else { 00255 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00256 return; 00257 } 00258 break; 00259 case GL_OPERAND0_RGB: 00260 case GL_OPERAND1_RGB: 00261 if (ctx->Extensions.EXT_texture_env_combine || 00262 ctx->Extensions.ARB_texture_env_combine) { 00263 const GLenum operand = (GLenum) (GLint) *param; 00264 const GLuint s = pname - GL_OPERAND0_RGB; 00265 if (texUnit->Combine.OperandRGB[s] == operand) 00266 return; 00267 switch (operand) { 00268 case GL_SRC_COLOR: 00269 case GL_ONE_MINUS_SRC_COLOR: 00270 case GL_SRC_ALPHA: 00271 case GL_ONE_MINUS_SRC_ALPHA: 00272 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00273 texUnit->Combine.OperandRGB[s] = operand; 00274 break; 00275 default: 00276 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand); 00277 return; 00278 } 00279 } 00280 else { 00281 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00282 return; 00283 } 00284 break; 00285 case GL_OPERAND0_ALPHA: 00286 case GL_OPERAND1_ALPHA: 00287 if (ctx->Extensions.EXT_texture_env_combine || 00288 ctx->Extensions.ARB_texture_env_combine) { 00289 const GLenum operand = (GLenum) (GLint) *param; 00290 if (texUnit->Combine.OperandA[pname-GL_OPERAND0_ALPHA] == operand) 00291 return; 00292 switch (operand) { 00293 case GL_SRC_ALPHA: 00294 case GL_ONE_MINUS_SRC_ALPHA: 00295 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00296 texUnit->Combine.OperandA[pname-GL_OPERAND0_ALPHA] = operand; 00297 break; 00298 default: 00299 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand); 00300 return; 00301 } 00302 } 00303 else { 00304 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00305 return; 00306 } 00307 break; 00308 case GL_OPERAND2_RGB: 00309 if (ctx->Extensions.ARB_texture_env_combine) { 00310 const GLenum operand = (GLenum) (GLint) *param; 00311 if (texUnit->Combine.OperandRGB[2] == operand) 00312 return; 00313 switch (operand) { 00314 case GL_SRC_COLOR: /* ARB combine only */ 00315 case GL_ONE_MINUS_SRC_COLOR: /* ARB combine only */ 00316 case GL_SRC_ALPHA: 00317 case GL_ONE_MINUS_SRC_ALPHA: /* ARB combine only */ 00318 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00319 texUnit->Combine.OperandRGB[2] = operand; 00320 break; 00321 default: 00322 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand); 00323 return; 00324 } 00325 } 00326 else if (ctx->Extensions.EXT_texture_env_combine) { 00327 const GLenum operand = (GLenum) (GLint) *param; 00328 if (texUnit->Combine.OperandRGB[2] == operand) 00329 return; 00330 /* operand must be GL_SRC_ALPHA which is the initial value - thus 00331 don't need to actually compare the operand to the possible value */ 00332 else { 00333 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand); 00334 return; 00335 } 00336 } 00337 else { 00338 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00339 return; 00340 } 00341 break; 00342 case GL_OPERAND2_ALPHA: 00343 if (ctx->Extensions.ARB_texture_env_combine) { 00344 const GLenum operand = (GLenum) (GLint) *param; 00345 if (texUnit->Combine.OperandA[2] == operand) 00346 return; 00347 switch (operand) { 00348 case GL_SRC_ALPHA: 00349 case GL_ONE_MINUS_SRC_ALPHA: /* ARB combine only */ 00350 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00351 texUnit->Combine.OperandA[2] = operand; 00352 break; 00353 default: 00354 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand); 00355 return; 00356 } 00357 } 00358 else if (ctx->Extensions.EXT_texture_env_combine) { 00359 const GLenum operand = (GLenum) (GLint) *param; 00360 if (texUnit->Combine.OperandA[2] == operand) 00361 return; 00362 /* operand must be GL_SRC_ALPHA which is the initial value - thus 00363 don't need to actually compare the operand to the possible value */ 00364 else { 00365 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand); 00366 return; 00367 } 00368 } 00369 else { 00370 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00371 return; 00372 } 00373 break; 00374 case GL_RGB_SCALE: 00375 if (ctx->Extensions.EXT_texture_env_combine || 00376 ctx->Extensions.ARB_texture_env_combine) { 00377 GLuint newshift; 00378 if (*param == 1.0) { 00379 newshift = 0; 00380 } 00381 else if (*param == 2.0) { 00382 newshift = 1; 00383 } 00384 else if (*param == 4.0) { 00385 newshift = 2; 00386 } 00387 else { 00388 _mesa_error( ctx, GL_INVALID_VALUE, 00389 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" ); 00390 return; 00391 } 00392 if (texUnit->Combine.ScaleShiftRGB == newshift) 00393 return; 00394 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00395 texUnit->Combine.ScaleShiftRGB = newshift; 00396 } 00397 else { 00398 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00399 return; 00400 } 00401 break; 00402 case GL_ALPHA_SCALE: 00403 if (ctx->Extensions.EXT_texture_env_combine || 00404 ctx->Extensions.ARB_texture_env_combine) { 00405 GLuint newshift; 00406 if (*param == 1.0) { 00407 newshift = 0; 00408 } 00409 else if (*param == 2.0) { 00410 newshift = 1; 00411 } 00412 else if (*param == 4.0) { 00413 newshift = 2; 00414 } 00415 else { 00416 _mesa_error( ctx, GL_INVALID_VALUE, 00417 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" ); 00418 return; 00419 } 00420 if (texUnit->Combine.ScaleShiftA == newshift) 00421 return; 00422 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00423 texUnit->Combine.ScaleShiftA = newshift; 00424 } 00425 else { 00426 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00427 return; 00428 } 00429 break; 00430 default: 00431 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" ); 00432 return; 00433 } 00434 } 00435 else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) { 00436 /* GL_EXT_texture_lod_bias */ 00437 if (!ctx->Extensions.EXT_texture_lod_bias) { 00438 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)", target ); 00439 return; 00440 } 00441 if (pname == GL_TEXTURE_LOD_BIAS_EXT) { 00442 if (texUnit->LodBias == param[0]) 00443 return; 00444 FLUSH_VERTICES(ctx, _NEW_TEXTURE); 00445 texUnit->LodBias = param[0]; 00446 } 00447 else { 00448 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 00449 return; 00450 } 00451 } 00452 else if (target == GL_POINT_SPRITE_NV) { 00453 /* GL_ARB_point_sprite / GL_NV_point_sprite */ 00454 if (!ctx->Extensions.NV_point_sprite 00455 && !ctx->Extensions.ARB_point_sprite) { 00456 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)", target ); 00457 return; 00458 } 00459 if (pname == GL_COORD_REPLACE_NV) { 00460 const GLenum value = (GLenum) param[0]; 00461 if (value == GL_TRUE || value == GL_FALSE) { 00462 /* It's kind of weird to set point state via glTexEnv, 00463 * but that's what the spec calls for. 00464 */ 00465 const GLboolean state = (GLboolean) value; 00466 if (ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] == state) 00467 return; 00468 FLUSH_VERTICES(ctx, _NEW_POINT); 00469 ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] = state; 00470 } 00471 else { 00472 _mesa_error( ctx, GL_INVALID_VALUE, "glTexEnv(param=0x%x)", value); 00473 return; 00474 } 00475 } 00476 else { 00477 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname=0x%x)", pname ); 00478 return; 00479 } 00480 } 00481 else { 00482 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)",target ); 00483 return; 00484 } 00485 00486 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE)) 00487 _mesa_debug(ctx, "glTexEnv %s %s %.1f(%s) ...\n", 00488 _mesa_lookup_enum_by_nr(target), 00489 _mesa_lookup_enum_by_nr(pname), 00490 *param, 00491 _mesa_lookup_enum_by_nr((GLenum) (GLint) *param)); 00492 00493 /* Tell device driver about the new texture environment */ 00494 if (ctx->Driver.TexEnv) { 00495 (*ctx->Driver.TexEnv)( ctx, target, pname, param ); 00496 } 00497 } 00498 00499 00500 void GLAPIENTRY 00501 _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param ) 00502 { 00503 _mesa_TexEnvfv( target, pname, ¶m ); 00504 } 00505 00506 00507 00508 void GLAPIENTRY 00509 _mesa_TexEnvi( GLenum target, GLenum pname, GLint param ) 00510 { 00511 GLfloat p[4]; 00512 p[0] = (GLfloat) param; 00513 p[1] = p[2] = p[3] = 0.0; 00514 _mesa_TexEnvfv( target, pname, p ); 00515 } 00516 00517 00518 void GLAPIENTRY 00519 _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param ) 00520 { 00521 GLfloat p[4]; 00522 if (pname == GL_TEXTURE_ENV_COLOR) { 00523 p[0] = INT_TO_FLOAT( param[0] ); 00524 p[1] = INT_TO_FLOAT( param[1] ); 00525 p[2] = INT_TO_FLOAT( param[2] ); 00526 p[3] = INT_TO_FLOAT( param[3] ); 00527 } 00528 else { 00529 p[0] = (GLfloat) param[0]; 00530 p[1] = p[2] = p[3] = 0; /* init to zero, just to be safe */ 00531 } 00532 _mesa_TexEnvfv( target, pname, p ); 00533 } 00534 00535 00536 00541 static GLint 00542 get_texenvi(GLcontext *ctx, const struct gl_texture_unit *texUnit, 00543 GLenum pname) 00544 { 00545 switch (pname) { 00546 case GL_TEXTURE_ENV_MODE: 00547 return texUnit->EnvMode; 00548 break; 00549 case GL_COMBINE_RGB: 00550 if (ctx->Extensions.EXT_texture_env_combine || 00551 ctx->Extensions.ARB_texture_env_combine) { 00552 return texUnit->Combine.ModeRGB; 00553 } 00554 else { 00555 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 00556 } 00557 break; 00558 case GL_COMBINE_ALPHA: 00559 if (ctx->Extensions.EXT_texture_env_combine || 00560 ctx->Extensions.ARB_texture_env_combine) { 00561 return texUnit->Combine.ModeA; 00562 } 00563 else { 00564 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 00565 } 00566 break; 00567 case GL_SOURCE0_RGB: 00568 case GL_SOURCE1_RGB: 00569 case GL_SOURCE2_RGB: 00570 if (ctx->Extensions.EXT_texture_env_combine || 00571 ctx->Extensions.ARB_texture_env_combine) { 00572 const unsigned rgb_idx = pname - GL_SOURCE0_RGB; 00573 return texUnit->Combine.SourceRGB[rgb_idx]; 00574 } 00575 else { 00576 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 00577 } 00578 break; 00579 case GL_SOURCE0_ALPHA: 00580 case GL_SOURCE1_ALPHA: 00581 case GL_SOURCE2_ALPHA: 00582 if (ctx->Extensions.EXT_texture_env_combine || 00583 ctx->Extensions.ARB_texture_env_combine) { 00584 const unsigned alpha_idx = pname - GL_SOURCE0_ALPHA; 00585 return texUnit->Combine.SourceA[alpha_idx]; 00586 } 00587 else { 00588 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 00589 } 00590 break; 00591 case GL_OPERAND0_RGB: 00592 case GL_OPERAND1_RGB: 00593 case GL_OPERAND2_RGB: 00594 if (ctx->Extensions.EXT_texture_env_combine || 00595 ctx->Extensions.ARB_texture_env_combine) { 00596 const unsigned op_rgb = pname - GL_OPERAND0_RGB; 00597 return texUnit->Combine.OperandRGB[op_rgb]; 00598 } 00599 else { 00600 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 00601 } 00602 break; 00603 case GL_OPERAND0_ALPHA: 00604 case GL_OPERAND1_ALPHA: 00605 case GL_OPERAND2_ALPHA: 00606 if (ctx->Extensions.EXT_texture_env_combine || 00607 ctx->Extensions.ARB_texture_env_combine) { 00608 const unsigned op_alpha = pname - GL_OPERAND0_ALPHA; 00609 return texUnit->Combine.OperandA[op_alpha]; 00610 } 00611 else { 00612 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 00613 } 00614 break; 00615 case GL_RGB_SCALE: 00616 if (ctx->Extensions.EXT_texture_env_combine || 00617 ctx->Extensions.ARB_texture_env_combine) { 00618 return 1 << texUnit->Combine.ScaleShiftRGB; 00619 } 00620 else { 00621 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 00622 } 00623 break; 00624 case GL_ALPHA_SCALE: 00625 if (ctx->Extensions.EXT_texture_env_combine || 00626 ctx->Extensions.ARB_texture_env_combine) { 00627 return 1 << texUnit->Combine.ScaleShiftA; 00628 } 00629 else { 00630 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 00631 } 00632 break; 00633 default: 00634 ; 00635 } 00636 00637 return -1; /* error */ 00638 } 00639 00640 00641 00642 void GLAPIENTRY 00643 _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params ) 00644 { 00645 GLuint maxUnit; 00646 const struct gl_texture_unit *texUnit; 00647 GET_CURRENT_CONTEXT(ctx); 00648 ASSERT_OUTSIDE_BEGIN_END(ctx); 00649 00650 maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV) 00651 ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxTextureImageUnits; 00652 if (ctx->Texture.CurrentUnit >= maxUnit) { 00653 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexEnvfv(current unit)"); 00654 return; 00655 } 00656 00657 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 00658 00659 if (target == GL_TEXTURE_ENV) { 00660 if (pname == GL_TEXTURE_ENV_COLOR) { 00661 COPY_4FV( params, texUnit->EnvColor ); 00662 } 00663 else { 00664 GLint val = get_texenvi(ctx, texUnit, pname); 00665 if (val >= 0) { 00666 *params = (GLfloat) val; 00667 } 00668 } 00669 } 00670 else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) { 00671 /* GL_EXT_texture_lod_bias */ 00672 if (!ctx->Extensions.EXT_texture_lod_bias) { 00673 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" ); 00674 return; 00675 } 00676 if (pname == GL_TEXTURE_LOD_BIAS_EXT) { 00677 *params = texUnit->LodBias; 00678 } 00679 else { 00680 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" ); 00681 return; 00682 } 00683 } 00684 else if (target == GL_POINT_SPRITE_NV) { 00685 /* GL_ARB_point_sprite / GL_NV_point_sprite */ 00686 if (!ctx->Extensions.NV_point_sprite 00687 && !ctx->Extensions.ARB_point_sprite) { 00688 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" ); 00689 return; 00690 } 00691 if (pname == GL_COORD_REPLACE_NV) { 00692 *params = (GLfloat) ctx->Point.CoordReplace[ctx->Texture.CurrentUnit]; 00693 } 00694 else { 00695 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" ); 00696 return; 00697 } 00698 } 00699 else { 00700 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" ); 00701 return; 00702 } 00703 } 00704 00705 00706 void GLAPIENTRY 00707 _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params ) 00708 { 00709 GLuint maxUnit; 00710 const struct gl_texture_unit *texUnit; 00711 GET_CURRENT_CONTEXT(ctx); 00712 ASSERT_OUTSIDE_BEGIN_END(ctx); 00713 00714 maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV) 00715 ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxTextureImageUnits; 00716 if (ctx->Texture.CurrentUnit >= maxUnit) { 00717 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexEnviv(current unit)"); 00718 return; 00719 } 00720 00721 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 00722 00723 if (target == GL_TEXTURE_ENV) { 00724 if (pname == GL_TEXTURE_ENV_COLOR) { 00725 params[0] = FLOAT_TO_INT( texUnit->EnvColor[0] ); 00726 params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] ); 00727 params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] ); 00728 params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] ); 00729 } 00730 else { 00731 GLint val = get_texenvi(ctx, texUnit, pname); 00732 if (val >= 0) { 00733 *params = val; 00734 } 00735 } 00736 } 00737 else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) { 00738 /* GL_EXT_texture_lod_bias */ 00739 if (!ctx->Extensions.EXT_texture_lod_bias) { 00740 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" ); 00741 return; 00742 } 00743 if (pname == GL_TEXTURE_LOD_BIAS_EXT) { 00744 *params = (GLint) texUnit->LodBias; 00745 } 00746 else { 00747 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" ); 00748 return; 00749 } 00750 } 00751 else if (target == GL_POINT_SPRITE_NV) { 00752 /* GL_ARB_point_sprite / GL_NV_point_sprite */ 00753 if (!ctx->Extensions.NV_point_sprite 00754 && !ctx->Extensions.ARB_point_sprite) { 00755 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" ); 00756 return; 00757 } 00758 if (pname == GL_COORD_REPLACE_NV) { 00759 *params = (GLint) ctx->Point.CoordReplace[ctx->Texture.CurrentUnit]; 00760 } 00761 else { 00762 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" ); 00763 return; 00764 } 00765 } 00766 else { 00767 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" ); 00768 return; 00769 } 00770 } 00771 00772 Generated on Sun May 27 2012 04:20:29 for ReactOS by
1.7.6.1
|