From b259368b37e27e61b1afc2bd5608a61cd4657bc2 Mon Sep 17 00:00:00 2001 From: Jaime Ita Passos Date: Fri, 11 Dec 2020 01:06:45 -0300 Subject: [PATCH] Refactoring --- src/hardware/hw_batching.c | 36 +- src/hardware/hw_batching.h | 12 +- src/hardware/hw_cache.c | 413 ++++++------ src/hardware/hw_data.h | 47 +- src/hardware/hw_defs.h | 289 ++++----- src/hardware/hw_draw.c | 6 +- src/hardware/hw_drv.h | 28 +- src/hardware/hw_glob.h | 7 +- src/hardware/hw_light.c | 22 +- src/hardware/hw_main.c | 159 +++-- src/hardware/hw_main.h | 10 +- src/hardware/hw_md2.c | 131 ++-- src/hardware/r_opengl/ogl_win.c | 39 +- src/hardware/r_opengl/r_opengl.c | 1030 +++++++++++++----------------- src/hardware/r_opengl/r_opengl.h | 28 +- src/p_setup.c | 5 +- src/p_setup.h | 2 +- src/r_patch.c | 6 +- src/sdl/hwsym_sdl.c | 5 +- src/sdl/i_video.c | 8 +- src/sdl/ogl_sdl.c | 33 +- src/win32/win_dll.c | 10 +- src/z_zone.c | 2 +- src/z_zone.h | 2 +- 24 files changed, 1069 insertions(+), 1261 deletions(-) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index fb3417158..d572145bf 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -16,7 +16,7 @@ // The texture for the next polygon given to HWR_ProcessPolygon. // Set with HWR_SetCurrentTexture. -GLMipmap_t *current_texture = NULL; +HWRTexture_t *current_texture = NULL; boolean currently_batching = false; @@ -61,7 +61,7 @@ void HWR_StartBatching(void) // This replaces the direct calls to pfnSetTexture in cases where batching is available. // The texture selection is saved for the next HWR_ProcessPolygon call. // Doing this was easier than getting a texture pointer to HWR_ProcessPolygon. -void HWR_SetCurrentTexture(GLMipmap_t *texture) +void HWR_SetCurrentTexture(HWRTexture_t *texture) { if (currently_batching) { @@ -76,7 +76,7 @@ void HWR_SetCurrentTexture(GLMipmap_t *texture) // If batching is enabled, this function collects the polygon data and the chosen texture // for later use in HWR_RenderBatches. Otherwise the rendering backend is used to // render the polygon immediately. -void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial) +void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, UINT32 iNumPts, UINT32 PolyFlags, int shader, boolean horizonSpecial) { if (currently_batching) { @@ -165,11 +165,11 @@ static int comparePolygons(const void *p1, const void *p2) diff64 = poly1->surf.FadeColor.rgba - poly2->surf.FadeColor.rgba; if (diff64 < 0) return -1; else if (diff64 > 0) return 1; - diff = poly1->surf.LightInfo.light_level - poly2->surf.LightInfo.light_level; + diff = poly1->surf.LightInfo.LightLevel - poly2->surf.LightInfo.LightLevel; if (diff != 0) return diff; - diff = poly1->surf.LightInfo.fade_start - poly2->surf.LightInfo.fade_start; + diff = poly1->surf.LightInfo.FadeStart - poly2->surf.LightInfo.FadeStart; if (diff != 0) return diff; - diff = poly1->surf.LightInfo.fade_end - poly2->surf.LightInfo.fade_end; + diff = poly1->surf.LightInfo.FadeEnd - poly2->surf.LightInfo.FadeEnd; return diff; } @@ -182,8 +182,8 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) int diff; INT64 diff64; - GLMipmap_t *texture1 = poly1->texture; - GLMipmap_t *texture2 = poly2->texture; + HWRTexture_t *texture1 = poly1->texture; + HWRTexture_t *texture2 = poly2->texture; if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) texture1 = NULL; if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial) @@ -215,10 +215,10 @@ void HWR_RenderBatches(void) int currentShader; int nextShader = 0; - GLMipmap_t *currentTexture; - GLMipmap_t *nextTexture = NULL; - FBITFIELD currentPolyFlags = 0; - FBITFIELD nextPolyFlags = 0; + HWRTexture_t *currentTexture; + HWRTexture_t *nextTexture = NULL; + UINT32 currentPolyFlags = 0; + UINT32 nextPolyFlags = 0; FSurfaceInfo currentSurfaceInfo; FSurfaceInfo nextSurfaceInfo; @@ -227,9 +227,9 @@ void HWR_RenderBatches(void) if (!currently_batching) I_Error("HWR_RenderBatches called without starting batching"); - nextSurfaceInfo.LightInfo.fade_end = 0; - nextSurfaceInfo.LightInfo.fade_start = 0; - nextSurfaceInfo.LightInfo.light_level = 0; + nextSurfaceInfo.LightInfo.FadeEnd = 0; + nextSurfaceInfo.LightInfo.FadeStart = 0; + nextSurfaceInfo.LightInfo.LightLevel = 0; currently_batching = false;// no longer collecting batches if (!polygonArraySize) @@ -374,9 +374,9 @@ void HWR_RenderBatches(void) if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba || - currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level || - currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start || - currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end) + currentSurfaceInfo.LightInfo.LightLevel != nextSurfaceInfo.LightInfo.LightLevel || + currentSurfaceInfo.LightInfo.FadeStart != nextSurfaceInfo.LightInfo.FadeStart || + currentSurfaceInfo.LightInfo.FadeEnd != nextSurfaceInfo.LightInfo.FadeEnd) { changeState = true; changeSurfaceInfo = true; diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index 3d22324ac..60a93995a 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -16,21 +16,21 @@ #include "hw_data.h" #include "hw_drv.h" -typedef struct +typedef struct { FSurfaceInfo surf;// surf also has its own polyflags for some reason, but it seems unused unsigned int vertsIndex;// location of verts in unsortedVertexArray - FUINT numVerts; - FBITFIELD polyFlags; - GLMipmap_t *texture; + UINT32 numVerts; + UINT32 polyFlags; + HWRTexture_t *texture; int shader; // this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls boolean horizonSpecial; } PolygonArrayEntry; void HWR_StartBatching(void); -void HWR_SetCurrentTexture(GLMipmap_t *texture); -void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial); +void HWR_SetCurrentTexture(HWRTexture_t *texture); +void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, UINT32 iNumPts, UINT32 PolyFlags, int shader, boolean horizonSpecial); void HWR_RenderBatches(void); #endif diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index b4fa7ec6c..7280b0744 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -29,14 +29,14 @@ #include "../r_picformats.h" #include "../p_setup.h" -INT32 patchformat = GL_TEXFMT_AP_88; // use alpha for holes -INT32 textureformat = GL_TEXFMT_P_8; // use chromakey for hole +INT32 gl_patchformat = GPU_TEXFMT_AP_88; // use alpha for holes +INT32 gl_textureformat = GPU_TEXFMT_P_8; // use chromakey for hole static INT32 format2bpp(GLTextureFormat_t format) { - if (format == GL_TEXFMT_RGBA) + if (format == GPU_TEXFMT_RGBA) return 4; - else if (format == GL_TEXFMT_ALPHA_INTENSITY_88 || format == GL_TEXFMT_AP_88) + else if (format == GPU_TEXFMT_ALPHA_INTENSITY_88 || format == GPU_TEXFMT_AP_88) return 2; else return 1; @@ -45,7 +45,7 @@ static INT32 format2bpp(GLTextureFormat_t format) // This code was originally placed directly in HWR_DrawPatchInCache. // It is now split from it for my sanity! (and the sanity of others) // -- Monster Iestyn (13/02/19) -static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipmap_t *mipmap, +static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, HWRTexture_t *texture, INT32 pblockheight, INT32 blockmodulo, fixed_t yfracstep, fixed_t scale_y, texpatch_t *originPatch, INT32 patchheight, @@ -103,12 +103,12 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm texel = source[yfrac>>FRACBITS]; alpha = 0xFF; // Make pixel transparent if chroma keyed - if ((mipmap->flags & TF_CHROMAKEYED) && (texel == HWR_PATCHES_CHROMAKEY_COLORINDEX)) + if ((texture->flags & TF_CHROMAKEYED) && (texel == GPU_PATCHES_CHROMAKEY_COLORINDEX)) alpha = 0x00; //Hurdler: 25/04/2000: now support colormap in hardware mode - if (mipmap->colormap) - texel = mipmap->colormap[texel]; + if (texture->colormap) + texel = texture->colormap[texel]; // hope compiler will get this switch out of the loops (dreams...) // gcc do it ! but vcc not ! (why don't use cygwin gcc for win32 ?) @@ -156,7 +156,7 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm } } -static void HWR_DrawFlippedColumnInCache(const column_t *patchcol, UINT8 *block, GLMipmap_t *mipmap, +static void HWR_DrawFlippedColumnInCache(const column_t *patchcol, UINT8 *block, HWRTexture_t *texture, INT32 pblockheight, INT32 blockmodulo, fixed_t yfracstep, fixed_t scale_y, texpatch_t *originPatch, INT32 patchheight, @@ -213,12 +213,12 @@ static void HWR_DrawFlippedColumnInCache(const column_t *patchcol, UINT8 *block, texel = source[yfrac>>FRACBITS]; alpha = 0xFF; // Make pixel transparent if chroma keyed - if ((mipmap->flags & TF_CHROMAKEYED) && (texel == HWR_PATCHES_CHROMAKEY_COLORINDEX)) + if ((texture->flags & TF_CHROMAKEYED) && (texel == GPU_PATCHES_CHROMAKEY_COLORINDEX)) alpha = 0x00; //Hurdler: 25/04/2000: now support colormap in hardware mode - if (mipmap->colormap) - texel = mipmap->colormap[texel]; + if (texture->colormap) + texel = texture->colormap[texel]; // hope compiler will get this switch out of the loops (dreams...) // gcc do it ! but vcc not ! (why don't use cygwin gcc for win32 ?) @@ -272,7 +272,7 @@ static void HWR_DrawFlippedColumnInCache(const column_t *patchcol, UINT8 *block, // no alpha or flipping should be present since we do not want non-texture graphics to have them // no offsets are used either // -- Monster Iestyn (13/02/19) -static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, +static void HWR_DrawPatchInCache(HWRTexture_t *texture, INT32 pblockwidth, INT32 pblockheight, INT32 pwidth, INT32 pheight, const patch_t *realpatch) @@ -281,7 +281,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, fixed_t xfrac, xfracstep; fixed_t yfracstep, scale_y; const column_t *patchcol; - UINT8 *block = mipmap->data; + UINT8 *block = texture->data; INT32 bpp; INT32 blockmodulo; @@ -296,7 +296,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, yfracstep = FRACUNIT; scale_y = FRACUNIT; - bpp = format2bpp(mipmap->format); + bpp = format2bpp(texture->format); if (bpp < 1 || bpp > 4) I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp); @@ -309,7 +309,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, { patchcol = (const column_t *)((const UINT8 *)realpatch->columns + (realpatch->columnofs[xfrac>>FRACBITS])); - HWR_DrawColumnInCache(patchcol, block, mipmap, + HWR_DrawColumnInCache(patchcol, block, texture, pblockheight, blockmodulo, yfracstep, scale_y, NULL, pheight, // not that pheight is going to get used anyway... @@ -318,7 +318,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, } // This function we use for caching patches that belong to textures -static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, +static void HWR_DrawTexturePatchInCache(HWRTexture_t *hwrTexture, INT32 pblockwidth, INT32 pblockheight, texture_t *texture, texpatch_t *patch, const softwarepatch_t *realpatch) @@ -328,12 +328,12 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, fixed_t xfrac, xfracstep; fixed_t yfracstep, scale_y; const column_t *patchcol; - UINT8 *block = mipmap->data; + UINT8 *block = hwrTexture->data; INT32 bpp; INT32 blockmodulo; INT32 width, height; // Column drawing function pointer. - static void (*ColumnDrawerPointer)(const column_t *patchcol, UINT8 *block, GLMipmap_t *mipmap, + static void (*ColumnDrawerPointer)(const column_t *patchcol, UINT8 *block, HWRTexture_t *texture, INT32 pblockheight, INT32 blockmodulo, fixed_t yfracstep, fixed_t scale_y, texpatch_t *originPatch, INT32 patchheight, @@ -389,7 +389,7 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, yfracstep = (texture->height<< FRACBITS) / pblockheight; scale_y = (pblockheight << FRACBITS) / texture->height; - bpp = format2bpp(mipmap->format); + bpp = format2bpp(hwrTexture->format); if (bpp < 1 || bpp > 4) I_Error("HWR_DrawTexturePatchInCache: no drawer defined for this bpp (%d)\n",bpp); @@ -405,7 +405,7 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, else patchcol = (const column_t *)((const UINT8 *)realpatch + LONG(realpatch->columnofs[xfrac>>FRACBITS])); - ColumnDrawerPointer(patchcol, block, mipmap, + ColumnDrawerPointer(patchcol, block, hwrTexture, pblockheight, blockmodulo, yfracstep, scale_y, patch, height, @@ -413,19 +413,19 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, } } -static UINT8 *MakeBlock(GLMipmap_t *grMipmap) +static UINT8 *MakeBlock(HWRTexture_t *hwrTexture) { UINT8 *block; INT32 bpp, i; - UINT16 bu16 = ((0x00 <<8) | HWR_PATCHES_CHROMAKEY_COLORINDEX); - INT32 blocksize = (grMipmap->width * grMipmap->height); + UINT16 bu16 = ((0x00 <<8) | GPU_PATCHES_CHROMAKEY_COLORINDEX); + INT32 blocksize = (hwrTexture->width * hwrTexture->height); - bpp = format2bpp(grMipmap->format); - block = Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(grMipmap->data)); + bpp = format2bpp(hwrTexture->format); + block = Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(hwrTexture->data)); switch (bpp) { - case 1: memset(block, HWR_PATCHES_CHROMAKEY_COLORINDEX, blocksize); break; + case 1: memset(block, GPU_PATCHES_CHROMAKEY_COLORINDEX, blocksize); break; case 2: // fill background with chromakey, alpha = 0 for (i = 0; i < blocksize; i++) @@ -465,26 +465,26 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex) ) { skyspecial = true; - grtex->mipmap.flags = TF_WRAPXY; // don't use the chromakey for sky + grtex->texture.flags = TF_WRAPXY; // don't use the chromakey for sky } else - grtex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY; + grtex->texture.flags = TF_CHROMAKEYED | TF_WRAPXY; - grtex->mipmap.width = (UINT16)texture->width; - grtex->mipmap.height = (UINT16)texture->height; - grtex->mipmap.format = textureformat; + grtex->texture.width = (UINT16)texture->width; + grtex->texture.height = (UINT16)texture->height; + grtex->texture.format = gl_textureformat; blockwidth = texture->width; blockheight = texture->height; blocksize = (blockwidth * blockheight); - block = MakeBlock(&grtex->mipmap); + block = MakeBlock(&grtex->texture); if (skyspecial) //Hurdler: not efficient, but better than holes in the sky (and it's done only at level loading) { INT32 j; RGBA_t col; - col = V_GetColor(HWR_PATCHES_CHROMAKEY_COLORINDEX); + col = V_GetColor(GPU_PATCHES_CHROMAKEY_COLORINDEX); for (j = 0; j < blockheight; j++) { for (i = 0; i < blockwidth; i++) @@ -520,19 +520,19 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex) dealloc = false; } - HWR_DrawTexturePatchInCache(&grtex->mipmap, blockwidth, blockheight, texture, patch, realpatch); + HWR_DrawTexturePatchInCache(&grtex->texture, blockwidth, blockheight, texture, patch, realpatch); if (dealloc) Z_Unlock(realpatch); } //Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :( - if (format2bpp(grtex->mipmap.format)==4) + if (format2bpp(grtex->texture.format)==4) { for (i = 3; i < blocksize*4; i += 4) // blocksize*4 because blocksize doesn't include the bpp { if (block[i] == 0) { - grtex->mipmap.flags |= TF_TRANSPARENT; + grtex->texture.flags |= TF_TRANSPARENT; break; } } @@ -542,34 +542,34 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex) grtex->scaleY = 1.0f/(texture->height*FRACUNIT); } -// patch may be NULL if grMipmap has been initialised already and makebitmap is false -void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap) +// patch may be NULL if hwrTexture has been initialised already and makebitmap is false +void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, HWRTexture_t *hwrTexture, boolean makebitmap) { - if (grMipmap->width == 0) + if (hwrTexture->width == 0) { - grMipmap->width = grMipmap->height = 1; - while (grMipmap->width < patch->width) grMipmap->width <<= 1; - while (grMipmap->height < patch->height) grMipmap->height <<= 1; + hwrTexture->width = hwrTexture->height = 1; + while (hwrTexture->width < patch->width) hwrTexture->width <<= 1; + while (hwrTexture->height < patch->height) hwrTexture->height <<= 1; // no wrap around, no chroma key - grMipmap->flags = 0; + hwrTexture->flags = 0; // setup the texture info - grMipmap->format = patchformat; + hwrTexture->format = gl_patchformat; - grPatch->max_s = (float)patch->width / (float)grMipmap->width; - grPatch->max_t = (float)patch->height / (float)grMipmap->height; + grPatch->max_s = (float)patch->width / (float)hwrTexture->width; + grPatch->max_t = (float)patch->height / (float)hwrTexture->height; } - Z_Free(grMipmap->data); - grMipmap->data = NULL; + Z_Free(hwrTexture->data); + hwrTexture->data = NULL; if (makebitmap) { - MakeBlock(grMipmap); + MakeBlock(hwrTexture); - HWR_DrawPatchInCache(grMipmap, - grMipmap->width, grMipmap->height, + HWR_DrawPatchInCache(hwrTexture, + hwrTexture->width, hwrTexture->height, patch->width, patch->height, patch); } @@ -585,21 +585,6 @@ static GLMapTexture_t *gl_textures; // For all textures static GLMapTexture_t *gl_flats; // For all (texture) flats, as normal flats don't need to be cached boolean gl_maptexturesloaded = false; -void HWR_FreeTextureData(patch_t *patch) -{ - GLPatch_t *grPatch; - - if (!patch || !patch->hardware) - return; - - grPatch = patch->hardware; - - if (vid.glstate == VID_GL_LIBRARY_LOADED) - HWD.pfnDeleteTexture(grPatch->mipmap); - if (grPatch->mipmap->data) - Z_Free(grPatch->mipmap->data); -} - void HWR_FreeTexture(patch_t *patch) { if (!patch) @@ -611,10 +596,13 @@ void HWR_FreeTexture(patch_t *patch) HWR_FreeTextureColormaps(patch); - if (grPatch->mipmap) + if (grPatch->texture) { - HWR_FreeTextureData(patch); - Z_Free(grPatch->mipmap); + if (vid.glstate == VID_GL_LIBRARY_LOADED) + HWD.pfnDeleteTexture(grPatch->texture); + if (grPatch->texture->data) + Z_Free(grPatch->texture->data); + Z_Free(grPatch->texture); } Z_Free(patch->hardware); @@ -623,7 +611,7 @@ void HWR_FreeTexture(patch_t *patch) patch->hardware = NULL; } -// Called by HWR_FreePatchCache. +// Called by FreeTextureCache. void HWR_FreeTextureColormaps(patch_t *patch) { GLPatch_t *pat; @@ -636,59 +624,74 @@ void HWR_FreeTextureColormaps(patch_t *patch) if (!pat) return; - // The mipmap must be valid, obviously - while (pat->mipmap) + // The texture must be valid, obviously + while (pat->texture) { - // Confusing at first, but pat->mipmap->nextcolormap + // Confusing at first, but pat->texture->nextcolormap // at the beginning of the loop is the first colormap // from the linked list of colormaps. - GLMipmap_t *next = NULL; + HWRTexture_t *next = NULL; - // No mipmap in this patch, break out of the loop. - if (!pat->mipmap) + // No texture in this patch, break out of the loop. + if (!pat->texture) break; - // No colormap mipmaps either. - if (!pat->mipmap->nextcolormap) + // No colormap textures either. + if (!pat->texture->nextcolormap) break; // Set the first colormap to the one that comes after it. - next = pat->mipmap->nextcolormap; - pat->mipmap->nextcolormap = next->nextcolormap; + next = pat->texture->nextcolormap; + pat->texture->nextcolormap = next->nextcolormap; // Free image data from memory. if (next->data) Z_Free(next->data); next->data = NULL; - HWD.pfnDeleteTexture(next); - // Free the old colormap mipmap from memory. + if (vid.glstate == VID_GL_LIBRARY_LOADED) + HWD.pfnDeleteTexture(next); + + // Free the old colormap texture from memory. free(next); } } -static void HWR_FreePatchCache(boolean freeall) +static boolean FreeTextureCallback(void *mem) { - INT32 i; - - for (i = 0; i < numwadfiles; i++) - { - INT32 j = 0; - for (; j < wadfiles[i]->numlumps; j++) - (freeall ? HWR_FreeTexture : HWR_FreeTextureColormaps)(wadfiles[i]->patchcache[j]); - } + patch_t *patch = (patch_t *)mem; + HWR_FreeTexture(patch); + return false; +} + +static boolean FreeColormapsCallback(void *mem) +{ + patch_t *patch = (patch_t *)mem; + HWR_FreeTextureColormaps(patch); + return false; +} + +static void FreeTextureCache(boolean freeall) +{ + boolean (*callback)(void *mem) = FreeTextureCallback; + + if (!freeall) + callback = FreeColormapsCallback; + + Z_IterateTags(PU_PATCH, PU_PATCH_ROTATED, callback); + Z_IterateTags(PU_SPRITE, PU_HUDGFX, callback); } -// free all textures after each level void HWR_ClearAllTextures(void) { - HWD.pfnClearMipMapCache(); // free references to the textures - HWR_FreePatchCache(true); + HWD.pfnClearTextureCache(); // free references to the textures + FreeTextureCache(true); } -void HWR_FreeColormapCache(void) +// free all texture colormaps after each level +void HWR_ClearColormapCache(void) { - HWR_FreePatchCache(false); + FreeTextureCache(false); } void HWR_InitMapTextures(void) @@ -700,10 +703,10 @@ void HWR_InitMapTextures(void) static void FreeMapTexture(GLMapTexture_t *tex) { - HWD.pfnDeleteTexture(&tex->mipmap); - if (tex->mipmap.data) - Z_Free(tex->mipmap.data); - tex->mipmap.data = NULL; + HWD.pfnDeleteTexture(&tex->texture); + if (tex->texture.data) + Z_Free(tex->texture.data); + tex->texture.data = NULL; } void HWR_FreeMapTextures(void) @@ -749,7 +752,7 @@ void HWR_SetPalette(RGBA_t *palette) // hardware driver will flush there own cache if cache is non paletized // now flush data texture cache so 32 bit texture are recomputed - if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA) + if (gl_patchformat == GPU_TEXFMT_RGBA || gl_textureformat == GPU_TEXFMT_RGBA) { Z_FreeTag(PU_HWRCACHE); Z_FreeTag(PU_HWRCACHE_UNLOCKED); @@ -772,27 +775,27 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex) grtex = &gl_textures[tex]; // Generate texture if missing from the cache - if (!grtex->mipmap.data && !grtex->mipmap.downloaded) + if (!grtex->texture.data && !grtex->texture.downloaded) HWR_GenerateTexture(tex, grtex); // If hardware does not have the texture, then call pfnSetTexture to upload it - if (!grtex->mipmap.downloaded) - HWD.pfnSetTexture(&grtex->mipmap); - HWR_SetCurrentTexture(&grtex->mipmap); + if (!grtex->texture.downloaded) + HWD.pfnSetTexture(&grtex->texture); + HWR_SetCurrentTexture(&grtex->texture); // The system-memory data can be purged now. - Z_ChangeTag(grtex->mipmap.data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(grtex->texture.data, PU_HWRCACHE_UNLOCKED); return grtex; } -static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) +static void HWR_CacheFlat(HWRTexture_t *hwrTexture, lumpnum_t flatlumpnum) { size_t size, pflatsize; // setup the texture info - grMipmap->format = GL_TEXFMT_P_8; - grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; + hwrTexture->format = GPU_TEXFMT_P_8; + hwrTexture->flags = TF_WRAPXY|TF_CHROMAKEYED; size = W_LumpLength(flatlumpnum); @@ -821,29 +824,29 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) break; } - grMipmap->width = (UINT16)pflatsize; - grMipmap->height = (UINT16)pflatsize; + hwrTexture->width = (UINT16)pflatsize; + hwrTexture->height = (UINT16)pflatsize; // the flat raw data needn't be converted with palettized textures W_ReadLump(flatlumpnum, Z_Malloc(W_LumpLength(flatlumpnum), - PU_HWRCACHE, &grMipmap->data)); + PU_HWRCACHE, &hwrTexture->data)); } -static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum) +static void HWR_CacheTextureAsFlat(HWRTexture_t *hwrTexture, INT32 texturenum) { UINT8 *flat; UINT8 *converted; size_t size; // setup the texture info - grMipmap->format = GL_TEXFMT_P_8; - grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; + hwrTexture->format = GPU_TEXFMT_P_8; + hwrTexture->flags = TF_WRAPXY|TF_CHROMAKEYED; - grMipmap->width = (UINT16)textures[texturenum]->width; - grMipmap->height = (UINT16)textures[texturenum]->height; - size = (grMipmap->width * grMipmap->height); + hwrTexture->width = (UINT16)textures[texturenum]->width; + hwrTexture->height = (UINT16)textures[texturenum]->height; + size = (hwrTexture->width * hwrTexture->height); - flat = Z_Malloc(size, PU_HWRCACHE, &grMipmap->data); + flat = Z_Malloc(size, PU_HWRCACHE, &hwrTexture->data); converted = (UINT8 *)Picture_TextureToFlat(texturenum); M_Memcpy(flat, converted, size); Z_Free(converted); @@ -852,24 +855,24 @@ static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum) // Download a Doom 'flat' to the hardware cache and make it ready for use void HWR_LiterallyGetFlat(lumpnum_t flatlumpnum) { - GLMipmap_t *grmip; + HWRTexture_t *hwrtex; patch_t *patch; if (flatlumpnum == LUMPERROR) return; patch = HWR_GetCachedGLPatch(flatlumpnum); - grmip = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap; - if (!grmip->downloaded && !grmip->data) - HWR_CacheFlat(grmip, flatlumpnum); + hwrtex = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->texture; + if (!hwrtex->downloaded && !hwrtex->data) + HWR_CacheFlat(hwrtex, flatlumpnum); // If hardware does not have the texture, then call pfnSetTexture to upload it - if (!grmip->downloaded) - HWD.pfnSetTexture(grmip); - HWR_SetCurrentTexture(grmip); + if (!hwrtex->downloaded) + HWD.pfnSetTexture(hwrtex); + HWR_SetCurrentTexture(hwrtex); // The system-memory data can be purged now. - Z_ChangeTag(grmip->data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(hwrtex->data, PU_HWRCACHE_UNLOCKED); } void HWR_GetLevelFlat(levelflat_t *levelflat) @@ -897,16 +900,16 @@ void HWR_GetLevelFlat(levelflat_t *levelflat) grtex = &gl_flats[texturenum]; // Generate flat if missing from the cache - if (!grtex->mipmap.data && !grtex->mipmap.downloaded) - HWR_CacheTextureAsFlat(&grtex->mipmap, texturenum); + if (!grtex->texture.data && !grtex->texture.downloaded) + HWR_CacheTextureAsFlat(&grtex->texture, texturenum); // If hardware does not have the texture, then call pfnSetTexture to upload it - if (!grtex->mipmap.downloaded) - HWD.pfnSetTexture(&grtex->mipmap); - HWR_SetCurrentTexture(&grtex->mipmap); + if (!grtex->texture.downloaded) + HWD.pfnSetTexture(&grtex->texture); + HWR_SetCurrentTexture(&grtex->texture); // The system-memory data can be purged now. - Z_ChangeTag(grtex->mipmap.data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(grtex->texture.data, PU_HWRCACHE_UNLOCKED); } else if (levelflat->type == LEVELFLAT_PATCH) { @@ -919,7 +922,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat) else if (levelflat->type == LEVELFLAT_PNG) { INT32 pngwidth = 0, pngheight = 0; - GLMipmap_t *mipmap = levelflat->mipmap; + HWRTexture_t *texture = levelflat->texture; UINT8 *flat; size_t size; @@ -931,28 +934,28 @@ void HWR_GetLevelFlat(levelflat_t *levelflat) levelflat->height = (UINT16)pngheight; } - // Make the mipmap. - if (mipmap == NULL) + // Make the texture. + if (texture == NULL) { - mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_LEVEL, NULL); - mipmap->format = GL_TEXFMT_P_8; - mipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; - levelflat->mipmap = mipmap; + texture = Z_Calloc(sizeof(HWRTexture_t), PU_LEVEL, NULL); + texture->format = GPU_TEXFMT_P_8; + texture->flags = TF_WRAPXY|TF_CHROMAKEYED; + levelflat->texture = texture; } - if (!mipmap->data && !mipmap->downloaded) + if (!texture->data && !texture->downloaded) { - mipmap->width = levelflat->width; - mipmap->height = levelflat->height; - size = (mipmap->width * mipmap->height); - flat = Z_Malloc(size, PU_LEVEL, &mipmap->data); + texture->width = levelflat->width; + texture->height = levelflat->height; + size = (texture->width * texture->height); + flat = Z_Malloc(size, PU_LEVEL, &texture->data); if (levelflat->picture == NULL) I_Error("HWR_GetLevelFlat: levelflat->picture == NULL"); M_Memcpy(flat, levelflat->picture, size); } - // Tell the hardware driver to bind the current texture to the flat's mipmap - HWD.pfnSetTexture(mipmap); + // Tell the hardware driver to bind the current texture to the flat's texture + HWD.pfnSetTexture(texture); } #endif else // set no texture @@ -960,21 +963,21 @@ void HWR_GetLevelFlat(levelflat_t *levelflat) } // --------------------+ -// HWR_LoadPatchMipmap : Generates a patch into a mipmap, usually the mipmap inside the patch itself +// HWR_LoadPatchTexture : Generates a patch into a texture, usually the texture inside the patch itself // --------------------+ -static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *grMipmap) +static void HWR_LoadPatchTexture(patch_t *patch, HWRTexture_t *hwrTexture) { GLPatch_t *grPatch = patch->hardware; - if (!grMipmap->downloaded && !grMipmap->data) - HWR_MakePatch(patch, grPatch, grMipmap, true); + if (!hwrTexture->downloaded && !hwrTexture->data) + HWR_MakePatch(patch, grPatch, hwrTexture, true); // If hardware does not have the texture, then call pfnSetTexture to upload it - if (!grMipmap->downloaded) - HWD.pfnSetTexture(grMipmap); - HWR_SetCurrentTexture(grMipmap); + if (!hwrTexture->downloaded) + HWD.pfnSetTexture(hwrTexture); + HWR_SetCurrentTexture(hwrTexture); // The system-memory data can be purged now. - Z_ChangeTag(grMipmap->data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(hwrTexture->data, PU_HWRCACHE_UNLOCKED); } // -----------------+ @@ -984,7 +987,7 @@ void HWR_GetPatch(patch_t *patch) { if (!patch->hardware) Patch_CreateGL(patch); - HWR_LoadPatchMipmap(patch, ((GLPatch_t *)patch->hardware)->mipmap); + HWR_LoadPatchTexture(patch, ((GLPatch_t *)patch->hardware)->texture); } // -------------------+ @@ -993,7 +996,7 @@ void HWR_GetPatch(patch_t *patch) void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) { GLPatch_t *grPatch; - GLMipmap_t *grMipmap, *newMipmap; + HWRTexture_t *hwrTexture, *newTexture; if (!patch->hardware) Patch_CreateGL(patch); @@ -1008,29 +1011,25 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) // search for the mimmap // skip the first (no colormap translated) - for (grMipmap = grPatch->mipmap; grMipmap->nextcolormap; ) + for (hwrTexture = grPatch->texture; hwrTexture->nextcolormap; ) { - grMipmap = grMipmap->nextcolormap; - if (grMipmap->colormap == colormap) + hwrTexture = hwrTexture->nextcolormap; + if (hwrTexture->colormap == colormap) { - HWR_LoadPatchMipmap(patch, grMipmap); + HWR_LoadPatchTexture(patch, hwrTexture); return; } } + // not found, create it! // If we are here, the sprite with the current colormap is not already in hardware memory - - //BP: WARNING: don't free it manually without clearing the cache of harware renderer - // (it have a liste of mipmap) - // this malloc is cleared in HWR_FreeColormapCache - // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better - newMipmap = calloc(1, sizeof (*newMipmap)); - if (newMipmap == NULL) + newTexture = calloc(1, sizeof (*newTexture)); + if (newTexture == NULL) I_Error("%s: Out of memory", "HWR_GetMappedPatch"); - grMipmap->nextcolormap = newMipmap; + hwrTexture->nextcolormap = newTexture; - newMipmap->colormap = colormap; - HWR_LoadPatchMipmap(patch, newMipmap); + newTexture->colormap = colormap; + HWR_LoadPatchTexture(patch, newTexture); } void HWR_UnlockCachedPatch(GLPatch_t *gpatch) @@ -1038,17 +1037,17 @@ void HWR_UnlockCachedPatch(GLPatch_t *gpatch) if (!gpatch) return; - Z_ChangeTag(gpatch->mipmap->data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(gpatch->texture->data, PU_HWRCACHE_UNLOCKED); Z_ChangeTag(gpatch, PU_HWRPATCHINFO_UNLOCKED); } static const INT32 picmode2GR[] = { - GL_TEXFMT_P_8, // PALETTE - 0, // INTENSITY (unsupported yet) - GL_TEXFMT_ALPHA_INTENSITY_88, // INTENSITY_ALPHA (corona use this) - 0, // RGB24 (unsupported yet) - GL_TEXFMT_RGBA, // RGBA32 (opengl only) + GPU_TEXFMT_P_8, // PALETTE + 0, // INTENSITY (unsupported yet) + GPU_TEXFMT_ALPHA_INTENSITY_88, // INTENSITY_ALPHA (corona use this) + 0, // RGB24 (unsupported yet) + GPU_TEXFMT_RGBA, // RGBA32 }; static void HWR_DrawPicInCache(UINT8 *block, INT32 pblockwidth, INT32 pblockheight, @@ -1125,7 +1124,7 @@ patch_t *HWR_GetPic(lumpnum_t lumpnum) patch_t *patch = HWR_GetCachedGLPatch(lumpnum); GLPatch_t *grPatch = (GLPatch_t *)(patch->hardware); - if (!grPatch->mipmap->downloaded && !grPatch->mipmap->data) + if (!grPatch->texture->downloaded && !grPatch->texture->data) { pic_t *pic; UINT8 *block; @@ -1136,40 +1135,40 @@ patch_t *HWR_GetPic(lumpnum_t lumpnum) patch->height = SHORT(pic->height); len = W_LumpLength(lumpnum) - sizeof (pic_t); - grPatch->mipmap->width = (UINT16)patch->width; - grPatch->mipmap->height = (UINT16)patch->height; + grPatch->texture->width = (UINT16)patch->width; + grPatch->texture->height = (UINT16)patch->height; if (pic->mode == PALETTE) - grPatch->mipmap->format = textureformat; // can be set by driver + grPatch->texture->format = gl_textureformat; // can be set by driver else - grPatch->mipmap->format = picmode2GR[pic->mode]; + grPatch->texture->format = picmode2GR[pic->mode]; - Z_Free(grPatch->mipmap->data); + Z_Free(grPatch->texture->data); // allocate block - block = MakeBlock(grPatch->mipmap); + block = MakeBlock(grPatch->texture); if (patch->width == SHORT(pic->width) && patch->height == SHORT(pic->height) && - format2bpp(grPatch->mipmap->format) == format2bpp(picmode2GR[pic->mode])) + format2bpp(grPatch->texture->format) == format2bpp(picmode2GR[pic->mode])) { // no conversion needed - M_Memcpy(grPatch->mipmap->data, pic->data,len); + M_Memcpy(grPatch->texture->data, pic->data,len); } else HWR_DrawPicInCache(block, SHORT(pic->width), SHORT(pic->height), - SHORT(pic->width)*format2bpp(grPatch->mipmap->format), + SHORT(pic->width)*format2bpp(grPatch->texture->format), pic, - format2bpp(grPatch->mipmap->format)); + format2bpp(grPatch->texture->format)); Z_Unlock(pic); Z_ChangeTag(block, PU_HWRCACHE_UNLOCKED); - grPatch->mipmap->flags = 0; + grPatch->texture->flags = 0; grPatch->max_s = grPatch->max_t = 1.0f; } - HWD.pfnSetTexture(grPatch->mipmap); - //CONS_Debug(DBG_RENDER, "picloaded at %x as texture %d\n",grPatch->mipmap->data, grPatch->mipmap->downloaded); + HWD.pfnSetTexture(grPatch->texture); + //CONS_Debug(DBG_RENDER, "picloaded at %x as texture %d\n",grPatch->texture->data, grPatch->texture->downloaded); return patch; } @@ -1192,12 +1191,12 @@ patch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum) } // Need to do this because they aren't powers of 2 -static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 pblockheight, +static void HWR_DrawFadeMaskInCache(HWRTexture_t *texture, INT32 pblockwidth, INT32 pblockheight, lumpnum_t fademasklumpnum, UINT16 fmwidth, UINT16 fmheight) { INT32 i,j; fixed_t posx, posy, stepx, stepy; - UINT8 *block = mipmap->data; // places the data directly into here + UINT8 *block = texture->data; // places the data directly into here UINT8 *flat; UINT8 *dest, *src, texel; RGBA_t col; @@ -1212,7 +1211,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 for (j = 0; j < pblockheight; j++) { posx = 0; - dest = &block[j*(mipmap->width)]; // 1bpp + dest = &block[j*(texture->width)]; // 1bpp src = &flat[(posy>>FRACBITS)*SHORT(fmwidth)]; for (i = 0; i < pblockwidth;i++) { @@ -1230,14 +1229,14 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 Z_Free(flat); } -static void HWR_CacheFadeMask(GLMipmap_t *grMipmap, lumpnum_t fademasklumpnum) +static void HWR_CacheFadeMask(HWRTexture_t *hwrTexture, lumpnum_t fademasklumpnum) { size_t size; UINT16 fmheight = 0, fmwidth = 0; // setup the texture info - grMipmap->format = GL_TEXFMT_ALPHA_8; // put the correct alpha levels straight in so I don't need to convert it later - grMipmap->flags = 0; + hwrTexture->format = GPU_TEXFMT_ALPHA_8; // put the correct alpha levels straight in so I don't need to convert it later + hwrTexture->flags = 0; size = W_LumpLength(fademasklumpnum); @@ -1266,12 +1265,12 @@ static void HWR_CacheFadeMask(GLMipmap_t *grMipmap, lumpnum_t fademasklumpnum) } // Thankfully, this will still work for this scenario - grMipmap->width = fmwidth; - grMipmap->height = fmheight; + hwrTexture->width = fmwidth; + hwrTexture->height = fmheight; - MakeBlock(grMipmap); + MakeBlock(hwrTexture); - HWR_DrawFadeMaskInCache(grMipmap, fmwidth, fmheight, fademasklumpnum, fmwidth, fmheight); + HWR_DrawFadeMaskInCache(hwrTexture, fmwidth, fmheight, fademasklumpnum, fmwidth, fmheight); // I DO need to convert this because it isn't power of 2 and we need the alpha } @@ -1280,14 +1279,14 @@ static void HWR_CacheFadeMask(GLMipmap_t *grMipmap, lumpnum_t fademasklumpnum) void HWR_GetFadeMask(lumpnum_t fademasklumpnum) { patch_t *patch = HWR_GetCachedGLPatch(fademasklumpnum); - GLMipmap_t *grmip = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap; - if (!grmip->downloaded && !grmip->data) - HWR_CacheFadeMask(grmip, fademasklumpnum); + HWRTexture_t *hwrtex = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->texture; + if (!hwrtex->downloaded && !hwrtex->data) + HWR_CacheFadeMask(hwrtex, fademasklumpnum); - HWD.pfnSetTexture(grmip); + HWD.pfnSetTexture(hwrtex); // The system-memory data can be purged now. - Z_ChangeTag(grmip->data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(hwrtex->data, PU_HWRCACHE_UNLOCKED); } #endif //HWRENDER diff --git a/src/hardware/hw_data.h b/src/hardware/hw_data.h index 3ae4ef8bc..cbdf56700 100644 --- a/src/hardware/hw_data.h +++ b/src/hardware/hw_data.h @@ -22,28 +22,27 @@ #include "../doomdef.h" #include "../screen.h" - // ========================================================================== // TEXTURE INFO // ========================================================================== -typedef enum GLTextureFormat_e +enum GLTextureFormat_e { - GL_TEXFMT_P_8 = 0x01, /* 8-bit palette */ - GL_TEXFMT_AP_88 = 0x02, /* 8-bit alpha, 8-bit palette */ + GPU_TEXFMT_P_8 = 0x01, /* 8-bit palette */ + GPU_TEXFMT_AP_88 = 0x02, /* 8-bit alpha, 8-bit palette */ - GL_TEXFMT_RGBA = 0x10, /* 32 bit RGBA! */ + GPU_TEXFMT_RGBA = 0x10, /* 32 bit RGBA! */ - GL_TEXFMT_ALPHA_8 = 0x20, /* (0..0xFF) alpha */ - GL_TEXFMT_INTENSITY_8 = 0x21, /* (0..0xFF) intensity */ - GL_TEXFMT_ALPHA_INTENSITY_88 = 0x22, -} GLTextureFormat_t; + GPU_TEXFMT_ALPHA_8 = 0x20, /* (0..0xFF) alpha */ + GPU_TEXFMT_INTENSITY_8 = 0x21, /* (0..0xFF) intensity */ + GPU_TEXFMT_ALPHA_INTENSITY_88 = 0x22, +}; +typedef enum GLTextureFormat_e GLTextureFormat_t; // data holds the address of the graphics data cached in heap memory -// NULL if the texture is not in Doom heap cache. -struct GLMipmap_s +// NULL if the texture is not in Doom heap cache. +struct HWRTexture_s { - // for TexDownloadMipMap GLTextureFormat_t format; void *data; @@ -52,32 +51,26 @@ struct GLMipmap_s UINT16 width; UINT32 downloaded; // The GPU has this texture. - struct GLMipmap_s *nextcolormap; + struct HWRTexture_s *nextcolormap; const UINT8 *colormap; - - struct GLMipmap_s *nextmipmap; // Linked list of all textures }; -typedef struct GLMipmap_s GLMipmap_t; +typedef struct HWRTexture_s HWRTexture_t; - -// -// Doom texture info, as cached for hardware rendering -// +// Texture info, as cached for hardware rendering struct GLMapTexture_s { - GLMipmap_t mipmap; - float scaleX; //used for scaling textures on walls - float scaleY; + HWRTexture_t texture; + float scaleX; + float scaleY; }; typedef struct GLMapTexture_s GLMapTexture_t; - -// a cached patch as converted to hardware format +// A cached patch, as converted to hardware format struct GLPatch_s { float max_s,max_t; - GLMipmap_t *mipmap; -} ATTRPACK; + HWRTexture_t *texture; +}; typedef struct GLPatch_s GLPatch_t; #endif //_HWR_DATA_ diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index a782762a3..fad978dfe 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -18,52 +18,26 @@ #define ZCLIP_PLANE 4.0f // Used for the actual game drawing #define NZCLIP_PLANE 0.9f // Seems to be only used for the HUD and screen textures -// ========================================================================== -// SIMPLE TYPES -// ========================================================================== - -typedef long FINT; -typedef unsigned long FUINT; -typedef unsigned char FUBYTE; -typedef unsigned long FBITFIELD; -#ifndef __MINGW32__ -typedef float FLOAT; -#endif -typedef unsigned char FBOOLEAN; - // ========================================================================== // COLORS // ========================================================================== // byte value for paletted graphics, which represent the transparent color -#define HWR_PATCHES_CHROMAKEY_COLORINDEX 255 -//#define HWR_CHROMAKEY_EQUIVALENTCOLORINDEX 130 +#define GPU_PATCHES_CHROMAKEY_COLORINDEX 255 // the chroma key color shows on border sprites, set it to black -#define HWR_PATCHES_CHROMAKEY_COLORVALUE (0x00000000) //RGBA format as in grSstWinOpen() +#define GPU_PATCHES_CHROMAKEY_COLORVALUE (0x00000000) //RGBA format as in grSstWinOpen() + +#define GPU_DEFAULTMIX 0x00000000 +#define GPU_DEFAULTFOG 0xFF000000 // RGBA Color components with float type ranging [ 0 ... 1 ] struct FRGBAFloat { - FLOAT red; - FLOAT green; - FLOAT blue; - FLOAT alpha; + float red, green, blue, alpha; }; typedef struct FRGBAFloat FRGBAFloat; -struct FColorARGB -{ - FUBYTE alpha; - FUBYTE red; - FUBYTE green; - FUBYTE blue; -}; -typedef struct FColorARGB ARGB_t; -typedef struct FColorARGB FColorARGB; - - - // ========================================================================== // VECTORS // ========================================================================== @@ -71,21 +45,15 @@ typedef struct FColorARGB FColorARGB; // Simple 2D coordinate typedef struct { - FLOAT x,y; + float x,y; } F2DCoord, v2d_t; // Simple 3D vector typedef struct FVector { - FLOAT x,y,z; + float x,y,z; } FVector; -// ====================== -// wallVert3D -// ---------------------- -// :crab: IS GONE! :crab: -// ====================== - // ----------- // structures // ----------- @@ -102,21 +70,21 @@ typedef struct FVector typedef struct { - FLOAT x,y,z; // position + float x,y,z; // position #ifdef USE_FTRANSFORM_ANGLEZ - FLOAT anglex,angley,anglez; // aimingangle / viewangle + float anglex,angley,anglez; // aimingangle / viewangle #else - FLOAT anglex,angley; // aimingangle / viewangle + float anglex,angley; // aimingangle / viewangle #endif - FLOAT scalex,scaley,scalez; - FLOAT fovxangle, fovyangle; + float scalex,scaley,scalez; + float fovxangle, fovyangle; UINT8 splitscreen; boolean flip; // screenflip boolean roll; SINT8 rollflip; - FLOAT rollangle; // done to not override USE_FTRANSFORM_ANGLEZ + float rollangle; // done to not override USE_FTRANSFORM_ANGLEZ UINT8 rotaxis; - FLOAT centerx, centery; + float centerx, centery; #ifdef USE_FTRANSFORM_MIRROR boolean mirror; // SRB2Kart: Encore Mode #endif @@ -127,83 +95,11 @@ typedef struct // Transformed vector, as passed to HWR API typedef struct { - FLOAT x,y,z; - FLOAT s; // s texture ordinate (s over w) - FLOAT t; // t texture ordinate (t over w) + float x, y, z; + float s; // s texture ordinate (s over w) + float t; // t texture ordinate (t over w) } FOutVector; -#ifdef GL_SHADERS -// Predefined shader types -enum -{ - SHADER_DEFAULT = 0, - - SHADER_FLOOR, - SHADER_WALL, - SHADER_SPRITE, - SHADER_MODEL, SHADER_MODEL_LIGHTING, - SHADER_WATER, - SHADER_FOG, - SHADER_SKY, - - NUMBASESHADERS, -}; - -// Maximum amount of shader programs -// Must be higher than NUMBASESHADERS -#define HWR_MAXSHADERS 16 - -// Shader sources (vertex and fragment) -typedef struct -{ - char *vertex; - char *fragment; -} shadersource_t; - -// Custom shader reference table -typedef struct -{ - const char *type; - INT32 id; -} customshaderxlat_t; - -#endif - -typedef struct vbo_vertex_s -{ - float x, y, z; - float u, v; - unsigned char r, g, b, a; -} gl_skyvertex_t; - -typedef enum gl_skyloopmode_e -{ - HWD_SKYLOOP_FAN, - HWD_SKYLOOP_STRIP -} gl_skyloopmode_t; - -typedef struct -{ - gl_skyloopmode_t mode; - int vertexcount; - int vertexindex; - boolean use_texture; -} gl_skyloopdef_t; - -typedef struct -{ - unsigned int vbo; - int rows, columns; - int loopcount; - - int detail, vertex_count; - int texture, width, height; - boolean rebuild; // VBO needs to be rebuilt - - gl_skyloopdef_t *loops; - gl_skyvertex_t *data; -} gl_sky_t; - // ========================================================================== // RENDER MODES // ========================================================================== @@ -240,7 +136,6 @@ enum EPolyFlags PF_ForceWrapY = 0x00040000 // Forces repeat texture on Y }; - enum ESurfFlags { SF_DYNLIGHT = 0x00000001, @@ -255,71 +150,141 @@ enum ETextureFlags TF_TRANSPARENT = 0x00000040, // texture with some alpha == 0 }; -typedef struct GLMipmap_s FTextureInfo; +struct FTextureInfo +{ + UINT32 width, height; + UINT32 name; + UINT32 format; + + struct HWRTexture_s *texture; + struct FTextureInfo *prev, *next; +}; +typedef struct FTextureInfo FTextureInfo; -// jimita 14032019 struct FLightInfo { - FUINT light_level; - FUINT fade_start; - FUINT fade_end; + UINT32 LightLevel; + UINT32 FadeStart, FadeEnd; }; typedef struct FLightInfo FLightInfo; // Description of a renderable surface struct FSurfaceInfo { - FUINT PolyFlags; + UINT32 PolyFlags; RGBA_t PolyColor; RGBA_t TintColor; RGBA_t FadeColor; - FLightInfo LightInfo; // jimita 14032019 + FLightInfo LightInfo; }; typedef struct FSurfaceInfo FSurfaceInfo; -#define GL_DEFAULTMIX 0x00000000 -#define GL_DEFAULTFOG 0xFF000000 - -//Hurdler: added for backward compatibility -enum hwdsetspecialstate +// Hurdler: added for backward compatibility +enum EGPUState { - HWD_SET_MODEL_LIGHTING = 1, - HWD_SET_SHADERS, - HWD_SET_TEXTUREFILTERMODE, - HWD_SET_TEXTUREANISOTROPICMODE, - HWD_NUMSTATE + GPU_STATE_TEXTUREFILTERMODE, + GPU_STATE_TEXTUREANISOTROPICMODE, + GPU_STATE_SHADERS, + GPU_STATE_MODEL_LIGHTING }; -typedef enum hwdsetspecialstate hwdspecialstate_t; - -// Lactozilla: Shader options -enum hwdshaderoption +enum EShaderOption { - HWD_SHADEROPTION_OFF, - HWD_SHADEROPTION_ON, - HWD_SHADEROPTION_NOCUSTOM, + GPU_SHADEROPTION_OFF, + GPU_SHADEROPTION_ON, + GPU_SHADEROPTION_NOCUSTOM, }; -typedef enum hwdshaderoption hwdshaderoption_t; - -// Lactozilla: Shader info -// Generally set at the start of the frame. -enum hwdshaderinfo +enum EShaderInfo { - HWD_SHADERINFO_LEVELTIME = 1, + GPU_SHADERINFO_LEVELTIME = 1, }; -typedef enum hwdshaderinfo hwdshaderinfo_t; - -enum hwdfiltermode +enum EFilterMode { - HWD_SET_TEXTUREFILTER_POINTSAMPLED, - HWD_SET_TEXTUREFILTER_BILINEAR, - HWD_SET_TEXTUREFILTER_TRILINEAR, - HWD_SET_TEXTUREFILTER_MIXED1, - HWD_SET_TEXTUREFILTER_MIXED2, - HWD_SET_TEXTUREFILTER_MIXED3, + GPU_TEXFILTER_POINTSAMPLED, + GPU_TEXFILTER_BILINEAR, + GPU_TEXFILTER_TRILINEAR, + GPU_TEXFILTER_MIXED1, + GPU_TEXFILTER_MIXED2, + GPU_TEXFILTER_MIXED3, }; +#ifdef GL_SHADERS +// Predefined shader types +enum +{ + SHADER_DEFAULT = 0, + + SHADER_FLOOR, + SHADER_WALL, + SHADER_SPRITE, + SHADER_MODEL, SHADER_MODEL_LIGHTING, + SHADER_WATER, + SHADER_FOG, + SHADER_SKY, + + NUMBASESHADERS, +}; + +// Maximum amount of shader programs +// Must be higher than NUMBASESHADERS +#define HWR_MAXSHADERS 16 + +// Shader sources (vertex and fragment) +struct FShaderSource +{ + char *vertex; + char *fragment; +}; +typedef struct FShaderSource FShaderSource; + +// Custom shader reference table +struct FShaderReferenceArray +{ + const char *type; + INT32 id; +}; +typedef struct FShaderReferenceArray FShaderReferenceArray; + +#endif + +struct FSkyVertex +{ + float x, y, z; + float u, v; + unsigned char r, g, b, a; +}; +typedef struct FSkyVertex FSkyVertex; + +enum ESkyLoopMode +{ + GPU_SKYLOOP_FAN, + GPU_SKYLOOP_STRIP +}; + +struct FSkyLoopDef +{ + int mode; + int vertexcount; + int vertexindex; + boolean use_texture; +}; +typedef struct FSkyLoopDef FSkyLoopDef; + +struct FSkyDome +{ + unsigned int vbo; + int rows, columns; + int loopcount; + + int detail, vertex_count; + int texture, width, height; + boolean rebuild; // VBO needs to be rebuilt + + FSkyLoopDef *loops; + FSkyVertex *data; +}; +typedef struct FSkyDome FSkyDome; #endif //_HWR_DEFS_ diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index c5d362520..51b1e5631 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -71,7 +71,7 @@ static UINT8 softwaretranstogl_lo[11] = { 0, 12, 24, 36, 48, 60, 71, 83, 95,111 void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) { FOutVector v[4]; - FBITFIELD flags; + UINT32 flags; GLPatch_t *hwrPatch; // 3--2 @@ -131,7 +131,7 @@ void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap) { FOutVector v[4]; - FBITFIELD flags; + UINT32 flags; float cx = FIXED_TO_FLOAT(x); float cy = FIXED_TO_FLOAT(y); UINT8 alphalevel = ((option & V_ALPHAMASK) >> V_ALPHASHIFT); @@ -385,7 +385,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h) { FOutVector v[4]; - FBITFIELD flags; + UINT32 flags; float cx = FIXED_TO_FLOAT(x); float cy = FIXED_TO_FLOAT(y); UINT8 alphalevel = ((option & V_ALPHAMASK) >> V_ALPHASHIFT); diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 5a2e0e44e..608712e34 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -35,21 +35,20 @@ EXPORT void HWRAPI(GetModeList) (vmode_t **pvidmodes, INT32 *numvidmodes); EXPORT void HWRAPI(SetPalette) (RGBA_t *ppal); EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl); EXPORT void HWRAPI(Draw2DLine) (F2DCoord *v1, F2DCoord *v2, RGBA_t Color); -EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags); -EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, UINT32 *IndexArray); -EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky); -EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags); -EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FRGBAFloat *ClearColor); -EXPORT void HWRAPI(SetTexture) (FTextureInfo *TexInfo); -EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *TexInfo); -EXPORT void HWRAPI(DeleteTexture) (FTextureInfo *TexInfo); +EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, UINT32 iNumPts, UINT32 PolyFlags); +EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, UINT32 iNumPts, UINT32 PolyFlags, UINT32 *IndexArray); +EXPORT void HWRAPI(RenderSkyDome) (FSkyDome *sky); +EXPORT void HWRAPI(SetBlend) (UINT32 PolyFlags); +EXPORT void HWRAPI(ClearBuffer) (boolean ColorMask, boolean DepthMask, FRGBAFloat *ClearColor); +EXPORT void HWRAPI(SetTexture) (HWRTexture_t *TexInfo); +EXPORT void HWRAPI(UpdateTexture) (HWRTexture_t *TexInfo); +EXPORT void HWRAPI(DeleteTexture) (HWRTexture_t *TexInfo); EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, INT32 dst_stride, UINT16 *dst_data); EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip); -EXPORT void HWRAPI(ClearMipMapCache) (void); -EXPORT void HWRAPI(ClearCacheList) (void); +EXPORT void HWRAPI(ClearTextureCache) (void); //Hurdler: added for backward compatibility -EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); +EXPORT void HWRAPI(SetState) (INT32 State, INT32 Value); //Hurdler: added for new development EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface); @@ -75,7 +74,7 @@ EXPORT void HWRAPI(CleanShaders) (void); EXPORT void HWRAPI(SetShader) (int type); EXPORT void HWRAPI(UnSetShader) (void); -EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value); +EXPORT void HWRAPI(SetShaderInfo) (INT32 info, INT32 value); EXPORT void HWRAPI(LoadCustomShader) (int number, char *code, size_t size, boolean isfragment); // ========================================================================== @@ -100,9 +99,8 @@ struct hwdriver_s DeleteTexture pfnDeleteTexture; ReadRect pfnReadRect; GClipRect pfnGClipRect; - ClearMipMapCache pfnClearMipMapCache; - ClearCacheList pfnClearCacheList; - SetSpecialState pfnSetSpecialState;//Hurdler: added for backward compatibility + ClearTextureCache pfnClearTextureCache; + SetState pfnSetState; DrawModel pfnDrawModel; CreateModelVBOs pfnCreateModelVBOs; SetTransform pfnSetTransform; diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 87405d3d4..78211288c 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -121,10 +121,9 @@ void HWR_GetLevelFlat(levelflat_t *levelflat); void HWR_LiterallyGetFlat(lumpnum_t flatlumpnum); void HWR_FreeTexture(patch_t *patch); -void HWR_FreeTextureData(patch_t *patch); void HWR_FreeTextureColormaps(patch_t *patch); void HWR_ClearAllTextures(void); -void HWR_FreeColormapCache(void); +void HWR_ClearColormapCache(void); void HWR_UnlockCachedPatch(GLPatch_t *gpatch); void HWR_SetPalette(RGBA_t *palette); @@ -133,7 +132,7 @@ void HWR_SetPalette(RGBA_t *palette); // -------- // hw_draw.c // -------- -extern INT32 patchformat; -extern INT32 textureformat; +extern INT32 gl_patchformat; +extern INT32 gl_textureformat; #endif //_HW_GLOB_ diff --git a/src/hardware/hw_light.c b/src/hardware/hw_light.c index 987d70c69..e05fe4cec 100644 --- a/src/hardware/hw_light.c +++ b/src/hardware/hw_light.c @@ -1206,8 +1206,8 @@ void HWR_DL_AddLight(gl_vissprite_t *spr, GLPatch_t *patch) dynlights->nb++; } -static GLMipmap_t lightmappatchmipmap; -static GLPatch_t lightmappatch = { .mipmap = &lightmappatchmipmap }; +static HWRTexture_t lightmappatchtexture; +static GLPatch_t lightmappatch = { .texture = &lightmappatchtexture }; void HWR_InitLight(void) { @@ -1217,7 +1217,7 @@ void HWR_InitLight(void) for (i = 0;i < NUMLIGHTS;i++) lspr[i].dynamic_sqrradius = lspr[i].dynamic_radius*lspr[i].dynamic_radius; - lightmappatch.mipmap->downloaded = false; + lightmappatch.texture->downloaded = false; coronalumpnum = W_CheckNumForName("CORONA"); } @@ -1228,10 +1228,10 @@ static void HWR_SetLight(void) { int i, j; - if (!lightmappatch.mipmap->downloaded && !lightmappatch.mipmap->data) + if (!lightmappatch.texture->downloaded && !lightmappatch.texture->data) { - UINT16 *Data = Z_Malloc(129*128*sizeof (UINT16), PU_HWRCACHE, &lightmappatch.mipmap->data); + UINT16 *Data = Z_Malloc(129*128*sizeof (UINT16), PU_HWRCACHE, &lightmappatch.texture->data); for (i = 0; i < 128; i++) { @@ -1244,18 +1244,18 @@ static void HWR_SetLight(void) Data[i*128+j] = 0; } } - lightmappatch.mipmap->format = GL_TEXFMT_ALPHA_INTENSITY_88; + lightmappatch.texture->format = GPU_TEXFMT_ALPHA_INTENSITY_88; lightmappatch.width = 128; lightmappatch.height = 128; - lightmappatch.mipmap->width = 128; - lightmappatch.mipmap->height = 128; - lightmappatch.mipmap->flags = 0; //TF_WRAPXY; // DEBUG: view the overdraw ! + lightmappatch.texture->width = 128; + lightmappatch.texture->height = 128; + lightmappatch.texture->flags = 0; //TF_WRAPXY; // DEBUG: view the overdraw ! } - HWD.pfnSetTexture(lightmappatch.mipmap); + HWD.pfnSetTexture(lightmappatch.texture); // The system-memory data can be purged now. - Z_ChangeTag(lightmappatch.mipmap->data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(lightmappatch.texture->data, PU_HWRCACHE_UNLOCKED); } //********************************************************** diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c5f63654b..e11a37a5c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -65,9 +65,9 @@ static void HWR_ProjectSprite(mobj_t *thing); static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing); #endif -void HWR_AddTransparentFloor(levelflat_t *levelflat, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, boolean fogplane, extracolormap_t *planecolormap); +void HWR_AddTransparentFloor(levelflat_t *levelflat, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, UINT32 blend, boolean fogplane, extracolormap_t *planecolormap); void HWR_AddTransparentPolyobjectFloor(levelflat_t *levelflat, polyobj_t *polysector, boolean isceiling, fixed_t fixedheight, - INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, extracolormap_t *planecolormap); + INT32 lightlevel, INT32 alpha, sector_t *FOFSector, UINT32 blend, extracolormap_t *planecolormap); boolean drawsky = true; @@ -178,8 +178,8 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col RGBA_t poly_color, tint_color, fade_color; poly_color.rgba = 0xFFFFFFFF; - tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : GL_DEFAULTMIX; - fade_color.rgba = (colormap != NULL) ? (UINT32)colormap->fadergba : GL_DEFAULTFOG; + tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : GPU_DEFAULTMIX; + fade_color.rgba = (colormap != NULL) ? (UINT32)colormap->fadergba : GPU_DEFAULTFOG; // Crappy backup coloring if you can't do shaders if (!cv_glshaders.value || !gl_shadersavailable) @@ -224,9 +224,9 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col Surface->PolyColor.rgba = poly_color.rgba; Surface->TintColor.rgba = tint_color.rgba; Surface->FadeColor.rgba = fade_color.rgba; - Surface->LightInfo.light_level = light_level; - Surface->LightInfo.fade_start = (colormap != NULL) ? colormap->fadestart : 0; - Surface->LightInfo.fade_end = (colormap != NULL) ? colormap->fadeend : 31; + Surface->LightInfo.LightLevel = light_level; + Surface->LightInfo.FadeStart = (colormap != NULL) ? colormap->fadestart : 0; + Surface->LightInfo.FadeEnd = (colormap != NULL) ? colormap->fadeend : 31; } UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if this can work @@ -234,7 +234,7 @@ UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if RGBA_t realcolor, surfcolor; INT32 alpha; - realcolor.rgba = (colormap != NULL) ? colormap->rgba : GL_DEFAULTMIX; + realcolor.rgba = (colormap != NULL) ? colormap->rgba : GPU_DEFAULTMIX; if (cv_glshaders.value && gl_shadersavailable) { @@ -259,7 +259,7 @@ UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if return surfcolor.s.alpha; } -static FUINT HWR_CalcWallLight(FUINT lightnum, fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y) +static UINT32 HWR_CalcWallLight(UINT32 lightnum, fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y) { INT16 finallight = lightnum; @@ -295,10 +295,10 @@ static FUINT HWR_CalcWallLight(FUINT lightnum, fixed_t v1x, fixed_t v1y, fixed_t } } - return (FUINT)finallight; + return (UINT32)finallight; } -static FUINT HWR_CalcSlopeLight(FUINT lightnum, angle_t dir, fixed_t delta) +static UINT32 HWR_CalcSlopeLight(UINT32 lightnum, angle_t dir, fixed_t delta) { INT16 finallight = lightnum; @@ -339,7 +339,7 @@ static FUINT HWR_CalcSlopeLight(FUINT lightnum, angle_t dir, fixed_t delta) } } - return (FUINT)finallight; + return (UINT32)finallight; } // ========================================================================== @@ -351,7 +351,7 @@ static FUINT HWR_CalcSlopeLight(FUINT lightnum, angle_t dir, fixed_t delta) // -----------------+ // HWR_RenderPlane : Render a floor or ceiling convex polygon // -----------------+ -static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, levelflat_t *levelflat, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap) +static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, UINT32 PolyFlags, INT32 lightlevel, levelflat_t *levelflat, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap) { polyvertex_t * pv; float height; //constant y for all points on the convex flat polygon @@ -702,7 +702,7 @@ static void HWR_RenderSkyPlane(extrasubsector_t *xsub, fixed_t fixedheight) #endif //doplanes -FBITFIELD HWR_GetBlendModeFlag(INT32 ast) +UINT32 HWR_GetBlendModeFlag(INT32 ast) { switch (ast) { @@ -742,7 +742,7 @@ UINT8 HWR_GetTranstableAlpha(INT32 transtablenum) return 0xff; } -FBITFIELD HWR_SurfaceBlend(INT32 style, INT32 transtablenum, FSurfaceInfo *pSurf) +UINT32 HWR_SurfaceBlend(INT32 style, INT32 transtablenum, FSurfaceInfo *pSurf) { if (!transtablenum) { @@ -754,7 +754,7 @@ FBITFIELD HWR_SurfaceBlend(INT32 style, INT32 transtablenum, FSurfaceInfo *pSurf return HWR_GetBlendModeFlag(style); } -FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf) +UINT32 HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf) { if (!transtablenum) { @@ -766,7 +766,7 @@ FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf) return PF_Translucent; } -static void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); +static void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, INT32 texnum, UINT32 blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); // ========================================================================== // Wall generation from subsector segs @@ -783,7 +783,7 @@ static void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, I // // HWR_ProjectWall // -static void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blendmode, INT32 lightlevel, extracolormap_t *wallcolormap) +static void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, UINT32 blendmode, INT32 lightlevel, extracolormap_t *wallcolormap) { HWR_Lighting(pSurf, lightlevel, wallcolormap); HWR_ProcessPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude, SHADER_WALL, false); // wall shader @@ -857,7 +857,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, INT32 solid, i; lightlist_t * list = sector->lightlist; const UINT8 alpha = Surf->PolyColor.s.alpha; - FUINT lightnum = HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y); + UINT32 lightnum = HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y); extracolormap_t *colormap = NULL; realtop = top = wallVerts[3].y; @@ -1046,7 +1046,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom fixed_t h, l; // 3D sides and 2s middle textures fixed_t hS, lS; - FUINT lightnum = 0; // shut up compiler + UINT32 lightnum = 0; // shut up compiler extracolormap_t *colormap; FSurfaceInfo Surf; @@ -1184,7 +1184,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (gl_frontsector->numlights) HWR_SplitWall(gl_frontsector, wallVerts, gl_toptexture, &Surf, FF_CUTLEVEL, NULL); - else if (grTex->mipmap.flags & TF_TRANSPARENT) + else if (grTex->texture.flags & TF_TRANSPARENT) HWR_AddTransparentWall(wallVerts, &Surf, gl_toptexture, PF_Environment, false, lightnum, colormap); else HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); @@ -1250,7 +1250,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (gl_frontsector->numlights) HWR_SplitWall(gl_frontsector, wallVerts, gl_bottomtexture, &Surf, FF_CUTLEVEL, NULL); - else if (grTex->mipmap.flags & TF_TRANSPARENT) + else if (grTex->texture.flags & TF_TRANSPARENT) HWR_AddTransparentWall(wallVerts, &Surf, gl_bottomtexture, PF_Environment, false, lightnum, colormap); else HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); @@ -1258,7 +1258,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom gl_midtexture = R_GetTextureNum(gl_sidedef->midtexture); if (gl_midtexture) { - FBITFIELD blendmode; + UINT32 blendmode; sector_t *front, *back; fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; fixed_t texturevpeg = 0; @@ -1557,7 +1557,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom HWR_SplitWall(gl_frontsector, wallVerts, gl_midtexture, &Surf, FF_CUTLEVEL, NULL); else { - if (grTex->mipmap.flags & TF_TRANSPARENT) + if (grTex->texture.flags & TF_TRANSPARENT) HWR_AddTransparentWall(wallVerts, &Surf, gl_midtexture, PF_Environment, false, lightnum, colormap); else HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); @@ -1707,7 +1707,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } if (rover->flags & FF_FOG) { - FBITFIELD blendmode; + UINT32 blendmode; blendmode = PF_Fog|PF_NoTexture; @@ -1723,7 +1723,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else { - FBITFIELD blendmode = PF_Masked; + UINT32 blendmode = PF_Masked; if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256) { @@ -1819,7 +1819,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->flags & FF_FOG) { - FBITFIELD blendmode; + UINT32 blendmode; blendmode = PF_Fog|PF_NoTexture; @@ -1835,7 +1835,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else { - FBITFIELD blendmode = PF_Masked; + UINT32 blendmode = PF_Masked; if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256) { @@ -2656,7 +2656,7 @@ static inline void HWR_AddPolyObjectSegs(void) } static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t fixedheight, - FBITFIELD blendmode, UINT8 lightlevel, levelflat_t *levelflat, sector_t *FOFsector, + UINT32 blendmode, UINT8 lightlevel, levelflat_t *levelflat, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap) { float height; //constant y for all points on the convex flat polygon @@ -2875,7 +2875,7 @@ static void HWR_AddPolyObjectPlanes(void) if (po_ptrs[i]->translucency > 0) { FSurfaceInfo Surf; - FBITFIELD blendmode; + UINT32 blendmode; memset(&Surf, 0x00, sizeof(Surf)); blendmode = HWR_TranstableToAlpha(po_ptrs[i]->translucency, &Surf); HWR_AddTransparentPolyobjectFloor(&levelflats[polyobjsector->floorpic], po_ptrs[i], false, polyobjsector->floorheight, @@ -2898,7 +2898,7 @@ static void HWR_AddPolyObjectPlanes(void) if (po_ptrs[i]->translucency > 0) { FSurfaceInfo Surf; - FBITFIELD blendmode; + UINT32 blendmode; memset(&Surf, 0x00, sizeof(Surf)); blendmode = HWR_TranstableToAlpha(po_ptrs[i]->translucency, &Surf); HWR_AddTransparentPolyobjectFloor(&levelflats[polyobjsector->ceilingpic], po_ptrs[i], true, polyobjsector->ceilingheight, @@ -3506,9 +3506,9 @@ static void HWR_LinkDrawHackFinish(void) surf.PolyColor.rgba = 0xFFFFFFFF; surf.TintColor.rgba = 0xFFFFFFFF; surf.FadeColor.rgba = 0xFFFFFFFF; - surf.LightInfo.light_level = 0; - surf.LightInfo.fade_start = 0; - surf.LightInfo.fade_end = 31; + surf.LightInfo.LightLevel = 0; + surf.LightInfo.FadeStart = 0; + surf.LightInfo.FadeEnd = 31; for (i = 0; i < linkdrawcount; i++) { // draw sprite shape, only to z-buffer @@ -3588,7 +3588,7 @@ static void HWR_DrawDropShadow(mobj_t *thing, fixed_t scale) alpha = 255 - alpha; gpatch = (patch_t *)W_CachePatchName("DSHADOW", PU_SPRITE); - if (!(gpatch && ((GLPatch_t *)gpatch->hardware)->mipmap->format)) return; + if (!(gpatch && ((GLPatch_t *)gpatch->hardware)->texture->format)) return; HWR_GetPatch(gpatch); scalemul = FixedMul(FRACUNIT - floordiff/640, scale); @@ -3702,10 +3702,10 @@ static void HWR_SplitSprite(gl_vissprite_t *spr) patch_t *gpatch; FSurfaceInfo Surf; extracolormap_t *colormap = NULL; - FUINT lightlevel; + UINT32 lightlevel; boolean lightset = true; - FBITFIELD blend = 0; - FBITFIELD occlusion; + UINT32 blend = 0; + UINT32 occlusion; boolean use_linkdraw_hack = false; boolean splat = R_ThingIsFloorSprite(spr->mobj); UINT8 alpha; @@ -4219,8 +4219,8 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) } { - FBITFIELD blend = 0; - FBITFIELD occlusion; + UINT32 blend = 0; + UINT32 occlusion; boolean use_linkdraw_hack = false; // if sprite has linkdraw, then dont write to z-buffer (by not using PF_Occlude) @@ -4282,7 +4282,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) // Sprite drawer for precipitation static inline void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) { - FBITFIELD blend = 0; + UINT32 blend = 0; FOutVector wallVerts[4]; patch_t *gpatch; // sprite patch converted to hardware FSurfaceInfo Surf; @@ -4469,7 +4469,7 @@ typedef struct FOutVector wallVerts[4]; FSurfaceInfo Surf; INT32 texnum; - FBITFIELD blend; + UINT32 blend; INT32 drawcount; boolean fogwall; INT32 lightlevel; @@ -4479,7 +4479,7 @@ typedef struct static wallinfo_t *wallinfo = NULL; static size_t numwalls = 0; // a list of transparent walls to be drawn -void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); +void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, UINT32 blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); #define MAX_TRANSPARENTWALL 256 @@ -4492,7 +4492,7 @@ typedef struct levelflat_t *levelflat; INT32 alpha; sector_t *FOFSector; - FBITFIELD blend; + UINT32 blend; boolean fogplane; extracolormap_t *planecolormap; INT32 drawcount; @@ -4510,7 +4510,7 @@ typedef struct levelflat_t *levelflat; INT32 alpha; sector_t *FOFSector; - FBITFIELD blend; + UINT32 blend; extracolormap_t *planecolormap; INT32 drawcount; } polyplaneinfo_t; @@ -4535,7 +4535,7 @@ static INT32 drawcount = 0; #define MAX_TRANSPARENTFLOOR 512 // This will likely turn into a copy of HWR_Add3DWater and replace it. -void HWR_AddTransparentFloor(levelflat_t *levelflat, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, boolean fogplane, extracolormap_t *planecolormap) +void HWR_AddTransparentFloor(levelflat_t *levelflat, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, UINT32 blend, boolean fogplane, extracolormap_t *planecolormap) { static size_t allocedplanes = 0; @@ -4566,7 +4566,7 @@ void HWR_AddTransparentFloor(levelflat_t *levelflat, extrasubsector_t *xsub, boo // Adding this for now until I can create extrasubsector info for polyobjects // When that happens it'll just be done through HWR_AddTransparentFloor and HWR_RenderPlane -void HWR_AddTransparentPolyobjectFloor(levelflat_t *levelflat, polyobj_t *polysector, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, extracolormap_t *planecolormap) +void HWR_AddTransparentPolyobjectFloor(levelflat_t *levelflat, polyobj_t *polysector, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, UINT32 blend, extracolormap_t *planecolormap) { static size_t allocedpolyplanes = 0; @@ -4768,7 +4768,7 @@ static void HWR_DrawSprites(void) { UINT32 i; boolean skipshadow = false; // skip shadow if it was drawn already for a linkdraw sprite encountered earlier in the list - HWD.pfnSetSpecialState(HWD_SET_MODEL_LIGHTING, cv_glmodellighting.value); + HWD.pfnSetState(GPU_STATE_MODEL_LIGHTING, cv_glmodellighting.value); for (i = 0; i < gl_visspritecount; i++) { gl_vissprite_t *spr = gl_vsprorder[i]; @@ -4826,7 +4826,7 @@ static void HWR_DrawSprites(void) } } } - HWD.pfnSetSpecialState(HWD_SET_MODEL_LIGHTING, 0); + HWD.pfnSetState(GPU_STATE_MODEL_LIGHTING, 0); // At the end of sprite drawing, draw shapes of linkdraw sprites to z-buffer, so they // don't get drawn over by transparent surfaces. @@ -5420,9 +5420,9 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) // Sky dome rendering, ported from PrBoom+ // ========================================================================== -static gl_sky_t gl_sky; +static FSkyDome SkyDome; -static void HWR_SkyDomeVertex(gl_sky_t *sky, gl_skyvertex_t *vbo, int r, int c, signed char yflip, float delta, boolean foglayer) +static void HWR_SkyDomeVertex(FSkyDome *sky, FSkyVertex *vbo, int r, int c, signed char yflip, float delta, boolean foglayer) { const float radians = (float)(M_PIl / 180.0f); const float scale = 10000.0f; @@ -5466,7 +5466,7 @@ static void HWR_SkyDomeVertex(gl_sky_t *sky, gl_skyvertex_t *vbo, int r, int c, // Clears the sky dome. void HWR_ClearSkyDome(void) { - gl_sky_t *sky = &gl_sky; + FSkyDome *sky = &SkyDome; if (sky->loops) free(sky->loops); @@ -5495,8 +5495,8 @@ void HWR_BuildSkyDome(void) int col_count = 4; float delta; - gl_sky_t *sky = &gl_sky; - gl_skyvertex_t *vertex_p; + FSkyDome *sky = &SkyDome; + FSkyVertex *vertex_p; texture_t *texture = textures[texturetranslation[skytexture]]; sky->detail = 16; @@ -5525,7 +5525,7 @@ void HWR_BuildSkyDome(void) for (yflip = 0; yflip < 2; yflip++) { - sky->loops[sky->loopcount].mode = HWD_SKYLOOP_FAN; + sky->loops[sky->loopcount].mode = GPU_SKYLOOP_FAN; sky->loops[sky->loopcount].vertexindex = vertex_p - &sky->data[0]; sky->loops[sky->loopcount].vertexcount = col_count; sky->loops[sky->loopcount].use_texture = false; @@ -5547,7 +5547,7 @@ void HWR_BuildSkyDome(void) for (r = 0; r < row_count; r++) { - sky->loops[sky->loopcount].mode = HWD_SKYLOOP_STRIP; + sky->loops[sky->loopcount].mode = GPU_SKYLOOP_STRIP; sky->loops[sky->loopcount].vertexindex = vertex_p - &sky->data[0]; sky->loops[sky->loopcount].vertexcount = 2 * col_count + 2; sky->loops[sky->loopcount].use_texture = true; @@ -5604,7 +5604,7 @@ static void HWR_DrawSkyBackground(player_t *player) HWR_GetTexture(texturetranslation[skytexture]); - if (gl_sky.texture != texturetranslation[skytexture]) + if (SkyDome.texture != texturetranslation[skytexture]) { HWR_ClearSkyDome(); HWR_BuildSkyDome(); @@ -5612,7 +5612,7 @@ static void HWR_DrawSkyBackground(player_t *player) HWD.pfnSetShader(SHADER_SKY); // sky shader HWD.pfnSetTransform(&dometransform); - HWD.pfnRenderSkyDome(&gl_sky); + HWD.pfnRenderSkyDome(&SkyDome); } else { @@ -5787,12 +5787,12 @@ static void HWR_SetTransformAiming(FTransform *trans, player_t *player, boolean // static void HWR_SetShaderState(void) { - hwdshaderoption_t state = cv_glshaders.value; + INT32 state = cv_glshaders.value; if (!cv_glallowshaders.value) - state = (cv_glshaders.value == HWD_SHADEROPTION_ON ? HWD_SHADEROPTION_NOCUSTOM : cv_glshaders.value); + state = (cv_glshaders.value == GPU_SHADEROPTION_ON ? GPU_SHADEROPTION_NOCUSTOM : cv_glshaders.value); - HWD.pfnSetSpecialState(HWD_SET_SHADERS, (INT32)state); + HWD.pfnSetState(GPU_STATE_SHADERS, (INT32)state); HWD.pfnSetShader(SHADER_DEFAULT); } @@ -6012,7 +6012,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ClearColor.alpha = 1.0f; if (cv_glshaders.value) - HWD.pfnSetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. + HWD.pfnSetShaderInfo(GPU_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. if (viewnumber == 0) // Only do it if it's the first screen being rendered HWD.pfnClearBuffer(true, false, &ClearColor); // Clear the Color Buffer, stops HOMs. Also seems to fix the skybox issue on Intel GPUs. @@ -6239,7 +6239,7 @@ void HWR_LoadLevel(void) // 3D ENGINE COMMANDS // ========================================================================== -static CV_PossibleValue_t glshaders_cons_t[] = {{HWD_SHADEROPTION_OFF, "Off"}, {HWD_SHADEROPTION_ON, "On"}, {HWD_SHADEROPTION_NOCUSTOM, "Ignore custom shaders"}, {0, NULL}}; +static CV_PossibleValue_t glshaders_cons_t[] = {{GPU_SHADEROPTION_OFF, "Off"}, {GPU_SHADEROPTION_ON, "On"}, {GPU_SHADEROPTION_NOCUSTOM, "Ignore custom shaders"}, {0, NULL}}; static CV_PossibleValue_t glmodelinterpolation_cons_t[] = {{0, "Off"}, {1, "Sometimes"}, {2, "Always"}, {0, NULL}}; static CV_PossibleValue_t glfakecontrast_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "Smooth"}, {0, NULL}}; static CV_PossibleValue_t glshearing_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "Third-person"}, {0, NULL}}; @@ -6247,11 +6247,11 @@ static CV_PossibleValue_t glshearing_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "Thi static void CV_glfiltermode_OnChange(void); static void CV_glanisotropic_OnChange(void); -static CV_PossibleValue_t glfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"}, - {HWD_SET_TEXTUREFILTER_BILINEAR, "Bilinear"}, {HWD_SET_TEXTUREFILTER_TRILINEAR, "Trilinear"}, - {HWD_SET_TEXTUREFILTER_MIXED1, "Linear_Nearest"}, - {HWD_SET_TEXTUREFILTER_MIXED2, "Nearest_Linear"}, - {HWD_SET_TEXTUREFILTER_MIXED3, "Nearest_Mipmap"}, +static CV_PossibleValue_t glfiltermode_cons_t[]= {{GPU_TEXFILTER_POINTSAMPLED, "Nearest"}, + {GPU_TEXFILTER_BILINEAR, "Bilinear"}, {GPU_TEXFILTER_TRILINEAR, "Trilinear"}, + {GPU_TEXFILTER_MIXED1, "Linear_Nearest"}, + {GPU_TEXFILTER_MIXED2, "Nearest_Linear"}, + {GPU_TEXFILTER_MIXED3, "Nearest_Mipmap"}, {0, NULL}}; CV_PossibleValue_t glanisotropicmode_cons_t[] = {{1, "MIN"}, {16, "MAX"}, {0, NULL}}; @@ -6286,13 +6286,13 @@ consvar_t cv_glbatching = CVAR_INIT ("gr_batching", "On", 0, CV_OnOff, NULL); static void CV_glfiltermode_OnChange(void) { if (rendermode == render_opengl) - HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_glfiltermode.value); + HWD.pfnSetState(GPU_STATE_TEXTUREFILTERMODE, cv_glfiltermode.value); } static void CV_glanisotropic_OnChange(void) { if (rendermode == render_opengl) - HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_glanisotropicmode.value); + HWD.pfnSetState(GPU_STATE_TEXTUREANISOTROPICMODE, cv_glanisotropicmode.value); } //added by Hurdler: console varibale that are saved @@ -6358,9 +6358,7 @@ void HWR_Startup(void) gl_shadersavailable = false; } - if (rendermode == render_opengl) - textureformat = patchformat = GL_TEXFMT_RGBA; - + gl_patchformat = gl_textureformat = GPU_TEXFMT_RGBA; gl_init = true; } @@ -6374,8 +6372,8 @@ void HWR_Switch(void) HWR_AddSessionCommands(); // Set special states from CVARs - HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_glfiltermode.value); - HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_glanisotropicmode.value); + HWD.pfnSetState(GPU_STATE_TEXTUREFILTERMODE, cv_glfiltermode.value); + HWD.pfnSetState(GPU_STATE_TEXTUREANISOTROPICMODE, cv_glanisotropicmode.value); // Load textures if (!gl_maptexturesloaded) @@ -6383,10 +6381,7 @@ void HWR_Switch(void) // Create plane polygons if (!gl_maploaded && (gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN && titlemapinaction))) - { - HWR_ClearAllTextures(); HWR_LoadLevel(); - } } // -------------------------------------------------------------------------- @@ -6424,7 +6419,7 @@ void transform(float *cx, float *cy, float *cz) *cx *= gl_fovlud; } -void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) +void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, INT32 texnum, UINT32 blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) { static size_t allocedwalls = 0; @@ -6449,9 +6444,9 @@ void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, INT32 te numwalls++; } -void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) +void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, UINT32 blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) { - FBITFIELD blendmode = blend; + UINT32 blendmode = blend; UINT8 alpha = pSurf->PolyColor.s.alpha; // retain the alpha int shader; @@ -6666,7 +6661,7 @@ boolean HWR_CompileShaders(void) return HWD.pfnCompileShaders(); } -customshaderxlat_t shaderxlat[] = +FShaderReferenceArray shaderxlat[] = { {"Flat", SHADER_FLOOR}, {"WallTexture", SHADER_WALL}, diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 4ad09aa3d..d1de5c328 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -40,7 +40,7 @@ void HWR_SetViewSize(void); void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option); void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap); void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t scale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h); -void HWR_MakePatch(const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap); +void HWR_MakePatch(const patch_t *patch, GLPatch_t *grPatch, HWRTexture_t *hwrTexture, boolean makebitmap); void HWR_CreatePlanePolygons(INT32 bspnum); void HWR_CreateStaticLightmaps(INT32 bspnum); void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color); @@ -69,9 +69,9 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap); // Let's see if this can work UINT8 HWR_GetTranstableAlpha(INT32 transtablenum); -FBITFIELD HWR_GetBlendModeFlag(INT32 ast); -FBITFIELD HWR_SurfaceBlend(INT32 style, INT32 transtablenum, FSurfaceInfo *pSurf); -FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf); +UINT32 HWR_GetBlendModeFlag(INT32 ast); +UINT32 HWR_SurfaceBlend(INT32 style, INT32 transtablenum, FSurfaceInfo *pSurf); +UINT32 HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf); boolean HWR_CompileShaders(void); @@ -79,7 +79,7 @@ void HWR_LoadAllCustomShaders(void); void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3); const char *HWR_GetShaderName(INT32 shader); -extern customshaderxlat_t shaderxlat[]; +extern FShaderReferenceArray shaderxlat[]; extern CV_PossibleValue_t glanisotropicmode_cons_t[]; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 9c786e67e..64b20c716 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -201,7 +201,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ //CONS_Debug(DBG_RENDER, "libpng load error on %s\n", filename); png_destroy_read_struct(&png_ptr, &png_info_ptr, NULL); fclose(png_FILE); - Z_Free(grpatch->mipmap->data); + Z_Free(grpatch->texture->data); return 0; } #ifdef USE_FAR_KEYWORD @@ -242,7 +242,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ { png_uint_32 i, pitch = png_get_rowbytes(png_ptr, png_info_ptr); - png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRMODELTEXTURE, &grpatch->mipmap->data); + png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRMODELTEXTURE, &grpatch->texture->data); png_bytepp row_pointers = png_malloc(png_ptr, height * sizeof (png_bytep)); for (i = 0; i < height; i++) row_pointers[i] = PNG_image + i*pitch; @@ -255,7 +255,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ fclose(png_FILE); *w = (int)width; *h = (int)height; - return GL_TEXFMT_RGBA; + return GPU_TEXFMT_RGBA; } #endif @@ -322,7 +322,7 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h, pw = *w = header.xmax - header.xmin + 1; ph = *h = header.ymax - header.ymin + 1; - image = Z_Malloc(pw*ph*4, PU_HWRMODELTEXTURE, &grpatch->mipmap->data); + image = Z_Malloc(pw*ph*4, PU_HWRMODELTEXTURE, &grpatch->texture->data); if (fread(palette, sizeof (UINT8), PALSIZE, file) != PALSIZE) { @@ -356,7 +356,7 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h, } } fclose(file); - return GL_TEXFMT_RGBA; + return GPU_TEXFMT_RGBA; } // -----------------+ @@ -373,7 +373,7 @@ static void md2_loadTexture(md2_t *model) patch = model->grpatch; grPatch = (GLPatch_t *)(patch->hardware); if (grPatch) - Z_Free(grPatch->mipmap->data); + Z_Free(grPatch->texture->data); } else model->grpatch = patch = Patch_Create(NULL, 0, NULL); @@ -384,33 +384,33 @@ static void md2_loadTexture(md2_t *model) if (grPatch == NULL) grPatch = (GLPatch_t *)(patch->hardware); - if (!grPatch->mipmap->downloaded && !grPatch->mipmap->data) + if (!grPatch->texture->downloaded && !grPatch->texture->data) { int w = 0, h = 0; UINT32 size; RGBA_t *image; #ifdef HAVE_PNG - grPatch->mipmap->format = PNG_Load(filename, &w, &h, grPatch); - if (grPatch->mipmap->format == 0) + grPatch->texture->format = PNG_Load(filename, &w, &h, grPatch); + if (grPatch->texture->format == 0) #endif - grPatch->mipmap->format = PCX_Load(filename, &w, &h, grPatch); - if (grPatch->mipmap->format == 0) + grPatch->texture->format = PCX_Load(filename, &w, &h, grPatch); + if (grPatch->texture->format == 0) { model->notexturefile = true; // mark it so its not searched for again repeatedly return; } - grPatch->mipmap->downloaded = 0; - grPatch->mipmap->flags = 0; + grPatch->texture->downloaded = 0; + grPatch->texture->flags = 0; patch->width = (INT16)w; patch->height = (INT16)h; - grPatch->mipmap->width = (UINT16)w; - grPatch->mipmap->height = (UINT16)h; + grPatch->texture->width = (UINT16)w; + grPatch->texture->height = (UINT16)h; // Lactozilla: Apply colour cube - image = grPatch->mipmap->data; + image = grPatch->texture->data; size = w*h; while (size--) { @@ -418,7 +418,7 @@ static void md2_loadTexture(md2_t *model) image++; } } - HWD.pfnSetTexture(grPatch->mipmap); + HWD.pfnSetTexture(grPatch->texture); } // -----------------+ @@ -438,7 +438,7 @@ static void md2_loadBlendTexture(md2_t *model) patch = model->blendgrpatch; grPatch = (GLPatch_t *)(patch->hardware); if (grPatch) - Z_Free(grPatch->mipmap->data); + Z_Free(grPatch->texture->data); } else model->blendgrpatch = patch = Patch_Create(NULL, 0, NULL); @@ -449,30 +449,30 @@ static void md2_loadBlendTexture(md2_t *model) if (grPatch == NULL) grPatch = (GLPatch_t *)(patch->hardware); - if (!grPatch->mipmap->downloaded && !grPatch->mipmap->data) + if (!grPatch->texture->downloaded && !grPatch->texture->data) { int w = 0, h = 0; #ifdef HAVE_PNG - grPatch->mipmap->format = PNG_Load(filename, &w, &h, grPatch); - if (grPatch->mipmap->format == 0) + grPatch->texture->format = PNG_Load(filename, &w, &h, grPatch); + if (grPatch->texture->format == 0) #endif - grPatch->mipmap->format = PCX_Load(filename, &w, &h, grPatch); - if (grPatch->mipmap->format == 0) + grPatch->texture->format = PCX_Load(filename, &w, &h, grPatch); + if (grPatch->texture->format == 0) { model->noblendfile = true; // mark it so its not searched for again repeatedly Z_Free(filename); return; } - grPatch->mipmap->downloaded = 0; - grPatch->mipmap->flags = 0; + grPatch->texture->downloaded = 0; + grPatch->texture->flags = 0; patch->width = (INT16)w; patch->height = (INT16)h; - grPatch->mipmap->width = (UINT16)w; - grPatch->mipmap->height = (UINT16)h; + grPatch->texture->width = (UINT16)w; + grPatch->texture->height = (UINT16)h; } - HWD.pfnSetTexture(grPatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary + HWD.pfnSetTexture(grPatch->texture); // We do need to do this so that it can be cleared and knows to recreate it when necessary Z_Free(filename); } @@ -702,7 +702,7 @@ spritemodelfound: #define SETBRIGHTNESS(brightness,r,g,b) \ brightness = (UINT8)(((1063*(UINT16)(r))/5000) + ((3576*(UINT16)(g))/5000) + ((361*(UINT16)(b))/5000)) -static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMipmap_t *grMipmap, INT32 skinnum, skincolornum_t color) +static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, HWRTexture_t *hwrTexture, INT32 skinnum, skincolornum_t color) { GLPatch_t *hwrPatch = gpatch->hardware; GLPatch_t *hwrBlendPatch = blendgpatch->hardware; @@ -718,29 +718,29 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi memset(translation, 0, sizeof(translation)); memset(cutoff, 0, sizeof(cutoff)); - if (grMipmap->width == 0) + if (hwrTexture->width == 0) { - grMipmap->width = gpatch->width; - grMipmap->height = gpatch->height; + hwrTexture->width = gpatch->width; + hwrTexture->height = gpatch->height; // no wrap around, no chroma key - grMipmap->flags = 0; + hwrTexture->flags = 0; // setup the texture info - grMipmap->format = GL_TEXFMT_RGBA; + hwrTexture->format = GPU_TEXFMT_RGBA; } - if (grMipmap->data) + if (hwrTexture->data) { - Z_Free(grMipmap->data); - grMipmap->data = NULL; + Z_Free(hwrTexture->data); + hwrTexture->data = NULL; } - cur = Z_Malloc(size*4, PU_HWRMODELTEXTURE, &grMipmap->data); + cur = Z_Malloc(size*4, PU_HWRMODELTEXTURE, &hwrTexture->data); memset(cur, 0x00, size*4); - image = hwrPatch->mipmap->data; - blendimage = hwrBlendPatch->mipmap->data; + image = hwrPatch->texture->data; + blendimage = hwrBlendPatch->texture->data; // TC_METALSONIC includes an actual skincolor translation, on top of its flashing. if (skinnum == TC_METALSONIC) @@ -1084,34 +1084,34 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendpatch, INT32 ski // mostly copied from HWR_GetMappedPatch, hence the similarities and comment GLPatch_t *grPatch = patch->hardware; GLPatch_t *grBlendPatch = NULL; - GLMipmap_t *grMipmap, *newMipmap; + HWRTexture_t *hwrTexture, *newTexture; if (blendpatch == NULL || colormap == colormaps || colormap == NULL) { // Don't do any blending - HWD.pfnSetTexture(grPatch->mipmap); + HWD.pfnSetTexture(grPatch->texture); return; } - if ((blendpatch && (grBlendPatch = blendpatch->hardware) && grBlendPatch->mipmap->format) + if ((blendpatch && (grBlendPatch = blendpatch->hardware) && grBlendPatch->texture->format) && (patch->width != blendpatch->width || patch->height != blendpatch->height)) { // Blend image exists, but it's bad. - HWD.pfnSetTexture(grPatch->mipmap); + HWD.pfnSetTexture(grPatch->texture); return; } - // search for the mipmap + // search for the texture // skip the first (no colormap translated) - for (grMipmap = grPatch->mipmap; grMipmap->nextcolormap; ) + for (hwrTexture = grPatch->texture; hwrTexture->nextcolormap; ) { - grMipmap = grMipmap->nextcolormap; - if (grMipmap->colormap == colormap) + hwrTexture = hwrTexture->nextcolormap; + if (hwrTexture->colormap == colormap) { - if (grMipmap->downloaded && grMipmap->data) + if (hwrTexture->downloaded && hwrTexture->data) { - HWD.pfnSetTexture(grMipmap); // found the colormap, set it to the correct texture - Z_ChangeTag(grMipmap->data, PU_HWRMODELTEXTURE_UNLOCKED); + HWD.pfnSetTexture(hwrTexture); // found the colormap, set it to the correct texture + Z_ChangeTag(hwrTexture->data, PU_HWRMODELTEXTURE_UNLOCKED); return; } } @@ -1119,21 +1119,16 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendpatch, INT32 ski // If here, the blended texture has not been created // So we create it - - //BP: WARNING: don't free it manually without clearing the cache of harware renderer - // (it have a liste of mipmap) - // this malloc is cleared in HWR_FreeColormapCache - // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better - newMipmap = calloc(1, sizeof (*newMipmap)); - if (newMipmap == NULL) + newTexture = calloc(1, sizeof (*newTexture)); + if (newTexture == NULL) I_Error("%s: Out of memory", "HWR_GetBlendedTexture"); - grMipmap->nextcolormap = newMipmap; - newMipmap->colormap = colormap; + hwrTexture->nextcolormap = newTexture; + newTexture->colormap = colormap; - HWR_CreateBlendedTexture(patch, blendpatch, newMipmap, skinnum, color); + HWR_CreateBlendedTexture(patch, blendpatch, newTexture, skinnum, color); - HWD.pfnSetTexture(newMipmap); - Z_ChangeTag(newMipmap->data, PU_HWRMODELTEXTURE_UNLOCKED); + HWD.pfnSetTexture(newTexture); + Z_ChangeTag(newTexture->data, PU_HWRMODELTEXTURE_UNLOCKED); } #define NORMALFOG 0x00000000 @@ -1376,7 +1371,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) hwrPatch = ((GLPatch_t *)gpatch->hardware); if (!gpatch || !hwrPatch - || ((!hwrPatch->mipmap->format || !hwrPatch->mipmap->downloaded) && !md2->notexturefile)) + || ((!hwrPatch->texture->format || !hwrPatch->texture->downloaded) && !md2->notexturefile)) md2_loadTexture(md2); // Load it again, because it isn't being loaded into gpatch after md2_loadtexture... @@ -1389,9 +1384,9 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) if (blendgpatch) hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware); - if ((gpatch && hwrPatch && hwrPatch->mipmap->format) // don't load the blend texture if the base texture isn't available + if ((gpatch && hwrPatch && hwrPatch->texture->format) // don't load the blend texture if the base texture isn't available && (!blendgpatch || !hwrBlendPatch - || ((!hwrBlendPatch->mipmap->format || !hwrBlendPatch->mipmap->downloaded) && !md2->noblendfile))) + || ((!hwrBlendPatch->texture->format || !hwrBlendPatch->texture->downloaded) && !md2->noblendfile))) md2_loadBlendTexture(md2); if (md2->error) @@ -1407,7 +1402,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) md2_printModelInfo(md2->model); // If model uses sprite patch as texture, then // adjust texture coordinates to take power of two textures into account - if (!gpatch || !hwrPatch->mipmap->format) + if (!gpatch || !hwrPatch->texture->format) adjustTextureCoords(md2->model, spr->gpatch); // note down the max_s and max_t that end up in the VBO md2->model->vbo_max_s = md2->model->max_s; @@ -1426,7 +1421,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) finalscale = md2->scale; //Hurdler: arf, I don't like that implementation at all... too much crappy - if (gpatch && hwrPatch && hwrPatch->mipmap->format) // else if meant that if a texture couldn't be loaded, it would just end up using something else's texture + if (gpatch && hwrPatch && hwrPatch->texture->format) // else if meant that if a texture couldn't be loaded, it would just end up using something else's texture { INT32 skinnum = TC_DEFAULT; diff --git a/src/hardware/r_opengl/ogl_win.c b/src/hardware/r_opengl/ogl_win.c index c9bf60144..9e37abbe1 100644 --- a/src/hardware/r_opengl/ogl_win.c +++ b/src/hardware/r_opengl/ogl_win.c @@ -58,7 +58,6 @@ PFNglGetString pglGetString; #define MAX_VIDEO_MODES 32 static vmode_t video_modes[MAX_VIDEO_MODES]; -INT32 oglflags = 0; // ************************************************************************** // FUNCTIONS @@ -239,7 +238,6 @@ int SetupPixelFormat(INT32 WantColorBits, INT32 WantStencilBits, INT32 WantDepth // -----------------+ static INT32 WINAPI SetRes(viddef_t *lvid, vmode_t *pcurrentmode) { - LPCSTR renderer; BOOL WantFullScreen = !(lvid->u.windowed); //(lvid->u.windowed ? 0 : CDS_FULLSCREEN); UNREFERENCED_PARAMETER(pcurrentmode); @@ -332,40 +330,37 @@ static INT32 WINAPI SetRes(viddef_t *lvid, vmode_t *pcurrentmode) } } - gl_extensions = pglGetString(GL_EXTENSIONS); // Get info and extensions. //BP: why don't we make it earlier ? //Hurdler: we cannot do that before intialising gl context - renderer = (LPCSTR)pglGetString(GL_RENDERER); - GL_DBG_Printf("Vendor : %s\n", pglGetString(GL_VENDOR)); - GL_DBG_Printf("Renderer : %s\n", renderer); - GL_DBG_Printf("Version : %s\n", pglGetString(GL_VERSION)); - GL_DBG_Printf("Extensions : %s\n", gl_extensions); + GLVersion = pglGetString(GL_VERSION); + GLRenderer = pglGetString(GL_RENDERER); + GLExtensions = pglGetString(GL_EXTENSIONS); - // BP: disable advenced feature that don't work on somes hardware - // Hurdler: Now works on G400 with bios 1.6 and certified drivers 6.04 - if (strstr(renderer, "810")) oglflags |= GLF_NOZBUFREAD; - GL_DBG_Printf("oglflags : 0x%X\n", oglflags); + GL_DBG_Printf("OpenGL %s\n", GLVersion); + GL_DBG_Printf("GPU: %s\n", GLRenderer); + GL_DBG_Printf("Vendor: %s\n", pglGetString(GL_VENDOR)); + GL_DBG_Printf("Extensions: %s\n", GLExtensions); #ifdef USE_WGL_SWAP - if (isExtAvailable("WGL_EXT_swap_control",gl_extensions)) + if (isExtAvailable("WGL_EXT_swap_control", GLExtensions)) wglSwapIntervalEXT = GetGLFunc("wglSwapIntervalEXT"); else wglSwapIntervalEXT = NULL; #endif - if (isExtAvailable("GL_EXT_texture_filter_anisotropic",gl_extensions)) - pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); + if (isExtAvailable("GL_EXT_texture_filter_anisotropic", GLExtensions)) + pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &GPUMaximumAnisotropy); else - maximumAnisotropy = 0; + GPUMaximumAnisotropy = 0; SetupGLFunc13(); - screen_depth = (GLbyte)(lvid->bpp*8); - if (screen_depth > 16) - textureformatGL = GL_RGBA; + GPUScreenDepth = (GLbyte)(lvid->bpp*8); + if (GPUScreenDepth > 16) + GPUTextureFormat = GL_RGBA; else - textureformatGL = GL_RGB5_A1; + GPUTextureFormat = GL_RGB5_A1; SetModelView(lvid->width, lvid->height); SetStates(); @@ -568,9 +563,9 @@ EXPORT void HWRAPI(SetPalette) (RGBA_t *pal) { size_t palsize = (sizeof(RGBA_t) * 256); // on a palette change, you have to reload all of the textures - if (memcmp(&myPaletteData, pal, palsize)) + if (memcmp(&GPUTexturePalette, pal, palsize)) { - memcpy(&myPaletteData, pal, palsize); + memcpy(&GPUTexturePalette, pal, palsize); Flush(); } } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 8cd948eea..096fb482e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -40,92 +40,56 @@ static const GLubyte white[4] = { 255, 255, 255, 255 }; // CONSTANTS // ========================================================================== -// With OpenGL 1.1+, the first texture should be 1 -static GLuint NOTEXTURE_NUM = 0; - -#define N_PI_DEMI (M_PIl/2.0f) //(1.5707963268f) - #define ASPECT_RATIO (1.0f) //(320.0f/200.0f) +#define FIELD_OF_VIEW 90.0f + #define FAR_CLIPPING_PLANE 32768.0f // Draw further! Tails 01-21-2001 static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; +#define N_PI_DEMI (M_PIl/2.0f) //(1.5707963268f) + // ************************************************************************** // GLOBALS // ************************************************************************** +RGBA_t GPUTexturePalette[256]; +GLint GPUTextureFormat; +GLint GPUScreenWidth, GPUScreenHeight; +GLbyte GPUScreenDepth; +GLint GPUMaximumAnisotropy = 0; -static GLuint tex_downloaded = 0; -static GLfloat fov = 90.0f; -static FBITFIELD CurrentPolyFlags; +// Linked list of all textures. +static FTextureInfo *TexCacheTail = NULL; +static FTextureInfo *TexCacheHead = NULL; -static FTextureInfo *gl_cachetail = NULL; -static FTextureInfo *gl_cachehead = NULL; +static GLuint CurrentTexture = 0; +static GLuint BlankTexture = 0; // With OpenGL 1.1+, the first texture should be 1 -RGBA_t myPaletteData[256]; -GLint screen_width = 0; // used by Draw2DLine() -GLint screen_height = 0; -GLbyte screen_depth = 0; -GLint textureformatGL = 0; -GLint maximumAnisotropy = 0; -static GLboolean MipMap = GL_FALSE; -static GLint min_filter = GL_LINEAR; -static GLint mag_filter = GL_LINEAR; -static GLint anisotropic_filter = 0; -static boolean model_lighting = false; +static GLuint ScreenTexture = 0; +static GLuint FinalScreenTexture = 0; +static GLuint WipeStartTexture = 0; +static GLuint WipeEndTexture = 0; -const GLubyte *gl_version = NULL; -const GLubyte *gl_renderer = NULL; -const GLubyte *gl_extensions = NULL; +static UINT32 CurrentPolyFlags; -//Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) -static GLfloat modelMatrix[16]; -static GLfloat projMatrix[16]; -static GLint viewport[4]; +static GLboolean MipmappingEnabled = GL_FALSE; +static GLboolean ModelLightingEnabled = GL_FALSE; -// Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing -// flush all of the stored textures, leaving them unavailable at times such as between levels -// These need to start at 0 and be set to their number, and be reset to 0 when deleted so that intel GPUs -// can know when the textures aren't there, as textures are always considered resident in their virtual memory -static GLuint screentexture = 0; -static GLuint startScreenWipe = 0; -static GLuint endScreenWipe = 0; -static GLuint finalScreenTexture = 0; +static GLint MipmapMinFilter = GL_LINEAR; +static GLint MipmapMagFilter = GL_LINEAR; +static GLint AnisotropicFilter = 0; + +const GLubyte *GLVersion = NULL; +const GLubyte *GLRenderer = NULL; +const GLubyte *GLExtensions = NULL; + +// Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) +static GLfloat ModelMatrix[16]; +static GLfloat ProjectionMatrix[16]; +static GLint SceneViewport[4]; // shortcut for ((float)1/i) -static const GLfloat byte2float[256] = { - 0.000000f, 0.003922f, 0.007843f, 0.011765f, 0.015686f, 0.019608f, 0.023529f, 0.027451f, - 0.031373f, 0.035294f, 0.039216f, 0.043137f, 0.047059f, 0.050980f, 0.054902f, 0.058824f, - 0.062745f, 0.066667f, 0.070588f, 0.074510f, 0.078431f, 0.082353f, 0.086275f, 0.090196f, - 0.094118f, 0.098039f, 0.101961f, 0.105882f, 0.109804f, 0.113725f, 0.117647f, 0.121569f, - 0.125490f, 0.129412f, 0.133333f, 0.137255f, 0.141176f, 0.145098f, 0.149020f, 0.152941f, - 0.156863f, 0.160784f, 0.164706f, 0.168627f, 0.172549f, 0.176471f, 0.180392f, 0.184314f, - 0.188235f, 0.192157f, 0.196078f, 0.200000f, 0.203922f, 0.207843f, 0.211765f, 0.215686f, - 0.219608f, 0.223529f, 0.227451f, 0.231373f, 0.235294f, 0.239216f, 0.243137f, 0.247059f, - 0.250980f, 0.254902f, 0.258824f, 0.262745f, 0.266667f, 0.270588f, 0.274510f, 0.278431f, - 0.282353f, 0.286275f, 0.290196f, 0.294118f, 0.298039f, 0.301961f, 0.305882f, 0.309804f, - 0.313726f, 0.317647f, 0.321569f, 0.325490f, 0.329412f, 0.333333f, 0.337255f, 0.341176f, - 0.345098f, 0.349020f, 0.352941f, 0.356863f, 0.360784f, 0.364706f, 0.368627f, 0.372549f, - 0.376471f, 0.380392f, 0.384314f, 0.388235f, 0.392157f, 0.396078f, 0.400000f, 0.403922f, - 0.407843f, 0.411765f, 0.415686f, 0.419608f, 0.423529f, 0.427451f, 0.431373f, 0.435294f, - 0.439216f, 0.443137f, 0.447059f, 0.450980f, 0.454902f, 0.458824f, 0.462745f, 0.466667f, - 0.470588f, 0.474510f, 0.478431f, 0.482353f, 0.486275f, 0.490196f, 0.494118f, 0.498039f, - 0.501961f, 0.505882f, 0.509804f, 0.513726f, 0.517647f, 0.521569f, 0.525490f, 0.529412f, - 0.533333f, 0.537255f, 0.541177f, 0.545098f, 0.549020f, 0.552941f, 0.556863f, 0.560784f, - 0.564706f, 0.568627f, 0.572549f, 0.576471f, 0.580392f, 0.584314f, 0.588235f, 0.592157f, - 0.596078f, 0.600000f, 0.603922f, 0.607843f, 0.611765f, 0.615686f, 0.619608f, 0.623529f, - 0.627451f, 0.631373f, 0.635294f, 0.639216f, 0.643137f, 0.647059f, 0.650980f, 0.654902f, - 0.658824f, 0.662745f, 0.666667f, 0.670588f, 0.674510f, 0.678431f, 0.682353f, 0.686275f, - 0.690196f, 0.694118f, 0.698039f, 0.701961f, 0.705882f, 0.709804f, 0.713726f, 0.717647f, - 0.721569f, 0.725490f, 0.729412f, 0.733333f, 0.737255f, 0.741177f, 0.745098f, 0.749020f, - 0.752941f, 0.756863f, 0.760784f, 0.764706f, 0.768627f, 0.772549f, 0.776471f, 0.780392f, - 0.784314f, 0.788235f, 0.792157f, 0.796078f, 0.800000f, 0.803922f, 0.807843f, 0.811765f, - 0.815686f, 0.819608f, 0.823529f, 0.827451f, 0.831373f, 0.835294f, 0.839216f, 0.843137f, - 0.847059f, 0.850980f, 0.854902f, 0.858824f, 0.862745f, 0.866667f, 0.870588f, 0.874510f, - 0.878431f, 0.882353f, 0.886275f, 0.890196f, 0.894118f, 0.898039f, 0.901961f, 0.905882f, - 0.909804f, 0.913726f, 0.917647f, 0.921569f, 0.925490f, 0.929412f, 0.933333f, 0.937255f, - 0.941177f, 0.945098f, 0.949020f, 0.952941f, 0.956863f, 0.960784f, 0.964706f, 0.968628f, - 0.972549f, 0.976471f, 0.980392f, 0.984314f, 0.988235f, 0.992157f, 0.996078f, 1.000000f -}; +#define byte2float(x) (x / 255.0f) // -----------------+ // GL_DBG_Printf : Output debug messages to debug log if DEBUG_TO_FILE is defined, @@ -530,8 +494,8 @@ boolean SetupGLfunc(void) return true; } -static boolean gl_shadersenabled = false; -static hwdshaderoption_t gl_allowshaders = HWD_SHADEROPTION_OFF; +static GLboolean ShadersEnabled = GL_FALSE; +static INT32 ShadersAllowed = GPU_SHADEROPTION_OFF; #ifdef GL_SHADERS typedef GLuint (APIENTRY *PFNglCreateShader) (GLenum); @@ -578,53 +542,52 @@ static PFNglUniform2fv pglUniform2fv; static PFNglUniform3fv pglUniform3fv; static PFNglGetUniformLocation pglGetUniformLocation; -// 13062019 -typedef enum +enum EShaderUniform { // lighting - gluniform_poly_color, - gluniform_tint_color, - gluniform_fade_color, - gluniform_lighting, - gluniform_fade_start, - gluniform_fade_end, + uniform_poly_color, + uniform_tint_color, + uniform_fade_color, + uniform_lighting, + uniform_fade_start, + uniform_fade_end, // misc. (custom shaders) - gluniform_leveltime, + uniform_leveltime, - gluniform_max, -} gluniform_t; + uniform_max, +}; -typedef struct gl_shader_s +typedef struct FShaderObject { GLuint program; - GLint uniforms[gluniform_max+1]; + GLint uniforms[uniform_max+1]; boolean custom; -} gl_shader_t; +} FShaderObject; -static gl_shader_t gl_shaders[HWR_MAXSHADERS]; -static gl_shader_t gl_usershaders[HWR_MAXSHADERS]; -static shadersource_t gl_customshaders[HWR_MAXSHADERS]; +static FShaderObject ShaderObjects[HWR_MAXSHADERS]; +static FShaderObject UserShaderObjects[HWR_MAXSHADERS]; +static FShaderSource CustomShaders[HWR_MAXSHADERS]; // 09102020 -typedef struct gl_shaderstate_s +typedef struct FShaderState { - gl_shader_t *current; + FShaderObject *current; GLuint type; GLuint program; boolean changed; -} gl_shaderstate_t; -static gl_shaderstate_t gl_shaderstate; +} FShaderState; +static FShaderState ShaderState; // Shader info -static INT32 shader_leveltime = 0; +static INT32 ShaderLevelTime = 0; // Lactozilla: Shader functions -static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i, const GLchar *vert_shader, const GLchar *frag_shader); +static boolean Shader_CompileProgram(FShaderObject *shader, GLint i, const GLchar *vert_shader, const GLchar *frag_shader); static void Shader_CompileError(const char *message, GLuint program, INT32 shadernum); static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade); -static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f}; +static GLRGBAFloat ShaderDefaultColor = {1.0f, 1.0f, 1.0f, 1.0f}; // ================ // Vertex shaders @@ -918,20 +881,20 @@ EXPORT boolean HWRAPI(CompileShaders) (void) if (!pglUseProgram) return false; - gl_customshaders[SHADER_DEFAULT].vertex = NULL; - gl_customshaders[SHADER_DEFAULT].fragment = NULL; + CustomShaders[SHADER_DEFAULT].vertex = NULL; + CustomShaders[SHADER_DEFAULT].fragment = NULL; for (i = 0; gl_shadersources[i].vertex && gl_shadersources[i].fragment; i++) { - gl_shader_t *shader, *usershader; + FShaderObject *shader, *usershader; const GLchar *vert_shader = gl_shadersources[i].vertex; const GLchar *frag_shader = gl_shadersources[i].fragment; if (i >= HWR_MAXSHADERS) break; - shader = &gl_shaders[i]; - usershader = &gl_usershaders[i]; + shader = &ShaderObjects[i]; + usershader = &UserShaderObjects[i]; if (shader->program) pglDeleteProgram(shader->program); @@ -945,14 +908,14 @@ EXPORT boolean HWRAPI(CompileShaders) (void) shader->program = 0; // Compile custom shader - if ((i == SHADER_DEFAULT) || !(gl_customshaders[i].vertex || gl_customshaders[i].fragment)) + if ((i == SHADER_DEFAULT) || !(CustomShaders[i].vertex || CustomShaders[i].fragment)) continue; // 18032019 - if (gl_customshaders[i].vertex) - vert_shader = gl_customshaders[i].vertex; - if (gl_customshaders[i].fragment) - frag_shader = gl_customshaders[i].fragment; + if (CustomShaders[i].vertex) + vert_shader = CustomShaders[i].vertex; + if (CustomShaders[i].fragment) + frag_shader = CustomShaders[i].fragment; if (!Shader_CompileProgram(usershader, i, vert_shader, frag_shader)) { @@ -974,13 +937,13 @@ EXPORT boolean HWRAPI(CompileShaders) (void) // Those are given to the uniforms. // -EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value) +EXPORT void HWRAPI(SetShaderInfo) (INT32 info, INT32 value) { #ifdef GL_SHADERS switch (info) { - case HWD_SHADERINFO_LEVELTIME: - shader_leveltime = value; + case GPU_SHADERINFO_LEVELTIME: + ShaderLevelTime = value; break; default: break; @@ -997,7 +960,7 @@ EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value) EXPORT void HWRAPI(LoadCustomShader) (int number, char *code, size_t size, boolean isfragment) { #ifdef GL_SHADERS - shadersource_t *shader; + FShaderSource *shader; if (!pglUseProgram) return; @@ -1007,7 +970,7 @@ EXPORT void HWRAPI(LoadCustomShader) (int number, char *code, size_t size, boole else if (code == NULL) I_Error("LoadCustomShader: empty shader"); - shader = &gl_customshaders[number]; + shader = &CustomShaders[number]; #define COPYSHADER(source) { \ if (shader->source) \ @@ -1033,58 +996,58 @@ EXPORT void HWRAPI(LoadCustomShader) (int number, char *code, size_t size, boole EXPORT void HWRAPI(SetShader) (int type) { #ifdef GL_SHADERS - if (gl_allowshaders != HWD_SHADEROPTION_OFF) + if (ShadersAllowed != GPU_SHADEROPTION_OFF) { - gl_shader_t *shader = gl_shaderstate.current; + FShaderObject *shader = ShaderState.current; // If using model lighting, set the appropriate shader. // However don't override a custom shader. - if (type == SHADER_MODEL && model_lighting - && !(gl_shaders[SHADER_MODEL].custom && !gl_shaders[SHADER_MODEL_LIGHTING].custom)) + if (type == SHADER_MODEL && ModelLightingEnabled + && !(ShaderObjects[SHADER_MODEL].custom && !ShaderObjects[SHADER_MODEL_LIGHTING].custom)) type = SHADER_MODEL_LIGHTING; - if ((shader == NULL) || (GLuint)type != gl_shaderstate.type) + if ((shader == NULL) || (GLuint)type != ShaderState.type) { - gl_shader_t *baseshader = &gl_shaders[type]; - gl_shader_t *usershader = &gl_usershaders[type]; + FShaderObject *baseshader = &ShaderObjects[type]; + FShaderObject *usershader = &UserShaderObjects[type]; if (usershader->program) - shader = (gl_allowshaders == HWD_SHADEROPTION_NOCUSTOM) ? baseshader : usershader; + shader = (ShadersAllowed == GPU_SHADEROPTION_NOCUSTOM) ? baseshader : usershader; else shader = baseshader; - gl_shaderstate.current = shader; - gl_shaderstate.type = type; - gl_shaderstate.changed = true; + ShaderState.current = shader; + ShaderState.type = type; + ShaderState.changed = true; } - if (gl_shaderstate.program != shader->program) + if (ShaderState.program != shader->program) { - gl_shaderstate.program = shader->program; - gl_shaderstate.changed = true; + ShaderState.program = shader->program; + ShaderState.changed = true; } - gl_shadersenabled = (shader->program != 0); + ShadersEnabled = (shader->program != 0) ? GL_TRUE : GL_FALSE; return; } #else (void)type; #endif - gl_shadersenabled = false; + ShadersEnabled = GL_FALSE; } EXPORT void HWRAPI(UnSetShader) (void) { #ifdef GL_SHADERS - gl_shaderstate.current = NULL; - gl_shaderstate.type = 0; - gl_shaderstate.program = 0; + ShaderState.current = NULL; + ShaderState.type = 0; + ShaderState.program = 0; if (pglUseProgram) pglUseProgram(0); #endif - gl_shadersenabled = false; + ShadersEnabled = GL_FALSE; } EXPORT void HWRAPI(CleanShaders) (void) @@ -1093,7 +1056,7 @@ EXPORT void HWRAPI(CleanShaders) (void) for (i = 1; i < HWR_MAXSHADERS; i++) { - shadersource_t *shader = &gl_customshaders[i]; + FShaderSource *shader = &CustomShaders[i]; if (shader->vertex) free(shader->vertex); @@ -1112,12 +1075,19 @@ EXPORT void HWRAPI(CleanShaders) (void) static void SetNoTexture(void) { // Disable texture. - if (tex_downloaded != NOTEXTURE_NUM) + if (CurrentTexture != BlankTexture) { - if (NOTEXTURE_NUM == 0) - pglGenTextures(1, &NOTEXTURE_NUM); - pglBindTexture(GL_TEXTURE_2D, NOTEXTURE_NUM); - tex_downloaded = NOTEXTURE_NUM; + if (BlankTexture == 0) + { + // Generate a 1x1 white pixel for the blank texture + pglGenTextures(1, &BlankTexture); + pglBindTexture(GL_TEXTURE_2D, BlankTexture); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, white); + } + else + pglBindTexture(GL_TEXTURE_2D, BlankTexture); + + CurrentTexture = BlankTexture; } } @@ -1160,18 +1130,18 @@ static void GLProject(GLfloat objX, GLfloat objY, GLfloat objZ, for (i=0; i<4; i++) { out[i] = - objX * modelMatrix[0*4+i] + - objY * modelMatrix[1*4+i] + - objZ * modelMatrix[2*4+i] + - modelMatrix[3*4+i]; + objX * ModelMatrix[0*4+i] + + objY * ModelMatrix[1*4+i] + + objZ * ModelMatrix[2*4+i] + + ModelMatrix[3*4+i]; } for (i=0; i<4; i++) { in[i] = - out[0] * projMatrix[0*4+i] + - out[1] * projMatrix[1*4+i] + - out[2] * projMatrix[2*4+i] + - out[3] * projMatrix[3*4+i]; + out[0] * ProjectionMatrix[0*4+i] + + out[1] * ProjectionMatrix[1*4+i] + + out[2] * ProjectionMatrix[2*4+i] + + out[3] * ProjectionMatrix[3*4+i]; } if (fpclassify(in[3]) == FP_ZERO) return; in[0] /= in[3]; @@ -1183,8 +1153,8 @@ static void GLProject(GLfloat objX, GLfloat objY, GLfloat objZ, in[2] = in[2] * 0.5f + 0.5f; /* Map x,y to viewport */ - in[0] = in[0] * viewport[2] + viewport[0]; - in[1] = in[1] * viewport[3] + viewport[1]; + in[0] = in[0] * SceneViewport[2] + SceneViewport[0]; + in[1] = in[1] * SceneViewport[3] + SceneViewport[1]; *winX=in[0]; *winY=in[1]; @@ -1199,11 +1169,11 @@ void SetModelView(GLint w, GLint h) // GL_DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h); // The screen textures need to be flushed if the width or height change so that they be remade for the correct size - if (screen_width != w || screen_height != h) + if (GPUScreenWidth != w || GPUScreenHeight != h) FlushScreenTextures(); - screen_width = w; - screen_height = h; + GPUScreenWidth = w; + GPUScreenHeight = h; pglViewport(0, 0, w, h); @@ -1213,12 +1183,12 @@ void SetModelView(GLint w, GLint h) pglMatrixMode(GL_MODELVIEW); pglLoadIdentity(); - GLPerspective(fov, ASPECT_RATIO); + GLPerspective(FIELD_OF_VIEW, ASPECT_RATIO); //pglScalef(1.0f, 320.0f/200.0f, 1.0f); // gl_scalefrustum (ORIGINAL_ASPECT) // added for new coronas' code (without depth buffer) - pglGetIntegerv(GL_VIEWPORT, viewport); - pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); + pglGetIntegerv(GL_VIEWPORT, SceneViewport); + pglGetFloatv(GL_PROJECTION_MATRIX, ProjectionMatrix); } @@ -1261,7 +1231,7 @@ void SetStates(void) CurrentPolyFlags = 0xffffffff; SetBlend(0); - tex_downloaded = 0; + CurrentTexture = 0; SetNoTexture(); pglPolygonOffset(-1.0f, -1.0f); @@ -1280,17 +1250,37 @@ void SetStates(void) // bp : when no t&l :) pglLoadIdentity(); pglScalef(1.0f, 1.0f, -1.0f); - pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) + pglGetFloatv(GL_MODELVIEW_MATRIX, ModelMatrix); // added for new coronas' code (without depth buffer) } // -----------------+ // DeleteTexture : Deletes a texture from the GPU and frees its data // -----------------+ -EXPORT void HWRAPI(DeleteTexture) (FTextureInfo *pTexInfo) +EXPORT void HWRAPI(DeleteTexture) (HWRTexture_t *pTexInfo) { - if (pTexInfo->downloaded) + FTextureInfo *head = TexCacheHead; + + if (!pTexInfo) + return; + else if (pTexInfo->downloaded) pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded); + + while (head) + { + if (head->name == pTexInfo->downloaded) + { + if (head->next) + head->next->prev = head->prev; + if (head->prev) + head->prev->next = head->next; + free(head); + break; + } + + head = head->next; + } + pTexInfo->downloaded = 0; } @@ -1303,23 +1293,26 @@ void Flush(void) { //GL_DBG_Printf ("HWR_Flush()\n"); - while (gl_cachehead) + while (TexCacheHead) { - DeleteTexture(gl_cachehead); - gl_cachehead = gl_cachehead->nextmipmap; + FTextureInfo *pTexInfo = TexCacheHead; + HWRTexture_t *texture = pTexInfo->texture; + + if (pTexInfo->name) + { + pglDeleteTextures(1, (GLuint *)&pTexInfo->name); + pTexInfo->name = 0; + } + + if (texture) + texture->downloaded = 0; + + TexCacheHead = pTexInfo->next; + free(pTexInfo); } - ClearCacheList(); //Hurdler: well, gl_cachehead is already NULL - tex_downloaded = 0; -} - - -// -----------------+ -// ClearCacheList : Clears the texture cache tail and head -// -----------------+ -EXPORT void HWRAPI(ClearCacheList) (void) -{ - gl_cachetail = gl_cachehead = NULL; + TexCacheTail = TexCacheHead = NULL; // Hurdler: well, TexCacheHead is already NULL + CurrentTexture = 0; } @@ -1362,9 +1355,9 @@ EXPORT boolean HWRAPI(Init) (void) // -----------------+ -// ClearMipMapCache : Flush OpenGL textures from memory +// ClearTextureCache: Flush OpenGL textures from memory // -----------------+ -EXPORT void HWRAPI(ClearMipMapCache) (void) +EXPORT void HWRAPI(ClearTextureCache) (void) { // GL_DBG_Printf ("HWR_Flush(exe)\n"); Flush(); @@ -1430,27 +1423,25 @@ EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, f { // GL_DBG_Printf ("GClipRect(%d, %d, %d, %d)\n", minx, miny, maxx, maxy); - pglViewport(minx, screen_height-maxy, maxx-minx, maxy-miny); + pglViewport(minx, GPUScreenHeight-maxy, maxx-minx, maxy-miny); NEAR_CLIPPING_PLANE = nearclip; - //pglScissor(minx, screen_height-maxy, maxx-minx, maxy-miny); + //pglScissor(minx, GPUScreenHeight-maxy, maxx-minx, maxy-miny); pglMatrixMode(GL_PROJECTION); pglLoadIdentity(); - GLPerspective(fov, ASPECT_RATIO); + GLPerspective(FIELD_OF_VIEW, ASPECT_RATIO); pglMatrixMode(GL_MODELVIEW); // added for new coronas' code (without depth buffer) - pglGetIntegerv(GL_VIEWPORT, viewport); - pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); + pglGetIntegerv(GL_VIEWPORT, SceneViewport); + pglGetFloatv(GL_PROJECTION_MATRIX, ProjectionMatrix); } // -----------------+ // ClearBuffer : Clear the color/alpha/depth buffer(s) // -----------------+ -EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, - FBOOLEAN DepthMask, - FRGBAFloat * ClearColor) +EXPORT void HWRAPI(ClearBuffer) (boolean ColorMask, boolean DepthMask, FRGBAFloat *ClearColor) { // GL_DBG_Printf ("ClearBuffer(%d)\n", alpha); GLbitfield ClearMask = 0; @@ -1458,10 +1449,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, if (ColorMask) { if (ClearColor) - pglClearColor(ClearColor->red, - ClearColor->green, - ClearColor->blue, - ClearColor->alpha); + pglClearColor(ClearColor->red, ClearColor->green, ClearColor->blue, ClearColor->alpha); ClearMask |= GL_COLOR_BUFFER_BIT; } if (DepthMask) @@ -1502,8 +1490,8 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, angle = (float)atan((v2->y-v1->y)/(v2->x-v1->x)); else angle = (float)N_PI_DEMI; - dx = (float)sin(angle) / (float)screen_width; - dy = (float)cos(angle) / (float)screen_height; + dx = (float)sin(angle) / (float)GPUScreenWidth; + dy = (float)cos(angle) / (float)GPUScreenHeight; p[0] = v1->x - dx; p[1] = -(v1->y + dy); p[2] = 1; p[3] = v2->x - dx; p[4] = -(v2->y + dy); p[5] = 1; @@ -1538,7 +1526,7 @@ static void SetBlendEquation(GLenum mode) pglBlendEquation(mode); } -static void SetBlendMode(FBITFIELD flags) +static void SetBlendMode(UINT32 flags) { // Set blending function switch (flags) @@ -1614,9 +1602,9 @@ static void SetBlendMode(FBITFIELD flags) } } -EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) +EXPORT void HWRAPI(SetBlend) (UINT32 PolyFlags) { - FBITFIELD Xor; + UINT32 Xor; Xor = CurrentPolyFlags^PolyFlags; if (Xor & (PF_Blending|PF_RemoveYWrap|PF_ForceWrapX|PF_ForceWrapY|PF_Occlude|PF_NoTexture|PF_Modulated|PF_NoDepthTest|PF_Decal|PF_Invisible)) { @@ -1667,14 +1655,6 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) if (Xor & PF_Modulated) { -#if defined (__unix__) || defined (UNIXCOMMON) - if (oglflags & GLF_NOTEXENV) - { - if (!(PolyFlags & PF_Modulated)) - pglColor4ubv(white); - } - else -#endif if (PolyFlags & PF_Modulated) { // mix texture colour with Surface->PolyColor pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -1715,34 +1695,61 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) CurrentPolyFlags = PolyFlags; } +static void UploadTexture(HWRTexture_t *pTexInfo, const GLvoid *pTextureBuffer, GLenum format, boolean update) +{ + INT32 w = pTexInfo->width; + INT32 h = pTexInfo->height; + + GLint maxLOD = 5; + if (pTexInfo->format == GPU_TEXFMT_ALPHA_INTENSITY_88 || pTexInfo->format == GPU_TEXFMT_ALPHA_8) + maxLOD = 4; + + if (MipmappingEnabled) + { + pgluBuild2DMipmaps(GL_TEXTURE_2D, format, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pTextureBuffer); + + // Control the mipmap level of detail + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); // the lower the number, the higher the detail + + if (pTexInfo->flags & TF_TRANSPARENT) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mipmaps on transparent stuff + else + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, maxLOD); + } + else + { + if (update) + pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pTextureBuffer); + else + pglTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pTextureBuffer); + } +} + // -----------------+ // UpdateTexture : Updates the texture data. // -----------------+ -EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) +EXPORT void HWRAPI(UpdateTexture) (HWRTexture_t *pTexInfo) { - // Download a mipmap - boolean updatemipmap = true; - static RGBA_t tex[2048*2048]; - const GLvoid *ptex = tex; - INT32 w, h; - GLuint texnum = 0; + boolean update = true; + static RGBA_t textureBuffer[2048 * 2048]; + const GLvoid *pTextureBuffer = textureBuffer; + INT32 w = pTexInfo->width; + INT32 h = pTexInfo->height; + GLuint textureName = 0; if (!pTexInfo->downloaded) { - pglGenTextures(1, &texnum); - pTexInfo->downloaded = texnum; - updatemipmap = false; + pglGenTextures(1, &textureName); + pTexInfo->downloaded = textureName; + update = false; } else - texnum = pTexInfo->downloaded; + textureName = pTexInfo->downloaded; - //GL_DBG_Printf ("DownloadMipmap %d %x\n",(INT32)texnum,pTexInfo->data); + //GL_DBG_Printf ("UpdateTexture %d %x\n",(INT32)textureName,pTexInfo->data); - w = pTexInfo->width; - h = pTexInfo->height; - - if ((pTexInfo->format == GL_TEXFMT_P_8) || - (pTexInfo->format == GL_TEXFMT_AP_88)) + if ((pTexInfo->format == GPU_TEXFMT_P_8) || + (pTexInfo->format == GPU_TEXFMT_AP_88)) { const GLubyte *pImgData = (const GLubyte *)pTexInfo->data; INT32 i, j; @@ -1751,42 +1758,41 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) { for (i = 0; i < w; i++) { - if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && + if ((*pImgData == GPU_PATCHES_CHROMAKEY_COLORINDEX) && (pTexInfo->flags & TF_CHROMAKEYED)) { - tex[w*j+i].s.red = 0; - tex[w*j+i].s.green = 0; - tex[w*j+i].s.blue = 0; - tex[w*j+i].s.alpha = 0; + textureBuffer[w*j+i].s.red = 0; + textureBuffer[w*j+i].s.green = 0; + textureBuffer[w*j+i].s.blue = 0; + textureBuffer[w*j+i].s.alpha = 0; pTexInfo->flags |= TF_TRANSPARENT; // there is a hole in it } else { - tex[w*j+i].s.red = myPaletteData[*pImgData].s.red; - tex[w*j+i].s.green = myPaletteData[*pImgData].s.green; - tex[w*j+i].s.blue = myPaletteData[*pImgData].s.blue; - tex[w*j+i].s.alpha = myPaletteData[*pImgData].s.alpha; + textureBuffer[w*j+i].s.red = GPUTexturePalette[*pImgData].s.red; + textureBuffer[w*j+i].s.green = GPUTexturePalette[*pImgData].s.green; + textureBuffer[w*j+i].s.blue = GPUTexturePalette[*pImgData].s.blue; + textureBuffer[w*j+i].s.alpha = GPUTexturePalette[*pImgData].s.alpha; } pImgData++; - if (pTexInfo->format == GL_TEXFMT_AP_88) + if (pTexInfo->format == GPU_TEXFMT_AP_88) { if (!(pTexInfo->flags & TF_CHROMAKEYED)) - tex[w*j+i].s.alpha = *pImgData; + textureBuffer[w*j+i].s.alpha = *pImgData; pImgData++; } - } } } - else if (pTexInfo->format == GL_TEXFMT_RGBA) + else if (pTexInfo->format == GPU_TEXFMT_RGBA) { // corona test : passed as ARGB 8888, which is not in glide formats // Hurdler: not used for coronas anymore, just for dynamic lighting - ptex = pTexInfo->data; + pTextureBuffer = pTexInfo->data; } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) + else if (pTexInfo->format == GPU_TEXFMT_ALPHA_INTENSITY_88) { const GLubyte *pImgData = (const GLubyte *)pTexInfo->data; INT32 i, j; @@ -1795,16 +1801,16 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) { for (i = 0; i < w; i++) { - tex[w*j+i].s.red = *pImgData; - tex[w*j+i].s.green = *pImgData; - tex[w*j+i].s.blue = *pImgData; + textureBuffer[w*j+i].s.red = *pImgData; + textureBuffer[w*j+i].s.green = *pImgData; + textureBuffer[w*j+i].s.blue = *pImgData; pImgData++; - tex[w*j+i].s.alpha = *pImgData; + textureBuffer[w*j+i].s.alpha = *pImgData; pImgData++; } } } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) // Used for fade masks + else if (pTexInfo->format == GPU_TEXFMT_ALPHA_8) // Used for fade masks { const GLubyte *pImgData = (const GLubyte *)pTexInfo->data; INT32 i, j; @@ -1813,10 +1819,10 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) { for (i = 0; i < w; i++) { - tex[w*j+i].s.red = 255; // 255 because the fade mask is modulated with the screen texture, so alpha affects it while the colours don't - tex[w*j+i].s.green = 255; - tex[w*j+i].s.blue = 255; - tex[w*j+i].s.alpha = *pImgData; + textureBuffer[w*j+i].s.red = 255; // 255 because the fade mask is modulated with the screen texture, so alpha affects it while the colours don't + textureBuffer[w*j+i].s.green = 255; + textureBuffer[w*j+i].s.blue = 255; + textureBuffer[w*j+i].s.alpha = *pImgData; pImgData++; } } @@ -1825,8 +1831,8 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) GL_MSG_Warning ("SetTexture(bad format) %ld\n", pTexInfo->format); // the texture number was already generated by pglGenTextures - pglBindTexture(GL_TEXTURE_2D, texnum); - tex_downloaded = texnum; + pglBindTexture(GL_TEXTURE_2D, textureName); + CurrentTexture = textureName; // disable texture filtering on any texture that has holes so there's no dumb borders or blending issues if (pTexInfo->flags & TF_TRANSPARENT) @@ -1836,72 +1842,16 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) } else { - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, MipmapMagFilter); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MipmapMinFilter); } - if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) - { - //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - if (MipMap) - { - pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); - if (pTexInfo->flags & TF_TRANSPARENT) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff - else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); - //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); - } - else - { - if (updatemipmap) - pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - else - pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } - } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) - { - //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - if (MipMap) - { - pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); - if (pTexInfo->flags & TF_TRANSPARENT) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff - else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); - //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); - } - else - { - if (updatemipmap) - pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - else - pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } - } + if (pTexInfo->format == GPU_TEXFMT_ALPHA_INTENSITY_88) + UploadTexture(pTexInfo, pTextureBuffer, GL_LUMINANCE_ALPHA, update); + else if (pTexInfo->format == GPU_TEXFMT_ALPHA_8) + UploadTexture(pTexInfo, pTextureBuffer, GL_ALPHA, update); else - { - if (MipMap) - { - pgluBuild2DMipmaps(GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - // Control the mipmap level of detail - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); // the lower the number, the higer the detail - if (pTexInfo->flags & TF_TRANSPARENT) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff - else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); - } - else - { - if (updatemipmap) - pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - else - pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } - } + UploadTexture(pTexInfo, pTextureBuffer, GPUTextureFormat, update); if (pTexInfo->flags & TF_WRAPX) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -1913,14 +1863,14 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) else Clamp2D(GL_TEXTURE_WRAP_T); - if (maximumAnisotropy) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropic_filter); + if (GPUMaximumAnisotropy) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, AnisotropicFilter); } // -----------------+ -// SetTexture : The mipmap becomes the current texture source +// SetTexture : The texture becomes the current source // -----------------+ -EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) +EXPORT void HWRAPI(SetTexture) (HWRTexture_t *pTexInfo) { if (!pTexInfo) { @@ -1929,34 +1879,42 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) } else if (pTexInfo->downloaded) { - if (pTexInfo->downloaded != tex_downloaded) + if (pTexInfo->downloaded != CurrentTexture) { pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded); - tex_downloaded = pTexInfo->downloaded; + CurrentTexture = pTexInfo->downloaded; } } else { + FTextureInfo *newTex = calloc(1, sizeof (*newTex)); + UpdateTexture(pTexInfo); - pTexInfo->nextmipmap = NULL; + + newTex->texture = pTexInfo; + newTex->name = (UINT32)pTexInfo->downloaded; + newTex->width = (UINT32)pTexInfo->width; + newTex->height = (UINT32)pTexInfo->height; + newTex->format = (UINT32)pTexInfo->format; // insertion at the tail - if (gl_cachetail) + if (TexCacheTail) { - gl_cachetail->nextmipmap = pTexInfo; - gl_cachetail = pTexInfo; + newTex->prev = TexCacheTail; + TexCacheTail->next = newTex; + TexCacheTail = newTex; } else // initialization of the linked list - gl_cachetail = gl_cachehead = pTexInfo; + TexCacheTail = TexCacheHead = newTex; } } static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade) { #ifdef GL_SHADERS - gl_shader_t *shader = gl_shaderstate.current; + FShaderObject *shader = ShaderState.current; - if (gl_shadersenabled && (shader != NULL) && pglUseProgram) + if (ShadersEnabled && (shader != NULL) && pglUseProgram) { if (!shader->program) { @@ -1964,19 +1922,19 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF return; } - if (gl_shaderstate.changed) + if (ShaderState.changed) { pglUseProgram(shader->program); - gl_shaderstate.changed = false; + ShaderState.changed = false; } // Color uniforms can be left NULL and will be set to white (1.0f, 1.0f, 1.0f, 1.0f) if (poly == NULL) - poly = &shader_defaultcolor; + poly = &ShaderDefaultColor; if (tint == NULL) - tint = &shader_defaultcolor; + tint = &ShaderDefaultColor; if (fade == NULL) - fade = &shader_defaultcolor; + fade = &ShaderDefaultColor; #define UNIFORM_1(uniform, a, function) \ if (uniform != -1) \ @@ -1995,18 +1953,18 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF function (uniform, a, b, c, d); // polygon - UNIFORM_4(shader->uniforms[gluniform_poly_color], poly->red, poly->green, poly->blue, poly->alpha, pglUniform4f); - UNIFORM_4(shader->uniforms[gluniform_tint_color], tint->red, tint->green, tint->blue, tint->alpha, pglUniform4f); - UNIFORM_4(shader->uniforms[gluniform_fade_color], fade->red, fade->green, fade->blue, fade->alpha, pglUniform4f); + UNIFORM_4(shader->uniforms[uniform_poly_color], poly->red, poly->green, poly->blue, poly->alpha, pglUniform4f); + UNIFORM_4(shader->uniforms[uniform_tint_color], tint->red, tint->green, tint->blue, tint->alpha, pglUniform4f); + UNIFORM_4(shader->uniforms[uniform_fade_color], fade->red, fade->green, fade->blue, fade->alpha, pglUniform4f); if (Surface != NULL) { - UNIFORM_1(shader->uniforms[gluniform_lighting], Surface->LightInfo.light_level, pglUniform1f); - UNIFORM_1(shader->uniforms[gluniform_fade_start], Surface->LightInfo.fade_start, pglUniform1f); - UNIFORM_1(shader->uniforms[gluniform_fade_end], Surface->LightInfo.fade_end, pglUniform1f); + UNIFORM_1(shader->uniforms[uniform_lighting], Surface->LightInfo.LightLevel, pglUniform1f); + UNIFORM_1(shader->uniforms[uniform_fade_start], Surface->LightInfo.FadeStart, pglUniform1f); + UNIFORM_1(shader->uniforms[uniform_fade_end], Surface->LightInfo.FadeEnd, pglUniform1f); } - UNIFORM_1(shader->uniforms[gluniform_leveltime], ((float)shader_leveltime) / TICRATE, pglUniform1f); + UNIFORM_1(shader->uniforms[uniform_leveltime], ((float)ShaderLevelTime) / TICRATE, pglUniform1f); #undef UNIFORM_1 #undef UNIFORM_2 @@ -2021,7 +1979,7 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF #endif } -static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i, const GLchar *vert_shader, const GLchar *frag_shader) +static boolean Shader_CompileProgram(FShaderObject *shader, GLint i, const GLchar *vert_shader, const GLchar *frag_shader) { GLuint gl_vertShader, gl_fragShader; GLint result; @@ -2097,15 +2055,15 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i, const GLchar #define GETUNI(uniform) pglGetUniformLocation(shader->program, uniform); // lighting - shader->uniforms[gluniform_poly_color] = GETUNI("poly_color"); - shader->uniforms[gluniform_tint_color] = GETUNI("tint_color"); - shader->uniforms[gluniform_fade_color] = GETUNI("fade_color"); - shader->uniforms[gluniform_lighting] = GETUNI("lighting"); - shader->uniforms[gluniform_fade_start] = GETUNI("fade_start"); - shader->uniforms[gluniform_fade_end] = GETUNI("fade_end"); + shader->uniforms[uniform_poly_color] = GETUNI("poly_color"); + shader->uniforms[uniform_tint_color] = GETUNI("tint_color"); + shader->uniforms[uniform_fade_color] = GETUNI("fade_color"); + shader->uniforms[uniform_lighting] = GETUNI("lighting"); + shader->uniforms[uniform_fade_start] = GETUNI("fade_start"); + shader->uniforms[uniform_fade_end] = GETUNI("fade_end"); // misc. (custom shaders) - shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); + shader->uniforms[uniform_leveltime] = GETUNI("leveltime"); #undef GETUNI @@ -2133,15 +2091,12 @@ static void Shader_CompileError(const char *message, GLuint program, INT32 shade // code that is common between DrawPolygon and DrawIndexedTriangles // the corona thing is there too, i have no idea if that stuff works with DrawIndexedTriangles and batching -static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD PolyFlags) +static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, UINT32 PolyFlags) { static GLRGBAFloat poly = {0,0,0,0}; static GLRGBAFloat tint = {0,0,0,0}; static GLRGBAFloat fade = {0,0,0,0}; - if ((PolyFlags & PF_Corona) && (oglflags & GLF_NOZBUFREAD)) - PolyFlags &= ~(PF_NoDepthTest|PF_Corona); - SetBlend(PolyFlags); //TODO: inline (#pragma..) // PolyColor @@ -2151,33 +2106,33 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD if (CurrentPolyFlags & PF_Modulated) { // Poly color - poly.red = byte2float[pSurf->PolyColor.s.red]; - poly.green = byte2float[pSurf->PolyColor.s.green]; - poly.blue = byte2float[pSurf->PolyColor.s.blue]; - poly.alpha = byte2float[pSurf->PolyColor.s.alpha]; + poly.red = byte2float(pSurf->PolyColor.s.red); + poly.green = byte2float(pSurf->PolyColor.s.green); + poly.blue = byte2float(pSurf->PolyColor.s.blue); + poly.alpha = byte2float(pSurf->PolyColor.s.alpha); pglColor4ubv((GLubyte*)&pSurf->PolyColor.s); } // Tint color - tint.red = byte2float[pSurf->TintColor.s.red]; - tint.green = byte2float[pSurf->TintColor.s.green]; - tint.blue = byte2float[pSurf->TintColor.s.blue]; - tint.alpha = byte2float[pSurf->TintColor.s.alpha]; + tint.red = byte2float(pSurf->TintColor.s.red); + tint.green = byte2float(pSurf->TintColor.s.green); + tint.blue = byte2float(pSurf->TintColor.s.blue); + tint.alpha = byte2float(pSurf->TintColor.s.alpha); // Fade color - fade.red = byte2float[pSurf->FadeColor.s.red]; - fade.green = byte2float[pSurf->FadeColor.s.green]; - fade.blue = byte2float[pSurf->FadeColor.s.blue]; - fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; + fade.red = byte2float(pSurf->FadeColor.s.red); + fade.green = byte2float(pSurf->FadeColor.s.green); + fade.blue = byte2float(pSurf->FadeColor.s.blue); + fade.alpha = byte2float(pSurf->FadeColor.s.alpha); } // this test is added for new coronas' code (without depth buffer) // I think I should do a separate function for drawing coronas, so it will be a little faster if (PolyFlags & PF_Corona) // check to see if we need to draw the corona { - FUINT i; - FUINT j; + UINT32 i; + UINT32 j; //rem: all 8 (or 8.0f) values are hard coded: it can be changed to a higher value GLfloat buf[8][8]; @@ -2199,9 +2154,9 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD if ((pz < 0.0l) || (px < -8.0l) || - (py < viewport[1]-8.0l) || - (px > viewport[2]+8.0l) || - (py > viewport[1]+viewport[3]+8.0l)) + (py < SceneViewport[1]-8.0l) || + (px > SceneViewport[2]+8.0l) || + (py > SceneViewport[1]+SceneViewport[3]+8.0l)) return; // the damned slow glReadPixels functions :( @@ -2214,9 +2169,9 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD // quick test for screen border (not 100% correct, but looks ok) if (px < 4) scalef -= (GLfloat)(8*(4-px)); - if (py < viewport[1]+4) scalef -= (GLfloat)(8*(viewport[1]+4-py)); - if (px > viewport[2]-4) scalef -= (GLfloat)(8*(4-(viewport[2]-px))); - if (py > viewport[1]+viewport[3]-4) scalef -= (GLfloat)(8*(4-(viewport[1]+viewport[3]-py))); + if (py < SceneViewport[1]+4) scalef -= (GLfloat)(8*(SceneViewport[1]+4-py)); + if (px > SceneViewport[2]-4) scalef -= (GLfloat)(8*(4-(SceneViewport[2]-px))); + if (py > SceneViewport[1]+SceneViewport[3]-4) scalef -= (GLfloat)(8*(4-(SceneViewport[1]+SceneViewport[3]-py))); scalef /= 64; //GL_DBG_Printf("Scale factor: %f\n", scalef); @@ -2229,7 +2184,7 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD c[1] = pSurf->PolyColor.s.green; c[2] = pSurf->PolyColor.s.blue; - alpha = byte2float[pSurf->PolyColor.s.alpha]; + alpha = byte2float(pSurf->PolyColor.s.alpha); alpha *= scalef; // change the alpha value (it seems better than changing the size of the corona) c[3] = (unsigned char)(alpha * 255); pglColor4ubv(c); @@ -2241,7 +2196,7 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD // -----------------+ // DrawPolygon : Render a polygon, set the texture, set render mode // -----------------+ -EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags) +EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, UINT32 iNumPts, UINT32 PolyFlags) { PreparePolygon(pSurf, pOutVerts, PolyFlags); @@ -2259,7 +2214,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI Clamp2D(GL_TEXTURE_WRAP_T); } -EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, UINT32 *IndexArray) +EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, UINT32 iNumPts, UINT32 PolyFlags, UINT32 *IndexArray) { PreparePolygon(pSurf, pOutVerts, PolyFlags); @@ -2272,12 +2227,12 @@ EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutV static const boolean gl_ext_arb_vertex_buffer_object = true; -#define NULL_VBO_VERTEX ((gl_skyvertex_t*)NULL) +#define NULL_VBO_VERTEX ((FSkyVertex*)NULL) #define sky_vbo_x (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->x : &sky->data[0].x) #define sky_vbo_u (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->u : &sky->data[0].u) #define sky_vbo_r (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->r : &sky->data[0].r) -EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky) +EXPORT void HWRAPI(RenderSkyDome) (FSkyDome *sky) { int i, j; @@ -2328,7 +2283,7 @@ EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky) { for (i = 0; i < sky->loopcount; i++) { - gl_skyloopdef_t *loop = &sky->loops[i]; + FSkyLoopDef *loop = &sky->loops[i]; unsigned int mode = 0; if (j == 0 ? loop->use_texture : !loop->use_texture) @@ -2336,10 +2291,10 @@ EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky) switch (loop->mode) { - case HWD_SKYLOOP_FAN: + case GPU_SKYLOOP_FAN: mode = GL_TRIANGLE_FAN; break; - case HWD_SKYLOOP_STRIP: + case GPU_SKYLOOP_STRIP: mode = GL_TRIANGLE_STRIP; break; default: @@ -2364,64 +2319,66 @@ EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky) // ========================================================================== // // ========================================================================== -EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) +EXPORT void HWRAPI(SetState) (INT32 State, INT32 Value) { - switch (IdState) + switch (State) { - case HWD_SET_MODEL_LIGHTING: - model_lighting = Value; + case GPU_STATE_MODEL_LIGHTING: + ModelLightingEnabled = Value ? GL_TRUE : GL_FALSE; break; - case HWD_SET_SHADERS: - gl_allowshaders = (hwdshaderoption_t)Value; + case GPU_STATE_SHADERS: + ShadersAllowed = Value; break; - case HWD_SET_TEXTUREFILTERMODE: + case GPU_STATE_TEXTUREFILTERMODE: switch (Value) { - case HWD_SET_TEXTUREFILTER_TRILINEAR: - min_filter = GL_LINEAR_MIPMAP_LINEAR; - mag_filter = GL_LINEAR; - MipMap = GL_TRUE; + case GPU_TEXFILTER_TRILINEAR: + MipmapMinFilter = GL_LINEAR_MIPMAP_LINEAR; + MipmapMagFilter = GL_LINEAR; + MipmappingEnabled = GL_TRUE; break; - case HWD_SET_TEXTUREFILTER_BILINEAR: - min_filter = mag_filter = GL_LINEAR; - MipMap = GL_FALSE; + case GPU_TEXFILTER_BILINEAR: + MipmapMinFilter = MipmapMagFilter = GL_LINEAR; + MipmappingEnabled = GL_FALSE; break; - case HWD_SET_TEXTUREFILTER_POINTSAMPLED: - min_filter = mag_filter = GL_NEAREST; - MipMap = GL_FALSE; + case GPU_TEXFILTER_POINTSAMPLED: + MipmapMinFilter = MipmapMagFilter = GL_NEAREST; + MipmappingEnabled = GL_FALSE; break; - case HWD_SET_TEXTUREFILTER_MIXED1: - min_filter = GL_NEAREST; - mag_filter = GL_LINEAR; - MipMap = GL_FALSE; + case GPU_TEXFILTER_MIXED1: + MipmapMinFilter = GL_NEAREST; + MipmapMagFilter = GL_LINEAR; + MipmappingEnabled = GL_FALSE; break; - case HWD_SET_TEXTUREFILTER_MIXED2: - min_filter = GL_LINEAR; - mag_filter = GL_NEAREST; - MipMap = GL_FALSE; + case GPU_TEXFILTER_MIXED2: + MipmapMinFilter = GL_LINEAR; + MipmapMagFilter = GL_NEAREST; + MipmappingEnabled = GL_FALSE; break; - case HWD_SET_TEXTUREFILTER_MIXED3: - min_filter = GL_LINEAR_MIPMAP_LINEAR; - mag_filter = GL_NEAREST; - MipMap = GL_TRUE; + case GPU_TEXFILTER_MIXED3: + MipmapMinFilter = GL_LINEAR_MIPMAP_LINEAR; + MipmapMagFilter = GL_NEAREST; + MipmappingEnabled = GL_TRUE; break; default: - mag_filter = GL_LINEAR; - min_filter = GL_NEAREST; + MipmapMagFilter = GL_LINEAR; + MipmapMinFilter = GL_NEAREST; } + if (!pgluBuild2DMipmaps) { - MipMap = GL_FALSE; - min_filter = GL_LINEAR; + MipmappingEnabled = GL_FALSE; + MipmapMinFilter = GL_LINEAR; } + Flush(); //??? if we want to change filter mode by texture, remove this break; - case HWD_SET_TEXTUREANISOTROPICMODE: - anisotropic_filter = min(Value,maximumAnisotropy); - if (maximumAnisotropy) + case GPU_STATE_TEXTUREANISOTROPICMODE: + AnisotropicFilter = min(Value, GPUMaximumAnisotropy); + if (GPUMaximumAnisotropy) Flush(); //??? if we want to change filter mode by texture, remove this break; @@ -2643,7 +2600,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 boolean useVBO = true; - FBITFIELD flags; + UINT32 flags; int i; // Because otherwise, scaling the screen negatively vertically breaks the lighting @@ -2672,15 +2629,15 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pol = 0.0f; } - poly.red = byte2float[Surface->PolyColor.s.red]; - poly.green = byte2float[Surface->PolyColor.s.green]; - poly.blue = byte2float[Surface->PolyColor.s.blue]; - poly.alpha = byte2float[Surface->PolyColor.s.alpha]; + poly.red = byte2float(Surface->PolyColor.s.red); + poly.green = byte2float(Surface->PolyColor.s.green); + poly.blue = byte2float(Surface->PolyColor.s.blue); + poly.alpha = byte2float(Surface->PolyColor.s.alpha); #ifdef GL_LIGHT_MODEL_AMBIENT - if (model_lighting) + if (ModelLightingEnabled) { - if (!gl_shadersenabled) + if (!ShadersEnabled) { ambient[0] = poly.red; ambient[1] = poly.green; @@ -2711,15 +2668,15 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 else pglColor4ubv((GLubyte*)&Surface->PolyColor.s); - tint.red = byte2float[Surface->TintColor.s.red]; - tint.green = byte2float[Surface->TintColor.s.green]; - tint.blue = byte2float[Surface->TintColor.s.blue]; - tint.alpha = byte2float[Surface->TintColor.s.alpha]; + tint.red = byte2float(Surface->TintColor.s.red); + tint.green = byte2float(Surface->TintColor.s.green); + tint.blue = byte2float(Surface->TintColor.s.blue); + tint.alpha = byte2float(Surface->TintColor.s.alpha); - fade.red = byte2float[Surface->FadeColor.s.red]; - fade.green = byte2float[Surface->FadeColor.s.green]; - fade.blue = byte2float[Surface->FadeColor.s.blue]; - fade.alpha = byte2float[Surface->FadeColor.s.alpha]; + fade.red = byte2float(Surface->FadeColor.s.red); + fade.green = byte2float(Surface->FadeColor.s.green); + fade.blue = byte2float(Surface->FadeColor.s.blue); + fade.alpha = byte2float(Surface->FadeColor.s.alpha); flags = (Surface->PolyFlags | PF_Modulated); if (Surface->PolyFlags & (PF_Additive|PF_AdditiveSource|PF_Subtractive|PF_ReverseSubtract|PF_Multiplicative)) @@ -2923,9 +2880,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 pglDisable(GL_NORMALIZE); #ifdef GL_LIGHT_MODEL_AMBIENT - if (model_lighting) + if (ModelLightingEnabled) { - if (!gl_shadersenabled) + if (!ShadersEnabled) pglDisable(GL_LIGHTING); pglShadeModel(GL_FLAT); } @@ -2976,7 +2933,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) } else { - used_fov = fov; + used_fov = FIELD_OF_VIEW; pglScalef(1.0f, 1.0f, -1.0f); } @@ -3002,33 +2959,32 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) else GLPerspective(used_fov, ASPECT_RATIO); - pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) + pglGetFloatv(GL_PROJECTION_MATRIX, ProjectionMatrix); // added for new coronas' code (without depth buffer) pglMatrixMode(GL_MODELVIEW); - pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) + pglGetFloatv(GL_MODELVIEW_MATRIX, ModelMatrix); // added for new coronas' code (without depth buffer) } EXPORT INT32 HWRAPI(GetTextureUsed) (void) { - FTextureInfo *tmp = gl_cachehead; + FTextureInfo *tmp = TexCacheHead; INT32 res = 0; while (tmp) { // Figure out the correct bytes-per-pixel for this texture - // I don't know which one the game actually _uses_ but this - // follows format2bpp in hw_cache.c - int bpp = 1; - int format = tmp->format; - if (format == GL_TEXFMT_RGBA) + // This follows format2bpp in hw_cache.c + INT32 bpp = 1; + UINT32 format = tmp->format; + if (format == GPU_TEXFMT_RGBA) bpp = 4; - else if (format == GL_TEXFMT_ALPHA_INTENSITY_88 || format == GL_TEXFMT_AP_88) + else if (format == GPU_TEXFMT_ALPHA_INTENSITY_88 || format == GPU_TEXFMT_AP_88) bpp = 2; // Add it up! res += tmp->height*tmp->width*bpp; - tmp = tmp->nextmipmap; + tmp = tmp->next; } return res; @@ -3050,14 +3006,14 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) }; // Use a power of two texture, dammit - if(screen_width <= 1024) + if(GPUScreenWidth <= 1024) texsize = 1024; - if(screen_width <= 512) + if(GPUScreenWidth <= 512) texsize = 512; // X/Y stretch fix for all resolutions(!) - xfix = (float)(texsize)/((float)((screen_width)/(float)(SCREENVERTS-1))); - yfix = (float)(texsize)/((float)((screen_height)/(float)(SCREENVERTS-1))); + xfix = (float)(texsize)/((float)((GPUScreenWidth)/(float)(SCREENVERTS-1))); + yfix = (float)(texsize)/((float)((GPUScreenHeight)/(float)(SCREENVERTS-1))); pglDisable(GL_DEPTH_TEST); pglDisable(GL_BLEND); @@ -3127,79 +3083,57 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) // a new size EXPORT void HWRAPI(FlushScreenTextures) (void) { - pglDeleteTextures(1, &screentexture); - pglDeleteTextures(1, &startScreenWipe); - pglDeleteTextures(1, &endScreenWipe); - pglDeleteTextures(1, &finalScreenTexture); - screentexture = 0; - startScreenWipe = 0; - endScreenWipe = 0; - finalScreenTexture = 0; + pglDeleteTextures(1, &ScreenTexture); + pglDeleteTextures(1, &FinalScreenTexture); + pglDeleteTextures(1, &WipeStartTexture); + pglDeleteTextures(1, &WipeEndTexture); + + ScreenTexture = FinalScreenTexture = 0; + WipeStartTexture = WipeEndTexture = 0; } -// Create Screen to fade from +static void GenerateScreenTexture(GLuint *name) +{ + INT32 texsize = 2048; + boolean firstTime = ((*name) == 0); + + // Use a power of two texture, dammit + if(GPUScreenWidth <= 512) + texsize = 512; + else if (GPUScreenWidth <= 1024) + texsize = 1024; + + // Create screen texture + if (firstTime) + pglGenTextures(1, name); + pglBindTexture(GL_TEXTURE_2D, *name); + + if (firstTime) + { + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + Clamp2D(GL_TEXTURE_WRAP_S); + Clamp2D(GL_TEXTURE_WRAP_T); + pglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, texsize, texsize, 0); + } + else + pglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize); + + CurrentTexture = *name; +} + +// Create screen to fade from EXPORT void HWRAPI(StartScreenWipe) (void) { - INT32 texsize = 2048; - boolean firstTime = (startScreenWipe == 0); - - // Use a power of two texture, dammit - if(screen_width <= 512) - texsize = 512; - else if(screen_width <= 1024) - texsize = 1024; - - // Create screen texture - if (firstTime) - pglGenTextures(1, &startScreenWipe); - pglBindTexture(GL_TEXTURE_2D, startScreenWipe); - - if (firstTime) - { - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - Clamp2D(GL_TEXTURE_WRAP_S); - Clamp2D(GL_TEXTURE_WRAP_T); - pglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, texsize, texsize, 0); - } - else - pglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize); - - tex_downloaded = startScreenWipe; + GenerateScreenTexture(&WipeStartTexture); } -// Create Screen to fade to +// Create screen to fade to EXPORT void HWRAPI(EndScreenWipe)(void) { - INT32 texsize = 2048; - boolean firstTime = (endScreenWipe == 0); - - // Use a power of two texture, dammit - if(screen_width <= 512) - texsize = 512; - else if(screen_width <= 1024) - texsize = 1024; - - // Create screen texture - if (firstTime) - pglGenTextures(1, &endScreenWipe); - pglBindTexture(GL_TEXTURE_2D, endScreenWipe); - - if (firstTime) - { - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - Clamp2D(GL_TEXTURE_WRAP_S); - Clamp2D(GL_TEXTURE_WRAP_T); - pglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, texsize, texsize, 0); - } - else - pglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize); - - tex_downloaded = endScreenWipe; + GenerateScreenTexture(&WipeEndTexture); } - // Draw the last scene under the intermission EXPORT void HWRAPI(DrawIntermissionBG)(void) { @@ -3216,13 +3150,13 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void) float fix[8]; - if(screen_width <= 1024) + if(GPUScreenWidth <= 1024) texsize = 1024; - if(screen_width <= 512) + if(GPUScreenWidth <= 512) texsize = 512; - xfix = 1/((float)(texsize)/((float)((screen_width)))); - yfix = 1/((float)(texsize)/((float)((screen_height)))); + xfix = 1/((float)(texsize)/((float)((GPUScreenWidth)))); + yfix = 1/((float)(texsize)/((float)((GPUScreenHeight)))); // const float screenVerts[12] @@ -3238,14 +3172,14 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void) pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - pglBindTexture(GL_TEXTURE_2D, screentexture); + pglBindTexture(GL_TEXTURE_2D, ScreenTexture); pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, screenVerts); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); - tex_downloaded = screentexture; + CurrentTexture = ScreenTexture; } // Do screen fades! @@ -3254,7 +3188,7 @@ EXPORT void HWRAPI(DoScreenWipe)(void) INT32 texsize = 2048; float xfix, yfix; - INT32 fademaskdownloaded = tex_downloaded; // the fade mask that has been set + INT32 fademaskdownloaded = CurrentTexture; // the fade mask that has been set const float screenVerts[12] = { @@ -3275,13 +3209,13 @@ EXPORT void HWRAPI(DoScreenWipe)(void) }; // Use a power of two texture, dammit - if(screen_width <= 1024) + if(GPUScreenWidth <= 1024) texsize = 1024; - if(screen_width <= 512) + if(GPUScreenWidth <= 512) texsize = 512; - xfix = 1/((float)(texsize)/((float)((screen_width)))); - yfix = 1/((float)(texsize)/((float)((screen_height)))); + xfix = 1/((float)(texsize)/((float)((GPUScreenWidth)))); + yfix = 1/((float)(texsize)/((float)((GPUScreenHeight)))); // const float screenVerts[12] @@ -3301,7 +3235,7 @@ EXPORT void HWRAPI(DoScreenWipe)(void) pglEnable(GL_TEXTURE_2D); // Draw the original screen - pglBindTexture(GL_TEXTURE_2D, startScreenWipe); + pglBindTexture(GL_TEXTURE_2D, WipeStartTexture); pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, screenVerts); @@ -3312,7 +3246,7 @@ EXPORT void HWRAPI(DoScreenWipe)(void) // Draw the end screen that fades in pglActiveTexture(GL_TEXTURE0); pglEnable(GL_TEXTURE_2D); - pglBindTexture(GL_TEXTURE_2D, endScreenWipe); + pglBindTexture(GL_TEXTURE_2D, WipeEndTexture); pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); pglActiveTexture(GL_TEXTURE1); @@ -3336,68 +3270,18 @@ EXPORT void HWRAPI(DoScreenWipe)(void) pglActiveTexture(GL_TEXTURE0); pglClientActiveTexture(GL_TEXTURE0); - tex_downloaded = endScreenWipe; + CurrentTexture = WipeEndTexture; } // Create a texture from the screen. EXPORT void HWRAPI(MakeScreenTexture) (void) { - INT32 texsize = 2048; - boolean firstTime = (screentexture == 0); - - // Use a power of two texture, dammit - if(screen_width <= 512) - texsize = 512; - else if(screen_width <= 1024) - texsize = 1024; - - // Create screen texture - if (firstTime) - pglGenTextures(1, &screentexture); - pglBindTexture(GL_TEXTURE_2D, screentexture); - - if (firstTime) - { - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - Clamp2D(GL_TEXTURE_WRAP_S); - Clamp2D(GL_TEXTURE_WRAP_T); - pglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, texsize, texsize, 0); - } - else - pglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize); - - tex_downloaded = screentexture; + GenerateScreenTexture(&ScreenTexture); } EXPORT void HWRAPI(MakeScreenFinalTexture) (void) { - INT32 texsize = 2048; - boolean firstTime = (finalScreenTexture == 0); - - // Use a power of two texture, dammit - if(screen_width <= 512) - texsize = 512; - else if(screen_width <= 1024) - texsize = 1024; - - // Create screen texture - if (firstTime) - pglGenTextures(1, &finalScreenTexture); - pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - - if (firstTime) - { - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - Clamp2D(GL_TEXTURE_WRAP_S); - Clamp2D(GL_TEXTURE_WRAP_T); - pglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, texsize, texsize, 0); - } - else - pglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize); - - tex_downloaded = finalScreenTexture; + GenerateScreenTexture(&FinalScreenTexture); } EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) @@ -3411,15 +3295,15 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) float off[12]; float fix[8]; - if(screen_width <= 1024) + if(GPUScreenWidth <= 1024) texsize = 1024; - if(screen_width <= 512) + if(GPUScreenWidth <= 512) texsize = 512; - xfix = 1/((float)(texsize)/((float)((screen_width)))); - yfix = 1/((float)(texsize)/((float)((screen_height)))); + xfix = 1/((float)(texsize)/((float)((GPUScreenWidth)))); + yfix = 1/((float)(texsize)/((float)((GPUScreenHeight)))); - origaspect = (float)screen_width / screen_height; + origaspect = (float)GPUScreenWidth / GPUScreenHeight; newaspect = (float)width / height; if (origaspect < newaspect) { @@ -3461,7 +3345,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) clearColour.red = clearColour.green = clearColour.blue = 0; clearColour.alpha = 1; ClearBuffer(true, false, &clearColour); - pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); + pglBindTexture(GL_TEXTURE_2D, FinalScreenTexture); pglColor4ubv(white); @@ -3469,7 +3353,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) pglVertexPointer(3, GL_FLOAT, 0, off); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); - tex_downloaded = finalScreenTexture; + CurrentTexture = FinalScreenTexture; } #endif //HWRENDER diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index f44e0818b..09cbee399 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -117,25 +117,15 @@ static PFNglEnableClientState pglEnableClientState; // GLOBAL // ========================================================================== -extern const GLubyte *gl_version; -extern const GLubyte *gl_renderer; -extern const GLubyte *gl_extensions; +extern const GLubyte *GLVersion; +extern const GLubyte *GLRenderer; +extern const GLubyte *GLExtensions; -extern RGBA_t myPaletteData[]; -extern GLint screen_width; -extern GLint screen_height; -extern GLbyte screen_depth; -extern GLint maximumAnisotropy; - -/** \brief OpenGL flags for video driver -*/ -extern INT32 oglflags; -extern GLint textureformatGL; - -typedef enum -{ - GLF_NOZBUFREAD = 0x01, - GLF_NOTEXENV = 0x02, -} oglflags_t; +extern GLint GPUTextureFormat; +extern RGBA_t GPUTexturePalette[256]; +extern GLint GPUScreenWidth; +extern GLint GPUScreenHeight; +extern GLbyte GPUScreenDepth; +extern GLint GPUMaximumAnisotropy; #endif diff --git a/src/p_setup.c b/src/p_setup.c index 41d8822e2..0c6ef3e5c 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -4134,9 +4134,8 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) R_FlushTranslationColormapCache(); #ifdef HWRENDER - // Free GPU textures before freeing patches. if (vid.glstate == VID_GL_LIBRARY_LOADED) - HWR_ClearAllTextures(); + HWR_ClearColormapCache(); #endif Patch_FreeTag(PU_PATCH_LOWPRIORITY); @@ -4499,7 +4498,7 @@ boolean P_AddWadFile(const char *wadfilename) CONS_Printf(M_GetText("%s digital musics replaced\n"), sizeu1(digmreplaces)); #ifdef HWRENDER - // Free GPU textures before freeing patches. + // Free all GPU textures. if (vid.glstate == VID_GL_LIBRARY_LOADED) HWR_ClearAllTextures(); #endif diff --git a/src/p_setup.h b/src/p_setup.h index 34de9c93d..8bf3e6f76 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -79,7 +79,7 @@ typedef struct // for textures UINT8 *picture; #ifdef HWRENDER - void *mipmap; + void *texture; #endif } levelflat_t; diff --git a/src/r_patch.c b/src/r_patch.c index 1a08d1892..a0c4f1d91 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -141,7 +141,7 @@ void *Patch_AllocateHardwarePatch(patch_t *patch) if (!patch->hardware) { GLPatch_t *grPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, &patch->hardware); - grPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, &grPatch->mipmap); + grPatch->texture = Z_Calloc(sizeof(HWRTexture_t), PU_HWRPATCHINFO, &grPatch->texture); } return (void *)(patch->hardware); } @@ -153,8 +153,8 @@ void *Patch_AllocateHardwarePatch(patch_t *patch) void *Patch_CreateGL(patch_t *patch) { GLPatch_t *grPatch = (GLPatch_t *)Patch_AllocateHardwarePatch(patch); - if (!grPatch->mipmap->data) // Run HWR_MakePatch in all cases, to recalculate some things - HWR_MakePatch(patch, grPatch, grPatch->mipmap, false); + if (!grPatch->texture->data) // Run HWR_MakePatch in all cases, to recalculate some things + HWR_MakePatch(patch, grPatch, grPatch->texture, false); return grPatch; } #endif // HWRENDER diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 398508662..5ca424e8a 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -89,9 +89,8 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(DeleteTexture); GETFUNC(ReadRect); GETFUNC(GClipRect); - GETFUNC(ClearMipMapCache); - GETFUNC(ClearCacheList); - GETFUNC(SetSpecialState); + GETFUNC(ClearTextureCache); + GETFUNC(SetState); GETFUNC(GetTextureUsed); GETFUNC(DrawModel); GETFUNC(CreateModelVBOs); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 5ebff8700..f7ed27e32 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1568,6 +1568,9 @@ boolean VID_CheckRenderer(void) } SCR_SetDrawFuncs(); + + if (vid.glstate == VID_GL_LIBRARY_LOADED) + HWR_ClearAllTextures(); } #ifdef HWRENDER else if (rendermode == render_opengl && rendererchanged) @@ -1861,9 +1864,8 @@ void VID_StartupOpenGL(void) HWD.pfnDeleteTexture = hwSym("DeleteTexture",NULL); HWD.pfnReadRect = hwSym("ReadRect",NULL); HWD.pfnGClipRect = hwSym("GClipRect",NULL); - HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL); - HWD.pfnClearCacheList = hwSym("ClearCacheList",NULL); - HWD.pfnSetSpecialState = hwSym("SetSpecialState",NULL); + HWD.pfnClearTextureCache= hwSym("ClearTextureCache",NULL); + HWD.pfnSetState = hwSym("SetState",NULL); HWD.pfnSetPalette = hwSym("SetPalette",NULL); HWD.pfnGetTextureUsed = hwSym("GetTextureUsed",NULL); HWD.pfnDrawModel = hwSym("DrawModel",NULL); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 52727c056..6ef12cbed 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -69,7 +69,6 @@ PFNglGetString pglGetString; /** \brief SDL video display surface */ -INT32 oglflags = 0; void *GLUhandle = NULL; SDL_GLContext sdlglcontext = 0; @@ -156,20 +155,18 @@ boolean OglSdlSurface(INT32 w, INT32 h) INT32 cbpp = cv_scr_depth.value < 16 ? 16 : cv_scr_depth.value; static boolean first_init = false; - oglflags = 0; - if (!first_init) { - gl_version = pglGetString(GL_VERSION); - gl_renderer = pglGetString(GL_RENDERER); - gl_extensions = pglGetString(GL_EXTENSIONS); + GLVersion = pglGetString(GL_VERSION); + GLRenderer = pglGetString(GL_RENDERER); + GLExtensions = pglGetString(GL_EXTENSIONS); - GL_DBG_Printf("OpenGL %s\n", gl_version); - GL_DBG_Printf("GPU: %s\n", gl_renderer); - GL_DBG_Printf("Extensions: %s\n", gl_extensions); + GL_DBG_Printf("OpenGL %s\n", GLVersion); + GL_DBG_Printf("GPU: %s\n", GLRenderer); + GL_DBG_Printf("Extensions: %s\n", GLExtensions); - if (strcmp((const char*)gl_renderer, "GDI Generic") == 0 && - strcmp((const char*)gl_version, "1.1.0") == 0) + if (strcmp((const char*)GLRenderer, "GDI Generic") == 0 && + strcmp((const char*)GLVersion, "1.1.0") == 0) { // Oh no... Windows gave us the GDI Generic rasterizer, so something is wrong... // The game will crash later on when unsupported OpenGL commands are encountered. @@ -182,14 +179,14 @@ boolean OglSdlSurface(INT32 w, INT32 h) } first_init = true; - if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) - pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); + if (isExtAvailable("GL_EXT_texture_filter_anisotropic", GLExtensions)) + pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &GPUMaximumAnisotropy); else - maximumAnisotropy = 1; + GPUMaximumAnisotropy = 1; SetupGLFunc4(); - glanisotropicmode_cons_t[1].value = maximumAnisotropy; + glanisotropicmode_cons_t[1].value = GPUMaximumAnisotropy; SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); @@ -198,7 +195,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); HWR_Startup(); - textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; + GPUTextureFormat = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; return true; } @@ -237,9 +234,9 @@ EXPORT void HWRAPI(OglSdlSetPalette) (RGBA_t *palette) { size_t palsize = (sizeof(RGBA_t) * 256); // on a palette change, you have to reload all of the textures - if (memcmp(&myPaletteData, palette, palsize)) + if (memcmp(&GPUTexturePalette, palette, palsize)) { - memcpy(&myPaletteData, palette, palsize); + memcpy(&GPUTexturePalette, palette, palsize); Flush(); } } diff --git a/src/win32/win_dll.c b/src/win32/win_dll.c index d942d8cd4..7991a0394 100644 --- a/src/win32/win_dll.c +++ b/src/win32/win_dll.c @@ -110,9 +110,8 @@ static loadfunc_t hwdFuncTable[] = { {"DeleteTexture@4", &hwdriver.pfnDeleteTexture}, {"ReadRect@24", &hwdriver.pfnReadRect}, {"GClipRect@20", &hwdriver.pfnGClipRect}, - {"ClearMipMapCache@0", &hwdriver.pfnClearMipMapCache}, - {"ClearCacheList@0", &hwdriver.pfnClearCacheList}, - {"SetSpecialState@8", &hwdriver.pfnSetSpecialState}, + {"ClearTextureCache@0", &hwdriver.pfnClearTextureCache}, + {"SetState@8", &hwdriver.pfnSetState}, {"DrawModel@16", &hwdriver.pfnDrawModel}, {"SetTransform@4", &hwdriver.pfnSetTransform}, {"GetTextureUsed@0", &hwdriver.pfnGetTextureUsed}, @@ -144,9 +143,8 @@ static loadfunc_t hwdFuncTable[] = { {"DeleteTexture", &hwdriver.pfnDeleteTexture}, {"ReadRect", &hwdriver.pfnReadRect}, {"GClipRect", &hwdriver.pfnGClipRect}, - {"ClearMipMapCache", &hwdriver.pfnClearMipMapCache}, - {"ClearCacheList", &hwdriver.pfnClearCacheList}, - {"SetSpecialState", &hwdriver.pfnSetSpecialState}, + {"ClearTextureCache", &hwdriver.pfnClearTextureCache}, + {"SetState", &hwdriver.pfnSetState}, {"DrawModel", &hwdriver.pfnDrawModel}, {"SetTransform", &hwdriver.pfnSetTransform}, {"GetTextureUsed", &hwdriver.pfnGetTextureUsed}, diff --git a/src/z_zone.c b/src/z_zone.c index ad64a3a07..c3f2524aa 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -814,7 +814,7 @@ static void Command_Memfree_f(void) if (rendermode == render_opengl) { CONS_Printf(M_GetText("Patch info headers: %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); - CONS_Printf(M_GetText("Mipmap patches : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10)); + CONS_Printf(M_GetText("Colormap textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLTEXTURE)>>10)); CONS_Printf(M_GetText("HW Texture cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); CONS_Printf(M_GetText("HW model textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRMODELTEXTURE)>>10)); diff --git a/src/z_zone.h b/src/z_zone.h index e80a45e7f..2dccc8dbf 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -51,7 +51,7 @@ enum PU_HUDGFX = 19, // HUD patch, static until WAD added PU_HWRPATCHINFO = 21, // Hardware GLPatch_t struct for OpenGL texture cache - PU_HWRPATCHCOLMIPMAP = 22, // Hardware GLMipmap_t struct colormap variation of patch + PU_HWRPATCHCOLTEXTURE = 22, // Hardware HWRTexture_t struct colormap variation of patch PU_HWRMODELTEXTURE = 23, // Hardware model texture PU_HWRCACHE = 48, // static until unlocked