Changeset 3598 for trunk/src/opengl/mesa/teximage.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/teximage.c
r2962 r3598 1 /* $Id: teximage.c,v 1. 2 2000-03-01 18:49:36jeroen Exp $ */1 /* $Id: teximage.c,v 1.3 2000-05-23 20:40:55 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 29 29 #include "all.h" 30 30 #else 31 #ifndef XFree86Server 32 #include <assert.h> 33 #include <stdio.h> 34 #include <stdlib.h> 35 #include <string.h> 36 #else 37 #include "GL/xf86glx.h" 38 #endif 31 #include "glheader.h" 39 32 #include "types.h" 40 33 #include "context.h" 41 34 #include "image.h" 42 #include "macros.h"43 35 #include "mmath.h" 44 36 #include "span.h" 45 37 #include "teximage.h" 46 38 #include "texstate.h" 39 #include "mem.h" 47 40 #endif 48 41 … … 58 51 59 52 60 61 static struct gl_pixelstore_attrib defaultPacking = {62 1, /* Alignment */63 0, /* RowLength */64 0, /* SkipPixels */65 0, /* SkipRows */66 0, /* ImageHeight */67 0, /* SkipImages */68 GL_FALSE, /* SwapBytes */69 GL_FALSE /* LsbFirst */70 };71 72 73 74 53 /* 75 54 * Compute log base 2 of n. … … 77 56 * If n<0 return -1. 78 57 */ 79 static int logbase2( int n ) 58 static int 59 logbase2( int n ) 80 60 { 81 61 GLint i = 1; … … 106 86 * Return -1 if invalid enum. 107 87 */ 108 static GLint decode_internal_format( GLint format ) 88 GLint 89 _mesa_base_tex_format( GLint format ) 109 90 { 110 91 switch (format) { … … 178 159 * number of components for the format. Return -1 if invalid enum. 179 160 */ 180 static GLint components_in_intformat( GLint format ) 161 static GLint 162 components_in_intformat( GLint format ) 181 163 { 182 164 switch (format) { … … 244 226 245 227 246 struct gl_texture_image *gl_alloc_texture_image( void )247 {248 return CALLOC_STRUCT(gl_texture_image);249 }250 251 252 253 void gl_free_texture_image( struct gl_texture_image *teximage )254 {255 if (teximage->Data) {256 FREE( teximage->Data );257 teximage->Data = NULL;258 }259 FREE( teximage );260 }261 262 263 264 228 /* 265 229 * Examine the texImage->Format field and set the Red, Green, Blue, etc … … 268 232 * overwritting these fields to indicate true texel resolution. 269 233 */ 270 static void set_teximage_component_sizes( struct gl_texture_image *texImage ) 234 static void 235 set_teximage_component_sizes( struct gl_texture_image *texImage ) 271 236 { 272 237 switch (texImage->Format) { … … 370 335 371 336 337 338 /* 339 * Return new gl_texture_image struct with all fields initialized to zero. 340 */ 341 struct gl_texture_image * 342 gl_alloc_texture_image( void ) 343 { 344 return CALLOC_STRUCT(gl_texture_image); 345 } 346 347 348 349 /* 350 * Initialize most fields of a gl_texture_image struct. 351 */ 352 static void 353 init_texture_image( struct gl_texture_image *img, 354 GLsizei width, GLsizei height, GLsizei depth, 355 GLint border, GLenum internalFormat ) 356 { 357 ASSERT(img); 358 ASSERT(!img->Data); 359 img->Format = (GLenum) _mesa_base_tex_format(internalFormat); 360 set_teximage_component_sizes( img ); 361 img->IntFormat = (GLenum) internalFormat; 362 img->Border = border; 363 img->Width = width; 364 img->Height = height; 365 img->Depth = depth; 366 img->WidthLog2 = logbase2(width - 2 * border); 367 if (height == 1) /* 1-D texture */ 368 img->HeightLog2 = 0; 369 else 370 img->HeightLog2 = logbase2(height - 2 * border); 371 if (depth == 1) /* 2-D texture */ 372 img->DepthLog2 = 0; 373 else 374 img->DepthLog2 = logbase2(depth - 2 * border); 375 img->Width2 = 1 << img->WidthLog2; 376 img->Height2 = 1 << img->HeightLog2; 377 img->Depth2 = 1 << img->DepthLog2; 378 img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); 379 } 380 381 382 383 void 384 gl_free_texture_image( struct gl_texture_image *teximage ) 385 { 386 if (teximage->Data) { 387 FREE( teximage->Data ); 388 teximage->Data = NULL; 389 } 390 FREE( teximage ); 391 } 392 393 394 372 395 /* Need this to prevent an out-of-bounds memory access when using 373 396 * X86 optimized code. … … 382 405 383 406 /* 384 * This is called by glTexImage[123]D in order to build a gl_texture_image 385 * object given the client's parameters and image data. 386 * 387 * NOTES: Width, height and depth should include the border. 388 * All texture image parameters should have already been error checked. 407 * Called by glTexImage[123]D. Fill in a texture image with data given 408 * by the client. All pixel transfer and unpack modes are handled here. 409 * NOTE: All texture image parameters should have already been error checked. 389 410 */ 390 static struct gl_texture_image *391 make_texture_image( GLcontext *ctx, GLint internalFormat,392 GLint width, GLint height, GLint depth, GLint border,411 static void 412 make_texture_image( GLcontext *ctx, 413 struct gl_texture_image *texImage, 393 414 GLenum srcFormat, GLenum srcType, const GLvoid *pixels, 394 415 const struct gl_pixelstore_attrib *unpacking) 395 416 { 396 417 GLint components, numPixels; 397 struct gl_texture_image *texImage; 398 399 assert(width > 0); 400 assert(height > 0); 401 assert(depth > 0); 402 assert(border == 0 || border == 1); 403 assert(pixels); 404 assert(unpacking); 405 406 407 /* 408 * Allocate and initialize the texture_image struct 409 */ 410 texImage = gl_alloc_texture_image(); 411 if (!texImage) 412 return NULL; 413 414 texImage->Format = (GLenum) decode_internal_format(internalFormat); 415 set_teximage_component_sizes( texImage ); 416 texImage->IntFormat = (GLenum) internalFormat; 417 texImage->Border = border; 418 texImage->Width = width; 419 texImage->Height = height; 420 texImage->Depth = depth; 421 texImage->WidthLog2 = logbase2(width - 2 * border); 422 if (height == 1) /* 1-D texture */ 423 texImage->HeightLog2 = 0; 424 else 425 texImage->HeightLog2 = logbase2(height - 2 * border); 426 if (depth == 1) /* 2-D texture */ 427 texImage->DepthLog2 = 0; 428 else 429 texImage->DepthLog2 = logbase2(depth - 2 * border); 430 texImage->Width2 = 1 << texImage->WidthLog2; 431 texImage->Height2 = 1 << texImage->HeightLog2; 432 texImage->Depth2 = 1 << texImage->DepthLog2; 433 texImage->MaxLog2 = MAX2(texImage->WidthLog2, texImage->HeightLog2); 434 418 GLint internalFormat, width, height, depth, border; 419 420 ASSERT(ctx); 421 ASSERT(texImage); 422 ASSERT(!texImage->Data); 423 ASSERT(pixels); 424 ASSERT(unpacking); 425 426 internalFormat = texImage->IntFormat; 427 width = texImage->Width; 428 height = texImage->Height; 429 depth = texImage->Depth; 430 border = texImage->Border; 435 431 components = components_in_intformat(internalFormat); 436 numPixels = texImage->Width * texImage->Height * texImage->Depth; 432 433 ASSERT(width > 0); 434 ASSERT(height > 0); 435 ASSERT(depth > 0); 436 ASSERT(border == 0 || border == 1); 437 ASSERT(pixels); 438 ASSERT(unpacking); 439 ASSERT(components); 440 441 numPixels = width * height * depth; 437 442 438 443 texImage->Data = (GLubyte *) MALLOC(numPixels * components + EXTRA_BYTE); 439 440 if (!texImage->Data) { 441 /* out of memory */ 442 gl_free_texture_image(texImage); 443 return NULL; 444 } 445 444 if (!texImage->Data) 445 return; /* out of memory */ 446 446 447 447 /* … … 457 457 && srcType == GL_UNSIGNED_BYTE && depth == 1) { 458 458 459 if (srcFormat == internalFormat) { 459 if (srcFormat == internalFormat || 460 (srcFormat == GL_LUMINANCE && internalFormat == 1) || 461 (srcFormat == GL_LUMINANCE_ALPHA && internalFormat == 2) || 462 (srcFormat == GL_RGB && internalFormat == 3) || 463 (srcFormat == GL_RGBA && internalFormat == 4)) { 460 464 /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA, 461 465 * GL_LUMINANCE_ALPHA, etc. texture formats. 462 466 */ 463 const GLubyte *src = (GLubyte *)gl_pixel_addr_in_image(unpacking, 464 pixels, width, height, srcFormat, srcType, 0, 0, 0); 465 const GLubyte *src1 = (GLubyte *)gl_pixel_addr_in_image(unpacking, 466 pixels, width, height, srcFormat, srcType, 0, 1, 0); 467 const GLint srcStride = src1 - src; 467 const GLubyte *src = (const GLubyte *) _mesa_image_address( 468 unpacking, pixels, width, height, srcFormat, srcType, 0, 0, 0); 469 const GLint srcStride = _mesa_image_row_stride(unpacking, width, 470 srcFormat, srcType); 468 471 GLubyte *dst = texImage->Data; 469 472 GLint dstBytesPerRow = width * components * sizeof(GLubyte); … … 479 482 } 480 483 } 481 return texImage; /* all done */484 return; /* all done */ 482 485 } 483 486 else if (srcFormat == GL_RGBA && internalFormat == GL_RGB) { 484 487 /* commonly used by Quake */ 485 const GLubyte *src = (GLubyte *)gl_pixel_addr_in_image(unpacking, 486 pixels, width, height, srcFormat, srcType, 0, 0, 0); 487 const GLubyte *src1 = (GLubyte *)gl_pixel_addr_in_image(unpacking, 488 pixels, width, height, srcFormat, srcType, 0, 1, 0); 489 const GLint srcStride = src1 - src; 488 const GLubyte *src = (const GLubyte *) _mesa_image_address( 489 unpacking, pixels, width, height, srcFormat, srcType, 0, 0, 0); 490 const GLint srcStride = _mesa_image_row_stride(unpacking, width, 491 srcFormat, srcType); 490 492 GLubyte *dst = texImage->Data; 491 493 GLint i, j; … … 500 502 src += srcStride; 501 503 } 502 return texImage; /* all done */504 return; /* all done */ 503 505 } 504 506 } … … 516 518 for (img = 0; img < depth; img++) { 517 519 for (row = 0; row < height; row++) { 518 const GLvoid *source = gl_pixel_addr_in_image(unpacking,520 const GLvoid *source = _mesa_image_address(unpacking, 519 521 pixels, width, height, srcFormat, srcType, img, row, 0); 520 522 _mesa_unpack_index_span(ctx, width, dstType, dest, … … 532 534 for (img = 0; img < depth; img++) { 533 535 for (row = 0; row < height; row++) { 534 const GLvoid *source = gl_pixel_addr_in_image(unpacking,536 const GLvoid *source = _mesa_image_address(unpacking, 535 537 pixels, width, height, srcFormat, srcType, img, row, 0); 536 538 _mesa_unpack_ubyte_color_span(ctx, width, dstFormat, dest, … … 540 542 } 541 543 } 542 543 return texImage; /* All done! */544 544 } 545 545 … … 549 549 * glTexImage[123]D can accept a NULL image pointer. In this case we 550 550 * create a texture image with unspecified image contents per the OpenGL 551 * spec. 551 * spec. This function creates an empty image for the given texture image. 552 552 */ 553 static struct gl_texture_image * 554 make_null_texture( GLcontext *ctx, GLenum internalFormat, 555 GLsizei width, GLsizei height, GLsizei depth, GLint border ) 553 static void 554 make_null_texture( struct gl_texture_image *texImage ) 556 555 { 557 556 GLint components; 558 struct gl_texture_image *texImage;559 557 GLint numPixels; 560 (void) ctx; 561 562 /*internalFormat = decode_internal_format(internalFormat);*/ 563 components = components_in_intformat(internalFormat); 564 numPixels = width * height * depth; 565 566 texImage = gl_alloc_texture_image(); 567 if (!texImage) 568 return NULL; 569 570 texImage->Format = (GLenum) decode_internal_format(internalFormat); 571 set_teximage_component_sizes( texImage ); 572 texImage->IntFormat = internalFormat; 573 texImage->Border = border; 574 texImage->Width = width; 575 texImage->Height = height; 576 texImage->Depth = depth; 577 texImage->WidthLog2 = logbase2(width - 2*border); 578 if (height==1) /* 1-D texture */ 579 texImage->HeightLog2 = 0; 580 else 581 texImage->HeightLog2 = logbase2(height - 2*border); 582 if (depth==1) /* 2-D texture */ 583 texImage->DepthLog2 = 0; 584 else 585 texImage->DepthLog2 = logbase2(depth - 2*border); 586 texImage->Width2 = 1 << texImage->WidthLog2; 587 texImage->Height2 = 1 << texImage->HeightLog2; 588 texImage->Depth2 = 1 << texImage->DepthLog2; 589 texImage->MaxLog2 = MAX2( texImage->WidthLog2, texImage->HeightLog2 ); 590 591 /* XXX should we really allocate memory for the image or let it be NULL? */ 592 /*texImage->Data = NULL;*/ 558 559 ASSERT(texImage); 560 ASSERT(!texImage->Data); 561 562 components = components_in_intformat(texImage->IntFormat); 563 numPixels = texImage->Width * texImage->Height * texImage->Depth; 593 564 594 565 texImage->Data = (GLubyte *) MALLOC( numPixels * components + EXTRA_BYTE ); … … 600 571 */ 601 572 if (texImage->Data) { 602 char message[8][32] = {573 static const char message[8][32] = { 603 574 " X X XXXXX XXX X ", 604 575 " XX XX X X X X X ", … … 613 584 GLubyte *imgPtr = texImage->Data; 614 585 GLint i, j, k; 615 for (i =0;i<height;i++) {586 for (i = 0; i < texImage->Height; i++) { 616 587 GLint srcRow = 7 - i % 8; 617 for (j =0;j<width;j++) {588 for (j = 0; j < texImage->Width; j++) { 618 589 GLint srcCol = j % 32; 619 590 GLint texel = (message[srcRow][srcCol]=='X') ? 255 : 70; … … 624 595 } 625 596 } 626 627 return texImage;628 597 } 629 598 … … 674 643 675 644 /* Border */ 676 if (border !=0 && border!=1) {645 if (border != 0 && border != 1) { 677 646 if (!isProxy) { 678 647 char message[100]; … … 719 688 720 689 /* Level */ 721 if (level <0 || level>=ctx->Const.MaxTextureLevels) {690 if (level < 0 || level >= ctx->Const.MaxTextureLevels) { 722 691 if (!isProxy) { 723 692 char message[100]; … … 728 697 } 729 698 730 iformat = decode_internal_format( internalFormat );699 iformat = _mesa_base_tex_format( internalFormat ); 731 700 if (iformat < 0) { 732 701 if (!isProxy) { … … 738 707 } 739 708 740 if (! gl_is_legal_format_and_type( format, type )) {709 if (!_mesa_is_legal_format_and_type( format, type )) { 741 710 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there 742 711 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. … … 763 732 */ 764 733 static GLboolean 765 subtexture_error_check( GLcontext *ctx, GL int dimensions,734 subtexture_error_check( GLcontext *ctx, GLuint dimensions, 766 735 GLenum target, GLint level, 767 736 GLint xoffset, GLint yoffset, GLint zoffset, … … 854 823 } 855 824 856 if (! gl_is_legal_format_and_type(format, type)) {825 if (!_mesa_is_legal_format_and_type(format, type)) { 857 826 char message[100]; 858 827 sprintf(message, "glTexSubImage%dD(format or type)", dimensions); … … 871 840 */ 872 841 static GLboolean 873 copytexture_error_check( GLcontext *ctx, GL int dimensions,842 copytexture_error_check( GLcontext *ctx, GLuint dimensions, 874 843 GLenum target, GLint level, GLint internalFormat, 875 844 GLint width, GLint height, GLint border ) … … 927 896 } 928 897 929 iformat = decode_internal_format( internalFormat );898 iformat = _mesa_base_tex_format( internalFormat ); 930 899 if (iformat < 0) { 931 900 char message[100]; … … 941 910 942 911 static GLboolean 943 copytexsubimage_error_check( GLcontext *ctx, GL int dimensions,912 copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, 944 913 GLenum target, GLint level, 945 914 GLint xoffset, GLint yoffset, GLint zoffset, … … 1043 1012 * Called from the API. Note that width includes the border. 1044 1013 */ 1045 void gl_TexImage1D( GLcontext *ctx, GLenum target, GLint level,1046 GLint internalformat,1047 1048 1049 { 1050 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];1014 void 1015 _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, 1016 GLsizei width, GLint border, GLenum format, 1017 GLenum type, const GLvoid *pixels ) 1018 { 1019 GET_CURRENT_CONTEXT(ctx); 1051 1020 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage1D"); 1052 1021 1053 1022 if (target==GL_TEXTURE_1D) { 1054 struct gl_texture_image *teximage; 1055 if (texture_error_check( ctx, target, level, internalformat, 1023 struct gl_texture_unit *texUnit; 1024 struct gl_texture_object *texObj; 1025 struct gl_texture_image *texImage; 1026 1027 if (texture_error_check( ctx, target, level, internalFormat, 1056 1028 format, type, 1, width, 1, 1, border )) { 1057 /* error in texture image was detected */ 1058 return; 1059 } 1060 1061 /* free current texture image, if any */ 1062 if (texUnit->CurrentD[1]->Image[level]) { 1063 gl_free_texture_image( texUnit->CurrentD[1]->Image[level] ); 1064 } 1065 1066 /* make new texture from source image */ 1029 return; /* error in texture image was detected */ 1030 } 1031 1032 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1033 texObj = texUnit->CurrentD[1]; 1034 texImage = texObj->Image[level]; 1035 1036 if (!texImage) { 1037 texImage = gl_alloc_texture_image(); 1038 texObj->Image[level] = texImage; 1039 if (!texImage) { 1040 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); 1041 return; 1042 } 1043 } 1044 else if (texImage->Data) { 1045 FREE(texImage->Data); 1046 texImage->Data = NULL; 1047 } 1048 1049 /* setup the teximage struct's fields */ 1050 init_texture_image(texImage, width, 1, 1, border, internalFormat); 1051 1052 /* process the texture image */ 1067 1053 if (pixels) { 1068 teximage = make_texture_image(ctx, internalformat, width, 1, 1, 1069 border, format, type, pixels, &ctx->Unpack); 1054 GLboolean retain = GL_TRUE; 1055 GLboolean success = GL_FALSE; 1056 if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA 1057 && ctx->Driver.TexImage1D) { 1058 /* let device driver try to use raw image */ 1059 success = (*ctx->Driver.TexImage1D)( ctx, target, level, format, 1060 type, pixels, &ctx->Unpack, 1061 texObj, texImage, &retain); 1062 } 1063 if (retain || !success) { 1064 /* make internal copy of the texture image */ 1065 make_texture_image(ctx, texImage, format, type, 1066 pixels, &ctx->Unpack); 1067 if (!success && ctx->Driver.TexImage1D) { 1068 /* let device driver try to use unpacked image */ 1069 (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format, 1070 GL_UNSIGNED_BYTE, texImage->Data, 1071 &_mesa_native_packing, 1072 texObj, texImage, &retain); 1073 } 1074 } 1075 if (!retain && texImage->Data) { 1076 FREE(texImage->Data); 1077 texImage->Data = NULL; 1078 } 1070 1079 } 1071 1080 else { 1072 teximage = make_null_texture(ctx, (GLenum) internalformat, 1073 width, 1, 1, border); 1074 } 1075 1076 /* install new texture image */ 1077 texUnit->CurrentD[1]->Image[level] = teximage; 1078 gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[1] ); 1081 make_null_texture(texImage); 1082 if (ctx->Driver.TexImage1D) { 1083 GLboolean retain; 1084 (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format, 1085 GL_UNSIGNED_BYTE, texImage->Data, 1086 &_mesa_native_packing, 1087 texObj, texImage, &retain); 1088 } 1089 } 1090 1091 /* state update */ 1092 gl_put_texobj_on_dirty_list( ctx, texObj ); 1079 1093 ctx->NewState |= NEW_TEXTURING; 1080 1081 /* tell driver about change */1082 if (ctx->Driver.TexImage) {1083 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_1D,1084 texUnit->CurrentD[1],1085 level, internalformat, teximage );1086 }1087 1094 } 1088 1095 else if (target==GL_PROXY_TEXTURE_1D) { 1089 1096 /* Proxy texture: check for errors and update proxy state */ 1090 if (texture_error_check( ctx, target, level, internal format,1097 if (texture_error_check( ctx, target, level, internalFormat, 1091 1098 format, type, 1, width, 1, 1, border )) { 1092 1099 if (level>=0 && level<ctx->Const.MaxTextureLevels) { … … 1098 1105 ctx->Texture.Proxy1D->Image[level]->Format = (GLenum) format; 1099 1106 set_teximage_component_sizes( ctx->Texture.Proxy1D->Image[level] ); 1100 ctx->Texture.Proxy1D->Image[level]->IntFormat = (GLenum) internal format;1107 ctx->Texture.Proxy1D->Image[level]->IntFormat = (GLenum) internalFormat; 1101 1108 ctx->Texture.Proxy1D->Image[level]->Border = border; 1102 1109 ctx->Texture.Proxy1D->Image[level]->Width = width; … … 1112 1119 1113 1120 1114 void gl_TexImage2D( GLcontext *ctx, GLenum target, GLint level,1115 GLint internalformat,1116 1117 1118 1119 { 1120 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];1121 void 1122 _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 1123 GLsizei width, GLsizei height, GLint border, 1124 GLenum format, GLenum type, 1125 const GLvoid *pixels ) 1126 { 1127 GET_CURRENT_CONTEXT(ctx); 1121 1128 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage2D"); 1122 1129 1123 1130 if (target==GL_TEXTURE_2D) { 1124 struct gl_texture_image *teximage; 1125 if (texture_error_check( ctx, target, level, internalformat, 1131 struct gl_texture_unit *texUnit; 1132 struct gl_texture_object *texObj; 1133 struct gl_texture_image *texImage; 1134 1135 if (texture_error_check( ctx, target, level, internalFormat, 1126 1136 format, type, 2, width, height, 1, border )) { 1127 /* error in texture image was detected */ 1128 return; 1129 } 1130 1131 /* free current texture image, if any */ 1132 if (texUnit->CurrentD[2]->Image[level]) { 1133 gl_free_texture_image( texUnit->CurrentD[2]->Image[level] ); 1134 } 1135 1136 /* make new texture from source image */ 1137 return; /* error in texture image was detected */ 1138 } 1139 1140 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1141 texObj = texUnit->CurrentD[2]; 1142 texImage = texObj->Image[level]; 1143 1144 if (!texImage) { 1145 texImage = gl_alloc_texture_image(); 1146 texObj->Image[level] = texImage; 1147 if (!texImage) { 1148 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); 1149 return; 1150 } 1151 } 1152 else if (texImage->Data) { 1153 FREE(texImage->Data); 1154 texImage->Data = NULL; 1155 } 1156 1157 /* setup the teximage struct's fields */ 1158 init_texture_image(texImage, width, height, 1, border, internalFormat); 1159 1160 /* process the texture image */ 1137 1161 if (pixels) { 1138 teximage = make_texture_image(ctx, internalformat, width, height, 1, 1139 border, format, type, pixels, &ctx->Unpack); 1162 GLboolean retain = GL_TRUE; 1163 GLboolean success = GL_FALSE; 1164 if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA 1165 && ctx->Driver.TexImage2D) { 1166 /* let device driver try to use raw image */ 1167 success = (*ctx->Driver.TexImage2D)( ctx, target, level, format, 1168 type, pixels, &ctx->Unpack, 1169 texObj, texImage, &retain); 1170 } 1171 if (retain || !success) { 1172 /* make internal copy of the texture image */ 1173 make_texture_image(ctx, texImage, format, type, 1174 pixels, &ctx->Unpack); 1175 if (!success && ctx->Driver.TexImage2D) { 1176 /* let device driver try to use unpacked image */ 1177 (*ctx->Driver.TexImage2D)( ctx, target, level, texImage->Format, 1178 GL_UNSIGNED_BYTE, texImage->Data, 1179 &_mesa_native_packing, 1180 texObj, texImage, &retain); 1181 } 1182 } 1183 if (!retain && texImage->Data) { 1184 FREE(texImage->Data); 1185 texImage->Data = NULL; 1186 } 1140 1187 } 1141 1188 else { 1142 teximage = make_null_texture(ctx, (GLenum) internalformat, 1143 width, height, 1, border); 1144 } 1145 1146 /* install new texture image */ 1147 texUnit->CurrentD[2]->Image[level] = teximage; 1148 gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[2] ); 1189 make_null_texture(texImage); 1190 if (ctx->Driver.TexImage2D) { 1191 GLboolean retain; 1192 (*ctx->Driver.TexImage2D)( ctx, target, level, texImage->Format, 1193 GL_UNSIGNED_BYTE, texImage->Data, 1194 &_mesa_native_packing, 1195 texObj, texImage, &retain); 1196 } 1197 } 1198 1199 #define OLD_DD_TEXTURE 1200 #ifdef OLD_DD_TEXTURE 1201 /* XXX this will be removed in the future */ 1202 if (ctx->Driver.TexImage) { 1203 (*ctx->Driver.TexImage)( ctx, target, texObj, level, internalFormat, 1204 texImage ); 1205 } 1206 #endif 1207 1208 /* state update */ 1209 gl_put_texobj_on_dirty_list( ctx, texObj ); 1149 1210 ctx->NewState |= NEW_TEXTURING; 1150 1151 /* tell driver about change */1152 if (ctx->Driver.TexImage) {1153 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_2D,1154 texUnit->CurrentD[2],1155 level, internalformat, teximage );1156 }1157 1211 } 1158 1212 else if (target==GL_PROXY_TEXTURE_2D) { 1159 1213 /* Proxy texture: check for errors and update proxy state */ 1160 if (texture_error_check( ctx, target, level, internal format,1214 if (texture_error_check( ctx, target, level, internalFormat, 1161 1215 format, type, 2, width, height, 1, border )) { 1162 1216 if (level>=0 && level<ctx->Const.MaxTextureLevels) { … … 1168 1222 ctx->Texture.Proxy2D->Image[level]->Format = (GLenum) format; 1169 1223 set_teximage_component_sizes( ctx->Texture.Proxy2D->Image[level] ); 1170 ctx->Texture.Proxy2D->Image[level]->IntFormat = (GLenum) internal format;1224 ctx->Texture.Proxy2D->Image[level]->IntFormat = (GLenum) internalFormat; 1171 1225 ctx->Texture.Proxy2D->Image[level]->Border = border; 1172 1226 ctx->Texture.Proxy2D->Image[level]->Width = width; … … 1187 1241 * Note that width and height include the border. 1188 1242 */ 1189 void gl_TexImage3D( GLcontext *ctx, GLenum target, GLint level,1190 GLint internalformat,1191 1192 1193 1194 { 1195 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];1243 void 1244 _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, 1245 GLsizei width, GLsizei height, GLsizei depth, 1246 GLint border, GLenum format, GLenum type, 1247 const GLvoid *pixels ) 1248 { 1249 GET_CURRENT_CONTEXT(ctx); 1196 1250 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage3D"); 1197 1251 1198 if (target==GL_TEXTURE_3D) { 1199 struct gl_texture_image *teximage; 1200 if (texture_error_check( ctx, target, level, internalformat, 1252 if (target==GL_TEXTURE_3D_EXT) { 1253 struct gl_texture_unit *texUnit; 1254 struct gl_texture_object *texObj; 1255 struct gl_texture_image *texImage; 1256 if (texture_error_check( ctx, target, level, internalFormat, 1201 1257 format, type, 3, width, height, depth, 1202 1258 border )) { 1203 /* error in texture image was detected */ 1204 return; 1205 } 1206 1207 /* free current texture image, if any */ 1208 if (texUnit->CurrentD[3]->Image[level]) { 1209 gl_free_texture_image( texUnit->CurrentD[3]->Image[level] ); 1210 } 1211 1212 /* make new texture from source image */ 1259 return; /* error in texture image was detected */ 1260 } 1261 1262 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1263 texObj = texUnit->CurrentD[3]; 1264 texImage = texObj->Image[level]; 1265 1266 if (!texImage) { 1267 texImage = gl_alloc_texture_image(); 1268 texObj->Image[level] = texImage; 1269 if (!texImage) { 1270 gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); 1271 return; 1272 } 1273 } 1274 else if (texImage->Data) { 1275 FREE(texImage->Data); 1276 texImage->Data = NULL; 1277 } 1278 1279 /* setup the teximage struct's fields */ 1280 init_texture_image(texImage, width, height, depth, 1281 border, internalFormat); 1282 1283 /* process the texture image */ 1213 1284 if (pixels) { 1214 teximage = make_texture_image(ctx, internalformat, width, height, 1215 depth, border, format, type, pixels, &ctx->Unpack); 1285 GLboolean retain = GL_TRUE; 1286 GLboolean success = GL_FALSE; 1287 if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA 1288 && ctx->Driver.TexImage3D) { 1289 /* let device driver try to use raw image */ 1290 success = (*ctx->Driver.TexImage3D)( ctx, target, level, format, 1291 type, pixels, &ctx->Unpack, 1292 texObj, texImage, &retain); 1293 } 1294 if (retain || !success) { 1295 /* make internal copy of the texture image */ 1296 make_texture_image(ctx, texImage, format, type, 1297 pixels, &ctx->Unpack); 1298 if (!success && ctx->Driver.TexImage3D) { 1299 /* let device driver try to use unpacked image */ 1300 (*ctx->Driver.TexImage3D)( ctx, target, level, texImage->Format, 1301 GL_UNSIGNED_BYTE, texImage->Data, 1302 &_mesa_native_packing, 1303 texObj, texImage, &retain); 1304 } 1305 } 1306 if (!retain && texImage->Data) { 1307 FREE(texImage->Data); 1308 texImage->Data = NULL; 1309 } 1216 1310 } 1217 1311 else { 1218 teximage = make_null_texture(ctx, (GLenum) internalformat, 1219 width, height, depth, border); 1220 } 1221 1222 /* install new texture image */ 1223 texUnit->CurrentD[3]->Image[level] = teximage; 1224 gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[3] ); 1312 make_null_texture(texImage); 1313 if (ctx->Driver.TexImage3D) { 1314 GLboolean retain; 1315 (*ctx->Driver.TexImage3D)( ctx, target, level, texImage->Format, 1316 GL_UNSIGNED_BYTE, texImage->Data, 1317 &_mesa_native_packing, 1318 texObj, texImage, &retain); 1319 } 1320 } 1321 1322 /* state update */ 1323 gl_put_texobj_on_dirty_list( ctx, texObj ); 1225 1324 ctx->NewState |= NEW_TEXTURING; 1226 1227 /* tell driver about change */1228 if (ctx->Driver.TexImage) {1229 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_3D_EXT,1230 texUnit->CurrentD[3],1231 level, internalformat, teximage );1232 }1233 1325 } 1234 1326 else if (target==GL_PROXY_TEXTURE_3D_EXT) { 1235 1327 /* Proxy texture: check for errors and update proxy state */ 1236 if (texture_error_check( ctx, target, level, internal format,1328 if (texture_error_check( ctx, target, level, internalFormat, 1237 1329 format, type, 3, width, height, depth, 1238 1330 border )) { … … 1245 1337 ctx->Texture.Proxy3D->Image[level]->Format = (GLenum) format; 1246 1338 set_teximage_component_sizes( ctx->Texture.Proxy3D->Image[level] ); 1247 ctx->Texture.Proxy3D->Image[level]->IntFormat = (GLenum) internal format;1339 ctx->Texture.Proxy3D->Image[level]->IntFormat = (GLenum) internalFormat; 1248 1340 ctx->Texture.Proxy3D->Image[level]->Border = border; 1249 1341 ctx->Texture.Proxy3D->Image[level]->Width = width; … … 1259 1351 1260 1352 1261 1262 void gl_GetTexImage( GLcontext *ctx, GLenum target, GLint level, GLenum format, 1263 GLenum type, GLvoid *pixels ) 1264 { 1353 void 1354 _mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, 1355 GLsizei width, GLsizei height, GLsizei depth, 1356 GLint border, GLenum format, GLenum type, 1357 const GLvoid *pixels ) 1358 { 1359 _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, 1360 depth, border, format, type, pixels); 1361 } 1362 1363 1364 /* 1365 * Fetch a texture image from the device driver. 1366 * Store the results in the given texture object at the given mipmap level. 1367 */ 1368 static void 1369 get_teximage_from_driver( GLcontext *ctx, GLenum target, GLint level, 1370 const struct gl_texture_object *texObj ) 1371 { 1372 GLvoid *image; 1373 GLenum imgFormat, imgType; 1374 GLboolean freeImage; 1375 struct gl_texture_image *texImage; 1376 GLint destComponents, numPixels, srcBytesPerTexel; 1377 1378 if (!ctx->Driver.GetTexImage) 1379 return; 1380 1381 image = (*ctx->Driver.GetTexImage)( ctx, target, level, 1382 &imgFormat, &imgType, &freeImage); 1383 if (!image) 1384 return; 1385 1386 texImage = texObj->Image[level]; 1387 ASSERT(texImage); 1388 if (!texImage) 1389 return; 1390 1391 destComponents = components_in_intformat(texImage->Format); 1392 ASSERT(destComponents > 0); 1393 numPixels = texImage->Width * texImage->Height * texImage->Depth; 1394 ASSERT(numPixels > 0); 1395 srcBytesPerTexel = _mesa_bytes_per_pixel(imgFormat, imgType); 1396 ASSERT(srcBytesPerTexel > 0); 1397 1398 if (!texImage->Data) { 1399 /* Allocate memory for the texture image data */ 1400 texImage->Data = (GLubyte *) MALLOC(numPixels * destComponents + EXTRA_BYTE); 1401 } 1402 1403 if (imgFormat == texImage->Format && imgType == GL_UNSIGNED_BYTE) { 1404 /* We got lucky! The driver's format and type match Mesa's format. */ 1405 if (texImage->Data) { 1406 MEMCPY(texImage->Data, image, numPixels * destComponents); 1407 } 1408 } 1409 else { 1410 /* Convert the texture image from the driver's format to Mesa's 1411 * internal format. 1412 */ 1413 const GLint width = texImage->Width; 1414 const GLint height = texImage->Height; 1415 const GLint depth = texImage->Depth; 1416 const GLint destBytesPerRow = width * destComponents * sizeof(GLchan); 1417 const GLint srcBytesPerRow = width * srcBytesPerTexel; 1418 const GLenum dstType = GL_UNSIGNED_BYTE; 1419 const GLenum dstFormat = texImage->Format; 1420 const GLubyte *srcPtr = (const GLubyte *) image; 1421 GLubyte *destPtr = texImage->Data; 1422 1423 if (texImage->Format == GL_COLOR_INDEX) { 1424 /* color index texture */ 1425 GLint img, row; 1426 ASSERT(imgFormat == GL_COLOR_INDEX); 1427 for (img = 0; img < depth; img++) { 1428 for (row = 0; row < height; row++) { 1429 _mesa_unpack_index_span(ctx, width, dstType, destPtr, 1430 imgType, srcPtr, &_mesa_native_packing, GL_FALSE); 1431 destPtr += destBytesPerRow; 1432 srcPtr += srcBytesPerRow; 1433 } 1434 } 1435 } 1436 else { 1437 /* color texture */ 1438 GLint img, row; 1439 for (img = 0; img < depth; img++) { 1440 for (row = 0; row < height; row++) { 1441 _mesa_unpack_ubyte_color_span(ctx, width, dstFormat, destPtr, 1442 imgFormat, imgType, srcPtr, &_mesa_native_packing, GL_FALSE); 1443 destPtr += destBytesPerRow; 1444 srcPtr += srcBytesPerRow; 1445 } 1446 } 1447 } 1448 } 1449 1450 if (freeImage) 1451 FREE(image); 1452 } 1453 1454 1455 void 1456 _mesa_GetTexImage( GLenum target, GLint level, GLenum format, 1457 GLenum type, GLvoid *pixels ) 1458 { 1459 GET_CURRENT_CONTEXT(ctx); 1265 1460 const struct gl_texture_object *texObj; 1461 struct gl_texture_image *texImage; 1462 GLboolean discardImage; 1266 1463 1267 1464 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexImage"); … … 1272 1469 } 1273 1470 1274 if ( gl_sizeof_type(type) <= 0) {1471 if (_mesa_sizeof_type(type) <= 0) { 1275 1472 gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); 1276 1473 return; 1277 1474 } 1278 1475 1279 if ( gl_components_in_format(format) <= 0) {1476 if (_mesa_components_in_format(format) <= 0) { 1280 1477 gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); 1281 1478 return; … … 1283 1480 1284 1481 if (!pixels) 1285 return; /* XXX generate an error??? */1482 return; 1286 1483 1287 1484 switch (target) { … … 1300 1497 } 1301 1498 1302 if (texObj->Image[level] && texObj->Image[level]->Data) { 1303 const struct gl_texture_image *texImage = texObj->Image[level]; 1499 texImage = texObj->Image[level]; 1500 if (!texImage) { 1501 /* invalid mipmap level */ 1502 return; 1503 } 1504 1505 if (!texImage->Data) { 1506 /* try to get the texture image from the device driver */ 1507 get_teximage_from_driver(ctx, target, level, texObj); 1508 discardImage = GL_TRUE; 1509 } 1510 else { 1511 discardImage = GL_FALSE; 1512 } 1513 1514 if (texImage->Data) { 1304 1515 GLint width = texImage->Width; 1305 1516 GLint height = texImage->Height; … … 1308 1519 for (row = 0; row < height; row++) { 1309 1520 /* compute destination address in client memory */ 1310 GLvoid *dest = gl_pixel_addr_in_image( &ctx->Unpack, pixels,1521 GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels, 1311 1522 width, height, 1312 1523 format, type, 0, row, 0); 1313 1524 1314 assert(dest);1525 ASSERT(dest); 1315 1526 if (texImage->Format == GL_RGBA) { 1316 1527 const GLubyte *src = texImage->Data + row * width * 4 * sizeof(GLubyte); 1317 gl_pack_rgba_span( ctx, width, 1318 (const GLubyte (*)[4]) src, 1319 format, type, dest, 1320 &ctx->Pack, GL_TRUE ); 1528 _mesa_pack_rgba_span( ctx, width, (CONST GLubyte (*)[4]) src, 1529 format, type, dest, &ctx->Pack, GL_TRUE ); 1321 1530 } 1322 1531 else { … … 1381 1590 gl_problem( ctx, "bad format in gl_GetTexImage" ); 1382 1591 } 1383 gl_pack_rgba_span( ctx, width, (const GLubyte (*)[4])rgba, 1384 format, type, dest, &ctx->Pack, GL_TRUE ); 1385 } 1386 } 1387 } 1388 } 1389 1390 1391 1392 void gl_TexSubImage1D( GLcontext *ctx, GLenum target, GLint level, 1393 GLint xoffset, GLsizei width, 1394 GLenum format, GLenum type, 1395 const GLvoid *pixels ) 1396 { 1397 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1398 struct gl_texture_image *destTex; 1592 _mesa_pack_rgba_span( ctx, width, (const GLubyte (*)[4])rgba, 1593 format, type, dest, &ctx->Pack, GL_TRUE ); 1594 } 1595 } 1596 1597 /* if we got the teximage from the device driver we'll discard it now */ 1598 if (discardImage) { 1599 FREE(texImage->Data); 1600 texImage->Data = NULL; 1601 } 1602 } 1603 } 1604 1605 1606 1607 void 1608 _mesa_TexSubImage1D( GLenum target, GLint level, 1609 GLint xoffset, GLsizei width, 1610 GLenum format, GLenum type, 1611 const GLvoid *pixels ) 1612 { 1613 GET_CURRENT_CONTEXT(ctx); 1614 struct gl_texture_unit *texUnit; 1615 struct gl_texture_object *texObj; 1616 struct gl_texture_image *texImage; 1617 GLboolean success = GL_FALSE; 1399 1618 1400 1619 if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, 1401 1620 width, 1, 1, format, type)) { 1402 /* error was detected */ 1403 return; 1404 } 1405 1406 destTex = texUnit->CurrentD[1]->Image[level]; 1407 assert(destTex); 1621 return; /* error was detected */ 1622 } 1623 1624 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1625 texObj = texUnit->CurrentD[1]; 1626 texImage = texObj->Image[level]; 1627 ASSERT(texImage); 1408 1628 1409 1629 if (width == 0 || !pixels) … … 1411 1631 1412 1632 1413 /* 1414 * Replace the texture subimage 1415 */ 1416 { 1417 const GLint texComponents = components_in_intformat(destTex->Format); 1418 const GLenum texFormat = destTex->Format; 1419 const GLint xoffsetb = xoffset + destTex->Border; 1420 GLubyte *dst = destTex->Data + xoffsetb * texComponents; 1633 if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA 1634 && ctx->Driver.TexSubImage1D) { 1635 success = (*ctx->Driver.TexSubImage1D)( ctx, target, level, xoffset, 1636 width, format, type, pixels, 1637 &ctx->Unpack, texObj, texImage ); 1638 } 1639 if (!success) { 1640 /* XXX if Driver.TexSubImage1D, unpack image and try again? */ 1641 1642 const GLint texComponents = components_in_intformat(texImage->Format); 1643 const GLenum texFormat = texImage->Format; 1644 const GLint xoffsetb = xoffset + texImage->Border; 1645 GLboolean retain = GL_TRUE; 1646 if (!texImage->Data) { 1647 get_teximage_from_driver( ctx, target, level, texObj ); 1648 if (!texImage->Data) { 1649 make_null_texture(texImage); 1650 } 1651 if (!texImage->Data) 1652 return; /* we're really out of luck! */ 1653 } 1654 1421 1655 if (texFormat == GL_COLOR_INDEX) { 1422 1656 /* color index texture */ 1423 const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels, 1424 width, 1, format, type, 0, 0, 0); 1657 GLubyte *dst = texImage->Data + xoffsetb * texComponents; 1658 const GLvoid *src = _mesa_image_address(&ctx->Unpack, pixels, width, 1659 1, format, type, 0, 0, 0); 1425 1660 _mesa_unpack_index_span(ctx, width, GL_UNSIGNED_BYTE, dst, 1426 1661 type, src, &ctx->Unpack, GL_TRUE); 1427 1662 } 1428 1663 else { 1429 1664 /* color texture */ 1430 const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels, 1431 width, 1, format, type, 0, 0, 0); 1432 _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst, 1433 format, type, src, &ctx->Unpack, GL_TRUE); 1434 } 1435 } 1436 1437 gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[1] ); 1438 1439 /* 1440 * Inform device driver of texture image change. 1441 */ 1442 if (ctx->Driver.TexSubImage) { 1443 (*ctx->Driver.TexSubImage)(ctx, GL_TEXTURE_1D, texUnit->CurrentD[1], 1444 level, xoffset, 0, width, 1, 1445 texUnit->CurrentD[1]->Image[level]->IntFormat, 1446 destTex ); 1447 } 1448 else { 1449 if (ctx->Driver.TexImage) { 1450 (*ctx->Driver.TexImage)(ctx, GL_TEXTURE_1D, texUnit->CurrentD[1], 1451 level, 1452 texUnit->CurrentD[1]->Image[level]->IntFormat, 1453 destTex ); 1454 } 1455 } 1456 } 1457 1458 1459 void gl_TexSubImage2D( GLcontext *ctx, GLenum target, GLint level, 1460 GLint xoffset, GLint yoffset, 1461 GLsizei width, GLsizei height, 1462 GLenum format, GLenum type, 1463 const GLvoid *pixels ) 1464 { 1465 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1466 struct gl_texture_image *destTex; 1665 GLubyte *dst = texImage->Data + xoffsetb * texComponents; 1666 const GLvoid *src = _mesa_image_address(&ctx->Unpack, pixels, width, 1667 1, format, type, 0, 0, 0); 1668 _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst, format, 1669 type, src, &ctx->Unpack, GL_TRUE); 1670 } 1671 1672 if (ctx->Driver.TexImage1D) { 1673 (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format, 1674 GL_UNSIGNED_BYTE, texImage->Data, 1675 &_mesa_native_packing, texObj, texImage, 1676 &retain ); 1677 } 1678 1679 if (!retain && texImage->Data) { 1680 FREE(texImage->Data); 1681 texImage->Data = NULL; 1682 } 1683 } 1684 1685 /*gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[1] );*/ 1686 } 1687 1688 1689 void 1690 _mesa_TexSubImage2D( GLenum target, GLint level, 1691 GLint xoffset, GLint yoffset, 1692 GLsizei width, GLsizei height, 1693 GLenum format, GLenum type, 1694 const GLvoid *pixels ) 1695 { 1696 GET_CURRENT_CONTEXT(ctx); 1697 struct gl_texture_unit *texUnit; 1698 struct gl_texture_object *texObj; 1699 struct gl_texture_image *texImage; 1700 GLboolean success = GL_FALSE; 1467 1701 1468 1702 if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, 1469 1703 width, height, 1, format, type)) { 1470 /* error was detected */ 1471 return; 1472 } 1473 1474 destTex = texUnit->CurrentD[2]->Image[level]; 1475 assert(destTex); 1704 return; /* error was detected */ 1705 } 1706 1707 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1708 texObj = texUnit->CurrentD[2]; 1709 texImage = texObj->Image[level]; 1710 ASSERT(texImage); 1476 1711 1477 1712 if (width == 0 || height == 0 || !pixels) 1478 1713 return; /* no-op, not an error */ 1479 1714 1480 1481 /* 1482 * Replace the texture subimage 1483 */ 1484 { 1485 const GLint texComponents = components_in_intformat(destTex->Format); 1486 const GLenum texFormat = destTex->Format; 1487 const GLint xoffsetb = xoffset + destTex->Border; 1488 const GLint yoffsetb = yoffset + destTex->Border; 1489 GLubyte *dst = destTex->Data 1490 + (yoffsetb * destTex->Width + xoffsetb) * texComponents; 1715 if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA 1716 && ctx->Driver.TexSubImage2D) { 1717 success = (*ctx->Driver.TexSubImage2D)( ctx, target, level, xoffset, 1718 yoffset, width, height, format, type, 1719 pixels, &ctx->Unpack, texObj, texImage ); 1720 } 1721 if (!success) { 1722 /* XXX if Driver.TexSubImage2D, unpack image and try again? */ 1723 1724 const GLint texComponents = components_in_intformat(texImage->Format); 1725 const GLenum texFormat = texImage->Format; 1726 const GLint xoffsetb = xoffset + texImage->Border; 1727 const GLint yoffsetb = yoffset + texImage->Border; 1728 const GLint srcStride = _mesa_image_row_stride(&ctx->Unpack, width, 1729 format, type); 1730 const GLint dstStride = texImage->Width * texComponents *sizeof(GLubyte); 1731 GLboolean retain = GL_TRUE; 1732 1733 if (!texImage->Data) { 1734 get_teximage_from_driver( ctx, target, level, texObj ); 1735 if (!texImage->Data) { 1736 make_null_texture(texImage); 1737 } 1738 if (!texImage->Data) 1739 return; /* we're really out of luck! */ 1740 } 1741 1491 1742 if (texFormat == GL_COLOR_INDEX) { 1492 1743 /* color index texture */ 1493 const GLint stride = destTex->Width * sizeof(GLubyte); 1744 GLubyte *dst = texImage->Data 1745 + (yoffsetb * texImage->Width + xoffsetb) * texComponents; 1746 const GLubyte *src = (const GLubyte *)_mesa_image_address(&ctx->Unpack, pixels, 1747 width, height, format, type, 0, 0, 0); 1494 1748 GLint row; 1495 1749 for (row = 0; row < height; row++) { 1496 const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels, 1497 width, height, format, type, 0, row, 0); 1498 _mesa_unpack_index_span(ctx, width, GL_UNSIGNED_BYTE, dst, 1499 type, src, &ctx->Unpack, GL_TRUE); 1500 dst += stride; 1750 _mesa_unpack_index_span(ctx, width, GL_UNSIGNED_BYTE, dst, type, 1751 (const GLvoid *) src, &ctx->Unpack, GL_TRUE); 1752 src += srcStride; 1753 dst += dstStride; 1501 1754 } 1502 1755 } 1503 1756 else { 1504 1757 /* color texture */ 1505 const GLint stride = destTex->Width * texComponents * sizeof(GLubyte); 1758 GLubyte *dst = texImage->Data 1759 + (yoffsetb * texImage->Width + xoffsetb) * texComponents; 1760 const GLubyte *src = (const GLubyte *)_mesa_image_address(&ctx->Unpack, pixels, 1761 width, height, format, type, 0, 0, 0); 1506 1762 GLint row; 1507 1763 for (row = 0; row < height; row++) { 1508 const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels, 1509 width, height, format, type, 0, row, 0); 1510 _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst, 1511 format, type, src, &ctx->Unpack, GL_TRUE); 1512 dst += stride; 1513 } 1514 } 1515 } 1516 1517 gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[2] ); 1518 1519 /* 1520 * Inform device driver of texture image change. 1521 */ 1522 if (ctx->Driver.TexSubImage) { 1523 (*ctx->Driver.TexSubImage)(ctx, GL_TEXTURE_2D, texUnit->CurrentD[2], 1524 level, xoffset, yoffset, width, height, 1525 texUnit->CurrentD[2]->Image[level]->IntFormat, 1526 destTex ); 1527 } 1528 else { 1529 if (ctx->Driver.TexImage) { 1530 (*ctx->Driver.TexImage)(ctx, GL_TEXTURE_2D, texUnit->CurrentD[2], 1531 level, 1532 texUnit->CurrentD[2]->Image[level]->IntFormat, 1533 destTex ); 1534 } 1535 } 1536 } 1537 1538 1539 1540 void gl_TexSubImage3D( GLcontext *ctx, GLenum target, GLint level, 1541 GLint xoffset, GLint yoffset, GLint zoffset, 1542 GLsizei width, GLsizei height, GLsizei depth, 1543 GLenum format, GLenum type, 1544 const GLvoid *pixels ) 1545 { 1546 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1547 struct gl_texture_image *destTex; 1764 _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst, format, 1765 type, (const GLvoid *) src, &ctx->Unpack, GL_TRUE); 1766 src += srcStride; 1767 dst += dstStride; 1768 } 1769 } 1770 1771 if (ctx->Driver.TexImage2D) { 1772 (*ctx->Driver.TexImage2D)(ctx, target, level, texImage->Format, 1773 GL_UNSIGNED_BYTE, texImage->Data, 1774 &_mesa_native_packing, texObj, texImage, 1775 &retain); 1776 } 1777 1778 if (!retain && texImage->Data) { 1779 FREE(texImage->Data); 1780 texImage->Data = NULL; 1781 } 1782 1783 #ifdef OLD_DD_TEXTURE 1784 /* XXX this will be removed in the future */ 1785 if (ctx->Driver.TexSubImage) { 1786 (*ctx->Driver.TexSubImage)(ctx, target, texObj, level, 1787 xoffset, yoffset, width, height, 1788 texImage->IntFormat, texImage); 1789 } 1790 else if (ctx->Driver.TexImage) { 1791 (*ctx->Driver.TexImage)(ctx, GL_TEXTURE_2D, texObj, 1792 level, texImage->IntFormat, texImage ); 1793 } 1794 #endif 1795 } 1796 } 1797 1798 1799 1800 void 1801 _mesa_TexSubImage3D( GLenum target, GLint level, 1802 GLint xoffset, GLint yoffset, GLint zoffset, 1803 GLsizei width, GLsizei height, GLsizei depth, 1804 GLenum format, GLenum type, 1805 const GLvoid *pixels ) 1806 { 1807 GET_CURRENT_CONTEXT(ctx); 1808 struct gl_texture_unit *texUnit; 1809 struct gl_texture_object *texObj; 1810 struct gl_texture_image *texImage; 1811 GLboolean success = GL_FALSE; 1548 1812 1549 1813 if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, 1550 1814 width, height, depth, format, type)) { 1551 /* error was detected */ 1552 return; 1553 } 1554 1555 destTex = texUnit->CurrentD[3]->Image[level]; 1556 assert(destTex); 1815 return; /* error was detected */ 1816 } 1817 1818 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1819 texObj = texUnit->CurrentD[3]; 1820 texImage = texObj->Image[level]; 1821 ASSERT(texImage); 1557 1822 1558 1823 if (width == 0 || height == 0 || height == 0 || !pixels) 1559 1824 return; /* no-op, not an error */ 1560 1825 1561 /* 1562 * Replace the texture subimage 1563 */ 1564 { 1565 const GLint texComponents = components_in_intformat(destTex->Format); 1566 const GLenum texFormat = destTex->Format; 1567 const GLint xoffsetb = xoffset + destTex->Border; 1568 const GLint yoffsetb = yoffset + destTex->Border; 1569 const GLint zoffsetb = zoffset + destTex->Border; 1570 GLint dstRectArea = destTex->Width * destTex->Height; 1571 GLubyte *dst = destTex->Data 1572 + (zoffsetb * dstRectArea + yoffsetb * destTex->Width + xoffsetb) 1573 * texComponents; 1826 if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA 1827 && ctx->Driver.TexSubImage3D) { 1828 success = (*ctx->Driver.TexSubImage3D)( ctx, target, level, xoffset, 1829 yoffset, zoffset, width, height, depth, format, 1830 type, pixels, &ctx->Unpack, texObj, texImage ); 1831 } 1832 if (!success) { 1833 /* XXX if Driver.TexSubImage3D, unpack image and try again? */ 1834 1835 const GLint texComponents = components_in_intformat(texImage->Format); 1836 const GLenum texFormat = texImage->Format; 1837 const GLint xoffsetb = xoffset + texImage->Border; 1838 const GLint yoffsetb = yoffset + texImage->Border; 1839 const GLint zoffsetb = zoffset + texImage->Border; 1840 const GLint texWidth = texImage->Width; 1841 const GLint dstRectArea = texWidth * texImage->Height; 1842 const GLint srcStride = _mesa_image_row_stride(&ctx->Unpack, 1843 width, format, type); 1844 const GLint dstStride = texWidth * texComponents * sizeof(GLubyte); 1845 GLboolean retain = GL_TRUE; 1574 1846 1575 1847 if (texFormat == GL_COLOR_INDEX) { 1576 1848 /* color index texture */ 1577 const GLint stride = destTex->Width * sizeof(GLubyte);1578 1849 GLint img, row; 1579 1850 for (img = 0; img < depth; img++) { 1851 const GLubyte *src = (const GLubyte *)_mesa_image_address(&ctx->Unpack, pixels, 1852 width, height, format, type, img, 0, 0); 1853 GLubyte *dst = texImage->Data + ((zoffsetb + img) * dstRectArea 1854 + yoffsetb * texWidth + xoffsetb) * texComponents; 1580 1855 for (row = 0; row < height; row++) { 1581 const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels,1582 width, height, format, type, img, row, 0);1583 1856 _mesa_unpack_index_span(ctx, width, GL_UNSIGNED_BYTE, dst, 1584 type, src, &ctx->Unpack, GL_TRUE); 1585 dst += stride; 1857 type, (const GLvoid *) src, &ctx->Unpack, GL_TRUE); 1858 src += srcStride; 1859 dst += dstStride; 1586 1860 } 1587 1861 } … … 1589 1863 else { 1590 1864 /* color texture */ 1591 const GLint stride = destTex->Width * texComponents * sizeof(GLubyte);1592 1865 GLint img, row; 1593 1866 for (img = 0; img < depth; img++) { 1867 const GLubyte *src = (const GLubyte *)_mesa_image_address(&ctx->Unpack, pixels, 1868 width, height, format, type, img, 0, 0); 1869 GLubyte *dst = texImage->Data + ((zoffsetb + img) * dstRectArea 1870 + yoffsetb * texWidth + xoffsetb) * texComponents; 1594 1871 for (row = 0; row < height; row++) { 1595 const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels,1596 width, height, format, type, img, row, 0);1597 1872 _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst, 1598 format, type, src, &ctx->Unpack, GL_TRUE); 1599 dst += stride; 1873 format, type, (const GLvoid *) src, &ctx->Unpack, GL_TRUE); 1874 src += srcStride; 1875 dst += dstStride; 1600 1876 } 1601 1877 } 1602 1878 } 1603 } 1604 1605 gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[1] ); 1606 1607 /* 1608 * Inform device driver of texture image change. 1609 */ 1610 /* XXX todo */ 1879 1880 if (ctx->Driver.TexImage3D) { 1881 (*ctx->Driver.TexImage3D)(ctx, target, level, texImage->Format, 1882 GL_UNSIGNED_BYTE, texImage->Data, 1883 &_mesa_native_packing, texObj, texImage, 1884 &retain); 1885 } 1886 1887 if (!retain && texImage->Data) { 1888 FREE(texImage->Data); 1889 texImage->Data = NULL; 1890 } 1891 } 1611 1892 } 1612 1893 … … 1628 1909 GLubyte *image, *dst; 1629 1910 1630 image = (GLubyte *) MALLOC(width * height * 4 * sizeof(GLubyte));1911 image = (GLubyte *) MALLOC(width * height * 4 * sizeof(GLubyte)); 1631 1912 if (!image) 1632 1913 return NULL; 1633 1914 1634 1915 /* Select buffer to read from */ 1635 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer ); 1916 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 1917 ctx->Pixel.DriverReadBuffer ); 1636 1918 1637 1919 dst = image; 1638 1920 stride = width * 4 * sizeof(GLubyte); 1639 1921 for (i = 0; i < height; i++) { 1640 gl_read_rgba_span( ctx, width, x, y + i, (GLubyte (*)[4]) dst ); 1922 gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i, 1923 (GLubyte (*)[4]) dst ); 1641 1924 dst += stride; 1642 1925 } 1643 1926 1644 /* Restore drawing buffer */ 1645 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer ); 1927 /* Read from draw buffer (the default) */ 1928 (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, 1929 ctx->Color.DriverDrawBuffer ); 1646 1930 1647 1931 return image; … … 1650 1934 1651 1935 1652 void gl_CopyTexImage1D( GLcontext *ctx, GLenum target, GLint level, 1653 GLenum internalFormat, 1654 GLint x, GLint y, 1655 GLsizei width, GLint border ) 1656 { 1936 void 1937 _mesa_CopyTexImage1D( GLenum target, GLint level, 1938 GLenum internalFormat, 1939 GLint x, GLint y, 1940 GLsizei width, GLint border ) 1941 { 1942 GET_CURRENT_CONTEXT(ctx); 1657 1943 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexImage1D"); 1658 1944 1659 if (!copytexture_error_check(ctx, 1, target, level, internalFormat, 1660 width, 1, border)) { 1945 if (copytexture_error_check(ctx, 1, target, level, internalFormat, 1946 width, 1, border)) 1947 return; 1948 1949 if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA 1950 || !ctx->Driver.CopyTexImage1D 1951 || !(*ctx->Driver.CopyTexImage1D)(ctx, target, level, 1952 internalFormat, x, y, width, border)) 1953 { 1661 1954 GLubyte *image = read_color_image( ctx, x, y, width, 1 ); 1662 1955 if (!image) { … … 1664 1957 return; 1665 1958 } 1666 (*ctx->Exec .TexImage1D)( ctx,target, level, internalFormat, width,1667 border, GL_RGBA, GL_UNSIGNED_BYTE, image );1959 (*ctx->Exec->TexImage1D)( target, level, internalFormat, width, 1960 border, GL_RGBA, GL_UNSIGNED_BYTE, image ); 1668 1961 FREE(image); 1669 1962 } … … 1672 1965 1673 1966 1674 void gl_CopyTexImage2D( GLcontext *ctx, GLenum target, GLint level, 1675 GLenum internalFormat, 1676 GLint x, GLint y, GLsizei width, GLsizei height, 1677 GLint border ) 1678 { 1967 void 1968 _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, 1969 GLint x, GLint y, GLsizei width, GLsizei height, 1970 GLint border ) 1971 { 1972 GET_CURRENT_CONTEXT(ctx); 1679 1973 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexImage2D"); 1680 1974 1681 if (!copytexture_error_check(ctx, 2, target, level, internalFormat, 1682 width, height, border)) { 1975 if (copytexture_error_check(ctx, 2, target, level, internalFormat, 1976 width, height, border)) 1977 return; 1978 1979 if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA 1980 || !ctx->Driver.CopyTexImage2D 1981 || !(*ctx->Driver.CopyTexImage2D)(ctx, target, level, 1982 internalFormat, x, y, width, height, border)) 1983 { 1683 1984 GLubyte *image = read_color_image( ctx, x, y, width, height ); 1684 1985 if (!image) { … … 1686 1987 return; 1687 1988 } 1688 { 1689 struct gl_pixelstore_attrib save = ctx->Unpack; 1690 ctx->Unpack = defaultPacking; 1691 (ctx->Exec.TexImage2D)( ctx, target, level, internalFormat, width, 1692 height, border, GL_RGBA, GL_UNSIGNED_BYTE, image ); 1693 ctx->Unpack = save; /* restore */ 1694 } 1989 (ctx->Exec->TexImage2D)( target, level, internalFormat, width, 1990 height, border, GL_RGBA, GL_UNSIGNED_BYTE, image ); 1695 1991 FREE(image); 1696 1992 } … … 1708 2004 GLint dstx, GLint dsty, GLint dstz ) 1709 2005 { 1710 static struct gl_pixelstore_attrib packing = {1711 1, /* Alignment */1712 0, /* RowLength */1713 0, /* SkipPixels */1714 0, /* SkipRows */1715 0, /* ImageHeight */1716 0, /* SkipImages */1717 GL_FALSE, /* SwapBytes */1718 GL_FALSE /* LsbFirst */1719 };1720 1721 2006 GLint i; 1722 2007 GLint format, components, rectarea; … … 1735 2020 1736 2021 /* Select buffer to read from */ 1737 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer ); 2022 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 2023 ctx->Pixel.DriverReadBuffer ); 1738 2024 1739 2025 for (i = 0;i < height; i++) { 1740 2026 GLubyte rgba[MAX_WIDTH][4]; 1741 2027 GLubyte *dst; 1742 gl_read_rgba_span( ctx, width, srcx, srcy + i, rgba );2028 gl_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, srcy + i, rgba ); 1743 2029 dst = dest->Data + ( zoffset + (dsty+i) * texwidth + dstx) * components; 1744 _mesa_unpack_ubyte_color_span(ctx, width, (GLenum)format, dst,2030 _mesa_unpack_ubyte_color_span(ctx, width, format, dst, 1745 2031 GL_RGBA, GL_UNSIGNED_BYTE, rgba, 1746 &packing, GL_TRUE); 1747 } 1748 1749 /* Restore drawing buffer */ 1750 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer ); 1751 } 1752 1753 1754 1755 1756 void gl_CopyTexSubImage1D( GLcontext *ctx, GLenum target, GLint level, 1757 GLint xoffset, GLint x, GLint y, GLsizei width ) 1758 { 2032 &_mesa_native_packing, GL_TRUE); 2033 } 2034 2035 /* Read from draw buffer (the default) */ 2036 (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, 2037 ctx->Color.DriverDrawBuffer ); 2038 } 2039 2040 2041 2042 2043 void 2044 _mesa_CopyTexSubImage1D( GLenum target, GLint level, 2045 GLint xoffset, GLint x, GLint y, GLsizei width ) 2046 { 2047 GET_CURRENT_CONTEXT(ctx); 1759 2048 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage1D"); 1760 2049 1761 if (!copytexsubimage_error_check(ctx, 1, target, level, 1762 xoffset, 0, 0, width, 1)) { 2050 if (copytexsubimage_error_check(ctx, 1, target, level, 2051 xoffset, 0, 0, width, 1)) 2052 return; 2053 2054 if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA 2055 || !ctx->Driver.CopyTexSubImage1D 2056 || !(*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, 2057 xoffset, x, y, width)) { 1763 2058 struct gl_texture_unit *texUnit; 1764 2059 struct gl_texture_image *teximage; 1765 2060 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1766 2061 teximage = texUnit->CurrentD[1]->Image[level]; 1767 assert(teximage);2062 ASSERT(teximage); 1768 2063 if (teximage->Data) { 1769 2064 copy_tex_sub_image(ctx, teximage, width, 1, x, y, xoffset, 0, 0); 1770 /* tell driver about the change */ 1771 if (ctx->Driver.TexImage) { 1772 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_1D, 1773 texUnit->CurrentD[1], 1774 level, teximage->IntFormat, teximage ); 1775 } 1776 } 1777 } 1778 } 1779 1780 1781 1782 void gl_CopyTexSubImage2D( GLcontext *ctx, GLenum target, GLint level, 1783 GLint xoffset, GLint yoffset, 1784 GLint x, GLint y, GLsizei width, GLsizei height ) 1785 { 2065 /* tell driver about the change */ 2066 /* XXX this is obsolete */ 2067 if (ctx->Driver.TexImage) { 2068 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_1D, 2069 texUnit->CurrentD[1], 2070 level, teximage->IntFormat, teximage ); 2071 } 2072 } 2073 } 2074 } 2075 2076 2077 2078 void 2079 _mesa_CopyTexSubImage2D( GLenum target, GLint level, 2080 GLint xoffset, GLint yoffset, 2081 GLint x, GLint y, GLsizei width, GLsizei height ) 2082 { 2083 GET_CURRENT_CONTEXT(ctx); 1786 2084 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage2D"); 1787 2085 1788 if (!copytexsubimage_error_check(ctx, 2, target, level, 1789 xoffset, yoffset, 0, width, height)) { 2086 if (copytexsubimage_error_check(ctx, 2, target, level, 2087 xoffset, yoffset, 0, width, height)) 2088 return; 2089 2090 if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA 2091 || !ctx->Driver.CopyTexSubImage2D 2092 || !(*ctx->Driver.CopyTexSubImage2D)(ctx, target, level, 2093 xoffset, yoffset, x, y, width, height )) { 1790 2094 struct gl_texture_unit *texUnit; 1791 2095 struct gl_texture_image *teximage; 1792 2096 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1793 2097 teximage = texUnit->CurrentD[2]->Image[level]; 1794 assert(teximage);2098 ASSERT(teximage); 1795 2099 if (teximage->Data) { 1796 2100 copy_tex_sub_image(ctx, teximage, width, height, 1797 2101 x, y, xoffset, yoffset, 0); 1798 /* tell driver about the change */ 1799 if (ctx->Driver.TexImage) { 1800 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_2D, 1801 texUnit->CurrentD[2], 1802 level, teximage->IntFormat, teximage ); 1803 } 1804 } 1805 } 1806 } 1807 1808 1809 1810 void gl_CopyTexSubImage3D( GLcontext *ctx, GLenum target, GLint level, 1811 GLint xoffset, GLint yoffset, GLint zoffset, 1812 GLint x, GLint y, GLsizei width, GLsizei height ) 1813 { 2102 /* tell driver about the change */ 2103 /* XXX this is obsolete */ 2104 if (ctx->Driver.TexImage) { 2105 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_2D, 2106 texUnit->CurrentD[2], 2107 level, teximage->IntFormat, teximage ); 2108 } 2109 } 2110 } 2111 } 2112 2113 2114 2115 void 2116 _mesa_CopyTexSubImage3D( GLenum target, GLint level, 2117 GLint xoffset, GLint yoffset, GLint zoffset, 2118 GLint x, GLint y, GLsizei width, GLsizei height ) 2119 { 2120 GET_CURRENT_CONTEXT(ctx); 1814 2121 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage3D"); 1815 2122 1816 if (!copytexsubimage_error_check(ctx, 3, target, level, 1817 xoffset, yoffset, zoffset, width, height)) { 2123 if (copytexsubimage_error_check(ctx, 3, target, level, 2124 xoffset, yoffset, zoffset, width, height)) 2125 return; 2126 2127 if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA 2128 || !ctx->Driver.CopyTexSubImage3D 2129 || !(*ctx->Driver.CopyTexSubImage3D)(ctx, target, level, 2130 xoffset, yoffset, zoffset, x, y, width, height )) { 1818 2131 struct gl_texture_unit *texUnit; 1819 2132 struct gl_texture_image *teximage; 1820 2133 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1821 2134 teximage = texUnit->CurrentD[3]->Image[level]; 1822 assert(teximage);2135 ASSERT(teximage); 1823 2136 if (teximage->Data) { 1824 2137 copy_tex_sub_image(ctx, teximage, width, height, 1825 2138 x, y, xoffset, yoffset, zoffset); 1826 1827 if (ctx->Driver.TexImage) { 1828 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_3D, 1829 texUnit->CurrentD[3],1830 level, teximage->IntFormat, teximage ); 1831 } 1832 }1833 }1834 }1835 2139 /* tell driver about the change */ 2140 /* XXX this is obsolete */ 2141 if (ctx->Driver.TexImage) { 2142 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_3D, 2143 texUnit->CurrentD[3], 2144 level, teximage->IntFormat, teximage ); 2145 } 2146 } 2147 } 2148 }
Note:
See TracChangeset
for help on using the changeset viewer.