Changeset 25154 in vbox
- Timestamp:
- Dec 2, 2009 9:21:15 PM (15 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/OpenGL/include/state/cr_texture.h
r16969 r25154 22 22 */ 23 23 #define CR_STATE_NO_TEXTURE_IMAGE_STORE 24 25 #define CR_MAX_MIPMAP_LEVELS 20 24 26 25 27 typedef struct { -
trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c
r24891 r25154 54 54 */ 55 55 56 /*@todo move with the one from state_texture.c to some header*/57 #define MAX_MIPMAP_LEVELS 2058 59 56 static int32_t crStateAllocAndSSMR3GetMem(PSSMHANDLE pSSM, void **pBuffer, size_t cbBuffer) 60 57 { … … 71 68 { 72 69 int32_t rc, face, i; 70 GLboolean bound = GL_FALSE; 73 71 74 72 CRASSERT(pTexture && pSSM); 75 73 74 crDebug("crStateSaveTextureObjData %u. START", pTexture->name); 75 76 76 for (face = 0; face < 6; face++) { 77 77 CRASSERT(pTexture->level[face]); 78 78 79 /*@todo, check if safe to go till MAX_MIPMAP_LEVELS intead of TextureState->maxLevel*/ 80 for (i = 0; i < MAX_MIPMAP_LEVELS; i++) { 79 for (i = 0; i < CR_MAX_MIPMAP_LEVELS; i++) { 81 80 CRTextureLevel *ptl = &(pTexture->level[face][i]); 82 81 rc = SSMR3PutMem(pSSM, ptl, sizeof(*ptl)); … … 98 97 { 99 98 char *pImg; 100 99 GLenum target; 100 101 if (!bound) 102 { 103 diff_api.BindTexture(pTexture->target, pTexture->name); 104 bound = GL_TRUE; 105 } 106 107 if (pTexture->target!=GL_TEXTURE_CUBE_MAP_ARB) 108 { 109 target = pTexture->target; 110 } 111 else 112 { 113 target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face; 114 } 115 116 #ifdef DEBUG 117 pImg = crAlloc(ptl->bytes+4); 118 #else 101 119 pImg = crAlloc(ptl->bytes); 120 #endif 102 121 if (!pImg) return VERR_NO_MEMORY; 103 122 104 diff_api.BindTexture(pTexture->target, pTexture->name); 105 diff_api.GetTexImage(pTexture->target, i, ptl->format, ptl->type, pImg); 123 #ifdef DEBUG 124 { 125 GLint w,h=0; 126 *(int*)((char*)pImg+ptl->bytes) = 0xDEADDEAD; 127 crDebug("get image: compressed %i, face %i, level %i, width %i, height %i, bytes %i", 128 ptl->compressed, face, i, ptl->width, ptl->height, ptl->bytes); 129 diff_api.GetTexLevelParameteriv(target, i, GL_TEXTURE_WIDTH, &w); 130 diff_api.GetTexLevelParameteriv(target, i, GL_TEXTURE_HEIGHT, &h); 131 if (w!=ptl->width || h!=ptl->height) 132 { 133 crWarning("!!!tex size mismatch %i, %i!!!", w, h); 134 } 135 } 136 #endif 137 138 /*@todo: ugly workaround for crashes inside ati driver, 139 * they overwrite their own allocated memory in cases where texlevel >=4 140 and width or height <=2. 141 */ 142 if (i<4 || (ptl->width>2 && ptl->height>2)) 143 if (!ptl->compressed) 144 { 145 diff_api.GetTexImage(target, i, ptl->format, ptl->type, pImg); 146 } 147 else 148 { 149 diff_api.GetCompressedTexImageARB(target, i, pImg); 150 } 151 152 #ifdef DEBUG 153 if (*(int*)((char*)pImg+ptl->bytes) != 0xDEADDEAD) 154 { 155 crWarning("Texture is bigger than expected!!!"); 156 } 157 #endif 106 158 107 159 rc = SSMR3PutMem(pSSM, pImg, ptl->bytes); … … 113 165 } 114 166 167 crDebug("crStateSaveTextureObjData %u. END", pTexture->name); 168 115 169 return VINF_SUCCESS; 116 170 } … … 125 179 CRASSERT(pTexture->level[face]); 126 180 127 for (i = 0; i < MAX_MIPMAP_LEVELS; i++) {181 for (i = 0; i < CR_MAX_MIPMAP_LEVELS; i++) { 128 182 CRTextureLevel *ptl = &(pTexture->level[face][i]); 129 183 CRASSERT(!ptl->img); … … 1330 1384 /*allocate actual memory*/ 1331 1385 for (i=0; i<6; ++i) { 1332 pTexture->level[i] = (CRTextureLevel *) crCalloc(sizeof(CRTextureLevel) * MAX_MIPMAP_LEVELS);1386 pTexture->level[i] = (CRTextureLevel *) crCalloc(sizeof(CRTextureLevel) * CR_MAX_MIPMAP_LEVELS); 1333 1387 if (!pTexture->level[i]) return VERR_NO_MEMORY; 1334 1388 } -
trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_special
r23399 r25154 375 375 BindAttribLocation 376 376 GetUniformLocation 377 CopyTexImage2D -
trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_teximage.c
r16969 r25154 15 15 #include "state_internals.h" 16 16 17 #ifndef IN_GUEST 18 /*# define CR_DUMP_TEXTURES_2D*/ 19 #endif 20 21 #ifdef CR_DUMP_TEXTURES_2D 22 static int _tnum = 0; 23 24 #pragma pack(1) 25 typedef struct tgaheader_tag 26 { 27 char idlen; 28 29 char colormap; 30 31 char imagetype; 32 33 short cm_index; 34 short cm_len; 35 char cm_entrysize; 36 37 short x, y, w, h; 38 char depth; 39 char imagedesc; 40 41 } tgaheader_t; 42 #pragma pack() 43 44 static crDumpTGA(short w, short h, char* data) 45 { 46 char fname[200]; 47 tgaheader_t header; 48 FILE *out; 49 50 if (!w || !h) return; 51 52 sprintf(fname, "tex%i.tga", _tnum++); 53 out = fopen(fname, "w"); 54 if (!out) crError("can't create %s!", fname); 55 56 header.idlen = 0; 57 header.colormap = 0; 58 header.imagetype = 2; 59 header.cm_index = 0; 60 header.cm_len = 0; 61 header.cm_entrysize = 0; 62 header.x = 0; 63 header.y = 0; 64 header.w = w; 65 header.h = h; 66 header.depth = 32; 67 header.imagedesc = 0x08; 68 fwrite(&header, sizeof(header), 1, out); 69 70 fwrite(data, w*h*4, 1, out); 71 72 fclose(out); 73 } 74 #endif 17 75 18 76 … … 593 651 } 594 652 653 static void crStateNukeMipmaps(CRTextureObj *tobj) 654 { 655 int i, face; 656 657 for (face = 0; face < 6; face++) 658 { 659 CRTextureLevel *levels = tobj->level[face]; 660 661 if (levels) 662 { 663 for (i = 0; i < CR_MAX_MIPMAP_LEVELS; i++) 664 { 665 if (levels[i].img) 666 { 667 crFree(levels[i].img); 668 } 669 levels[i].img = NULL; 670 levels[i].bytes = 0; 671 levels[i].internalFormat = GL_ONE; 672 levels[i].format = GL_RGBA; 673 levels[i].type = GL_UNSIGNED_BYTE; 674 675 } 676 } 677 } 678 } 679 680 void STATE_APIENTRY 681 crStateCopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) 682 { 683 CRContext *g = GetCurrentContext(); 684 CRTextureObj *tobj = NULL; 685 CRTextureLevel *tl = NULL; 686 687 crStateGetTextureObjectAndImage(g, target, level, &tobj, &tl); 688 CRASSERT(tobj); 689 CRASSERT(tl); 690 691 crStateNukeMipmaps(tobj); 692 693 tl->bytes = crImageSize(GL_RGBA, GL_UNSIGNED_BYTE, width, height); 694 695 tl->width = width; 696 tl->height = height; 697 tl->depth = 1; 698 tl->format = GL_RGBA; 699 tl->internalFormat = internalFormat; 700 crStateTextureInitTextureFormat(tl, internalFormat); 701 tl->border = border; 702 tl->type = GL_UNSIGNED_BYTE; 703 tl->compressed = GL_FALSE; 704 if (width && height) 705 { 706 tl->bytesPerPixel = tl->bytes / (width * height); 707 } 708 else 709 tl->bytesPerPixel = 0; 710 711 #ifdef CR_SGIS_generate_mipmap 712 if (level == tobj->baseLevel && tobj->generateMipmap) { 713 generate_mipmap(tobj, target); 714 } 715 else { 716 tl->generateMipmap = GL_FALSE; 717 } 718 #endif 719 } 595 720 596 721 void STATE_APIENTRY … … 628 753 CRASSERT(tobj); 629 754 CRASSERT(tl); 755 756 if (level==tobj->baseLevel && (tl->width!=width || tl->height!=height)) 757 { 758 crStateNukeMipmaps(tobj); 759 } 630 760 631 761 /* compute size of image buffer */ … … 704 834 DIRTY(tl->dirty, g->neg_bitid); 705 835 DIRTY(tb->dirty, g->neg_bitid); 706 } 707 836 837 #ifdef CR_DUMP_TEXTURES_2D 838 if (pixels) 839 { 840 GLint w,h; 841 char *data; 842 843 diff_api.GetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &w); 844 diff_api.GetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &h); 845 846 data = crAlloc(w*h*4); 847 if (!data) crError("no memory!"); 848 diff_api.GetTexImage(target, level, GL_RGBA, GL_UNSIGNED_BYTE, data); 849 crDumpTGA(w, h, data); 850 crFree(data); 851 } 852 #endif 853 } 708 854 709 855 #if defined( CR_OPENGL_VERSION_1_2 ) || defined( GL_EXT_texture3D ) … … 917 1063 DIRTY(tl->dirty, g->neg_bitid); 918 1064 DIRTY(tb->dirty, g->neg_bitid); 1065 1066 #ifdef CR_DUMP_TEXTURES_2D 1067 { 1068 GLint w,h; 1069 char *data; 1070 1071 diff_api.GetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &w); 1072 diff_api.GetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &h); 1073 1074 data = crAlloc(w*h*4); 1075 if (!data) crError("no memory!"); 1076 diff_api.GetTexImage(target, level, GL_RGBA, GL_UNSIGNED_BYTE, data); 1077 crDumpTGA(w, h, data); 1078 crFree(data); 1079 } 1080 #endif 919 1081 } 920 1082 -
trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texture.c
r23694 r25154 13 13 #include "cr_version.h" 14 14 #include "state_internals.h" 15 16 17 #define MAX_MIPMAP_LEVELS 2018 19 15 20 16 #define UNUSED(x) ((void) (x)) … … 205 201 for (face = 0; face < 6; face++) { 206 202 /* allocate array of mipmap levels */ 207 CRASSERT(t->maxLevel < MAX_MIPMAP_LEVELS);203 CRASSERT(t->maxLevel < CR_MAX_MIPMAP_LEVELS); 208 204 tobj->level[face] = (CRTextureLevel *) 209 crCalloc(sizeof(CRTextureLevel) * MAX_MIPMAP_LEVELS);205 crCalloc(sizeof(CRTextureLevel) * CR_MAX_MIPMAP_LEVELS); 210 206 211 207 if (!tobj->level[face]) … … 569 565 if (levels) { 570 566 /* free all mipmap levels for this face */ 571 for (k = 0; k < MAX_MIPMAP_LEVELS; k++) {567 for (k = 0; k < CR_MAX_MIPMAP_LEVELS; k++) { 572 568 CRTextureLevel *tl = levels + k; 573 569 if (tl->img) { -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_gentextures.c
r22538 r25154 101 101 } 102 102 103 crStateCopyTexImage2D(target, level, internalFormat, x, y, width, height, border); 103 104 cr_server.head_spu->dispatch_table.CopyTexImage2D(target, level, internalFormat, x, y, width, height, border); 104 105 }
Note:
See TracChangeset
for help on using the changeset viewer.