Changeset 16939 in vbox for trunk/src/VBox/GuestHost/OpenGL/state_tracker
- Timestamp:
- Feb 19, 2009 8:44:34 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_teximage.c
r15532 r16939 20 20 bitcount(int value) 21 21 { 22 23 24 25 26 27 22 int bits = 0; 23 for (; value > 0; value >>= 1) { 24 if (value & 0x1) 25 bits++; 26 } 27 return bits; 28 28 } 29 29 … … 35 35 IsProxyTarget(GLenum target) 36 36 { 37 38 39 40 41 37 return (target == GL_PROXY_TEXTURE_1D || 38 target == GL_PROXY_TEXTURE_2D || 39 target == GL_PROXY_TEXTURE_3D || 40 target == GL_PROXY_TEXTURE_RECTANGLE_NV || 41 target == GL_PROXY_TEXTURE_CUBE_MAP); 42 42 } 43 43 … … 52 52 isLegalSize(CRContext *g, GLsizei size, GLsizei max) 53 53 { 54 55 56 57 58 59 60 61 54 if (size < 0 || size > max) 55 return GL_FALSE; 56 if (!g->extensions.ARB_texture_non_power_of_two) { 57 /* check for power of two */ 58 if (size > 0 && bitcount(size) != 1) 59 return GL_FALSE; 60 } 61 return GL_TRUE; 62 62 } 63 63 … … 69 69 MaxTextureLevel(CRContext *g, GLenum target) 70 70 { 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 71 CRTextureState *t = &(g->texture); 72 switch (target) { 73 case GL_TEXTURE_1D: 74 case GL_PROXY_TEXTURE_1D: 75 case GL_TEXTURE_2D: 76 case GL_PROXY_TEXTURE_2D: 77 return t->maxLevel; 78 case GL_TEXTURE_3D: 79 case GL_PROXY_TEXTURE_3D: 80 return t->max3DLevel; 81 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 82 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 83 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 84 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 85 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 86 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 87 case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 88 return t->maxCubeMapLevel; 89 case GL_TEXTURE_RECTANGLE_NV: 90 case GL_PROXY_TEXTURE_RECTANGLE_NV: 91 return t->maxRectLevel; 92 default: 93 return 0; 94 } 95 95 } 96 96 … … 106 106 generate_mipmap(CRTextureObj *tobj, GLenum target) 107 107 { 108 109 108 CRTextureLevel *levels; 109 GLint level, width, height, depth; 110 110 111 111 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && … … 117 117 } 118 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 119 width = levels[tobj->baseLevel].width; 120 height = levels[tobj->baseLevel].height; 121 depth = levels[tobj->baseLevel].depth; 122 123 for (level = tobj->baseLevel + 1; level <= tobj->maxLevel; level++) 124 { 125 if (width > 1) 126 width /= 2; 127 if (height > 1) 128 height /= 2; 129 if (depth > 1) 130 depth /= 2; 131 levels[level].width = width; 132 levels[level].height = height; 133 levels[level].depth = depth; 134 levels[level].internalFormat = levels[tobj->baseLevel].internalFormat; 135 levels[level].format = levels[tobj->baseLevel].format; 136 levels[level].type = levels[tobj->baseLevel].type; 137 137 #ifdef CR_ARB_texture_compression 138 139 #endif 140 141 142 143 144 145 146 147 148 138 levels[level].compressed = levels[tobj->baseLevel].compressed; 139 #endif 140 levels[level].texFormat = levels[tobj->baseLevel].texFormat; 141 if (width == 1 && height == 1 && depth == 1) 142 break; 143 } 144 145 /* Set this flag so when we do the state diff, we enable GENERATE_MIPMAP 146 * prior to calling diff.TexImage(). 147 */ 148 levels[tobj->baseLevel].generateMipmap = GL_TRUE; 149 149 } 150 150 … … 156 156 void 157 157 crStateGetTextureObjectAndImage(CRContext *g, GLenum texTarget, GLint level, 158 159 { 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 158 CRTextureObj **obj, CRTextureLevel **img) 159 { 160 CRTextureState *t = &(g->texture); 161 CRTextureUnit *unit = t->unit + t->curTextureUnit; 162 163 switch (texTarget) { 164 case GL_TEXTURE_1D: 165 *obj = unit->currentTexture1D; 166 *img = unit->currentTexture1D->level[0] + level; 167 return; 168 case GL_PROXY_TEXTURE_1D: 169 *obj = &(t->proxy1D); 170 *img = t->proxy1D.level[0] + level; 171 return; 172 case GL_TEXTURE_2D: 173 *obj = unit->currentTexture2D; 174 *img = unit->currentTexture2D->level[0] + level; 175 return; 176 case GL_PROXY_TEXTURE_2D: 177 *obj = &(t->proxy2D); 178 *img = t->proxy2D.level[0] + level; 179 return; 180 case GL_TEXTURE_3D: 181 *obj = unit->currentTexture3D; 182 *img = unit->currentTexture3D->level[0] + level; 183 return; 184 case GL_PROXY_TEXTURE_3D: 185 *obj = &(t->proxy3D); 186 *img = t->proxy3D.level[0] + level; 187 return; 188 default: 189 /* fall-through */ 190 ; 191 } 192 192 193 193 #ifdef CR_NV_texture_rectangle 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 194 if (g->extensions.NV_texture_rectangle) { 195 switch (texTarget) { 196 case GL_PROXY_TEXTURE_RECTANGLE_NV: 197 *obj = &(t->proxyRect); 198 *img = t->proxyRect.level[0] + level; 199 return; 200 case GL_TEXTURE_RECTANGLE_NV: 201 *obj = unit->currentTextureRect; 202 *img = unit->currentTextureRect->level[0] + level; 203 return; 204 default: 205 /* fall-through */ 206 ; 207 } 208 } 209 209 #endif 210 210 211 211 #ifdef CR_ARB_texture_cube_map 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 #endif 252 253 254 212 if (g->extensions.ARB_texture_cube_map) { 213 switch (texTarget) { 214 case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 215 *obj = &(t->proxyCubeMap); 216 *img = t->proxyCubeMap.level[0] + level; 217 return; 218 case GL_TEXTURE_CUBE_MAP_ARB: 219 *obj = unit->currentTextureCubeMap; 220 *img = NULL; 221 return; 222 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 223 *obj = unit->currentTextureCubeMap; 224 *img = unit->currentTextureCubeMap->level[0] + level; 225 return; 226 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 227 *obj = unit->currentTextureCubeMap; 228 *img = unit->currentTextureCubeMap->level[1] + level; 229 return; 230 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 231 *obj = unit->currentTextureCubeMap; 232 *img = unit->currentTextureCubeMap->level[2] + level; 233 return; 234 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 235 *obj = unit->currentTextureCubeMap; 236 *img = unit->currentTextureCubeMap->level[3] + level; 237 return; 238 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 239 *obj = unit->currentTextureCubeMap; 240 *img = unit->currentTextureCubeMap->level[4] + level; 241 return; 242 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 243 *obj = unit->currentTextureCubeMap; 244 *img = unit->currentTextureCubeMap->level[5] + level; 245 return; 246 default: 247 /* fall-through */ 248 ; 249 } 250 } 251 #endif 252 253 *obj = NULL; 254 *img = NULL; 255 255 } 256 256 … … 263 263 static GLboolean 264 264 ErrorCheckTexImage(GLuint dims, GLenum target, GLint level, 265 266 { 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 265 GLsizei width, GLsizei height, GLsizei depth, GLint border) 266 { 267 CRContext *g = GetCurrentContext(); 268 269 if (g->current.inBeginEnd) 270 { 271 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, 272 "glTexImage%uD called in Begin/End", dims); 273 return GL_TRUE; 274 } 275 276 /* 277 * Test target 278 */ 279 switch (target) 280 { 281 case GL_TEXTURE_1D: 282 case GL_PROXY_TEXTURE_1D: 283 if (dims != 1) { 284 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 285 "glTexImage(invalid target=0x%x)", target); 286 return GL_TRUE; 287 } 288 break; 289 case GL_TEXTURE_2D: 290 case GL_PROXY_TEXTURE_2D: 291 if (dims != 2) { 292 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 293 "glTexImage(invalid target=0x%x)", target); 294 return GL_TRUE; 295 } 296 break; 297 case GL_TEXTURE_3D: 298 case GL_PROXY_TEXTURE_3D: 299 if (dims != 3) { 300 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 301 "glTexImage(invalid target=0x%x)", target); 302 return GL_TRUE; 303 } 304 break; 305 305 #ifdef CR_NV_texture_rectangle 306 307 308 309 310 311 312 313 306 case GL_TEXTURE_RECTANGLE_NV: 307 case GL_PROXY_TEXTURE_RECTANGLE_NV: 308 if (dims != 2 || !g->extensions.NV_texture_rectangle) { 309 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 310 "glTexImage2D(invalid target=0x%x)", target); 311 return GL_TRUE; 312 } 313 break; 314 314 #endif 315 315 #ifdef CR_ARB_texture_cube_map 316 317 318 319 320 321 322 323 324 325 326 327 328 329 #endif 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 316 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 317 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 318 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 319 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 320 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 321 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 322 case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 323 if (dims != 2 || !g->extensions.ARB_texture_cube_map) { 324 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 325 "glTexImage2D(invalid target=0x%x)", target); 326 return GL_TRUE; 327 } 328 break; 329 #endif 330 default: 331 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 332 "glTexImage%uD(invalid target=0x%x)", dims, target); 333 return GL_TRUE; 334 } 335 336 /* 337 * Test level 338 */ 339 if (level < 0 || level > MaxTextureLevel(g, target)) { 340 if (!IsProxyTarget(target)) 341 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 342 "glTexImage%uD(level=%d)", dims, level); 343 return GL_TRUE; 344 } 345 346 /* 347 * Test border 348 */ 349 if (border != 0 && border != 1) { 350 if (!IsProxyTarget(target)) 351 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 352 "glTexImage%uD(border=%d)", dims, border); 353 return GL_TRUE; 354 } 355 356 if ((target == GL_PROXY_TEXTURE_RECTANGLE_NV || 357 target == GL_TEXTURE_RECTANGLE_NV) && border != 0) { 358 if (!IsProxyTarget(target)) 359 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 360 "glTexImage2D(border=%d)", border); 361 return GL_TRUE; 362 } 363 364 /* 365 * Test width, height, depth 366 */ 367 if (target == GL_PROXY_TEXTURE_1D || target == GL_TEXTURE_1D) { 368 if (!isLegalSize(g, width - 2 * border, g->limits.maxTextureSize)) { 369 if (!IsProxyTarget(target)) 370 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 371 "glTexImage1D(width=%d)", width); 372 return GL_TRUE; 373 } 374 } 375 else if (target == GL_PROXY_TEXTURE_2D || target == GL_TEXTURE_2D) { 376 if (!isLegalSize(g, width - 2 * border, g->limits.maxTextureSize) || 377 !isLegalSize(g, height - 2 * border, g->limits.maxTextureSize)) { 378 if (!IsProxyTarget(target)) 379 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 380 "glTexImage2D(width=%d, height=%d)", width, height); 381 return GL_TRUE; 382 } 383 } 384 else if (target == GL_PROXY_TEXTURE_3D || target == GL_TEXTURE_3D) { 385 if (!isLegalSize(g, width - 2 * border, g->limits.max3DTextureSize) || 386 !isLegalSize(g, height - 2 * border, g->limits.max3DTextureSize) || 387 !isLegalSize(g, depth - 2 * border, g->limits.max3DTextureSize)) { 388 if (!IsProxyTarget(target)) 389 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 390 "glTexImage3D(width=%d, height=%d, depth=%d)", 391 width, height, depth); 392 return GL_TRUE; 393 } 394 } 395 else if (target == GL_PROXY_TEXTURE_RECTANGLE_NV || 396 target == GL_TEXTURE_RECTANGLE_NV) { 397 if (width < 0 || width > (int) g->limits.maxRectTextureSize || 398 height < 0 || height > (int) g->limits.maxRectTextureSize) { 399 if (!IsProxyTarget(target)) 400 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 401 "glTexImage2D(width=%d, height=%d)", width, height); 402 return GL_TRUE; 403 } 404 } 405 else { 406 /* cube map */ 407 if (!isLegalSize(g, width - 2*border, g->limits.maxCubeMapTextureSize) || 408 !isLegalSize(g, height - 2*border, g->limits.maxCubeMapTextureSize) || 409 width != height) { 410 if (!IsProxyTarget(target)) 411 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 412 "glTexImage2D(width=%d, height=%d)", width, height); 413 return GL_TRUE; 414 } 415 } 416 417 /* OK, no errors */ 418 return GL_FALSE; 419 419 } 420 420 … … 427 427 static GLboolean 428 428 ErrorCheckTexSubImage(GLuint dims, GLenum target, GLint level, 429 430 431 { 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 429 GLint xoffset, GLint yoffset, GLint zoffset, 430 GLsizei width, GLsizei height, GLsizei depth) 431 { 432 CRContext *g = GetCurrentContext(); 433 CRTextureObj *tobj; 434 CRTextureLevel *tl; 435 436 if (g->current.inBeginEnd) { 437 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, 438 "glTexSubImage%uD called in Begin/End", dims); 439 return GL_TRUE; 440 } 441 442 if (dims == 1) { 443 if (target != GL_TEXTURE_1D) { 444 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 445 "glTexSubImage1D(target=0x%x)", target); 446 return GL_TRUE; 447 } 448 } 449 else if (dims == 2) { 450 if (target != GL_TEXTURE_2D && 451 target != GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && 452 target != GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB && 453 target != GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB && 454 target != GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB && 455 target != GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB && 456 target != GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && 457 target != GL_TEXTURE_RECTANGLE_NV) { 458 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 459 "glTexSubImage2D(target=0x%x)", target); 460 return GL_TRUE; 461 } 462 } 463 else if (dims == 3) { 464 if (target != GL_TEXTURE_3D) { 465 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 466 "glTexSubImage3D(target=0x%x)", target); 467 return GL_TRUE; 468 } 469 } 470 471 /* test level */ 472 if (level < 0 || level > MaxTextureLevel(g, target)) { 473 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 474 "glTexSubImage%uD(level=%d)", dims, level); 475 return GL_TRUE; 476 } 477 478 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 479 if (!tobj || !tl) { 480 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 481 "glTexSubImage%uD(target or level)", dims); 482 return GL_TRUE; 483 } 484 485 /* test x/y/zoffset and size */ 486 if (xoffset < -tl->border || xoffset + width > tl->width) { 487 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 488 "glTexSubImage%uD(xoffset=%d + width=%d > %d)", 489 dims, xoffset, width, tl->width); 490 return GL_TRUE; 491 } 492 if (dims > 1 && (yoffset < -tl->border || yoffset + height > tl->height)) { 493 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 494 "glTexSubImage%uD(yoffset=%d + height=%d > %d)", 495 dims, yoffset, height, tl->height); 496 return GL_TRUE; 497 } 498 if (dims > 2 && (zoffset < -tl->border || zoffset + depth > tl->depth)) { 499 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, 500 "glTexSubImage%uD(zoffset=%d and/or depth=%d)", 501 dims, zoffset, depth); 502 return GL_TRUE; 503 } 504 505 /* OK, no errors */ 506 return GL_FALSE; 507 507 } 508 508 … … 511 511 void STATE_APIENTRY 512 512 crStateTexImage1D(GLenum target, GLint level, GLint internalFormat, 513 514 515 { 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 513 GLsizei width, GLint border, GLenum format, 514 GLenum type, const GLvoid * pixels) 515 { 516 CRContext *g = GetCurrentContext(); 517 CRTextureState *t = &(g->texture); 518 CRClientState *c = &(g->client); 519 CRTextureObj *tobj; 520 CRTextureLevel *tl; 521 CRStateBits *sb = GetCurrentBits(); 522 CRTextureBits *tb = &(sb->texture); 523 524 FLUSH(); 525 526 if (ErrorCheckTexImage(1, target, level, width, 1, 1, border)) { 527 if (IsProxyTarget(target)) { 528 /* clear all state, but don't generate error */ 529 crStateTextureInitTextureObj(g, &(t->proxy1D), 0, GL_TEXTURE_1D); 530 } 531 else { 532 /* error was already recorded */ 533 } 534 return; 535 } 536 537 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 538 CRASSERT(tobj); 539 CRASSERT(tl); 540 541 if (IsProxyTarget(target)) 542 tl->bytes = 0; 543 else 544 tl->bytes = crImageSize(format, type, width, 1); 545 546 if (tl->bytes) 547 { 548 /* this is not a proxy texture target so alloc storage */ 549 if (tl->img) 550 crFree(tl->img); 551 tl->img = (GLubyte *) crAlloc(tl->bytes); 552 if (!tl->img) 553 { 554 crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, 555 "glTexImage1D out of memory"); 556 return; 557 } 558 if (pixels) 559 crPixelCopy1D((GLvoid *) tl->img, format, type, 560 pixels, format, type, width, &(c->unpack)); 561 } 562 563 tl->width = width; 564 tl->height = 1; 565 tl->depth = 1; 566 tl->format = format; 567 tl->border = border; 568 tl->internalFormat = internalFormat; 569 crStateTextureInitTextureFormat(tl, internalFormat); 570 tl->type = type; 571 tl->compressed = GL_FALSE; 572 if (width) 573 tl->bytesPerPixel = tl->bytes / width; 574 else 575 tl->bytesPerPixel = 0; 576 576 577 577 #ifdef CR_SGIS_generate_mipmap 578 579 580 581 582 583 584 #endif 585 586 587 588 589 590 578 if (level == tobj->baseLevel && tobj->generateMipmap) { 579 generate_mipmap(tobj, target); 580 } 581 else { 582 tl->generateMipmap = GL_FALSE; 583 } 584 #endif 585 586 /* XXX may need to do some fine-tuning here for proxy textures */ 587 DIRTY(tobj->dirty, g->neg_bitid); 588 DIRTY(tobj->imageBit, g->neg_bitid); 589 DIRTY(tl->dirty, g->neg_bitid); 590 DIRTY(tb->dirty, g->neg_bitid); 591 591 } 592 592 … … 594 594 void STATE_APIENTRY 595 595 crStateTexImage2D(GLenum target, GLint level, GLint internalFormat, 596 597 598 { 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 (GLvoid *) tl->img, format, type, NULL,/* dst */664 pixels, format, type, &(c->unpack));/* src */665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 596 GLsizei width, GLsizei height, GLint border, 597 GLenum format, GLenum type, const GLvoid * pixels) 598 { 599 CRContext *g = GetCurrentContext(); 600 CRTextureState *t = &(g->texture); 601 CRClientState *c = &(g->client); 602 CRTextureObj *tobj = NULL; 603 CRTextureLevel *tl = NULL; 604 CRStateBits *sb = GetCurrentBits(); 605 CRTextureBits *tb = &(sb->texture); 606 const int is_distrib = ((type == GL_TRUE) || (type == GL_FALSE)); 607 608 FLUSH(); 609 610 /* NOTE: we skip parameter error checking if this is a distributed 611 * texture! The user better provide correct parameters!!! 612 */ 613 if (!is_distrib 614 && ErrorCheckTexImage(2, target, level, width, height, 1, border)) { 615 if (IsProxyTarget(target)) { 616 /* clear all state, but don't generate error */ 617 crStateTextureInitTextureObj(g, &(t->proxy2D), 0, GL_TEXTURE_2D); 618 } 619 else { 620 /* error was already recorded */ 621 } 622 return; 623 } 624 625 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 626 CRASSERT(tobj); 627 CRASSERT(tl); 628 629 /* compute size of image buffer */ 630 if (is_distrib) { 631 tl->bytes = crStrlen((char *) pixels) + 1; 632 tl->bytes += crImageSize(format, GL_UNSIGNED_BYTE, width, height); 633 } 634 else if (IsProxyTarget(target)) { 635 tl->bytes = 0; 636 } 637 else { 638 tl->bytes = crImageSize(format, type, width, height); 639 } 640 641 /* allocate the image buffer and fill it */ 642 if (tl->bytes) 643 { 644 /* this is not a proxy texture target so alloc storage */ 645 if (tl->img) 646 crFree(tl->img); 647 tl->img = (GLubyte *) crAlloc(tl->bytes); 648 if (!tl->img) 649 { 650 crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, 651 "glTexImage2D out of memory"); 652 return; 653 } 654 if (pixels) 655 { 656 if (is_distrib) 657 { 658 crMemcpy((void *) tl->img, (void *) pixels, tl->bytes); 659 } 660 else 661 { 662 crPixelCopy2D(width, height, 663 (GLvoid *) tl->img, format, type, NULL, /* dst */ 664 pixels, format, type, &(c->unpack)); /* src */ 665 } 666 } 667 } 668 669 tl->width = width; 670 tl->height = height; 671 tl->depth = 1; 672 tl->format = format; 673 tl->internalFormat = internalFormat; 674 crStateTextureInitTextureFormat(tl, internalFormat); 675 tl->border = border; 676 tl->type = type; 677 tl->compressed = GL_FALSE; 678 if (width && height) 679 { 680 if (is_distrib) 681 tl->bytesPerPixel = 3; /* only support GL_RGB */ 682 else 683 tl->bytesPerPixel = tl->bytes / (width * height); 684 } 685 else 686 tl->bytesPerPixel = 0; 687 687 688 688 #ifdef CR_SGIS_generate_mipmap 689 690 691 692 693 694 695 #endif 696 697 698 699 700 701 689 if (level == tobj->baseLevel && tobj->generateMipmap) { 690 generate_mipmap(tobj, target); 691 } 692 else { 693 tl->generateMipmap = GL_FALSE; 694 } 695 #endif 696 697 /* XXX may need to do some fine-tuning here for proxy textures */ 698 DIRTY(tobj->dirty, g->neg_bitid); 699 DIRTY(tobj->imageBit, g->neg_bitid); 700 DIRTY(tl->dirty, g->neg_bitid); 701 DIRTY(tb->dirty, g->neg_bitid); 702 702 } 703 703 … … 706 706 void STATE_APIENTRY 707 707 crStateTexImage3D(GLenum target, GLint level, 708 709 710 711 712 { 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 708 GLint internalFormat, 709 GLsizei width, GLsizei height, 710 GLsizei depth, GLint border, 711 GLenum format, GLenum type, const GLvoid * pixels) 712 { 713 CRContext *g = GetCurrentContext(); 714 CRTextureState *t = &(g->texture); 715 CRClientState *c = &(g->client); 716 CRTextureObj *tobj = NULL; 717 CRTextureLevel *tl = NULL; 718 CRStateBits *sb = GetCurrentBits(); 719 CRTextureBits *tb = &(sb->texture); 720 721 FLUSH(); 722 723 if (ErrorCheckTexImage(3, target, level, width, height, depth, border)) { 724 if (IsProxyTarget(target)) { 725 /* clear all state, but don't generate error */ 726 crStateTextureInitTextureObj(g, &(t->proxy3D), 0, GL_TEXTURE_3D); 727 } 728 else { 729 /* error was already recorded */ 730 } 731 return; 732 } 733 734 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 735 CRASSERT(tobj); 736 CRASSERT(tl); 737 738 if (IsProxyTarget(target)) 739 tl->bytes = 0; 740 else 741 tl->bytes = crTextureSize(format, type, width, height, depth); 742 743 if (tl->bytes) 744 { 745 /* this is not a proxy texture target so alloc storage */ 746 if (tl->img) 747 crFree(tl->img); 748 tl->img = (GLubyte *) crAlloc(tl->bytes); 749 if (!tl->img) 750 { 751 crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, 752 "glTexImage3D out of memory"); 753 return; 754 } 755 if (pixels) 756 crPixelCopy3D(width, height, depth, (GLvoid *) (tl->img), format, type, 757 NULL, pixels, format, type, &(c->unpack)); 758 } 759 760 tl->internalFormat = internalFormat; 761 tl->border = border; 762 tl->width = width; 763 tl->height = height; 764 tl->depth = depth; 765 tl->format = format; 766 tl->type = type; 767 tl->compressed = GL_FALSE; 768 768 769 769 #ifdef CR_SGIS_generate_mipmap 770 771 772 773 774 775 776 #endif 777 778 779 780 781 782 770 if (level == tobj->baseLevel && tobj->generateMipmap) { 771 generate_mipmap(tobj, target); 772 } 773 else { 774 tl->generateMipmap = GL_FALSE; 775 } 776 #endif 777 778 /* XXX may need to do some fine-tuning here for proxy textures */ 779 DIRTY(tobj->dirty, g->neg_bitid); 780 DIRTY(tobj->imageBit, g->neg_bitid); 781 DIRTY(tl->dirty, g->neg_bitid); 782 DIRTY(tb->dirty, g->neg_bitid); 783 783 } 784 784 #endif /* CR_OPENGL_VERSION_1_2 || GL_EXT_texture3D */ … … 788 788 void STATE_APIENTRY 789 789 crStateTexImage3DEXT(GLenum target, GLint level, 790 791 792 793 794 { 795 796 790 GLenum internalFormat, 791 GLsizei width, GLsizei height, GLsizei depth, 792 GLint border, GLenum format, GLenum type, 793 const GLvoid * pixels) 794 { 795 crStateTexImage3D(target, level, (GLint) internalFormat, width, height, 796 depth, border, format, type, pixels); 797 797 } 798 798 #endif /* GL_EXT_texture3D */ … … 801 801 void STATE_APIENTRY 802 802 crStateTexSubImage1D(GLenum target, GLint level, GLint xoffset, 803 804 805 { 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 803 GLsizei width, GLenum format, 804 GLenum type, const GLvoid * pixels) 805 { 806 CRContext *g = GetCurrentContext(); 807 CRTextureState *t = &(g->texture); 808 CRClientState *c = &(g->client); 809 CRStateBits *sb = GetCurrentBits(); 810 CRTextureBits *tb = &(sb->texture); 811 CRTextureUnit *unit = t->unit + t->curTextureUnit; 812 CRTextureObj *tobj = unit->currentTexture1D; 813 CRTextureLevel *tl = tobj->level[0] + level; 814 815 FLUSH(); 816 817 if (ErrorCheckTexSubImage(1, target, level, xoffset, 0, 0, 818 width, 1, 1)) { 819 return; /* GL error state already set */ 820 } 821 822 xoffset += tl->border; 823 824 crPixelCopy1D((void *) (tl->img + xoffset * tl->bytesPerPixel), 825 tl->format, tl->type, 826 pixels, format, type, width, &(c->unpack)); 827 827 828 828 #ifdef CR_SGIS_generate_mipmap 829 830 831 832 833 834 835 #endif 836 837 838 839 840 829 if (level == tobj->baseLevel && tobj->generateMipmap) { 830 generate_mipmap(tobj, target); 831 } 832 else { 833 tl->generateMipmap = GL_FALSE; 834 } 835 #endif 836 837 DIRTY(tobj->dirty, g->neg_bitid); 838 DIRTY(tobj->imageBit, g->neg_bitid); 839 DIRTY(tl->dirty, g->neg_bitid); 840 DIRTY(tb->dirty, g->neg_bitid); 841 841 } 842 842 … … 844 844 void STATE_APIENTRY 845 845 crStateTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 846 847 848 { 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 crPixelCopy2D(width, height, subimg, tl->format, tl->type, NULL,/* dst */878 pixels, format, type, &(c->unpack));/* src */879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 846 GLsizei width, GLsizei height, 847 GLenum format, GLenum type, const GLvoid * pixels) 848 { 849 CRContext *g = GetCurrentContext(); 850 CRClientState *c = &(g->client); 851 CRStateBits *sb = GetCurrentBits(); 852 CRTextureBits *tb = &(sb->texture); 853 CRTextureObj *tobj; 854 CRTextureLevel *tl; 855 GLubyte *subimg = NULL; 856 GLubyte *img = NULL; 857 GLubyte *src; 858 int i; 859 860 FLUSH(); 861 862 if (ErrorCheckTexSubImage(2, target, level, xoffset, yoffset, 0, 863 width, height, 1)) { 864 return; /* GL error state already set */ 865 } 866 867 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 868 CRASSERT(tobj); 869 CRASSERT(tl); 870 871 xoffset += tl->border; 872 yoffset += tl->border; 873 874 subimg = 875 (GLubyte *) crAlloc(crImageSize(tl->format, tl->type, width, height)); 876 877 crPixelCopy2D(width, height, subimg, tl->format, tl->type, NULL, /* dst */ 878 pixels, format, type, &(c->unpack)); /* src */ 879 880 img = tl->img + 881 xoffset * tl->bytesPerPixel + yoffset * tl->width * tl->bytesPerPixel; 882 883 src = subimg; 884 885 /* Copy the data into the texture */ 886 for (i = 0; i < height; i++) 887 { 888 crMemcpy(img, src, tl->bytesPerPixel * width); 889 img += tl->width * tl->bytesPerPixel; 890 src += width * tl->bytesPerPixel; 891 } 892 893 crFree(subimg); 894 894 895 895 #ifdef CR_SGIS_generate_mipmap 896 897 898 899 900 901 902 #endif 903 904 905 906 907 896 if (level == tobj->baseLevel && tobj->generateMipmap) { 897 generate_mipmap(tobj, target); 898 } 899 else { 900 tl->generateMipmap = GL_FALSE; 901 } 902 #endif 903 904 DIRTY(tobj->dirty, g->neg_bitid); 905 DIRTY(tobj->imageBit, g->neg_bitid); 906 DIRTY(tl->dirty, g->neg_bitid); 907 DIRTY(tb->dirty, g->neg_bitid); 908 908 } 909 909 … … 911 911 void STATE_APIENTRY 912 912 crStateTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 913 914 915 916 { 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 913 GLint zoffset, GLsizei width, GLsizei height, 914 GLsizei depth, GLenum format, GLenum type, 915 const GLvoid * pixels) 916 { 917 CRContext *g = GetCurrentContext(); 918 CRTextureState *t = &(g->texture); 919 CRClientState *c = &(g->client); 920 CRStateBits *sb = GetCurrentBits(); 921 CRTextureBits *tb = &(sb->texture); 922 CRTextureUnit *unit = t->unit + t->curTextureUnit; 923 CRTextureObj *tobj = unit->currentTexture3D; 924 CRTextureLevel *tl = tobj->level[0] + level; 925 GLubyte *subimg = NULL; 926 GLubyte *img = NULL; 927 GLubyte *src; 928 int i; 929 930 FLUSH(); 931 932 if (ErrorCheckTexSubImage(3, target, level, xoffset, yoffset, zoffset, 933 width, height, depth)) { 934 return; /* GL error state already set */ 935 } 936 937 xoffset += tl->border; 938 yoffset += tl->border; 939 zoffset += tl->border; 940 941 subimg = 942 (GLubyte *) 943 crAlloc(crTextureSize(tl->format, tl->type, width, height, depth)); 944 945 crPixelCopy3D(width, height, depth, subimg, tl->format, tl->type, NULL, 946 pixels, format, type, &(c->unpack)); 947 948 img = tl->img + xoffset * tl->bytesPerPixel + 949 yoffset * tl->width * tl->bytesPerPixel + 950 zoffset * tl->width * tl->height * tl->bytesPerPixel; 951 952 src = subimg; 953 954 /* Copy the data into the texture */ 955 for (i = 0; i < depth; i++) 956 { 957 crMemcpy(img, src, tl->bytesPerPixel * width * height); 958 img += tl->width * tl->height * tl->bytesPerPixel; 959 src += width * height * tl->bytesPerPixel; 960 } 961 962 crFree(subimg); 963 963 964 964 #ifdef CR_SGIS_generate_mipmap 965 966 967 968 969 970 971 #endif 972 973 974 975 976 965 if (level == tobj->baseLevel && tobj->generateMipmap) { 966 generate_mipmap(tobj, target); 967 } 968 else { 969 tl->generateMipmap = GL_FALSE; 970 } 971 #endif 972 973 DIRTY(tobj->dirty, g->neg_bitid); 974 DIRTY(tobj->imageBit, g->neg_bitid); 975 DIRTY(tl->dirty, g->neg_bitid); 976 DIRTY(tb->dirty, g->neg_bitid); 977 977 } 978 978 #endif /* CR_OPENGL_VERSION_1_2 || GL_EXT_texture3D */ … … 981 981 void STATE_APIENTRY 982 982 crStateCompressedTexImage1DARB(GLenum target, GLint level, 983 984 985 986 { 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 983 GLenum internalFormat, GLsizei width, 984 GLint border, GLsizei imageSize, 985 const GLvoid * data) 986 { 987 CRContext *g = GetCurrentContext(); 988 CRTextureState *t = &(g->texture); 989 CRTextureObj *tobj; 990 CRTextureLevel *tl; 991 CRStateBits *sb = GetCurrentBits(); 992 CRTextureBits *tb = &(sb->texture); 993 994 FLUSH(); 995 996 if (ErrorCheckTexImage(1, target, level, width, 1, 1, border)) { 997 if (IsProxyTarget(target)) { 998 /* clear all state, but don't generate error */ 999 crStateTextureInitTextureObj(g, &(t->proxy1D), 0, GL_TEXTURE_1D); 1000 } 1001 else { 1002 /* error was already recorded */ 1003 } 1004 return; 1005 } 1006 1007 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 1008 CRASSERT(tobj); 1009 CRASSERT(tl); 1010 1011 if (IsProxyTarget(target)) 1012 tl->bytes = 0; 1013 else 1014 tl->bytes = imageSize; 1015 1016 if (tl->bytes) 1017 { 1018 /* this is not a proxy texture target so alloc storage */ 1019 if (tl->img) 1020 crFree(tl->img); 1021 tl->img = (GLubyte *) crAlloc(tl->bytes); 1022 if (!tl->img) 1023 { 1024 crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, 1025 "glTexImage1D out of memory"); 1026 return; 1027 } 1028 if (data) 1029 crMemcpy(tl->img, data, imageSize); 1030 } 1031 1032 tl->width = width; 1033 tl->height = 1; 1034 tl->depth = 1; 1035 tl->border = border; 1036 tl->format = GL_NONE; 1037 tl->type = GL_NONE; 1038 tl->internalFormat = internalFormat; 1039 crStateTextureInitTextureFormat(tl, internalFormat); 1040 tl->compressed = GL_TRUE; 1041 tl->bytesPerPixel = 0; /* n/a */ 1042 1042 1043 1043 #ifdef CR_SGIS_generate_mipmap 1044 1045 1046 1047 1048 1049 1050 #endif 1051 1052 1053 1054 1055 1044 if (level == tobj->baseLevel && tobj->generateMipmap) { 1045 generate_mipmap(tobj, target); 1046 } 1047 else { 1048 tl->generateMipmap = GL_FALSE; 1049 } 1050 #endif 1051 1052 DIRTY(tobj->dirty, g->neg_bitid); 1053 DIRTY(tobj->imageBit, g->neg_bitid); 1054 DIRTY(tl->dirty, g->neg_bitid); 1055 DIRTY(tb->dirty, g->neg_bitid); 1056 1056 } 1057 1057 … … 1059 1059 void STATE_APIENTRY 1060 1060 crStateCompressedTexImage2DARB(GLenum target, GLint level, 1061 1062 1063 1064 { 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1061 GLenum internalFormat, GLsizei width, 1062 GLsizei height, GLint border, 1063 GLsizei imageSize, const GLvoid * data) 1064 { 1065 CRContext *g = GetCurrentContext(); 1066 CRTextureState *t = &(g->texture); 1067 CRTextureObj *tobj = NULL; 1068 CRTextureLevel *tl = NULL; 1069 CRStateBits *sb = GetCurrentBits(); 1070 CRTextureBits *tb = &(sb->texture); 1071 1072 FLUSH(); 1073 1074 if (ErrorCheckTexImage(2, target, level, width, height, 1, border)) { 1075 if (IsProxyTarget(target)) { 1076 /* clear all state, but don't generate error */ 1077 crStateTextureInitTextureObj(g, &(t->proxy2D), 0, GL_TEXTURE_2D); 1078 } 1079 else { 1080 /* error was already recorded */ 1081 } 1082 return; 1083 } 1084 1085 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 1086 CRASSERT(tobj); 1087 CRASSERT(tl); 1088 1089 if (IsProxyTarget(target)) 1090 tl->bytes = 0; 1091 else 1092 tl->bytes = imageSize; 1093 1094 if (tl->bytes) 1095 { 1096 /* this is not a proxy texture target so alloc storage */ 1097 if (tl->img) 1098 crFree(tl->img); 1099 tl->img = (GLubyte *) crAlloc(tl->bytes); 1100 if (!tl->img) 1101 { 1102 crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, 1103 "glTexImage2D out of memory"); 1104 return; 1105 } 1106 if (data) 1107 crMemcpy(tl->img, data, imageSize); 1108 } 1109 1110 tl->width = width; 1111 tl->height = height; 1112 tl->depth = 1; 1113 tl->border = border; 1114 tl->format = GL_NONE; 1115 tl->type = GL_NONE; 1116 tl->internalFormat = internalFormat; 1117 crStateTextureInitTextureFormat(tl, internalFormat); 1118 tl->compressed = GL_TRUE; 1119 tl->bytesPerPixel = 0; /* n/a */ 1120 1120 1121 1121 #ifdef CR_SGIS_generate_mipmap 1122 1123 1124 1125 1126 1127 1128 #endif 1129 1130 1131 1132 1133 1134 1122 if (level == tobj->baseLevel && tobj->generateMipmap) { 1123 generate_mipmap(tobj, target); 1124 } 1125 else { 1126 tl->generateMipmap = GL_FALSE; 1127 } 1128 #endif 1129 1130 /* XXX may need to do some fine-tuning here for proxy textures */ 1131 DIRTY(tobj->dirty, g->neg_bitid); 1132 DIRTY(tobj->imageBit, g->neg_bitid); 1133 DIRTY(tl->dirty, g->neg_bitid); 1134 DIRTY(tb->dirty, g->neg_bitid); 1135 1135 } 1136 1136 … … 1138 1138 void STATE_APIENTRY 1139 1139 crStateCompressedTexImage3DARB(GLenum target, GLint level, 1140 1141 1142 1143 { 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1140 GLenum internalFormat, GLsizei width, 1141 GLsizei height, GLsizei depth, GLint border, 1142 GLsizei imageSize, const GLvoid * data) 1143 { 1144 CRContext *g = GetCurrentContext(); 1145 CRTextureState *t = &(g->texture); 1146 CRTextureObj *tobj = NULL; 1147 CRTextureLevel *tl = NULL; 1148 CRStateBits *sb = GetCurrentBits(); 1149 CRTextureBits *tb = &(sb->texture); 1150 1151 FLUSH(); 1152 1153 if (ErrorCheckTexImage(3, target, level, width, height, depth, border)) { 1154 if (IsProxyTarget(target)) { 1155 /* clear all state, but don't generate error */ 1156 crStateTextureInitTextureObj(g, &(t->proxy3D), 0, GL_TEXTURE_3D); 1157 } 1158 else { 1159 /* error was already recorded */ 1160 } 1161 return; 1162 } 1163 1164 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 1165 CRASSERT(tobj); 1166 CRASSERT(tl); 1167 1168 if (IsProxyTarget(target)) 1169 tl->bytes = 0; 1170 else 1171 tl->bytes = imageSize; 1172 1173 if (tl->bytes) 1174 { 1175 /* this is not a proxy texture target so alloc storage */ 1176 if (tl->img) 1177 crFree(tl->img); 1178 tl->img = (GLubyte *) crAlloc(tl->bytes); 1179 if (!tl->img) 1180 { 1181 crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, 1182 "glCompressedTexImage3D out of memory"); 1183 return; 1184 } 1185 if (data) 1186 crMemcpy(tl->img, data, imageSize); 1187 } 1188 1189 tl->width = width; 1190 tl->height = height; 1191 tl->depth = depth; 1192 tl->border = border; 1193 tl->format = GL_NONE; 1194 tl->type = GL_NONE; 1195 tl->internalFormat = internalFormat; 1196 crStateTextureInitTextureFormat(tl, internalFormat); 1197 tl->compressed = GL_TRUE; 1198 tl->bytesPerPixel = 0; /* n/a */ 1199 1199 1200 1200 #ifdef CR_SGIS_generate_mipmap 1201 1202 1203 1204 1205 1206 1207 #endif 1208 1209 1210 1211 1212 1213 1201 if (level == tobj->baseLevel && tobj->generateMipmap) { 1202 generate_mipmap(tobj, target); 1203 } 1204 else { 1205 tl->generateMipmap = GL_FALSE; 1206 } 1207 #endif 1208 1209 /* XXX may need to do some fine-tuning here for proxy textures */ 1210 DIRTY(tobj->dirty, g->neg_bitid); 1211 DIRTY(tobj->imageBit, g->neg_bitid); 1212 DIRTY(tl->dirty, g->neg_bitid); 1213 DIRTY(tb->dirty, g->neg_bitid); 1214 1214 } 1215 1215 … … 1217 1217 void STATE_APIENTRY 1218 1218 crStateCompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, 1219 1220 1221 { 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1219 GLsizei width, GLenum format, 1220 GLsizei imageSize, const GLvoid * data) 1221 { 1222 CRContext *g = GetCurrentContext(); 1223 CRTextureState *t = &(g->texture); 1224 CRStateBits *sb = GetCurrentBits(); 1225 CRTextureBits *tb = &(sb->texture); 1226 CRTextureUnit *unit = t->unit + t->curTextureUnit; 1227 CRTextureObj *tobj = unit->currentTexture1D; 1228 CRTextureLevel *tl = tobj->level[0] + level; 1229 1230 FLUSH(); 1231 1232 if (ErrorCheckTexSubImage(1, target, level, xoffset, 0, 0, width, 1, 1)) { 1233 return; /* GL error state already set */ 1234 } 1235 1236 xoffset += tl->border; 1237 1238 if (xoffset == 0 && width == tl->width) { 1239 /* just memcpy */ 1240 crMemcpy(tl->img, data, imageSize); 1241 } 1242 else { 1243 /* XXX this depends on the exact compression method */ 1244 } 1245 1245 1246 1246 #ifdef CR_SGIS_generate_mipmap 1247 1248 1249 1250 1251 1252 1253 #endif 1254 1255 1256 1257 1258 1247 if (level == tobj->baseLevel && tobj->generateMipmap) { 1248 generate_mipmap(tobj, target); 1249 } 1250 else { 1251 tl->generateMipmap = GL_FALSE; 1252 } 1253 #endif 1254 1255 DIRTY(tobj->dirty, g->neg_bitid); 1256 DIRTY(tobj->imageBit, g->neg_bitid); 1257 DIRTY(tl->dirty, g->neg_bitid); 1258 DIRTY(tb->dirty, g->neg_bitid); 1259 1259 } 1260 1260 … … 1262 1262 void STATE_APIENTRY 1263 1263 crStateCompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, 1264 1265 1266 1267 { 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1264 GLint yoffset, GLsizei width, 1265 GLsizei height, GLenum format, 1266 GLsizei imageSize, const GLvoid * data) 1267 { 1268 CRContext *g = GetCurrentContext(); 1269 CRTextureState *t = &(g->texture); 1270 CRStateBits *sb = GetCurrentBits(); 1271 CRTextureBits *tb = &(sb->texture); 1272 CRTextureUnit *unit = t->unit + t->curTextureUnit; 1273 CRTextureObj *tobj = unit->currentTexture1D; 1274 CRTextureLevel *tl = tobj->level[0] + level; 1275 1276 FLUSH(); 1277 1278 if (ErrorCheckTexSubImage(2, target, level, xoffset, yoffset, 0, 1279 width, height, 1)) { 1280 return; /* GL error state already set */ 1281 } 1282 1283 xoffset += tl->border; 1284 yoffset += tl->border; 1285 1286 if (xoffset == 0 && width == tl->width && 1287 yoffset == 0 && height == tl->height) { 1288 /* just memcpy */ 1289 crMemcpy(tl->img, data, imageSize); 1290 } 1291 else { 1292 /* XXX this depends on the exact compression method */ 1293 } 1294 1294 1295 1295 #ifdef CR_SGIS_generate_mipmap 1296 1297 1298 1299 1300 1301 1302 #endif 1303 1304 1305 1306 1307 1296 if (level == tobj->baseLevel && tobj->generateMipmap) { 1297 generate_mipmap(tobj, target); 1298 } 1299 else { 1300 tl->generateMipmap = GL_FALSE; 1301 } 1302 #endif 1303 1304 DIRTY(tobj->dirty, g->neg_bitid); 1305 DIRTY(tobj->imageBit, g->neg_bitid); 1306 DIRTY(tl->dirty, g->neg_bitid); 1307 DIRTY(tb->dirty, g->neg_bitid); 1308 1308 } 1309 1309 … … 1311 1311 void STATE_APIENTRY 1312 1312 crStateCompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, 1313 1314 1315 1316 1317 { 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1313 GLint yoffset, GLint zoffset, GLsizei width, 1314 GLsizei height, GLsizei depth, 1315 GLenum format, GLsizei imageSize, 1316 const GLvoid * data) 1317 { 1318 CRContext *g = GetCurrentContext(); 1319 CRTextureState *t = &(g->texture); 1320 CRStateBits *sb = GetCurrentBits(); 1321 CRTextureBits *tb = &(sb->texture); 1322 CRTextureUnit *unit = t->unit + t->curTextureUnit; 1323 CRTextureObj *tobj = unit->currentTexture1D; 1324 CRTextureLevel *tl = tobj->level[0] + level; 1325 1326 FLUSH(); 1327 1328 if (ErrorCheckTexSubImage(3, target, level, xoffset, yoffset, zoffset, 1329 width, height, depth)) { 1330 return; /* GL error state already set */ 1331 } 1332 1333 xoffset += tl->border; 1334 yoffset += tl->border; 1335 zoffset += tl->border; 1336 1337 if (xoffset == 0 && width == tl->width && 1338 yoffset == 0 && height == tl->height && 1339 zoffset == 0 && depth == tl->depth) { 1340 /* just memcpy */ 1341 crMemcpy(tl->img, data, imageSize); 1342 } 1343 else { 1344 /* XXX this depends on the exact compression method */ 1345 } 1346 1346 1347 1347 #ifdef CR_SGIS_generate_mipmap 1348 1349 1350 1351 1352 1353 1354 #endif 1355 1356 1357 1358 1359 1348 if (level == tobj->baseLevel && tobj->generateMipmap) { 1349 generate_mipmap(tobj, target); 1350 } 1351 else { 1352 tl->generateMipmap = GL_FALSE; 1353 } 1354 #endif 1355 1356 DIRTY(tobj->dirty, g->neg_bitid); 1357 DIRTY(tobj->imageBit, g->neg_bitid); 1358 DIRTY(tl->dirty, g->neg_bitid); 1359 DIRTY(tb->dirty, g->neg_bitid); 1360 1360 } 1361 1361 … … 1364 1364 crStateGetCompressedTexImageARB(GLenum target, GLint level, GLvoid * img) 1365 1365 { 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1366 CRContext *g = GetCurrentContext(); 1367 CRTextureObj *tobj; 1368 CRTextureLevel *tl; 1369 1370 if (g->current.inBeginEnd) 1371 { 1372 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, 1373 "glGetCompressedTexImage called in begin/end"); 1374 return; 1375 } 1376 1377 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 1378 if (!tobj || !tl) { 1379 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 1380 "glGetCompressedTexImage(invalid target or level)"); 1381 return; 1382 } 1383 1384 if (!tl->compressed) { 1385 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, 1386 "glGetCompressedTexImage(not a compressed texture)"); 1387 return; 1388 } 1389 1390 crMemcpy(img, tl->img, tl->bytes); 1391 1391 } 1392 1392 … … 1394 1394 void STATE_APIENTRY 1395 1395 crStateGetTexImage(GLenum target, GLint level, GLenum format, 1396 1397 { 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1396 GLenum type, GLvoid * pixels) 1397 { 1398 CRContext *g = GetCurrentContext(); 1399 CRClientState *c = &(g->client); 1400 CRTextureObj *tobj; 1401 CRTextureLevel *tl; 1402 1403 if (g->current.inBeginEnd) 1404 { 1405 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, 1406 "glGetTexImage called in begin/end"); 1407 return; 1408 } 1409 1410 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 1411 if (!tobj || !tl) { 1412 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 1413 "glGetTexImage(invalid target or level)"); 1414 return; 1415 } 1416 1417 if (tl->compressed) { 1418 crWarning("glGetTexImage cannot decompress a compressed texture!"); 1419 return; 1420 } 1421 1422 switch (format) 1423 { 1424 case GL_RED: 1425 case GL_GREEN: 1426 case GL_BLUE: 1427 case GL_ALPHA: 1428 case GL_RGB: 1429 case GL_RGBA: 1430 case GL_LUMINANCE: 1431 case GL_LUMINANCE_ALPHA: 1432 break; 1433 default: 1434 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 1435 "glGetTexImage called with bogus format: %d", format); 1436 return; 1437 } 1438 1439 switch (type) 1440 { 1441 case GL_UNSIGNED_BYTE: 1442 case GL_BYTE: 1443 case GL_UNSIGNED_SHORT: 1444 case GL_SHORT: 1445 case GL_UNSIGNED_INT: 1446 case GL_INT: 1447 case GL_FLOAT: 1448 break; 1449 default: 1450 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, 1451 "glGetTexImage called with bogus type: %d", type); 1452 return; 1453 } 1454 1454 1455 1455 #ifdef CR_OPENGL_VERSION_1_2 1456 1457 1458 1459 1460 1461 1462 #endif 1463 1464 1465 crPixelCopy2D(tl->width, tl->height, (GLvoid *) pixels, format, type, NULL,/* dst */1466 (tl->img), format, type, &(c->pack));/* src */1467 1468 } 1456 if (target == GL_TEXTURE_3D) 1457 { 1458 crPixelCopy3D(tl->width, tl->height, tl->depth, (GLvoid *) pixels, format, 1459 type, NULL, (tl->img), format, type, &(c->pack)); 1460 } 1461 else 1462 #endif 1463 if ((target == GL_TEXTURE_2D) || (target == GL_TEXTURE_1D)) 1464 { 1465 crPixelCopy2D(tl->width, tl->height, (GLvoid *) pixels, format, type, NULL, /* dst */ 1466 (tl->img), format, type, &(c->pack)); /* src */ 1467 } 1468 }
Note:
See TracChangeset
for help on using the changeset viewer.