2 * Glide64 - Glide video plugin for Nintendo 64 emulators.
3 * Copyright (c) 2002 Dave2001
4 * Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 /* Napalm extensions to GrTextureFormat_t */
32 #define GR_TEXFMT_ARGB_CMP_FXT1 0x11
33 #define GR_TEXFMT_ARGB_8888 0x12
34 #define GR_TEXFMT_YUYV_422 0x13
35 #define GR_TEXFMT_UYVY_422 0x14
36 #define GR_TEXFMT_AYUV_444 0x15
37 #define GR_TEXFMT_ARGB_CMP_DXT1 0x16
38 #define GR_TEXFMT_ARGB_CMP_DXT2 0x17
39 #define GR_TEXFMT_ARGB_CMP_DXT3 0x18
40 #define GR_TEXFMT_ARGB_CMP_DXT4 0x19
41 #define GR_TEXFMT_ARGB_CMP_DXT5 0x1A
42 #define GR_TEXTFMT_RGB_888 0xFF
44 int TMU_SIZE = 8*2048*2048;
45 static unsigned char* texture = NULL;
47 int packed_pixels_support = -1;
49 float largest_supported_anisotropy = 1.0f;
51 #ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
52 #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
55 int tex0_width, tex0_height, tex1_width, tex1_height;
58 static int min_filter0, mag_filter0, wrap_s0, wrap_t0;
59 static int min_filter1, mag_filter1, wrap_s1, wrap_t1;
61 unsigned char *filter(unsigned char *source, int width, int height, int *width2, int *height2);
63 typedef struct _texlist
66 struct _texlist *next;
70 static texlist *list = NULL;
73 extern PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT;
74 extern PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT;
75 extern PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB;
77 void remove_tex(unsigned int idmin, unsigned int idmax)
83 if (aux == NULL) return;
84 t = (unsigned int*)malloc(sz * sizeof(int));
85 while (aux && aux->id >= idmin && aux->id < idmax)
88 t = (unsigned int *) realloc(t, ++sz*sizeof(int));
95 while (aux != NULL && aux->next != NULL)
97 if (aux->next->id >= idmin && aux->next->id < idmax)
99 texlist *aux2 = aux->next->next;
101 t = (unsigned int *) realloc(t, ++sz*sizeof(int));
102 t[n++] = aux->next->id;
109 glDeleteTextures(n, t);
111 //printf("RMVTEX nbtex is now %d (%06x - %06x)\n", nbTex, idmin, idmax);
115 void add_tex(unsigned int id)
119 //printf("ADDTEX nbtex is now %d (%06x)\n", nbTex, id);
120 if (list == NULL || id < list->id)
123 list = (texlist*)malloc(sizeof(texlist));
128 while (aux->next != NULL && aux->next->id < id) aux = aux->next;
129 // ZIGGY added this test so that add_tex now accept re-adding an existing texture
130 if (aux->next != NULL && aux->next->id == id) return;
133 aux->next = (texlist*)malloc(sizeof(texlist));
135 aux->next->next = aux2;
140 tex0_width = tex0_height = tex1_width = tex1_height = 2;
141 // ZIGGY because remove_tex isn't called (Pj64 doesn't like it), it's better
142 // to leave these so that they'll be reused (otherwise we have a memory leak)
146 if (!texture) texture = (unsigned char*)malloc(2048*2048*4);
152 // ZIGGY for some reasons, Pj64 doesn't like remove_tex on exit
153 remove_tex(0x00000000, 0xFFFFFFFF);
155 if (texture != NULL) {
161 FX_ENTRY FxU32 FX_CALL
162 grTexMinAddress( GrChipID_t tmu )
164 LOG("grTexMinAddress(%d)\r\n", tmu);
171 FX_ENTRY FxU32 FX_CALL
172 grTexMaxAddress( GrChipID_t tmu )
174 LOG("grTexMaxAddress(%d)\r\n", tmu);
176 return TMU_SIZE*2 - 1;
178 return tmu*TMU_SIZE + TMU_SIZE - 1;
181 FX_ENTRY FxU32 FX_CALL
182 grTexTextureMemRequired( FxU32 evenOdd,
186 LOG("grTextureMemRequired(%d)\r\n", evenOdd);
187 if (info->largeLodLog2 != info->smallLodLog2) display_warning("grTexTextureMemRequired : loading more than one LOD");
189 if (info->aspectRatioLog2 < 0)
191 height = 1 << info->largeLodLog2;
192 width = height >> -info->aspectRatioLog2;
196 width = 1 << info->largeLodLog2;
197 height = width >> info->aspectRatioLog2;
202 case GR_TEXFMT_ALPHA_8:
203 case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii
204 case GR_TEXFMT_ALPHA_INTENSITY_44:
207 case GR_TEXFMT_ARGB_1555:
208 case GR_TEXFMT_ARGB_4444:
209 case GR_TEXFMT_ALPHA_INTENSITY_88:
210 case GR_TEXFMT_RGB_565:
211 return (width*height)<<1;
213 case GR_TEXFMT_ARGB_8888:
214 return (width*height)<<2;
216 case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii
217 return ((((width+0x3)&~0x3)*((height+0x3)&~0x3))>>1);
218 case GR_TEXFMT_ARGB_CMP_DXT3:
219 return ((width+0x3)&~0x3)*((height+0x3)&~0x3);
220 case GR_TEXFMT_ARGB_CMP_DXT5:
221 return ((width+0x3)&~0x3)*((height+0x3)&~0x3);
222 case GR_TEXFMT_ARGB_CMP_FXT1:
223 return ((((width+0x7)&~0x7)*((height+0x3)&~0x3))>>1);
225 display_warning("grTexTextureMemRequired : unknown texture format: %x", info->format);
230 FX_ENTRY FxU32 FX_CALL
231 grTexCalcMemRequired(
232 GrLOD_t lodmin, GrLOD_t lodmax,
233 GrAspectRatio_t aspect, GrTextureFormat_t fmt)
236 LOG("grTexCalcMemRequired(%d, %d, %d, %d)\r\n", lodmin, lodmax, aspect, fmt);
237 if (lodmax != lodmin) display_warning("grTexCalcMemRequired : loading more than one LOD");
241 height = 1 << lodmax;
242 width = height >> -aspect;
247 height = width >> aspect;
252 case GR_TEXFMT_ALPHA_8:
253 case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii
254 case GR_TEXFMT_ALPHA_INTENSITY_44:
257 case GR_TEXFMT_ARGB_1555:
258 case GR_TEXFMT_ARGB_4444:
259 case GR_TEXFMT_ALPHA_INTENSITY_88:
260 case GR_TEXFMT_RGB_565:
261 return (width*height)<<1;
263 case GR_TEXFMT_ARGB_8888:
264 return (width*height)<<2;
266 case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii
267 return ((((width+0x3)&~0x3)*((height+0x3)&~0x3))>>1);
268 case GR_TEXFMT_ARGB_CMP_DXT3:
269 return ((width+0x3)&~0x3)*((height+0x3)&~0x3);
270 case GR_TEXFMT_ARGB_CMP_DXT5:
271 return ((width+0x3)&~0x3)*((height+0x3)&~0x3);
272 case GR_TEXFMT_ARGB_CMP_FXT1:
273 return ((((width+0x7)&~0x7)*((height+0x3)&~0x3))>>1);
275 display_warning("grTexTextureMemRequired : unknown texture format: %x", fmt);
280 int grTexFormatSize(int fmt)
284 case GR_TEXFMT_ALPHA_8:
285 case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii
288 case GR_TEXFMT_ALPHA_INTENSITY_44:
291 case GR_TEXFMT_RGB_565:
294 case GR_TEXFMT_ARGB_1555:
297 case GR_TEXFMT_ALPHA_INTENSITY_88:
300 case GR_TEXFMT_ARGB_4444:
303 case GR_TEXFMT_ARGB_8888:
306 case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii
307 factor = 8; // HACKALERT: factor holds block bytes
309 case GR_TEXFMT_ARGB_CMP_DXT3: // FXT1,DXT1,5 support - H.Morii
310 factor = 16; // HACKALERT: factor holds block bytes
312 case GR_TEXFMT_ARGB_CMP_DXT5:
315 case GR_TEXFMT_ARGB_CMP_FXT1:
319 display_warning("grTexFormatSize : unknown texture format: %x", fmt);
324 int grTexFormat2GLPackedFmt(int fmt, int * gltexfmt, int * glpixfmt, int * glpackfmt)
328 *glpackfmt = GL_UNSIGNED_BYTE;
333 case GR_TEXFMT_ALPHA_8:
335 *gltexfmt = GL_INTENSITY8;
336 *glpixfmt = GL_LUMINANCE;
337 *glpackfmt = GL_UNSIGNED_BYTE;
339 case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii
341 *gltexfmt = GL_LUMINANCE8;
342 *glpixfmt = GL_LUMINANCE;
343 *glpackfmt = GL_UNSIGNED_BYTE;
345 case GR_TEXFMT_ALPHA_INTENSITY_44:
347 case GR_TEXFMT_RGB_565:
351 *glpackfmt = GL_UNSIGNED_SHORT_5_6_5;
353 case GR_TEXFMT_ARGB_1555:
354 if (ati_sucks > 0) return -1; // ATI sucks as usual (fixes slowdown on ATI)
356 *gltexfmt = GL_RGB5_A1;
358 *glpackfmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
360 case GR_TEXFMT_ALPHA_INTENSITY_88:
362 *gltexfmt = GL_LUMINANCE8_ALPHA8;
363 *glpixfmt = GL_LUMINANCE_ALPHA;
364 *glpackfmt = GL_UNSIGNED_BYTE;
366 case GR_TEXFMT_ARGB_4444:
368 *gltexfmt = GL_RGBA4;
370 *glpackfmt = GL_UNSIGNED_SHORT_4_4_4_4_REV;
372 case GR_TEXFMT_ARGB_8888:
374 *gltexfmt = GL_RGBA8;
376 *glpackfmt = GL_UNSIGNED_INT_8_8_8_8_REV;
378 case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii
379 // HACKALERT: 3Dfx Glide uses GR_TEXFMT_ARGB_CMP_DXT1 for both opaque DXT1 and DXT1 with 1bit alpha.
380 // GlideHQ compiled with GLIDE64_DXTN option enabled, uses opaqe DXT1 only.
381 factor = 8; // HACKALERT: factor holds block bytes
382 *gltexfmt = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; // these variables aren't used
383 *glpixfmt = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
384 *glpackfmt = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
386 case GR_TEXFMT_ARGB_CMP_DXT3:
388 *gltexfmt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
389 *glpixfmt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
390 *glpackfmt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
392 case GR_TEXFMT_ARGB_CMP_DXT5:
394 *gltexfmt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
395 *glpixfmt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
396 *glpackfmt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
398 case GR_TEXFMT_ARGB_CMP_FXT1:
400 *gltexfmt = GL_COMPRESSED_RGBA_FXT1_3DFX;
401 *glpixfmt = GL_COMPRESSED_RGBA_FXT1_3DFX;
402 *glpackfmt = GL_COMPRESSED_RGBA_FXT1_3DFX; // XXX: what should we do about GL_COMPRESSED_RGB_FXT1_3DFX?
405 display_warning("grTexFormat2GLPackedFmt : unknown texture format: %x", fmt);
411 FX_ENTRY void FX_CALL
412 grTexDownloadMipMap( GrChipID_t tmu,
417 int width, height, i, j;
420 int gltexfmt, glpixfmt, glpackfmt;
421 LOG("grTexDownloadMipMap(%d,%d,%d)\r\n", tmu, startAddress, evenOdd);
422 if (info->largeLodLog2 != info->smallLodLog2) display_warning("grTexDownloadMipMap : loading more than one LOD");
424 if (info->aspectRatioLog2 < 0)
426 height = 1 << info->largeLodLog2;
427 width = height >> -info->aspectRatioLog2;
431 width = 1 << info->largeLodLog2;
432 height = width >> info->aspectRatioLog2;
435 if (!packed_pixels_support)
438 factor = grTexFormat2GLPackedFmt(info->format, &gltexfmt, &glpixfmt, &glpackfmt);
439 //printf("grTexDownloadMipmap, id=%x, size=%ix%i, format=%x\n", startAddress+1, width, height, info->format);
443 glpackfmt = GL_UNSIGNED_BYTE;
445 // VP fixed the texture conversions to be more accurate, also swapped
446 // the for i/j loops so that is is less likely to break the memory cache
447 register int n = 0, m = 0;
450 case GR_TEXFMT_ALPHA_8:
451 /* for (i=0; i<height; i++)
453 for (j=0; j<width; j++)
455 unsigned int texel = (unsigned int)((unsigned char*)info->data)[m];
456 texel |= (texel << 8);
457 texel |= (texel << 16);
458 ((unsigned int*)texture)[n] = texel;
464 glformat = GL_RGBA;*/
466 for (i=0; i<height; i++)
468 for (j=0; j<width; j++)
470 unsigned short texel = (unsigned short)((unsigned char*)info->data)[m];
471 ((unsigned short*)texture)[n] = texel|(texel<<8);
477 glformat = gltexfmt = glpixfmt = GL_LUMINANCE_ALPHA;
478 glpackfmt = GL_UNSIGNED_BYTE;
481 case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii
482 /* for (i=0; i<height; i++)
484 for (j=0; j<width; j++)
486 unsigned int texel = (unsigned int)((unsigned char*)info->data)[m];
487 texel |= (0xFF000000 | (texel << 16) | (texel << 8));
488 ((unsigned int*)texture)[n] = texel;
494 // glformat = GL_ALPHA;
495 memcpy(texture, info->data, width*height);
496 glformat = gltexfmt = glpixfmt = GL_LUMINANCE;
497 glpackfmt = GL_UNSIGNED_BYTE;
500 case GR_TEXFMT_ALPHA_INTENSITY_44:
502 for (i=0; i<height; i++)
504 for (j=0; j<width; j++)
506 /* unsigned int texel = (unsigned int)((unsigned char*)info->data)[m];
508 // accurate conversion
509 unsigned int texel_hi = (texel & 0x000000F0) << 20;
510 unsigned int texel_low = texel & 0x0000000F;
511 texel_low |= (texel_low << 4);
512 texel_hi |= ((texel_hi << 4) | (texel_low << 16) | (texel_low << 8) | texel_low);
514 unsigned int texel_hi = (texel & 0x000000F0) << 24;
515 unsigned int texel_low = (texel & 0x0000000F) << 4;
516 texel_hi |= ((texel_low << 16) | (texel_low << 8) | texel_low);
518 ((unsigned int*)texture)[n] = texel_hi;
520 unsigned char texel = ((unsigned char*)info->data)[m];
521 unsigned short texel_hi = (texel & 0x000000F0) << 4;
522 unsigned short texel_low = texel & 0x0000000F;
523 texel_low |= (texel_low << 4);
524 texel_hi |= ((texel_hi << 4) | (texel_low));
525 ((unsigned short*)texture)[n] = texel_hi;
531 glformat = gltexfmt = glpixfmt = GL_LUMINANCE_ALPHA;
532 glpackfmt = GL_UNSIGNED_BYTE;
533 // glformat = GL_LUMINANCE_ALPHA;
536 case GR_TEXFMT_RGB_565:
537 /* for (i=0; i<height; i++)
539 for (j=0; j<width; j++)
541 /* unsigned int texel = (unsigned int)((unsigned short*)info->data)[m];
542 unsigned int B = texel & 0x0000F800;
543 unsigned int G = texel & 0x000007E0;
544 unsigned int R = texel & 0x0000001F;
546 // accurate conversion
547 ((unsigned int*)texture)[n] = 0xFF000000 | (R << 19) | ((R >> 2) << 16) | (G << 5) | ((G >> 9) << 8) | (B >> 8) | (B >> 13);
549 ((unsigned int*)texture)[n] = 0xFF000000 | (R << 19) | (G << 5) | (B >> 8);
552 /* const unsigned short texel = ((unsigned short*)info->data)[m];
553 const unsigned short B = (texel & 0xF800)>>11;
554 const unsigned short G = texel & 0x07E0;
555 const unsigned short R = (texel & 0x001F)<<11;
556 ((unsigned short*)texture)[n] = R|G|B;
561 memcpy(texture, info->data, width*height*2);
563 // glformat = GL_RGB;
564 glformat = gltexfmt = glpixfmt = GL_RGB;
565 glpackfmt = GL_UNSIGNED_SHORT_5_6_5;
567 case GR_TEXFMT_ARGB_1555:
568 for (i=0; i<height; i++)
570 for (j=0; j<width; j++)
572 /* unsigned int texel = (unsigned int)((unsigned short*)info->data)[m];
573 unsigned int A = texel & 0x00008000 ? 0xFF000000 : 0;
574 unsigned int B = texel & 0x00007C00;
575 unsigned int G = texel & 0x000003E0;
576 unsigned int R = texel & 0x0000001F;
578 // accurate conversion
579 ((unsigned int*)texture)[n] = A | (R << 19) | ((R >> 2) << 16) | (G << 6) | ((G >> 8) << 8) | (B >> 7) | (B >> 12);
581 ((unsigned int*)texture)[n] = A | (R << 19) | (G << 6) | (B >> 7);
584 unsigned short texel = ((unsigned short*)info->data)[m];
585 unsigned short A = (texel & 0x8000)>>15;
586 ((unsigned short*)texture)[n] = A|(texel&0x7fff)<<1;
588 unsigned short B = (texel & 0x7C00)>>9;
589 unsigned short G = texel & 0x03E0<<1;
590 unsigned short R = (texel & 0x001F)<<11;
591 ((unsigned short*)texture)[n] = A|R|G|B;*/
597 // glformat = GL_RGBA;
598 glformat = gltexfmt = glpixfmt = GL_RGBA;
599 glpackfmt = GL_UNSIGNED_SHORT_5_5_5_1;
601 case GR_TEXFMT_ALPHA_INTENSITY_88:
602 /* for (i=0; i<height; i++)
604 for (j=0; j<width; j++)
606 unsigned int AI = (unsigned int)((unsigned short*)info->data)[m];
607 unsigned int I = (unsigned int)(AI & 0x000000FF);
608 ((unsigned int*)texture)[n] = (AI << 16) | (I << 8) | I;
613 memcpy(texture, info->data, width*height*2);
615 glformat = GL_LUMINANCE_ALPHA;
616 glformat = gltexfmt = glpixfmt = GL_LUMINANCE_ALPHA;
617 glpackfmt = GL_UNSIGNED_BYTE;
619 case GR_TEXFMT_ARGB_4444:
621 for (i=0; i<height; i++)
623 for (j=0; j<width; j++)
625 /* unsigned int texel = (unsigned int)((unsigned short*)info->data)[m];
626 unsigned int A = texel & 0x0000F000;
627 unsigned int B = texel & 0x00000F00;
628 unsigned int G = texel & 0x000000F0;
629 unsigned int R = texel & 0x0000000F;
631 // accurate conversion
632 ((unsigned int*)texture)[n] = (A << 16) | (A << 12) | (R << 20) | (R << 16) | (G << 8) | (G << 4) | (B >> 4) | (B >> 8);
634 ((unsigned int*)texture)[n] = (A << 16) | (R << 20) | (G << 8) | (B >> 4);
637 unsigned short texel = ((unsigned short*)info->data)[m];
638 unsigned int A = (texel & 0xF000)>>12;
639 ((unsigned short*)texture)[n] = A|(texel&0x0fff)<<4;
646 glformat = gltexfmt = glpixfmt = GL_RGBA;
647 glpackfmt = GL_UNSIGNED_SHORT_4_4_4_4;
649 case GR_TEXFMT_ARGB_8888:
650 for (i=0; i<height; i++)
652 for (j=0; j<width; j++)
654 unsigned int texel = ((unsigned int*)info->data)[m];
655 unsigned int A = texel & 0xFF000000;
656 unsigned int B = texel & 0x00FF0000;
657 unsigned int G = texel & 0x0000FF00;
658 unsigned int R = texel & 0x000000FF;
659 ((unsigned int*)texture)[n] = A | (R << 16) | G | (B >> 16);
668 case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii
669 factor = 8; // HACKALERT: factor holds block bytes
670 glformat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
672 case GR_TEXFMT_ARGB_CMP_DXT3: // FXT1,DXT1,5 support - H.Morii
673 factor = 16; // HACKALERT: factor holds block bytes
674 glformat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
676 case GR_TEXFMT_ARGB_CMP_DXT5:
678 glformat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
680 case GR_TEXFMT_ARGB_CMP_FXT1:
682 glformat = GL_COMPRESSED_RGBA_FXT1_3DFX;
686 display_warning("grTexDownloadMipMap : unknown texture format: %x", info->format);
691 if (nbTextureUnits <= 2)
692 glActiveTexture(GL_TEXTURE1);
694 glActiveTexture(GL_TEXTURE2);
698 case GR_TEXFMT_ARGB_CMP_DXT1:
699 case GR_TEXFMT_ARGB_CMP_DXT3:
700 case GR_TEXFMT_ARGB_CMP_DXT5:
701 case GR_TEXFMT_ARGB_CMP_FXT1:
702 remove_tex(startAddress+1, startAddress+1+((width*height*factor)>>4));
705 remove_tex(startAddress+1, startAddress+1+(width*height*factor));
708 add_tex(startAddress+1);
709 glBindTexture(GL_TEXTURE_2D, startAddress+1);
711 if (largest_supported_anisotropy > 1.0f)
712 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, largest_supported_anisotropy);
714 //*SEB* glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
715 //printf("new texture, id=%x, size=%ix%i, fmt=%x/%x\n", startAddress+1, width, height, gltexfmt, glpackfmt);
716 glTexImage2D(GL_TEXTURE_2D, 0, gltexfmt, width, height, 0, glpixfmt, glpackfmt, texture);
720 case GR_TEXFMT_ARGB_CMP_DXT1:
721 case GR_TEXFMT_ARGB_CMP_DXT3:
722 case GR_TEXFMT_ARGB_CMP_DXT5:
723 case GR_TEXFMT_ARGB_CMP_FXT1:
724 glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, (glformat ? glformat : gltexfmt), width, height, 0, (width*height*factor)>>4, info->data);
728 glTexImage2D(GL_TEXTURE_2D, 0, glformat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
730 glTexImage2D(GL_TEXTURE_2D, 0, gltexfmt, width, height, 0, glpixfmt, glpackfmt, info->data);
734 glBindTexture(GL_TEXTURE_2D, default_texture);
737 int CheckTextureBufferFormat(GrChipID_t tmu, FxU32 startAddress, GrTexInfo *info );
739 FX_ENTRY void FX_CALL
740 grTexSource( GrChipID_t tmu,
745 LOG("grTexSource(%d,%d,%d)\r\n", tmu, startAddress, evenOdd);
747 if (tmu == GR_TMU1 || nbTextureUnits <= 2)
749 if (tmu == GR_TMU1 && nbTextureUnits <= 2) return;
750 glActiveTexture(GL_TEXTURE0);
752 if (info->aspectRatioLog2 < 0)
755 tex0_width = tex0_height >> -info->aspectRatioLog2;
760 tex0_height = tex0_width >> info->aspectRatioLog2;
763 glBindTexture(GL_TEXTURE_2D, startAddress+1);
765 dump_tex(startAddress+1);
767 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter0);
768 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter0);
769 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s0);
770 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t0);
774 glActiveTexture(GL_TEXTURE1);
776 if (info->aspectRatioLog2 < 0)
779 tex1_width = tex1_height >> -info->aspectRatioLog2;
784 tex1_height = tex1_width >> info->aspectRatioLog2;
787 glBindTexture(GL_TEXTURE_2D, startAddress+1);
789 dump_tex(startAddress+1);
791 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter1);
792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter1);
793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s1);
794 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t1);
796 if(!CheckTextureBufferFormat(tmu, startAddress+1, info))
798 if(tmu == 0 && blackandwhite1 != 0)
803 if(tmu == 1 && blackandwhite0 != 0)
811 extern int auxbuffer;
812 static int oldbuffer;
813 FX_ENTRY void FX_CALL grAuxBufferExt( GrBuffer_t buffer );
814 if (auxbuffer == GR_BUFFER_AUXBUFFER && auxbuffer != oldbuffer)
815 grAuxBufferExt(auxbuffer);
816 oldbuffer = auxbuffer;
820 FX_ENTRY void FX_CALL
828 LOG("grTexDetailControl(%d,%d,%d,%d)\r\n", tmu, lod_bias, detail_scale, detail_max);
829 if (lod_bias != 31 && detail_scale != 7)
831 if (!lod_bias && !detail_scale && !detail_max) return;
833 display_warning("grTexDetailControl : %d, %d, %f", lod_bias, detail_scale, detail_max);
838 lambda = 1.0f - (255.0f - lambda);
840 if(lambda > 1.0f) display_warning("lambda:%f", lambda);
845 FX_ENTRY void FX_CALL
846 grTexLodBiasValue(GrChipID_t tmu, float bias )
848 LOG("grTexLodBiasValue(%d,%f)\r\n", tmu, bias);
851 FX_ENTRY void FX_CALL
854 GrTextureFilterMode_t minfilter_mode,
855 GrTextureFilterMode_t magfilter_mode
858 LOG("grTexFilterMode(%d,%d,%d)\r\n", tmu, minfilter_mode, magfilter_mode);
859 if (tmu == GR_TMU1 || nbTextureUnits <= 2)
861 if (tmu == GR_TMU1 && nbTextureUnits <= 2) return;
862 if (minfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) min_filter0 = GL_NEAREST;
863 else min_filter0 = GL_LINEAR;
865 if (magfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) mag_filter0 = GL_NEAREST;
866 else mag_filter0 = GL_LINEAR;
868 glActiveTexture(GL_TEXTURE0);
869 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter0);
870 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter0);
874 if (minfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) min_filter1 = GL_NEAREST;
875 else min_filter1 = GL_LINEAR;
877 if (magfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) mag_filter1 = GL_NEAREST;
878 else mag_filter1 = GL_LINEAR;
880 glActiveTexture(GL_TEXTURE1);
881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter1);
882 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter1);
886 FX_ENTRY void FX_CALL
889 GrTextureClampMode_t s_clampmode,
890 GrTextureClampMode_t t_clampmode
893 LOG("grTexClampMode(%d, %d, %d)\r\n", tmu, s_clampmode, t_clampmode);
894 if (tmu == GR_TMU1 || nbTextureUnits <= 2)
896 if (tmu == GR_TMU1 && nbTextureUnits <= 2) return;
899 case GR_TEXTURECLAMP_WRAP:
902 case GR_TEXTURECLAMP_CLAMP:
903 wrap_s0 = GL_CLAMP_TO_EDGE;
905 case GR_TEXTURECLAMP_MIRROR_EXT:
906 wrap_s0 = GL_MIRRORED_REPEAT;
909 display_warning("grTexClampMode : unknown s_clampmode : %x", s_clampmode);
913 case GR_TEXTURECLAMP_WRAP:
916 case GR_TEXTURECLAMP_CLAMP:
917 wrap_t0 = GL_CLAMP_TO_EDGE;
919 case GR_TEXTURECLAMP_MIRROR_EXT:
920 wrap_t0 = GL_MIRRORED_REPEAT;
923 display_warning("grTexClampMode : unknown t_clampmode : %x", t_clampmode);
925 glActiveTexture(GL_TEXTURE0);
926 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s0);
927 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t0);
933 case GR_TEXTURECLAMP_WRAP:
936 case GR_TEXTURECLAMP_CLAMP:
937 wrap_s1 = GL_CLAMP_TO_EDGE;
939 case GR_TEXTURECLAMP_MIRROR_EXT:
940 wrap_s1 = GL_MIRRORED_REPEAT;
943 display_warning("grTexClampMode : unknown s_clampmode : %x", s_clampmode);
947 case GR_TEXTURECLAMP_WRAP:
950 case GR_TEXTURECLAMP_CLAMP:
951 wrap_t1 = GL_CLAMP_TO_EDGE;
953 case GR_TEXTURECLAMP_MIRROR_EXT:
954 wrap_t1 = GL_MIRRORED_REPEAT;
957 display_warning("grTexClampMode : unknown t_clampmode : %x", t_clampmode);
959 glActiveTexture(GL_TEXTURE1);
960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s1);
961 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t1);