| 1 |
/* $Id: teximage.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 <stdlib.h> |
| 25 |
#include <string.h> |
| 26 |
#include "context.h" |
| 27 |
#include "image.h" |
| 28 |
#include "macros.h" |
| 29 |
#include "pixel.h" |
| 30 |
#include "span.h" |
| 31 |
#include "teximage.h" |
| 32 |
#include "types.h" |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
/* |
| 37 |
* NOTES: |
| 38 |
* |
| 39 |
* The internal texture storage convension is an array of N GLubytes |
| 40 |
* where N = width * height * components. There is no padding. |
| 41 |
*/ |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
/* |
| 47 |
* Compute log base 2 of n. |
| 48 |
* If n isn't an exact power of two return -1. |
| 49 |
* If n<0 return -1. |
| 50 |
*/ |
| 51 |
static int logbase2( int n ) |
| 52 |
{ |
| 53 |
GLint i = 1; |
| 54 |
GLint log2 = 0; |
| 55 |
|
| 56 |
if (n<0) { |
| 57 |
return -1; |
| 58 |
} |
| 59 |
|
| 60 |
while ( n > i ) { |
| 61 |
i *= 2; |
| 62 |
log2++; |
| 63 |
} |
| 64 |
if (i != n) { |
| 65 |
return -1; |
| 66 |
} |
| 67 |
else { |
| 68 |
return log2; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
/* |
| 75 |
* Given an internal texture format enum or 1, 2, 3, 4 return the |
| 76 |
* corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE, |
| 77 |
* GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. Return -1 if |
| 78 |
* invalid enum. |
| 79 |
*/ |
| 80 |
static GLint decode_internal_format( GLint format ) |
| 81 |
{ |
| 82 |
switch (format) { |
| 83 |
case GL_ALPHA: |
| 84 |
case GL_ALPHA4: |
| 85 |
case GL_ALPHA8: |
| 86 |
case GL_ALPHA12: |
| 87 |
case GL_ALPHA16: |
| 88 |
return GL_ALPHA; |
| 89 |
case 1: |
| 90 |
case GL_LUMINANCE: |
| 91 |
case GL_LUMINANCE4: |
| 92 |
case GL_LUMINANCE8: |
| 93 |
case GL_LUMINANCE12: |
| 94 |
case GL_LUMINANCE16: |
| 95 |
return GL_LUMINANCE; |
| 96 |
case 2: |
| 97 |
case GL_LUMINANCE_ALPHA: |
| 98 |
case GL_LUMINANCE4_ALPHA4: |
| 99 |
case GL_LUMINANCE6_ALPHA2: |
| 100 |
case GL_LUMINANCE8_ALPHA8: |
| 101 |
case GL_LUMINANCE12_ALPHA4: |
| 102 |
case GL_LUMINANCE12_ALPHA12: |
| 103 |
case GL_LUMINANCE16_ALPHA16: |
| 104 |
return GL_LUMINANCE_ALPHA; |
| 105 |
case GL_INTENSITY: |
| 106 |
case GL_INTENSITY4: |
| 107 |
case GL_INTENSITY8: |
| 108 |
case GL_INTENSITY12: |
| 109 |
case GL_INTENSITY16: |
| 110 |
return GL_INTENSITY; |
| 111 |
case 3: |
| 112 |
case GL_RGB: |
| 113 |
case GL_R3_G3_B2: |
| 114 |
case GL_RGB4: |
| 115 |
case GL_RGB5: |
| 116 |
case GL_RGB8: |
| 117 |
case GL_RGB10: |
| 118 |
case GL_RGB12: |
| 119 |
case GL_RGB16: |
| 120 |
return GL_RGB; |
| 121 |
case 4: |
| 122 |
case GL_RGBA: |
| 123 |
case GL_RGBA2: |
| 124 |
case GL_RGBA4: |
| 125 |
case GL_RGB5_A1: |
| 126 |
case GL_RGBA8: |
| 127 |
case GL_RGB10_A2: |
| 128 |
case GL_RGBA12: |
| 129 |
case GL_RGBA16: |
| 130 |
return GL_RGBA; |
| 131 |
default: |
| 132 |
return -1; /* error */ |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
/* |
| 139 |
* Given an internal texture format enum or 1, 2, 3, 4 return the |
| 140 |
* corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE, |
| 141 |
* GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. Return the |
| 142 |
* number of components for the format. Return -1 if invalid enum. |
| 143 |
*/ |
| 144 |
static GLint components_in_intformat( GLint format ) |
| 145 |
{ |
| 146 |
switch (format) { |
| 147 |
case GL_ALPHA: |
| 148 |
case GL_ALPHA4: |
| 149 |
case GL_ALPHA8: |
| 150 |
case GL_ALPHA12: |
| 151 |
case GL_ALPHA16: |
| 152 |
return 1; |
| 153 |
case 1: |
| 154 |
case GL_LUMINANCE: |
| 155 |
case GL_LUMINANCE4: |
| 156 |
case GL_LUMINANCE8: |
| 157 |
case GL_LUMINANCE12: |
| 158 |
case GL_LUMINANCE16: |
| 159 |
return 1; |
| 160 |
case 2: |
| 161 |
case GL_LUMINANCE_ALPHA: |
| 162 |
case GL_LUMINANCE4_ALPHA4: |
| 163 |
case GL_LUMINANCE6_ALPHA2: |
| 164 |
case GL_LUMINANCE8_ALPHA8: |
| 165 |
case GL_LUMINANCE12_ALPHA4: |
| 166 |
case GL_LUMINANCE12_ALPHA12: |
| 167 |
case GL_LUMINANCE16_ALPHA16: |
| 168 |
return 2; |
| 169 |
case GL_INTENSITY: |
| 170 |
case GL_INTENSITY4: |
| 171 |
case GL_INTENSITY8: |
| 172 |
case GL_INTENSITY12: |
| 173 |
case GL_INTENSITY16: |
| 174 |
return 1; |
| 175 |
case 3: |
| 176 |
case GL_RGB: |
| 177 |
case GL_R3_G3_B2: |
| 178 |
case GL_RGB4: |
| 179 |
case GL_RGB5: |
| 180 |
case GL_RGB8: |
| 181 |
case GL_RGB10: |
| 182 |
case GL_RGB12: |
| 183 |
case GL_RGB16: |
| 184 |
return 3; |
| 185 |
case 4: |
| 186 |
case GL_RGBA: |
| 187 |
case GL_RGBA2: |
| 188 |
case GL_RGBA4: |
| 189 |
case GL_RGB5_A1: |
| 190 |
case GL_RGBA8: |
| 191 |
case GL_RGB10_A2: |
| 192 |
case GL_RGBA12: |
| 193 |
case GL_RGBA16: |
| 194 |
return 4; |
| 195 |
default: |
| 196 |
return -1; /* error */ |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
struct gl_texture_image *gl_alloc_texture_image( void ) |
| 203 |
{ |
| 204 |
return calloc( 1, sizeof(struct gl_texture_image) ); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
void gl_free_texture_image( struct gl_texture_image *teximage ) |
| 210 |
{ |
| 211 |
if (teximage->Data) { |
| 212 |
free( teximage->Data ); |
| 213 |
} |
| 214 |
free( teximage ); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
/* |
| 220 |
* Given a gl_image, apply the pixel transfer scale, bias, and mapping |
| 221 |
* to produce a gl_texture_image. |
| 222 |
* Input: image - the incoming gl_image |
| 223 |
* internalFormat - desired format of resultant texture |
| 224 |
* border - texture border width (0 or 1) |
| 225 |
* Return: pointer to a gl_texture_image or NULL if an error occurs. |
| 226 |
*/ |
| 227 |
struct gl_texture_image *gl_image_to_texture( GLcontext *ctx, |
| 228 |
const struct gl_image *image, |
| 229 |
GLenum internalFormat, |
| 230 |
GLint border ) |
| 231 |
{ |
| 232 |
GLint components; |
| 233 |
struct gl_texture_image *texImage; |
| 234 |
GLint numPixels, pixel; |
| 235 |
GLboolean scaleOrBias; |
| 236 |
|
| 237 |
assert(image->Width>0); |
| 238 |
assert(image->Height>0); |
| 239 |
assert(image->Depth>0); |
| 240 |
|
| 241 |
internalFormat = decode_internal_format(internalFormat); |
| 242 |
components = components_in_intformat(internalFormat); |
| 243 |
numPixels = image->Width * image->Height * image->Depth; |
| 244 |
|
| 245 |
texImage = gl_alloc_texture_image(); |
| 246 |
texImage->Format = internalFormat; |
| 247 |
texImage->Border = border; |
| 248 |
texImage->Width = image->Width; |
| 249 |
texImage->Height = image->Height; |
| 250 |
texImage->Depth = image->Depth; |
| 251 |
texImage->WidthLog2 = logbase2(image->Width - 2*border); |
| 252 |
if (image->Height==1) /* 1-D texture */ |
| 253 |
texImage->HeightLog2 = 0; |
| 254 |
else |
| 255 |
texImage->HeightLog2 = logbase2(image->Height - 2*border); |
| 256 |
if (image->Depth==1) /* 2-D texture */ |
| 257 |
texImage->DepthLog2 = 0; |
| 258 |
else |
| 259 |
texImage->DepthLog2 = logbase2(image->Depth - 2*border); |
| 260 |
texImage->Width2 = 1 << texImage->WidthLog2; |
| 261 |
texImage->Height2 = 1 << texImage->HeightLog2; |
| 262 |
texImage->Depth2 = 1 << texImage->DepthLog2; |
| 263 |
texImage->MaxLog2 = MAX2( texImage->WidthLog2, texImage->HeightLog2 ); |
| 264 |
texImage->Data = (GLubyte *) malloc( numPixels * components ); |
| 265 |
|
| 266 |
assert(texImage->WidthLog2>=0); |
| 267 |
assert(texImage->HeightLog2>=0); |
| 268 |
assert(texImage->DepthLog2>=0); |
| 269 |
|
| 270 |
if (!texImage->Data) { |
| 271 |
/* out of memory */ |
| 272 |
gl_free_texture_image( texImage ); |
| 273 |
return NULL; |
| 274 |
} |
| 275 |
|
| 276 |
/* Determine if scaling and/or biasing is needed */ |
| 277 |
if (ctx->Pixel.RedScale!=1.0F || ctx->Pixel.RedBias!=0.0F || |
| 278 |
ctx->Pixel.GreenScale!=1.0F || ctx->Pixel.GreenBias!=0.0F || |
| 279 |
ctx->Pixel.BlueScale!=1.0F || ctx->Pixel.BlueBias!=0.0F || |
| 280 |
ctx->Pixel.AlphaScale!=1.0F || ctx->Pixel.AlphaBias!=0.0F) { |
| 281 |
scaleOrBias = GL_TRUE; |
| 282 |
} |
| 283 |
else { |
| 284 |
scaleOrBias = GL_FALSE; |
| 285 |
} |
| 286 |
|
| 287 |
switch (image->Type) { |
| 288 |
case GL_BITMAP: |
| 289 |
{ |
| 290 |
GLint shift = ctx->Pixel.IndexShift; |
| 291 |
GLint offset = ctx->Pixel.IndexOffset; |
| 292 |
/* MapIto[RGBA]Size must be powers of two */ |
| 293 |
GLint rMask = ctx->Pixel.MapItoRsize-1; |
| 294 |
GLint gMask = ctx->Pixel.MapItoGsize-1; |
| 295 |
GLint bMask = ctx->Pixel.MapItoBsize-1; |
| 296 |
GLint aMask = ctx->Pixel.MapItoAsize-1; |
| 297 |
GLint i, j; |
| 298 |
GLubyte *srcPtr = (GLubyte *) image->Data; |
| 299 |
|
| 300 |
assert( image->Format==GL_COLOR_INDEX ); |
| 301 |
|
| 302 |
for (j=0; j<image->Height; j++) { |
| 303 |
GLubyte bitMask = 128; |
| 304 |
for (i=0; i<image->Width; i++) { |
| 305 |
GLint index; |
| 306 |
GLubyte red, green, blue, alpha; |
| 307 |
|
| 308 |
/* Fetch image color index */ |
| 309 |
index = (*srcPtr & bitMask) ? 1 : 0; |
| 310 |
bitMask = bitMask >> 1; |
| 311 |
if (bitMask==0) { |
| 312 |
bitMask = 128; |
| 313 |
srcPtr++; |
| 314 |
} |
| 315 |
/* apply index shift and offset */ |
| 316 |
if (shift>=0) { |
| 317 |
index = (index << shift) + offset; |
| 318 |
} |
| 319 |
else { |
| 320 |
index = (index >> -shift) + offset; |
| 321 |
} |
| 322 |
/* convert index to RGBA */ |
| 323 |
red = (GLint) (ctx->Pixel.MapItoR[index & rMask] * 255.0F); |
| 324 |
green = (GLint) (ctx->Pixel.MapItoG[index & gMask] * 255.0F); |
| 325 |
blue = (GLint) (ctx->Pixel.MapItoB[index & bMask] * 255.0F); |
| 326 |
alpha = (GLint) (ctx->Pixel.MapItoA[index & aMask] * 255.0F); |
| 327 |
|
| 328 |
/* store texel (components are GLubytes in [0,255]) */ |
| 329 |
pixel = j * image->Width + i; |
| 330 |
switch (internalFormat) { |
| 331 |
case GL_ALPHA: |
| 332 |
texImage->Data[pixel] = alpha; |
| 333 |
break; |
| 334 |
case GL_LUMINANCE: |
| 335 |
texImage->Data[pixel] = red; |
| 336 |
break; |
| 337 |
case GL_LUMINANCE_ALPHA: |
| 338 |
texImage->Data[pixel*2+0] = red; |
| 339 |
texImage->Data[pixel*2+1] = alpha; |
| 340 |
break; |
| 341 |
case GL_INTENSITY: |
| 342 |
texImage->Data[pixel] = red; |
| 343 |
break; |
| 344 |
case GL_RGB: |
| 345 |
texImage->Data[pixel*3+0] = red; |
| 346 |
texImage->Data[pixel*3+1] = green; |
| 347 |
texImage->Data[pixel*3+2] = blue; |
| 348 |
break; |
| 349 |
case GL_RGBA: |
| 350 |
texImage->Data[pixel*4+0] = red; |
| 351 |
texImage->Data[pixel*4+1] = green; |
| 352 |
texImage->Data[pixel*4+2] = blue; |
| 353 |
texImage->Data[pixel*4+3] = alpha; |
| 354 |
break; |
| 355 |
default: |
| 356 |
abort(); |
| 357 |
} |
| 358 |
} |
| 359 |
if (bitMask!=128) { |
| 360 |
srcPtr++; |
| 361 |
} |
| 362 |
} |
| 363 |
} |
| 364 |
break; |
| 365 |
|
| 366 |
case GL_UNSIGNED_BYTE: |
| 367 |
for (pixel=0; pixel<numPixels; pixel++) { |
| 368 |
GLubyte red, green, blue, alpha; |
| 369 |
switch (image->Format) { |
| 370 |
case GL_COLOR_INDEX: |
| 371 |
{ |
| 372 |
GLint index = ((GLubyte*)image->Data)[pixel]; |
| 373 |
red = 255.0F * ctx->Pixel.MapItoR[index]; |
| 374 |
green = 255.0F * ctx->Pixel.MapItoG[index]; |
| 375 |
blue = 255.0F * ctx->Pixel.MapItoB[index]; |
| 376 |
alpha = 255; |
| 377 |
} |
| 378 |
break; |
| 379 |
case GL_RGB: |
| 380 |
/* Fetch image RGBA values */ |
| 381 |
red = ((GLubyte*) image->Data)[pixel*3+0]; |
| 382 |
green = ((GLubyte*) image->Data)[pixel*3+1]; |
| 383 |
blue = ((GLubyte*) image->Data)[pixel*3+2]; |
| 384 |
alpha = 255; |
| 385 |
break; |
| 386 |
case GL_RGBA: |
| 387 |
red = ((GLubyte*) image->Data)[pixel*4+0]; |
| 388 |
green = ((GLubyte*) image->Data)[pixel*4+1]; |
| 389 |
blue = ((GLubyte*) image->Data)[pixel*4+2]; |
| 390 |
alpha = ((GLubyte*) image->Data)[pixel*4+3]; |
| 391 |
break; |
| 392 |
case GL_RED: |
| 393 |
red = ((GLubyte*) image->Data)[pixel]; |
| 394 |
green = 0; |
| 395 |
blue = 0; |
| 396 |
alpha = 255; |
| 397 |
break; |
| 398 |
case GL_GREEN: |
| 399 |
red = 0; |
| 400 |
green = ((GLubyte*) image->Data)[pixel]; |
| 401 |
blue = 0; |
| 402 |
alpha = 255; |
| 403 |
break; |
| 404 |
case GL_BLUE: |
| 405 |
red = 0; |
| 406 |
green = 0; |
| 407 |
blue = ((GLubyte*) image->Data)[pixel]; |
| 408 |
alpha = 255; |
| 409 |
break; |
| 410 |
case GL_ALPHA: |
| 411 |
red = 0; |
| 412 |
green = 0; |
| 413 |
blue = 0; |
| 414 |
alpha = ((GLubyte*) image->Data)[pixel]; |
| 415 |
break; |
| 416 |
case GL_LUMINANCE: |
| 417 |
red = ((GLubyte*) image->Data)[pixel]; |
| 418 |
green = red; |
| 419 |
blue = red; |
| 420 |
alpha = 255; |
| 421 |
break; |
| 422 |
case GL_LUMINANCE_ALPHA: |
| 423 |
red = ((GLubyte*) image->Data)[pixel*2+0]; |
| 424 |
green = red; |
| 425 |
blue = red; |
| 426 |
alpha = ((GLubyte*) image->Data)[pixel*2+1]; |
| 427 |
break; |
| 428 |
default: |
| 429 |
abort(); |
| 430 |
} |
| 431 |
|
| 432 |
if (scaleOrBias || ctx->Pixel.MapColorFlag) { |
| 433 |
/* Apply RGBA scale and bias */ |
| 434 |
GLfloat r = red * (1.0F/255.0F); |
| 435 |
GLfloat g = green * (1.0F/255.0F); |
| 436 |
GLfloat b = blue * (1.0F/255.0F); |
| 437 |
GLfloat a = alpha * (1.0F/255.0F); |
| 438 |
if (scaleOrBias) { |
| 439 |
/* r,g,b,a now in [0,1] */ |
| 440 |
r = r * ctx->Pixel.RedScale + ctx->Pixel.RedBias; |
| 441 |
g = g * ctx->Pixel.GreenScale + ctx->Pixel.GreenBias; |
| 442 |
b = b * ctx->Pixel.BlueScale + ctx->Pixel.BlueBias; |
| 443 |
a = a * ctx->Pixel.AlphaScale + ctx->Pixel.AlphaBias; |
| 444 |
r = CLAMP( r, 0.0F, 1.0F ); |
| 445 |
g = CLAMP( g, 0.0F, 1.0F ); |
| 446 |
b = CLAMP( b, 0.0F, 1.0F ); |
| 447 |
a = CLAMP( a, 0.0F, 1.0F ); |
| 448 |
} |
| 449 |
/* Apply pixel maps */ |
| 450 |
if (ctx->Pixel.MapColorFlag) { |
| 451 |
GLint ir = (GLint) (r*ctx->Pixel.MapRtoRsize); |
| 452 |
GLint ig = (GLint) (g*ctx->Pixel.MapGtoGsize); |
| 453 |
GLint ib = (GLint) (b*ctx->Pixel.MapBtoBsize); |
| 454 |
GLint ia = (GLint) (a*ctx->Pixel.MapAtoAsize); |
| 455 |
r = ctx->Pixel.MapRtoR[ir]; |
| 456 |
g = ctx->Pixel.MapGtoG[ig]; |
| 457 |
b = ctx->Pixel.MapBtoB[ib]; |
| 458 |
a = ctx->Pixel.MapAtoA[ia]; |
| 459 |
} |
| 460 |
red = (GLint) (r * 255.0F); |
| 461 |
green = (GLint) (g * 255.0F); |
| 462 |
blue = (GLint) (b * 255.0F); |
| 463 |
alpha = (GLint) (a * 255.0F); |
| 464 |
} |
| 465 |
|
| 466 |
/* store texel (components are GLubytes in [0,255]) */ |
| 467 |
switch (internalFormat) { |
| 468 |
case GL_ALPHA: |
| 469 |
texImage->Data[pixel] = alpha; |
| 470 |
break; |
| 471 |
case GL_LUMINANCE: |
| 472 |
texImage->Data[pixel] = red; |
| 473 |
break; |
| 474 |
case GL_LUMINANCE_ALPHA: |
| 475 |
texImage->Data[pixel*2+0] = red; |
| 476 |
texImage->Data[pixel*2+1] = alpha; |
| 477 |
break; |
| 478 |
case GL_INTENSITY: |
| 479 |
texImage->Data[pixel] = red; |
| 480 |
break; |
| 481 |
case GL_RGB: |
| 482 |
texImage->Data[pixel*3+0] = red; |
| 483 |
texImage->Data[pixel*3+1] = green; |
| 484 |
texImage->Data[pixel*3+2] = blue; |
| 485 |
break; |
| 486 |
case GL_RGBA: |
| 487 |
texImage->Data[pixel*4+0] = red; |
| 488 |
texImage->Data[pixel*4+1] = green; |
| 489 |
texImage->Data[pixel*4+2] = blue; |
| 490 |
texImage->Data[pixel*4+3] = alpha; |
| 491 |
break; |
| 492 |
default: |
| 493 |
abort(); |
| 494 |
} |
| 495 |
} |
| 496 |
break; |
| 497 |
|
| 498 |
case GL_FLOAT: |
| 499 |
for (pixel=0; pixel<numPixels; pixel++) { |
| 500 |
GLfloat red, green, blue, alpha; |
| 501 |
switch (image->Format) { |
| 502 |
case GL_COLOR_INDEX: |
| 503 |
{ |
| 504 |
GLint shift = ctx->Pixel.IndexShift; |
| 505 |
GLint offset = ctx->Pixel.IndexOffset; |
| 506 |
/* MapIto[RGBA]Size must be powers of two */ |
| 507 |
GLint rMask = ctx->Pixel.MapItoRsize-1; |
| 508 |
GLint gMask = ctx->Pixel.MapItoGsize-1; |
| 509 |
GLint bMask = ctx->Pixel.MapItoBsize-1; |
| 510 |
GLint aMask = ctx->Pixel.MapItoAsize-1; |
| 511 |
/* Fetch image color index */ |
| 512 |
GLint index = (GLint) ((GLfloat*) image->Data)[pixel]; |
| 513 |
/* apply index shift and offset */ |
| 514 |
if (shift>=0) { |
| 515 |
index = (index << shift) + offset; |
| 516 |
} |
| 517 |
else { |
| 518 |
index = (index >> -shift) + offset; |
| 519 |
} |
| 520 |
/* convert index to RGBA */ |
| 521 |
red = ctx->Pixel.MapItoR[index & rMask]; |
| 522 |
green = ctx->Pixel.MapItoG[index & gMask]; |
| 523 |
blue = ctx->Pixel.MapItoB[index & bMask]; |
| 524 |
alpha = ctx->Pixel.MapItoA[index & aMask]; |
| 525 |
} |
| 526 |
break; |
| 527 |
case GL_RGB: |
| 528 |
/* Fetch image RGBA values */ |
| 529 |
red = ((GLfloat*) image->Data)[pixel*3+0]; |
| 530 |
green = ((GLfloat*) image->Data)[pixel*3+1]; |
| 531 |
blue = ((GLfloat*) image->Data)[pixel*3+2]; |
| 532 |
alpha = 1.0; |
| 533 |
break; |
| 534 |
case GL_RGBA: |
| 535 |
red = ((GLfloat*) image->Data)[pixel*4+0]; |
| 536 |
green = ((GLfloat*) image->Data)[pixel*4+1]; |
| 537 |
blue = ((GLfloat*) image->Data)[pixel*4+2]; |
| 538 |
alpha = ((GLfloat*) image->Data)[pixel*4+3]; |
| 539 |
break; |
| 540 |
case GL_RED: |
| 541 |
red = ((GLfloat*) image->Data)[pixel]; |
| 542 |
green = 0.0; |
| 543 |
blue = 0.0; |
| 544 |
alpha = 1.0; |
| 545 |
break; |
| 546 |
case GL_GREEN: |
| 547 |
red = 0.0; |
| 548 |
green = ((GLfloat*) image->Data)[pixel]; |
| 549 |
blue = 0.0; |
| 550 |
alpha = 1.0; |
| 551 |
break; |
| 552 |
case GL_BLUE: |
| 553 |
red = 0.0; |
| 554 |
green = 0.0; |
| 555 |
blue = ((GLfloat*) image->Data)[pixel]; |
| 556 |
alpha = 1.0; |
| 557 |
break; |
| 558 |
case GL_ALPHA: |
| 559 |
red = 0.0; |
| 560 |
green = 0.0; |
| 561 |
blue = 0.0; |
| 562 |
alpha = ((GLfloat*) image->Data)[pixel]; |
| 563 |
break; |
| 564 |
case GL_LUMINANCE: |
| 565 |
red = ((GLfloat*) image->Data)[pixel]; |
| 566 |
green = red; |
| 567 |
blue = red; |
| 568 |
alpha = 1.0; |
| 569 |
break; |
| 570 |
case GL_LUMINANCE_ALPHA: |
| 571 |
red = ((GLfloat*) image->Data)[pixel*2+0]; |
| 572 |
green = red; |
| 573 |
blue = red; |
| 574 |
alpha = ((GLfloat*) image->Data)[pixel*2+1]; |
| 575 |
break; |
| 576 |
default: |
| 577 |
abort(); |
| 578 |
} |
| 579 |
|
| 580 |
if (image->Format!=GL_COLOR_INDEX) { |
| 581 |
/* Apply RGBA scale and bias */ |
| 582 |
if (scaleOrBias) { |
| 583 |
red = red * ctx->Pixel.RedScale + ctx->Pixel.RedBias; |
| 584 |
green = green * ctx->Pixel.GreenScale + ctx->Pixel.GreenBias; |
| 585 |
blue = blue * ctx->Pixel.BlueScale + ctx->Pixel.BlueBias; |
| 586 |
alpha = alpha * ctx->Pixel.AlphaScale + ctx->Pixel.AlphaBias; |
| 587 |
red = CLAMP( red, 0.0F, 1.0F ); |
| 588 |
green = CLAMP( green, 0.0F, 1.0F ); |
| 589 |
blue = CLAMP( blue, 0.0F, 1.0F ); |
| 590 |
alpha = CLAMP( alpha, 0.0F, 1.0F ); |
| 591 |
} |
| 592 |
/* Apply pixel maps */ |
| 593 |
if (ctx->Pixel.MapColorFlag) { |
| 594 |
GLint ir = (GLint) (red *ctx->Pixel.MapRtoRsize); |
| 595 |
GLint ig = (GLint) (green*ctx->Pixel.MapGtoGsize); |
| 596 |
GLint ib = (GLint) (blue *ctx->Pixel.MapBtoBsize); |
| 597 |
GLint ia = (GLint) (alpha*ctx->Pixel.MapAtoAsize); |
| 598 |
red = ctx->Pixel.MapRtoR[ir]; |
| 599 |
green = ctx->Pixel.MapGtoG[ig]; |
| 600 |
blue = ctx->Pixel.MapBtoB[ib]; |
| 601 |
alpha = ctx->Pixel.MapAtoA[ia]; |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
/* store texel (components are GLubytes in [0,255]) */ |
| 606 |
switch (internalFormat) { |
| 607 |
case GL_ALPHA: |
| 608 |
texImage->Data[pixel] = (GLint) (alpha * 255.0F); |
| 609 |
break; |
| 610 |
case GL_LUMINANCE: |
| 611 |
texImage->Data[pixel] = (GLint) (red * 255.0F); |
| 612 |
break; |
| 613 |
case GL_LUMINANCE_ALPHA: |
| 614 |
texImage->Data[pixel*2+0] = (GLint) (red * 255.0F); |
| 615 |
texImage->Data[pixel*2+1] = (GLint) (alpha * 255.0F); |
| 616 |
break; |
| 617 |
case GL_INTENSITY: |
| 618 |
texImage->Data[pixel] = (GLint) (red * 255.0F); |
| 619 |
break; |
| 620 |
case GL_RGB: |
| 621 |
texImage->Data[pixel*3+0] = (GLint) (red * 255.0F); |
| 622 |
texImage->Data[pixel*3+1] = (GLint) (green * 255.0F); |
| 623 |
texImage->Data[pixel*3+2] = (GLint) (blue * 255.0F); |
| 624 |
break; |
| 625 |
case GL_RGBA: |
| 626 |
texImage->Data[pixel*4+0] = (GLint) (red * 255.0F); |
| 627 |
texImage->Data[pixel*4+1] = (GLint) (green * 255.0F); |
| 628 |
texImage->Data[pixel*4+2] = (GLint) (blue * 255.0F); |
| 629 |
texImage->Data[pixel*4+3] = (GLint) (alpha * 255.0F); |
| 630 |
break; |
| 631 |
default: |
| 632 |
abort(); |
| 633 |
} |
| 634 |
} |
| 635 |
break; |
| 636 |
|
| 637 |
default: |
| 638 |
abort(); |
| 639 |
} |
| 640 |
|
| 641 |
return texImage; |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
/* |
| 648 |
* Test glTexImagee1D() parameters for errors. |
| 649 |
* Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 650 |
*/ |
| 651 |
static GLboolean texture_1d_error_check( GLcontext *ctx, GLenum target, |
| 652 |
GLint level, GLenum internalFormat, |
| 653 |
GLenum format, GLenum type, |
| 654 |
GLint width, GLint border ) |
| 655 |
{ |
| 656 |
GLint iformat; |
| 657 |
if (target!=GL_TEXTURE_1D && target!=GL_PROXY_TEXTURE_1D) { |
| 658 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D" ); |
| 659 |
return GL_TRUE; |
| 660 |
} |
| 661 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 662 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage1D(level)" ); |
| 663 |
return GL_TRUE; |
| 664 |
} |
| 665 |
iformat = decode_internal_format( internalFormat ); |
| 666 |
if (iformat<0) { |
| 667 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage1D(internalFormat)" ); |
| 668 |
return GL_TRUE; |
| 669 |
} |
| 670 |
if (border!=0 && border!=1) { |
| 671 |
if (target!=GL_PROXY_TEXTURE_1D) { |
| 672 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage1D(border)" ); |
| 673 |
} |
| 674 |
return GL_TRUE; |
| 675 |
} |
| 676 |
if (width<2*border || width>2+MAX_TEXTURE_SIZE) { |
| 677 |
if (target!=GL_PROXY_TEXTURE_1D) { |
| 678 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage1D(width)" ); |
| 679 |
} |
| 680 |
return GL_TRUE; |
| 681 |
} |
| 682 |
if (logbase2( width-2*border )<0) { |
| 683 |
gl_error( ctx, GL_INVALID_VALUE, |
| 684 |
"glTexImage1D(width != 2^k + 2*border)"); |
| 685 |
return GL_TRUE; |
| 686 |
} |
| 687 |
switch (format) { |
| 688 |
case GL_COLOR_INDEX: |
| 689 |
case GL_RED: |
| 690 |
case GL_GREEN: |
| 691 |
case GL_BLUE: |
| 692 |
case GL_ALPHA: |
| 693 |
case GL_RGB: |
| 694 |
case GL_RGBA: |
| 695 |
case GL_LUMINANCE: |
| 696 |
case GL_LUMINANCE_ALPHA: |
| 697 |
/* OK */ |
| 698 |
break; |
| 699 |
default: |
| 700 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(format)" ); |
| 701 |
return GL_TRUE; |
| 702 |
} |
| 703 |
switch (type) { |
| 704 |
case GL_UNSIGNED_BYTE: |
| 705 |
case GL_BYTE: |
| 706 |
case GL_UNSIGNED_SHORT: |
| 707 |
case GL_SHORT: |
| 708 |
case GL_FLOAT: |
| 709 |
/* OK */ |
| 710 |
break; |
| 711 |
default: |
| 712 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(type)" ); |
| 713 |
return GL_TRUE; |
| 714 |
} |
| 715 |
return GL_FALSE; |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
/* |
| 720 |
* Test glTexImagee2D() parameters for errors. |
| 721 |
* Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 722 |
*/ |
| 723 |
static GLboolean texture_2d_error_check( GLcontext *ctx, GLenum target, |
| 724 |
GLint level, GLenum internalFormat, |
| 725 |
GLenum format, GLenum type, |
| 726 |
GLint width, GLint height, |
| 727 |
GLint border ) |
| 728 |
{ |
| 729 |
GLint iformat; |
| 730 |
if (target!=GL_TEXTURE_2D && target!=GL_PROXY_TEXTURE_2D) { |
| 731 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); |
| 732 |
return GL_TRUE; |
| 733 |
} |
| 734 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 735 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(level)" ); |
| 736 |
return GL_TRUE; |
| 737 |
} |
| 738 |
iformat = decode_internal_format( internalFormat ); |
| 739 |
if (iformat<0) { |
| 740 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(internalFormat)" ); |
| 741 |
return GL_TRUE; |
| 742 |
} |
| 743 |
if (border!=0 && border!=1) { |
| 744 |
if (target!=GL_PROXY_TEXTURE_2D) { |
| 745 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(border)" ); |
| 746 |
} |
| 747 |
return GL_TRUE; |
| 748 |
} |
| 749 |
if (width<2*border || width>2+MAX_TEXTURE_SIZE) { |
| 750 |
if (target!=GL_PROXY_TEXTURE_2D) { |
| 751 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(width)" ); |
| 752 |
} |
| 753 |
return GL_TRUE; |
| 754 |
} |
| 755 |
if (height<2*border || height>2+MAX_TEXTURE_SIZE) { |
| 756 |
if (target!=GL_PROXY_TEXTURE_2D) { |
| 757 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(height)" ); |
| 758 |
} |
| 759 |
return GL_TRUE; |
| 760 |
} |
| 761 |
if (logbase2( width-2*border )<0) { |
| 762 |
gl_error( ctx,GL_INVALID_VALUE, |
| 763 |
"glTexImage2D(width != 2^k + 2*border)"); |
| 764 |
return GL_TRUE; |
| 765 |
} |
| 766 |
if (logbase2( height-2*border )<0) { |
| 767 |
gl_error( ctx,GL_INVALID_VALUE, |
| 768 |
"glTexImage2D(height != 2^k + 2*border)"); |
| 769 |
return GL_TRUE; |
| 770 |
} |
| 771 |
switch (format) { |
| 772 |
case GL_COLOR_INDEX: |
| 773 |
case GL_RED: |
| 774 |
case GL_GREEN: |
| 775 |
case GL_BLUE: |
| 776 |
case GL_ALPHA: |
| 777 |
case GL_RGB: |
| 778 |
case GL_RGBA: |
| 779 |
case GL_LUMINANCE: |
| 780 |
case GL_LUMINANCE_ALPHA: |
| 781 |
/* OK */ |
| 782 |
break; |
| 783 |
default: |
| 784 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(format)" ); |
| 785 |
return GL_TRUE; |
| 786 |
} |
| 787 |
switch (type) { |
| 788 |
case GL_UNSIGNED_BYTE: |
| 789 |
case GL_BYTE: |
| 790 |
case GL_UNSIGNED_SHORT: |
| 791 |
case GL_SHORT: |
| 792 |
case GL_UNSIGNED_INT: |
| 793 |
case GL_INT: |
| 794 |
case GL_FLOAT: |
| 795 |
/* OK */ |
| 796 |
break; |
| 797 |
default: |
| 798 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(type)" ); |
| 799 |
return GL_TRUE; |
| 800 |
} |
| 801 |
return GL_FALSE; |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
/* |
| 806 |
* Test glTexImage3DEXT() parameters for errors. |
| 807 |
* Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 808 |
*/ |
| 809 |
static GLboolean texture_3d_error_check( GLcontext *ctx, GLenum target, |
| 810 |
GLint level, GLenum internalFormat, |
| 811 |
GLenum format, GLenum type, |
| 812 |
GLint width, GLint height, |
| 813 |
GLint depth, GLint border ) |
| 814 |
{ |
| 815 |
GLint iformat; |
| 816 |
if (target!=GL_TEXTURE_3D_EXT && target!=GL_PROXY_TEXTURE_3D_EXT) { |
| 817 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage3DEXT(target)" ); |
| 818 |
return GL_TRUE; |
| 819 |
} |
| 820 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 821 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage3DEXT(level)" ); |
| 822 |
return GL_TRUE; |
| 823 |
} |
| 824 |
iformat = decode_internal_format( internalFormat ); |
| 825 |
if (iformat<0) { |
| 826 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage3DEXT(internalFormat)" ); |
| 827 |
return GL_TRUE; |
| 828 |
} |
| 829 |
if (border!=0 && border!=1) { |
| 830 |
if (target!=GL_PROXY_TEXTURE_3D_EXT) { |
| 831 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage3DEXT(border)" ); |
| 832 |
} |
| 833 |
return GL_TRUE; |
| 834 |
} |
| 835 |
if (width<2*border || width>2+MAX_TEXTURE_SIZE) { |
| 836 |
if (target!=GL_PROXY_TEXTURE_3D_EXT) { |
| 837 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage3DEXT(width)" ); |
| 838 |
} |
| 839 |
return GL_TRUE; |
| 840 |
} |
| 841 |
if (height<2*border || height>2+MAX_TEXTURE_SIZE) { |
| 842 |
if (target!=GL_PROXY_TEXTURE_3D_EXT) { |
| 843 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage3DEXT(height)" ); |
| 844 |
} |
| 845 |
return GL_TRUE; |
| 846 |
} |
| 847 |
if (depth<2*border || depth>2+MAX_TEXTURE_SIZE) { |
| 848 |
if (target!=GL_PROXY_TEXTURE_3D_EXT) { |
| 849 |
gl_error( ctx, GL_INVALID_VALUE, "glTexImage3DEXT(depth)" ); |
| 850 |
} |
| 851 |
return GL_TRUE; |
| 852 |
} |
| 853 |
if (logbase2( width-2*border )<0) { |
| 854 |
gl_error( ctx,GL_INVALID_VALUE, |
| 855 |
"glTexImage3DEXT(width != 2^k + 2*border))"); |
| 856 |
return GL_TRUE; |
| 857 |
} |
| 858 |
if (logbase2( height-2*border )<0) { |
| 859 |
gl_error( ctx,GL_INVALID_VALUE, |
| 860 |
"glTexImage3DEXT(height != 2^k + 2*border))"); |
| 861 |
return GL_TRUE; |
| 862 |
} |
| 863 |
if (logbase2( depth-2*border )<0) { |
| 864 |
gl_error( ctx,GL_INVALID_VALUE, |
| 865 |
"glTexImage3DEXT(depth != 2^k + 2*border))"); |
| 866 |
return GL_TRUE; |
| 867 |
} |
| 868 |
switch (format) { |
| 869 |
case GL_COLOR_INDEX: |
| 870 |
case GL_RED: |
| 871 |
case GL_GREEN: |
| 872 |
case GL_BLUE: |
| 873 |
case GL_ALPHA: |
| 874 |
case GL_RGB: |
| 875 |
case GL_RGBA: |
| 876 |
case GL_LUMINANCE: |
| 877 |
case GL_LUMINANCE_ALPHA: |
| 878 |
/* OK */ |
| 879 |
break; |
| 880 |
default: |
| 881 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage3DEXT(format)" ); |
| 882 |
return GL_TRUE; |
| 883 |
} |
| 884 |
switch (type) { |
| 885 |
case GL_UNSIGNED_BYTE: |
| 886 |
case GL_BYTE: |
| 887 |
case GL_UNSIGNED_SHORT: |
| 888 |
case GL_SHORT: |
| 889 |
case GL_UNSIGNED_INT: |
| 890 |
case GL_INT: |
| 891 |
case GL_FLOAT: |
| 892 |
/* OK */ |
| 893 |
break; |
| 894 |
default: |
| 895 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage3DEXT(type)" ); |
| 896 |
return GL_TRUE; |
| 897 |
} |
| 898 |
return GL_FALSE; |
| 899 |
} |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
/* |
| 904 |
* Called from the API. Note that width includes the border. |
| 905 |
*/ |
| 906 |
void gl_TexImage1D( GLcontext *ctx, |
| 907 |
GLenum target, GLint level, GLint internalformat, |
| 908 |
GLsizei width, GLint border, GLenum format, |
| 909 |
GLenum type, struct gl_image *image ) |
| 910 |
{ |
| 911 |
if (INSIDE_BEGIN_END(ctx)) { |
| 912 |
gl_error( ctx, GL_INVALID_OPERATION, "glTexImage1D" ); |
| 913 |
return; |
| 914 |
} |
| 915 |
|
| 916 |
if (image) { |
| 917 |
/* if image is not NULL then it's probably valid... */ |
| 918 |
if (target==GL_TEXTURE_1D) { |
| 919 |
struct gl_texture_image *teximage; |
| 920 |
if (texture_1d_error_check( ctx, target, level, internalformat, |
| 921 |
format, type, width, border )) { |
| 922 |
/* error in texture image was detected */ |
| 923 |
return; |
| 924 |
} |
| 925 |
/* free current texture image, if any */ |
| 926 |
if (ctx->Texture.Current1D->Image[level]) { |
| 927 |
gl_free_texture_image( ctx->Texture.Current1D->Image[level] ); |
| 928 |
} |
| 929 |
/* install new texture image */ |
| 930 |
teximage = gl_image_to_texture( ctx, image, internalformat, border ); |
| 931 |
if (image->RefCount==0) { |
| 932 |
/* if RefCount==1 then image must be in a display list */ |
| 933 |
gl_free_image(image); |
| 934 |
} |
| 935 |
ctx->Texture.Current1D->Image[level] = teximage; |
| 936 |
ctx->NewState |= NEW_TEXTURING; |
| 937 |
|
| 938 |
/* Send texture image to device driver */ |
| 939 |
if (ctx->Driver.TexImage) { |
| 940 |
(*ctx->Driver.TexImage)( ctx, GL_TEXTURE_1D, |
| 941 |
ctx->Texture.Current1D->Name, |
| 942 |
level, internalformat, teximage ); |
| 943 |
} |
| 944 |
} |
| 945 |
else if (target==GL_PROXY_TEXTURE_1D) { |
| 946 |
/* Proxy texture: check for errors and update proxy state */ |
| 947 |
if (texture_1d_error_check( ctx, target, level, internalformat, |
| 948 |
format, type, width, border )) { |
| 949 |
if (level>=0 && level<MAX_TEXTURE_LEVELS) { |
| 950 |
MEMSET( ctx->Texture.Proxy1D->Image[level], 0, |
| 951 |
sizeof(struct gl_texture_image) ); |
| 952 |
} |
| 953 |
} |
| 954 |
else { |
| 955 |
ctx->Texture.Proxy1D->Image[level]->Format = internalformat; |
| 956 |
ctx->Texture.Proxy1D->Image[level]->Border = border; |
| 957 |
ctx->Texture.Proxy1D->Image[level]->Width = width; |
| 958 |
ctx->Texture.Proxy1D->Image[level]->Height = 1; |
| 959 |
} |
| 960 |
if (image->RefCount==0) { |
| 961 |
/* if RefCount==1 then image must be in a display list */ |
| 962 |
gl_free_image(image); |
| 963 |
} |
| 964 |
} |
| 965 |
else { |
| 966 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); |
| 967 |
return; |
| 968 |
} |
| 969 |
} |
| 970 |
else { |
| 971 |
/* An error must have occured during texture unpacking. Record the |
| 972 |
* error now. |
| 973 |
*/ |
| 974 |
(void) texture_1d_error_check( ctx, target, level, internalformat, |
| 975 |
format, type, width, border ); |
| 976 |
} |
| 977 |
} |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
/* |
| 983 |
* Called by the API or display list executor. |
| 984 |
* Note that width and height include the border. |
| 985 |
*/ |
| 986 |
void gl_TexImage2D( GLcontext *ctx, |
| 987 |
GLenum target, GLint level, GLint internalformat, |
| 988 |
GLsizei width, GLsizei height, GLint border, |
| 989 |
GLenum format, GLenum type, |
| 990 |
struct gl_image *image ) |
| 991 |
{ |
| 992 |
if (INSIDE_BEGIN_END(ctx)) { |
| 993 |
gl_error( ctx, GL_INVALID_OPERATION, "glTexImage2D" ); |
| 994 |
return; |
| 995 |
} |
| 996 |
|
| 997 |
if (image) { |
| 998 |
/* if image is not NULL then it's probably valid... */ |
| 999 |
if (target==GL_TEXTURE_2D) { |
| 1000 |
struct gl_texture_image *teximage; |
| 1001 |
if (texture_2d_error_check( ctx, target, level, internalformat, |
| 1002 |
format, type, width, height, border )) { |
| 1003 |
/* error in texture image was detected */ |
| 1004 |
return; |
| 1005 |
} |
| 1006 |
/* free current texture image, if any */ |
| 1007 |
if (ctx->Texture.Current2D->Image[level]) { |
| 1008 |
gl_free_texture_image( ctx->Texture.Current2D->Image[level] ); |
| 1009 |
} |
| 1010 |
/* install new texture image */ |
| 1011 |
teximage = gl_image_to_texture( ctx, image, internalformat, border ); |
| 1012 |
if (image->RefCount==0) { |
| 1013 |
/* if RefCount==1 then image must be in a display list */ |
| 1014 |
gl_free_image(image); |
| 1015 |
} |
| 1016 |
ctx->Texture.Current2D->Image[level] = teximage; |
| 1017 |
ctx->NewState |= NEW_TEXTURING; |
| 1018 |
|
| 1019 |
/* Send texture image to device driver */ |
| 1020 |
if (ctx->Driver.TexImage) { |
| 1021 |
(*ctx->Driver.TexImage)( ctx, GL_TEXTURE_2D, |
| 1022 |
ctx->Texture.Current2D->Name, |
| 1023 |
level, internalformat, teximage ); |
| 1024 |
} |
| 1025 |
} |
| 1026 |
else if (target==GL_PROXY_TEXTURE_2D) { |
| 1027 |
/* Proxy texture: check for errors and update proxy state */ |
| 1028 |
if (texture_2d_error_check( ctx, target, level, internalformat, |
| 1029 |
format, type, width, height, border )) { |
| 1030 |
if (level>=0 && level<MAX_TEXTURE_LEVELS) { |
| 1031 |
MEMSET( ctx->Texture.Proxy2D->Image[level], 0, |
| 1032 |
sizeof(struct gl_texture_image) ); |
| 1033 |
} |
| 1034 |
} |
| 1035 |
else { |
| 1036 |
ctx->Texture.Proxy2D->Image[level]->Format = internalformat; |
| 1037 |
ctx->Texture.Proxy2D->Image[level]->Border = border; |
| 1038 |
ctx->Texture.Proxy2D->Image[level]->Width = width; |
| 1039 |
ctx->Texture.Proxy2D->Image[level]->Height = height; |
| 1040 |
} |
| 1041 |
if (image->RefCount==0) { |
| 1042 |
/* if RefCount==1 then image must be in a display list */ |
| 1043 |
gl_free_image(image); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
else { |
| 1047 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); |
| 1048 |
return; |
| 1049 |
} |
| 1050 |
} |
| 1051 |
else { |
| 1052 |
/* |
| 1053 |
* An error must have occured during texture unpacking. |
| 1054 |
* Take care of reporting the error now. |
| 1055 |
*/ |
| 1056 |
(void) texture_2d_error_check( ctx, target, level, internalformat, |
| 1057 |
format, type, width, height, border ); |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
/* |
| 1064 |
* Called by the API or display list executor. |
| 1065 |
* Note that width and height include the border. |
| 1066 |
*/ |
| 1067 |
void gl_TexImage3DEXT( GLcontext *ctx, |
| 1068 |
GLenum target, GLint level, GLint internalformat, |
| 1069 |
GLsizei width, GLsizei height, GLsizei depth, |
| 1070 |
GLint border, GLenum format, GLenum type, |
| 1071 |
struct gl_image *image ) |
| 1072 |
{ |
| 1073 |
if (INSIDE_BEGIN_END(ctx)) { |
| 1074 |
gl_error( ctx, GL_INVALID_OPERATION, "glTexImage3DEXT" ); |
| 1075 |
return; |
| 1076 |
} |
| 1077 |
|
| 1078 |
if (image) { |
| 1079 |
/* if image is not NULL then it must be valid */ |
| 1080 |
if (target==GL_TEXTURE_3D_EXT) { |
| 1081 |
struct gl_texture_image *teximage; |
| 1082 |
if (texture_3d_error_check( ctx, target, level, internalformat, |
| 1083 |
format, type, width, height, depth, |
| 1084 |
border )) { |
| 1085 |
/* error in texture image was detected */ |
| 1086 |
return; |
| 1087 |
} |
| 1088 |
/* free current texture image, if any */ |
| 1089 |
if (ctx->Texture.Current3D->Image[level]) { |
| 1090 |
gl_free_texture_image( ctx->Texture.Current3D->Image[level] ); |
| 1091 |
} |
| 1092 |
/* install new texture image */ |
| 1093 |
teximage = gl_image_to_texture( ctx, image, internalformat, border ); |
| 1094 |
if (image->RefCount==0) { |
| 1095 |
/* if RefCount==1 then image must be in a display list */ |
| 1096 |
gl_free_image(image); |
| 1097 |
} |
| 1098 |
ctx->Texture.Current3D->Image[level] = teximage; |
| 1099 |
ctx->NewState |= NEW_TEXTURING; |
| 1100 |
|
| 1101 |
/* Send texture image to device driver */ |
| 1102 |
/* TODO: device driver 3-D texture function */ |
| 1103 |
} |
| 1104 |
else if (target==GL_PROXY_TEXTURE_3D_EXT) { |
| 1105 |
/* Proxy texture: check for errors and update proxy state */ |
| 1106 |
if (texture_3d_error_check( ctx, target, level, internalformat, |
| 1107 |
format, type, width, height, depth, |
| 1108 |
border )) { |
| 1109 |
if (level>=0 && level<MAX_TEXTURE_LEVELS) { |
| 1110 |
MEMSET( ctx->Texture.Proxy3D->Image[level], 0, |
| 1111 |
sizeof(struct gl_texture_image) ); |
| 1112 |
} |
| 1113 |
} |
| 1114 |
else { |
| 1115 |
ctx->Texture.Proxy3D->Image[level]->Format = internalformat; |
| 1116 |
ctx->Texture.Proxy3D->Image[level]->Border = border; |
| 1117 |
ctx->Texture.Proxy3D->Image[level]->Width = width; |
| 1118 |
ctx->Texture.Proxy3D->Image[level]->Height = height; |
| 1119 |
ctx->Texture.Proxy3D->Image[level]->Depth = depth; |
| 1120 |
} |
| 1121 |
if (image->RefCount==0) { |
| 1122 |
/* if RefCount==1 then image must be in a display list */ |
| 1123 |
gl_free_image(image); |
| 1124 |
} |
| 1125 |
} |
| 1126 |
else { |
| 1127 |
gl_error( ctx, GL_INVALID_ENUM, "glTexImage3DEXT(target)" ); |
| 1128 |
return; |
| 1129 |
} |
| 1130 |
} |
| 1131 |
else { |
| 1132 |
/* |
| 1133 |
* An error must have occured during texture unpacking. |
| 1134 |
* Take care of reporting the error now. |
| 1135 |
*/ |
| 1136 |
(void) texture_3d_error_check( ctx, target, level, internalformat, |
| 1137 |
format, type, width, height, depth, |
| 1138 |
border ); |
| 1139 |
} |
| 1140 |
} |
| 1141 |
|
| 1142 |
|
| 1143 |
void gl_GetTexImage( GLcontext *ctx, GLenum target, GLint level, GLenum format, |
| 1144 |
GLenum type, GLvoid *pixels ) |
| 1145 |
{ |
| 1146 |
/* TODO */ |
| 1147 |
} |
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
/* |
| 1154 |
* GL_EXT_copy_texture |
| 1155 |
*/ |
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
/* |
| 1160 |
* Unpack the image data given to glTexSubImage[12]D. |
| 1161 |
*/ |
| 1162 |
struct gl_image * |
| 1163 |
gl_unpack_texsubimage( GLcontext *ctx, GLint width, GLint height, |
| 1164 |
GLenum format, GLenum type, const GLvoid *pixels ) |
| 1165 |
{ |
| 1166 |
GLint components; |
| 1167 |
GLenum desttype; |
| 1168 |
|
| 1169 |
if (width<0 || height<0 || !pixels) { |
| 1170 |
return NULL; |
| 1171 |
} |
| 1172 |
|
| 1173 |
if (type==GL_BITMAP && format!=GL_COLOR_INDEX) { |
| 1174 |
return NULL; |
| 1175 |
} |
| 1176 |
|
| 1177 |
components = components_in_intformat( format ); |
| 1178 |
if (components<0 || format==GL_STENCIL_INDEX || format==GL_DEPTH_COMPONENT){ |
| 1179 |
return NULL; |
| 1180 |
} |
| 1181 |
|
| 1182 |
if (gl_sizeof_type(type)<=0) { |
| 1183 |
return NULL; |
| 1184 |
} |
| 1185 |
|
| 1186 |
if (type==GL_UNSIGNED_BYTE) { |
| 1187 |
desttype = GL_UNSIGNED_BYTE; |
| 1188 |
} |
| 1189 |
else { |
| 1190 |
desttype = GL_FLOAT; |
| 1191 |
} |
| 1192 |
|
| 1193 |
return gl_unpack_image( ctx, width, height, format, type, |
| 1194 |
desttype, pixels, GL_FALSE ); |
| 1195 |
} |
| 1196 |
|
| 1197 |
|
| 1198 |
/* |
| 1199 |
* Unpack the image data given to glTexSubImage3D. |
| 1200 |
*/ |
| 1201 |
struct gl_image * |
| 1202 |
gl_unpack_texsubimage3D( GLcontext *ctx, GLint width, GLint height, |
| 1203 |
GLint depth, GLenum format, GLenum type, |
| 1204 |
const GLvoid *pixels ) |
| 1205 |
{ |
| 1206 |
GLint components; |
| 1207 |
GLenum desttype; |
| 1208 |
|
| 1209 |
if (width<0 || height<0 || depth<0 || !pixels) { |
| 1210 |
return NULL; |
| 1211 |
} |
| 1212 |
|
| 1213 |
if (type==GL_BITMAP && format!=GL_COLOR_INDEX) { |
| 1214 |
return NULL; |
| 1215 |
} |
| 1216 |
|
| 1217 |
components = components_in_intformat( format ); |
| 1218 |
if (components<0 || format==GL_STENCIL_INDEX || format==GL_DEPTH_COMPONENT) { |
| 1219 |
return NULL; |
| 1220 |
} |
| 1221 |
|
| 1222 |
if (gl_sizeof_type(type)<=0) { |
| 1223 |
return NULL; |
| 1224 |
} |
| 1225 |
|
| 1226 |
if (type==GL_UNSIGNED_BYTE) { |
| 1227 |
desttype = GL_UNSIGNED_BYTE; |
| 1228 |
} |
| 1229 |
else { |
| 1230 |
desttype = GL_FLOAT; |
| 1231 |
} |
| 1232 |
|
| 1233 |
return gl_unpack_image3D( ctx, width, height, depth, format, type, |
| 1234 |
desttype, pixels, GL_FALSE ); |
| 1235 |
} |
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
void gl_TexSubImage1D( GLcontext *ctx, |
| 1240 |
GLenum target, GLint level, GLint xoffset, |
| 1241 |
GLsizei width, GLenum format, GLenum type, |
| 1242 |
struct gl_image *image ) |
| 1243 |
{ |
| 1244 |
struct gl_texture_image *teximage; |
| 1245 |
|
| 1246 |
if (target!=GL_TEXTURE_1D) { |
| 1247 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); |
| 1248 |
return; |
| 1249 |
} |
| 1250 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 1251 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(level)" ); |
| 1252 |
return; |
| 1253 |
} |
| 1254 |
|
| 1255 |
teximage = ctx->Texture.Current1D->Image[level]; |
| 1256 |
if (!teximage) { |
| 1257 |
gl_error( ctx, GL_INVALID_OPERATION, "glTexSubImage1D" ); |
| 1258 |
return; |
| 1259 |
} |
| 1260 |
|
| 1261 |
if (xoffset < -teximage->Border) { |
| 1262 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage1D(xoffset)" ); |
| 1263 |
return; |
| 1264 |
} |
| 1265 |
if (xoffset + width > teximage->Width+teximage->Border) { |
| 1266 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage1D(xoffset+width)" ); |
| 1267 |
return; |
| 1268 |
} |
| 1269 |
|
| 1270 |
if (image) { |
| 1271 |
/* unpacking must have been error-free */ |
| 1272 |
GLint texcomponents, i, k; |
| 1273 |
GLubyte *dst, *src; |
| 1274 |
|
| 1275 |
/* TODO: this is temporary. If Type==GL_FLOAT or scale&bias needed */ |
| 1276 |
/* then do more work. */ |
| 1277 |
if (image->Type==GL_FLOAT) { |
| 1278 |
gl_problem( ctx, "unimplemented texture type in glTexSubImage1D" ); |
| 1279 |
return; |
| 1280 |
} |
| 1281 |
|
| 1282 |
texcomponents = components_in_intformat(teximage->Format); |
| 1283 |
|
| 1284 |
dst = teximage->Data + texcomponents * xoffset; |
| 1285 |
|
| 1286 |
if (texcomponents == image->Components) { |
| 1287 |
MEMCPY( dst, image->Data, width * texcomponents ); |
| 1288 |
} |
| 1289 |
else { |
| 1290 |
/* TODO: this is a hack */ |
| 1291 |
gl_problem( ctx, "component mismatch in glTexSubImage1D" ); |
| 1292 |
for (i=0;i<width;i++) { |
| 1293 |
for (k=0;k<texcomponents;k++) { |
| 1294 |
dst[k] = src[k]; |
| 1295 |
} |
| 1296 |
dst += texcomponents; |
| 1297 |
src += image->Components; |
| 1298 |
} |
| 1299 |
} |
| 1300 |
} |
| 1301 |
else { |
| 1302 |
/* if no image, an error must have occured, do more testing now */ |
| 1303 |
GLint components, size; |
| 1304 |
|
| 1305 |
if (width<0) { |
| 1306 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage1D(width)" ); |
| 1307 |
return; |
| 1308 |
} |
| 1309 |
if (type==GL_BITMAP && format!=GL_COLOR_INDEX) { |
| 1310 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(format)" ); |
| 1311 |
return; |
| 1312 |
} |
| 1313 |
components = components_in_intformat( format ); |
| 1314 |
if (components<0 || format==GL_STENCIL_INDEX |
| 1315 |
|| format==GL_DEPTH_COMPONENT){ |
| 1316 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(format)" ); |
| 1317 |
return; |
| 1318 |
} |
| 1319 |
size = gl_sizeof_type( type ); |
| 1320 |
if (size<=0) { |
| 1321 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(type)" ); |
| 1322 |
return; |
| 1323 |
} |
| 1324 |
/* if we get here, probably ran out of memory during unpacking */ |
| 1325 |
gl_error( ctx, GL_OUT_OF_MEMORY, "glTexSubImage1D" ); |
| 1326 |
} |
| 1327 |
} |
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
void gl_TexSubImage2D( GLcontext *ctx, |
| 1332 |
GLenum target, GLint level, |
| 1333 |
GLint xoffset, GLint yoffset, |
| 1334 |
GLsizei width, GLsizei height, |
| 1335 |
GLenum format, GLenum type, |
| 1336 |
struct gl_image *image ) |
| 1337 |
{ |
| 1338 |
struct gl_texture_image *teximage; |
| 1339 |
|
| 1340 |
if (target!=GL_TEXTURE_2D) { |
| 1341 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); |
| 1342 |
return; |
| 1343 |
} |
| 1344 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 1345 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(level)" ); |
| 1346 |
return; |
| 1347 |
} |
| 1348 |
|
| 1349 |
teximage = ctx->Texture.Current2D->Image[level]; |
| 1350 |
if (!teximage) { |
| 1351 |
gl_error( ctx, GL_INVALID_OPERATION, "glTexSubImage2D" ); |
| 1352 |
return; |
| 1353 |
} |
| 1354 |
|
| 1355 |
if (xoffset < -teximage->Border) { |
| 1356 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(xoffset)" ); |
| 1357 |
return; |
| 1358 |
} |
| 1359 |
if (yoffset < -teximage->Border) { |
| 1360 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(yoffset)" ); |
| 1361 |
return; |
| 1362 |
} |
| 1363 |
if (xoffset + width > teximage->Width+teximage->Border) { |
| 1364 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(xoffset+width)" ); |
| 1365 |
return; |
| 1366 |
} |
| 1367 |
if (yoffset + height > teximage->Height+teximage->Border) { |
| 1368 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(yoffset+height)" ); |
| 1369 |
return; |
| 1370 |
} |
| 1371 |
|
| 1372 |
if (image) { |
| 1373 |
/* unpacking must have been error-free */ |
| 1374 |
GLint texcomponents, i, j, k; |
| 1375 |
GLubyte *dst, *src; |
| 1376 |
|
| 1377 |
/* TODO: this is temporary. If Type==GL_FLOAT or scale&bias needed */ |
| 1378 |
/* then do more work. */ |
| 1379 |
if (image->Type==GL_FLOAT) { |
| 1380 |
gl_problem( ctx, "unimplemented texture type in glTexSubImage2D" ); |
| 1381 |
return; |
| 1382 |
} |
| 1383 |
|
| 1384 |
texcomponents = components_in_intformat(teximage->Format); |
| 1385 |
|
| 1386 |
if (texcomponents == image->Components) { |
| 1387 |
dst = teximage->Data |
| 1388 |
+ (yoffset * teximage->Width + xoffset) * texcomponents; |
| 1389 |
src = image->Data; |
| 1390 |
for (j=0;j<height;j++) { |
| 1391 |
MEMCPY( dst, src, width * texcomponents ); |
| 1392 |
dst += teximage->Width * texcomponents; |
| 1393 |
src += width * texcomponents; |
| 1394 |
} |
| 1395 |
} |
| 1396 |
else { |
| 1397 |
/* TODO: this is a hack */ |
| 1398 |
gl_problem( ctx, "component mismatch in glTexSubImage2D" ); |
| 1399 |
|
| 1400 |
for (j=0;j<height;j++) { |
| 1401 |
dst = teximage->Data |
| 1402 |
+ ((yoffset+j) * teximage->Width + xoffset) * texcomponents; |
| 1403 |
src = (GLubyte *) image->Data + j * width * image->Components; |
| 1404 |
for (i=0;i<width;i++) { |
| 1405 |
for (k=0;k<texcomponents;k++) { |
| 1406 |
dst[k] = src[k]; |
| 1407 |
} |
| 1408 |
dst += texcomponents; |
| 1409 |
src += image->Components; |
| 1410 |
} |
| 1411 |
} |
| 1412 |
} |
| 1413 |
} |
| 1414 |
else { |
| 1415 |
/* if no image, an error must have occured, do more testing now */ |
| 1416 |
GLint components, size; |
| 1417 |
|
| 1418 |
if (width<0) { |
| 1419 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(width)" ); |
| 1420 |
return; |
| 1421 |
} |
| 1422 |
if (height<0) { |
| 1423 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(height)" ); |
| 1424 |
return; |
| 1425 |
} |
| 1426 |
if (type==GL_BITMAP && format!=GL_COLOR_INDEX) { |
| 1427 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(format)" ); |
| 1428 |
return; |
| 1429 |
} |
| 1430 |
components = components_in_intformat( format ); |
| 1431 |
if (components<0 || format==GL_STENCIL_INDEX |
| 1432 |
|| format==GL_DEPTH_COMPONENT){ |
| 1433 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(format)" ); |
| 1434 |
return; |
| 1435 |
} |
| 1436 |
size = gl_sizeof_type( type ); |
| 1437 |
if (size<=0) { |
| 1438 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(type)" ); |
| 1439 |
return; |
| 1440 |
} |
| 1441 |
/* if we get here, probably ran out of memory during unpacking */ |
| 1442 |
gl_error( ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D" ); |
| 1443 |
} |
| 1444 |
} |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
void gl_TexSubImage3DEXT( GLcontext *ctx, |
| 1449 |
GLenum target, GLint level, |
| 1450 |
GLint xoffset, GLint yoffset, GLint zoffset, |
| 1451 |
GLsizei width, GLsizei height, GLsizei depth, |
| 1452 |
GLenum format, GLenum type, |
| 1453 |
struct gl_image *image ) |
| 1454 |
{ |
| 1455 |
struct gl_texture_image *teximage; |
| 1456 |
|
| 1457 |
if (target!=GL_TEXTURE_3D_EXT) { |
| 1458 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3DEXT(target)" ); |
| 1459 |
return; |
| 1460 |
} |
| 1461 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 1462 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3DEXT(level)" ); |
| 1463 |
return; |
| 1464 |
} |
| 1465 |
|
| 1466 |
teximage = ctx->Texture.Current3D->Image[level]; |
| 1467 |
if (!teximage) { |
| 1468 |
gl_error( ctx, GL_INVALID_OPERATION, "glTexSubImage3DEXT" ); |
| 1469 |
return; |
| 1470 |
} |
| 1471 |
|
| 1472 |
if (xoffset < -teximage->Border) { |
| 1473 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage3DEXT(xoffset)" ); |
| 1474 |
return; |
| 1475 |
} |
| 1476 |
if (yoffset < -teximage->Border) { |
| 1477 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage3DEXT(yoffset)" ); |
| 1478 |
return; |
| 1479 |
} |
| 1480 |
if (zoffset < -teximage->Border) { |
| 1481 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage3DEXT(zoffset)" ); |
| 1482 |
return; |
| 1483 |
} |
| 1484 |
if (xoffset + width > teximage->Width+teximage->Border) { |
| 1485 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage3DEXT(xoffset+width)" ); |
| 1486 |
return; |
| 1487 |
} |
| 1488 |
if (yoffset + height > teximage->Height+teximage->Border) { |
| 1489 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage3DEXT(yoffset+height)" ); |
| 1490 |
return; |
| 1491 |
} |
| 1492 |
if (zoffset + depth > teximage->Depth+teximage->Border) { |
| 1493 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage3DEXT(zoffset+depth)" ); |
| 1494 |
return; |
| 1495 |
} |
| 1496 |
|
| 1497 |
if (image) { |
| 1498 |
/* unpacking must have been error-free */ |
| 1499 |
GLint texcomponents, i, j, k, rectarea; |
| 1500 |
GLubyte *dst, *src; |
| 1501 |
|
| 1502 |
/* TODO: this is temporary. If Type==GL_FLOAT or scale&bias needed */ |
| 1503 |
/* then do more work. */ |
| 1504 |
if (image->Type==GL_FLOAT) { |
| 1505 |
gl_problem( ctx, "unimplemented texture type in glTexSubImagDEXT" ); |
| 1506 |
return; |
| 1507 |
} |
| 1508 |
|
| 1509 |
texcomponents = components_in_intformat(teximage->Format); |
| 1510 |
rectarea=teximage->Width * teximage->Height; |
| 1511 |
|
| 1512 |
if (texcomponents == image->Components) { |
| 1513 |
dst = teximage->Data |
| 1514 |
+ (zoffset * rectarea + yoffset * teximage->Width + xoffset) |
| 1515 |
* texcomponents; |
| 1516 |
src = image->Data; |
| 1517 |
for(k=0;k<depth; k++) { |
| 1518 |
for (j=0;j<height;j++) { |
| 1519 |
MEMCPY( dst, src, width * texcomponents ); |
| 1520 |
dst += teximage->Width * texcomponents; |
| 1521 |
src += width * texcomponents; |
| 1522 |
} |
| 1523 |
dst += rectarea * texcomponents; |
| 1524 |
src += rectarea * texcomponents; |
| 1525 |
} |
| 1526 |
} |
| 1527 |
else { |
| 1528 |
/* TODO: this is a hack */ |
| 1529 |
GLint l, trarea, tzoffset, tloffset; |
| 1530 |
|
| 1531 |
gl_problem( ctx, "component mismatch in glTexSubImage3DEXT" ); |
| 1532 |
trarea=width*depth * image->Components; |
| 1533 |
for (l=0; l<depth; l++) { |
| 1534 |
tzoffset=(zoffset+l) * rectarea; |
| 1535 |
tloffset=l * trarea; |
| 1536 |
for (j=0;j<height;j++) { |
| 1537 |
dst = teximage->Data |
| 1538 |
+ (tzoffset + (yoffset+j) * teximage->Width + xoffset) |
| 1539 |
* texcomponents; |
| 1540 |
src = (GLubyte *) image->Data + tloffset + j * width * image->Components; |
| 1541 |
for (i=0;i<width;i++) { |
| 1542 |
for (k=0;k<texcomponents;k++) { |
| 1543 |
dst[k] = src[k]; |
| 1544 |
} |
| 1545 |
dst += texcomponents; |
| 1546 |
src += image->Components; |
| 1547 |
} |
| 1548 |
} |
| 1549 |
} |
| 1550 |
} |
| 1551 |
} |
| 1552 |
else { |
| 1553 |
/* if no image, an error must have occured, do more testing now */ |
| 1554 |
GLint components, size; |
| 1555 |
|
| 1556 |
if (width<0) { |
| 1557 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage3DEXT(width)" ); |
| 1558 |
return; |
| 1559 |
} |
| 1560 |
if (height<0) { |
| 1561 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage3DEXT(height)" ); |
| 1562 |
return; |
| 1563 |
} |
| 1564 |
if (depth<0) { |
| 1565 |
gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage3DEXT(depth)" ); |
| 1566 |
return; |
| 1567 |
} |
| 1568 |
if (type==GL_BITMAP && format!=GL_COLOR_INDEX) { |
| 1569 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3DEXT(format)" ); |
| 1570 |
return; |
| 1571 |
} |
| 1572 |
components = components_in_intformat( format ); |
| 1573 |
if (components<0 || format==GL_STENCIL_INDEX |
| 1574 |
|| format==GL_DEPTH_COMPONENT){ |
| 1575 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3DEXT(format)" ); |
| 1576 |
return; |
| 1577 |
} |
| 1578 |
size = gl_sizeof_type( type ); |
| 1579 |
if (size<=0) { |
| 1580 |
gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3DEXT(type)" ); |
| 1581 |
return; |
| 1582 |
} |
| 1583 |
/* if we get here, probably ran out of memory during unpacking */ |
| 1584 |
gl_error( ctx, GL_OUT_OF_MEMORY, "glTexSubImage3DEXT" ); |
| 1585 |
} |
| 1586 |
} |
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
/* |
| 1591 |
* Read an RGBA image from the frame buffer. |
| 1592 |
* Input: ctx - the context |
| 1593 |
* x, y - lower left corner |
| 1594 |
* width, height - size of region to read |
| 1595 |
* format - one of GL_RED, GL_RGB, GL_LUMINANCE, etc. |
| 1596 |
* Return: gl_image pointer or NULL if out of memory |
| 1597 |
*/ |
| 1598 |
struct gl_image *gl_read_color_image( GLcontext *ctx, GLint x, GLint y, |
| 1599 |
GLsizei width, GLsizei height, |
| 1600 |
GLint format ) |
| 1601 |
{ |
| 1602 |
struct gl_image *image; |
| 1603 |
GLubyte *imgptr; |
| 1604 |
GLint components; |
| 1605 |
GLint i, j; |
| 1606 |
|
| 1607 |
components = components_in_intformat( format ); |
| 1608 |
|
| 1609 |
/* |
| 1610 |
* Allocate image struct and image data buffer |
| 1611 |
*/ |
| 1612 |
image = (struct gl_image *) malloc( sizeof(struct gl_image) ); |
| 1613 |
if (image) { |
| 1614 |
image->Width = width; |
| 1615 |
image->Height = height; |
| 1616 |
image->Components = components; |
| 1617 |
image->Format = format; |
| 1618 |
image->Type = GL_UNSIGNED_BYTE; |
| 1619 |
image->Interleaved = GL_FALSE; |
| 1620 |
image->Data = (GLubyte *) malloc( width * height * components ); |
| 1621 |
if (!image->Data) { |
| 1622 |
free(image); |
| 1623 |
return NULL; |
| 1624 |
} |
| 1625 |
} |
| 1626 |
else { |
| 1627 |
return NULL; |
| 1628 |
} |
| 1629 |
|
| 1630 |
imgptr = image->Data; |
| 1631 |
|
| 1632 |
/* Select buffer to read from */ |
| 1633 |
(void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.ReadBuffer ); |
| 1634 |
|
| 1635 |
for (j=0;j<height;j++) { |
| 1636 |
GLubyte red[MAX_WIDTH], green[MAX_WIDTH]; |
| 1637 |
GLubyte blue[MAX_WIDTH], alpha[MAX_WIDTH]; |
| 1638 |
gl_read_color_span( ctx, width, x, y+j, red, green, blue, alpha ); |
| 1639 |
|
| 1640 |
if (!ctx->Visual->EightBitColor) { |
| 1641 |
/* scale red, green, blue, alpha values to range [0,255] */ |
| 1642 |
GLfloat rscale = 255.0f * ctx->Visual->InvRedScale; |
| 1643 |
GLfloat gscale = 255.0f * ctx->Visual->InvGreenScale; |
| 1644 |
GLfloat bscale = 255.0f * ctx->Visual->InvBlueScale; |
| 1645 |
GLfloat ascale = 255.0f * ctx->Visual->InvAlphaScale; |
| 1646 |
for (i=0;i<width;i++) { |
| 1647 |
red[i] = (GLubyte) (GLint) (red[i] * rscale); |
| 1648 |
green[i] = (GLubyte) (GLint) (green[i] * gscale); |
| 1649 |
blue[i] = (GLubyte) (GLint) (blue[i] * bscale); |
| 1650 |
alpha[i] = (GLubyte) (GLint) (alpha[i] * ascale); |
| 1651 |
} |
| 1652 |
} |
| 1653 |
|
| 1654 |
switch (format) { |
| 1655 |
case GL_ALPHA: |
| 1656 |
for (i=0;i<width;i++) { |
| 1657 |
*imgptr++ = alpha[i]; |
| 1658 |
} |
| 1659 |
break; |
| 1660 |
case GL_LUMINANCE: |
| 1661 |
for (i=0;i<width;i++) { |
| 1662 |
*imgptr++ = red[i]; |
| 1663 |
} |
| 1664 |
break; |
| 1665 |
case GL_LUMINANCE_ALPHA: |
| 1666 |
for (i=0;i<width;i++) { |
| 1667 |
*imgptr++ = red[i]; |
| 1668 |
*imgptr++ = alpha[i]; |
| 1669 |
} |
| 1670 |
break; |
| 1671 |
case GL_INTENSITY: |
| 1672 |
for (i=0;i<width;i++) { |
| 1673 |
*imgptr++ = red[i]; |
| 1674 |
} |
| 1675 |
break; |
| 1676 |
case GL_RGB: |
| 1677 |
for (i=0;i<width;i++) { |
| 1678 |
*imgptr++ = red[i]; |
| 1679 |
*imgptr++ = green[i]; |
| 1680 |
*imgptr++ = blue[i]; |
| 1681 |
} |
| 1682 |
break; |
| 1683 |
case GL_RGBA: |
| 1684 |
for (i=0;i<width;i++) { |
| 1685 |
*imgptr++ = red[i]; |
| 1686 |
*imgptr++ = green[i]; |
| 1687 |
*imgptr++ = blue[i]; |
| 1688 |
*imgptr++ = alpha[i]; |
| 1689 |
} |
| 1690 |
break; |
| 1691 |
} /*switch*/ |
| 1692 |
|
| 1693 |
} /*for*/ |
| 1694 |
|
| 1695 |
/* Restore drawing buffer */ |
| 1696 |
(void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DrawBuffer ); |
| 1697 |
|
| 1698 |
return image; |
| 1699 |
} |
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
void gl_CopyTexImage1D( GLcontext *ctx, |
| 1705 |
GLenum target, GLint level, |
| 1706 |
GLenum internalformat, |
| 1707 |
GLint x, GLint y, |
| 1708 |
GLsizei width, GLint border ) |
| 1709 |
{ |
| 1710 |
GLint format; |
| 1711 |
struct gl_image *teximage; |
| 1712 |
|
| 1713 |
if (INSIDE_BEGIN_END(ctx)) { |
| 1714 |
gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexImage1D" ); |
| 1715 |
return; |
| 1716 |
} |
| 1717 |
if (target!=GL_TEXTURE_1D) { |
| 1718 |
gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); |
| 1719 |
return; |
| 1720 |
} |
| 1721 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 1722 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage1D(level)" ); |
| 1723 |
return; |
| 1724 |
} |
| 1725 |
if (border!=0 && border!=1) { |
| 1726 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage1D(border)" ); |
| 1727 |
return; |
| 1728 |
} |
| 1729 |
if (width<2*border || width>2+MAX_TEXTURE_SIZE || width<0) { |
| 1730 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage1D(width)" ); |
| 1731 |
return; |
| 1732 |
} |
| 1733 |
format = decode_internal_format( internalformat ); |
| 1734 |
if (format<0 || (internalformat>=1 && internalformat<=4)) { |
| 1735 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage1D(format)" ); |
| 1736 |
return; |
| 1737 |
} |
| 1738 |
|
| 1739 |
teximage = gl_read_color_image( ctx, x, y, width, 1, format ); |
| 1740 |
if (!teximage) { |
| 1741 |
gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D" ); |
| 1742 |
return; |
| 1743 |
} |
| 1744 |
|
| 1745 |
gl_TexImage1D( ctx, target, level, internalformat, width, |
| 1746 |
border, GL_RGBA, GL_UNSIGNED_BYTE, teximage ); |
| 1747 |
|
| 1748 |
gl_free_image( teximage ); |
| 1749 |
} |
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
void gl_CopyTexImage2D( GLcontext *ctx, |
| 1754 |
GLenum target, GLint level, GLenum internalformat, |
| 1755 |
GLint x, GLint y, GLsizei width, GLsizei height, |
| 1756 |
GLint border ) |
| 1757 |
{ |
| 1758 |
GLint format; |
| 1759 |
struct gl_image *teximage; |
| 1760 |
|
| 1761 |
if (INSIDE_BEGIN_END(ctx)) { |
| 1762 |
gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexImage2D" ); |
| 1763 |
return; |
| 1764 |
} |
| 1765 |
if (target!=GL_TEXTURE_2D) { |
| 1766 |
gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); |
| 1767 |
return; |
| 1768 |
} |
| 1769 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 1770 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(level)" ); |
| 1771 |
return; |
| 1772 |
} |
| 1773 |
if (border!=0 && border!=1) { |
| 1774 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(border)" ); |
| 1775 |
return; |
| 1776 |
} |
| 1777 |
if (width<2*border || width>2+MAX_TEXTURE_SIZE || width<0) { |
| 1778 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width)" ); |
| 1779 |
return; |
| 1780 |
} |
| 1781 |
if (height<2*border || height>2+MAX_TEXTURE_SIZE || height<0) { |
| 1782 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(height)" ); |
| 1783 |
return; |
| 1784 |
} |
| 1785 |
format = decode_internal_format( internalformat ); |
| 1786 |
if (format<0 || (internalformat>=1 && internalformat<=4)) { |
| 1787 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(format)" ); |
| 1788 |
return; |
| 1789 |
} |
| 1790 |
|
| 1791 |
teximage = gl_read_color_image( ctx, x, y, width, height, format ); |
| 1792 |
if (!teximage) { |
| 1793 |
gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D" ); |
| 1794 |
return; |
| 1795 |
} |
| 1796 |
|
| 1797 |
gl_TexImage2D( ctx, target, level, internalformat, width, height, |
| 1798 |
border, GL_RGBA, GL_UNSIGNED_BYTE, teximage ); |
| 1799 |
|
| 1800 |
gl_free_image( teximage ); |
| 1801 |
} |
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
/* |
| 1807 |
* Do the work of glCopyTexSubImage[12]D. |
| 1808 |
* TODO: apply pixel bias scale and mapping. |
| 1809 |
*/ |
| 1810 |
static void copy_tex_sub_image( GLcontext *ctx, struct gl_texture_image *dest, |
| 1811 |
GLint width, GLint height, |
| 1812 |
GLint srcx, GLint srcy, |
| 1813 |
GLint dstx, GLint dsty, GLint zoffset ) |
| 1814 |
{ |
| 1815 |
GLint i, j; |
| 1816 |
GLint format, components, rectarea; |
| 1817 |
|
| 1818 |
rectarea = width*height; |
| 1819 |
zoffset *= rectarea; |
| 1820 |
format = dest->Format; |
| 1821 |
components = components_in_intformat( format ); |
| 1822 |
|
| 1823 |
for (j=0;j<height;j++) { |
| 1824 |
GLubyte red[MAX_WIDTH], green[MAX_WIDTH]; |
| 1825 |
GLubyte blue[MAX_WIDTH], alpha[MAX_WIDTH]; |
| 1826 |
GLubyte *texptr; |
| 1827 |
|
| 1828 |
gl_read_color_span( ctx, width, srcx, srcy+j, red, green, blue, alpha ); |
| 1829 |
|
| 1830 |
if (!ctx->Visual->EightBitColor) { |
| 1831 |
/* scale red, green, blue, alpha values to range [0,255] */ |
| 1832 |
GLfloat rscale = 255.0f * ctx->Visual->InvRedScale; |
| 1833 |
GLfloat gscale = 255.0f * ctx->Visual->InvGreenScale; |
| 1834 |
GLfloat bscale = 255.0f * ctx->Visual->InvBlueScale; |
| 1835 |
GLfloat ascale = 255.0f * ctx->Visual->InvAlphaScale; |
| 1836 |
for (i=0;i<width;i++) { |
| 1837 |
red[i] = (GLubyte) (GLint) (red[i] * rscale); |
| 1838 |
green[i] = (GLubyte) (GLint) (green[i] * gscale); |
| 1839 |
blue[i] = (GLubyte) (GLint) (blue[i] * bscale); |
| 1840 |
alpha[i] = (GLubyte) (GLint) (alpha[i] * ascale); |
| 1841 |
} |
| 1842 |
} |
| 1843 |
|
| 1844 |
texptr = dest->Data + ( zoffset + (dsty+j) * width + dstx) * components; |
| 1845 |
|
| 1846 |
switch (format) { |
| 1847 |
case GL_ALPHA: |
| 1848 |
for (i=0;i<width;i++) { |
| 1849 |
*texptr++ = alpha[i]; |
| 1850 |
} |
| 1851 |
break; |
| 1852 |
case GL_LUMINANCE: |
| 1853 |
for (i=0;i<width;i++) { |
| 1854 |
*texptr++ = red[i]; |
| 1855 |
} |
| 1856 |
break; |
| 1857 |
case GL_LUMINANCE_ALPHA: |
| 1858 |
for (i=0;i<width;i++) { |
| 1859 |
*texptr++ = red[i]; |
| 1860 |
*texptr++ = alpha[i]; |
| 1861 |
} |
| 1862 |
break; |
| 1863 |
case GL_INTENSITY: |
| 1864 |
for (i=0;i<width;i++) { |
| 1865 |
*texptr++ = red[i]; |
| 1866 |
} |
| 1867 |
break; |
| 1868 |
case GL_RGB: |
| 1869 |
for (i=0;i<width;i++) { |
| 1870 |
*texptr++ = red[i]; |
| 1871 |
*texptr++ = green[i]; |
| 1872 |
*texptr++ = blue[i]; |
| 1873 |
} |
| 1874 |
break; |
| 1875 |
case GL_RGBA: |
| 1876 |
for (i=0;i<width;i++) { |
| 1877 |
*texptr++ = red[i]; |
| 1878 |
*texptr++ = green[i]; |
| 1879 |
*texptr++ = blue[i]; |
| 1880 |
*texptr++ = alpha[i]; |
| 1881 |
} |
| 1882 |
break; |
| 1883 |
} /*switch*/ |
| 1884 |
} /*for*/ |
| 1885 |
} |
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
void gl_CopyTexSubImage1D( GLcontext *ctx, |
| 1891 |
GLenum target, GLint level, |
| 1892 |
GLint xoffset, GLint x, GLint y, GLsizei width ) |
| 1893 |
{ |
| 1894 |
struct gl_texture_image *teximage; |
| 1895 |
|
| 1896 |
if (INSIDE_BEGIN_END(ctx)) { |
| 1897 |
gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage1D" ); |
| 1898 |
return; |
| 1899 |
} |
| 1900 |
if (target!=GL_TEXTURE_1D) { |
| 1901 |
gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); |
| 1902 |
return; |
| 1903 |
} |
| 1904 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 1905 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage1D(level)" ); |
| 1906 |
return; |
| 1907 |
} |
| 1908 |
if (width<0) { |
| 1909 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage1D(width)" ); |
| 1910 |
return; |
| 1911 |
} |
| 1912 |
|
| 1913 |
teximage = ctx->Texture.Current1D->Image[level]; |
| 1914 |
|
| 1915 |
if (teximage) { |
| 1916 |
if (xoffset < -teximage->Border) { |
| 1917 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage1D(xoffset)" ); |
| 1918 |
return; |
| 1919 |
} |
| 1920 |
/* NOTE: we're adding the border here, not subtracting! */ |
| 1921 |
if (xoffset+width > teximage->Width+teximage->Border) { |
| 1922 |
gl_error( ctx, GL_INVALID_VALUE, |
| 1923 |
"glCopyTexSubImage1D(xoffset+width)" ); |
| 1924 |
return; |
| 1925 |
} |
| 1926 |
if (teximage->Data) { |
| 1927 |
copy_tex_sub_image( ctx, teximage, width, 1, x, y, xoffset, 0, 0 ); |
| 1928 |
} |
| 1929 |
} |
| 1930 |
else { |
| 1931 |
gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage1D" ); |
| 1932 |
} |
| 1933 |
} |
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
void gl_CopyTexSubImage2D( GLcontext *ctx, |
| 1938 |
GLenum target, GLint level, |
| 1939 |
GLint xoffset, GLint yoffset, |
| 1940 |
GLint x, GLint y, GLsizei width, GLsizei height ) |
| 1941 |
{ |
| 1942 |
struct gl_texture_image *teximage; |
| 1943 |
|
| 1944 |
if (INSIDE_BEGIN_END(ctx)) { |
| 1945 |
gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D" ); |
| 1946 |
return; |
| 1947 |
} |
| 1948 |
if (target!=GL_TEXTURE_2D) { |
| 1949 |
gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); |
| 1950 |
return; |
| 1951 |
} |
| 1952 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 1953 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(level)" ); |
| 1954 |
return; |
| 1955 |
} |
| 1956 |
if (width<0) { |
| 1957 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(width)" ); |
| 1958 |
return; |
| 1959 |
} |
| 1960 |
if (height<0) { |
| 1961 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(height)" ); |
| 1962 |
return; |
| 1963 |
} |
| 1964 |
|
| 1965 |
teximage = ctx->Texture.Current2D->Image[level]; |
| 1966 |
|
| 1967 |
if (teximage) { |
| 1968 |
if (xoffset < -teximage->Border) { |
| 1969 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(xoffset)" ); |
| 1970 |
return; |
| 1971 |
} |
| 1972 |
if (yoffset < -teximage->Border) { |
| 1973 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(yoffset)" ); |
| 1974 |
return; |
| 1975 |
} |
| 1976 |
/* NOTE: we're adding the border here, not subtracting! */ |
| 1977 |
if (xoffset+width > teximage->Width+teximage->Border) { |
| 1978 |
gl_error( ctx, GL_INVALID_VALUE, |
| 1979 |
"glCopyTexSubImage2D(xoffset+width)" ); |
| 1980 |
return; |
| 1981 |
} |
| 1982 |
if (yoffset+height > teximage->Height+teximage->Border) { |
| 1983 |
gl_error( ctx, GL_INVALID_VALUE, |
| 1984 |
"glCopyTexSubImage2D(yoffset+height)" ); |
| 1985 |
return; |
| 1986 |
} |
| 1987 |
|
| 1988 |
if (teximage->Data) { |
| 1989 |
copy_tex_sub_image( ctx, teximage, width, height, |
| 1990 |
x, y, xoffset, yoffset, 0 ); |
| 1991 |
} |
| 1992 |
} |
| 1993 |
else { |
| 1994 |
gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D" ); |
| 1995 |
} |
| 1996 |
} |
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
void gl_CopyTexSubImage3DEXT( GLcontext *ctx, |
| 2001 |
GLenum target, GLint level, |
| 2002 |
GLint xoffset, GLint yoffset, GLint zoffset, |
| 2003 |
GLint x, GLint y, GLsizei width, GLsizei height ) |
| 2004 |
{ |
| 2005 |
struct gl_texture_image *teximage; |
| 2006 |
|
| 2007 |
if (INSIDE_BEGIN_END(ctx)) { |
| 2008 |
gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage3DEXT" ); |
| 2009 |
return; |
| 2010 |
} |
| 2011 |
if (target!=GL_TEXTURE_2D) { |
| 2012 |
gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3DEXT(target)" ); |
| 2013 |
return; |
| 2014 |
} |
| 2015 |
if (level<0 || level>=MAX_TEXTURE_LEVELS) { |
| 2016 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage3DEXT(level)" ); |
| 2017 |
return; |
| 2018 |
} |
| 2019 |
if (width<0) { |
| 2020 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage3DEXT(width)" ); |
| 2021 |
return; |
| 2022 |
} |
| 2023 |
if (height<0) { |
| 2024 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage3DEXT(height)" ); |
| 2025 |
return; |
| 2026 |
} |
| 2027 |
|
| 2028 |
teximage = ctx->Texture.Current3D->Image[level]; |
| 2029 |
if (teximage) { |
| 2030 |
if (xoffset < -teximage->Border) { |
| 2031 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage3DEXT(xoffset)" ); |
| 2032 |
return; |
| 2033 |
} |
| 2034 |
if (yoffset < -teximage->Border) { |
| 2035 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage3DEXT(yoffset)" ); |
| 2036 |
return; |
| 2037 |
} |
| 2038 |
if (zoffset < -teximage->Border) { |
| 2039 |
gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage3DEXT(zoffset)" ); |
| 2040 |
return; |
| 2041 |
} |
| 2042 |
/* NOTE: we're adding the border here, not subtracting! */ |
| 2043 |
if (xoffset+width > teximage->Width+teximage->Border) { |
| 2044 |
gl_error( ctx, GL_INVALID_VALUE, |
| 2045 |
"glCopyTexSubImage3DEXT(xoffset+width)" ); |
| 2046 |
return; |
| 2047 |
} |
| 2048 |
if (yoffset+height > teximage->Height+teximage->Border) { |
| 2049 |
gl_error( ctx, GL_INVALID_VALUE, |
| 2050 |
"glCopyTexSubImage3DEXT(yoffset+height)" ); |
| 2051 |
return; |
| 2052 |
} |
| 2053 |
if (zoffset > teximage->Depth+teximage->Border) { |
| 2054 |
gl_error( ctx, GL_INVALID_VALUE, |
| 2055 |
"glCopyTexSubImage3DEXT(zoffset+depth)" ); |
| 2056 |
return; |
| 2057 |
} |
| 2058 |
|
| 2059 |
if (teximage->Data) { |
| 2060 |
copy_tex_sub_image( ctx, teximage, width, height, |
| 2061 |
x, y, xoffset, yoffset, zoffset); |
| 2062 |
} |
| 2063 |
} |
| 2064 |
else { |
| 2065 |
gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage3DEXT" ); |
| 2066 |
} |
| 2067 |
} |
| 2068 |
|