diff --git a/Source/Project64-video/Combine.cpp b/Source/Project64-video/Combine.cpp index fb640fe5a..6537a018e 100644 --- a/Source/Project64-video/Combine.cpp +++ b/Source/Project64-video/Combine.cpp @@ -11,6 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ +#include #include #include "Gfx_1.3.h" #include "Util.h" @@ -122,7 +123,7 @@ COMBINE cmb; cmb.tex |= 1, \ cmb.tmu0_func = GR_COMBINE_FUNCTION_LOCAL #define USE_T1() \ - if (voodoo.num_tmu > 1) { \ + if ((nbTextureUnits > 2 ? 2 : 1) > 1) { \ rdp.best_tex = 1; \ cmb.tex |= 2, \ cmb.tmu1_func = GR_COMBINE_FUNCTION_LOCAL, \ @@ -467,7 +468,7 @@ COMBINE cmb; cmb.tex |= 1, \ cmb.tmu0_a_func = GR_COMBINE_FUNCTION_LOCAL #define A_USE_T1() \ - if (voodoo.num_tmu > 1) { \ + if ((nbTextureUnits > 2 ? 2 : 1) > 1) { \ cmb.tex |= 2, \ cmb.tmu1_a_func = GR_COMBINE_FUNCTION_LOCAL, \ cmb.tmu0_a_func = GR_COMBINE_FUNCTION_SCALE_OTHER, \ diff --git a/Source/Project64-video/Main.cpp b/Source/Project64-video/Main.cpp index 06e14bad7..5458efd67 100644 --- a/Source/Project64-video/Main.cpp +++ b/Source/Project64-video/Main.cpp @@ -11,6 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ +#include #include #include #include "Gfx_1.3.h" @@ -268,7 +269,7 @@ void guLoadTextures() rdp.texbufs[0].count = 0; rdp.texbufs[0].clear_allowed = TRUE; offset_font = tbuf_size; - if (voodoo.num_tmu > 1) + if ((nbTextureUnits > 2 ? 2 : 1) > 1) { rdp.texbufs[1].tmu = GR_TMU1; rdp.texbufs[1].begin = voodoo.tex_UMA ? rdp.texbufs[0].end : voodoo.tex_min_addr[GR_TMU1]; @@ -534,13 +535,10 @@ int InitGfx() GfxInitDone = TRUE; to_fullscreen = FALSE; - // get the # of TMUs available - grGet(GR_NUM_TMU, 4, (FxI32*)&voodoo.num_tmu); // get maximal texture size grGet(GR_MAX_TEXTURE_SIZE, 4, (FxI32*)&voodoo.max_tex_size); voodoo.sup_large_tex = (voodoo.max_tex_size > 256 && !g_settings->hacks(CSettings::hack_PPL)); - //num_tmu = 1; if (voodoo.tex_UMA) { GetTexAddr = GetTexAddrUMA; @@ -576,12 +574,10 @@ int InitGfx() InitCombine(); #ifdef SIMULATE_VOODOO1 - voodoo.num_tmu = 1; voodoo.sup_mirroring = 0; #endif #ifdef SIMULATE_BANSHEE - voodoo.num_tmu = 1; voodoo.sup_mirroring = 1; #endif @@ -986,7 +982,6 @@ that there is a waiting interrupt. int CALL InitiateGFX(GFX_INFO Gfx_Info) { WriteTrace(TraceInterface, TraceDebug, "Start"); - voodoo.num_tmu = 2; // Assume scale of 1 for debug purposes rdp.scale_x = 1.0f; diff --git a/Source/Project64-video/Project64-video.vcxproj b/Source/Project64-video/Project64-video.vcxproj index b07da702a..af6cfa89b 100644 --- a/Source/Project64-video/Project64-video.vcxproj +++ b/Source/Project64-video/Project64-video.vcxproj @@ -48,6 +48,8 @@ + + @@ -137,6 +139,7 @@ + diff --git a/Source/Project64-video/Project64-video.vcxproj.filters b/Source/Project64-video/Project64-video.vcxproj.filters index 216cb2112..02c06f4b9 100644 --- a/Source/Project64-video/Project64-video.vcxproj.filters +++ b/Source/Project64-video/Project64-video.vcxproj.filters @@ -154,6 +154,12 @@ + + Renderer + + + Renderer + @@ -266,6 +272,9 @@ ucode + + Renderer + diff --git a/Source/Project64-video/Renderer/OGLEScombiner.cpp b/Source/Project64-video/Renderer/OGLEScombiner.cpp index db01dac84..67d1c36d5 100644 --- a/Source/Project64-video/Renderer/OGLEScombiner.cpp +++ b/Source/Project64-video/Renderer/OGLEScombiner.cpp @@ -11,7 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ -#include +#include #ifdef _WIN32 #include diff --git a/Source/Project64-video/Renderer/OGLESgeometry.cpp b/Source/Project64-video/Renderer/OGLESgeometry.cpp index 079c4a311..3c3c9db76 100644 --- a/Source/Project64-video/Renderer/OGLESgeometry.cpp +++ b/Source/Project64-video/Renderer/OGLESgeometry.cpp @@ -368,154 +368,11 @@ grDrawTriangle(const void *a, const void *b, const void *c) FX_ENTRY void FX_CALL grDrawPoint(const void *pt) { - /* - float *x = (float*)pt + xy_off/sizeof(float); - float *y = (float*)pt + xy_off/sizeof(float) + 1; - float *z = (float*)pt + z_off/sizeof(float); - float *q = (float*)pt + q_off/sizeof(float); - unsigned char *pargb = (unsigned char*)pt + pargb_off; - float *s0 = (float*)pt + st0_off/sizeof(float); - float *t0 = (float*)pt + st0_off/sizeof(float) + 1; - float *s1 = (float*)pt + st1_off/sizeof(float); - float *t1 = (float*)pt + st1_off/sizeof(float) + 1; - float *fog = (float*)pt + fog_ext_off/sizeof(float); - WriteTrace(TraceGlitch, TraceDebug,"grDrawPoint()\r\n"); - - if(nvidia_viewport_hack && !render_to_texture) - { - glViewport(0, g_viewport_offset, viewport_width, viewport_height); - nvidia_viewport_hack = 0; - } - - reloadTexture(); - - if(need_to_compile) compile_shader(); - - glBegin(GL_POINTS); - - if (nbTextureUnits > 2) - { - if (st0_en) - glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width, - ytex(0, *t0 / *q / (float)tex1_height)); - if (st1_en) - glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width, - ytex(1, *t1 / *q / (float)tex0_height)); - } - else - { - if (st0_en) - glTexCoord2f(*s0 / *q / (float)tex0_width, - ytex(0, *t0 / *q / (float)tex0_height)); - } - if (pargb_en) - glColor4f(pargb[2]/255.0f, pargb[1]/255.0f, pargb[0]/255.0f, pargb[3]/255.0f); - if (fog_enabled && fog_coord_support) - { - if(!fog_ext_en || fog_enabled != 2) - glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f); - else - glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f); - } - glVertex4f((*x - (float)widtho) / (float)(width/2) / *q, - -(*y - (float)heighto) / (float)(height/2) / *q, ZCALC(*z ,*q), 1.0f / *q); - - glEnd(); - */ } FX_ENTRY void FX_CALL grDrawLine(const void *a, const void *b) { - /* - float *a_x = (float*)a + xy_off/sizeof(float); - float *a_y = (float*)a + xy_off/sizeof(float) + 1; - float *a_z = (float*)a + z_off/sizeof(float); - float *a_q = (float*)a + q_off/sizeof(float); - unsigned char *a_pargb = (unsigned char*)a + pargb_off; - float *a_s0 = (float*)a + st0_off/sizeof(float); - float *a_t0 = (float*)a + st0_off/sizeof(float) + 1; - float *a_s1 = (float*)a + st1_off/sizeof(float); - float *a_t1 = (float*)a + st1_off/sizeof(float) + 1; - float *a_fog = (float*)a + fog_ext_off/sizeof(float); - - float *b_x = (float*)b + xy_off/sizeof(float); - float *b_y = (float*)b + xy_off/sizeof(float) + 1; - float *b_z = (float*)b + z_off/sizeof(float); - float *b_q = (float*)b + q_off/sizeof(float); - unsigned char *b_pargb = (unsigned char*)b + pargb_off; - float *b_s0 = (float*)b + st0_off/sizeof(float); - float *b_t0 = (float*)b + st0_off/sizeof(float) + 1; - float *b_s1 = (float*)b + st1_off/sizeof(float); - float *b_t1 = (float*)b + st1_off/sizeof(float) + 1; - float *b_fog = (float*)b + fog_ext_off/sizeof(float); - WriteTrace(TraceGlitch, TraceDebug,"grDrawLine()\r\n"); - - if(nvidia_viewport_hack && !render_to_texture) - { - glViewport(0, g_viewport_offset, viewport_width, viewport_height); - nvidia_viewport_hack = 0; - } - - reloadTexture(); - - if(need_to_compile) compile_shader(); - - glBegin(GL_LINES); - - if (nbTextureUnits > 2) - { - if (st0_en) - glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width, ytex(0, *a_t0 / *a_q / (float)tex1_height)); - if (st1_en) - glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width, ytex(1, *a_t1 / *a_q / (float)tex0_height)); - } - else - { - if (st0_en) - glTexCoord2f(*a_s0 / *a_q / (float)tex0_width, ytex(0, *a_t0 / *a_q / (float)tex0_height)); - } - if (pargb_en) - glColor4f(a_pargb[2]/255.0f, a_pargb[1]/255.0f, a_pargb[0]/255.0f, a_pargb[3]/255.0f); - if (fog_enabled && fog_coord_support) - { - if(!fog_ext_en || fog_enabled != 2) - glSecondaryColor3f((1.0f / *a_q) / 255.0f, 0.0f, 0.0f); - else - glSecondaryColor3f((1.0f / *a_fog) / 255.0f, 0.0f, 0.0f); - } - glVertex4f((*a_x - (float)widtho) / (float)(width/2) / *a_q, - -(*a_y - (float)heighto) / (float)(height/2) / *a_q, ZCALC(*a_z, *a_q), 1.0f / *a_q); - - if (nbTextureUnits > 2) - { - if (st0_en) - glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width, - ytex(0, *b_t0 / *b_q / (float)tex1_height)); - if (st1_en) - glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width, - ytex(1, *b_t1 / *b_q / (float)tex0_height)); - } - else - { - if (st0_en) - glTexCoord2f(*b_s0 / *b_q / (float)tex0_width, - ytex(0, *b_t0 / *b_q / (float)tex0_height)); - } - if (pargb_en) - glColor4f(b_pargb[2]/255.0f, b_pargb[1]/255.0f, b_pargb[0]/255.0f, b_pargb[3]/255.0f); - if (fog_enabled && fog_coord_support) - { - if(!fog_ext_en || fog_enabled != 2) - glSecondaryColor3f((1.0f / *b_q) / 255.0f, 0.0f, 0.0f); - else - glSecondaryColor3f((1.0f / *b_fog) / 255.0f, 0.0f, 0.0f); - } - glVertex4f((*b_x - (float)widtho) / (float)(width/2) / *b_q, - -(*b_y - (float)heighto) / (float)(height/2) / *b_q, ZCALC(*b_z, *b_q), 1.0f / *b_q); - - glEnd(); - */ } FX_ENTRY void FX_CALL diff --git a/Source/Project64-video/Renderer/OGLESglitchmain.cpp b/Source/Project64-video/Renderer/OGLESglitchmain.cpp index e196b4eb5..5dfc774da 100644 --- a/Source/Project64-video/Renderer/OGLESglitchmain.cpp +++ b/Source/Project64-video/Renderer/OGLESglitchmain.cpp @@ -11,7 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ -#include +#include #define SAVE_CBUFFER @@ -138,7 +138,6 @@ typedef struct int buff_clear; } fb; -int nbTextureUnits; int nbAuxBuffers, current_buffer; int g_scr_res_x, g_width, widtho, heighto, g_scr_res_y, g_height; int g_res_x, g_res_y; @@ -393,32 +392,13 @@ FX_ENTRY GrContext_t FX_CALL grSstWinOpen(GrColorFormat_t color_format, GrOrigin #endif // _WIN32 nbTextureUnits = 4; - //glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &nbTextureUnits); - if (nbTextureUnits == 1) WriteTrace(TraceGlitch, TraceWarning, "You need a video card that has at least 2 texture units"); - nbAuxBuffers = 4; //glGetIntegerv(GL_AUX_BUFFERS, &nbAuxBuffers); if (nbAuxBuffers > 0) printf("Congratulations, you have %d auxilliary buffers, we'll use them wisely !\n", nbAuxBuffers); -#ifdef VOODOO1 - nbTextureUnits = 2; -#endif blend_func_separate_support = 1; packed_pixels_support = 0; - /* - if (isExtensionSupported("GL_EXT_blend_func_separate") == 0) - blend_func_separate_support = 0; - else - blend_func_separate_support = 1; - - if (isExtensionSupported("GL_EXT_packed_pixels") == 0) - packed_pixels_support = 0; - else { - printf("packed pixels extension used\n"); - packed_pixels_support = 1; - } - */ if (isExtensionSupported("GL_ARB_texture_non_power_of_two") == 0) npot_support = 0; @@ -984,19 +964,7 @@ grGet(FxU32 pname, FxU32 plength, FxI32 *params) break; case GR_NUM_TMU: if (plength < 4 || params == NULL) return 0; - if (!nbTextureUnits) - { - grSstWinOpen(GR_COLORFORMAT_ARGB, GR_ORIGIN_UPPER_LEFT, 2, 1); - grSstWinClose(0); - } -#ifdef VOODOO1 - params[0] = 1; -#else - if (nbTextureUnits > 2) - params[0] = 2; - else - params[0] = 1; -#endif + params[0] = 2; return 4; break; case GR_NUM_BOARDS: @@ -1019,7 +987,7 @@ grGet(FxU32 pname, FxU32 plength, FxI32 *params) break; case GR_MEMORY_UMA: if (plength < 4 || params == NULL) return 0; - params[0] = 16 * 1024 * 1024 * nbTextureUnits; + params[0] = 16 * 1024 * 1024 * 4; return 4; break; case GR_BITS_RGBA: @@ -1622,7 +1590,7 @@ grLfbLock(GrLock_t type, GrBuffer_t buffer, GrLfbWriteMode_t writeMode, } return FXTRUE; -} + } FX_ENTRY FxBool FX_CALL grLfbUnlock(GrLock_t type, GrBuffer_t buffer) @@ -1856,7 +1824,7 @@ grLfbWriteRegion(GrBuffer_t dst_buffer, //glDrawBuffer(current_buffer); //glPopAttrib(); return FXTRUE; -} + } /* wrapper-specific glide extensions */ diff --git a/Source/Project64-video/Renderer/OGLEStextures.cpp b/Source/Project64-video/Renderer/OGLEStextures.cpp index 37bdb3f51..e922db4bb 100644 --- a/Source/Project64-video/Renderer/OGLEStextures.cpp +++ b/Source/Project64-video/Renderer/OGLEStextures.cpp @@ -34,7 +34,7 @@ #define GR_TEXFMT_ARGB_CMP_DXT5 0x1A #define GR_TEXTFMT_RGB_888 0xFF -int TMU_SIZE = 8*2048*2048; +int TMU_SIZE = 8 * 2048 * 2048; static unsigned char* texture = NULL; int packed_pixels_support = -1; @@ -55,8 +55,8 @@ unsigned char *filter(unsigned char *source, int width, int height, int *width2, typedef struct _texlist { - unsigned int id; - struct _texlist *next; + unsigned int id; + struct _texlist *next; } texlist; static int nbTex = 0; @@ -69,249 +69,248 @@ extern PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB; #endif void remove_tex(unsigned int idmin, unsigned int idmax) { - unsigned int *t; - int n = 0; - texlist *aux = list; - int sz = nbTex; - if (aux == NULL) return; - t = (unsigned int*)malloc(sz * sizeof(int)); - while (aux && aux->id >= idmin && aux->id < idmax) - { - if (n >= sz) - t = (unsigned int *) realloc(t, ++sz*sizeof(int)); - t[n++] = aux->id; - aux = aux->next; - free(list); - list = aux; - nbTex--; - } - while (aux != NULL && aux->next != NULL) - { - if (aux->next->id >= idmin && aux->next->id < idmax) + unsigned int *t; + int n = 0; + texlist *aux = list; + int sz = nbTex; + if (aux == NULL) return; + t = (unsigned int*)malloc(sz * sizeof(int)); + while (aux && aux->id >= idmin && aux->id < idmax) { - texlist *aux2 = aux->next->next; - if (n >= sz) - t = (unsigned int *) realloc(t, ++sz*sizeof(int)); - t[n++] = aux->next->id; - free(aux->next); - aux->next = aux2; - nbTex--; + if (n >= sz) + t = (unsigned int *)realloc(t, ++sz * sizeof(int)); + t[n++] = aux->id; + aux = aux->next; + free(list); + list = aux; + nbTex--; } - aux = aux->next; - } - glDeleteTextures(n, t); - free(t); - //printf("RMVTEX nbtex is now %d (%06x - %06x)\n", nbTex, idmin, idmax); + while (aux != NULL && aux->next != NULL) + { + if (aux->next->id >= idmin && aux->next->id < idmax) + { + texlist *aux2 = aux->next->next; + if (n >= sz) + t = (unsigned int *)realloc(t, ++sz * sizeof(int)); + t[n++] = aux->next->id; + free(aux->next); + aux->next = aux2; + nbTex--; + } + aux = aux->next; + } + glDeleteTextures(n, t); + free(t); + //printf("RMVTEX nbtex is now %d (%06x - %06x)\n", nbTex, idmin, idmax); } - void add_tex(unsigned int id) { - texlist *aux = list; - texlist *aux2; - //printf("ADDTEX nbtex is now %d (%06x)\n", nbTex, id); - if (list == NULL || id < list->id) - { + texlist *aux = list; + texlist *aux2; + //printf("ADDTEX nbtex is now %d (%06x)\n", nbTex, id); + if (list == NULL || id < list->id) + { + nbTex++; + list = (texlist*)malloc(sizeof(texlist)); + list->next = aux; + list->id = id; + return; + } + while (aux->next != NULL && aux->next->id < id) aux = aux->next; + // ZIGGY added this test so that add_tex now accept re-adding an existing texture + if (aux->next != NULL && aux->next->id == id) return; nbTex++; - list = (texlist*)malloc(sizeof(texlist)); - list->next = aux; - list->id = id; - return; - } - while (aux->next != NULL && aux->next->id < id) aux = aux->next; - // ZIGGY added this test so that add_tex now accept re-adding an existing texture - if (aux->next != NULL && aux->next->id == id) return; - nbTex++; - aux2 = aux->next; - aux->next = (texlist*)malloc(sizeof(texlist)); - aux->next->id = id; - aux->next->next = aux2; + aux2 = aux->next; + aux->next = (texlist*)malloc(sizeof(texlist)); + aux->next->id = id; + aux->next->next = aux2; } void init_textures() { - tex0_width = tex0_height = tex1_width = tex1_height = 2; - // ZIGGY because remove_tex isn't called (Pj64 doesn't like it), it's better - // to leave these so that they'll be reused (otherwise we have a memory leak) - // list = NULL; - // nbTex = 0; + tex0_width = tex0_height = tex1_width = tex1_height = 2; + // ZIGGY because remove_tex isn't called (Pj64 doesn't like it), it's better + // to leave these so that they'll be reused (otherwise we have a memory leak) + // list = NULL; + // nbTex = 0; - if (!texture) texture = (unsigned char*)malloc(2048*2048*4); + if (!texture) texture = (unsigned char*)malloc(2048 * 2048 * 4); } void free_textures() { #ifndef WIN32 - // ZIGGY for some reasons, Pj64 doesn't like remove_tex on exit - remove_tex(0x00000000, 0xFFFFFFFF); + // ZIGGY for some reasons, Pj64 doesn't like remove_tex on exit + remove_tex(0x00000000, 0xFFFFFFFF); #endif - if (texture != NULL) { - free(texture); - texture = NULL; - } + if (texture != NULL) { + free(texture); + texture = NULL; + } } FX_ENTRY FxU32 FX_CALL -grTexMinAddress( GrChipID_t tmu ) +grTexMinAddress(GrChipID_t tmu) { WriteTrace(TraceGlitch, TraceDebug, "tmu = %d", tmu); - if (UMAmode) - return 0; - else - return tmu*TMU_SIZE; + if (UMAmode) + return 0; + else + return tmu*TMU_SIZE; } FX_ENTRY FxU32 FX_CALL -grTexMaxAddress( GrChipID_t tmu ) +grTexMaxAddress(GrChipID_t tmu) { WriteTrace(TraceGlitch, TraceDebug, "tmu = %d", tmu); - if (UMAmode) - return TMU_SIZE*2 - 1; - else - return tmu*TMU_SIZE + TMU_SIZE - 1; + if (UMAmode) + return TMU_SIZE * 2 - 1; + else + return tmu*TMU_SIZE + TMU_SIZE - 1; } FX_ENTRY FxU32 FX_CALL -grTexTextureMemRequired( FxU32 evenOdd, - GrTexInfo *info ) +grTexTextureMemRequired(FxU32 evenOdd, + GrTexInfo *info) { WriteTrace(TraceGlitch, TraceDebug, "evenOdd = %d", evenOdd); - int width, height; - if (info->largeLodLog2 != info->smallLodLog2) WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : loading more than one LOD"); + int width, height; + if (info->largeLodLog2 != info->smallLodLog2) WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : loading more than one LOD"); - if (info->aspectRatioLog2 < 0) - { - height = 1 << info->largeLodLog2; - width = height >> -info->aspectRatioLog2; - } - else - { - width = 1 << info->largeLodLog2; - height = width >> info->aspectRatioLog2; - } + if (info->aspectRatioLog2 < 0) + { + height = 1 << info->largeLodLog2; + width = height >> -info->aspectRatioLog2; + } + else + { + width = 1 << info->largeLodLog2; + height = width >> info->aspectRatioLog2; + } - switch(info->format) - { - case GR_TEXFMT_ALPHA_8: - case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii - case GR_TEXFMT_ALPHA_INTENSITY_44: - return width*height; - break; - case GR_TEXFMT_ARGB_1555: - case GR_TEXFMT_ARGB_4444: - case GR_TEXFMT_ALPHA_INTENSITY_88: - case GR_TEXFMT_RGB_565: - return (width*height)<<1; - break; - case GR_TEXFMT_ARGB_8888: - return (width*height)<<2; - break; - case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii - return ((((width+0x3)&~0x3)*((height+0x3)&~0x3))>>1); - case GR_TEXFMT_ARGB_CMP_DXT3: - return ((width+0x3)&~0x3)*((height+0x3)&~0x3); - case GR_TEXFMT_ARGB_CMP_DXT5: - return ((width+0x3)&~0x3)*((height+0x3)&~0x3); - case GR_TEXFMT_ARGB_CMP_FXT1: - return ((((width+0x7)&~0x7)*((height+0x3)&~0x3))>>1); - default: - WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : unknown texture format: %x", info->format); - } - return 0; + switch (info->format) + { + case GR_TEXFMT_ALPHA_8: + case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii + case GR_TEXFMT_ALPHA_INTENSITY_44: + return width*height; + break; + case GR_TEXFMT_ARGB_1555: + case GR_TEXFMT_ARGB_4444: + case GR_TEXFMT_ALPHA_INTENSITY_88: + case GR_TEXFMT_RGB_565: + return (width*height) << 1; + break; + case GR_TEXFMT_ARGB_8888: + return (width*height) << 2; + break; + case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii + return ((((width + 0x3)&~0x3)*((height + 0x3)&~0x3)) >> 1); + case GR_TEXFMT_ARGB_CMP_DXT3: + return ((width + 0x3)&~0x3)*((height + 0x3)&~0x3); + case GR_TEXFMT_ARGB_CMP_DXT5: + return ((width + 0x3)&~0x3)*((height + 0x3)&~0x3); + case GR_TEXFMT_ARGB_CMP_FXT1: + return ((((width + 0x7)&~0x7)*((height + 0x3)&~0x3)) >> 1); + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : unknown texture format: %x", info->format); + } + return 0; } FX_ENTRY FxU32 FX_CALL grTexCalcMemRequired( - GrLOD_t lodmin, GrLOD_t lodmax, - GrAspectRatio_t aspect, GrTextureFormat_t fmt) + GrLOD_t lodmin, GrLOD_t lodmax, + GrAspectRatio_t aspect, GrTextureFormat_t fmt) { WriteTrace(TraceGlitch, TraceDebug, "lodmin = %d, lodmax: %d aspect: %d fmt: %d", lodmin, lodmax, aspect, fmt); - int width, height; - if (lodmax != lodmin) WriteTrace(TraceGlitch, TraceWarning, "grTexCalcMemRequired : loading more than one LOD"); + int width, height; + if (lodmax != lodmin) WriteTrace(TraceGlitch, TraceWarning, "grTexCalcMemRequired : loading more than one LOD"); - if (aspect < 0) - { - height = 1 << lodmax; - width = height >> -aspect; - } - else - { - width = 1 << lodmax; - height = width >> aspect; - } + if (aspect < 0) + { + height = 1 << lodmax; + width = height >> -aspect; + } + else + { + width = 1 << lodmax; + height = width >> aspect; + } - switch(fmt) - { - case GR_TEXFMT_ALPHA_8: - case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii - case GR_TEXFMT_ALPHA_INTENSITY_44: - return width*height; - break; - case GR_TEXFMT_ARGB_1555: - case GR_TEXFMT_ARGB_4444: - case GR_TEXFMT_ALPHA_INTENSITY_88: - case GR_TEXFMT_RGB_565: - return (width*height)<<1; - break; - case GR_TEXFMT_ARGB_8888: - return (width*height)<<2; - break; - case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii - return ((((width+0x3)&~0x3)*((height+0x3)&~0x3))>>1); - case GR_TEXFMT_ARGB_CMP_DXT3: - return ((width+0x3)&~0x3)*((height+0x3)&~0x3); - case GR_TEXFMT_ARGB_CMP_DXT5: - return ((width+0x3)&~0x3)*((height+0x3)&~0x3); - case GR_TEXFMT_ARGB_CMP_FXT1: - return ((((width+0x7)&~0x7)*((height+0x3)&~0x3))>>1); - default: - WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : unknown texture format: %x", fmt); - } - return 0; + switch (fmt) + { + case GR_TEXFMT_ALPHA_8: + case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii + case GR_TEXFMT_ALPHA_INTENSITY_44: + return width*height; + break; + case GR_TEXFMT_ARGB_1555: + case GR_TEXFMT_ARGB_4444: + case GR_TEXFMT_ALPHA_INTENSITY_88: + case GR_TEXFMT_RGB_565: + return (width*height) << 1; + break; + case GR_TEXFMT_ARGB_8888: + return (width*height) << 2; + break; + case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii + return ((((width + 0x3)&~0x3)*((height + 0x3)&~0x3)) >> 1); + case GR_TEXFMT_ARGB_CMP_DXT3: + return ((width + 0x3)&~0x3)*((height + 0x3)&~0x3); + case GR_TEXFMT_ARGB_CMP_DXT5: + return ((width + 0x3)&~0x3)*((height + 0x3)&~0x3); + case GR_TEXFMT_ARGB_CMP_FXT1: + return ((((width + 0x7)&~0x7)*((height + 0x3)&~0x3)) >> 1); + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : unknown texture format: %x", fmt); + } + return 0; } int grTexFormatSize(int fmt) { - int factor = -1; - switch(fmt) { - case GR_TEXFMT_ALPHA_8: - case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii - factor = 1; - break; - case GR_TEXFMT_ALPHA_INTENSITY_44: - factor = 1; - break; - case GR_TEXFMT_RGB_565: - factor = 2; - break; - case GR_TEXFMT_ARGB_1555: - factor = 2; - break; - case GR_TEXFMT_ALPHA_INTENSITY_88: - factor = 2; - break; - case GR_TEXFMT_ARGB_4444: - factor = 2; - break; - case GR_TEXFMT_ARGB_8888: - factor = 4; - break; - case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii - factor = 8; // HACKALERT: factor holds block bytes - break; - case GR_TEXFMT_ARGB_CMP_DXT3: // FXT1,DXT1,5 support - H.Morii - factor = 16; // HACKALERT: factor holds block bytes - break; - case GR_TEXFMT_ARGB_CMP_DXT5: - factor = 16; - break; - case GR_TEXFMT_ARGB_CMP_FXT1: - factor = 8; - break; - default: - WriteTrace(TraceGlitch, TraceWarning, "grTexFormatSize : unknown texture format: %x", fmt); - } - return factor; + int factor = -1; + switch (fmt) { + case GR_TEXFMT_ALPHA_8: + case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii + factor = 1; + break; + case GR_TEXFMT_ALPHA_INTENSITY_44: + factor = 1; + break; + case GR_TEXFMT_RGB_565: + factor = 2; + break; + case GR_TEXFMT_ARGB_1555: + factor = 2; + break; + case GR_TEXFMT_ALPHA_INTENSITY_88: + factor = 2; + break; + case GR_TEXFMT_ARGB_4444: + factor = 2; + break; + case GR_TEXFMT_ARGB_8888: + factor = 4; + break; + case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii + factor = 8; // HACKALERT: factor holds block bytes + break; + case GR_TEXFMT_ARGB_CMP_DXT3: // FXT1,DXT1,5 support - H.Morii + factor = 16; // HACKALERT: factor holds block bytes + break; + case GR_TEXFMT_ARGB_CMP_DXT5: + factor = 16; + break; + case GR_TEXFMT_ARGB_CMP_FXT1: + factor = 8; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexFormatSize : unknown texture format: %x", fmt); + } + return factor; } int grTexFormat2GLPackedFmt(int fmt, int * gltexfmt, int * glpixfmt, int * glpackfmt) @@ -320,575 +319,568 @@ int grTexFormat2GLPackedFmt(int fmt, int * gltexfmt, int * glpixfmt, int * glpac *glpixfmt = GL_RGBA; *glpackfmt = GL_UNSIGNED_BYTE; return 0; -/* - int factor = -1; - switch(fmt) { - case GR_TEXFMT_ALPHA_8: - factor = 1; - *gltexfmt = GL_INTENSITY8; - *glpixfmt = GL_LUMINANCE; - *glpackfmt = GL_UNSIGNED_BYTE; - break; - case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii - factor = 1; - *gltexfmt = GL_LUMINANCE8; - *glpixfmt = GL_LUMINANCE; - *glpackfmt = GL_UNSIGNED_BYTE; - break; - case GR_TEXFMT_ALPHA_INTENSITY_44: - break; - case GR_TEXFMT_RGB_565: - factor = 2; - *gltexfmt = GL_RGB; - *glpixfmt = GL_RGB; - *glpackfmt = GL_UNSIGNED_SHORT_5_6_5; - break; - case GR_TEXFMT_ARGB_1555: - if (ati_sucks > 0) return -1; // ATI sucks as usual (fixes slowdown on ATI) - factor = 2; - *gltexfmt = GL_RGB5_A1; - *glpixfmt = GL_BGRA; - *glpackfmt = GL_UNSIGNED_SHORT_1_5_5_5_REV; - break; - case GR_TEXFMT_ALPHA_INTENSITY_88: - factor = 2; - *gltexfmt = GL_LUMINANCE8_ALPHA8; - *glpixfmt = GL_LUMINANCE_ALPHA; - *glpackfmt = GL_UNSIGNED_BYTE; - break; - case GR_TEXFMT_ARGB_4444: - factor = 2; - *gltexfmt = GL_RGBA4; - *glpixfmt = GL_BGRA; - *glpackfmt = GL_UNSIGNED_SHORT_4_4_4_4_REV; - break; - case GR_TEXFMT_ARGB_8888: - factor = 4; - *gltexfmt = GL_RGBA8; - *glpixfmt = GL_BGRA; - *glpackfmt = GL_UNSIGNED_INT_8_8_8_8_REV; - break; - case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii - // HACKALERT: 3Dfx Glide uses GR_TEXFMT_ARGB_CMP_DXT1 for both opaque DXT1 and DXT1 with 1bit alpha. - // GlideHQ compiled with GLIDE64_DXTN option enabled, uses opaqe DXT1 only. - factor = 8; // HACKALERT: factor holds block bytes - *gltexfmt = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; // these variables aren't used - *glpixfmt = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - *glpackfmt = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - break; - case GR_TEXFMT_ARGB_CMP_DXT3: - factor = 16; - *gltexfmt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - *glpixfmt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - *glpackfmt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - break; - case GR_TEXFMT_ARGB_CMP_DXT5: - factor = 16; - *gltexfmt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - *glpixfmt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - *glpackfmt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - break; - case GR_TEXFMT_ARGB_CMP_FXT1: - factor = 8; - *gltexfmt = GL_COMPRESSED_RGBA_FXT1_3DFX; - *glpixfmt = GL_COMPRESSED_RGBA_FXT1_3DFX; - *glpackfmt = GL_COMPRESSED_RGBA_FXT1_3DFX; // XXX: what should we do about GL_COMPRESSED_RGB_FXT1_3DFX? - break; - default: - WriteTrace(TraceGlitch, TraceWarning, "grTexFormat2GLPackedFmt : unknown texture format: %x", fmt); - } - return factor; -*/ + /* + int factor = -1; + switch(fmt) { + case GR_TEXFMT_ALPHA_8: + factor = 1; + *gltexfmt = GL_INTENSITY8; + *glpixfmt = GL_LUMINANCE; + *glpackfmt = GL_UNSIGNED_BYTE; + break; + case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii + factor = 1; + *gltexfmt = GL_LUMINANCE8; + *glpixfmt = GL_LUMINANCE; + *glpackfmt = GL_UNSIGNED_BYTE; + break; + case GR_TEXFMT_ALPHA_INTENSITY_44: + break; + case GR_TEXFMT_RGB_565: + factor = 2; + *gltexfmt = GL_RGB; + *glpixfmt = GL_RGB; + *glpackfmt = GL_UNSIGNED_SHORT_5_6_5; + break; + case GR_TEXFMT_ARGB_1555: + if (ati_sucks > 0) return -1; // ATI sucks as usual (fixes slowdown on ATI) + factor = 2; + *gltexfmt = GL_RGB5_A1; + *glpixfmt = GL_BGRA; + *glpackfmt = GL_UNSIGNED_SHORT_1_5_5_5_REV; + break; + case GR_TEXFMT_ALPHA_INTENSITY_88: + factor = 2; + *gltexfmt = GL_LUMINANCE8_ALPHA8; + *glpixfmt = GL_LUMINANCE_ALPHA; + *glpackfmt = GL_UNSIGNED_BYTE; + break; + case GR_TEXFMT_ARGB_4444: + factor = 2; + *gltexfmt = GL_RGBA4; + *glpixfmt = GL_BGRA; + *glpackfmt = GL_UNSIGNED_SHORT_4_4_4_4_REV; + break; + case GR_TEXFMT_ARGB_8888: + factor = 4; + *gltexfmt = GL_RGBA8; + *glpixfmt = GL_BGRA; + *glpackfmt = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii + // HACKALERT: 3Dfx Glide uses GR_TEXFMT_ARGB_CMP_DXT1 for both opaque DXT1 and DXT1 with 1bit alpha. + // GlideHQ compiled with GLIDE64_DXTN option enabled, uses opaqe DXT1 only. + factor = 8; // HACKALERT: factor holds block bytes + *gltexfmt = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; // these variables aren't used + *glpixfmt = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + *glpackfmt = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + break; + case GR_TEXFMT_ARGB_CMP_DXT3: + factor = 16; + *gltexfmt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + *glpixfmt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + *glpackfmt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + break; + case GR_TEXFMT_ARGB_CMP_DXT5: + factor = 16; + *gltexfmt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + *glpixfmt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + *glpackfmt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + break; + case GR_TEXFMT_ARGB_CMP_FXT1: + factor = 8; + *gltexfmt = GL_COMPRESSED_RGBA_FXT1_3DFX; + *glpixfmt = GL_COMPRESSED_RGBA_FXT1_3DFX; + *glpackfmt = GL_COMPRESSED_RGBA_FXT1_3DFX; // XXX: what should we do about GL_COMPRESSED_RGB_FXT1_3DFX? + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexFormat2GLPackedFmt : unknown texture format: %x", fmt); + } + return factor; + */ } FX_ENTRY void FX_CALL -grTexDownloadMipMap( GrChipID_t tmu, - FxU32 startAddress, - FxU32 evenOdd, - GrTexInfo *info ) +grTexDownloadMipMap(GrChipID_t tmu, + FxU32 startAddress, + FxU32 evenOdd, + GrTexInfo *info) { WriteTrace(TraceGlitch, TraceDebug, "tmu = %d, startAddress: %d evenOdd: %d", tmu, startAddress, evenOdd); - int width, height, i, j; - int factor; - int glformat = 0; - int gltexfmt, glpixfmt, glpackfmt; - if (info->largeLodLog2 != info->smallLodLog2) WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMap : loading more than one LOD"); + int width, height, i, j; + int factor; + int glformat = 0; + int gltexfmt, glpixfmt, glpackfmt; + if (info->largeLodLog2 != info->smallLodLog2) WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMap : loading more than one LOD"); - if (info->aspectRatioLog2 < 0) - { - height = 1 << info->largeLodLog2; - width = height >> -info->aspectRatioLog2; - } - else - { - width = 1 << info->largeLodLog2; - height = width >> info->aspectRatioLog2; - } - - if (!packed_pixels_support) - factor = -1; - else - factor = grTexFormat2GLPackedFmt(info->format, &gltexfmt, &glpixfmt, &glpackfmt); - - if (factor < 0) { - - // VP fixed the texture conversions to be more accurate, also swapped - // the for i/j loops so that is is less likely to break the memory cache - register int n = 0, m = 0; - switch(info->format) + if (info->aspectRatioLog2 < 0) { - case GR_TEXFMT_ALPHA_8: - for (i=0; idata)[m]; - texel |= (texel << 8); - texel |= (texel << 16); - ((unsigned int*)texture)[n] = texel; - m++; - n++; - } - } - factor = 1; - glformat = GL_RGBA; - break; - case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii - for (i=0; idata)[m]; - texel |= (0xFF000000 | (texel << 16) | (texel << 8)); - ((unsigned int*)texture)[n] = texel; - m++; - n++; - } - } - factor = 1; - glformat = GL_ALPHA; - break; - case GR_TEXFMT_ALPHA_INTENSITY_44: -#if 1 - for (i=0; idata)[m]; -#if 1 - /* accurate conversion */ - unsigned int texel_hi = (texel & 0x000000F0) << 20; - unsigned int texel_low = texel & 0x0000000F; - texel_low |= (texel_low << 4); - texel_hi |= ((texel_hi << 4) | (texel_low << 16) | (texel_low << 8) | texel_low); -#else - unsigned int texel_hi = (texel & 0x000000F0) << 24; - unsigned int texel_low = (texel & 0x0000000F) << 4; - texel_hi |= ((texel_low << 16) | (texel_low << 8) | texel_low); -#endif - ((unsigned int*)texture)[n] = texel_hi; - m++; - n++; - } - } - factor = 1; - glformat = GL_LUMINANCE_ALPHA; -#endif - break; - case GR_TEXFMT_RGB_565: - for (i=0; idata)[m]; - unsigned int B = texel & 0x0000F800; - unsigned int G = texel & 0x000007E0; - unsigned int R = texel & 0x0000001F; -#if 0 - /* accurate conversion */ - ((unsigned int*)texture)[n] = 0xFF000000 | (R << 19) | ((R >> 2) << 16) | (G << 5) | ((G >> 9) << 8) | (B >> 8) | (B >> 13); -#else - ((unsigned int*)texture)[n] = 0xFF000000 | (R << 19) | (G << 5) | (B >> 8); -#endif - m++; - n++; - } - } - factor = 2; - glformat = GL_RGB; - break; - case GR_TEXFMT_ARGB_1555: - for (i=0; idata)[m]; - unsigned int A = texel & 0x00008000 ? 0xFF000000 : 0; - unsigned int B = texel & 0x00007C00; - unsigned int G = texel & 0x000003E0; - unsigned int R = texel & 0x0000001F; -#if 0 - /* accurate conversion */ - ((unsigned int*)texture)[n] = A | (R << 19) | ((R >> 2) << 16) | (G << 6) | ((G >> 8) << 8) | (B >> 7) | (B >> 12); -#else - ((unsigned int*)texture)[n] = A | (R << 19) | (G << 6) | (B >> 7); -#endif - m++; - n++; - } - } - factor = 2; - glformat = GL_RGBA; - break; - case GR_TEXFMT_ALPHA_INTENSITY_88: - for (i=0; idata)[m]; - unsigned int I = (unsigned int)(AI & 0x000000FF); - ((unsigned int*)texture)[n] = (AI << 16) | (I << 8) | I; - m++; - n++; - } - } - factor = 2; - glformat = GL_LUMINANCE_ALPHA; - break; - case GR_TEXFMT_ARGB_4444: - - for (i=0; idata)[m]; - unsigned int A = texel & 0x0000F000; - unsigned int B = texel & 0x00000F00; - unsigned int G = texel & 0x000000F0; - unsigned int R = texel & 0x0000000F; -#if 0 - /* accurate conversion */ - ((unsigned int*)texture)[n] = (A << 16) | (A << 12) | (R << 20) | (R << 16) | (G << 8) | (G << 4) | (B >> 4) | (B >> 8); -#else - ((unsigned int*)texture)[n] = (A << 16) | (R << 20) | (G << 8) | (B >> 4); -#endif - m++; - n++; - } - } - factor = 2; - glformat = GL_RGBA; - break; - case GR_TEXFMT_ARGB_8888: - for (i=0; idata)[m]; - unsigned int A = texel & 0xFF000000; - unsigned int B = texel & 0x00FF0000; - unsigned int G = texel & 0x0000FF00; - unsigned int R = texel & 0x000000FF; - ((unsigned int*)texture)[n] = A | (R << 16) | G | (B >> 16); - m++; - n++; - } - } - factor = 4; - glformat = GL_RGBA; - break; -/* - case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii - factor = 8; // HACKALERT: factor holds block bytes - glformat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - break; - case GR_TEXFMT_ARGB_CMP_DXT3: // FXT1,DXT1,5 support - H.Morii - factor = 16; // HACKALERT: factor holds block bytes - glformat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - break; - case GR_TEXFMT_ARGB_CMP_DXT5: - factor = 16; - glformat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - break; - case GR_TEXFMT_ARGB_CMP_FXT1: - factor = 8; - glformat = GL_COMPRESSED_RGBA_FXT1_3DFX; - break; -*/ - default: - WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMap : unknown texture format: %x", info->format); - factor = 0; + height = 1 << info->largeLodLog2; + width = height >> -info->aspectRatioLog2; + } + else + { + width = 1 << info->largeLodLog2; + height = width >> info->aspectRatioLog2; + } + + if (!packed_pixels_support) + factor = -1; + else + factor = grTexFormat2GLPackedFmt(info->format, &gltexfmt, &glpixfmt, &glpackfmt); + + if (factor < 0) { + // VP fixed the texture conversions to be more accurate, also swapped + // the for i/j loops so that is is less likely to break the memory cache + register int n = 0, m = 0; + switch (info->format) + { + case GR_TEXFMT_ALPHA_8: + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + unsigned int texel = (unsigned int)((unsigned char*)info->data)[m]; + texel |= (texel << 8); + texel |= (texel << 16); + ((unsigned int*)texture)[n] = texel; + m++; + n++; + } + } + factor = 1; + glformat = GL_RGBA; + break; + case GR_TEXFMT_INTENSITY_8: // I8 support - H.Morii + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + unsigned int texel = (unsigned int)((unsigned char*)info->data)[m]; + texel |= (0xFF000000 | (texel << 16) | (texel << 8)); + ((unsigned int*)texture)[n] = texel; + m++; + n++; + } + } + factor = 1; + glformat = GL_ALPHA; + break; + case GR_TEXFMT_ALPHA_INTENSITY_44: +#if 1 + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + unsigned int texel = (unsigned int)((unsigned char*)info->data)[m]; +#if 1 + /* accurate conversion */ + unsigned int texel_hi = (texel & 0x000000F0) << 20; + unsigned int texel_low = texel & 0x0000000F; + texel_low |= (texel_low << 4); + texel_hi |= ((texel_hi << 4) | (texel_low << 16) | (texel_low << 8) | texel_low); +#else + unsigned int texel_hi = (texel & 0x000000F0) << 24; + unsigned int texel_low = (texel & 0x0000000F) << 4; + texel_hi |= ((texel_low << 16) | (texel_low << 8) | texel_low); +#endif + ((unsigned int*)texture)[n] = texel_hi; + m++; + n++; + } + } + factor = 1; + glformat = GL_LUMINANCE_ALPHA; +#endif + break; + case GR_TEXFMT_RGB_565: + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + unsigned int texel = (unsigned int)((unsigned short*)info->data)[m]; + unsigned int B = texel & 0x0000F800; + unsigned int G = texel & 0x000007E0; + unsigned int R = texel & 0x0000001F; +#if 0 + /* accurate conversion */ + ((unsigned int*)texture)[n] = 0xFF000000 | (R << 19) | ((R >> 2) << 16) | (G << 5) | ((G >> 9) << 8) | (B >> 8) | (B >> 13); +#else + ((unsigned int*)texture)[n] = 0xFF000000 | (R << 19) | (G << 5) | (B >> 8); +#endif + m++; + n++; + } + } + factor = 2; + glformat = GL_RGB; + break; + case GR_TEXFMT_ARGB_1555: + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + unsigned int texel = (unsigned int)((unsigned short*)info->data)[m]; + unsigned int A = texel & 0x00008000 ? 0xFF000000 : 0; + unsigned int B = texel & 0x00007C00; + unsigned int G = texel & 0x000003E0; + unsigned int R = texel & 0x0000001F; +#if 0 + /* accurate conversion */ + ((unsigned int*)texture)[n] = A | (R << 19) | ((R >> 2) << 16) | (G << 6) | ((G >> 8) << 8) | (B >> 7) | (B >> 12); +#else + ((unsigned int*)texture)[n] = A | (R << 19) | (G << 6) | (B >> 7); +#endif + m++; + n++; + } + } + factor = 2; + glformat = GL_RGBA; + break; + case GR_TEXFMT_ALPHA_INTENSITY_88: + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + unsigned int AI = (unsigned int)((unsigned short*)info->data)[m]; + unsigned int I = (unsigned int)(AI & 0x000000FF); + ((unsigned int*)texture)[n] = (AI << 16) | (I << 8) | I; + m++; + n++; + } + } + factor = 2; + glformat = GL_LUMINANCE_ALPHA; + break; + case GR_TEXFMT_ARGB_4444: + + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + unsigned int texel = (unsigned int)((unsigned short*)info->data)[m]; + unsigned int A = texel & 0x0000F000; + unsigned int B = texel & 0x00000F00; + unsigned int G = texel & 0x000000F0; + unsigned int R = texel & 0x0000000F; +#if 0 + /* accurate conversion */ + ((unsigned int*)texture)[n] = (A << 16) | (A << 12) | (R << 20) | (R << 16) | (G << 8) | (G << 4) | (B >> 4) | (B >> 8); +#else + ((unsigned int*)texture)[n] = (A << 16) | (R << 20) | (G << 8) | (B >> 4); +#endif + m++; + n++; + } + } + factor = 2; + glformat = GL_RGBA; + break; + case GR_TEXFMT_ARGB_8888: + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + unsigned int texel = ((unsigned int*)info->data)[m]; + unsigned int A = texel & 0xFF000000; + unsigned int B = texel & 0x00FF0000; + unsigned int G = texel & 0x0000FF00; + unsigned int R = texel & 0x000000FF; + ((unsigned int*)texture)[n] = A | (R << 16) | G | (B >> 16); + m++; + n++; + } + } + factor = 4; + glformat = GL_RGBA; + break; + /* + case GR_TEXFMT_ARGB_CMP_DXT1: // FXT1,DXT1,5 support - H.Morii + factor = 8; // HACKALERT: factor holds block bytes + glformat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + break; + case GR_TEXFMT_ARGB_CMP_DXT3: // FXT1,DXT1,5 support - H.Morii + factor = 16; // HACKALERT: factor holds block bytes + glformat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + break; + case GR_TEXFMT_ARGB_CMP_DXT5: + factor = 16; + glformat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + break; + case GR_TEXFMT_ARGB_CMP_FXT1: + factor = 8; + glformat = GL_COMPRESSED_RGBA_FXT1_3DFX; + break; + */ + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMap : unknown texture format: %x", info->format); + factor = 0; + } } - } - if (nbTextureUnits <= 2) - glActiveTexture(GL_TEXTURE1); - else glActiveTexture(GL_TEXTURE2); - switch(info->format) - { - case GR_TEXFMT_ARGB_CMP_DXT1: - case GR_TEXFMT_ARGB_CMP_DXT3: - case GR_TEXFMT_ARGB_CMP_DXT5: - case GR_TEXFMT_ARGB_CMP_FXT1: - remove_tex(startAddress+1, startAddress+1+((width*height*factor)>>4)); - break; - default: - remove_tex(startAddress+1, startAddress+1+(width*height*factor)); - } + switch (info->format) + { + case GR_TEXFMT_ARGB_CMP_DXT1: + case GR_TEXFMT_ARGB_CMP_DXT3: + case GR_TEXFMT_ARGB_CMP_DXT5: + case GR_TEXFMT_ARGB_CMP_FXT1: + remove_tex(startAddress + 1, startAddress + 1 + ((width*height*factor) >> 4)); + break; + default: + remove_tex(startAddress + 1, startAddress + 1 + (width*height*factor)); + } - add_tex(startAddress+1); - glBindTexture(GL_TEXTURE_2D, startAddress+1); + add_tex(startAddress + 1); + glBindTexture(GL_TEXTURE_2D, startAddress + 1); - if (largest_supported_anisotropy > 1.0f) - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, largest_supported_anisotropy); + if (largest_supported_anisotropy > 1.0f) + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, largest_supported_anisotropy); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); -/* - switch(info->format) - { - case GR_TEXFMT_ARGB_CMP_DXT1: - case GR_TEXFMT_ARGB_CMP_DXT3: - case GR_TEXFMT_ARGB_CMP_DXT5: - case GR_TEXFMT_ARGB_CMP_FXT1: - glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, (glformat ? glformat : gltexfmt), width, height, 0, (width*height*factor)>>4, info->data); - break; - default: - if (glformat) { - glTexImage2D(GL_TEXTURE_2D, 0, glformat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); - } else - glTexImage2D(GL_TEXTURE_2D, 0, gltexfmt, width, height, 0, glpixfmt, glpackfmt, info->data); - } -*/ + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); + /* + switch(info->format) + { + case GR_TEXFMT_ARGB_CMP_DXT1: + case GR_TEXFMT_ARGB_CMP_DXT3: + case GR_TEXFMT_ARGB_CMP_DXT5: + case GR_TEXFMT_ARGB_CMP_FXT1: + glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, (glformat ? glformat : gltexfmt), width, height, 0, (width*height*factor)>>4, info->data); + break; + default: + if (glformat) { + glTexImage2D(GL_TEXTURE_2D, 0, glformat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); + } else + glTexImage2D(GL_TEXTURE_2D, 0, gltexfmt, width, height, 0, glpixfmt, glpackfmt, info->data); + } + */ - glBindTexture(GL_TEXTURE_2D, default_texture); + glBindTexture(GL_TEXTURE_2D, default_texture); } -int CheckTextureBufferFormat(GrChipID_t tmu, FxU32 startAddress, GrTexInfo *info ); +int CheckTextureBufferFormat(GrChipID_t tmu, FxU32 startAddress, GrTexInfo *info); FX_ENTRY void FX_CALL -grTexSource( GrChipID_t tmu, - FxU32 startAddress, - FxU32 evenOdd, - GrTexInfo *info ) +grTexSource(GrChipID_t tmu, + FxU32 startAddress, + FxU32 evenOdd, + GrTexInfo *info) { WriteTrace(TraceGlitch, TraceDebug, "tmu = %d, startAddress: %d evenOdd: %d", tmu, startAddress, evenOdd); - if (tmu == GR_TMU1 || nbTextureUnits <= 2) - { - if (tmu == GR_TMU1 && nbTextureUnits <= 2) return; - glActiveTexture(GL_TEXTURE0); - - if (info->aspectRatioLog2 < 0) + if (tmu == GR_TMU1) { - tex0_height = 256; - tex0_width = tex0_height >> -info->aspectRatioLog2; + glActiveTexture(GL_TEXTURE0); + + if (info->aspectRatioLog2 < 0) + { + tex0_height = 256; + tex0_width = tex0_height >> -info->aspectRatioLog2; + } + else + { + tex0_width = 256; + tex0_height = tex0_width >> info->aspectRatioLog2; + } + + glBindTexture(GL_TEXTURE_2D, startAddress + 1); +#ifdef VPDEBUG + dump_tex(startAddress + 1); +#endif + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t0); } else { - tex0_width = 256; - tex0_height = tex0_width >> info->aspectRatioLog2; - } + glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, startAddress+1); + if (info->aspectRatioLog2 < 0) + { + tex1_height = 256; + tex1_width = tex1_height >> -info->aspectRatioLog2; + } + else + { + tex1_width = 256; + tex1_height = tex1_width >> info->aspectRatioLog2; + } + + glBindTexture(GL_TEXTURE_2D, startAddress + 1); #ifdef VPDEBUG - dump_tex(startAddress+1); + dump_tex(startAddress + 1); #endif - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t0); - } - else - { - glActiveTexture(GL_TEXTURE1); - - if (info->aspectRatioLog2 < 0) - { - tex1_height = 256; - tex1_width = tex1_height >> -info->aspectRatioLog2; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t1); } - else + if (!CheckTextureBufferFormat(tmu, startAddress + 1, info)) { - tex1_width = 256; - tex1_height = tex1_width >> info->aspectRatioLog2; + if (tmu == 0 && blackandwhite1 != 0) + { + blackandwhite1 = 0; + need_to_compile = 1; + } + if (tmu == 1 && blackandwhite0 != 0) + { + blackandwhite0 = 0; + need_to_compile = 1; + } } - glBindTexture(GL_TEXTURE_2D, startAddress+1); -#ifdef VPDEBUG - dump_tex(startAddress+1); -#endif - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter1); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter1); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s1); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t1); - } - if(!CheckTextureBufferFormat(tmu, startAddress+1, info)) - { - if(tmu == 0 && blackandwhite1 != 0) - { - blackandwhite1 = 0; - need_to_compile = 1; - } - if(tmu == 1 && blackandwhite0 != 0) - { - blackandwhite0 = 0; - need_to_compile = 1; - } - } - #if 0 - extern int auxbuffer; - static int oldbuffer; - FX_ENTRY void FX_CALL grAuxBufferExt( GrBuffer_t buffer ); - if (auxbuffer == GR_BUFFER_AUXBUFFER && auxbuffer != oldbuffer) - grAuxBufferExt(auxbuffer); - oldbuffer = auxbuffer; + extern int auxbuffer; + static int oldbuffer; + FX_ENTRY void FX_CALL grAuxBufferExt(GrBuffer_t buffer); + if (auxbuffer == GR_BUFFER_AUXBUFFER && auxbuffer != oldbuffer) + grAuxBufferExt(auxbuffer); + oldbuffer = auxbuffer; #endif } FX_ENTRY void FX_CALL grTexDetailControl( - GrChipID_t tmu, - int lod_bias, - FxU8 detail_scale, - float detail_max - ) + GrChipID_t tmu, + int lod_bias, + FxU8 detail_scale, + float detail_max +) { WriteTrace(TraceGlitch, TraceDebug, "tmu = %d, lod_bias: %d detail_scale: %d detail_max: %d", tmu, lod_bias, detail_scale, detail_max); - if (lod_bias != 31 && detail_scale != 7) - { - if (!lod_bias && !detail_scale && !detail_max) return; - else - WriteTrace(TraceGlitch, TraceWarning, "grTexDetailControl : %d, %d, %f", lod_bias, detail_scale, detail_max); - } - lambda = detail_max; - if(lambda > 1.0f) - { - lambda = 1.0f - (255.0f - lambda); - } - if(lambda > 1.0f) WriteTrace(TraceGlitch, TraceWarning, "lambda:%f", lambda); + if (lod_bias != 31 && detail_scale != 7) + { + if (!lod_bias && !detail_scale && !detail_max) return; + else + WriteTrace(TraceGlitch, TraceWarning, "grTexDetailControl : %d, %d, %f", lod_bias, detail_scale, detail_max); + } + lambda = detail_max; + if (lambda > 1.0f) + { + lambda = 1.0f - (255.0f - lambda); + } + if (lambda > 1.0f) WriteTrace(TraceGlitch, TraceWarning, "lambda:%f", lambda); - set_lambda(); + set_lambda(); } FX_ENTRY void FX_CALL -grTexLodBiasValue(GrChipID_t tmu, float bias ) +grTexLodBiasValue(GrChipID_t tmu, float bias) { WriteTrace(TraceGlitch, TraceDebug, "tmu = %d, bias: %f", tmu, bias); } FX_ENTRY void FX_CALL grTexFilterMode( - GrChipID_t tmu, - GrTextureFilterMode_t minfilter_mode, - GrTextureFilterMode_t magfilter_mode - ) + GrChipID_t tmu, + GrTextureFilterMode_t minfilter_mode, + GrTextureFilterMode_t magfilter_mode +) { WriteTrace(TraceGlitch, TraceDebug, "tmu = %d, bias: %d magfilter_mode: %d", tmu, minfilter_mode, magfilter_mode); - if (tmu == GR_TMU1 || nbTextureUnits <= 2) - { - if (tmu == GR_TMU1 && nbTextureUnits <= 2) return; - if (minfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) min_filter0 = GL_NEAREST; - else min_filter0 = GL_LINEAR; + if (tmu == GR_TMU1) + { + if (minfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) min_filter0 = GL_NEAREST; + else min_filter0 = GL_LINEAR; - if (magfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) mag_filter0 = GL_NEAREST; - else mag_filter0 = GL_LINEAR; + if (magfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) mag_filter0 = GL_NEAREST; + else mag_filter0 = GL_LINEAR; - glActiveTexture(GL_TEXTURE0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter0); - } - else - { - if (minfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) min_filter1 = GL_NEAREST; - else min_filter1 = GL_LINEAR; + glActiveTexture(GL_TEXTURE0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter0); + } + else + { + if (minfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) min_filter1 = GL_NEAREST; + else min_filter1 = GL_LINEAR; - if (magfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) mag_filter1 = GL_NEAREST; - else mag_filter1 = GL_LINEAR; + if (magfilter_mode == GR_TEXTUREFILTER_POINT_SAMPLED) mag_filter1 = GL_NEAREST; + else mag_filter1 = GL_LINEAR; - glActiveTexture(GL_TEXTURE1); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter1); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter1); - } + glActiveTexture(GL_TEXTURE1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter1); + } } FX_ENTRY void FX_CALL grTexClampMode( - GrChipID_t tmu, - GrTextureClampMode_t s_clampmode, - GrTextureClampMode_t t_clampmode - ) + GrChipID_t tmu, + GrTextureClampMode_t s_clampmode, + GrTextureClampMode_t t_clampmode +) { WriteTrace(TraceGlitch, TraceDebug, "tmu = %d, s_clampmode: %d t_clampmode: %d", tmu, s_clampmode, t_clampmode); - if (tmu == GR_TMU1 || nbTextureUnits <= 2) - { - if (tmu == GR_TMU1 && nbTextureUnits <= 2) return; - switch(s_clampmode) + if (tmu == GR_TMU1) { - case GR_TEXTURECLAMP_WRAP: - wrap_s0 = GL_REPEAT; - break; - case GR_TEXTURECLAMP_CLAMP: - wrap_s0 = GL_CLAMP_TO_EDGE; - break; - case GR_TEXTURECLAMP_MIRROR_EXT: - wrap_s0 = GL_MIRRORED_REPEAT; - break; - default: - WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown s_clampmode : %x", s_clampmode); + switch (s_clampmode) + { + case GR_TEXTURECLAMP_WRAP: + wrap_s0 = GL_REPEAT; + break; + case GR_TEXTURECLAMP_CLAMP: + wrap_s0 = GL_CLAMP_TO_EDGE; + break; + case GR_TEXTURECLAMP_MIRROR_EXT: + wrap_s0 = GL_MIRRORED_REPEAT; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown s_clampmode : %x", s_clampmode); + } + switch (t_clampmode) + { + case GR_TEXTURECLAMP_WRAP: + wrap_t0 = GL_REPEAT; + break; + case GR_TEXTURECLAMP_CLAMP: + wrap_t0 = GL_CLAMP_TO_EDGE; + break; + case GR_TEXTURECLAMP_MIRROR_EXT: + wrap_t0 = GL_MIRRORED_REPEAT; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown t_clampmode : %x", t_clampmode); + } + glActiveTexture(GL_TEXTURE0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t0); } - switch(t_clampmode) + else { - case GR_TEXTURECLAMP_WRAP: - wrap_t0 = GL_REPEAT; - break; - case GR_TEXTURECLAMP_CLAMP: - wrap_t0 = GL_CLAMP_TO_EDGE; - break; - case GR_TEXTURECLAMP_MIRROR_EXT: - wrap_t0 = GL_MIRRORED_REPEAT; - break; - default: - WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown t_clampmode : %x", t_clampmode); + switch (s_clampmode) + { + case GR_TEXTURECLAMP_WRAP: + wrap_s1 = GL_REPEAT; + break; + case GR_TEXTURECLAMP_CLAMP: + wrap_s1 = GL_CLAMP_TO_EDGE; + break; + case GR_TEXTURECLAMP_MIRROR_EXT: + wrap_s1 = GL_MIRRORED_REPEAT; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown s_clampmode : %x", s_clampmode); + } + switch (t_clampmode) + { + case GR_TEXTURECLAMP_WRAP: + wrap_t1 = GL_REPEAT; + break; + case GR_TEXTURECLAMP_CLAMP: + wrap_t1 = GL_CLAMP_TO_EDGE; + break; + case GR_TEXTURECLAMP_MIRROR_EXT: + wrap_t1 = GL_MIRRORED_REPEAT; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown t_clampmode : %x", t_clampmode); + } + glActiveTexture(GL_TEXTURE1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t1); } - glActiveTexture(GL_TEXTURE0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t0); - } - else - { - switch(s_clampmode) - { - case GR_TEXTURECLAMP_WRAP: - wrap_s1 = GL_REPEAT; - break; - case GR_TEXTURECLAMP_CLAMP: - wrap_s1 = GL_CLAMP_TO_EDGE; - break; - case GR_TEXTURECLAMP_MIRROR_EXT: - wrap_s1 = GL_MIRRORED_REPEAT; - break; - default: - WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown s_clampmode : %x", s_clampmode); - } - switch(t_clampmode) - { - case GR_TEXTURECLAMP_WRAP: - wrap_t1 = GL_REPEAT; - break; - case GR_TEXTURECLAMP_CLAMP: - wrap_t1 = GL_CLAMP_TO_EDGE; - break; - case GR_TEXTURECLAMP_MIRROR_EXT: - wrap_t1 = GL_MIRRORED_REPEAT; - break; - default: - WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown t_clampmode : %x", t_clampmode); - } - glActiveTexture(GL_TEXTURE1); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s1); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t1); - } -} +} \ No newline at end of file diff --git a/Source/Project64-video/Renderer/OGLcombiner.cpp b/Source/Project64-video/Renderer/OGLcombiner.cpp index 8547f96f4..7baefbb0f 100644 --- a/Source/Project64-video/Renderer/OGLcombiner.cpp +++ b/Source/Project64-video/Renderer/OGLcombiner.cpp @@ -11,7 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ -#include +#include #ifdef _WIN32 #include diff --git a/Source/Project64-video/Renderer/OGLglitchmain.cpp b/Source/Project64-video/Renderer/OGLglitchmain.cpp index d4ce8760d..761e46d21 100644 --- a/Source/Project64-video/Renderer/OGLglitchmain.cpp +++ b/Source/Project64-video/Renderer/OGLglitchmain.cpp @@ -11,7 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ -#include +#include #define SAVE_CBUFFER @@ -281,7 +281,6 @@ typedef struct int buff_clear; } fb; -int nbTextureUnits; int nbAuxBuffers, current_buffer; int g_scr_res_x, g_width, widtho, heighto, g_scr_res_y, g_height; int g_res_x, g_res_y; @@ -2073,13 +2072,13 @@ grLfbWriteRegion(GrBuffer_t dst_buffer, glDrawPixels(src_width, src_height + (g_viewport_offset), GL_DEPTH_COMPONENT, GL_FLOAT, buf); free(buf); - } + } glDrawBuffer(current_buffer); glPopAttrib(); grDisplayGLError("grLfbWriteRegion"); return FXTRUE; - } +} /* wrapper-specific glide extensions */ @@ -2404,7 +2403,7 @@ grGetGammaTableExt(FxU32 /*nentries*/, FxU32 *red, FxU32 *green, FxU32 *blue) blue[i] = aGammaRamp[2][i] >> 8; } } - } +} FX_ENTRY void FX_CALL guGammaCorrectionRGB(FxFloat gammaR, FxFloat gammaG, FxFloat gammaB) @@ -2419,7 +2418,7 @@ guGammaCorrectionRGB(FxFloat gammaR, FxFloat gammaG, FxFloat gammaB) aGammaRamp[2][i] = (((FxU16)((pow(i / 255.0F, 1.0F / gammaB)) * 255.0F + 0.5F)) << 8) & 0xFFFF; } CorrectGamma(aGammaRamp); - } +} FX_ENTRY void FX_CALL grDitherMode(GrDitherMode_t /*mode*/) @@ -2550,7 +2549,7 @@ void dump_stop() ((unsigned char *)frameBuffer)[(i + j*width) * 3] = d & 0xff; ((unsigned char *)frameBuffer)[(i + j*width) * 3 + 1] = d >> 8; ((unsigned char *)frameBuffer)[(i + j*width) * 3 + 2] = c & 0xff; - } + } } ilTexImage(width, height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, frameBuffer); ilSaveImage("dump/framedepth.png"); diff --git a/Source/Project64-video/Renderer/Renderer.cpp b/Source/Project64-video/Renderer/Renderer.cpp new file mode 100644 index 000000000..c6d635540 --- /dev/null +++ b/Source/Project64-video/Renderer/Renderer.cpp @@ -0,0 +1,16 @@ +/*************************************************************************** +* * +* Project64-video - A Nintendo 64 gfx plugin. * +* http://www.pj64-emu.com/ * +* Copyright (C) 2017 Project64. All rights reserved. * +* Copyright (C) 2003-2009 Sergey 'Gonetz' Lipski * +* Copyright (C) 2002 Dave2001 * +* * +* License: * +* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html * +* version 2 of the License, or (at your option) any later version. * +* * +****************************************************************************/ +#include + +int32_t nbTextureUnits = 0; \ No newline at end of file diff --git a/Source/Project64-video/Renderer/Renderer.h b/Source/Project64-video/Renderer/Renderer.h new file mode 100644 index 000000000..5e49515dd --- /dev/null +++ b/Source/Project64-video/Renderer/Renderer.h @@ -0,0 +1,17 @@ +/*************************************************************************** +* * +* Project64-video - A Nintendo 64 gfx plugin. * +* http://www.pj64-emu.com/ * +* Copyright (C) 2017 Project64. All rights reserved. * +* Copyright (C) 2003-2009 Sergey 'Gonetz' Lipski * +* Copyright (C) 2002 Dave2001 * +* * +* License: * +* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html * +* version 2 of the License, or (at your option) any later version. * +* * +****************************************************************************/ +#pragma once +#include + +extern int32_t nbTextureUnits; diff --git a/Source/Project64-video/TexBuffer.cpp b/Source/Project64-video/TexBuffer.cpp index 986393af8..b13d74e96 100644 --- a/Source/Project64-video/TexBuffer.cpp +++ b/Source/Project64-video/TexBuffer.cpp @@ -11,6 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ +#include #include #include "Gfx_1.3.h" #include "TexBuffer.h" @@ -130,7 +131,7 @@ static TBUFF_COLOR_IMAGE * AllocateTextureBuffer(COLOR_IMAGE & cimage) uint32_t required = grTexCalcMemRequired(texbuf.info.smallLodLog2, texbuf.info.largeLodLog2, texbuf.info.aspectRatioLog2, texbuf.info.format); //find free space - for (int i = 0; i < voodoo.num_tmu; i++) + for (int i = 0; i < (nbTextureUnits > 2 ? 2 : 1); i++) { uint32_t available = 0; uint32_t top = 0; @@ -230,7 +231,7 @@ int OpenTextureBuffer(COLOR_IMAGE & cimage) } if (search) { - for (int i = 0; (i < voodoo.num_tmu) && !found; i++) + for (int i = 0; (i < (nbTextureUnits > 2 ? 2 : 1)) && !found; i++) { for (int j = 0; (j < rdp.texbufs[i].count) && !found; j++) { @@ -662,7 +663,7 @@ int FindTextureBuffer(uint32_t addr, uint16_t width) WriteTrace(TraceRDP, TraceDebug, "FindTextureBuffer. addr: %08lx, width: %d, scale_x: %f", addr, width, rdp.scale_x); int found = FALSE; uint32_t shift = 0; - for (int i = 0; i < voodoo.num_tmu && !found; i++) + for (int i = 0; i < (nbTextureUnits > 2 ? 2 : 1) && !found; i++) { uint8_t index = rdp.cur_tex_buf^i; for (int j = 0; j < rdp.texbufs[index].count && !found; j++) diff --git a/Source/Project64-video/TexCache.cpp b/Source/Project64-video/TexCache.cpp index bc49d7a0f..bdfb534e6 100644 --- a/Source/Project64-video/TexCache.cpp +++ b/Source/Project64-video/TexCache.cpp @@ -11,6 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ +#include #include "Gfx_1.3.h" #include "TexCache.h" @@ -37,7 +38,7 @@ uint8_t *texture_buffer = tex1; extern bool g_ghq_use; -typedef struct TEXINFO_t +typedef struct TEXINFO_t { int real_image_width, real_image_height; // FOR ALIGNMENT PURPOSES ONLY!!! int tile_width, tile_height; @@ -53,7 +54,7 @@ typedef struct TEXINFO_t TEXINFO texinfo[2]; int tex_found[2][MAX_TMU]; -typedef struct HIRESTEX_t +typedef struct HIRESTEX_t { int width, height; uint16_t format; @@ -474,8 +475,8 @@ int ChooseBestTmu(int tmu1, int tmu2) if (!GfxInitDone) return tmu1; if (voodoo.tex_UMA) return 0; - if (tmu1 >= voodoo.num_tmu) return tmu2; - if (tmu2 >= voodoo.num_tmu) return tmu1; + if (tmu1 >= (nbTextureUnits > 2 ? 2 : 1)) return tmu2; + if (tmu2 >= (nbTextureUnits > 2 ? 2 : 1)) return tmu1; if (voodoo.tex_max_addr[tmu1] - voodoo.tmem_ptr[tmu1] > voodoo.tex_max_addr[tmu2] - voodoo.tmem_ptr[tmu2]) @@ -655,7 +656,7 @@ void TexCache() // little change to make single-tmu cards look better, use first texture no matter what - if (voodoo.num_tmu == 1) + if ((nbTextureUnits > 2 ? 2 : 1) == 1) { if (rdp.best_tex == 0) { @@ -709,7 +710,7 @@ void TexCache() return; } - if (tmu_1 < voodoo.num_tmu) + if (tmu_1 < (nbTextureUnits > 2 ? 2 : 1)) { if (cmb.tex_cmb_ext_use) { @@ -737,7 +738,7 @@ void TexCache() grTexDetailControl(tmu_1, cmb.dc1_lodbias, cmb.dc1_detailscale, cmb.dc1_detailmax); grTexLodBiasValue(tmu_1, cmb.lodbias1); } - if (tmu_0 < voodoo.num_tmu) + if (tmu_0 < (nbTextureUnits > 2 ? 2 : 1)) { if (cmb.tex_cmb_ext_use) { @@ -767,7 +768,7 @@ void TexCache() } } - if ((rdp.tex & 1) && tmu_0 < voodoo.num_tmu) + if ((rdp.tex & 1) && tmu_0 < (nbTextureUnits > 2 ? 2 : 1)) { if (aTBuff[0] && aTBuff[0]->cache) { @@ -798,7 +799,7 @@ void TexCache() else LoadTex(0, tmu_0); } - if ((rdp.tex & 2) && tmu_1 < voodoo.num_tmu) + if ((rdp.tex & 2) && tmu_1 < (nbTextureUnits > 2 ? 2 : 1)) { if (aTBuff[1] && aTBuff[1]->cache) { @@ -840,7 +841,7 @@ void TexCache() { const int tmu = tmu_v[i]; - if (tmu >= voodoo.num_tmu) continue; + if (tmu >= (nbTextureUnits > 2 ? 2 : 1)) continue; int tile = rdp.cur_tile + i; @@ -1320,7 +1321,7 @@ void LoadTex(int id, int tmu) start_src >>= 1; result = load_table[rdp.tiles[td].size][rdp.tiles[td].format] - (uintptr_t(texture) + start_dst, uintptr_t(rdp.tmem) + (rdp.tiles[td].t_mem << 3) + start_src, + (uintptr_t(texture) + start_dst, uintptr_t(rdp.tmem) + (rdp.tiles[td].t_mem << 3) + start_src, texinfo[id].wid_64, texinfo[id].height, texinfo[id].line, real_x, td); uint32_t size = HIWORD(result); @@ -1337,7 +1338,7 @@ void LoadTex(int id, int tmu) else { result = load_table[rdp.tiles[td].size][rdp.tiles[td].format] - (uintptr_t(texture), uintptr_t(rdp.tmem) + (rdp.tiles[td].t_mem << 3), + (uintptr_t(texture), uintptr_t(rdp.tmem) + (rdp.tiles[td].t_mem << 3), texinfo[id].wid_64, texinfo[id].height, texinfo[id].line, real_x, td); uint32_t size = HIWORD(result); @@ -1369,25 +1370,25 @@ void LoadTex(int id, int tmu) { if (size == 1) Mirror16bS((texture), rdp.tiles[td].mask_s, - real_x, real_x, texinfo[id].height); + real_x, real_x, texinfo[id].height); else if (size != 2) Mirror8bS((texture), rdp.tiles[td].mask_s, - real_x, real_x, texinfo[id].height); + real_x, real_x, texinfo[id].height); else Mirror32bS((texture), rdp.tiles[td].mask_s, - real_x, real_x, texinfo[id].height); + real_x, real_x, texinfo[id].height); } else { if (size == 1) Wrap16bS((texture), rdp.tiles[td].mask_s, - real_x, real_x, texinfo[id].height); + real_x, real_x, texinfo[id].height); else if (size != 2) Wrap8bS((texture), rdp.tiles[td].mask_s, - real_x, real_x, texinfo[id].height); + real_x, real_x, texinfo[id].height); else Wrap32bS((texture), rdp.tiles[td].mask_s, - real_x, real_x, texinfo[id].height); + real_x, real_x, texinfo[id].height); } } @@ -1407,25 +1408,25 @@ void LoadTex(int id, int tmu) { if (size == 1) Mirror16bT((texture), rdp.tiles[td].mask_t, - real_y, real_x); + real_y, real_x); else if (size != 2) Mirror8bT((texture), rdp.tiles[td].mask_t, - real_y, real_x); + real_y, real_x); else Mirror32bT((texture), rdp.tiles[td].mask_t, - real_y, real_x); + real_y, real_x); } else { if (size == 1) Wrap16bT((texture), rdp.tiles[td].mask_t, - real_y, real_x); + real_y, real_x); else if (size != 2) Wrap8bT((texture), rdp.tiles[td].mask_t, - real_y, real_x); + real_y, real_x); else Wrap32bT((texture), rdp.tiles[td].mask_t, - real_y, real_x); + real_y, real_x); } } } diff --git a/Source/Project64-video/Util.cpp b/Source/Project64-video/Util.cpp index 891bf425d..494c39e89 100644 --- a/Source/Project64-video/Util.cpp +++ b/Source/Project64-video/Util.cpp @@ -11,6 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ +#include #include #include @@ -118,7 +119,7 @@ int cull_tri(VERTEX **v) // type changed to VERTEX** [Dave2001] { case 1: // cull front // if ((x1*y2 - y1*x2) < 0.0f) //counter-clockwise, positive - if ((y1*x2-x1*y2) < 0.0f) //counter-clockwise, positive + if ((y1*x2 - x1*y2) < 0.0f) //counter-clockwise, positive { WriteTrace(TraceRDP, TraceDebug, " culled!"); return TRUE; @@ -126,7 +127,7 @@ int cull_tri(VERTEX **v) // type changed to VERTEX** [Dave2001] return FALSE; case 2: // cull back // if ((x1*y2 - y1*x2) >= 0.0f) //clockwise, negative - if ((y1*x2-x1*y2) >= 0.0f) //clockwise, negative + if ((y1*x2 - x1*y2) >= 0.0f) //clockwise, negative { WriteTrace(TraceRDP, TraceDebug, " culled!"); return TRUE; @@ -284,7 +285,7 @@ void draw_tri(VERTEX **vtx, uint16_t linew) double diffz_02 = vtx[0]->sz - vtx[2]->sz; double diffz_12 = vtx[1]->sz - vtx[2]->sz; double fdzdx = (diffz_02 * diffy_12 - diffz_12 * diffy_02) / denom; - if ((rdp.rm & 0xC00) == 0xC00) + if ((rdp.rm & 0xC00) == 0xC00) { // Calculate deltaZ per polygon for Decal z-mode double fdzdy = (diffz_02 * diffx_12 - diffz_12 * diffx_02) / denom; @@ -781,7 +782,7 @@ void do_triangle_stuff(uint16_t linew, int old_interpolate) // what else?? do th if (!g_settings->clip_zmin()) { rdp.clip &= ~CLIP_ZMIN; - } + } if (!g_settings->clip_zmax()) { rdp.clip &= ~CLIP_ZMAX; @@ -926,21 +927,6 @@ static void InterpolateColors3(VERTEX &v1, VERTEX &v2, VERTEX &v3, VERTEX &out) static void CalculateLOD(VERTEX *v, int n) { - //rdp.update |= UPDATE_TEXTURE; - /* - if (rdp.lod_calculated) - { - float detailmax; - if (dc0_detailmax < 0.5) - detailmax = rdp.lod_fraction; - else - detailmax = 1.0f - rdp.lod_fraction; - grTexDetailControl (GR_TMU0, dc0_lodbias, dc0_detailscale, detailmax); - if (num_tmu == 2) - grTexDetailControl (GR_TMU1, dc1_lodbias, dc1_detailscale, detailmax); - return; - } - */ float deltaS, deltaT; float deltaX, deltaY; double deltaTexels, deltaPixels, lodFactor = 0; @@ -994,7 +980,7 @@ static void CalculateLOD(VERTEX *v, int n) else detailmax = 1.0f - lod_fraction; grTexDetailControl(GR_TMU0, cmb.dc0_lodbias, cmb.dc0_detailscale, detailmax); - if (voodoo.num_tmu == 2) + if ((nbTextureUnits > 2 ? 2 : 1) == 2) grTexDetailControl(GR_TMU1, cmb.dc1_lodbias, cmb.dc1_detailscale, detailmax); WriteTrace(TraceRDP, TraceDebug, "CalculateLOD factor: %f, tile: %d, lod_fraction: %f", (float)lodFactor, lod_tile, lod_fraction); } @@ -1852,7 +1838,7 @@ void update() } if (rdp.acmp == 3 && rdp.cycle_mode < 2) { - if (g_settings->old_style_adither() || rdp.alpha_dither_mode != 3) + if (g_settings->old_style_adither() || rdp.alpha_dither_mode != 3) { WriteTrace(TraceRDP, TraceDebug, " |- alpha compare: dither"); grStippleMode(g_settings->stipple_mode()); @@ -2002,4 +1988,4 @@ void set_message_combiner() GR_MIPMAPLEVELMASK_BOTH, &fontTex); grFogMode(GR_FOG_DISABLE); -} +} \ No newline at end of file diff --git a/Source/Project64-video/rdp.cpp b/Source/Project64-video/rdp.cpp index 38b8c8cba..3522cdcfc 100644 --- a/Source/Project64-video/rdp.cpp +++ b/Source/Project64-video/rdp.cpp @@ -11,6 +11,7 @@ * version 2 of the License, or (at your option) any later version. * * * ****************************************************************************/ +#include #include #include @@ -667,7 +668,7 @@ EXPORT void CALL ProcessDList(void) DisplayError("The GFX plugin caused an exception and has been disabled"); to_fullscreen = TRUE; return; - } + } #endif if (g_settings->fb_emulation_enabled()) @@ -696,7 +697,7 @@ EXPORT void CALL ProcessDList(void) CI_SET = FALSE; } WriteTrace(TraceRDP, TraceDebug, "ProcessDList end"); -} + } // undef - undefined instruction, always ignore void undef() @@ -1521,7 +1522,7 @@ void rdp_loadtlut() { //the buffer is definitely wrong, as there must be no CI frame buffers //find and remove it - for (int i = 0; i < voodoo.num_tmu; i++) + for (int i = 0; i < (nbTextureUnits > 2 ? 2 : 1); i++) { for (int j = 0; j < rdp.texbufs[i].count; j++) { @@ -3328,7 +3329,7 @@ void DetectFrameBufferUsage() if (g_settings->fb_hwfbe_enabled()) { - for (i = 0; i < voodoo.num_tmu; i++) + for (i = 0; i < (nbTextureUnits > 2 ? 2 : 1); i++) { rdp.texbufs[i].clear_allowed = TRUE; for (int j = 0; j < 256; j++) diff --git a/Source/Project64-video/rdp.h b/Source/Project64-video/rdp.h index 619938067..2395c6f51 100644 --- a/Source/Project64-video/rdp.h +++ b/Source/Project64-video/rdp.h @@ -133,7 +133,7 @@ typedef struct } VERTEX; // Clipping (scissors) -typedef struct +typedef struct { uint32_t ul_x; uint32_t ul_y; @@ -153,7 +153,6 @@ typedef struct { typedef struct { - int num_tmu; int max_tex_size; int sup_large_tex; int sup_mirroring;