diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index ea928c1ff..412348855 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -1292,35 +1292,33 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp pth->skyface = facen; pth->hicr = hicr; - if (glinfo.texcompr && glusetexcompr && glusetexcache && !(hicr->flags & HICR_NOSAVE)) - if (!gotcache) + if (!gotcache && glinfo.texcompr && glusetexcompr && glusetexcache && !(hicr->flags & HICR_NOSAVE)) + { + const int32_t nonpow2 = check_nonpow2(siz.x) || check_nonpow2(siz.y); + + // save off the compressed version + cachead.quality = (hicr->flags & HICR_NOCOMPRESS) ? 0 : r_downsize; + cachead.xdim = tsiz.x >> cachead.quality; + cachead.ydim = tsiz.y >> cachead.quality; + + // handle nocompress: + cachead.flags = nonpow2 * CACHEAD_NONPOW2 | (hasalpha != 255 ? CACHEAD_HASALPHA : 0) | + (hicr->flags & HICR_NOCOMPRESS ? CACHEAD_NOCOMPRESS : 0); + + /// OSD_Printf("Caching \"%s\"\n", fn); + texcache_writetex(fn, picfillen + (dapalnum << 8), dameth, effect, &cachead); + + if (willprint) { - const int32_t nonpow2 = check_nonpow2(siz.x) || check_nonpow2(siz.y); - - // save off the compressed version - cachead.quality = (hicr->flags & HICR_NOCOMPRESS) ? 0 : r_downsize; - cachead.xdim = tsiz.x>>cachead.quality; - cachead.ydim = tsiz.y>>cachead.quality; - - // handle nocompress: - cachead.flags = nonpow2*CACHEAD_NONPOW2 | - (hasalpha != 255 ? CACHEAD_HASALPHA : 0) | - (hicr->flags & HICR_NOCOMPRESS ? CACHEAD_NOCOMPRESS : 0); - -/// OSD_Printf("Caching \"%s\"\n", fn); - texcache_writetex(fn, picfillen+(dapalnum<<8), dameth, effect, &cachead); - - if (willprint) - { - int32_t etime = getticks()-startticks; - if (etime>=MIN_CACHETIME_PRINT) - OSD_Printf("Load tile %4d: p%d-m%d-e%d %s... cached... %d ms\n", dapic, dapalnum, dameth, effect, - willprint==2 ? fn : "", etime); - willprint = 0; - } - else - OSD_Printf("Cached \"%s\"\n", fn); + int32_t etime = getticks() - startticks; + if (etime >= MIN_CACHETIME_PRINT) + OSD_Printf("Load tile %4d: p%d-m%d-e%d %s... cached... %d ms\n", dapic, dapalnum, dameth, effect, + willprint == 2 ? fn : "", etime); + willprint = 0; } + else + OSD_Printf("Cached \"%s\"\n", fn); + } if (willprint) { diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 7bffc3235..5fd927b5b 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -1143,8 +1143,6 @@ static void destroy_window_resources() #ifdef USE_OPENGL void sdlayer_setvideomode_opengl(void) { - char *p; - polymost_glreset(); bglEnable(GL_TEXTURE_2D); @@ -1192,31 +1190,32 @@ void sdlayer_setvideomode_opengl(void) glinfo.texcompr = 0; // process the extensions string and flag stuff we recognize - p = Bstrdup(glinfo.extensions); + glinfo.clamptoedge = !!Bstrstr(glinfo.extensions, "GL_EXT_texture_edge_clamp") || + !!Bstrstr(glinfo.extensions, "GL_SGIS_texture_edge_clamp"); + glinfo.bgra = !!Bstrstr(glinfo.extensions, "GL_EXT_bgra"); + glinfo.texcompr = + !!Bstrstr(glinfo.extensions, "GL_ARB_texture_compression") && Bstrcmp(glinfo.vendor, "ATI Technologies Inc."); + glinfo.texnpot = !!Bstrstr(glinfo.extensions, "GL_ARB_texture_non_power_of_two"); + glinfo.multisample = !!Bstrstr(glinfo.extensions, "GL_ARB_multisample"); + glinfo.nvmultisamplehint = !!Bstrstr(glinfo.extensions, "GL_NV_multisample_filter_hint"); + glinfo.arbfp = !!Bstrstr(glinfo.extensions, "GL_ARB_fragment_program"); + glinfo.depthtex = !!Bstrstr(glinfo.extensions, "GL_ARB_depth_texture"); + glinfo.shadow = !!Bstrstr(glinfo.extensions, "GL_ARB_shadow"); + glinfo.fbos = !!Bstrstr(glinfo.extensions, "GL_EXT_framebuffer_object"); + glinfo.rect = + !!Bstrstr(glinfo.extensions, "GL_NV_texture_rectangle") || !!Bstrstr(glinfo.extensions, "GL_EXT_texture_rectangle"); + glinfo.multitex = !!Bstrstr(glinfo.extensions, "GL_ARB_multitexture"); + glinfo.envcombine = !!Bstrstr(glinfo.extensions, "GL_ARB_texture_env_combine"); + glinfo.vbos = !!Bstrstr(glinfo.extensions, "GL_ARB_vertex_buffer_object"); + glinfo.sm4 = !!Bstrstr(glinfo.extensions, "GL_EXT_gpu_shader4"); + glinfo.occlusionqueries = !!Bstrstr(glinfo.extensions, "GL_ARB_occlusion_query"); + glinfo.glsl = !!Bstrstr(glinfo.extensions, "GL_ARB_shader_objects"); + glinfo.debugoutput = !!Bstrstr(glinfo.extensions, "GL_ARB_debug_output"); - glinfo.clamptoedge = !!Bstrstr(p, "GL_EXT_texture_edge_clamp") || !!Bstrstr(p, "GL_SGIS_texture_edge_clamp"); - glinfo.bgra = !!Bstrstr(p, "GL_EXT_bgra"); - glinfo.texcompr = !!Bstrstr(p, "GL_ARB_texture_compression") && Bstrcmp(glinfo.vendor, "ATI Technologies Inc."); - glinfo.texnpot = !!Bstrstr(p, "GL_ARB_texture_non_power_of_two"); - glinfo.multisample = !!Bstrstr(p, "GL_ARB_multisample"); - glinfo.nvmultisamplehint = !!Bstrstr(p, "GL_NV_multisample_filter_hint"); - glinfo.arbfp = !!Bstrstr(p, "GL_ARB_fragment_program"); - glinfo.depthtex = !!Bstrstr(p, "GL_ARB_depth_texture"); - glinfo.shadow = !!Bstrstr(p, "GL_ARB_shadow"); - glinfo.fbos = !!Bstrstr(p, "GL_EXT_framebuffer_object"); - glinfo.rect = !!Bstrstr(p, "GL_NV_texture_rectangle") || !!Bstrstr(p, "GL_EXT_texture_rectangle"); - glinfo.multitex = !!Bstrstr(p, "GL_ARB_multitexture"); - glinfo.envcombine = !!Bstrstr(p, "GL_ARB_texture_env_combine"); - glinfo.vbos = !!Bstrstr(p, "GL_ARB_vertex_buffer_object"); - glinfo.sm4 = !!Bstrstr(p, "GL_EXT_gpu_shader4"); - glinfo.occlusionqueries = !!Bstrstr(p, "GL_ARB_occlusion_query"); - glinfo.glsl = !!Bstrstr(p, "GL_ARB_shader_objects"); - glinfo.debugoutput = !!Bstrstr(p, "GL_ARB_debug_output"); - - if (Bstrstr(p, "GL_EXT_texture_filter_anisotropic")) + if (Bstrstr(glinfo.extensions, "GL_EXT_texture_filter_anisotropic")) bglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glinfo.maxanisotropy); - if (Bstrstr(p, "WGL_3DFX_gamma_control")) + if (Bstrstr(glinfo.extensions, "WGL_3DFX_gamma_control")) { static int32_t warnonce; // 3dfx cards have issues with fog @@ -1650,13 +1649,10 @@ int32_t setgamma(void) #if !defined(__APPLE__) && !defined(__ANDROID__) extern struct sdlappicon sdlappicon; -static SDL_Surface *loadappicon(void) +static inline SDL_Surface *loadappicon(void) { - SDL_Surface *surf; - - surf = SDL_CreateRGBSurfaceFrom((void *)sdlappicon.pixels, sdlappicon.width, sdlappicon.height, 32, - sdlappicon.width * 4, 0xffl, 0xff00l, 0xff0000l, 0xff000000l); - + SDL_Surface *surf = SDL_CreateRGBSurfaceFrom((void *)sdlappicon.pixels, sdlappicon.width, sdlappicon.height, 32, + sdlappicon.width * 4, 0xffl, 0xff00l, 0xff0000l, 0xff000000l); return surf; } #endif diff --git a/polymer/eduke32/build/src/texcache.c b/polymer/eduke32/build/src/texcache.c index 9dd2a7b54..2855c8e8b 100644 --- a/polymer/eduke32/build/src/texcache.c +++ b/polymer/eduke32/build/src/texcache.c @@ -95,7 +95,7 @@ pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int3 int32_t tilestat; pthtyp *pth; - const int32_t j = dapicnum&(GLTEXCACHEADSIZ-1); + const int32_t j = dapicnum & (GLTEXCACHEADSIZ - 1); hicreplctyp *si = usehightile ? hicfindsubst(dapicnum, dapalnum) : NULL; if (drawingskybox && usehightile) @@ -107,8 +107,8 @@ pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int3 if (!si) { - if (dapalnum >= (MAXPALOOKUPS - RESERVEDPALS)) return NULL; - return hicprecaching ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); + return (dapalnum >= (MAXPALOOKUPS - RESERVEDPALS) || hicprecaching) ? + NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); } /* if palette > 0 && replacement found @@ -118,57 +118,56 @@ pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int3 */ // load a replacement - for (pth=texcache.list[j]; pth; pth=pth->next) + for (pth = texcache.list[j]; pth; pth = pth->next) { if (pth->picnum == dapicnum && pth->palnum == si->palnum && - (si->palnum>0 ? 1 : (pth->effects == hictinting[dapalnum].f)) && - (pth->flags & (PTH_CLAMPED + PTH_HIGHTILE + PTH_SKYBOX)) - == (TO_PTH_CLAMPED(dameth) + PTH_HIGHTILE + (drawingskybox>0)*PTH_SKYBOX) && - (drawingskybox>0 ? (pth->skyface == drawingskybox) : 1) - ) + (si->palnum > 0 ? 1 : (pth->effects == hictinting[dapalnum].f)) && + (pth->flags & (PTH_CLAMPED + PTH_HIGHTILE + PTH_SKYBOX)) == + (TO_PTH_CLAMPED(dameth) + PTH_HIGHTILE + (drawingskybox > 0) * PTH_SKYBOX) && + (drawingskybox > 0 ? (pth->skyface == drawingskybox) : 1)) { if (pth->flags & PTH_INVALIDATED) { pth->flags &= ~PTH_INVALIDATED; tilestat = gloadtile_hi(dapicnum, dapalnum, drawingskybox, si, dameth, pth, 0, - (si->palnum>0) ? 0 : hictinting[dapalnum].f); // reload tile + (si->palnum > 0) ? 0 : hictinting[dapalnum].f); // reload tile - if (tilestat) - { - if (tilestat == -2) // bad filename - hicclearsubst(dapicnum, dapalnum); - if (drawingskybox) return NULL; - return hicprecaching ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); - } + if (!tilestat) + continue; + + if (tilestat == -2) // bad filename + hicclearsubst(dapicnum, dapalnum); + return (drawingskybox || hicprecaching) ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); } - return(pth); + return (pth); } } - pth = (pthtyp *)Xcalloc(1,sizeof(pthtyp)); + pth = (pthtyp *)Xcalloc(1, sizeof(pthtyp)); // possibly fetch an already loaded multitexture :_) if (dapalnum >= (MAXPALOOKUPS - RESERVEDPALS) && texcache_fetchmulti(pth, si, dapicnum, dameth)) return pth; - tilestat = gloadtile_hi(dapicnum, dapalnum, drawingskybox, si, dameth, pth, 1, (si->palnum>0) ? 0 : hictinting[dapalnum].f); + tilestat = + gloadtile_hi(dapicnum, dapalnum, drawingskybox, si, dameth, pth, 1, (si->palnum > 0) ? 0 : hictinting[dapalnum].f); - if (tilestat) + if (!tilestat) { - if (tilestat == -2) // bad filename - hicclearsubst(dapicnum, dapalnum); - Bfree(pth); - if (drawingskybox) return NULL; - return hicprecaching ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); + pth->next = texcache.list[j]; + pth->palnum = si->palnum; + texcache.list[j] = pth; + return pth; } - pth->palnum = si->palnum; - pth->next = texcache.list[j]; - texcache.list[j] = pth; + if (tilestat == -2) // bad filename + hicclearsubst(dapicnum, dapalnum); - return(pth); + Bfree(pth); + + return (drawingskybox || hicprecaching) ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); } static void texcache_closefiles(void) @@ -183,25 +182,25 @@ static void texcache_closefiles(void) void texcache_freeptrs(void) { - int32_t i; + texcache.iptrcnt = 0; - if (texcache.iptrs) - for (i = 0; i < texcache.numentries; i++) + if (!texcache.iptrs) + return; + + for (int i = 0; i < texcache.numentries; i++) if (texcache.iptrs[i]) { - int32_t ii; - for (ii = texcache.numentries-1; ii >= 0; ii--) + for (int ii = texcache.numentries - 1; ii >= 0; ii--) if (i != ii && texcache.iptrs[ii] == texcache.iptrs[i]) { /*OSD_Printf("removing duplicate cacheptr %d\n",ii);*/ texcache.iptrs[ii] = NULL; } - Bfree(texcache.iptrs[i]); - texcache.iptrs[i] = NULL; + Bfree(texcache.iptrs[i]); + texcache.iptrs[i] = NULL; } - texcache.iptrcnt = 0; DO_FREE_AND_NULL(texcache.iptrs); }