| 1 |
/* $Id: texture.c,v 1.2 2000/10/27 15:21:40 mholst Exp $ */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Mesa 3-D graphics library |
| 5 |
* Version: 2.2 |
| 6 |
* Copyright (C) 1995-1997 Brian Paul |
| 7 |
* |
| 8 |
* This library is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Library General Public |
| 10 |
* License as published by the Free Software Foundation; either |
| 11 |
* version 2 of the License, or (at your option) any later version. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Library General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Library General Public |
| 19 |
* License along with this library; if not, write to the Free |
| 20 |
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <assert.h> |
| 24 |
#include <math.h> |
| 25 |
#include <stdio.h> |
| 26 |
#include <stdlib.h> |
| 27 |
#include <string.h> |
| 28 |
#include "context.h" |
| 29 |
#include "dlist.h" |
| 30 |
#include "macros.h" |
| 31 |
#include "matrix.h" |
| 32 |
#include "pb.h" |
| 33 |
#include "teximage.h" |
| 34 |
#include "texture.h" |
| 35 |
#include "types.h" |
| 36 |
#include "xform.h" |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
/**********************************************************************/ |
| 42 |
/* Texture Environment */ |
| 43 |
/**********************************************************************/ |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
void gl_TexEnvfv( GLcontext *ctx, |
| 48 |
GLenum target, GLenum pname, const GLfloat *param ) |
| 49 |
{ |
| 50 |
if (INSIDE_BEGIN_END(ctx)) { |
| 51 |
gl_error( ctx, GL_INVALID_OPERATION, "glTexEnv" ); |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
if (target!=GL_TEXTURE_ENV) { |
| 56 |
gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" ); |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
if (pname==GL_TEXTURE_ENV_MODE) { |
| 61 |
GLenum mode = (GLenum) (GLint) *param; |
| 62 |
switch (mode) { |
| 63 |
case GL_MODULATE: |
| 64 |
case GL_BLEND: |
| 65 |
case GL_DECAL: |
| 66 |
case GL_REPLACE: |
| 67 |
ctx->Texture.EnvMode = mode; |
| 68 |
break; |
| 69 |
default: |
| 70 |
gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); |
| 71 |
return; |
| 72 |
} |
| 73 |
} |
| 74 |
else if (pname==GL_TEXTURE_ENV_COLOR) { |
| 75 |
ctx->Texture.EnvColor[0] = CLAMP( param[0], 0.0, 1.0 ); |
| 76 |
ctx->Texture.EnvColor[1] = CLAMP( param[1], 0.0, 1.0 ); |
| 77 |
ctx->Texture.EnvColor[2] = CLAMP( param[2], 0.0, 1.0 ); |
| 78 |
ctx->Texture.EnvColor[3] = CLAMP( param[3], 0.0, 1.0 ); |
| 79 |
} |
| 80 |
else { |
| 81 |
gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" ); |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
/* Tell device driver about the new texture environment */ |
| 86 |
if (ctx->Driver.TexEnv) { |
| 87 |
(*ctx->Driver.TexEnv)( ctx, pname, param ); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
void gl_GetTexEnvfv( GLcontext *ctx, |
| 96 |
GLenum target, GLenum pname, GLfloat *params ) |
| 97 |
{ |
| 98 |
if (target!=GL_TEXTURE_ENV) { |
| 99 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" ); |
| 100 |
return; |
| 101 |
} |
| 102 |
switch (pname) { |
| 103 |
case GL_TEXTURE_ENV_MODE: |
| 104 |
*params = (GLfloat) ctx->Texture.EnvMode; |
| 105 |
break; |
| 106 |
case GL_TEXTURE_ENV_COLOR: |
| 107 |
COPY_4V( params, ctx->Texture.EnvColor ); |
| 108 |
break; |
| 109 |
default: |
| 110 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" ); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
void gl_GetTexEnviv( GLcontext *ctx, |
| 116 |
GLenum target, GLenum pname, GLint *params ) |
| 117 |
{ |
| 118 |
if (target!=GL_TEXTURE_ENV) { |
| 119 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" ); |
| 120 |
return; |
| 121 |
} |
| 122 |
switch (pname) { |
| 123 |
case GL_TEXTURE_ENV_MODE: |
| 124 |
*params = (GLint) ctx->Texture.EnvMode; |
| 125 |
break; |
| 126 |
case GL_TEXTURE_ENV_COLOR: |
| 127 |
params[0] = FLOAT_TO_INT( ctx->Texture.EnvColor[0] ); |
| 128 |
params[1] = FLOAT_TO_INT( ctx->Texture.EnvColor[1] ); |
| 129 |
params[2] = FLOAT_TO_INT( ctx->Texture.EnvColor[2] ); |
| 130 |
params[3] = FLOAT_TO_INT( ctx->Texture.EnvColor[3] ); |
| 131 |
break; |
| 132 |
default: |
| 133 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" ); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
/**********************************************************************/ |
| 141 |
/* Texture Parameters */ |
| 142 |
/**********************************************************************/ |
| 143 |
|
| 144 |
|
| 145 |
void gl_TexParameterfv( GLcontext *ctx, |
| 146 |
GLenum target, GLenum pname, const GLfloat *params ) |
| 147 |
{ |
| 148 |
GLenum eparam = (GLenum) (GLint) params[0]; |
| 149 |
GLuint ddTexObject; |
| 150 |
|
| 151 |
if (target==GL_TEXTURE_1D) { |
| 152 |
switch (pname) { |
| 153 |
case GL_TEXTURE_MIN_FILTER: |
| 154 |
if (eparam==GL_NEAREST || eparam==GL_LINEAR |
| 155 |
|| eparam==GL_NEAREST_MIPMAP_NEAREST |
| 156 |
|| eparam==GL_LINEAR_MIPMAP_NEAREST |
| 157 |
|| eparam==GL_NEAREST_MIPMAP_LINEAR |
| 158 |
|| eparam==GL_LINEAR_MIPMAP_LINEAR) { |
| 159 |
ctx->Texture.Current1D->MinFilter = eparam; |
| 160 |
ctx->NewState |= NEW_TEXTURING; |
| 161 |
} |
| 162 |
else { |
| 163 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 164 |
return; |
| 165 |
} |
| 166 |
break; |
| 167 |
case GL_TEXTURE_MAG_FILTER: |
| 168 |
if (eparam==GL_NEAREST || eparam==GL_LINEAR) { |
| 169 |
ctx->Texture.Current1D->MagFilter = eparam; |
| 170 |
ctx->NewState |= NEW_TEXTURING; |
| 171 |
} |
| 172 |
else { |
| 173 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 174 |
return; |
| 175 |
} |
| 176 |
break; |
| 177 |
case GL_TEXTURE_WRAP_S: |
| 178 |
if (eparam==GL_CLAMP || eparam==GL_REPEAT) { |
| 179 |
ctx->Texture.Current1D->WrapS = eparam; |
| 180 |
} |
| 181 |
else { |
| 182 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 183 |
return; |
| 184 |
} |
| 185 |
break; |
| 186 |
case GL_TEXTURE_WRAP_T: |
| 187 |
if (eparam==GL_CLAMP || eparam==GL_REPEAT) { |
| 188 |
ctx->Texture.Current1D->WrapT = eparam; |
| 189 |
} |
| 190 |
else { |
| 191 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 192 |
return; |
| 193 |
} |
| 194 |
break; |
| 195 |
case GL_TEXTURE_BORDER_COLOR: |
| 196 |
{ |
| 197 |
GLint *bc = ctx->Texture.Current1D->BorderColor; |
| 198 |
bc[0] = CLAMP((GLint)(params[0]*255.0), 0, 255); |
| 199 |
bc[1] = CLAMP((GLint)(params[1]*255.0), 0, 255); |
| 200 |
bc[2] = CLAMP((GLint)(params[2]*255.0), 0, 255); |
| 201 |
bc[3] = CLAMP((GLint)(params[3]*255.0), 0, 255); |
| 202 |
} |
| 203 |
break; |
| 204 |
default: |
| 205 |
gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(pname)" ); |
| 206 |
return; |
| 207 |
} |
| 208 |
ddTexObject = ctx->Texture.Current1D->Name; |
| 209 |
} |
| 210 |
else if (target==GL_TEXTURE_2D) { |
| 211 |
switch (pname) { |
| 212 |
case GL_TEXTURE_MIN_FILTER: |
| 213 |
if (eparam==GL_NEAREST || eparam==GL_LINEAR |
| 214 |
|| eparam==GL_NEAREST_MIPMAP_NEAREST |
| 215 |
|| eparam==GL_LINEAR_MIPMAP_NEAREST |
| 216 |
|| eparam==GL_NEAREST_MIPMAP_LINEAR |
| 217 |
|| eparam==GL_LINEAR_MIPMAP_LINEAR) { |
| 218 |
ctx->Texture.Current2D->MinFilter = eparam; |
| 219 |
ctx->NewState |= NEW_TEXTURING; |
| 220 |
} |
| 221 |
else { |
| 222 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 223 |
return; |
| 224 |
} |
| 225 |
break; |
| 226 |
case GL_TEXTURE_MAG_FILTER: |
| 227 |
if (eparam==GL_NEAREST || eparam==GL_LINEAR) { |
| 228 |
ctx->Texture.Current2D->MagFilter = eparam; |
| 229 |
ctx->NewState |= NEW_TEXTURING; |
| 230 |
} |
| 231 |
else { |
| 232 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 233 |
return; |
| 234 |
} |
| 235 |
break; |
| 236 |
case GL_TEXTURE_WRAP_S: |
| 237 |
if (eparam==GL_CLAMP || eparam==GL_REPEAT) { |
| 238 |
ctx->Texture.Current2D->WrapS = eparam; |
| 239 |
} |
| 240 |
else { |
| 241 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 242 |
return; |
| 243 |
} |
| 244 |
break; |
| 245 |
case GL_TEXTURE_WRAP_T: |
| 246 |
if (eparam==GL_CLAMP || eparam==GL_REPEAT) { |
| 247 |
ctx->Texture.Current2D->WrapT = eparam; |
| 248 |
} |
| 249 |
else { |
| 250 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 251 |
return; |
| 252 |
} |
| 253 |
break; |
| 254 |
case GL_TEXTURE_BORDER_COLOR: |
| 255 |
{ |
| 256 |
GLint *bc = ctx->Texture.Current2D->BorderColor; |
| 257 |
bc[0] = CLAMP((GLint)(params[0]*255.0), 0, 255); |
| 258 |
bc[1] = CLAMP((GLint)(params[1]*255.0), 0, 255); |
| 259 |
bc[2] = CLAMP((GLint)(params[2]*255.0), 0, 255); |
| 260 |
bc[3] = CLAMP((GLint)(params[3]*255.0), 0, 255); |
| 261 |
} |
| 262 |
break; |
| 263 |
default: |
| 264 |
gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(pname)" ); |
| 265 |
return; |
| 266 |
} |
| 267 |
ddTexObject = ctx->Texture.Current1D->Name; |
| 268 |
} |
| 269 |
else if (target==GL_TEXTURE_3D_EXT) { |
| 270 |
switch (pname) { |
| 271 |
case GL_TEXTURE_MIN_FILTER: |
| 272 |
if (eparam==GL_NEAREST || eparam==GL_LINEAR |
| 273 |
|| eparam==GL_NEAREST_MIPMAP_NEAREST |
| 274 |
|| eparam==GL_LINEAR_MIPMAP_NEAREST |
| 275 |
|| eparam==GL_NEAREST_MIPMAP_LINEAR |
| 276 |
|| eparam==GL_LINEAR_MIPMAP_LINEAR) { |
| 277 |
ctx->Texture.Current3D->MinFilter = eparam; |
| 278 |
ctx->NewState |= NEW_TEXTURING; |
| 279 |
} |
| 280 |
else { |
| 281 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 282 |
} |
| 283 |
break; |
| 284 |
case GL_TEXTURE_MAG_FILTER: |
| 285 |
if (eparam==GL_NEAREST || eparam==GL_LINEAR) { |
| 286 |
ctx->Texture.Current3D->MagFilter = eparam; |
| 287 |
ctx->NewState |= NEW_TEXTURING; |
| 288 |
} |
| 289 |
else { |
| 290 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 291 |
} |
| 292 |
break; |
| 293 |
case GL_TEXTURE_WRAP_S: |
| 294 |
if (eparam==GL_CLAMP || eparam==GL_REPEAT) { |
| 295 |
ctx->Texture.Current3D->WrapS = eparam; |
| 296 |
} |
| 297 |
else { |
| 298 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 299 |
} |
| 300 |
break; |
| 301 |
case GL_TEXTURE_WRAP_T: |
| 302 |
if (eparam==GL_CLAMP || eparam==GL_REPEAT) { |
| 303 |
ctx->Texture.Current3D->WrapT = eparam; |
| 304 |
} |
| 305 |
else { |
| 306 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 307 |
} |
| 308 |
break; |
| 309 |
case GL_TEXTURE_WRAP_R_EXT: |
| 310 |
if (eparam==GL_CLAMP || eparam==GL_REPEAT) { |
| 311 |
ctx->Texture.Current3D->WrapR = eparam; |
| 312 |
} |
| 313 |
else { |
| 314 |
gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); |
| 315 |
} |
| 316 |
break; |
| 317 |
case GL_TEXTURE_BORDER_COLOR: |
| 318 |
{ |
| 319 |
GLint *bc = ctx->Texture.Current3D->BorderColor; |
| 320 |
bc[0] = CLAMP((GLint)(params[0]*255.0), 0, 255); |
| 321 |
bc[1] = CLAMP((GLint)(params[1]*255.0), 0, 255); |
| 322 |
bc[2] = CLAMP((GLint)(params[2]*255.0), 0, 255); |
| 323 |
bc[3] = CLAMP((GLint)(params[3]*255.0), 0, 255); |
| 324 |
} |
| 325 |
break; |
| 326 |
default: |
| 327 |
gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(pname)" ); |
| 328 |
} |
| 329 |
} |
| 330 |
else { |
| 331 |
gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" ); |
| 332 |
return; |
| 333 |
} |
| 334 |
|
| 335 |
/* Pass this glTexParameter*() call to the device driver. */ |
| 336 |
if (ctx->Driver.TexParameter) { |
| 337 |
(*ctx->Driver.TexParameter)( ctx, target, ddTexObject, pname, params ); |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
void gl_GetTexLevelParameterfv( GLcontext *ctx, GLenum target, GLint level, |
| 344 |
GLenum pname, GLfloat *params ) |
| 345 |
{ |
| 346 |
struct gl_texture_image *tex; |
| 347 |
|
| 348 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 349 |
gl_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameterfv" ); |
| 350 |
return; |
| 351 |
} |
| 352 |
|
| 353 |
switch (target) { |
| 354 |
case GL_TEXTURE_1D: |
| 355 |
tex = ctx->Texture.Current1D->Image[level]; |
| 356 |
switch (pname) { |
| 357 |
case GL_TEXTURE_WIDTH: |
| 358 |
*params = (GLfloat) tex->Width; |
| 359 |
break; |
| 360 |
case GL_TEXTURE_COMPONENTS: |
| 361 |
*params = (GLfloat) tex->Format; |
| 362 |
break; |
| 363 |
case GL_TEXTURE_BORDER: |
| 364 |
*params = (GLfloat) tex->Border; |
| 365 |
break; |
| 366 |
case GL_TEXTURE_RED_SIZE: |
| 367 |
case GL_TEXTURE_GREEN_SIZE: |
| 368 |
case GL_TEXTURE_BLUE_SIZE: |
| 369 |
case GL_TEXTURE_ALPHA_SIZE: |
| 370 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 371 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 372 |
*params = 8.0; /* 8-bits */ |
| 373 |
break; |
| 374 |
default: |
| 375 |
gl_error( ctx, GL_INVALID_ENUM, |
| 376 |
"glGetTexLevelParameterfv(pname)" ); |
| 377 |
} |
| 378 |
break; |
| 379 |
case GL_TEXTURE_2D: |
| 380 |
tex = ctx->Texture.Current2D->Image[level]; |
| 381 |
switch (pname) { |
| 382 |
case GL_TEXTURE_WIDTH: |
| 383 |
*params = (GLfloat) tex->Width; |
| 384 |
break; |
| 385 |
case GL_TEXTURE_HEIGHT: |
| 386 |
*params = (GLfloat) tex->Height; |
| 387 |
break; |
| 388 |
case GL_TEXTURE_COMPONENTS: |
| 389 |
*params = (GLfloat) tex->Format; |
| 390 |
break; |
| 391 |
case GL_TEXTURE_BORDER: |
| 392 |
*params = (GLfloat) tex->Border; |
| 393 |
break; |
| 394 |
case GL_TEXTURE_RED_SIZE: |
| 395 |
case GL_TEXTURE_GREEN_SIZE: |
| 396 |
case GL_TEXTURE_BLUE_SIZE: |
| 397 |
case GL_TEXTURE_ALPHA_SIZE: |
| 398 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 399 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 400 |
*params = 8.0; /* 8-bits */ |
| 401 |
break; |
| 402 |
default: |
| 403 |
gl_error( ctx, GL_INVALID_ENUM, |
| 404 |
"glGetTexLevelParameterfv(pname)" ); |
| 405 |
} |
| 406 |
break; |
| 407 |
case GL_TEXTURE_3D_EXT: |
| 408 |
tex = ctx->Texture.Current3D->Image[level]; |
| 409 |
switch (pname) { |
| 410 |
case GL_TEXTURE_WIDTH: |
| 411 |
*params = (GLfloat) tex->Width; |
| 412 |
break; |
| 413 |
case GL_TEXTURE_HEIGHT: |
| 414 |
*params = (GLfloat) tex->Height; |
| 415 |
break; |
| 416 |
case GL_TEXTURE_DEPTH_EXT: |
| 417 |
*params = (GLfloat) tex->Depth; |
| 418 |
break; |
| 419 |
case GL_TEXTURE_COMPONENTS: |
| 420 |
*params = (GLfloat) tex->Format; |
| 421 |
break; |
| 422 |
case GL_TEXTURE_BORDER: |
| 423 |
*params = (GLfloat) tex->Border; |
| 424 |
break; |
| 425 |
default: |
| 426 |
gl_error( ctx, GL_INVALID_ENUM, |
| 427 |
"glGetTexLevelParameterfv(pname)" ); |
| 428 |
} |
| 429 |
break; |
| 430 |
case GL_PROXY_TEXTURE_1D: |
| 431 |
tex = ctx->Texture.Proxy1D->Image[level]; |
| 432 |
switch (pname) { |
| 433 |
case GL_TEXTURE_WIDTH: |
| 434 |
*params = (GLfloat) tex->Width; |
| 435 |
break; |
| 436 |
case GL_TEXTURE_COMPONENTS: |
| 437 |
*params = (GLfloat) tex->Format; |
| 438 |
break; |
| 439 |
case GL_TEXTURE_BORDER: |
| 440 |
*params = (GLfloat) tex->Border; |
| 441 |
break; |
| 442 |
case GL_TEXTURE_RED_SIZE: |
| 443 |
case GL_TEXTURE_GREEN_SIZE: |
| 444 |
case GL_TEXTURE_BLUE_SIZE: |
| 445 |
case GL_TEXTURE_ALPHA_SIZE: |
| 446 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 447 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 448 |
*params = 8.0; /* 8-bits */ |
| 449 |
break; |
| 450 |
default: |
| 451 |
gl_error( ctx, GL_INVALID_ENUM, |
| 452 |
"glGetTexLevelParameterfv(pname)" ); |
| 453 |
} |
| 454 |
break; |
| 455 |
case GL_PROXY_TEXTURE_2D: |
| 456 |
tex = ctx->Texture.Proxy2D->Image[level]; |
| 457 |
switch (pname) { |
| 458 |
case GL_TEXTURE_WIDTH: |
| 459 |
*params = (GLfloat) tex->Width; |
| 460 |
break; |
| 461 |
case GL_TEXTURE_HEIGHT: |
| 462 |
*params = (GLfloat) tex->Height; |
| 463 |
break; |
| 464 |
case GL_TEXTURE_COMPONENTS: |
| 465 |
*params = (GLfloat) tex->Format; |
| 466 |
break; |
| 467 |
case GL_TEXTURE_BORDER: |
| 468 |
*params = (GLfloat) tex->Border; |
| 469 |
break; |
| 470 |
case GL_TEXTURE_RED_SIZE: |
| 471 |
case GL_TEXTURE_GREEN_SIZE: |
| 472 |
case GL_TEXTURE_BLUE_SIZE: |
| 473 |
case GL_TEXTURE_ALPHA_SIZE: |
| 474 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 475 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 476 |
*params = 8.0; /* 8-bits */ |
| 477 |
break; |
| 478 |
default: |
| 479 |
gl_error( ctx, GL_INVALID_ENUM, |
| 480 |
"glGetTexLevelParameterfv(pname)" ); |
| 481 |
} |
| 482 |
break; |
| 483 |
case GL_PROXY_TEXTURE_3D_EXT: |
| 484 |
tex = ctx->Texture.Proxy3D->Image[level]; |
| 485 |
switch (pname) { |
| 486 |
case GL_TEXTURE_WIDTH: |
| 487 |
*params = (GLfloat) tex->Width; |
| 488 |
break; |
| 489 |
case GL_TEXTURE_HEIGHT: |
| 490 |
*params = (GLfloat) tex->Height; |
| 491 |
break; |
| 492 |
case GL_TEXTURE_DEPTH_EXT: |
| 493 |
*params = (GLfloat) tex->Depth; |
| 494 |
break; |
| 495 |
case GL_TEXTURE_COMPONENTS: |
| 496 |
*params = (GLfloat) tex->Format; |
| 497 |
break; |
| 498 |
case GL_TEXTURE_BORDER: |
| 499 |
*params = (GLfloat) tex->Border; |
| 500 |
break; |
| 501 |
case GL_TEXTURE_RED_SIZE: |
| 502 |
case GL_TEXTURE_GREEN_SIZE: |
| 503 |
case GL_TEXTURE_BLUE_SIZE: |
| 504 |
case GL_TEXTURE_ALPHA_SIZE: |
| 505 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 506 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 507 |
*params = 8.0; /* 8-bits */ |
| 508 |
break; |
| 509 |
default: |
| 510 |
gl_error( ctx, GL_INVALID_ENUM, |
| 511 |
"glGetTexLevelParameterfv(pname)" ); |
| 512 |
} |
| 513 |
break; |
| 514 |
default: |
| 515 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexLevelParameterfv(target)" ); |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
void gl_GetTexLevelParameteriv( GLcontext *ctx, GLenum target, GLint level, |
| 522 |
GLenum pname, GLint *params ) |
| 523 |
{ |
| 524 |
struct gl_texture_image *tex; |
| 525 |
|
| 526 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 527 |
gl_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameteriv" ); |
| 528 |
return; |
| 529 |
} |
| 530 |
|
| 531 |
switch (target) { |
| 532 |
case GL_TEXTURE_1D: |
| 533 |
tex = ctx->Texture.Current1D->Image[level]; |
| 534 |
switch (pname) { |
| 535 |
case GL_TEXTURE_WIDTH: |
| 536 |
*params = tex->Width; |
| 537 |
break; |
| 538 |
case GL_TEXTURE_COMPONENTS: |
| 539 |
*params = tex->Format; |
| 540 |
break; |
| 541 |
case GL_TEXTURE_BORDER: |
| 542 |
*params = tex->Border; |
| 543 |
break; |
| 544 |
case GL_TEXTURE_RED_SIZE: |
| 545 |
case GL_TEXTURE_GREEN_SIZE: |
| 546 |
case GL_TEXTURE_BLUE_SIZE: |
| 547 |
case GL_TEXTURE_ALPHA_SIZE: |
| 548 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 549 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 550 |
*params = 8; /* 8-bits */ |
| 551 |
break; |
| 552 |
default: |
| 553 |
gl_error( ctx, GL_INVALID_ENUM, |
| 554 |
"glGetTexLevelParameteriv(pname)" ); |
| 555 |
} |
| 556 |
break; |
| 557 |
case GL_TEXTURE_2D: |
| 558 |
tex = ctx->Texture.Current2D->Image[level]; |
| 559 |
switch (pname) { |
| 560 |
case GL_TEXTURE_WIDTH: |
| 561 |
*params = tex->Width; |
| 562 |
break; |
| 563 |
case GL_TEXTURE_HEIGHT: |
| 564 |
*params = tex->Height; |
| 565 |
break; |
| 566 |
case GL_TEXTURE_COMPONENTS: |
| 567 |
*params = tex->Format; |
| 568 |
break; |
| 569 |
case GL_TEXTURE_BORDER: |
| 570 |
*params = tex->Border; |
| 571 |
break; |
| 572 |
case GL_TEXTURE_RED_SIZE: |
| 573 |
case GL_TEXTURE_GREEN_SIZE: |
| 574 |
case GL_TEXTURE_BLUE_SIZE: |
| 575 |
case GL_TEXTURE_ALPHA_SIZE: |
| 576 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 577 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 578 |
*params = 8; /* 8-bits */ |
| 579 |
break; |
| 580 |
default: |
| 581 |
gl_error( ctx, GL_INVALID_ENUM, |
| 582 |
"glGetTexLevelParameteriv(pname)" ); |
| 583 |
} |
| 584 |
break; |
| 585 |
case GL_TEXTURE_3D_EXT: |
| 586 |
tex = ctx->Texture.Current3D->Image[level]; |
| 587 |
switch (pname) { |
| 588 |
case GL_TEXTURE_WIDTH: |
| 589 |
*params = tex->Width; |
| 590 |
break; |
| 591 |
case GL_TEXTURE_HEIGHT: |
| 592 |
*params = tex->Height; |
| 593 |
break; |
| 594 |
case GL_TEXTURE_DEPTH_EXT: |
| 595 |
*params = tex->Depth; |
| 596 |
break; |
| 597 |
case GL_TEXTURE_COMPONENTS: |
| 598 |
*params = tex->Format; |
| 599 |
break; |
| 600 |
case GL_TEXTURE_BORDER: |
| 601 |
*params = tex->Border; |
| 602 |
break; |
| 603 |
default: |
| 604 |
gl_error( ctx, GL_INVALID_ENUM, |
| 605 |
"glGetTexLevelParameteriv(pname)" ); |
| 606 |
} |
| 607 |
break; |
| 608 |
case GL_PROXY_TEXTURE_1D: |
| 609 |
tex = ctx->Texture.Proxy1D->Image[level]; |
| 610 |
switch (pname) { |
| 611 |
case GL_TEXTURE_WIDTH: |
| 612 |
*params = tex->Width; |
| 613 |
break; |
| 614 |
case GL_TEXTURE_COMPONENTS: |
| 615 |
*params = tex->Format; |
| 616 |
break; |
| 617 |
case GL_TEXTURE_BORDER: |
| 618 |
*params = tex->Border; |
| 619 |
break; |
| 620 |
case GL_TEXTURE_RED_SIZE: |
| 621 |
case GL_TEXTURE_GREEN_SIZE: |
| 622 |
case GL_TEXTURE_BLUE_SIZE: |
| 623 |
case GL_TEXTURE_ALPHA_SIZE: |
| 624 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 625 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 626 |
*params = 8; /* 8-bits */ |
| 627 |
break; |
| 628 |
default: |
| 629 |
gl_error( ctx, GL_INVALID_ENUM, |
| 630 |
"glGetTexLevelParameteriv(pname)" ); |
| 631 |
} |
| 632 |
break; |
| 633 |
case GL_PROXY_TEXTURE_2D: |
| 634 |
tex = ctx->Texture.Proxy2D->Image[level]; |
| 635 |
switch (pname) { |
| 636 |
case GL_TEXTURE_WIDTH: |
| 637 |
*params = tex->Width; |
| 638 |
break; |
| 639 |
case GL_TEXTURE_HEIGHT: |
| 640 |
*params = tex->Height; |
| 641 |
break; |
| 642 |
case GL_TEXTURE_COMPONENTS: |
| 643 |
*params = tex->Format; |
| 644 |
break; |
| 645 |
case GL_TEXTURE_BORDER: |
| 646 |
*params = tex->Border; |
| 647 |
break; |
| 648 |
case GL_TEXTURE_RED_SIZE: |
| 649 |
case GL_TEXTURE_GREEN_SIZE: |
| 650 |
case GL_TEXTURE_BLUE_SIZE: |
| 651 |
case GL_TEXTURE_ALPHA_SIZE: |
| 652 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 653 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 654 |
*params = 8; /* 8-bits */ |
| 655 |
break; |
| 656 |
default: |
| 657 |
gl_error( ctx, GL_INVALID_ENUM, |
| 658 |
"glGetTexLevelParameteriv(pname)" ); |
| 659 |
} |
| 660 |
break; |
| 661 |
case GL_PROXY_TEXTURE_3D_EXT: |
| 662 |
tex = ctx->Texture.Proxy3D->Image[level]; |
| 663 |
switch (pname) { |
| 664 |
case GL_TEXTURE_WIDTH: |
| 665 |
*params = tex->Width; |
| 666 |
break; |
| 667 |
case GL_TEXTURE_HEIGHT: |
| 668 |
*params = tex->Height; |
| 669 |
break; |
| 670 |
case GL_TEXTURE_DEPTH_EXT: |
| 671 |
*params = tex->Depth; |
| 672 |
break; |
| 673 |
case GL_TEXTURE_COMPONENTS: |
| 674 |
*params = tex->Format; |
| 675 |
break; |
| 676 |
case GL_TEXTURE_BORDER: |
| 677 |
*params = tex->Border; |
| 678 |
break; |
| 679 |
case GL_TEXTURE_RED_SIZE: |
| 680 |
case GL_TEXTURE_GREEN_SIZE: |
| 681 |
case GL_TEXTURE_BLUE_SIZE: |
| 682 |
case GL_TEXTURE_ALPHA_SIZE: |
| 683 |
case GL_TEXTURE_INTENSITY_SIZE: |
| 684 |
case GL_TEXTURE_LUMINANCE_SIZE: |
| 685 |
*params = 8; /* 8-bits */ |
| 686 |
break; |
| 687 |
default: |
| 688 |
gl_error( ctx, GL_INVALID_ENUM, |
| 689 |
"glGetTexLevelParameteriv(pname)" ); |
| 690 |
} |
| 691 |
break; |
| 692 |
default: |
| 693 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexLevelParameteriv(target)" ); |
| 694 |
} |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
void gl_GetTexParameterfv( GLcontext *ctx, |
| 701 |
GLenum target, GLenum pname, GLfloat *params ) |
| 702 |
{ |
| 703 |
switch (target) { |
| 704 |
case GL_TEXTURE_1D: |
| 705 |
switch (pname) { |
| 706 |
case GL_TEXTURE_MAG_FILTER: |
| 707 |
*params = (GLfloat) ctx->Texture.Current1D->MagFilter; |
| 708 |
break; |
| 709 |
case GL_TEXTURE_MIN_FILTER: |
| 710 |
*params = (GLfloat) ctx->Texture.Current1D->MinFilter; |
| 711 |
break; |
| 712 |
case GL_TEXTURE_WRAP_S: |
| 713 |
*params = (GLfloat) ctx->Texture.Current1D->WrapS; |
| 714 |
break; |
| 715 |
case GL_TEXTURE_WRAP_T: |
| 716 |
*params = (GLfloat) ctx->Texture.Current1D->WrapT; |
| 717 |
break; |
| 718 |
case GL_TEXTURE_BORDER_COLOR: |
| 719 |
params[0] = ctx->Texture.Current1D->BorderColor[0] / 255.0f; |
| 720 |
params[1] = ctx->Texture.Current1D->BorderColor[1] / 255.0f; |
| 721 |
params[2] = ctx->Texture.Current1D->BorderColor[2] / 255.0f; |
| 722 |
params[3] = ctx->Texture.Current1D->BorderColor[3] / 255.0f; |
| 723 |
break; |
| 724 |
case GL_TEXTURE_RESIDENT: |
| 725 |
*params = (GLfloat) GL_TRUE; |
| 726 |
break; |
| 727 |
case GL_TEXTURE_PRIORITY: |
| 728 |
*params = ctx->Texture.Current1D->Priority; |
| 729 |
break; |
| 730 |
default: |
| 731 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" ); |
| 732 |
} |
| 733 |
break; |
| 734 |
case GL_TEXTURE_2D: |
| 735 |
switch (pname) { |
| 736 |
case GL_TEXTURE_MAG_FILTER: |
| 737 |
*params = (GLfloat) ctx->Texture.Current2D->MagFilter; |
| 738 |
break; |
| 739 |
case GL_TEXTURE_MIN_FILTER: |
| 740 |
*params = (GLfloat) ctx->Texture.Current2D->MinFilter; |
| 741 |
break; |
| 742 |
case GL_TEXTURE_WRAP_S: |
| 743 |
*params = (GLfloat) ctx->Texture.Current2D->WrapS; |
| 744 |
break; |
| 745 |
case GL_TEXTURE_WRAP_T: |
| 746 |
*params = (GLfloat) ctx->Texture.Current2D->WrapT; |
| 747 |
break; |
| 748 |
case GL_TEXTURE_BORDER_COLOR: |
| 749 |
params[0] = ctx->Texture.Current2D->BorderColor[0] / 255.0f; |
| 750 |
params[1] = ctx->Texture.Current2D->BorderColor[1] / 255.0f; |
| 751 |
params[2] = ctx->Texture.Current2D->BorderColor[2] / 255.0f; |
| 752 |
params[3] = ctx->Texture.Current2D->BorderColor[3] / 255.0f; |
| 753 |
break; |
| 754 |
case GL_TEXTURE_RESIDENT: |
| 755 |
*params = (GLfloat) GL_TRUE; |
| 756 |
break; |
| 757 |
case GL_TEXTURE_PRIORITY: |
| 758 |
*params = ctx->Texture.Current2D->Priority; |
| 759 |
break; |
| 760 |
default: |
| 761 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" ); |
| 762 |
} |
| 763 |
break; |
| 764 |
case GL_TEXTURE_3D_EXT: |
| 765 |
switch (pname) { |
| 766 |
case GL_TEXTURE_MAG_FILTER: |
| 767 |
*params = (GLfloat) ctx->Texture.Current3D->MagFilter; |
| 768 |
break; |
| 769 |
case GL_TEXTURE_MIN_FILTER: |
| 770 |
*params = (GLfloat) ctx->Texture.Current3D->MinFilter; |
| 771 |
break; |
| 772 |
case GL_TEXTURE_WRAP_S: |
| 773 |
*params = (GLfloat) ctx->Texture.Current3D->WrapS; |
| 774 |
break; |
| 775 |
case GL_TEXTURE_WRAP_T: |
| 776 |
*params = (GLfloat) ctx->Texture.Current3D->WrapT; |
| 777 |
break; |
| 778 |
case GL_TEXTURE_WRAP_R_EXT: |
| 779 |
*params = (GLfloat) ctx->Texture.Current3D->WrapR; |
| 780 |
break; |
| 781 |
case GL_TEXTURE_BORDER_COLOR: |
| 782 |
params[0] = ctx->Texture.Current3D->BorderColor[0] / 255.0f; |
| 783 |
params[1] = ctx->Texture.Current3D->BorderColor[1] / 255.0f; |
| 784 |
params[2] = ctx->Texture.Current3D->BorderColor[2] / 255.0f; |
| 785 |
params[3] = ctx->Texture.Current3D->BorderColor[3] / 255.0f; |
| 786 |
break; |
| 787 |
case GL_TEXTURE_RESIDENT: |
| 788 |
*params = (GLfloat) GL_TRUE; |
| 789 |
break; |
| 790 |
case GL_TEXTURE_PRIORITY: |
| 791 |
*params = ctx->Texture.Current3D->Priority; |
| 792 |
break; |
| 793 |
default: |
| 794 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" ); |
| 795 |
} |
| 796 |
break; |
| 797 |
default: |
| 798 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)" ); |
| 799 |
} |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
void gl_GetTexParameteriv( GLcontext *ctx, |
| 804 |
GLenum target, GLenum pname, GLint *params ) |
| 805 |
{ |
| 806 |
switch (target) { |
| 807 |
case GL_TEXTURE_1D: |
| 808 |
switch (pname) { |
| 809 |
case GL_TEXTURE_MAG_FILTER: |
| 810 |
*params = (GLint) ctx->Texture.Current1D->MagFilter; |
| 811 |
break; |
| 812 |
case GL_TEXTURE_MIN_FILTER: |
| 813 |
*params = (GLint) ctx->Texture.Current1D->MinFilter; |
| 814 |
break; |
| 815 |
case GL_TEXTURE_WRAP_S: |
| 816 |
*params = (GLint) ctx->Texture.Current1D->WrapS; |
| 817 |
break; |
| 818 |
case GL_TEXTURE_WRAP_T: |
| 819 |
*params = (GLint) ctx->Texture.Current1D->WrapT; |
| 820 |
break; |
| 821 |
case GL_TEXTURE_BORDER_COLOR: |
| 822 |
{ |
| 823 |
GLfloat color[4]; |
| 824 |
color[0] = ctx->Texture.Current1D->BorderColor[0]/255.0; |
| 825 |
color[1] = ctx->Texture.Current1D->BorderColor[1]/255.0; |
| 826 |
color[2] = ctx->Texture.Current1D->BorderColor[2]/255.0; |
| 827 |
color[3] = ctx->Texture.Current1D->BorderColor[3]/255.0; |
| 828 |
params[0] = FLOAT_TO_INT( color[0] ); |
| 829 |
params[1] = FLOAT_TO_INT( color[1] ); |
| 830 |
params[2] = FLOAT_TO_INT( color[2] ); |
| 831 |
params[3] = FLOAT_TO_INT( color[3] ); |
| 832 |
} |
| 833 |
break; |
| 834 |
case GL_TEXTURE_RESIDENT: |
| 835 |
*params = (GLint) GL_TRUE; |
| 836 |
break; |
| 837 |
case GL_TEXTURE_PRIORITY: |
| 838 |
*params = (GLint) ctx->Texture.Current1D->Priority; |
| 839 |
break; |
| 840 |
default: |
| 841 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" ); |
| 842 |
} |
| 843 |
break; |
| 844 |
case GL_TEXTURE_2D: |
| 845 |
switch (pname) { |
| 846 |
case GL_TEXTURE_MAG_FILTER: |
| 847 |
*params = (GLint) ctx->Texture.Current2D->MagFilter; |
| 848 |
break; |
| 849 |
case GL_TEXTURE_MIN_FILTER: |
| 850 |
*params = (GLint) ctx->Texture.Current2D->MinFilter; |
| 851 |
break; |
| 852 |
case GL_TEXTURE_WRAP_S: |
| 853 |
*params = (GLint) ctx->Texture.Current2D->WrapS; |
| 854 |
break; |
| 855 |
case GL_TEXTURE_WRAP_T: |
| 856 |
*params = (GLint) ctx->Texture.Current2D->WrapT; |
| 857 |
break; |
| 858 |
case GL_TEXTURE_BORDER_COLOR: |
| 859 |
{ |
| 860 |
GLfloat color[4]; |
| 861 |
color[0] = ctx->Texture.Current2D->BorderColor[0]/255.0; |
| 862 |
color[1] = ctx->Texture.Current2D->BorderColor[1]/255.0; |
| 863 |
color[2] = ctx->Texture.Current2D->BorderColor[2]/255.0; |
| 864 |
color[3] = ctx->Texture.Current2D->BorderColor[3]/255.0; |
| 865 |
params[0] = FLOAT_TO_INT( color[0] ); |
| 866 |
params[1] = FLOAT_TO_INT( color[1] ); |
| 867 |
params[2] = FLOAT_TO_INT( color[2] ); |
| 868 |
params[3] = FLOAT_TO_INT( color[3] ); |
| 869 |
} |
| 870 |
break; |
| 871 |
case GL_TEXTURE_RESIDENT: |
| 872 |
*params = (GLint) GL_TRUE; |
| 873 |
break; |
| 874 |
case GL_TEXTURE_PRIORITY: |
| 875 |
*params = (GLint) ctx->Texture.Current2D->Priority; |
| 876 |
break; |
| 877 |
default: |
| 878 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" ); |
| 879 |
} |
| 880 |
break; |
| 881 |
case GL_TEXTURE_3D_EXT: |
| 882 |
switch (pname) { |
| 883 |
case GL_TEXTURE_MAG_FILTER: |
| 884 |
*params = (GLint) ctx->Texture.Current3D->MagFilter; |
| 885 |
break; |
| 886 |
case GL_TEXTURE_MIN_FILTER: |
| 887 |
*params = (GLint) ctx->Texture.Current3D->MinFilter; |
| 888 |
break; |
| 889 |
case GL_TEXTURE_WRAP_S: |
| 890 |
*params = (GLint) ctx->Texture.Current3D->WrapS; |
| 891 |
break; |
| 892 |
case GL_TEXTURE_WRAP_T: |
| 893 |
*params = (GLint) ctx->Texture.Current3D->WrapT; |
| 894 |
break; |
| 895 |
case GL_TEXTURE_WRAP_R_EXT: |
| 896 |
*params = (GLint) ctx->Texture.Current3D->WrapR; |
| 897 |
break; |
| 898 |
case GL_TEXTURE_BORDER_COLOR: |
| 899 |
{ |
| 900 |
GLfloat color[4]; |
| 901 |
color[0] = ctx->Texture.Current3D->BorderColor[0]/255.0; |
| 902 |
color[1] = ctx->Texture.Current3D->BorderColor[1]/255.0; |
| 903 |
color[2] = ctx->Texture.Current3D->BorderColor[2]/255.0; |
| 904 |
color[3] = ctx->Texture.Current3D->BorderColor[3]/255.0; |
| 905 |
params[0] = FLOAT_TO_INT( color[0] ); |
| 906 |
params[1] = FLOAT_TO_INT( color[1] ); |
| 907 |
params[2] = FLOAT_TO_INT( color[2] ); |
| 908 |
params[3] = FLOAT_TO_INT( color[3] ); |
| 909 |
} |
| 910 |
break; |
| 911 |
case GL_TEXTURE_RESIDENT: |
| 912 |
*params = (GLint) GL_TRUE; |
| 913 |
break; |
| 914 |
case GL_TEXTURE_PRIORITY: |
| 915 |
*params = (GLint) ctx->Texture.Current3D->Priority; |
| 916 |
break; |
| 917 |
default: |
| 918 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" ); |
| 919 |
} |
| 920 |
break; |
| 921 |
default: |
| 922 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)" ); |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
/**********************************************************************/ |
| 930 |
/* Texture Coord Generation */ |
| 931 |
/**********************************************************************/ |
| 932 |
|
| 933 |
|
| 934 |
void gl_TexGenfv( GLcontext *ctx, |
| 935 |
GLenum coord, GLenum pname, const GLfloat *params ) |
| 936 |
{ |
| 937 |
if (INSIDE_BEGIN_END(ctx)) { |
| 938 |
gl_error( ctx, GL_INVALID_OPERATION, "glTexGenfv" ); |
| 939 |
return; |
| 940 |
} |
| 941 |
|
| 942 |
switch( coord ) { |
| 943 |
case GL_S: |
| 944 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 945 |
GLenum mode = (GLenum) (GLint) *params; |
| 946 |
if (mode==GL_OBJECT_LINEAR || |
| 947 |
mode==GL_EYE_LINEAR || |
| 948 |
mode==GL_SPHERE_MAP) { |
| 949 |
ctx->Texture.GenModeS = mode; |
| 950 |
} |
| 951 |
else { |
| 952 |
gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" ); |
| 953 |
return; |
| 954 |
} |
| 955 |
} |
| 956 |
else if (pname==GL_OBJECT_PLANE) { |
| 957 |
ctx->Texture.ObjectPlaneS[0] = params[0]; |
| 958 |
ctx->Texture.ObjectPlaneS[1] = params[1]; |
| 959 |
ctx->Texture.ObjectPlaneS[2] = params[2]; |
| 960 |
ctx->Texture.ObjectPlaneS[3] = params[3]; |
| 961 |
} |
| 962 |
else if (pname==GL_EYE_PLANE) { |
| 963 |
/* Transform plane equation by the inverse modelview matrix */ |
| 964 |
if (!ctx->ModelViewInvValid) { |
| 965 |
gl_compute_modelview_inverse(ctx); |
| 966 |
} |
| 967 |
gl_transform_vector( ctx->Texture.EyePlaneS, params, |
| 968 |
ctx->ModelViewInv ); |
| 969 |
} |
| 970 |
else { |
| 971 |
gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" ); |
| 972 |
return; |
| 973 |
} |
| 974 |
break; |
| 975 |
case GL_T: |
| 976 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 977 |
GLenum mode = (GLenum) (GLint) *params; |
| 978 |
if (mode==GL_OBJECT_LINEAR || |
| 979 |
mode==GL_EYE_LINEAR || |
| 980 |
mode==GL_SPHERE_MAP) { |
| 981 |
ctx->Texture.GenModeT = mode; |
| 982 |
} |
| 983 |
else { |
| 984 |
gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" ); |
| 985 |
return; |
| 986 |
} |
| 987 |
} |
| 988 |
else if (pname==GL_OBJECT_PLANE) { |
| 989 |
ctx->Texture.ObjectPlaneT[0] = params[0]; |
| 990 |
ctx->Texture.ObjectPlaneT[1] = params[1]; |
| 991 |
ctx->Texture.ObjectPlaneT[2] = params[2]; |
| 992 |
ctx->Texture.ObjectPlaneT[3] = params[3]; |
| 993 |
} |
| 994 |
else if (pname==GL_EYE_PLANE) { |
| 995 |
/* Transform plane equation by the inverse modelview matrix */ |
| 996 |
if (!ctx->ModelViewInvValid) { |
| 997 |
gl_compute_modelview_inverse(ctx); |
| 998 |
} |
| 999 |
gl_transform_vector( ctx->Texture.EyePlaneT, params, |
| 1000 |
ctx->ModelViewInv ); |
| 1001 |
} |
| 1002 |
else { |
| 1003 |
gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" ); |
| 1004 |
return; |
| 1005 |
} |
| 1006 |
break; |
| 1007 |
case GL_R: |
| 1008 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1009 |
GLenum mode = (GLenum) (GLint) *params; |
| 1010 |
if (mode==GL_OBJECT_LINEAR || |
| 1011 |
mode==GL_EYE_LINEAR) { |
| 1012 |
ctx->Texture.GenModeR = mode; |
| 1013 |
} |
| 1014 |
else { |
| 1015 |
gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" ); |
| 1016 |
return; |
| 1017 |
} |
| 1018 |
} |
| 1019 |
else if (pname==GL_OBJECT_PLANE) { |
| 1020 |
ctx->Texture.ObjectPlaneR[0] = params[0]; |
| 1021 |
ctx->Texture.ObjectPlaneR[1] = params[1]; |
| 1022 |
ctx->Texture.ObjectPlaneR[2] = params[2]; |
| 1023 |
ctx->Texture.ObjectPlaneR[3] = params[3]; |
| 1024 |
} |
| 1025 |
else if (pname==GL_EYE_PLANE) { |
| 1026 |
/* Transform plane equation by the inverse modelview matrix */ |
| 1027 |
if (!ctx->ModelViewInvValid) { |
| 1028 |
gl_compute_modelview_inverse(ctx); |
| 1029 |
} |
| 1030 |
gl_transform_vector( ctx->Texture.EyePlaneR, params, |
| 1031 |
ctx->ModelViewInv ); |
| 1032 |
} |
| 1033 |
else { |
| 1034 |
gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" ); |
| 1035 |
return; |
| 1036 |
} |
| 1037 |
break; |
| 1038 |
case GL_Q: |
| 1039 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1040 |
GLenum mode = (GLenum) (GLint) *params; |
| 1041 |
if (mode==GL_OBJECT_LINEAR || |
| 1042 |
mode==GL_EYE_LINEAR) { |
| 1043 |
ctx->Texture.GenModeQ = mode; |
| 1044 |
} |
| 1045 |
else { |
| 1046 |
gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" ); |
| 1047 |
return; |
| 1048 |
} |
| 1049 |
} |
| 1050 |
else if (pname==GL_OBJECT_PLANE) { |
| 1051 |
ctx->Texture.ObjectPlaneQ[0] = params[0]; |
| 1052 |
ctx->Texture.ObjectPlaneQ[1] = params[1]; |
| 1053 |
ctx->Texture.ObjectPlaneQ[2] = params[2]; |
| 1054 |
ctx->Texture.ObjectPlaneQ[3] = params[3]; |
| 1055 |
} |
| 1056 |
else if (pname==GL_EYE_PLANE) { |
| 1057 |
/* Transform plane equation by the inverse modelview matrix */ |
| 1058 |
if (!ctx->ModelViewInvValid) { |
| 1059 |
gl_compute_modelview_inverse(ctx); |
| 1060 |
} |
| 1061 |
gl_transform_vector( ctx->Texture.EyePlaneQ, params, |
| 1062 |
ctx->ModelViewInv ); |
| 1063 |
} |
| 1064 |
else { |
| 1065 |
gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" ); |
| 1066 |
return; |
| 1067 |
} |
| 1068 |
break; |
| 1069 |
default: |
| 1070 |
gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(coord)" ); |
| 1071 |
return; |
| 1072 |
} |
| 1073 |
|
| 1074 |
ctx->NewState |= NEW_TEXTURING; |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
void gl_GetTexGendv( GLcontext *ctx, |
| 1080 |
GLenum coord, GLenum pname, GLdouble *params ) |
| 1081 |
{ |
| 1082 |
if (INSIDE_BEGIN_END(ctx)) { |
| 1083 |
gl_error( ctx, GL_INVALID_OPERATION, "glGetTexGendv" ); |
| 1084 |
return; |
| 1085 |
} |
| 1086 |
|
| 1087 |
switch( coord ) { |
| 1088 |
case GL_S: |
| 1089 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1090 |
params[0] = ctx->Texture.GenModeS; |
| 1091 |
} |
| 1092 |
else if (pname==GL_OBJECT_PLANE) { |
| 1093 |
COPY_4V( params, ctx->Texture.ObjectPlaneS ); |
| 1094 |
} |
| 1095 |
else if (pname==GL_EYE_PLANE) { |
| 1096 |
COPY_4V( params, ctx->Texture.EyePlaneS ); |
| 1097 |
} |
| 1098 |
else { |
| 1099 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" ); |
| 1100 |
return; |
| 1101 |
} |
| 1102 |
break; |
| 1103 |
case GL_T: |
| 1104 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1105 |
params[0] = ctx->Texture.GenModeT; |
| 1106 |
} |
| 1107 |
else if (pname==GL_OBJECT_PLANE) { |
| 1108 |
COPY_4V( params, ctx->Texture.ObjectPlaneT ); |
| 1109 |
} |
| 1110 |
else if (pname==GL_EYE_PLANE) { |
| 1111 |
COPY_4V( params, ctx->Texture.EyePlaneT ); |
| 1112 |
} |
| 1113 |
else { |
| 1114 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" ); |
| 1115 |
return; |
| 1116 |
} |
| 1117 |
break; |
| 1118 |
case GL_R: |
| 1119 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1120 |
params[0] = ctx->Texture.GenModeR; |
| 1121 |
} |
| 1122 |
else if (pname==GL_OBJECT_PLANE) { |
| 1123 |
COPY_4V( params, ctx->Texture.ObjectPlaneR ); |
| 1124 |
} |
| 1125 |
else if (pname==GL_EYE_PLANE) { |
| 1126 |
COPY_4V( params, ctx->Texture.EyePlaneR ); |
| 1127 |
} |
| 1128 |
else { |
| 1129 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" ); |
| 1130 |
return; |
| 1131 |
} |
| 1132 |
break; |
| 1133 |
case GL_Q: |
| 1134 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1135 |
params[0] = ctx->Texture.GenModeQ; |
| 1136 |
} |
| 1137 |
else if (pname==GL_OBJECT_PLANE) { |
| 1138 |
COPY_4V( params, ctx->Texture.ObjectPlaneQ ); |
| 1139 |
} |
| 1140 |
else if (pname==GL_EYE_PLANE) { |
| 1141 |
COPY_4V( params, ctx->Texture.EyePlaneQ ); |
| 1142 |
} |
| 1143 |
else { |
| 1144 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" ); |
| 1145 |
return; |
| 1146 |
} |
| 1147 |
break; |
| 1148 |
default: |
| 1149 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)" ); |
| 1150 |
return; |
| 1151 |
} |
| 1152 |
} |
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
void gl_GetTexGenfv( GLcontext *ctx, |
| 1157 |
GLenum coord, GLenum pname, GLfloat *params ) |
| 1158 |
{ |
| 1159 |
if (INSIDE_BEGIN_END(ctx)) { |
| 1160 |
gl_error( ctx, GL_INVALID_OPERATION, "glGetTexGenfv" ); |
| 1161 |
return; |
| 1162 |
} |
| 1163 |
|
| 1164 |
switch( coord ) { |
| 1165 |
case GL_S: |
| 1166 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1167 |
params[0] = ctx->Texture.GenModeS; |
| 1168 |
} |
| 1169 |
else if (pname==GL_OBJECT_PLANE) { |
| 1170 |
COPY_4V( params, ctx->Texture.ObjectPlaneS ); |
| 1171 |
} |
| 1172 |
else if (pname==GL_EYE_PLANE) { |
| 1173 |
COPY_4V( params, ctx->Texture.EyePlaneS ); |
| 1174 |
} |
| 1175 |
else { |
| 1176 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" ); |
| 1177 |
return; |
| 1178 |
} |
| 1179 |
break; |
| 1180 |
case GL_T: |
| 1181 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1182 |
params[0] = ctx->Texture.GenModeT; |
| 1183 |
} |
| 1184 |
else if (pname==GL_OBJECT_PLANE) { |
| 1185 |
COPY_4V( params, ctx->Texture.ObjectPlaneT ); |
| 1186 |
} |
| 1187 |
else if (pname==GL_EYE_PLANE) { |
| 1188 |
COPY_4V( params, ctx->Texture.EyePlaneT ); |
| 1189 |
} |
| 1190 |
else { |
| 1191 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" ); |
| 1192 |
return; |
| 1193 |
} |
| 1194 |
break; |
| 1195 |
case GL_R: |
| 1196 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1197 |
params[0] = ctx->Texture.GenModeR; |
| 1198 |
} |
| 1199 |
else if (pname==GL_OBJECT_PLANE) { |
| 1200 |
COPY_4V( params, ctx->Texture.ObjectPlaneR ); |
| 1201 |
} |
| 1202 |
else if (pname==GL_EYE_PLANE) { |
| 1203 |
COPY_4V( params, ctx->Texture.EyePlaneR ); |
| 1204 |
} |
| 1205 |
else { |
| 1206 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" ); |
| 1207 |
return; |
| 1208 |
} |
| 1209 |
break; |
| 1210 |
case GL_Q: |
| 1211 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1212 |
params[0] = ctx->Texture.GenModeQ; |
| 1213 |
} |
| 1214 |
else if (pname==GL_OBJECT_PLANE) { |
| 1215 |
COPY_4V( params, ctx->Texture.ObjectPlaneQ ); |
| 1216 |
} |
| 1217 |
else if (pname==GL_EYE_PLANE) { |
| 1218 |
COPY_4V( params, ctx->Texture.EyePlaneQ ); |
| 1219 |
} |
| 1220 |
else { |
| 1221 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" ); |
| 1222 |
return; |
| 1223 |
} |
| 1224 |
break; |
| 1225 |
default: |
| 1226 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)" ); |
| 1227 |
return; |
| 1228 |
} |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
void gl_GetTexGeniv( GLcontext *ctx, |
| 1234 |
GLenum coord, GLenum pname, GLint *params ) |
| 1235 |
{ |
| 1236 |
if (INSIDE_BEGIN_END(ctx)) { |
| 1237 |
gl_error( ctx, GL_INVALID_OPERATION, "glGetTexGeniv" ); |
| 1238 |
return; |
| 1239 |
} |
| 1240 |
|
| 1241 |
switch( coord ) { |
| 1242 |
case GL_S: |
| 1243 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1244 |
params[0] = ctx->Texture.GenModeS; |
| 1245 |
} |
| 1246 |
else if (pname==GL_OBJECT_PLANE) { |
| 1247 |
COPY_4V( params, ctx->Texture.ObjectPlaneS ); |
| 1248 |
} |
| 1249 |
else if (pname==GL_EYE_PLANE) { |
| 1250 |
COPY_4V( params, ctx->Texture.EyePlaneS ); |
| 1251 |
} |
| 1252 |
else { |
| 1253 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" ); |
| 1254 |
return; |
| 1255 |
} |
| 1256 |
break; |
| 1257 |
case GL_T: |
| 1258 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1259 |
params[0] = ctx->Texture.GenModeT; |
| 1260 |
} |
| 1261 |
else if (pname==GL_OBJECT_PLANE) { |
| 1262 |
COPY_4V( params, ctx->Texture.ObjectPlaneT ); |
| 1263 |
} |
| 1264 |
else if (pname==GL_EYE_PLANE) { |
| 1265 |
COPY_4V( params, ctx->Texture.EyePlaneT ); |
| 1266 |
} |
| 1267 |
else { |
| 1268 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" ); |
| 1269 |
return; |
| 1270 |
} |
| 1271 |
break; |
| 1272 |
case GL_R: |
| 1273 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1274 |
params[0] = ctx->Texture.GenModeR; |
| 1275 |
} |
| 1276 |
else if (pname==GL_OBJECT_PLANE) { |
| 1277 |
COPY_4V( params, ctx->Texture.ObjectPlaneR ); |
| 1278 |
} |
| 1279 |
else if (pname==GL_EYE_PLANE) { |
| 1280 |
COPY_4V( params, ctx->Texture.EyePlaneR ); |
| 1281 |
} |
| 1282 |
else { |
| 1283 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" ); |
| 1284 |
return; |
| 1285 |
} |
| 1286 |
break; |
| 1287 |
case GL_Q: |
| 1288 |
if (pname==GL_TEXTURE_GEN_MODE) { |
| 1289 |
params[0] = ctx->Texture.GenModeQ; |
| 1290 |
} |
| 1291 |
else if (pname==GL_OBJECT_PLANE) { |
| 1292 |
COPY_4V( params, ctx->Texture.ObjectPlaneQ ); |
| 1293 |
} |
| 1294 |
else if (pname==GL_EYE_PLANE) { |
| 1295 |
COPY_4V( params, ctx->Texture.EyePlaneQ ); |
| 1296 |
} |
| 1297 |
else { |
| 1298 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" ); |
| 1299 |
return; |
| 1300 |
} |
| 1301 |
break; |
| 1302 |
default: |
| 1303 |
gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)" ); |
| 1304 |
return; |
| 1305 |
} |
| 1306 |
} |
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
/* |
| 1311 |
* Perform automatic texture coordinate generation. |
| 1312 |
* Input: ctx - the context |
| 1313 |
* n - number of texture coordinates to generate |
| 1314 |
* obj - array of vertexes in object coordinate system |
| 1315 |
* eye - array of vertexes in eye coordinate system |
| 1316 |
* normal - array of normal vectores in eye coordinate system |
| 1317 |
* Output: texcoord - array of resuling texture coordinates |
| 1318 |
*/ |
| 1319 |
void gl_texgen( GLcontext *ctx, GLint n, |
| 1320 |
GLfloat obj[][4], GLfloat eye[][4], |
| 1321 |
GLfloat normal[][3], GLfloat texcoord[][4] ) |
| 1322 |
{ |
| 1323 |
/* special case: S and T sphere mapping */ |
| 1324 |
if (ctx->Texture.TexGenEnabled==(S_BIT|T_BIT) |
| 1325 |
&& ctx->Texture.GenModeS==GL_SPHERE_MAP |
| 1326 |
&& ctx->Texture.GenModeT==GL_SPHERE_MAP) { |
| 1327 |
GLint i; |
| 1328 |
for (i=0;i<n;i++) { |
| 1329 |
GLfloat u[3], two_nn, m, fx, fy, fz; |
| 1330 |
COPY_3V( u, eye[i] ); |
| 1331 |
NORMALIZE_3V( u ); |
| 1332 |
two_nn = 2.0F * DOT3(normal[i],normal[i]); |
| 1333 |
fx = u[0] - two_nn * u[0]; |
| 1334 |
fy = u[1] - two_nn * u[1]; |
| 1335 |
fz = u[2] - two_nn * u[2]; |
| 1336 |
m = 2.0F * sqrt( fx*fx + fy*fy + (fz+1.0F)*(fz+1.0F) ); |
| 1337 |
if (m==0.0F) { |
| 1338 |
texcoord[i][0] = 0.5F; |
| 1339 |
texcoord[i][1] = 0.5F; |
| 1340 |
} |
| 1341 |
else { |
| 1342 |
GLfloat mInv = 1.0F / m; |
| 1343 |
texcoord[i][0] = fx * mInv + 0.5F; |
| 1344 |
texcoord[i][1] = fy * mInv + 0.5F; |
| 1345 |
} |
| 1346 |
} |
| 1347 |
return; |
| 1348 |
} |
| 1349 |
|
| 1350 |
/* general solution */ |
| 1351 |
if (ctx->Texture.TexGenEnabled & S_BIT) { |
| 1352 |
GLint i; |
| 1353 |
switch (ctx->Texture.GenModeS) { |
| 1354 |
case GL_OBJECT_LINEAR: |
| 1355 |
for (i=0;i<n;i++) { |
| 1356 |
texcoord[i][0] = DOT4( obj[i], ctx->Texture.ObjectPlaneS ); |
| 1357 |
} |
| 1358 |
break; |
| 1359 |
case GL_EYE_LINEAR: |
| 1360 |
for (i=0;i<n;i++) { |
| 1361 |
texcoord[i][0] = DOT4( eye[i], ctx->Texture.EyePlaneS ); |
| 1362 |
} |
| 1363 |
break; |
| 1364 |
case GL_SPHERE_MAP: |
| 1365 |
for (i=0;i<n;i++) { |
| 1366 |
GLfloat u[3], two_nn, m, fx, fy, fz; |
| 1367 |
COPY_3V( u, eye[i] ); |
| 1368 |
NORMALIZE_3V( u ); |
| 1369 |
two_nn = 2.0*DOT3(normal[i],normal[i]); |
| 1370 |
fx = u[0] - two_nn * u[0]; |
| 1371 |
fy = u[1] - two_nn * u[1]; |
| 1372 |
fz = u[2] - two_nn * u[2]; |
| 1373 |
m = 2.0 * sqrt( fx*fx + fy*fy + (fz+1.0)*(fz+1.0) ); |
| 1374 |
if (m==0.0) { |
| 1375 |
texcoord[i][0] = 0.0; |
| 1376 |
} |
| 1377 |
else { |
| 1378 |
texcoord[i][0] = fx / m + 0.5; |
| 1379 |
} |
| 1380 |
} |
| 1381 |
break; |
| 1382 |
default: |
| 1383 |
abort(); |
| 1384 |
} |
| 1385 |
} |
| 1386 |
|
| 1387 |
if (ctx->Texture.TexGenEnabled & T_BIT) { |
| 1388 |
GLint i; |
| 1389 |
switch (ctx->Texture.GenModeT) { |
| 1390 |
case GL_OBJECT_LINEAR: |
| 1391 |
for (i=0;i<n;i++) { |
| 1392 |
texcoord[i][1] = DOT4( obj[i], ctx->Texture.ObjectPlaneT ); |
| 1393 |
} |
| 1394 |
break; |
| 1395 |
case GL_EYE_LINEAR: |
| 1396 |
for (i=0;i<n;i++) { |
| 1397 |
texcoord[i][1] = DOT4( eye[i], ctx->Texture.EyePlaneT ); |
| 1398 |
} |
| 1399 |
break; |
| 1400 |
case GL_SPHERE_MAP: |
| 1401 |
/* TODO: safe to assume that m and fy valid from above??? */ |
| 1402 |
for (i=0;i<n;i++) { |
| 1403 |
GLfloat u[3], two_nn, m, fx, fy, fz; |
| 1404 |
COPY_3V( u, eye[i] ); |
| 1405 |
NORMALIZE_3V( u ); |
| 1406 |
two_nn = 2.0*DOT3(normal[i],normal[i]); |
| 1407 |
fx = u[0] - two_nn * u[0]; |
| 1408 |
fy = u[1] - two_nn * u[1]; |
| 1409 |
fz = u[2] - two_nn * u[2]; |
| 1410 |
m = 2.0 * sqrt( fx*fx + fy*fy + (fz+1.0)*(fz+1.0) ); |
| 1411 |
if (m==0.0) { |
| 1412 |
texcoord[i][1] = 0.0; |
| 1413 |
} |
| 1414 |
else { |
| 1415 |
texcoord[i][1] = fy / m + 0.5; |
| 1416 |
} |
| 1417 |
} |
| 1418 |
break; |
| 1419 |
default: |
| 1420 |
abort(); |
| 1421 |
} |
| 1422 |
} |
| 1423 |
|
| 1424 |
if (ctx->Texture.TexGenEnabled & R_BIT) { |
| 1425 |
GLint i; |
| 1426 |
switch (ctx->Texture.GenModeR) { |
| 1427 |
case GL_OBJECT_LINEAR: |
| 1428 |
for (i=0;i<n;i++) { |
| 1429 |
texcoord[i][2] = DOT4( obj[i], ctx->Texture.ObjectPlaneR ); |
| 1430 |
} |
| 1431 |
break; |
| 1432 |
case GL_EYE_LINEAR: |
| 1433 |
for (i=0;i<n;i++) { |
| 1434 |
texcoord[i][2] = DOT4( eye[i], ctx->Texture.EyePlaneR ); |
| 1435 |
} |
| 1436 |
break; |
| 1437 |
default: |
| 1438 |
abort(); |
| 1439 |
} |
| 1440 |
} |
| 1441 |
|
| 1442 |
if (ctx->Texture.TexGenEnabled & Q_BIT) { |
| 1443 |
GLint i; |
| 1444 |
switch (ctx->Texture.GenModeQ) { |
| 1445 |
case GL_OBJECT_LINEAR: |
| 1446 |
for (i=0;i<n;i++) { |
| 1447 |
texcoord[i][3] = DOT4( obj[i], ctx->Texture.ObjectPlaneQ ); |
| 1448 |
} |
| 1449 |
break; |
| 1450 |
case GL_EYE_LINEAR: |
| 1451 |
for (i=0;i<n;i++) { |
| 1452 |
texcoord[i][3] = DOT4( eye[i], ctx->Texture.EyePlaneQ ); |
| 1453 |
} |
| 1454 |
break; |
| 1455 |
default: |
| 1456 |
abort(); |
| 1457 |
} |
| 1458 |
} |
| 1459 |
} |
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
/**********************************************************************/ |
| 1466 |
/* 1-D Texture Sampling Functions */ |
| 1467 |
/**********************************************************************/ |
| 1468 |
|
| 1469 |
|
| 1470 |
/* |
| 1471 |
* Return the fractional part of x. |
| 1472 |
*/ |
| 1473 |
#define frac(x) ((GLfloat)(x)-floor((GLfloat)x)) |
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
/* |
| 1478 |
* Given 1-D texture image and an (i) texel column coordinate, return the |
| 1479 |
* texel color. |
| 1480 |
*/ |
| 1481 |
static void get_1d_texel( struct gl_texture_image *img, GLint i, |
| 1482 |
GLubyte *red, GLubyte *green, GLubyte *blue, |
| 1483 |
GLubyte *alpha ) |
| 1484 |
{ |
| 1485 |
GLubyte *texel; |
| 1486 |
|
| 1487 |
/* DEBUG */ |
| 1488 |
GLint width = img->Width; |
| 1489 |
if (i<0 || i>=width) abort(); |
| 1490 |
|
| 1491 |
switch (img->Format) { |
| 1492 |
case GL_ALPHA: |
| 1493 |
*alpha = img->Data[ i ]; |
| 1494 |
return; |
| 1495 |
case GL_LUMINANCE: |
| 1496 |
case GL_INTENSITY: |
| 1497 |
*red = img->Data[ i ]; |
| 1498 |
return; |
| 1499 |
case GL_LUMINANCE_ALPHA: |
| 1500 |
texel = img->Data + i * 2; |
| 1501 |
*red = texel[0]; |
| 1502 |
*alpha = texel[1]; |
| 1503 |
return; |
| 1504 |
case GL_RGB: |
| 1505 |
texel = img->Data + i * 3; |
| 1506 |
*red = texel[0]; |
| 1507 |
*green = texel[1]; |
| 1508 |
*blue = texel[2]; |
| 1509 |
return; |
| 1510 |
case GL_RGBA: |
| 1511 |
texel = img->Data + i * 4; |
| 1512 |
*red = texel[0]; |
| 1513 |
*green = texel[1]; |
| 1514 |
*blue = texel[2]; |
| 1515 |
*alpha = texel[3]; |
| 1516 |
return; |
| 1517 |
default: |
| 1518 |
abort(); |
| 1519 |
} |
| 1520 |
} |
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
/* |
| 1525 |
* Return the texture sample for coordinate (s) using GL_NEAREST filter. |
| 1526 |
*/ |
| 1527 |
static void sample_1d_nearest( GLcontext *ctx, |
| 1528 |
struct gl_texture_image *img, |
| 1529 |
GLfloat s, |
| 1530 |
GLubyte *red, GLubyte *green, |
| 1531 |
GLubyte *blue, GLubyte *alpha ) |
| 1532 |
{ |
| 1533 |
GLint width = img->Width2; /* without border, power of two */ |
| 1534 |
GLint i; |
| 1535 |
GLubyte *texel; |
| 1536 |
|
| 1537 |
/* Clamp/Repeat S and convert to integer texel coordinate */ |
| 1538 |
if (ctx->Texture.Current1D->WrapS==GL_REPEAT) { |
| 1539 |
/* s limited to [0,1) */ |
| 1540 |
/* i limited to [0,width-1] */ |
| 1541 |
i = (GLint) (s * width); |
| 1542 |
i &= (width-1); |
| 1543 |
} |
| 1544 |
else { |
| 1545 |
/* s limited to [0,1] */ |
| 1546 |
/* i limited to [0,width-1] */ |
| 1547 |
if (s<0.0F) i = 0; |
| 1548 |
else if (s>1.0F) i = width-1; |
| 1549 |
else i = (GLint) (s * width); |
| 1550 |
} |
| 1551 |
|
| 1552 |
/* skip over the border, if any */ |
| 1553 |
i += img->Border; |
| 1554 |
|
| 1555 |
/* Get the texel */ |
| 1556 |
switch (img->Format) { |
| 1557 |
case GL_ALPHA: |
| 1558 |
*alpha = img->Data[i]; |
| 1559 |
return; |
| 1560 |
case GL_LUMINANCE: |
| 1561 |
case GL_INTENSITY: |
| 1562 |
*red = img->Data[i]; |
| 1563 |
return; |
| 1564 |
case GL_LUMINANCE_ALPHA: |
| 1565 |
texel = img->Data + i * 2; |
| 1566 |
*red = texel[0]; |
| 1567 |
*alpha = texel[1]; |
| 1568 |
return; |
| 1569 |
case GL_RGB: |
| 1570 |
texel = img->Data + i * 3; |
| 1571 |
*red = texel[0]; |
| 1572 |
*green = texel[1]; |
| 1573 |
*blue = texel[2]; |
| 1574 |
return; |
| 1575 |
case GL_RGBA: |
| 1576 |
texel = img->Data + i * 4; |
| 1577 |
*red = texel[0]; |
| 1578 |
*green = texel[1]; |
| 1579 |
*blue = texel[2]; |
| 1580 |
*alpha = texel[3]; |
| 1581 |
return; |
| 1582 |
default: |
| 1583 |
abort(); |
| 1584 |
} |
| 1585 |
} |
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
/* |
| 1590 |
* Return the texture sample for coordinate (s) using GL_LINEAR filter. |
| 1591 |
*/ |
| 1592 |
static void sample_1d_linear( GLcontext *ctx, |
| 1593 |
struct gl_texture_image *img, |
| 1594 |
GLfloat s, |
| 1595 |
GLubyte *red, GLubyte *green, |
| 1596 |
GLubyte *blue, GLubyte *alpha ) |
| 1597 |
{ |
| 1598 |
GLint width = img->Width2; |
| 1599 |
GLint i0, i1; |
| 1600 |
GLfloat u; |
| 1601 |
GLint i0border, i1border; |
| 1602 |
|
| 1603 |
u = s * width; |
| 1604 |
if (ctx->Texture.Current1D->WrapS==GL_REPEAT) { |
| 1605 |
i0 = ((GLint) floor(u - 0.5F)) % width; |
| 1606 |
i1 = (i0 + 1) & (width-1); |
| 1607 |
i0border = i1border = 0; |
| 1608 |
} |
| 1609 |
else { |
| 1610 |
i0 = (GLint) floor(u - 0.5F); |
| 1611 |
i1 = i0 + 1; |
| 1612 |
i0border = (i0<0) | (i0>=width); |
| 1613 |
i1border = (i1<0) | (i1>=width); |
| 1614 |
} |
| 1615 |
|
| 1616 |
if (img->Border) { |
| 1617 |
i0 += img->Border; |
| 1618 |
i1 += img->Border; |
| 1619 |
i0border = i1border = 0; |
| 1620 |
} |
| 1621 |
else { |
| 1622 |
i0 &= (width-1); |
| 1623 |
} |
| 1624 |
|
| 1625 |
{ |
| 1626 |
GLfloat a = frac(u - 0.5F); |
| 1627 |
|
| 1628 |
GLint w0 = (GLint) ((1.0F-a) * 256.0F); |
| 1629 |
GLint w1 = (GLint) ( a * 256.0F); |
| 1630 |
|
| 1631 |
GLubyte red0, green0, blue0, alpha0; |
| 1632 |
GLubyte red1, green1, blue1, alpha1; |
| 1633 |
|
| 1634 |
if (i0border) { |
| 1635 |
red0 = ctx->Texture.Current1D->BorderColor[0]; |
| 1636 |
green0 = ctx->Texture.Current1D->BorderColor[1]; |
| 1637 |
blue0 = ctx->Texture.Current1D->BorderColor[2]; |
| 1638 |
alpha0 = ctx->Texture.Current1D->BorderColor[3]; |
| 1639 |
} |
| 1640 |
else { |
| 1641 |
get_1d_texel( img, i0, &red0, &green0, &blue0, &alpha0 ); |
| 1642 |
} |
| 1643 |
if (i1border) { |
| 1644 |
red1 = ctx->Texture.Current1D->BorderColor[0]; |
| 1645 |
green1 = ctx->Texture.Current1D->BorderColor[1]; |
| 1646 |
blue1 = ctx->Texture.Current1D->BorderColor[2]; |
| 1647 |
alpha1 = ctx->Texture.Current1D->BorderColor[3]; |
| 1648 |
} |
| 1649 |
else { |
| 1650 |
get_1d_texel( img, i1, &red1, &green1, &blue1, &alpha1 ); |
| 1651 |
} |
| 1652 |
|
| 1653 |
*red = (w0*red0 + w1*red1) >> 8; |
| 1654 |
*green = (w0*green0 + w1*green1) >> 8; |
| 1655 |
*blue = (w0*blue0 + w1*blue1) >> 8; |
| 1656 |
*alpha = (w0*alpha0 + w1*alpha1) >> 8; |
| 1657 |
} |
| 1658 |
} |
| 1659 |
|
| 1660 |
|
| 1661 |
static void sample_1d_nearest_mipmap_nearest( GLcontext *ctx, |
| 1662 |
GLfloat lambda, GLfloat s, |
| 1663 |
GLubyte *red, GLubyte *green, |
| 1664 |
GLubyte *blue, GLubyte *alpha ) |
| 1665 |
{ |
| 1666 |
GLint level; |
| 1667 |
if (lambda<=0.5F) { |
| 1668 |
level = 0; |
| 1669 |
} |
| 1670 |
else { |
| 1671 |
GLint widthlog2 = ctx->Texture.Current1D->Image[0]->WidthLog2; |
| 1672 |
level = (GLint) (lambda + 0.499999F); |
| 1673 |
if (level>widthlog2 ) { |
| 1674 |
level = widthlog2; |
| 1675 |
} |
| 1676 |
} |
| 1677 |
sample_1d_nearest( ctx, ctx->Texture.Current1D->Image[level], |
| 1678 |
s, red, green, blue, alpha ); |
| 1679 |
} |
| 1680 |
|
| 1681 |
|
| 1682 |
static void sample_1d_linear_mipmap_nearest( GLcontext *ctx, |
| 1683 |
GLfloat lambda, GLfloat s, |
| 1684 |
GLubyte *red, GLubyte *green, |
| 1685 |
GLubyte *blue, GLubyte *alpha ) |
| 1686 |
{ |
| 1687 |
GLint level; |
| 1688 |
if (lambda<=0.5F) { |
| 1689 |
level = 0; |
| 1690 |
} |
| 1691 |
else { |
| 1692 |
GLint widthlog2 = ctx->Texture.Current1D->Image[0]->WidthLog2; |
| 1693 |
level = (GLint) (lambda + 0.499999F); |
| 1694 |
if (level>widthlog2 ) { |
| 1695 |
level = widthlog2; |
| 1696 |
} |
| 1697 |
} |
| 1698 |
sample_1d_linear( ctx, ctx->Texture.Current1D->Image[level], |
| 1699 |
s, red, green, blue, alpha ); |
| 1700 |
} |
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
static void sample_1d_nearest_mipmap_linear( GLcontext *ctx, |
| 1705 |
GLfloat lambda, GLfloat s, |
| 1706 |
GLubyte *red, GLubyte *green, |
| 1707 |
GLubyte *blue, GLubyte *alpha ) |
| 1708 |
{ |
| 1709 |
GLint max = ctx->Texture.Current1D->Image[0]->MaxLog2; |
| 1710 |
|
| 1711 |
if (lambda>=max) { |
| 1712 |
sample_1d_nearest( ctx, ctx->Texture.Current1D->Image[max], |
| 1713 |
s, red, green, blue, alpha ); |
| 1714 |
} |
| 1715 |
else { |
| 1716 |
GLubyte red0, green0, blue0, alpha0; |
| 1717 |
GLubyte red1, green1, blue1, alpha1; |
| 1718 |
GLfloat f = frac(lambda); |
| 1719 |
GLint level = (GLint) (lambda + 1.0F); |
| 1720 |
level = CLAMP( level, 1, max ); |
| 1721 |
sample_1d_nearest( ctx, ctx->Texture.Current1D->Image[level-1], |
| 1722 |
s, &red0, &green0, &blue0, &alpha0 ); |
| 1723 |
sample_1d_nearest( ctx, ctx->Texture.Current1D->Image[level], |
| 1724 |
s, &red1, &green1, &blue1, &alpha1 ); |
| 1725 |
*red = (1.0F-f)*red0 + f*red1; |
| 1726 |
*green = (1.0F-f)*green0 + f*green1; |
| 1727 |
*blue = (1.0F-f)*blue0 + f*blue1; |
| 1728 |
*alpha = (1.0F-f)*alpha0 + f*alpha1; |
| 1729 |
} |
| 1730 |
} |
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
static void sample_1d_linear_mipmap_linear( GLcontext *ctx, |
| 1735 |
GLfloat lambda, GLfloat s, |
| 1736 |
GLubyte *red, GLubyte *green, |
| 1737 |
GLubyte *blue, GLubyte *alpha ) |
| 1738 |
{ |
| 1739 |
GLint max = ctx->Texture.Current1D->Image[0]->MaxLog2; |
| 1740 |
|
| 1741 |
if (lambda>=max) { |
| 1742 |
sample_1d_linear( ctx, ctx->Texture.Current1D->Image[max], |
| 1743 |
s, red, green, blue, alpha ); |
| 1744 |
} |
| 1745 |
else { |
| 1746 |
GLubyte red0, green0, blue0, alpha0; |
| 1747 |
GLubyte red1, green1, blue1, alpha1; |
| 1748 |
GLfloat f = frac(lambda); |
| 1749 |
GLint level = (GLint) (lambda + 1.0F); |
| 1750 |
level = CLAMP( level, 1, max ); |
| 1751 |
sample_1d_linear( ctx, ctx->Texture.Current1D->Image[level-1], |
| 1752 |
s, &red0, &green0, &blue0, &alpha0 ); |
| 1753 |
sample_1d_linear( ctx, ctx->Texture.Current1D->Image[level], |
| 1754 |
s, &red1, &green1, &blue1, &alpha1 ); |
| 1755 |
*red = (1.0F-f)*red0 + f*red1; |
| 1756 |
*green = (1.0F-f)*green0 + f*green1; |
| 1757 |
*blue = (1.0F-f)*blue0 + f*blue1; |
| 1758 |
*alpha = (1.0F-f)*alpha0 + f*alpha1; |
| 1759 |
} |
| 1760 |
} |
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
/* |
| 1765 |
* Given an (s) texture coordinate and lambda (level of detail) value, |
| 1766 |
* return a texture sample. |
| 1767 |
* |
| 1768 |
*/ |
| 1769 |
static void sample_1d_texture( GLcontext *ctx, |
| 1770 |
GLfloat s, GLfloat lambda, |
| 1771 |
GLubyte *red, GLubyte *green, GLubyte *blue, |
| 1772 |
GLubyte *alpha, GLfloat c ) |
| 1773 |
{ |
| 1774 |
GLint level; |
| 1775 |
|
| 1776 |
if (lambda>c) { |
| 1777 |
/* minification */ |
| 1778 |
switch (ctx->Texture.Current1D->MinFilter) { |
| 1779 |
case GL_NEAREST: |
| 1780 |
level = 0; |
| 1781 |
sample_1d_nearest( ctx, ctx->Texture.Current1D->Image[level], |
| 1782 |
s, red, green, blue, alpha ); |
| 1783 |
break; |
| 1784 |
case GL_LINEAR: |
| 1785 |
level = 0; |
| 1786 |
sample_1d_linear( ctx, ctx->Texture.Current1D->Image[level], |
| 1787 |
s, red, green, blue, alpha ); |
| 1788 |
break; |
| 1789 |
case GL_NEAREST_MIPMAP_NEAREST: |
| 1790 |
sample_1d_nearest_mipmap_nearest( ctx, lambda, s, |
| 1791 |
red, green, blue, alpha ); |
| 1792 |
break; |
| 1793 |
case GL_LINEAR_MIPMAP_NEAREST: |
| 1794 |
sample_1d_linear_mipmap_nearest( ctx, lambda, s, |
| 1795 |
red, green, blue, alpha ); |
| 1796 |
break; |
| 1797 |
case GL_NEAREST_MIPMAP_LINEAR: |
| 1798 |
sample_1d_nearest_mipmap_linear( ctx, lambda, s, |
| 1799 |
red, green, blue, alpha ); |
| 1800 |
break; |
| 1801 |
case GL_LINEAR_MIPMAP_LINEAR: |
| 1802 |
sample_1d_linear_mipmap_linear( ctx, lambda, s, |
| 1803 |
red, green, blue, alpha ); |
| 1804 |
break; |
| 1805 |
default: |
| 1806 |
abort(); |
| 1807 |
} |
| 1808 |
} |
| 1809 |
else { |
| 1810 |
/* magnification */ |
| 1811 |
switch (ctx->Texture.Current1D->MagFilter) { |
| 1812 |
case GL_NEAREST: |
| 1813 |
sample_1d_nearest( ctx, ctx->Texture.Current1D->Image[0], |
| 1814 |
s, red, green, blue, alpha ); |
| 1815 |
break; |
| 1816 |
case GL_LINEAR: |
| 1817 |
sample_1d_linear( ctx, ctx->Texture.Current1D->Image[0], |
| 1818 |
s, red, green, blue, alpha ); |
| 1819 |
break; |
| 1820 |
default: |
| 1821 |
abort(); |
| 1822 |
} |
| 1823 |
} |
| 1824 |
} |
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
/**********************************************************************/ |
| 1829 |
/* 2-D Texture Sampling Functions */ |
| 1830 |
/**********************************************************************/ |
| 1831 |
|
| 1832 |
|
| 1833 |
/* |
| 1834 |
* Given a texture image and an (i,j) integer texel coordinate, return the |
| 1835 |
* texel color. |
| 1836 |
*/ |
| 1837 |
static void get_2d_texel( struct gl_texture_image *img, GLint i, GLint j, |
| 1838 |
GLubyte *red, GLubyte *green, GLubyte *blue, |
| 1839 |
GLubyte *alpha ) |
| 1840 |
{ |
| 1841 |
GLint width = img->Width; /* includes border */ |
| 1842 |
GLubyte *texel; |
| 1843 |
|
| 1844 |
#ifdef DEBUG |
| 1845 |
GLint height = img->Height; /* includes border */ |
| 1846 |
if (i<0 || i>=width) abort(); |
| 1847 |
if (j<0 || j>=height) abort(); |
| 1848 |
#endif |
| 1849 |
|
| 1850 |
switch (img->Format) { |
| 1851 |
case GL_ALPHA: |
| 1852 |
*alpha = img->Data[ width * j + i ]; |
| 1853 |
return; |
| 1854 |
case GL_LUMINANCE: |
| 1855 |
case GL_INTENSITY: |
| 1856 |
*red = img->Data[ width * j + i ]; |
| 1857 |
return; |
| 1858 |
case GL_LUMINANCE_ALPHA: |
| 1859 |
texel = img->Data + (width * j + i) * 2; |
| 1860 |
*red = texel[0]; |
| 1861 |
*alpha = texel[1]; |
| 1862 |
return; |
| 1863 |
case GL_RGB: |
| 1864 |
texel = img->Data + (width * j + i) * 3; |
| 1865 |
*red = texel[0]; |
| 1866 |
*green = texel[1]; |
| 1867 |
*blue = texel[2]; |
| 1868 |
return; |
| 1869 |
case GL_RGBA: |
| 1870 |
texel = img->Data + (width * j + i) * 4; |
| 1871 |
*red = texel[0]; |
| 1872 |
*green = texel[1]; |
| 1873 |
*blue = texel[2]; |
| 1874 |
*alpha = texel[3]; |
| 1875 |
return; |
| 1876 |
default: |
| 1877 |
abort(); |
| 1878 |
} |
| 1879 |
} |
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
/* |
| 1884 |
* Return the texture sample for coordinate (s,t) using GL_NEAREST filter. |
| 1885 |
*/ |
| 1886 |
static void sample_2d_nearest( GLcontext *ctx, |
| 1887 |
struct gl_texture_image *img, |
| 1888 |
GLfloat s, GLfloat t, |
| 1889 |
GLubyte *red, GLubyte *green, |
| 1890 |
GLubyte *blue, GLubyte *alpha ) |
| 1891 |
{ |
| 1892 |
GLint imgWidth = img->Width; /* includes border */ |
| 1893 |
GLint width = img->Width2; /* without border, power of two */ |
| 1894 |
GLint height = img->Height2; /* without border, power of two */ |
| 1895 |
GLint i, j; |
| 1896 |
GLubyte *texel; |
| 1897 |
|
| 1898 |
/* Clamp/Repeat S and convert to integer texel coordinate */ |
| 1899 |
if (ctx->Texture.Current2D->WrapS==GL_REPEAT) { |
| 1900 |
/* s limited to [0,1) */ |
| 1901 |
/* i limited to [0,width-1] */ |
| 1902 |
i = (GLint) (s * width); |
| 1903 |
i &= (width-1); |
| 1904 |
} |
| 1905 |
else { |
| 1906 |
/* s limited to [0,1] */ |
| 1907 |
/* i limited to [0,width-1] */ |
| 1908 |
if (s<=0.0F) i = 0; |
| 1909 |
else if (s>1.0F) i = width-1; |
| 1910 |
else i = (GLint) (s * width); |
| 1911 |
} |
| 1912 |
|
| 1913 |
/* Clamp/Repeat T and convert to integer texel coordinate */ |
| 1914 |
if (ctx->Texture.Current2D->WrapT==GL_REPEAT) { |
| 1915 |
/* t limited to [0,1) */ |
| 1916 |
/* j limited to [0,height-1] */ |
| 1917 |
j = (GLint) (t * height); |
| 1918 |
j &= (height-1); |
| 1919 |
} |
| 1920 |
else { |
| 1921 |
/* t limited to [0,1] */ |
| 1922 |
/* j limited to [0,height-1] */ |
| 1923 |
if (t<=0.0F) j = 0; |
| 1924 |
else if (t>1.0F) j = height-1; |
| 1925 |
else j = (GLint) (t * height); |
| 1926 |
} |
| 1927 |
|
| 1928 |
/* skip over the border, if any */ |
| 1929 |
i += img->Border; |
| 1930 |
j += img->Border; |
| 1931 |
|
| 1932 |
switch (img->Format) { |
| 1933 |
case GL_ALPHA: |
| 1934 |
*alpha = img->Data[ j * imgWidth + i ]; |
| 1935 |
return; |
| 1936 |
case GL_LUMINANCE: |
| 1937 |
case GL_INTENSITY: |
| 1938 |
*red = img->Data[ j * imgWidth + i ]; |
| 1939 |
return; |
| 1940 |
case GL_LUMINANCE_ALPHA: |
| 1941 |
texel = img->Data + ((j * imgWidth + i) << 1); |
| 1942 |
*red = texel[0]; |
| 1943 |
*alpha = texel[1]; |
| 1944 |
return; |
| 1945 |
case GL_RGB: |
| 1946 |
texel = img->Data + (j * imgWidth + i) * 3; |
| 1947 |
*red = texel[0]; |
| 1948 |
*green = texel[1]; |
| 1949 |
*blue = texel[2]; |
| 1950 |
return; |
| 1951 |
case GL_RGBA: |
| 1952 |
texel = img->Data + ((j * imgWidth + i) << 2); |
| 1953 |
*red = texel[0]; |
| 1954 |
*green = texel[1]; |
| 1955 |
*blue = texel[2]; |
| 1956 |
*alpha = texel[3]; |
| 1957 |
return; |
| 1958 |
default: |
| 1959 |
abort(); |
| 1960 |
} |
| 1961 |
} |
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
/* |
| 1966 |
* Return the texture sample for coordinate (s,t) using GL_LINEAR filter. |
| 1967 |
*/ |
| 1968 |
static void sample_2d_linear( GLcontext *ctx, |
| 1969 |
struct gl_texture_image *img, |
| 1970 |
GLfloat s, GLfloat t, |
| 1971 |
GLubyte *red, GLubyte *green, |
| 1972 |
GLubyte *blue, GLubyte *alpha ) |
| 1973 |
{ |
| 1974 |
GLint width = img->Width2; |
| 1975 |
GLint height = img->Height2; |
| 1976 |
GLint i0, j0, i1, j1; |
| 1977 |
GLint i0border, j0border, i1border, j1border; |
| 1978 |
GLfloat u, v; |
| 1979 |
|
| 1980 |
u = s * width; |
| 1981 |
if (ctx->Texture.Current2D->WrapS==GL_REPEAT) { |
| 1982 |
i0 = ((GLint) floor(u - 0.5F)) % width; |
| 1983 |
i1 = (i0 + 1) & (width-1); |
| 1984 |
i0border = i1border = 0; |
| 1985 |
} |
| 1986 |
else { |
| 1987 |
i0 = (GLint) floor(u - 0.5F); |
| 1988 |
i1 = i0 + 1; |
| 1989 |
i0border = (i0<0) | (i0>=width); |
| 1990 |
i1border = (i1<0) | (i1>=width); |
| 1991 |
} |
| 1992 |
|
| 1993 |
v = t * height; |
| 1994 |
if (ctx->Texture.Current2D->WrapT==GL_REPEAT) { |
| 1995 |
j0 = ((GLint) floor(v - 0.5F)) % height; |
| 1996 |
j1 = (j0 + 1) & (height-1); |
| 1997 |
j0border = j1border = 0; |
| 1998 |
} |
| 1999 |
else { |
| 2000 |
j0 = (GLint) floor(v - 0.5F ); |
| 2001 |
j1 = j0 + 1; |
| 2002 |
j0border = (j0<0) | (j0>=height); |
| 2003 |
j1border = (j1<0) | (j1>=height); |
| 2004 |
} |
| 2005 |
|
| 2006 |
if (img->Border) { |
| 2007 |
i0 += img->Border; |
| 2008 |
i1 += img->Border; |
| 2009 |
j0 += img->Border; |
| 2010 |
j1 += img->Border; |
| 2011 |
i0border = i1border = 0; |
| 2012 |
j0border = j1border = 0; |
| 2013 |
} |
| 2014 |
else { |
| 2015 |
i0 &= (width-1); |
| 2016 |
j0 &= (height-1); |
| 2017 |
} |
| 2018 |
|
| 2019 |
{ |
| 2020 |
GLfloat a = frac(u - 0.5F); |
| 2021 |
GLfloat b = frac(v - 0.5F); |
| 2022 |
|
| 2023 |
GLint w00 = (GLint) ((1.0F-a)*(1.0F-b) * 256.0F); |
| 2024 |
GLint w10 = (GLint) ( a *(1.0F-b) * 256.0F); |
| 2025 |
GLint w01 = (GLint) ((1.0F-a)* b * 256.0F); |
| 2026 |
GLint w11 = (GLint) ( a * b * 256.0F); |
| 2027 |
|
| 2028 |
GLubyte red00, green00, blue00, alpha00; |
| 2029 |
GLubyte red10, green10, blue10, alpha10; |
| 2030 |
GLubyte red01, green01, blue01, alpha01; |
| 2031 |
GLubyte red11, green11, blue11, alpha11; |
| 2032 |
|
| 2033 |
if (i0border | j0border) { |
| 2034 |
red00 = ctx->Texture.Current2D->BorderColor[0]; |
| 2035 |
green00 = ctx->Texture.Current2D->BorderColor[1]; |
| 2036 |
blue00 = ctx->Texture.Current2D->BorderColor[2]; |
| 2037 |
alpha00 = ctx->Texture.Current2D->BorderColor[3]; |
| 2038 |
} |
| 2039 |
else { |
| 2040 |
get_2d_texel( img, i0, j0, &red00, &green00, &blue00, &alpha00 ); |
| 2041 |
} |
| 2042 |
if (i1border | j0border) { |
| 2043 |
red10 = ctx->Texture.Current2D->BorderColor[0]; |
| 2044 |
green10 = ctx->Texture.Current2D->BorderColor[1]; |
| 2045 |
blue10 = ctx->Texture.Current2D->BorderColor[2]; |
| 2046 |
alpha10 = ctx->Texture.Current2D->BorderColor[3]; |
| 2047 |
} |
| 2048 |
else { |
| 2049 |
get_2d_texel( img, i1, j0, &red10, &green10, &blue10, &alpha10 ); |
| 2050 |
} |
| 2051 |
if (i0border | j1border) { |
| 2052 |
red01 = ctx->Texture.Current2D->BorderColor[0]; |
| 2053 |
green01 = ctx->Texture.Current2D->BorderColor[1]; |
| 2054 |
blue01 = ctx->Texture.Current2D->BorderColor[2]; |
| 2055 |
alpha01 = ctx->Texture.Current2D->BorderColor[3]; |
| 2056 |
} |
| 2057 |
else { |
| 2058 |
get_2d_texel( img, i0, j1, &red01, &green01, &blue01, &alpha01 ); |
| 2059 |
} |
| 2060 |
if (i1border | j1border) { |
| 2061 |
red11 = ctx->Texture.Current2D->BorderColor[0]; |
| 2062 |
green11 = ctx->Texture.Current2D->BorderColor[1]; |
| 2063 |
blue11 = ctx->Texture.Current2D->BorderColor[2]; |
| 2064 |
alpha11 = ctx->Texture.Current2D->BorderColor[3]; |
| 2065 |
} |
| 2066 |
else { |
| 2067 |
get_2d_texel( img, i1, j1, &red11, &green11, &blue11, &alpha11 ); |
| 2068 |
} |
| 2069 |
|
| 2070 |
*red = (w00*red00 + w10*red10 + w01*red01 + w11*red11 ) >> 8; |
| 2071 |
*green = (w00*green00 + w10*green10 + w01*green01 + w11*green11) >> 8; |
| 2072 |
*blue = (w00*blue00 + w10*blue10 + w01*blue01 + w11*blue11 ) >> 8; |
| 2073 |
*alpha = (w00*alpha00 + w10*alpha10 + w01*alpha01 + w11*alpha11) >> 8; |
| 2074 |
} |
| 2075 |
} |
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
static void sample_2d_nearest_mipmap_nearest( GLcontext *ctx, |
| 2080 |
GLfloat lambda, |
| 2081 |
GLfloat s, GLfloat t, |
| 2082 |
GLubyte *red, GLubyte *green, |
| 2083 |
GLubyte *blue, GLubyte *alpha ) |
| 2084 |
{ |
| 2085 |
GLint level; |
| 2086 |
if (lambda<=0.5F) { |
| 2087 |
level = 0; |
| 2088 |
} |
| 2089 |
else { |
| 2090 |
GLint max = ctx->Texture.Current2D->Image[0]->MaxLog2; |
| 2091 |
level = (GLint) (lambda + 0.499999F); |
| 2092 |
if (level>max) { |
| 2093 |
level = max; |
| 2094 |
} |
| 2095 |
} |
| 2096 |
sample_2d_nearest( ctx, ctx->Texture.Current2D->Image[level], |
| 2097 |
s, t, red, green, blue, alpha ); |
| 2098 |
} |
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
static void sample_2d_linear_mipmap_nearest( GLcontext *ctx, |
| 2103 |
GLfloat lambda, |
| 2104 |
GLfloat s, GLfloat t, |
| 2105 |
GLubyte *red, GLubyte *green, |
| 2106 |
GLubyte *blue, GLubyte *alpha ) |
| 2107 |
{ |
| 2108 |
GLint level; |
| 2109 |
if (lambda<=0.5F) { |
| 2110 |
level = 0; |
| 2111 |
} |
| 2112 |
else { |
| 2113 |
GLint max = ctx->Texture.Current2D->Image[0]->MaxLog2; |
| 2114 |
level = (GLint) (lambda + 0.499999F); |
| 2115 |
if (level>max) { |
| 2116 |
level = max; |
| 2117 |
} |
| 2118 |
} |
| 2119 |
sample_2d_linear( ctx, ctx->Texture.Current2D->Image[level], |
| 2120 |
s, t, red, green, blue, alpha ); |
| 2121 |
} |
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
static void sample_2d_nearest_mipmap_linear( GLcontext *ctx, |
| 2126 |
GLfloat lambda, |
| 2127 |
GLfloat s, GLfloat t, |
| 2128 |
GLubyte *red, GLubyte *green, |
| 2129 |
GLubyte *blue, GLubyte *alpha ) |
| 2130 |
{ |
| 2131 |
GLint max = ctx->Texture.Current2D->Image[0]->MaxLog2; |
| 2132 |
|
| 2133 |
if (lambda>=max) { |
| 2134 |
sample_2d_nearest( ctx, ctx->Texture.Current2D->Image[max], |
| 2135 |
s, t, red, green, blue, alpha ); |
| 2136 |
} |
| 2137 |
else { |
| 2138 |
GLubyte red0, green0, blue0, alpha0; |
| 2139 |
GLubyte red1, green1, blue1, alpha1; |
| 2140 |
GLfloat f = frac(lambda); |
| 2141 |
GLint level = (GLint) (lambda + 1.0F); |
| 2142 |
level = CLAMP( level, 1, max ); |
| 2143 |
sample_2d_nearest( ctx, ctx->Texture.Current2D->Image[level-1], s, t, |
| 2144 |
&red0, &green0, &blue0, &alpha0 ); |
| 2145 |
sample_2d_nearest( ctx, ctx->Texture.Current2D->Image[level], s, t, |
| 2146 |
&red1, &green1, &blue1, &alpha1 ); |
| 2147 |
*red = (1.0F-f)*red0 + f*red1; |
| 2148 |
*green = (1.0F-f)*green0 + f*green1; |
| 2149 |
*blue = (1.0F-f)*blue0 + f*blue1; |
| 2150 |
*alpha = (1.0F-f)*alpha0 + f*alpha1; |
| 2151 |
} |
| 2152 |
} |
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
static void sample_2d_linear_mipmap_linear( GLcontext *ctx, |
| 2157 |
GLfloat lambda, |
| 2158 |
GLfloat s, GLfloat t, |
| 2159 |
GLubyte *red, GLubyte *green, |
| 2160 |
GLubyte *blue, GLubyte *alpha ) |
| 2161 |
{ |
| 2162 |
GLint max = ctx->Texture.Current2D->Image[0]->MaxLog2; |
| 2163 |
|
| 2164 |
if (lambda>=max) { |
| 2165 |
sample_2d_linear( ctx, ctx->Texture.Current2D->Image[max], |
| 2166 |
s, t, red, green, blue, alpha ); |
| 2167 |
} |
| 2168 |
else { |
| 2169 |
GLubyte red0, green0, blue0, alpha0; |
| 2170 |
GLubyte red1, green1, blue1, alpha1; |
| 2171 |
GLfloat f = frac(lambda); |
| 2172 |
GLint level = (GLint) (lambda + 1.0F); |
| 2173 |
level = CLAMP( level, 1, max ); |
| 2174 |
sample_2d_linear( ctx, ctx->Texture.Current2D->Image[level-1], s, t, |
| 2175 |
&red0, &green0, &blue0, &alpha0 ); |
| 2176 |
sample_2d_linear( ctx, ctx->Texture.Current2D->Image[level], s, t, |
| 2177 |
&red1, &green1, &blue1, &alpha1 ); |
| 2178 |
*red = (1.0F-f)*red0 + f*red1; |
| 2179 |
*green = (1.0F-f)*green0 + f*green1; |
| 2180 |
*blue = (1.0F-f)*blue0 + f*blue1; |
| 2181 |
*alpha = (1.0F-f)*alpha0 + f*alpha1; |
| 2182 |
} |
| 2183 |
} |
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
/* |
| 2189 |
* Given an (s,t) texture coordinate and lambda (level of detail) value, |
| 2190 |
* return a texture sample. |
| 2191 |
*/ |
| 2192 |
static void sample_2d_texture( GLcontext *ctx, |
| 2193 |
GLfloat s, GLfloat t, GLfloat lambda, |
| 2194 |
GLubyte *red, GLubyte *green, GLubyte *blue, |
| 2195 |
GLubyte *alpha, GLfloat c ) |
| 2196 |
{ |
| 2197 |
if (lambda>c) { |
| 2198 |
/* minification */ |
| 2199 |
switch (ctx->Texture.Current2D->MinFilter) { |
| 2200 |
case GL_NEAREST: |
| 2201 |
sample_2d_nearest( ctx, ctx->Texture.Current2D->Image[0], |
| 2202 |
s, t, red, green, blue, alpha ); |
| 2203 |
break; |
| 2204 |
case GL_LINEAR: |
| 2205 |
sample_2d_linear( ctx, ctx->Texture.Current2D->Image[0], |
| 2206 |
s, t, red, green, blue, alpha ); |
| 2207 |
break; |
| 2208 |
case GL_NEAREST_MIPMAP_NEAREST: |
| 2209 |
sample_2d_nearest_mipmap_nearest( ctx, lambda, s, t, |
| 2210 |
red, green, blue, alpha ); |
| 2211 |
break; |
| 2212 |
case GL_LINEAR_MIPMAP_NEAREST: |
| 2213 |
sample_2d_linear_mipmap_nearest( ctx, lambda, s, t, |
| 2214 |
red, green, blue, alpha ); |
| 2215 |
break; |
| 2216 |
case GL_NEAREST_MIPMAP_LINEAR: |
| 2217 |
sample_2d_nearest_mipmap_linear( ctx, lambda, s, t, |
| 2218 |
red, green, blue, alpha ); |
| 2219 |
break; |
| 2220 |
case GL_LINEAR_MIPMAP_LINEAR: |
| 2221 |
sample_2d_linear_mipmap_linear( ctx, lambda, s, t, |
| 2222 |
red, green, blue, alpha ); |
| 2223 |
break; |
| 2224 |
default: |
| 2225 |
abort(); |
| 2226 |
} |
| 2227 |
} |
| 2228 |
else { |
| 2229 |
/* magnification */ |
| 2230 |
switch (ctx->Texture.Current2D->MagFilter) { |
| 2231 |
case GL_NEAREST: |
| 2232 |
sample_2d_nearest( ctx, ctx->Texture.Current2D->Image[0], |
| 2233 |
s, t, red, green, blue, alpha ); |
| 2234 |
break; |
| 2235 |
case GL_LINEAR: |
| 2236 |
sample_2d_linear( ctx, ctx->Texture.Current2D->Image[0], |
| 2237 |
s, t, red, green, blue, alpha ); |
| 2238 |
break; |
| 2239 |
default: |
| 2240 |
abort(); |
| 2241 |
} |
| 2242 |
} |
| 2243 |
} |
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
/**********************************************************************/ |
| 2248 |
/* 3-D Texture Sampling Functions */ |
| 2249 |
/**********************************************************************/ |
| 2250 |
|
| 2251 |
/* |
| 2252 |
* Given a texture image and an (i,j,k) integer texel coordinate, return the |
| 2253 |
* texel color. |
| 2254 |
*/ |
| 2255 |
static void get_3d_texel( struct gl_texture_image *img, |
| 2256 |
GLint i, GLint j, GLint k, |
| 2257 |
GLubyte *red, GLubyte *green, GLubyte *blue, |
| 2258 |
GLubyte *alpha ) |
| 2259 |
{ |
| 2260 |
GLint width = img->Width; /* includes border */ |
| 2261 |
GLint height = img->Height; /* includes border */ |
| 2262 |
GLint depth = img->Depth; /* includes border */ |
| 2263 |
GLint rectarea; /* = width * heigth */ |
| 2264 |
GLubyte *texel; |
| 2265 |
|
| 2266 |
rectarea = width*height; |
| 2267 |
|
| 2268 |
#ifdef DEBUG |
| 2269 |
if (i<0 || i>=width) abort(); |
| 2270 |
if (j<0 || j>=height) abort(); |
| 2271 |
if (k<0 || k>=depth) abort(); |
| 2272 |
#endif |
| 2273 |
|
| 2274 |
switch (img->Format) { |
| 2275 |
case GL_ALPHA: |
| 2276 |
*alpha = img->Data[ rectarea * k + width * j + i ]; |
| 2277 |
return; |
| 2278 |
case GL_LUMINANCE: |
| 2279 |
case GL_INTENSITY: |
| 2280 |
*red = img->Data[ rectarea * k + width * j + i ]; |
| 2281 |
return; |
| 2282 |
case GL_LUMINANCE_ALPHA: |
| 2283 |
texel = img->Data + ( rectarea * k + width * j + i) * 2; |
| 2284 |
*red = texel[0]; |
| 2285 |
*alpha = texel[1]; |
| 2286 |
return; |
| 2287 |
case GL_RGB: |
| 2288 |
texel = img->Data + (rectarea * k + width * j + i) * 3; |
| 2289 |
*red = texel[0]; |
| 2290 |
*green = texel[1]; |
| 2291 |
*blue = texel[2]; |
| 2292 |
return; |
| 2293 |
case GL_RGBA: |
| 2294 |
texel = img->Data + (rectarea * k + width * j + i) * 4; |
| 2295 |
*red = texel[0]; |
| 2296 |
*green = texel[1]; |
| 2297 |
*blue = texel[2]; |
| 2298 |
*alpha = texel[3]; |
| 2299 |
return; |
| 2300 |
default: |
| 2301 |
abort(); |
| 2302 |
} |
| 2303 |
} |
| 2304 |
|
| 2305 |
|
| 2306 |
/* |
| 2307 |
* Return the texture sample for coordinate (s,t,r) using GL_NEAREST filter. |
| 2308 |
*/ |
| 2309 |
static void sample_3d_nearest( GLcontext *ctx, |
| 2310 |
struct gl_texture_image *img, |
| 2311 |
GLfloat s, GLfloat t, GLfloat r, |
| 2312 |
GLubyte *red, GLubyte *green, |
| 2313 |
GLubyte *blue, GLubyte *alpha ) |
| 2314 |
{ |
| 2315 |
GLint imgWidth = img->Width; /* includes border, if any */ |
| 2316 |
GLint imgHeight = img->Height; /* includes border, if any */ |
| 2317 |
GLint width = img->Width2; /* without border, power of two */ |
| 2318 |
GLint height = img->Height2; /* without border, power of two */ |
| 2319 |
GLint depth = img->Depth2; /* without border, power of two */ |
| 2320 |
GLint rectarea; /* = width * height */ |
| 2321 |
GLint i, j, k; |
| 2322 |
GLubyte *texel; |
| 2323 |
|
| 2324 |
rectarea = imgWidth * imgHeight; |
| 2325 |
|
| 2326 |
/* Clamp/Repeat S and convert to integer texel coordinate */ |
| 2327 |
if (ctx->Texture.Current3D->WrapS==GL_REPEAT) { |
| 2328 |
/* s limited to [0,1) */ |
| 2329 |
/* i limited to [0,width-1] */ |
| 2330 |
i = (GLint) (s * width); |
| 2331 |
i &= (width-1); |
| 2332 |
} |
| 2333 |
else { |
| 2334 |
/* s limited to [0,1] */ |
| 2335 |
/* i limited to [0,width-1] */ |
| 2336 |
if (s<0.0F) i = 0; |
| 2337 |
else if (s>1.0F) i = width-1; |
| 2338 |
else i = (GLint) (s * width); |
| 2339 |
} |
| 2340 |
|
| 2341 |
/* Clamp/Repeat T and convert to integer texel coordinate */ |
| 2342 |
if (ctx->Texture.Current3D->WrapT==GL_REPEAT) { |
| 2343 |
/* t limited to [0,1) */ |
| 2344 |
/* j limited to [0,height-1] */ |
| 2345 |
j = (GLint) (t * height); |
| 2346 |
j &= (height-1); |
| 2347 |
} |
| 2348 |
else { |
| 2349 |
/* t limited to [0,1] */ |
| 2350 |
/* j limited to [0,height-1] */ |
| 2351 |
if (t<0.0F) j = 0; |
| 2352 |
else if (t>1.0F) j = height-1; |
| 2353 |
else j = (GLint) (t * height); |
| 2354 |
} |
| 2355 |
|
| 2356 |
/* Clamp/Repeat R and convert to integer texel coordinate */ |
| 2357 |
if (ctx->Texture.Current3D->WrapR==GL_REPEAT) { |
| 2358 |
/* r limited to [0,1) */ |
| 2359 |
/* k limited to [0,depth-1] */ |
| 2360 |
k = (GLint) (r * depth); |
| 2361 |
k &= (depth-1); |
| 2362 |
} |
| 2363 |
else { |
| 2364 |
/* r limited to [0,1] */ |
| 2365 |
/* k limited to [0,depth-1] */ |
| 2366 |
if (r<0.0F) k = 0; |
| 2367 |
else if (r>1.0F) k = depth-1; |
| 2368 |
else k = (GLint) (r * depth); |
| 2369 |
} |
| 2370 |
|
| 2371 |
switch (img->Format) { |
| 2372 |
case GL_ALPHA: |
| 2373 |
*alpha = img->Data[ rectarea * k + j * imgWidth + i ]; |
| 2374 |
return; |
| 2375 |
case GL_LUMINANCE: |
| 2376 |
case GL_INTENSITY: |
| 2377 |
*red = img->Data[ rectarea * k + j * imgWidth + i ]; |
| 2378 |
return; |
| 2379 |
case GL_LUMINANCE_ALPHA: |
| 2380 |
texel = img->Data + ((rectarea * k + j * imgWidth + i) << 1); |
| 2381 |
*red = texel[0]; |
| 2382 |
*alpha = texel[1]; |
| 2383 |
return; |
| 2384 |
case GL_RGB: |
| 2385 |
texel = img->Data + ( rectarea * k + j * imgWidth + i) * 3; |
| 2386 |
*red = texel[0]; |
| 2387 |
*green = texel[1]; |
| 2388 |
*blue = texel[2]; |
| 2389 |
return; |
| 2390 |
case GL_RGBA: |
| 2391 |
texel = img->Data + ((rectarea * k + j * imgWidth + i) << 2); |
| 2392 |
*red = texel[0]; |
| 2393 |
*green = texel[1]; |
| 2394 |
*blue = texel[2]; |
| 2395 |
*alpha = texel[3]; |
| 2396 |
return; |
| 2397 |
default: |
| 2398 |
abort(); |
| 2399 |
} |
| 2400 |
} |
| 2401 |
|
| 2402 |
|
| 2403 |
/* |
| 2404 |
* Return the texture sample for coordinate (s,t,r) using GL_LINEAR filter. |
| 2405 |
*/ |
| 2406 |
static void sample_3d_linear( GLcontext *ctx, |
| 2407 |
struct gl_texture_image *img, |
| 2408 |
GLfloat s, GLfloat t, GLfloat r, |
| 2409 |
GLubyte *red, GLubyte *green, |
| 2410 |
GLubyte *blue, GLubyte *alpha ) |
| 2411 |
{ |
| 2412 |
GLint width = img->Width2; |
| 2413 |
GLint height = img->Height2; |
| 2414 |
GLint depth = img->Depth2; |
| 2415 |
GLint i0, j0, k0, i1, j1, k1; |
| 2416 |
GLint i0border, j0border, k0border, i1border, j1border, k1border; |
| 2417 |
GLfloat u, v, w; |
| 2418 |
|
| 2419 |
u = s * width; |
| 2420 |
if (ctx->Texture.Current3D->WrapS==GL_REPEAT) { |
| 2421 |
i0 = ((GLint) floor(u - 0.5F)) % width; |
| 2422 |
i1 = (i0 + 1) & (width-1); |
| 2423 |
i0border = i1border = 0; |
| 2424 |
} |
| 2425 |
else { |
| 2426 |
i0 = (GLint) floor(u - 0.5F); |
| 2427 |
i1 = i0 + 1; |
| 2428 |
i0border = (i0<0) | (i0>=width); |
| 2429 |
i1border = (i1<0) | (i1>=width); |
| 2430 |
} |
| 2431 |
|
| 2432 |
v = t * height; |
| 2433 |
if (ctx->Texture.Current3D->WrapT==GL_REPEAT) { |
| 2434 |
j0 = ((GLint) floor(v - 0.5F)) % height; |
| 2435 |
j1 = (j0 + 1) & (height-1); |
| 2436 |
j0border = j1border = 0; |
| 2437 |
} |
| 2438 |
else { |
| 2439 |
j0 = (GLint) floor(v - 0.5F); |
| 2440 |
j1 = j0 + 1; |
| 2441 |
j0border = (j0<0) | (j0>=height); |
| 2442 |
j1border = (j1<0) | (j1>=height); |
| 2443 |
} |
| 2444 |
|
| 2445 |
w = r * depth; |
| 2446 |
if (ctx->Texture.Current3D->WrapR==GL_REPEAT) { |
| 2447 |
k0 = ((GLint) floor(w - 0.5F)) % depth; |
| 2448 |
k1 = (k0 + 1) & (depth-1); |
| 2449 |
k0border = k1border = 0; |
| 2450 |
} |
| 2451 |
else { |
| 2452 |
k0 = (GLint) floor(v - 0.5F); |
| 2453 |
k1 = k0 + 1; |
| 2454 |
k0border = (k0<0) | (k0>=depth); |
| 2455 |
k1border = (k1<0) | (k1>=depth); |
| 2456 |
} |
| 2457 |
|
| 2458 |
if (img->Border) { |
| 2459 |
i0 += img->Border; |
| 2460 |
i1 += img->Border; |
| 2461 |
j0 += img->Border; |
| 2462 |
j1 += img->Border; |
| 2463 |
k0 += img->Border; |
| 2464 |
k1 += img->Border; |
| 2465 |
i0border = i1border = 0; |
| 2466 |
j0border = j1border = 0; |
| 2467 |
k0border = k1border = 0; |
| 2468 |
} |
| 2469 |
else { |
| 2470 |
i0 &= (width-1); |
| 2471 |
j0 &= (height-1); |
| 2472 |
k0 &= (depth-1); |
| 2473 |
} |
| 2474 |
|
| 2475 |
{ |
| 2476 |
GLfloat a = frac(u - 0.5F); |
| 2477 |
GLfloat b = frac(v - 0.5F); |
| 2478 |
GLfloat c = frac(w - 0.5F); |
| 2479 |
|
| 2480 |
GLint w000 = (GLint) ((1.0F-a)*(1.0F-b) * (1.0F-c) * 256.0F); |
| 2481 |
GLint w010 = (GLint) ( a *(1.0F-b) * (1.0F-c) * 256.0F); |
| 2482 |
GLint w001 = (GLint) ((1.0F-a)* b * (1.0F-c) * 256.0F); |
| 2483 |
GLint w011 = (GLint) ( a * b * (1.0F-c) * 256.0F); |
| 2484 |
GLint w100 = (GLint) ((1.0F-a)*(1.0F-b) * c * 256.0F); |
| 2485 |
GLint w110 = (GLint) ( a *(1.0F-b) * c * 256.0F); |
| 2486 |
GLint w101 = (GLint) ((1.0F-a)* b * c * 256.0F); |
| 2487 |
GLint w111 = (GLint) ( a * b * c * 256.0F); |
| 2488 |
|
| 2489 |
|
| 2490 |
GLubyte red000, green000, blue000, alpha000; |
| 2491 |
GLubyte red010, green010, blue010, alpha010; |
| 2492 |
GLubyte red001, green001, blue001, alpha001; |
| 2493 |
GLubyte red011, green011, blue011, alpha011; |
| 2494 |
GLubyte red100, green100, blue100, alpha100; |
| 2495 |
GLubyte red110, green110, blue110, alpha110; |
| 2496 |
GLubyte red101, green101, blue101, alpha101; |
| 2497 |
GLubyte red111, green111, blue111, alpha111; |
| 2498 |
|
| 2499 |
if (k0border | i0border | j0border ) { |
| 2500 |
red000 = ctx->Texture.Current3D->BorderColor[0]; |
| 2501 |
green000 = ctx->Texture.Current3D->BorderColor[1]; |
| 2502 |
blue000 = ctx->Texture.Current3D->BorderColor[2]; |
| 2503 |
alpha000 = ctx->Texture.Current3D->BorderColor[3]; |
| 2504 |
} |
| 2505 |
else { |
| 2506 |
get_3d_texel( img, i0, j0, k0, &red000, &green000, &blue000, &alpha000 ); |
| 2507 |
} |
| 2508 |
if (k0border | i1border | j0border) { |
| 2509 |
red010 = ctx->Texture.Current3D->BorderColor[0]; |
| 2510 |
green010 = ctx->Texture.Current3D->BorderColor[1]; |
| 2511 |
blue010 = ctx->Texture.Current3D->BorderColor[2]; |
| 2512 |
alpha010 = ctx->Texture.Current3D->BorderColor[3]; |
| 2513 |
} |
| 2514 |
else { |
| 2515 |
get_3d_texel( img, i1, j0, k0, &red010, &green010, &blue010, &alpha010 ); |
| 2516 |
} |
| 2517 |
if (k0border | i0border | j1border) { |
| 2518 |
red001 = ctx->Texture.Current3D->BorderColor[0]; |
| 2519 |
green001 = ctx->Texture.Current3D->BorderColor[1]; |
| 2520 |
blue001 = ctx->Texture.Current3D->BorderColor[2]; |
| 2521 |
alpha001 = ctx->Texture.Current3D->BorderColor[3]; |
| 2522 |
} |
| 2523 |
else { |
| 2524 |
get_3d_texel( img, i0, j1, k0, &red001, &green001, &blue001, &alpha001 ); |
| 2525 |
} |
| 2526 |
if (k0border | i1border | j1border) { |
| 2527 |
red011 = ctx->Texture.Current3D->BorderColor[0]; |
| 2528 |
green011 = ctx->Texture.Current3D->BorderColor[1]; |
| 2529 |
blue011 = ctx->Texture.Current3D->BorderColor[2]; |
| 2530 |
alpha011 = ctx->Texture.Current3D->BorderColor[3]; |
| 2531 |
} |
| 2532 |
else { |
| 2533 |
get_3d_texel( img, i1, j1, k0, &red011, &green011, &blue011, &alpha011 ); |
| 2534 |
} |
| 2535 |
|
| 2536 |
if (k1border | i0border | j0border ) { |
| 2537 |
red100 = ctx->Texture.Current3D->BorderColor[0]; |
| 2538 |
green100 = ctx->Texture.Current3D->BorderColor[1]; |
| 2539 |
blue100 = ctx->Texture.Current3D->BorderColor[2]; |
| 2540 |
alpha100 = ctx->Texture.Current3D->BorderColor[3]; |
| 2541 |
} |
| 2542 |
else { |
| 2543 |
get_3d_texel( img, i0, j0, k1, &red100, &green100, &blue100, &alpha100 ); |
| 2544 |
} |
| 2545 |
if (k1border | i1border | j0border) { |
| 2546 |
red110 = ctx->Texture.Current3D->BorderColor[0]; |
| 2547 |
green110 = ctx->Texture.Current3D->BorderColor[1]; |
| 2548 |
blue110 = ctx->Texture.Current3D->BorderColor[2]; |
| 2549 |
alpha110 = ctx->Texture.Current3D->BorderColor[3]; |
| 2550 |
} |
| 2551 |
else { |
| 2552 |
get_3d_texel( img, i1, j0, k1, &red110, &green110, &blue110, &alpha110 ); |
| 2553 |
} |
| 2554 |
if (k1border | i0border | j1border) { |
| 2555 |
red101 = ctx->Texture.Current3D->BorderColor[0]; |
| 2556 |
green101 = ctx->Texture.Current3D->BorderColor[1]; |
| 2557 |
blue101 = ctx->Texture.Current3D->BorderColor[2]; |
| 2558 |
alpha101 = ctx->Texture.Current3D->BorderColor[3]; |
| 2559 |
} |
| 2560 |
else { |
| 2561 |
get_3d_texel( img, i0, j1, k1, &red101, &green101, &blue101, &alpha101 ); |
| 2562 |
} |
| 2563 |
if (k1border | i1border | j1border) { |
| 2564 |
red111 = ctx->Texture.Current3D->BorderColor[0]; |
| 2565 |
green111 = ctx->Texture.Current3D->BorderColor[1]; |
| 2566 |
blue111 = ctx->Texture.Current3D->BorderColor[2]; |
| 2567 |
alpha111 = ctx->Texture.Current3D->BorderColor[3]; |
| 2568 |
} |
| 2569 |
else { |
| 2570 |
get_3d_texel( img, i1, j1, k1, &red111, &green111, &blue111, &alpha111 ); |
| 2571 |
} |
| 2572 |
|
| 2573 |
*red = (w000*red000 + w010*red010 + w001*red001 + w011*red011 + |
| 2574 |
w100*red100 + w110*red110 + w101*red101 + w111*red111 ) |
| 2575 |
>> 8; |
| 2576 |
*green = (w000*green000 + w010*green010 + w001*green001 + w011*green011 + |
| 2577 |
w100*green100 + w110*green110 + w101*green101 + w111*green111 ) |
| 2578 |
>> 8; |
| 2579 |
*blue = (w000*blue000 + w010*blue010 + w001*blue001 + w011*blue011 + |
| 2580 |
w100*blue100 + w110*blue110 + w101*blue101 + w111*blue111 ) |
| 2581 |
>> 8; |
| 2582 |
*alpha = (w000*alpha000 + w010*alpha010 + w001*alpha001 + w011*alpha011 + |
| 2583 |
w100*alpha100 + w110*alpha110 + w101*alpha101 + w111*alpha111 ) |
| 2584 |
>> 8; |
| 2585 |
} |
| 2586 |
} |
| 2587 |
|
| 2588 |
|
| 2589 |
static void sample_3d_nearest_mipmap_nearest( GLcontext *ctx, |
| 2590 |
GLfloat lambda, |
| 2591 |
GLfloat s, GLfloat t, GLfloat r, |
| 2592 |
GLubyte *red, GLubyte *green, |
| 2593 |
GLubyte *blue, GLubyte *alpha ) |
| 2594 |
{ |
| 2595 |
GLint level; |
| 2596 |
if (lambda<=0.5F) { |
| 2597 |
level = 0; |
| 2598 |
} |
| 2599 |
else { |
| 2600 |
GLint widthlog2 = ctx->Texture.Current3D->Image[0]->WidthLog2; |
| 2601 |
level = (GLint) (lambda + 0.499999F); |
| 2602 |
if (level>widthlog2 ) { |
| 2603 |
level = widthlog2; |
| 2604 |
} |
| 2605 |
} |
| 2606 |
sample_3d_nearest( ctx, ctx->Texture.Current3D->Image[level], |
| 2607 |
s, t, r, red, green, blue, alpha ); |
| 2608 |
} |
| 2609 |
|
| 2610 |
|
| 2611 |
static void sample_3d_linear_mipmap_nearest( GLcontext *ctx, |
| 2612 |
GLfloat lambda, |
| 2613 |
GLfloat s, GLfloat t, GLfloat r, |
| 2614 |
GLubyte *red, GLubyte *green, |
| 2615 |
GLubyte *blue, GLubyte *alpha ) |
| 2616 |
{ |
| 2617 |
GLint level; |
| 2618 |
if (lambda<=0.5F) { |
| 2619 |
level = 0; |
| 2620 |
} |
| 2621 |
else { |
| 2622 |
GLint widthlog2 = ctx->Texture.Current3D->Image[0]->WidthLog2; |
| 2623 |
level = (GLint) (lambda + 0.499999F); |
| 2624 |
if (level>widthlog2 ) { |
| 2625 |
level = widthlog2; |
| 2626 |
} |
| 2627 |
} |
| 2628 |
sample_3d_linear( ctx, ctx->Texture.Current3D->Image[level], |
| 2629 |
s, t, r, red, green, blue, alpha ); |
| 2630 |
} |
| 2631 |
|
| 2632 |
|
| 2633 |
static void sample_3d_nearest_mipmap_linear( GLcontext *ctx, |
| 2634 |
GLfloat lambda, |
| 2635 |
GLfloat s, GLfloat t, GLfloat r, |
| 2636 |
GLubyte *red, GLubyte *green, |
| 2637 |
GLubyte *blue, GLubyte *alpha ) |
| 2638 |
{ |
| 2639 |
GLint max = ctx->Texture.Current3D->Image[0]->MaxLog2; |
| 2640 |
|
| 2641 |
if (lambda>=max) { |
| 2642 |
sample_3d_nearest( ctx, ctx->Texture.Current3D->Image[max], |
| 2643 |
s, t, r, red, green, blue, alpha ); |
| 2644 |
} |
| 2645 |
else { |
| 2646 |
GLubyte red0, green0, blue0, alpha0; |
| 2647 |
GLubyte red1, green1, blue1, alpha1; |
| 2648 |
GLfloat f = frac(lambda); |
| 2649 |
GLint level = (GLint) (lambda + 1.0F); |
| 2650 |
level = CLAMP( level, 1, max ); |
| 2651 |
sample_3d_nearest( ctx, ctx->Texture.Current3D->Image[level-1], s, t, r, |
| 2652 |
&red0, &green0, &blue0, &alpha0 ); |
| 2653 |
sample_3d_nearest( ctx, ctx->Texture.Current3D->Image[level], s, t, r, |
| 2654 |
&red1, &green1, &blue1, &alpha1 ); |
| 2655 |
*red = (1.0F-f)*red1 + f*red0; |
| 2656 |
*green = (1.0F-f)*green1 + f*green0; |
| 2657 |
*blue = (1.0F-f)*blue1 + f*blue0; |
| 2658 |
*alpha = (1.0F-f)*alpha1 + f*alpha0; |
| 2659 |
} |
| 2660 |
} |
| 2661 |
|
| 2662 |
|
| 2663 |
static void sample_3d_linear_mipmap_linear( GLcontext *ctx, |
| 2664 |
GLfloat lambda, |
| 2665 |
GLfloat s, GLfloat t, GLfloat r, |
| 2666 |
GLubyte *red, GLubyte *green, |
| 2667 |
GLubyte *blue, GLubyte *alpha ) |
| 2668 |
{ |
| 2669 |
GLint max = ctx->Texture.Current3D->Image[0]->MaxLog2; |
| 2670 |
|
| 2671 |
if (lambda>=max) { |
| 2672 |
sample_3d_linear( ctx, ctx->Texture.Current3D->Image[max], |
| 2673 |
s, t, r, red, green, blue, alpha ); |
| 2674 |
} |
| 2675 |
else { |
| 2676 |
GLubyte red0, green0, blue0, alpha0; |
| 2677 |
GLubyte red1, green1, blue1, alpha1; |
| 2678 |
GLfloat f = frac(lambda); |
| 2679 |
GLint level = (GLint) (lambda + 1.0F); |
| 2680 |
level = CLAMP( level, 1, max ); |
| 2681 |
sample_3d_linear( ctx, ctx->Texture.Current3D->Image[level-1], s, t, r, |
| 2682 |
&red0, &green0, &blue0, &alpha0 ); |
| 2683 |
sample_3d_linear( ctx, ctx->Texture.Current3D->Image[level], s, t, r, |
| 2684 |
&red1, &green1, &blue1, &alpha1 ); |
| 2685 |
*red = (1.0F-f)*red1 + f*red0; |
| 2686 |
*green = (1.0F-f)*green1 + f*green0; |
| 2687 |
*blue = (1.0F-f)*blue1 + f*blue0; |
| 2688 |
*alpha = (1.0F-f)*alpha1 + f*alpha0; |
| 2689 |
} |
| 2690 |
} |
| 2691 |
|
| 2692 |
|
| 2693 |
/* |
| 2694 |
* Given an (s,t,r) texture coordinate and lambda (level of detail) value, |
| 2695 |
* return a texture sample. |
| 2696 |
*/ |
| 2697 |
static void sample_3d_texture( GLcontext *ctx, |
| 2698 |
GLfloat s, GLfloat t, GLfloat r, GLfloat lambda, |
| 2699 |
GLubyte *red, GLubyte *green, GLubyte *blue, |
| 2700 |
GLubyte *alpha, GLfloat c ) |
| 2701 |
{ |
| 2702 |
if (lambda>c) { |
| 2703 |
/* minification */ |
| 2704 |
switch (ctx->Texture.Current3D->MinFilter) { |
| 2705 |
case GL_NEAREST: |
| 2706 |
sample_3d_nearest( ctx, ctx->Texture.Current3D->Image[0], |
| 2707 |
s, t, r, red, green, blue, alpha ); |
| 2708 |
break; |
| 2709 |
case GL_LINEAR: |
| 2710 |
sample_3d_linear( ctx, ctx->Texture.Current3D->Image[0], |
| 2711 |
s, t, r, red, green, blue, alpha ); |
| 2712 |
break; |
| 2713 |
case GL_NEAREST_MIPMAP_NEAREST: |
| 2714 |
sample_3d_nearest_mipmap_nearest( ctx, lambda, s, t, r, |
| 2715 |
red, green, blue, alpha ); |
| 2716 |
break; |
| 2717 |
case GL_LINEAR_MIPMAP_NEAREST: |
| 2718 |
sample_3d_linear_mipmap_nearest( ctx, lambda, s, t, r, |
| 2719 |
red, green, blue, alpha ); |
| 2720 |
break; |
| 2721 |
case GL_NEAREST_MIPMAP_LINEAR: |
| 2722 |
sample_3d_nearest_mipmap_linear( ctx, lambda, s, t, r, |
| 2723 |
red, green, blue, alpha ); |
| 2724 |
break; |
| 2725 |
case GL_LINEAR_MIPMAP_LINEAR: |
| 2726 |
sample_3d_linear_mipmap_linear( ctx, lambda, s, t, r, |
| 2727 |
red, green, blue, alpha ); |
| 2728 |
break; |
| 2729 |
default: |
| 2730 |
abort(); |
| 2731 |
} |
| 2732 |
} |
| 2733 |
else { |
| 2734 |
/* magnification */ |
| 2735 |
switch (ctx->Texture.Current3D->MagFilter) { |
| 2736 |
case GL_NEAREST: |
| 2737 |
sample_3d_nearest( ctx, ctx->Texture.Current3D->Image[0], |
| 2738 |
s, t, r, red, green, blue, alpha ); |
| 2739 |
break; |
| 2740 |
case GL_LINEAR: |
| 2741 |
sample_3d_linear( ctx, ctx->Texture.Current3D->Image[0], |
| 2742 |
s, t, r, red, green, blue, alpha ); |
| 2743 |
break; |
| 2744 |
default: |
| 2745 |
abort(); |
| 2746 |
} |
| 2747 |
} |
| 2748 |
} |
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
/**********************************************************************/ |
| 2753 |
/* Texture Application */ |
| 2754 |
/**********************************************************************/ |
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
/* |
| 2759 |
* Combine incoming fragment color with texel color to produce output color. |
| 2760 |
* Input: n - number of fragments |
| 2761 |
* format - base internal texture format |
| 2762 |
* env_mode - texture environment mode |
| 2763 |
* Rt, Gt, Bt, At - array of texel colors |
| 2764 |
* InOut: red, green, blue, alpha - incoming fragment colors modified |
| 2765 |
* by texel colors according to the |
| 2766 |
* texture environment mode. |
| 2767 |
*/ |
| 2768 |
static void apply_texture( GLcontext *ctx, |
| 2769 |
GLuint n, GLint format, GLenum env_mode, |
| 2770 |
GLubyte red[], GLubyte green[], GLubyte blue[], GLubyte alpha[], |
| 2771 |
GLubyte Rt[], GLubyte Gt[], GLubyte Bt[], GLubyte At[] ) |
| 2772 |
{ |
| 2773 |
GLuint i; |
| 2774 |
GLint Rc, Gc, Bc, Ac; |
| 2775 |
|
| 2776 |
if (!ctx->Visual->EightBitColor) { |
| 2777 |
/* This is a hack! Rescale input colors from [0,scale] to [0,255]. */ |
| 2778 |
GLfloat rscale = 255.0 * ctx->Visual->InvRedScale; |
| 2779 |
GLfloat gscale = 255.0 * ctx->Visual->InvGreenScale; |
| 2780 |
GLfloat bscale = 255.0 * ctx->Visual->InvBlueScale; |
| 2781 |
GLfloat ascale = 255.0 * ctx->Visual->InvAlphaScale; |
| 2782 |
for (i=0;i<n;i++) { |
| 2783 |
red[i] = (GLint) (red[i] * rscale); |
| 2784 |
green[i] = (GLint) (green[i] * gscale); |
| 2785 |
blue[i] = (GLint) (blue[i] * bscale); |
| 2786 |
alpha[i] = (GLint) (alpha[i] * ascale); |
| 2787 |
} |
| 2788 |
} |
| 2789 |
|
| 2790 |
/* |
| 2791 |
* Use (A*(B+1)) >> 8 as a fast approximation of (A*B)/255 for A |
| 2792 |
* and B in [0,255] |
| 2793 |
*/ |
| 2794 |
#define PROD(A,B) (((GLint)(A) * (GLint)(B)+1) >> 8) |
| 2795 |
|
| 2796 |
switch (env_mode) { |
| 2797 |
case GL_REPLACE: |
| 2798 |
switch (format) { |
| 2799 |
case GL_ALPHA: |
| 2800 |
for (i=0;i<n;i++) { |
| 2801 |
/* Cv = Cf */ |
| 2802 |
/* Av = At */ |
| 2803 |
alpha[i] = At[i]; |
| 2804 |
} |
| 2805 |
break; |
| 2806 |
case GL_LUMINANCE: |
| 2807 |
for (i=0;i<n;i++) { |
| 2808 |
/* Cv = Lt */ |
| 2809 |
GLint Lt = Rt[i]; |
| 2810 |
red[i] = green[i] = blue[i] = Lt; |
| 2811 |
/* Av = Af */ |
| 2812 |
} |
| 2813 |
break; |
| 2814 |
case GL_LUMINANCE_ALPHA: |
| 2815 |
for (i=0;i<n;i++) { |
| 2816 |
GLint Lt = Rt[i]; |
| 2817 |
/* Cv = Lt */ |
| 2818 |
red[i] = green[i] = blue[i] = Lt; |
| 2819 |
/* Av = At */ |
| 2820 |
alpha[i] = At[i]; |
| 2821 |
} |
| 2822 |
break; |
| 2823 |
case GL_INTENSITY: |
| 2824 |
for (i=0;i<n;i++) { |
| 2825 |
/* Cv = It */ |
| 2826 |
GLint It = Rt[i]; |
| 2827 |
red[i] = green[i] = blue[i] = It; |
| 2828 |
/* Av = It */ |
| 2829 |
alpha[i] = It; |
| 2830 |
} |
| 2831 |
break; |
| 2832 |
case GL_RGB: |
| 2833 |
for (i=0;i<n;i++) { |
| 2834 |
/* Cv = Ct */ |
| 2835 |
red[i] = Rt[i]; |
| 2836 |
green[i] = Gt[i]; |
| 2837 |
blue[i] = Bt[i]; |
| 2838 |
/* Av = Af */ |
| 2839 |
} |
| 2840 |
break; |
| 2841 |
case GL_RGBA: |
| 2842 |
for (i=0;i<n;i++) { |
| 2843 |
/* Cv = Ct */ |
| 2844 |
red[i] = Rt[i]; |
| 2845 |
green[i] = Gt[i]; |
| 2846 |
blue[i] = Bt[i]; |
| 2847 |
/* Av = At */ |
| 2848 |
alpha[i] = At[i]; |
| 2849 |
} |
| 2850 |
break; |
| 2851 |
default: |
| 2852 |
abort(); |
| 2853 |
} |
| 2854 |
break; |
| 2855 |
|
| 2856 |
case GL_MODULATE: |
| 2857 |
switch (format) { |
| 2858 |
case GL_ALPHA: |
| 2859 |
for (i=0;i<n;i++) { |
| 2860 |
/* Cv = Cf */ |
| 2861 |
/* Av = AfAt */ |
| 2862 |
alpha[i] = PROD( alpha[i], At[i] ); |
| 2863 |
} |
| 2864 |
break; |
| 2865 |
case GL_LUMINANCE: |
| 2866 |
for (i=0;i<n;i++) { |
| 2867 |
/* Cv = LtCf */ |
| 2868 |
GLint Lt = Rt[i]; |
| 2869 |
red[i] = PROD( red[i], Lt ); |
| 2870 |
green[i] = PROD( green[i], Lt ); |
| 2871 |
blue[i] = PROD( blue[i], Lt ); |
| 2872 |
/* Av = Af */ |
| 2873 |
} |
| 2874 |
break; |
| 2875 |
case GL_LUMINANCE_ALPHA: |
| 2876 |
for (i=0;i<n;i++) { |
| 2877 |
/* Cv = CfLt */ |
| 2878 |
GLint Lt = Rt[i]; |
| 2879 |
red[i] = PROD( red[i], Lt ); |
| 2880 |
green[i] = PROD( green[i], Lt ); |
| 2881 |
blue[i] = PROD( blue[i], Lt ); |
| 2882 |
/* Av = AfAt */ |
| 2883 |
alpha[i] = PROD( alpha[i], At[i] ); |
| 2884 |
} |
| 2885 |
break; |
| 2886 |
case GL_INTENSITY: |
| 2887 |
for (i=0;i<n;i++) { |
| 2888 |
/* Cv = CfIt */ |
| 2889 |
GLint It = Rt[i]; |
| 2890 |
red[i] = PROD( red[i], It ); |
| 2891 |
green[i] = PROD( green[i], It ); |
| 2892 |
blue[i] = PROD( blue[i], It ); |
| 2893 |
/* Av = AfIt */ |
| 2894 |
alpha[i] = PROD( alpha[i], It ); |
| 2895 |
} |
| 2896 |
break; |
| 2897 |
case GL_RGB: |
| 2898 |
for (i=0;i<n;i++) { |
| 2899 |
/* Cv = CfCt */ |
| 2900 |
red[i] = PROD( red[i], Rt[i] ); |
| 2901 |
green[i] = PROD( green[i], Gt[i] ); |
| 2902 |
blue[i] = PROD( blue[i], Bt[i] ); |
| 2903 |
/* Av = Af */ |
| 2904 |
} |
| 2905 |
break; |
| 2906 |
case GL_RGBA: |
| 2907 |
for (i=0;i<n;i++) { |
| 2908 |
/* Cv = CfCt */ |
| 2909 |
red[i] = PROD( red[i], Rt[i] ); |
| 2910 |
green[i] = PROD( green[i], Gt[i] ); |
| 2911 |
blue[i] = PROD( blue[i], Bt[i] ); |
| 2912 |
/* Av = AfAt */ |
| 2913 |
alpha[i] = PROD( alpha[i], At[i] ); |
| 2914 |
} |
| 2915 |
break; |
| 2916 |
default: |
| 2917 |
abort(); |
| 2918 |
} |
| 2919 |
break; |
| 2920 |
|
| 2921 |
case GL_DECAL: |
| 2922 |
switch (format) { |
| 2923 |
case GL_ALPHA: |
| 2924 |
case GL_LUMINANCE: |
| 2925 |
case GL_LUMINANCE_ALPHA: |
| 2926 |
case GL_INTENSITY: |
| 2927 |
/* undefined */ |
| 2928 |
break; |
| 2929 |
case GL_RGB: |
| 2930 |
for (i=0;i<n;i++) { |
| 2931 |
/* Cv = Ct */ |
| 2932 |
red[i] = Rt[i]; |
| 2933 |
green[i] = Gt[i]; |
| 2934 |
blue[i] = Bt[i]; |
| 2935 |
/* Av = Af */ |
| 2936 |
} |
| 2937 |
break; |
| 2938 |
case GL_RGBA: |
| 2939 |
for (i=0;i<n;i++) { |
| 2940 |
/* Cv = Cf(1-At) + CtAt */ |
| 2941 |
GLint t = At[i], s = 255 - t; |
| 2942 |
red[i] = PROD(red[i], s) + PROD(Rt[i],t); |
| 2943 |
green[i] = PROD(green[i],s) + PROD(Gt[i],t); |
| 2944 |
blue[i] = PROD(blue[i], s) + PROD(Bt[i],t); |
| 2945 |
/* Av = Af */ |
| 2946 |
} |
| 2947 |
break; |
| 2948 |
default: |
| 2949 |
abort(); |
| 2950 |
} |
| 2951 |
break; |
| 2952 |
|
| 2953 |
case GL_BLEND: |
| 2954 |
Rc = (GLint) (ctx->Texture.EnvColor[0] * 255.0F); |
| 2955 |
Gc = (GLint) (ctx->Texture.EnvColor[1] * 255.0F); |
| 2956 |
Bc = (GLint) (ctx->Texture.EnvColor[2] * 255.0F); |
| 2957 |
Ac = (GLint) (ctx->Texture.EnvColor[2] * 255.0F); |
| 2958 |
switch (format) { |
| 2959 |
case GL_ALPHA: |
| 2960 |
for (i=0;i<n;i++) { |
| 2961 |
/* Cv = Cf */ |
| 2962 |
/* Av = AfAt */ |
| 2963 |
alpha[i] = PROD(alpha[i], At[i]); |
| 2964 |
} |
| 2965 |
break; |
| 2966 |
case GL_LUMINANCE: |
| 2967 |
for (i=0;i<n;i++) { |
| 2968 |
/* Cv = Cf(1-Lt) + CcLt */ |
| 2969 |
GLint Lt = Rt[i], s = 255 - Lt; |
| 2970 |
red[i] = PROD(red[i], s) + PROD(Rc, Lt); |
| 2971 |
green[i] = PROD(green[i],s) + PROD(Gc,Lt); |
| 2972 |
blue[i] = PROD(blue[i], s) + PROD(Bc, Lt); |
| 2973 |
/* Av = Af */ |
| 2974 |
} |
| 2975 |
break; |
| 2976 |
case GL_LUMINANCE_ALPHA: |
| 2977 |
for (i=0;i<n;i++) { |
| 2978 |
/* Cv = Cf(1-Lt) + CcLt */ |
| 2979 |
GLint Lt = Rt[i], s = 255 - Lt; |
| 2980 |
red[i] = PROD(red[i], s) + PROD(Rc, Lt); |
| 2981 |
green[i] = PROD(green[i],s) + PROD(Gc,Lt); |
| 2982 |
blue[i] = PROD(blue[i], s) + PROD(Bc, Lt); |
| 2983 |
/* Av = AfAt */ |
| 2984 |
alpha[i] = PROD(alpha[i],At[i]); |
| 2985 |
} |
| 2986 |
break; |
| 2987 |
case GL_INTENSITY: |
| 2988 |
for (i=0;i<n;i++) { |
| 2989 |
/* Cv = Cf(1-It) + CcLt */ |
| 2990 |
GLint It = Rt[i], s = 255 - It; |
| 2991 |
red[i] = PROD(red[i], s) + PROD(Rc,It); |
| 2992 |
green[i] = PROD(green[i],s) + PROD(Gc,It); |
| 2993 |
blue[i] = PROD(blue[i], s) + PROD(Bc,It); |
| 2994 |
/* Av = Af(1-It) + Ac*It */ |
| 2995 |
alpha[i] = PROD(alpha[i],s) + PROD(Ac,It); |
| 2996 |
} |
| 2997 |
break; |
| 2998 |
case GL_RGB: |
| 2999 |
for (i=0;i<n;i++) { |
| 3000 |
/* Cv = Cf(1-Ct) + CcCt */ |
| 3001 |
red[i] = PROD(red[i], (255-Rt[i])) + PROD(Rc,Rt[i]); |
| 3002 |
green[i] = PROD(green[i],(255-Gt[i])) + PROD(Gc,Gt[i]); |
| 3003 |
blue[i] = PROD(blue[i], (255-Bt[i])) + PROD(Bc,Bt[i]); |
| 3004 |
/* Av = Af */ |
| 3005 |
} |
| 3006 |
break; |
| 3007 |
case GL_RGBA: |
| 3008 |
for (i=0;i<n;i++) { |
| 3009 |
/* Cv = Cf(1-Ct) + CcCt */ |
| 3010 |
red[i] = PROD(red[i], (255-Rt[i])) + PROD(Rc,Rt[i]); |
| 3011 |
green[i] = PROD(green[i],(255-Gt[i])) + PROD(Gc,Gt[i]); |
| 3012 |
blue[i] = PROD(blue[i], (255-Bt[i])) + PROD(Bc,Bt[i]); |
| 3013 |
/* Av = AfAt */ |
| 3014 |
alpha[i] = PROD(alpha[i],At[i]); |
| 3015 |
} |
| 3016 |
break; |
| 3017 |
} |
| 3018 |
break; |
| 3019 |
|
| 3020 |
default: |
| 3021 |
abort(); |
| 3022 |
} |
| 3023 |
#undef PROD |
| 3024 |
|
| 3025 |
if (!ctx->Visual->EightBitColor) { |
| 3026 |
/* This is a hack! Rescale input colors from [0,255] to [0,scale]. */ |
| 3027 |
GLfloat rscale = ctx->Visual->RedScale * (1.0F/ 255.0F); |
| 3028 |
GLfloat gscale = ctx->Visual->GreenScale * (1.0F/ 255.0F); |
| 3029 |
GLfloat bscale = ctx->Visual->BlueScale * (1.0F/ 255.0F); |
| 3030 |
GLfloat ascale = ctx->Visual->AlphaScale * (1.0F/ 255.0F); |
| 3031 |
for (i=0;i<n;i++) { |
| 3032 |
red[i] = (GLint) (red[i] * rscale); |
| 3033 |
green[i] = (GLint) (green[i] * gscale); |
| 3034 |
blue[i] = (GLint) (blue[i] * bscale); |
| 3035 |
alpha[i] = (GLint) (alpha[i] * ascale); |
| 3036 |
} |
| 3037 |
} |
| 3038 |
} |
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
/* |
| 3043 |
* Given an array of fragment colors and texture coordinates, apply |
| 3044 |
* 1-D texturing to the fragments. |
| 3045 |
* Input: n - number of fragments |
| 3046 |
* s - array of texture coordinate s values |
| 3047 |
* lambda - array of lambda values |
| 3048 |
* InOut: red, green, blue, alpha - incoming and modifed fragment colors |
| 3049 |
*/ |
| 3050 |
void gl_texture_pixels_1d( GLcontext *ctx, |
| 3051 |
GLuint n, GLfloat s[], GLfloat lambda[], |
| 3052 |
GLubyte red[], GLubyte green[], |
| 3053 |
GLubyte blue[], GLubyte alpha[] ) |
| 3054 |
{ |
| 3055 |
GLubyte tred[PB_SIZE]; |
| 3056 |
GLubyte tgreen[PB_SIZE]; |
| 3057 |
GLubyte tblue[PB_SIZE]; |
| 3058 |
GLubyte talpha[PB_SIZE]; |
| 3059 |
GLuint i; |
| 3060 |
GLfloat c; |
| 3061 |
|
| 3062 |
if (!ctx->Texture.Current1D->Complete) { |
| 3063 |
return; |
| 3064 |
} |
| 3065 |
|
| 3066 |
/* Compute c, the min/mag filter threshold. */ |
| 3067 |
if (ctx->Texture.Current1D->MagFilter==GL_LINEAR |
| 3068 |
&& (ctx->Texture.Current1D->MinFilter==GL_NEAREST_MIPMAP_NEAREST || |
| 3069 |
ctx->Texture.Current1D->MinFilter==GL_LINEAR_MIPMAP_NEAREST)) { |
| 3070 |
c = 0.5F; |
| 3071 |
} |
| 3072 |
else { |
| 3073 |
c = 0.0F; |
| 3074 |
} |
| 3075 |
|
| 3076 |
/* Sample the texture. */ |
| 3077 |
if (lambda) { |
| 3078 |
/* minfilter!=magfilter or using mipmaps */ |
| 3079 |
for (i=0;i<n;i++) |
| 3080 |
sample_1d_texture( ctx, s[i],lambda[i], |
| 3081 |
&tred[i],&tgreen[i],&tblue[i],&talpha[i],c); |
| 3082 |
} |
| 3083 |
else { |
| 3084 |
/* use same filter for minification and magnification */ |
| 3085 |
if (ctx->Texture.Current1D->MagFilter==GL_NEAREST) { |
| 3086 |
struct gl_texture_image *img = ctx->Texture.Current1D->Image[0]; |
| 3087 |
for (i=0;i<n;i++) { |
| 3088 |
sample_1d_nearest( ctx, img, s[i], |
| 3089 |
&tred[i], &tgreen[i], &tblue[i], &talpha[i] ); |
| 3090 |
} |
| 3091 |
} |
| 3092 |
else { |
| 3093 |
/* mag filter must be GL_LINEAR */ |
| 3094 |
struct gl_texture_image *img = ctx->Texture.Current1D->Image[0]; |
| 3095 |
for (i=0;i<n;i++) { |
| 3096 |
sample_1d_linear( ctx, img, s[i], |
| 3097 |
&tred[i], &tgreen[i], &tblue[i], &talpha[i] ); |
| 3098 |
} |
| 3099 |
} |
| 3100 |
} |
| 3101 |
|
| 3102 |
/* Modify incoming fragment colors according to sampled texels */ |
| 3103 |
apply_texture( ctx, n, |
| 3104 |
ctx->Texture.Current1D->Image[0]->Format, |
| 3105 |
ctx->Texture.EnvMode, |
| 3106 |
red, green, blue, alpha, |
| 3107 |
tred, tgreen, tblue, talpha ); |
| 3108 |
} |
| 3109 |
|
| 3110 |
|
| 3111 |
|
| 3112 |
/* |
| 3113 |
* Given an array of fragment colors and texture coordinates, apply |
| 3114 |
* 2-D texturing to the fragments. |
| 3115 |
* Input: n - number of fragments |
| 3116 |
* s,s - array of texture coordinate (s,t) values |
| 3117 |
* lambda - array of lambda values |
| 3118 |
* InOut: red, green, blue, alpha - incoming and modifed fragment colors |
| 3119 |
*/ |
| 3120 |
void gl_texture_pixels_2d( GLcontext *ctx, |
| 3121 |
GLuint n, |
| 3122 |
GLfloat s[], GLfloat t[], GLfloat lambda[], |
| 3123 |
GLubyte red[], GLubyte green[], |
| 3124 |
GLubyte blue[], GLubyte alpha[] ) |
| 3125 |
{ |
| 3126 |
GLubyte tred[PB_SIZE]; |
| 3127 |
GLubyte tgreen[PB_SIZE]; |
| 3128 |
GLubyte tblue[PB_SIZE]; |
| 3129 |
GLubyte talpha[PB_SIZE]; |
| 3130 |
GLuint i; |
| 3131 |
GLfloat c; |
| 3132 |
|
| 3133 |
if (!ctx->Texture.Current2D->Complete) { |
| 3134 |
return; |
| 3135 |
} |
| 3136 |
|
| 3137 |
/* Compute c, the min/mag filter threshold. */ |
| 3138 |
if (ctx->Texture.Current2D->MagFilter==GL_LINEAR |
| 3139 |
&& (ctx->Texture.Current2D->MinFilter==GL_NEAREST_MIPMAP_NEAREST || |
| 3140 |
ctx->Texture.Current2D->MinFilter==GL_LINEAR_MIPMAP_NEAREST)) { |
| 3141 |
c = 0.5F; |
| 3142 |
} |
| 3143 |
else { |
| 3144 |
c = 0.0F; |
| 3145 |
} |
| 3146 |
|
| 3147 |
/* Sample the texture. */ |
| 3148 |
if (lambda) { |
| 3149 |
/* minfilter!=magfilter or using mipmaps */ |
| 3150 |
for (i=0;i<n;i++) { |
| 3151 |
sample_2d_texture( ctx, s[i], t[i], lambda[i], |
| 3152 |
&tred[i], &tgreen[i], &tblue[i], &talpha[i], c); |
| 3153 |
} |
| 3154 |
} |
| 3155 |
else { |
| 3156 |
/* use same filter for minification and magnification */ |
| 3157 |
if (ctx->Texture.Current2D->MagFilter==GL_NEAREST) { |
| 3158 |
struct gl_texture_image *img = ctx->Texture.Current2D->Image[0]; |
| 3159 |
for (i=0;i<n;i++) { |
| 3160 |
sample_2d_nearest( ctx, img, s[i], t[i], |
| 3161 |
&tred[i], &tgreen[i], &tblue[i], &talpha[i] ); |
| 3162 |
} |
| 3163 |
} |
| 3164 |
else { |
| 3165 |
/* mag filter must be GL_LINEAR */ |
| 3166 |
struct gl_texture_image *img = ctx->Texture.Current2D->Image[0]; |
| 3167 |
for (i=0;i<n;i++) { |
| 3168 |
sample_2d_linear( ctx, img, s[i], t[i], |
| 3169 |
&tred[i], &tgreen[i], &tblue[i], &talpha[i] ); |
| 3170 |
} |
| 3171 |
} |
| 3172 |
} |
| 3173 |
|
| 3174 |
apply_texture( ctx, n, |
| 3175 |
ctx->Texture.Current2D->Image[0]->Format, |
| 3176 |
ctx->Texture.EnvMode, |
| 3177 |
red, green, blue, alpha, |
| 3178 |
tred, tgreen, tblue, talpha ); |
| 3179 |
} |
| 3180 |
|
| 3181 |
|
| 3182 |
|
| 3183 |
/* |
| 3184 |
* Given an array of fragment colors and texture coordinates, apply |
| 3185 |
* 3-D texturing to the fragments. |
| 3186 |
* Input: n - number of fragments |
| 3187 |
* s,t,r - array of texture coordinate (s,t,r) values |
| 3188 |
* lambda - array of lambda values |
| 3189 |
* InOut: red, green, blue, alpha - incoming and modifed fragment colors |
| 3190 |
*/ |
| 3191 |
void gl_texture_pixels_3d( GLcontext *ctx, |
| 3192 |
GLuint n, |
| 3193 |
GLfloat s[], GLfloat t[], GLfloat r[], |
| 3194 |
GLfloat lambda[], |
| 3195 |
GLubyte red[], GLubyte green[], |
| 3196 |
GLubyte blue[], GLubyte alpha[] ) |
| 3197 |
{ |
| 3198 |
GLubyte tred[PB_SIZE]; |
| 3199 |
GLubyte tgreen[PB_SIZE]; |
| 3200 |
GLubyte tblue[PB_SIZE]; |
| 3201 |
GLubyte talpha[PB_SIZE]; |
| 3202 |
GLuint i; |
| 3203 |
GLfloat c; |
| 3204 |
|
| 3205 |
if (!ctx->Texture.Current3D->Complete) { |
| 3206 |
return; |
| 3207 |
} |
| 3208 |
|
| 3209 |
/* Compute c, the min/mag filter threshold. */ |
| 3210 |
if (ctx->Texture.Current3D->MagFilter==GL_LINEAR |
| 3211 |
&& (ctx->Texture.Current3D->MinFilter==GL_NEAREST_MIPMAP_NEAREST || |
| 3212 |
ctx->Texture.Current3D->MinFilter==GL_LINEAR_MIPMAP_NEAREST)) { |
| 3213 |
c = 0.5F; |
| 3214 |
} |
| 3215 |
else { |
| 3216 |
c = 0.0F; |
| 3217 |
} |
| 3218 |
|
| 3219 |
/* Sample the texture. */ |
| 3220 |
if (lambda) { |
| 3221 |
/* minfilter!=magfilter or using mipmaps */ |
| 3222 |
for (i=0;i<n;i++) { |
| 3223 |
sample_3d_texture( ctx, s[i], t[i], r[i], lambda[i], |
| 3224 |
&tred[i], &tgreen[i], &tblue[i], &talpha[i], c); |
| 3225 |
} |
| 3226 |
} |
| 3227 |
else { |
| 3228 |
/* use same filter for minification and magnification */ |
| 3229 |
if (ctx->Texture.Current3D->MagFilter==GL_NEAREST) { |
| 3230 |
struct gl_texture_image *img = ctx->Texture.Current3D->Image[0]; |
| 3231 |
for (i=0;i<n;i++) { |
| 3232 |
sample_3d_nearest( ctx, img, s[i], t[i], r[i], |
| 3233 |
&tred[i], &tgreen[i], &tblue[i], &talpha[i] ); |
| 3234 |
} |
| 3235 |
} |
| 3236 |
else { |
| 3237 |
/* mag filter must be GL_LINEAR */ |
| 3238 |
struct gl_texture_image *img = ctx->Texture.Current3D->Image[0]; |
| 3239 |
for (i=0;i<n;i++) { |
| 3240 |
sample_3d_linear( ctx, img, s[i], t[i], r[i], |
| 3241 |
&tred[i], &tgreen[i], &tblue[i], &talpha[i] ); |
| 3242 |
} |
| 3243 |
} |
| 3244 |
} |
| 3245 |
|
| 3246 |
apply_texture( ctx, n, |
| 3247 |
ctx->Texture.Current3D->Image[0]->Format, |
| 3248 |
ctx->Texture.EnvMode, |
| 3249 |
red, green, blue, alpha, |
| 3250 |
tred, tgreen, tblue, talpha ); |
| 3251 |
} |
| 3252 |
|
| 3253 |
|
| 3254 |
|
| 3255 |
/* |
| 3256 |
* This is called by gl_update_state() if the NEW_TEXTURING bit in |
| 3257 |
* ctx->NewState is set. Basically, we check if we have a complete set |
| 3258 |
* of mipmaps when mipmapping is enabled. |
| 3259 |
*/ |
| 3260 |
void gl_update_texture_state( GLcontext *ctx ) |
| 3261 |
{ |
| 3262 |
GLint i; |
| 3263 |
struct gl_texture_object *t; |
| 3264 |
|
| 3265 |
for (t = ctx->Shared->TexObjectList; t; t = t->Next) { |
| 3266 |
|
| 3267 |
/* |
| 3268 |
* Determine if we have a complete set of mipmaps |
| 3269 |
*/ |
| 3270 |
t->Complete = GL_TRUE; /* be optimistic */ |
| 3271 |
if ( t->MinFilter==GL_NEAREST_MIPMAP_NEAREST |
| 3272 |
|| t->MinFilter==GL_LINEAR_MIPMAP_NEAREST |
| 3273 |
|| t->MinFilter==GL_NEAREST_MIPMAP_LINEAR |
| 3274 |
|| t->MinFilter==GL_LINEAR_MIPMAP_LINEAR) { |
| 3275 |
|
| 3276 |
/* Test dimension-independent attributes */ |
| 3277 |
for (i=1; i<MAX_TEXTURE_LEVELS; i++) { |
| 3278 |
if (t->Image[i]) { |
| 3279 |
if (!t->Image[i]->Data) { |
| 3280 |
t->Complete = GL_FALSE; |
| 3281 |
break; |
| 3282 |
} |
| 3283 |
if (t->Image[i]->Format != t->Image[0]->Format) { |
| 3284 |
t->Complete = GL_FALSE; |
| 3285 |
break; |
| 3286 |
} |
| 3287 |
if (t->Image[i]->Border != t->Image[0]->Border) { |
| 3288 |
t->Complete = GL_FALSE; |
| 3289 |
break; |
| 3290 |
} |
| 3291 |
} |
| 3292 |
} |
| 3293 |
|
| 3294 |
if (t->Dimensions==1) { |
| 3295 |
if (t->Image[0]) { |
| 3296 |
/* Test 1-D mipmaps */ |
| 3297 |
GLuint width = t->Image[0]->Width2; |
| 3298 |
for (i=1; i<MAX_TEXTURE_LEVELS; i++) { |
| 3299 |
if (width>1) { |
| 3300 |
width /= 2; |
| 3301 |
} |
| 3302 |
if (!t->Image[i]) { |
| 3303 |
t->Complete = GL_FALSE; |
| 3304 |
break; |
| 3305 |
} |
| 3306 |
if (!t->Image[i]->Data) { |
| 3307 |
t->Complete = GL_FALSE; |
| 3308 |
break; |
| 3309 |
} |
| 3310 |
if (t->Image[i]->Format != t->Image[0]->Format) { |
| 3311 |
t->Complete = GL_FALSE; |
| 3312 |
break; |
| 3313 |
} |
| 3314 |
if (t->Image[i]->Border != t->Image[0]->Border) { |
| 3315 |
t->Complete = GL_FALSE; |
| 3316 |
break; |
| 3317 |
} |
| 3318 |
if (t->Image[i]->Width2 != width ) { |
| 3319 |
t->Complete = GL_FALSE; |
| 3320 |
break; |
| 3321 |
} |
| 3322 |
if (width==1) { |
| 3323 |
break; |
| 3324 |
} |
| 3325 |
} |
| 3326 |
} |
| 3327 |
else { |
| 3328 |
/* Image[0] missing, this is bad */ |
| 3329 |
t->Complete = GL_FALSE; |
| 3330 |
} |
| 3331 |
} |
| 3332 |
else if (t->Dimensions==2) { |
| 3333 |
if (t->Image[0]) { |
| 3334 |
/* Test 2-D mipmaps */ |
| 3335 |
GLuint width = t->Image[0]->Width2; |
| 3336 |
GLuint height = t->Image[0]->Height2; |
| 3337 |
for (i=1; i<MAX_TEXTURE_LEVELS; i++) { |
| 3338 |
if (width>1) { |
| 3339 |
width /= 2; |
| 3340 |
} |
| 3341 |
if (height>1) { |
| 3342 |
height /= 2; |
| 3343 |
} |
| 3344 |
if (!t->Image[i]) { |
| 3345 |
t->Complete = GL_FALSE; |
| 3346 |
break; |
| 3347 |
} |
| 3348 |
if (t->Image[i]->Width2 != width) { |
| 3349 |
t->Complete = GL_FALSE; |
| 3350 |
break; |
| 3351 |
} |
| 3352 |
if (t->Image[i]->Height2 != height) { |
| 3353 |
t->Complete = GL_FALSE; |
| 3354 |
break; |
| 3355 |
} |
| 3356 |
if (width==1 && height==1) { |
| 3357 |
break; |
| 3358 |
} |
| 3359 |
} |
| 3360 |
} |
| 3361 |
else { |
| 3362 |
/* Image[0] is missing, this is bad */ |
| 3363 |
t->Complete = GL_FALSE; |
| 3364 |
} |
| 3365 |
} |
| 3366 |
else if (t->Dimensions==3) { |
| 3367 |
if (t->Image[0]) { |
| 3368 |
/* Test 3-D mipmaps */ |
| 3369 |
GLuint width = t->Image[0]->Width2; |
| 3370 |
GLuint height = t->Image[0]->Height2; |
| 3371 |
GLuint depth = t->Image[0]->Depth2; |
| 3372 |
for (i=1; i<MAX_TEXTURE_LEVELS; i++) { |
| 3373 |
if (width>1) { |
| 3374 |
width /= 2; |
| 3375 |
} |
| 3376 |
if (height>1) { |
| 3377 |
height /= 2; |
| 3378 |
} |
| 3379 |
if (depth>1) { |
| 3380 |
depth /= 2; |
| 3381 |
} |
| 3382 |
if (!t->Image[i]) { |
| 3383 |
t->Complete = GL_FALSE; |
| 3384 |
break; |
| 3385 |
} |
| 3386 |
if (t->Image[i]->Width2 != width) { |
| 3387 |
t->Complete = GL_FALSE; |
| 3388 |
break; |
| 3389 |
} |
| 3390 |
if (t->Image[i]->Height2 != height) { |
| 3391 |
t->Complete = GL_FALSE; |
| 3392 |
break; |
| 3393 |
} |
| 3394 |
if (t->Image[i]->Depth2 != depth) { |
| 3395 |
t->Complete = GL_FALSE; |
| 3396 |
break; |
| 3397 |
} |
| 3398 |
if (width==1 && height==1 && depth==1) { |
| 3399 |
break; |
| 3400 |
} |
| 3401 |
} |
| 3402 |
} |
| 3403 |
else { |
| 3404 |
/* Image[0] is missing, this is bad */ |
| 3405 |
t->Complete = GL_FALSE; |
| 3406 |
} |
| 3407 |
} |
| 3408 |
else { |
| 3409 |
/* Dimensions = ??? */ |
| 3410 |
gl_problem(ctx, "Bug in gl_update_texture_state\n"); |
| 3411 |
} |
| 3412 |
} |
| 3413 |
else { |
| 3414 |
/* not mipmapping, only need the level 0 texture image */ |
| 3415 |
if (!t->Image[0] || !t->Image[0]->Data) { |
| 3416 |
t->Complete = GL_FALSE; |
| 3417 |
} |
| 3418 |
} |
| 3419 |
} |
| 3420 |
} |
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
/* |
| 3425 |
* Check if texturing is enabled. Remember, if any texture images |
| 3426 |
* (mipmap levels) are missing, it's as if texturing is disabled. |
| 3427 |
* Return: GL_TRUE if texturing is enabled and all is well, else GL_FALSE |
| 3428 |
*/ |
| 3429 |
GLboolean gl_texturing_enabled( GLcontext *ctx ) |
| 3430 |
{ |
| 3431 |
if ((ctx->Texture.Enabled & TEXTURE_3D) && ctx->Texture.Current3D->Complete) |
| 3432 |
return GL_TRUE; |
| 3433 |
else if ((ctx->Texture.Enabled & TEXTURE_2D) && ctx->Texture.Current2D->Complete) |
| 3434 |
return GL_TRUE; |
| 3435 |
else if ((ctx->Texture.Enabled & TEXTURE_1D) && ctx->Texture.Current1D->Complete) |
| 3436 |
return GL_TRUE; |
| 3437 |
else |
| 3438 |
return GL_FALSE; |
| 3439 |
} |