From 7304988071cba17b792a21348481eabbbaf6b89b Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 03:12:48 +0100 Subject: [PATCH 01/14] fix conflitc --- src/hardware/hw_batching.c | 22 +-- src/hardware/hw_batching.h | 4 +- src/hardware/hw_cache.c | 30 ++-- src/hardware/hw_draw.c | 42 ++--- src/hardware/hw_gpu.h | 76 +++++++++ src/hardware/hw_main.c | 112 ++++++------- src/hardware/hw_md2.c | 24 +-- src/hardware/hw_portal.c | 4 +- src/hardware/hw_shaders.c | 10 +- src/hardware/hw_shaders.h | 1 + src/hardware/r_opengl/ogl_win.c | 25 +-- src/hardware/r_opengl/r_opengl.c | 269 +++++++++++++++---------------- src/hardware/r_opengl/r_opengl.h | 23 +-- src/sdl/hwsym_sdl.c | 58 +------ src/sdl/i_video.c | 46 +----- src/sdl/ogl_sdl.c | 49 +++--- src/sdl/ogl_sdl.h | 4 +- 17 files changed, 379 insertions(+), 420 deletions(-) create mode 100644 src/hardware/hw_gpu.h diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index e32a7162a..82cfd31db 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -15,6 +15,8 @@ #include "hw_main.h" #include "../i_system.h" +#include "../doomdef.h" + #include "../qs22j.h" // The texture for the next polygon given to HWR_ProcessPolygon. @@ -63,7 +65,7 @@ void HWR_StartBatching(void) currently_batching = true; } -// This replaces the direct calls to pfnSetTexture in cases where batching is available. +// This replaces the direct calls to GL_SetTexture 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) @@ -74,7 +76,7 @@ void HWR_SetCurrentTexture(GLMipmap_t *texture) } else { - HWD.pfnSetTexture(texture); + GL_SetTexture(texture); } } @@ -128,8 +130,8 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt } else { - HWD.pfnSetShader((shader_target != SHADER_NONE) ? HWR_GetShaderFromTarget(shader_target) : shader_target); - HWD.pfnDrawPolygon(pSurf, pOutVerts, iNumPts, PolyFlags); + GL_SetShader((shader_target != SHADER_NONE) ? HWR_GetShaderFromTarget(shader_target) : shader_target); + GL_DrawPolygon(pSurf, pOutVerts, iNumPts, PolyFlags); } } @@ -290,13 +292,13 @@ void HWR_RenderBatches(void) if (cv_glshaders.value && gl_shadersavailable) { - HWD.pfnSetShader(currentShader); + GL_SetShader(currentShader); } if (currentPolyFlags & PF_NoTexture) currentTexture = NULL; else - HWD.pfnSetTexture(currentTexture); + GL_SetTexture(currentTexture); while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons) { @@ -411,7 +413,7 @@ void HWR_RenderBatches(void) if (changeState || stopFlag) { // execute draw call - HWD.pfnDrawIndexedTriangles(¤tSurfaceInfo, finalVertexArray, finalIndexWritePos, currentPolyFlags, finalVertexIndexArray); + GL_DrawIndexedTriangles(¤tSurfaceInfo, finalVertexArray, finalIndexWritePos, currentPolyFlags, finalVertexIndexArray); // update stats ps_hw_numcalls.value.i++; ps_hw_numverts.value.i += finalIndexWritePos; @@ -429,7 +431,7 @@ void HWR_RenderBatches(void) { if (changeShader) { - HWD.pfnSetShader(nextShader); + GL_SetShader(nextShader); currentShader = nextShader; changeShader = false; @@ -437,8 +439,8 @@ void HWR_RenderBatches(void) } if (changeTexture) { - // texture should be already ready for use from calls to SetTexture during batch collection - HWD.pfnSetTexture(nextTexture); + // texture should be already ready for use from calls to GL_SetTexture during batch collection + GL_SetTexture(nextTexture); currentTexture = nextTexture; changeTexture = false; diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index 22a4cc4c0..2825b0820 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -15,7 +15,9 @@ #include "hw_defs.h" #include "hw_data.h" -#include "hw_drv.h" +#include "hw_gpu.h" + +extern boolean currently_batching; typedef struct { diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 652e1e903..bfb1df1f1 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -16,7 +16,7 @@ #ifdef HWRENDER #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gpu.h" #include "hw_batching.h" #include "../doomstat.h" //gamemode @@ -494,7 +494,7 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) if (next->data) Z_Free(next->data); next->data = NULL; - HWD.pfnDeleteTexture(next); + GL_DeleteTexture(next); // Free the old colormap mipmap from memory. free(next); @@ -505,7 +505,7 @@ void HWR_FreeMipmapCache(void) { INT32 i; // free references to the textures - HWD.pfnClearMipMapCache(); + GL_ClearMipMapCache(); // free all hardware-converted graphics cached in the heap // our gool is only the textures since user of the texture is the texture cache @@ -572,7 +572,7 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) // If hardware does not have the texture, then call pfnSetTexture to upload it if (!gltex->mipmap.downloaded) - HWD.pfnSetTexture(&gltex->mipmap); + GL_SetTexture(&gltex->mipmap); HWR_SetCurrentTexture(&gltex->mipmap); // The system-memory data can be purged now. @@ -660,7 +660,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) // If hardware does not have the texture, then call pfnSetTexture to upload it if (!glMipmap->downloaded) - HWD.pfnSetTexture(glMipmap); + GL_SetTexture(glMipmap); HWR_SetCurrentTexture(glMipmap); // The system-memory data can be purged now. @@ -689,7 +689,7 @@ static void HWR_LoadMappedPatch(GLMipmap_t *glMipmap, GLPatch_t *glPatch) // If hardware does not have the texture, then call pfnSetTexture to upload it if (!glMipmap->downloaded) - HWD.pfnSetTexture(glMipmap); + GL_SetTexture(glMipmap); HWR_SetCurrentTexture(glMipmap); // The system-memory data can be purged now. @@ -719,7 +719,7 @@ void HWR_GetPatch(GLPatch_t *glPatch) // If hardware does not have the texture, then call pfnSetTexture to upload it if (!glPatch->mipmap->downloaded) - HWD.pfnSetTexture(glPatch->mipmap); + GL_SetTexture(glPatch->mipmap); HWR_SetCurrentTexture(glPatch->mipmap); // The system-memory patch data can be purged now. @@ -894,7 +894,7 @@ void HWR_GetFadeMask(lumpnum_t fademasklumpnum) if (!glMipmap->downloaded && !glMipmap->data) HWR_CacheFadeMask(glMipmap, fademasklumpnum); - HWD.pfnSetTexture(glMipmap); + GL_SetTexture(glMipmap); // The system-memory data can be purged now. Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); @@ -927,11 +927,11 @@ void HWR_SetPalette(RGBA_t *palette) crushed_palette[i].s.blue = (UINT8)(fblue / 31.0f * 255.0f); crushed_palette[i].s.alpha = 255; } - HWD.pfnSetScreenPalette(crushed_palette); + GL_SetScreenPalette(crushed_palette); } else { - HWD.pfnSetScreenPalette(palette); + GL_SetScreenPalette(palette); } // this part is responsible for keeping track of the palette OUTSIDE of a level. @@ -941,7 +941,7 @@ void HWR_SetPalette(RGBA_t *palette) else { // set the palette for the textures - HWD.pfnSetTexturePalette(palette); + GL_SetPalette(palette); // reset mapPalette so next call to HWR_SetMapPalette will update everything correctly memset(mapPalette, 0, sizeof(mapPalette)); // hardware driver will flush there own cache if cache is non paletized @@ -974,7 +974,7 @@ static void HWR_SetPaletteLookup(RGBA_t *palette) } } #undef STEP_SIZE - HWD.pfnSetPaletteLookup(lut); + GL_SetPaletteLookup(lut); Z_Free(lut); } @@ -1022,7 +1022,7 @@ void HWR_SetMapPalette(void) // in palette rendering mode, this means that all rgba textures now have wrong colors // and the lookup table is outdated HWR_SetPaletteLookup(mapPalette); - HWD.pfnSetTexturePalette(mapPalette); + GL_SetPalette(mapPalette); if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA) { @@ -1045,7 +1045,7 @@ UINT32 HWR_CreateLightTable(UINT8 *lighttable) for (i = 0; i < 256 * 32; i++) hw_lighttable[i] = palette[lighttable[i]]; - id = HWD.pfnCreateLightTable(hw_lighttable); + id = GL_CreateLightTable(hw_lighttable); Z_Free(hw_lighttable); return id; } @@ -1081,7 +1081,7 @@ UINT32 HWR_GetLightTableID(extracolormap_t *colormap) void HWR_ClearLightTables(void) { if (vid.glstate == VID_GL_LIBRARY_LOADED) - HWD.pfnClearLightTables(); + GL_ClearLightTables(); } #endif //HWRENDER diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 768e523e0..bfb1909e5 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -20,7 +20,7 @@ #ifdef HWRENDER #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gpu.h" #include "../m_misc.h" //FIL_WriteFile() #include "../r_draw.h" //viewborderlump @@ -122,7 +122,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) flags |= PF_ForceWrapY; // clip it since it is used for bunny scroll in doom I - HWD.pfnDrawPolygon(NULL, v, 4, flags); + GL_DrawPolygon(NULL, v, 4, flags); } void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap) @@ -303,10 +303,10 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[hudtrans]; else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; flags |= PF_Modulated; - HWD.pfnDrawPolygon(&Surf, v, 4, flags); + GL_DrawPolygon(&Surf, v, 4, flags); } else - HWD.pfnDrawPolygon(NULL, v, 4, flags); + GL_DrawPolygon(NULL, v, 4, flags); } void HWR_DrawCroppedPatch(GLPatch_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) @@ -460,10 +460,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[cv_translucenthud.value]; else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; flags |= PF_Modulated; - HWD.pfnDrawPolygon(&Surf, v, 4, flags); + GL_DrawPolygon(&Surf, v, 4, flags); } else - HWD.pfnDrawPolygon(NULL, v, 4, flags); + GL_DrawPolygon(NULL, v, 4, flags); } // ========================================================================== @@ -539,7 +539,7 @@ void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum // BTW, I see we put 0 for PFs, and If I'm right, that // means we take the previous PFs as default // how can we be sure they are ok? - HWD.pfnDrawPolygon(NULL, v, 4, PF_NoDepthTest); //PF_Translucent); + GL_DrawPolygon(NULL, v, 4, PF_NoDepthTest); //PF_Translucent); } @@ -575,10 +575,10 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) Surf.LightTableId = HWR_GetLightTableID(NULL); Surf.LightInfo.light_level = strength; - HWD.pfnMakeScreenTexture(scr_tex); - HWD.pfnSetShader(HWR_GetShaderFromTarget(SHADER_UI_COLORMAP_FADE)); - HWD.pfnDrawScreenTexture(scr_tex, &Surf, PF_ColorMapped|PF_NoDepthTest); - HWD.pfnUnSetShader(); + GL_MakeScreenTexture(scr_tex); + GL_SetShader(HWR_GetShaderFromTarget(SHADER_UI_COLORMAP_FADE)); + GL_DrawScreenTexture(scr_tex, &Surf, PF_ColorMapped|PF_NoDepthTest); + GL_UnSetShader(); return; } @@ -602,7 +602,7 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) poly_flags |= PF_Translucent; } - HWD.pfnDrawPolygon(&Surf, v, 4, poly_flags); + GL_DrawPolygon(&Surf, v, 4, poly_flags); } // Draw the console background with translucency support @@ -629,7 +629,7 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height) Surf.PolyColor.rgba = UINT2RGBA(color); Surf.PolyColor.s.alpha = 0x80; - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); + GL_DrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); } @@ -785,7 +785,7 @@ void HWR_drawAMline(const fline_t *fl, INT32 color) v2.x = ((float)fl->b.x-(vid.width/2.0f))*(2.0f/vid.width); v2.y = ((float)fl->b.y-(vid.height/2.0f))*(2.0f/vid.height); - HWD.pfnDraw2DLine(&v1, &v2, color_rgba); + GL_Draw2DLine(&v1, &v2, color_rgba); } // -----------------+ @@ -879,7 +879,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) Surf.PolyColor = palette[color&0xFF]; - HWD.pfnDrawPolygon(&Surf, v, 4, + GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_NoTexture|PF_NoDepthTest); } @@ -918,7 +918,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 clearColour.green = (float)rgbaColour.s.green / 255; clearColour.blue = (float)rgbaColour.s.blue / 255; clearColour.alpha = 1; - HWD.pfnClearBuffer(true, false, false, &clearColour); + GL_ClearBuffer(true, false, false, &clearColour); return; } @@ -989,7 +989,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 Surf.PolyColor.rgba = UINT2RGBA(color); Surf.PolyColor.s.alpha = 0x80; - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); + GL_DrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); } // -----------------+ @@ -1029,7 +1029,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) clearColour.green = (float)rgbaColour.s.green / 255; clearColour.blue = (float)rgbaColour.s.blue / 255; clearColour.alpha = 1; - HWD.pfnClearBuffer(true, false, false, &clearColour); + GL_ClearBuffer(true, false, false, &clearColour); return; } @@ -1107,7 +1107,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; } - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); + GL_DrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); } #ifdef HAVE_PNG @@ -1191,7 +1191,7 @@ UINT8 *HWR_GetScreenshot(void) return NULL; // returns 24bit 888 RGB - HWD.pfnReadScreenTexture(HWD_SCREENTEXTURE_GENERIC2, (void *)buf); + GL_ReadScreenTexture(HWD_SCREENTEXTURE_GENERIC2, (void *)buf); return buf; } @@ -1207,7 +1207,7 @@ boolean HWR_Screenshot(const char *pathname) } // returns 24bit 888 RGB - HWD.pfnReadScreenTexture(HWD_SCREENTEXTURE_GENERIC2, (void *)buf); + GL_ReadScreenTexture(HWD_SCREENTEXTURE_GENERIC2, (void *)buf); #ifdef USE_PNG ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL); diff --git a/src/hardware/hw_gpu.h b/src/hardware/hw_gpu.h new file mode 100644 index 000000000..384587b37 --- /dev/null +++ b/src/hardware/hw_gpu.h @@ -0,0 +1,76 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020 by Jaime "Lactozilla" Passos. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file hw_gpu.h +/// \brief GPU low-level interface API + +#ifndef __HWR_GPU_H__ +#define __HWR_GPU_H__ + +#include "../screen.h" +#include "hw_data.h" +#include "hw_defs.h" +#include "hw_md2.h" + +#define SCREENVERTS 10 + +boolean GL_Init (void); +void GL_FinishUpdate (INT32 waitvbl); +void SetupGLInfo (void); + +void GL_SetSpecialState (hwdspecialstate_t IdState, INT32 Value); +void GL_SetTransform (FTransform *stransform); +void GL_SetBlend (FBITFIELD PolyFlags); +void GL_SetPalette (RGBA_t *palette); +void GL_ClearBuffer (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat * ClearColor); + +void GL_DrawPolygon (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags); +void GL_DrawIndexedTriangles (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray); +void GL_Draw2DLine (F2DCoord *v1, F2DCoord *v2, RGBA_t Color); +void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface); +#define GL_DrawModel(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface) GL_DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface) +void GL_RenderSkyDome (gl_sky_t *sky); + +void GL_SetTexture (GLMipmap_t *pTexInfo); +void GL_UpdateTexture (GLMipmap_t *pTexInfo); +void GL_DeleteTexture (GLMipmap_t *pTexInfo); + +void GL_Flush(void); +#define GL_ClearMipMapCache GL_Flush + +INT32 GL_GetTextureUsed (void); + +void GL_CreateModelVBOs (model_t *model); + +void GL_ReadScreenTexture (int tex, UINT16 *dst_data); +void GL_GClipRect (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip); + +void GL_MakeScreenTexture (int tex); +void GL_FlushScreenTextures (void); + +void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags); +void GL_DoScreenWipe (int wipeStart, int wipeEnd); +void GL_RenderVhsEffect (fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); +void GL_DrawScreenFinalTexture (int tex, INT32 width, INT32 height, boolean useshader); + +void GL_PostImgRedraw (float points[SCREENVERTS][SCREENVERTS][2]); + +boolean GL_InitShaders (void); +void GL_LoadShader (int slot, char *code, hwdshaderstage_t stage); +boolean GL_CompileShader (int slot); +void GL_SetShader (int slot); +void GL_UnSetShader (void); + +void GL_SetShaderInfo (hwdshaderinfo_t info, INT32 value); + +void GL_SetPaletteLookup (UINT8 *lut); +UINT32 GL_CreateLightTable (RGBA_t *hw_lighttable); +void GL_ClearLightTables (void); +void GL_SetScreenPalette (RGBA_t *palette); + +#endif // __HWR_GPU_H__ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5e24e6eae..e084b78f6 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -14,13 +14,14 @@ #include #include "../doomstat.h" +#include "../doomdef.h" #include "../qs22j.h" #ifdef HWRENDER #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gpu.h" #include "hw_batching.h" #include "hw_md2.h" #include "hw_clip.h" @@ -63,8 +64,6 @@ #define ABS(x) ((x) < 0 ? -(x) : (x)) #define SOFTLIGHT(llevel) HWR_ShouldUsePaletteRendering() ? ((llevel) >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : (llevel) -struct hwdriver_s hwdriver; - // false if shaders have not been initialized yet, or if shaders are not available boolean gl_shadersavailable = false; @@ -242,7 +241,7 @@ static void CV_screentextures_OnChange(void) CV_SetValue(&cv_glframebuffer, 0); #endif } - HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_glscreentextures.value); + GL_SetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_glscreentextures.value); M_UpdateOGLMenu(); } @@ -283,13 +282,13 @@ static void CV_gllightdithering_OnChange(void) static void CV_filtermode_OnChange(void) { ONLY_IF_GL_LOADED - HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_glfiltermode.value); + GL_SetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_glfiltermode.value); } static void CV_anisotropic_OnChange(void) { ONLY_IF_GL_LOADED - HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_glanisotropicmode.value); + GL_SetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_glanisotropicmode.value); } static void CV_glpaletterendering_OnChange(void) @@ -324,7 +323,7 @@ boolean HWR_UseShader(void) static void HWR_SetShaderState(void) { - HWD.pfnSetSpecialState(HWD_SET_SHADERS, HWR_UseShader() ? 1 : 0); + GL_SetSpecialState(HWD_SET_SHADERS, HWR_UseShader() ? 1 : 0); } boolean HWR_ShouldUsePaletteRendering(void) @@ -1117,10 +1116,10 @@ static void HWR_DrawSkyWallList(void) surf.PolyColor.rgba = 0xFFFFFFFF; HWR_SetCurrentTexture(NULL); - HWD.pfnUnSetShader(); + GL_UnSetShader(); for (i = 0; i < skyWallVertexArraySize; i++) { - HWD.pfnDrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture); + GL_DrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture); } } @@ -4226,7 +4225,7 @@ static void HWR_RenderDrawNodes(void) PS_START_TIMING(ps_hw_nodedrawtime); // Okay! Let's draw it all! Woo! - HWD.pfnSetTransform(&atransform); + GL_SetTransform(&atransform); for (i = 0; i < numdrawnodes; i++) { @@ -5072,7 +5071,7 @@ static void HWR_DrawSkyBackground(void) if (drewsky) return; - HWD.pfnSetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated); + GL_SetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated); memcpy(&dometransform, &atransform, sizeof(FTransform)); @@ -5094,9 +5093,9 @@ static void HWR_DrawSkyBackground(void) } if (HWR_UseShader()) - HWD.pfnSetShader(HWR_GetShaderFromTarget(SHADER_SKY)); - HWD.pfnSetTransform(&dometransform); - HWD.pfnRenderSkyDome(&gl_sky); + GL_SetShader(HWR_GetShaderFromTarget(SHADER_SKY)); + GL_SetTransform(&dometransform); + GL_RenderSkyDome(&gl_sky); } // -----------------+ @@ -5104,12 +5103,12 @@ static void HWR_DrawSkyBackground(void) // -----------------+ static inline void HWR_ClearView(void) { - HWD.pfnGClipRect((INT32)gl_viewwindowx, - (INT32)gl_viewwindowy, - (INT32)(gl_viewwindowx + gl_viewwidth), - (INT32)(gl_viewwindowy + gl_viewheight), - ZCLIP_PLANE, FAR_ZCLIP_DEFAULT); - HWD.pfnClearBuffer(false, true, true, NULL); + GL_GClipRect((INT32)gl_viewwindowx, + (INT32)gl_viewwindowy, + (INT32)(gl_viewwindowx + gl_viewwidth), + (INT32)(gl_viewwindowy + gl_viewheight), + ZCLIP_PLANE, FAR_ZCLIP_DEFAULT); + GL_ClearBuffer(false, true, true, NULL); } @@ -5131,7 +5130,7 @@ void HWR_SetViewSize(void) gl_baseviewwindowy = 0; gl_baseviewwindowx = 0; - HWD.pfnFlushScreenTextures(); + GL_FlushScreenTextures(); } // Set view aiming, for the sky dome, the skybox, @@ -5196,7 +5195,7 @@ void HWR_SetTransform(float fpov, player_t *player) atransform.mirrorflip = true; // Set transform. - HWD.pfnSetTransform(&atransform); + GL_SetTransform(&atransform); } void HWR_ClearClipper(void) @@ -5213,8 +5212,8 @@ void HWR_ClearClipper(void) void HWR_SetStencilState(int state, int level) { if (level > -1) - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, state); + GL_SetSpecialState(HWD_SET_STENCIL_LEVEL, level); + GL_SetSpecialState(HWD_SET_PORTAL_MODE, state); } // Renders the current viewpoint, though takes portal arguments for recursive portals. @@ -5270,7 +5269,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl } // Set transform. - HWD.pfnSetTransform(&atransform); + GL_SetTransform(&atransform); validcount++; @@ -5314,7 +5313,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl drewsky = false; HWR_DrawSkyBackground(); HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); - HWD.pfnClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer + GL_ClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer HWR_SetTransform(fpov, player);// restore transform } gl_collect_skywalls = false; @@ -5385,11 +5384,11 @@ static void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) if (!skybox && cv_glrenderdistance.value) { - HWD.pfnGClipRect((INT32)gl_viewwindowx, - (INT32)gl_viewwindowy, - (INT32)(gl_viewwindowx + gl_viewwidth), - (INT32)(gl_viewwindowy + gl_viewheight), - ZCLIP_PLANE, clipping_distances[cv_glrenderdistance.value - 1]); + GL_GClipRect((INT32)gl_viewwindowx, + (INT32)gl_viewwindowy, + (INT32)(gl_viewwindowx + gl_viewwidth), + (INT32)(gl_viewwindowy + gl_viewheight), + ZCLIP_PLANE, clipping_distances[cv_glrenderdistance.value - 1]); current_bsp_culling_distance = bsp_culling_distances[cv_glrenderdistance.value - 1]; } @@ -5397,8 +5396,8 @@ static void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); // Unset transform and shader - HWD.pfnSetTransform(NULL); - HWD.pfnUnSetShader(); + GL_SetTransform(NULL); + GL_UnSetShader(); // Run post processor effects if (!skybox) @@ -5406,7 +5405,7 @@ static void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) // added by Hurdler for correct splitscreen // moved here by hurdler so it works with the new near clipping plane - HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); + GL_GClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); } // ========================================================================== @@ -5436,11 +5435,14 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ClearColor.blue = 0.0f; ClearColor.alpha = 1.0f; - HWD.pfnClearBuffer(true, false, false, &ClearColor); + GL_ClearBuffer(true, false, false, &ClearColor); } - if (HWR_UseShader() && cv_ripplewater.value) - HWD.pfnSetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. + if (HWR_UseShader()) + { + if (cv_ripplewater.value) + GL_SetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. + } if (viewnumber > 3) return; @@ -5507,7 +5509,7 @@ static void HWR_TogglePaletteRendering(void) // If the r_opengl "texture palette" stays the same during this switch, these textures // will not be cleared out. However they are still out of date since the // composite texture blending method has changed. Therefore they need to be cleared. - HWD.pfnClearMipMapCache(); + GL_ClearMipMapCache(); } } else @@ -5521,7 +5523,7 @@ static void HWR_TogglePaletteRendering(void) // If the r_opengl "texture palette" stays the same during this switch, these textures // will not be cleared out. However they are still out of date since the // composite texture blending method has changed. Therefore they need to be cleared. - HWD.pfnClearMipMapCache(); + GL_ClearMipMapCache(); } } } @@ -5591,7 +5593,7 @@ void HWR_Startup(void) HWR_TogglePaletteRendering(); if (msaa) - HWD.pfnSetSpecialState(HWD_SET_MSAA, a2c ? 2 : 1); + GL_SetSpecialState(HWD_SET_MSAA, a2c ? 2 : 1); } startupdone = true; } @@ -5605,9 +5607,9 @@ void HWR_Shutdown(void) HWR_FreeExtraSubsectors(); HWR_FreeMipmapCache(); HWR_FreeTextureCache(); - HWD.pfnFlushScreenTextures(); + GL_FlushScreenTextures(); #ifdef USE_FBO_OGL - GLFramebuffer_Disable(); + GL_Framebuffer_Disable(); #endif } @@ -5650,12 +5652,12 @@ static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD INT32 HWR_GetTextureUsed(void) { - return HWD.pfnGetTextureUsed(); + return GL_GetTextureUsed(); } static void HWR_DoPostProcessor(player_t *player) { - HWD.pfnUnSetShader(); + GL_UnSetShader(); // Armageddon Blast Flash! // Could this even be considered postprocessor? @@ -5679,7 +5681,7 @@ static void HWR_DoPostProcessor(player_t *player) Surf.PolyColor.s.alpha = 0xc0; // match software mode - HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest); + GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest); } if (cv_glscreentextures.value != 2) // screen textures are needed for the rest of the effects @@ -5687,7 +5689,7 @@ static void HWR_DoPostProcessor(player_t *player) // Capture the screen for intermission and screen waving if (gamestate != GS_INTERMISSION) - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_GENERIC1); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_GENERIC1); if (splitscreen) // Not supported in splitscreen - someone want to add support? return; @@ -5727,28 +5729,28 @@ static void HWR_DoPostProcessor(player_t *player) v[x][y][1] = (y/((float)(SCREENVERTS-1.0f)/9.0f))-4.5f; } } - HWD.pfnPostImgRedraw(v); + GL_PostImgRedraw(v); // Capture the screen again for screen waving on the intermission if (gamestate != GS_INTERMISSION) - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_GENERIC1); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_GENERIC1); } // Flipping of the screen isn't done here anymore } void HWR_StartScreenWipe(void) { - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_WIPE_START); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_WIPE_START); } void HWR_EndScreenWipe(void) { - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_WIPE_END); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_WIPE_END); } void HWR_DrawIntermissionBG(void) { - HWD.pfnDrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); + GL_DrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); } void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) @@ -5782,22 +5784,22 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) } HWR_GetFadeMask(lumpnum); - HWD.pfnDoScreenWipe(HWD_SCREENTEXTURE_WIPE_START, HWD_SCREENTEXTURE_WIPE_END); + GL_DoScreenWipe(HWD_SCREENTEXTURE_WIPE_START, HWD_SCREENTEXTURE_WIPE_END); } void HWR_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize) { - HWD.pfnRenderVhsEffect(upbary, downbary, updistort, downdistort, barsize); + GL_RenderVhsEffect(upbary, downbary, updistort, downdistort, barsize); } void HWR_MakeScreenFinalTexture(void) { - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_GENERIC2); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_GENERIC2); } void HWR_DrawScreenFinalTexture(INT32 width, INT32 height, boolean useshader) { - HWD.pfnDrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, width, height, useshader); + GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, width, height, useshader); } #endif // HWRENDER diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 3de86bbda..5018496dd 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -25,12 +25,13 @@ #include "../doomstat.h" #ifdef HWRENDER -#include "hw_drv.h" +#include "hw_gpu.h" #include "hw_md2.h" #include "../d_main.h" #include "../r_bsp.h" #include "../r_fps.h" #include "../r_main.h" +#include "../p_setup.h" #include "../m_misc.h" #include "../w_wad.h" #include "../z_zone.h" @@ -417,7 +418,7 @@ static void md2_loadTexture(md2_t *model) } } } - HWD.pfnSetTexture(glpatch->mipmap); + GL_SetTexture(glpatch->mipmap); HWR_UnlockCachedPatch(glpatch); } @@ -467,7 +468,7 @@ static void md2_loadBlendTexture(md2_t *model) glpatch->mipmap->width = (UINT16)w; glpatch->mipmap->height = (UINT16)h; } - HWD.pfnSetTexture(glpatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary + GL_SetTexture(glpatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary HWR_UnlockCachedPatch(glpatch); Z_Free(filename); @@ -1048,11 +1049,11 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT if (colormap == colormaps || colormap == NULL) { // Don't do any blending - HWD.pfnSetTexture(gpatch->mipmap); + GL_SetTexture(gpatch->mipmap); return; } - // search for the Mipmap + // search for the mimmap // skip the first (no colormap translated) for (glMipmap = gpatch->mipmap; glMipmap->nextcolormap; ) { @@ -1063,7 +1064,7 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT if (glMipmap->downloaded && glMipmap->data) { - HWD.pfnSetTexture(glMipmap); // found the colormap, set it to the correct texture + GL_SetTexture(glMipmap); // found the colormap, set it to the correct texture Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); return; } @@ -1084,10 +1085,11 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT HWR_CreateBlendedTexture(gpatch, blendgpatch, newMipmap, skinnum, color); - HWD.pfnSetTexture(newMipmap); + GL_SetTexture(newMipmap); Z_ChangeTag(newMipmap->data, PU_HWRCACHE_UNLOCKED); } + // -----------------+ // HWR_DrawMD2 : Draw MD2 // : @@ -1233,7 +1235,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) if (md2->model) { md2_printModelInfo(md2->model); - HWD.pfnCreateModelVBOs(md2->model); + GL_CreateModelVBOs(md2->model); } else { @@ -1288,7 +1290,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) else { // This is safe, since we know the texture has been downloaded - HWD.pfnSetTexture(gpatch->mipmap); + GL_SetTexture(gpatch->mipmap); } } else @@ -1461,7 +1463,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) p.mirror = atransform.mirror; // from Kart #endif - HWD.pfnSetShader(SHADER_MODEL); // model shader + GL_SetShader(SHADER_MODEL); // model shader { SINT8 flipfactor = flip ? -1 : 1; @@ -1478,7 +1480,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) p.y += ox * gl_viewcos; p.z += oy; - HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, md2->scale * xs, md2->scale * ys, flip, hflip, &Surf); + GL_DrawModel(md2->model, frame, durs, tics, nextFrame, &p, md2->scale * xs, md2->scale * ys, flip, hflip, &Surf); } } } diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index 120e59e6c..7b5f93b97 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -23,7 +23,7 @@ #include "../z_zone.h" #include "hw_clip.h" -#include "hw_drv.h" +#include "hw_gpu.h" #include "hw_defs.h" #include "hw_main.h" #include "hw_portal.h" @@ -153,7 +153,7 @@ static void HWR_RenderPortalSeg(gl_portal_t* portal, SINT8 state) // need to work around the r_opengl PF_Invisible bug with this call // similarly as in the linkdraw hack in HWR_DrawSprites - HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); + GL_SetBlend(PF_Translucent|PF_Occlude|PF_Masked); } // Renders a single portal from the current viewpoint. diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index d73efaa37..2068cbb99 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -13,7 +13,7 @@ #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gpu.h" #include "hw_shaders.h" #include "../z_zone.h" @@ -87,7 +87,7 @@ boolean HWR_InitShaders(void) { int i; - if (!HWD.pfnInitShaders()) + if (!GL_InitShaders()) return false; for (i = 0; i < NUMSHADERTARGETS; i++) @@ -366,16 +366,16 @@ static void HWR_CompileShader(int index) { char *preprocessed = HWR_PreprocessShader(vertex_source); if (!preprocessed) return; - HWD.pfnLoadShader(index, preprocessed, HWD_SHADERSTAGE_VERTEX); + GL_LoadShader(index, preprocessed, HWD_SHADERSTAGE_VERTEX); } if (fragment_source) { char *preprocessed = HWR_PreprocessShader(fragment_source); if (!preprocessed) return; - HWD.pfnLoadShader(index, preprocessed, HWD_SHADERSTAGE_FRAGMENT); + GL_LoadShader(index, preprocessed, HWD_SHADERSTAGE_FRAGMENT); } - gl_shaders[index].compiled = HWD.pfnCompileShader(index); + gl_shaders[index].compiled = GL_CompileShader(index); } // compile or recompile shaders diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index b540d4ac3..9826ba06f 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -99,6 +99,7 @@ GLSL_DOOM_COLORMAP_NODITHER \ "#endif\n" \ "}\n" + // lighting cap adjustment: // first num (155.0), increase to make it start to go dark sooner // second num (0.26), increase to make it go dark faster diff --git a/src/hardware/r_opengl/ogl_win.c b/src/hardware/r_opengl/ogl_win.c index 8ce44d788..e819e0f68 100644 --- a/src/hardware/r_opengl/ogl_win.c +++ b/src/hardware/r_opengl/ogl_win.c @@ -358,8 +358,8 @@ static INT32 WINAPI SetRes(viddef_t *lvid, vmode_t *pcurrentmode) else textureformatGL = GL_RGB5_A1; - SetModelView(lvid->width, lvid->height); - SetStates(); + GL_SetModelView(lvid->width, lvid->height); + GL_SetStates(); // we need to clear the depth buffer. Very important!!! pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); @@ -526,7 +526,7 @@ EXPORT void HWRAPI(Shutdown) (void) // -----------------+ // FinishUpdate : Swap front and back buffers // -----------------+ -EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl) +void GL_FinishUpdate (INT32 waitvbl) { #ifdef USE_WGL_SWAP static INT32 oldwaitvbl = 0; @@ -547,23 +547,4 @@ EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl) SwapBuffers(hDC); } - - -// -----------------+ -// SetPalette : Set the color lookup table for paletted textures -// : in OpenGL, we store values for conversion of paletted graphics when -// : they are downloaded to the 3D card. -// -----------------+ -EXPORT void HWRAPI(SetPalette) (RGBA_t *pal) -{ - INT32 i; - - for (i = 0; i < 256; i++) - { - myPaletteData[i].s.red = pal[i].s.red; - myPaletteData[i].s.green = pal[i].s.green; - myPaletteData[i].s.blue = pal[i].s.blue; - myPaletteData[i].s.alpha = pal[i].s.alpha; - } -} #endif diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 19c03a7be..37ce52cae 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -40,8 +40,6 @@ #include "../../r_local.h" // For rendertimefrac, used for the leveltime shader uniform #include "../../i_video.h" -extern fixed_t fovtan; // also extremely bad, I'm just too lazy!!! - struct GLRGBAFloat { GLfloat red; @@ -706,8 +704,8 @@ static gl_shaderstate_t gl_shaderstate; static float shader_leveltime = 0; // Lactozilla: Shader functions -static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i); -static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade); +static boolean GL_Shader_CompileProgram(gl_shader_t *shader, GLint i); +static void GL_Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade); static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f}; @@ -719,7 +717,7 @@ static boolean GLFramebuffer_CheckExt(void) return false; // check if all needed gl extensions are available - return (isExtAvailable("GL_ARB_framebuffer_no_attachments", gl_extensions) && isExtAvailable("GL_ARB_framebuffer_object", gl_extensions) && isExtAvailable("GL_ARB_framebuffer_sRGB", gl_extensions)); + return (GL_isExtAvailable("GL_ARB_framebuffer_no_attachments", gl_extensions) && GL_isExtAvailable("GL_ARB_framebuffer_object", gl_extensions) && GL_isExtAvailable("GL_ARB_framebuffer_sRGB", gl_extensions)); } #endif @@ -791,7 +789,7 @@ void SetupGLFunc4(void) #endif } -EXPORT boolean HWRAPI(InitShaders) (void) +boolean GL_InitShaders(void) { if (!pglUseProgram) return false; @@ -799,7 +797,7 @@ EXPORT boolean HWRAPI(InitShaders) (void) gl_fallback_shader.vertex_shader = Z_StrDup(GLSL_FALLBACK_VERTEX_SHADER); gl_fallback_shader.fragment_shader = Z_StrDup(GLSL_FALLBACK_FRAGMENT_SHADER); - if (!Shader_CompileProgram(&gl_fallback_shader, -1)) + if (!GL_Shader_CompileProgram(&gl_fallback_shader, -1)) { GL_MSG_Error("Failed to compile the fallback shader program!\n"); return false; @@ -808,7 +806,7 @@ EXPORT boolean HWRAPI(InitShaders) (void) return true; } -EXPORT void HWRAPI(LoadShader) (int slot, char *code, hwdshaderstage_t stage) +void GL_LoadShader(int slot, char *code, hwdshaderstage_t stage) { gl_shader_t *shader; @@ -833,12 +831,12 @@ EXPORT void HWRAPI(LoadShader) (int slot, char *code, hwdshaderstage_t stage) #undef LOADSHADER } -EXPORT boolean HWRAPI(CompileShader) (int slot) +boolean GL_CompileShader(int slot) { if (slot < 0 || slot >= HWR_MAXSHADERS) I_Error("CompileShader: Invalid slot %d", slot); - if (Shader_CompileProgram(&gl_shaders[slot], slot)) + if (GL_Shader_CompileProgram(&gl_shaders[slot], slot)) { return true; } @@ -854,7 +852,7 @@ EXPORT boolean HWRAPI(CompileShader) (int slot) // Those are given to the uniforms. // -EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value) +void GL_SetShaderInfo(hwdshaderinfo_t info, INT32 value) { switch (info) { @@ -866,11 +864,11 @@ EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value) } } -EXPORT void HWRAPI(SetShader) (int slot) +void GL_SetShader(int slot) { if (slot == SHADER_NONE) { - UnSetShader(); + GL_UnSetShader(); return; } if (gl_allowshaders) @@ -897,7 +895,7 @@ EXPORT void HWRAPI(SetShader) (int slot) gl_shadersenabled = false; } -EXPORT void HWRAPI(UnSetShader) (void) +void GL_UnSetShader(void) { if (gl_shadersenabled) // don't repeatedly call glUseProgram if not needed { @@ -916,10 +914,10 @@ EXPORT void HWRAPI(UnSetShader) (void) // -----------------+ // SetNoTexture : Disable texture // -----------------+ -static void SetNoTexture(void) +static void GL_SetNoTexture(void) { // Disable texture. - if (tex_downloaded != NOTEXTURE_NUM) + if (tex_downloaded != NOTEXTURE_NUM && !currently_batching) { if (NOTEXTURE_NUM == 0) pglGenTextures(1, &NOTEXTURE_NUM); @@ -928,7 +926,10 @@ static void SetNoTexture(void) } } -static void GLPerspective(GLfloat fovy, GLfloat aspect) +// -----------------+ +// Perspective : +// -----------------+ +static void GL_Perspective(GLfloat fovy, GLfloat aspect) { GLfloat m[4][4] = { @@ -957,7 +958,7 @@ static void GLPerspective(GLfloat fovy, GLfloat aspect) // -----------------+ // SetModelView : // -----------------+ -void SetModelView(GLint w, GLint h) +void GL_SetModelView(GLint w, GLint h) { //GL_DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h); @@ -969,7 +970,7 @@ void SetModelView(GLint w, GLint h) pglMatrixMode(GL_MODELVIEW); pglLoadIdentity(); - GLPerspective(fov, ASPECT_RATIO); + GL_Perspective(fov, ASPECT_RATIO); // added for new coronas' code (without depth buffer) pglGetIntegerv(GL_VIEWPORT, viewport); @@ -979,7 +980,7 @@ void SetModelView(GLint w, GLint h) // -----------------+ // SetStates : Set permanent states // -----------------+ -void SetStates(void) +void GL_SetStates(void) { pglEnable(GL_TEXTURE_2D); // two-dimensional texturing pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -999,10 +1000,10 @@ void SetStates(void) // this set CurrentPolyFlags to the actual configuration CurrentPolyFlags = 0xffffffff; - SetBlend(0); + GL_SetBlend(0); tex_downloaded = 0; - SetNoTexture(); + GL_SetNoTexture(); pglPolygonOffset(-1.0f, -1.0f); @@ -1015,7 +1016,7 @@ void SetStates(void) // -----------------+ // DeleteTexture : Deletes a texture from the GPU and frees its data // -----------------+ -EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) +void GL_DeleteTexture(GLMipmap_t *pTexInfo) { FTextureInfo *head = TexCacheHead; @@ -1047,7 +1048,7 @@ EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) } #ifdef USE_FBO_OGL -static void GLFramebuffer_GenerateAttachments(void) +static void GL_Framebuffer_GenerateAttachments(void) { if (!supportFBO || !UseScreenFBO()) return; @@ -1079,7 +1080,7 @@ static void GLFramebuffer_GenerateAttachments(void) pglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, RenderbufferObject); // Clear the renderbuffer - ClearBuffer(true, true, true, NULL); + GL_ClearBuffer(true, true, true, NULL); pglBindRenderbuffer(GL_RENDERBUFFER, 0); } @@ -1090,7 +1091,7 @@ static void GLFramebuffer_GenerateAttachments(void) fboinit = true; } -void GLFramebuffer_DeleteAttachments(void) +void GL_Framebuffer_DeleteAttachments(void) { if (!supportFBO || fboinit == false) return; @@ -1113,7 +1114,7 @@ void GLFramebuffer_DeleteAttachments(void) fboinit = false; } -static void GLFramebuffer_Generate(void) +static void GL_Framebuffer_Generate(void) { if (!supportFBO || !UseScreenFBO()) return; @@ -1123,10 +1124,10 @@ static void GLFramebuffer_Generate(void) pglGenFramebuffers(1, &FramebufferObject); if (pglCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) - GLFramebuffer_GenerateAttachments(); + GL_Framebuffer_GenerateAttachments(); } -static void GLFramebuffer_Delete(void) +static void GL_Framebuffer_Delete(void) { if (!supportFBO || fboinit == false) return; @@ -1134,11 +1135,11 @@ static void GLFramebuffer_Delete(void) if (FramebufferObject) pglDeleteFramebuffers(1, &FramebufferObject); - GLFramebuffer_DeleteAttachments(); + GL_Framebuffer_DeleteAttachments(); FramebufferObject = 0; } -inline void GLFramebuffer_Unbind(void) +inline void GL_Framebuffer_Unbind(void) { if (!supportFBO || fboinit == false) return; @@ -1150,21 +1151,21 @@ inline void GLFramebuffer_Unbind(void) pglBindRenderbuffer(GL_RENDERBUFFER, 0); } -inline void GLFramebuffer_Enable(void) +inline void GL_Framebuffer_Enable(void) { if (!supportFBO || !UseScreenFBO()) return; if (FramebufferObject == 0) - GLFramebuffer_Generate(); + GL_Framebuffer_Generate(); else if (FramebufferTexture == 0 || RenderbufferObject == 0) - GLFramebuffer_GenerateAttachments(); + GL_Framebuffer_GenerateAttachments(); pglBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject); pglBindRenderbuffer(GL_RENDERBUFFER, RenderbufferObject); } -void GLFramebuffer_Disable(void) +void GL_Framebuffer_Disable(void) { if (!supportFBO || fboinit == false) return; @@ -1175,7 +1176,7 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); - GLFramebuffer_Delete(); + GL_Framebuffer_Delete(); } #endif @@ -1183,7 +1184,7 @@ void GLFramebuffer_Disable(void) // Flush : flush OpenGL textures // : Clear list of downloaded mipmaps // -----------------+ -void Flush(void) +void GL_Flush(void) { while (TexCacheHead) { @@ -1215,7 +1216,7 @@ void Flush(void) // isExtAvailable : Look if an OpenGL extension is available // Returns : true if extension available // -----------------+ -INT32 isExtAvailable(const char *extension, const GLubyte *start) +INT32 GL_isExtAvailable(const char *extension, const GLubyte *start) { GLubyte *where, *terminator; @@ -1242,34 +1243,25 @@ INT32 isExtAvailable(const char *extension, const GLubyte *start) // Init : Initialise the OpenGL interface API // Returns : // -----------------+ -EXPORT boolean HWRAPI(Init) (void) +boolean GL_Init (void) { - return LoadGL(); + return SetupGLfunc(); } // -----------------+ // SetupGLInfo : Retreive and store currently loaded OpenGL version // -----------------+ -EXPORT void HWRAPI(SetupGLInfo) (void) +void SetupGLInfo(void) { const GLubyte *versionGL = pglGetString(GL_VERSION); CONS_Printf("Loaded OpenGL version %s\n", (const char*)versionGL); sscanf((const char*)versionGL, "%d.%d", &majorGL, &minorGL); } - -// -----------------+ -// ClearMipMapCache : Flush OpenGL textures from memory -// -----------------+ -EXPORT void HWRAPI(ClearMipMapCache) (void) -{ - Flush(); -} - // Writes screen texture tex into dst_data. // Pixel format is 24-bit RGB. Row order is top to bottom. // Dimensions are screen_width * screen_height. -EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data) +void GL_ReadScreenTexture(int tex, UINT16 *dst_data) { INT32 i; int dst_stride = screen_width * 3; // stride between rows of image data @@ -1282,11 +1274,11 @@ EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data) // and draw generic2 back after reading the framebuffer. // this hack is for some reason **much** faster than the simple solution of using glGetTexImage. if (tex != HWD_SCREENTEXTURE_GENERIC2) - DrawScreenTexture(tex, NULL, 0); + GL_DrawScreenTexture(tex, NULL, 0); pglPixelStorei(GL_PACK_ALIGNMENT, 1); pglReadPixels(0, 0, screen_width, screen_height, GL_RGB, GL_UNSIGNED_BYTE, dst_data); if (tex != HWD_SCREENTEXTURE_GENERIC2) - DrawScreenTexture(HWD_SCREENTEXTURE_GENERIC2, NULL, 0); + GL_DrawScreenTexture(HWD_SCREENTEXTURE_GENERIC2, NULL, 0); // Flip image upside down. // In other words, convert OpenGL's "bottom->top" row order into "top->bottom". for(i = 0; i < screen_height/2; i++) @@ -1300,10 +1292,24 @@ EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data) free(row); } +// -----------------+ +// SetPalette : Changes the current texture palette +// -----------------+ +void GL_SetPalette(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)) + { + memcpy(&myPaletteData, palette, palsize); + GL_Flush(); + } +} + // -----------------+ // GClipRect : Defines the 2D hardware clipping window // -----------------+ -EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip) +void GL_GClipRect(INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip) { //GL_DBG_Printf("GClipRect(%d, %d, %d, %d)\n", minx, miny, maxx, maxy); @@ -1314,7 +1320,7 @@ EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, f //pglScissor(minx, screen_height-maxy, maxx-minx, maxy-miny); pglMatrixMode(GL_PROJECTION); pglLoadIdentity(); - GLPerspective(fov, ASPECT_RATIO); + GL_Perspective(fov, ASPECT_RATIO); pglMatrixMode(GL_MODELVIEW); // added for new coronas' code (without depth buffer) @@ -1326,10 +1332,7 @@ EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, f // -----------------+ // ClearBuffer : Clear the color/alpha/depth buffer(s) // -----------------+ -EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, - FBOOLEAN DepthMask, - FBOOLEAN StencilMask, - FRGBAFloat * ClearColor) +void GL_ClearBuffer(FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat * ClearColor) { //GL_DBG_Printf("ClearBuffer(%d)\n", alpha); GLbitfield ClearMask = 0; @@ -1351,7 +1354,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, ClearMask |= GL_DEPTH_BUFFER_BIT; } - SetBlend(DepthMask ? PF_Occlude | CurrentPolyFlags : CurrentPolyFlags&~PF_Occlude); + GL_SetBlend(DepthMask ? PF_Occlude | CurrentPolyFlags : CurrentPolyFlags&~PF_Occlude); if (StencilMask) ClearMask |= GL_STENCIL_BUFFER_BIT;// looks like sometimes stencil buffer needs clearing? had a problem with random black screens @@ -1364,9 +1367,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, // -----------------+ // HWRAPI Draw2DLine: Render a 2D line // -----------------+ -EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, - F2DCoord * v2, - RGBA_t Color) +void GL_Draw2DLine(F2DCoord * v1, F2DCoord * v2, RGBA_t Color) { //GL_DBG_Printf("DrawLine(): %f %f, %f %f\n", v1->x, v1->y, v2->x, v2->y); GLfloat p[12]; @@ -1413,7 +1414,7 @@ static void Clamp2D(GLenum pname) // -----------------+ // PF_Masked - we could use an ALPHA_TEST of GL_EQUAL, and alpha ref of 0, // is it faster when pixels are discarded ? -EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) +void GL_SetBlend(FBITFIELD PolyFlags) { FBITFIELD Xor; Xor = CurrentPolyFlags^PolyFlags; @@ -1540,12 +1541,12 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) } } if (PolyFlags & PF_NoTexture) - SetNoTexture(); + GL_SetNoTexture(); } CurrentPolyFlags = PolyFlags; } -static void AllocTextureBuffer(GLMipmap_t *pTexInfo) +static void GL_AllocTextureBuffer(GLMipmap_t *pTexInfo) { size_t size = pTexInfo->width * pTexInfo->height; if (size > textureBufferSize) @@ -1560,7 +1561,7 @@ static void AllocTextureBuffer(GLMipmap_t *pTexInfo) // -----------------+ // UpdateTexture : Updates texture data. // -----------------+ -EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) +void GL_UpdateTexture(GLMipmap_t *pTexInfo) { // Upload a texture GLuint num = pTexInfo->downloaded; @@ -1572,7 +1573,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) const GLubyte *pImgData = (const GLubyte *)pTexInfo->data; const GLvoid *ptex = NULL; RGBA_t *tex = NULL; - + // Generate a new texture name. if (!num) { @@ -1585,7 +1586,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) if ((pTexInfo->format == GL_TEXFMT_P_8) || (pTexInfo->format == GL_TEXFMT_AP_88)) { - AllocTextureBuffer(pTexInfo); + GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; for (j = 0; j < h; j++) @@ -1627,7 +1628,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) } else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) { - AllocTextureBuffer(pTexInfo); + GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; for (j = 0; j < h; j++) @@ -1645,7 +1646,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) } else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) // Used for fade masks { - AllocTextureBuffer(pTexInfo); + GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; for (j = 0; j < h; j++) @@ -1765,18 +1766,19 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) // -----------------+ // SetTexture : The mipmap becomes the current texture source // -----------------+ -EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo) +void GL_SetTexture(GLMipmap_t *pTexInfo) { if (!pTexInfo) { - SetNoTexture(); + GL_SetNoTexture(); return; } else if (pTexInfo->downloaded) { if (pTexInfo->downloaded != tex_downloaded) { - pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded); + if (!currently_batching) + pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded); tex_downloaded = pTexInfo->downloaded; } } @@ -1784,7 +1786,7 @@ EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo) { FTextureInfo *newTex = calloc(1, sizeof (*newTex)); - UpdateTexture(pTexInfo); + GL_UpdateTexture(pTexInfo); newTex->texture = pTexInfo; newTex->downloaded = (UINT32)pTexInfo->downloaded; @@ -1804,7 +1806,7 @@ EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo) } } -static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade) +static void GL_Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade) { gl_shader_t *shader = gl_shaderstate.current; @@ -1869,7 +1871,7 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF } } -static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) +static boolean GL_Shader_CompileProgram(gl_shader_t *shader, GLint i) { GLuint gl_vertShader = 0; GLuint gl_fragShader = 0; @@ -2014,13 +2016,13 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) // code that is common between DrawPolygon and DrawIndexedTriangles // DrawScreenTexture also can use this function for fancier screen texture drawing // the corona thing is there too, i have no idea if that stuff works with DrawIndexedTriangles and batching -static void PreparePolygon(FSurfaceInfo *pSurf, FBITFIELD PolyFlags) +static void GL_PreparePolygon(FSurfaceInfo *pSurf, FBITFIELD PolyFlags) { static GLRGBAFloat poly = {0,0,0,0}; static GLRGBAFloat tint = {0,0,0,0}; static GLRGBAFloat fade = {0,0,0,0}; - SetBlend(PolyFlags); //TODO: inline (#pragma..) + GL_SetBlend(PolyFlags); //TODO: inline (#pragma..) if (pSurf) { @@ -2060,15 +2062,15 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FBITFIELD PolyFlags) } } - Shader_SetUniforms(pSurf, &poly, &tint, &fade); + GL_Shader_SetUniforms(pSurf, &poly, &tint, &fade); } // -----------------+ // DrawPolygon : Render a polygon, set the texture, set render mode // -----------------+ -EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags) +void GL_DrawPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags) { - PreparePolygon(pSurf, PolyFlags); + GL_PreparePolygon(pSurf, PolyFlags); pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x); pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s); @@ -2084,9 +2086,9 @@ 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, unsigned int *IndexArray) +void GL_DrawIndexedTriangles(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray) { - PreparePolygon(pSurf, PolyFlags); + GL_PreparePolygon(pSurf, PolyFlags); pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x); pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s); @@ -2102,11 +2104,11 @@ static const boolean gl_ext_arb_vertex_buffer_object = true; #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) +void GL_RenderSkyDome(gl_sky_t *sky) { int i, j; - Shader_SetUniforms(NULL, NULL, NULL, NULL); + GL_Shader_SetUniforms(NULL, NULL, NULL, NULL); // Build the sky dome! Yes! if (sky->rebuild) @@ -2189,7 +2191,7 @@ EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky) // ========================================================================== // // ========================================================================== -EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) +void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) { switch (IdState) { @@ -2237,7 +2239,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) min_filter = GL_LINEAR; } - Flush(); //??? if we want to change filter mode by texture, remove this + GL_Flush(); //??? if we want to change filter mode by texture, remove this break; case HWD_SET_MSAA: @@ -2252,7 +2254,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_TEXTUREANISOTROPICMODE: anisotropic_filter = min(Value,maximumAnisotropy); if (maximumAnisotropy) - Flush(); //??? if we want to change filter mode by texture, remove this + GL_Flush(); //??? if we want to change filter mode by texture, remove this break; case HWD_SET_SCREEN_TEXTURES: @@ -2338,7 +2340,7 @@ static size_t lerpTinyBufferSize = 0; // Static temporary buffer for doing frame interpolation // 'size' is the vertex size -static void AllocLerpBuffer(size_t size) +static void GL_AllocLerpBuffer(size_t size) { if (lerpBufferSize >= size) return; @@ -2356,7 +2358,7 @@ static void AllocLerpBuffer(size_t size) // Static temporary buffer for doing frame interpolation // 'size' is the vertex size -static void AllocLerpTinyBuffer(size_t size) +static void GL_AllocLerpTinyBuffer(size_t size) { if (lerpTinyBufferSize >= size) return; @@ -2380,7 +2382,7 @@ static void AllocLerpTinyBuffer(size_t size) #define GL_ARRAY_BUFFER 0x8892 #endif -static void CreateModelVBO(mesh_t *mesh, mdlframe_t *frame) +static void GL_CreateModelVBO(mesh_t *mesh, mdlframe_t *frame) { int bufferSize = sizeof(vbo64_t)*mesh->numTriangles * 3; vbo64_t *buffer = (vbo64_t*)malloc(bufferSize); @@ -2448,7 +2450,7 @@ static void CreateModelVBO(mesh_t *mesh, mdlframe_t *frame) pglBindBuffer(GL_ARRAY_BUFFER, 0); } -static void CreateModelVBOTiny(mesh_t *mesh, tinyframe_t *frame) +static void GL_CreateModelVBOTiny(mesh_t *mesh, tinyframe_t *frame) { int bufferSize = sizeof(vbotiny_t)*mesh->numTriangles * 3; vbotiny_t *buffer = (vbotiny_t*)malloc(bufferSize); @@ -2493,9 +2495,10 @@ static void CreateModelVBOTiny(mesh_t *mesh, tinyframe_t *frame) pglBindBuffer(GL_ARRAY_BUFFER, 0); } -EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) +void GL_CreateModelVBOs(model_t *model) { int i; + for (i = 0; i < model->numMeshes; i++) { mesh_t *mesh = &model->meshes[i]; @@ -2509,7 +2512,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) if (frame->vboID) pglDeleteBuffers(1, &frame->vboID); frame->vboID = 0; - CreateModelVBO(mesh, frame); + GL_CreateModelVBO(mesh, frame); } } else if (mesh->tinyframes) @@ -2521,7 +2524,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) if (frame->vboID) pglDeleteBuffers(1, &frame->vboID); frame->vboID = 0; - CreateModelVBOTiny(mesh, frame); + GL_CreateModelVBOTiny(mesh, frame); } } } @@ -2529,7 +2532,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) #define BUFFER_OFFSET(i) ((char*)(i)) -static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) +void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) { static GLRGBAFloat poly = {0,0,0,0}; static GLRGBAFloat tint = {0,0,0,0}; @@ -2568,9 +2571,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float poly.alpha = byte2float[Surface->PolyColor.s.alpha]; if (poly.alpha < 1) - SetBlend(PF_Translucent|PF_Modulated); + GL_SetBlend(PF_Translucent|PF_Modulated); else - SetBlend(PF_Masked|PF_Modulated|PF_Occlude); + GL_SetBlend(PF_Masked|PF_Modulated|PF_Occlude); pglColor4ubv((GLubyte*)&Surface->PolyColor.s); @@ -2592,7 +2595,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float lt_downloaded = Surface->LightTableId; } - Shader_SetUniforms(Surface, &poly, &tint, &fade); + GL_Shader_SetUniforms(Surface, &poly, &tint, &fade); pglEnable(GL_CULL_FACE); pglEnable(GL_NORMALIZE); @@ -2688,7 +2691,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float int j = 0; // Dangit, I soooo want to do this in a GLSL shader... - AllocLerpTinyBuffer(mesh->numVertices * sizeof(short) * 3); + GL_AllocLerpTinyBuffer(mesh->numVertices * sizeof(short) * 3); vertPtr = vertTinyBuffer; normPtr = normTinyBuffer; @@ -2731,7 +2734,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float int j = 0; // Dangit, I soooo want to do this in a GLSL shader... - AllocLerpBuffer(mesh->numVertices * sizeof(float) * 3); + GL_AllocLerpBuffer(mesh->numVertices * sizeof(float) * 3); vertPtr = vertBuffer; normPtr = normBuffer; @@ -2757,18 +2760,10 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float pglDisable(GL_NORMALIZE); } -// -----------------+ -// HWRAPI DrawModel : Draw a model -// -----------------+ -EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) -{ - DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface); -} - // -----------------+ // SetTransform : // -----------------+ -EXPORT void HWRAPI(SetTransform) (FTransform *stransform) +void GL_SetTransform(FTransform *stransform) { static boolean special_splitscreen; GLdouble used_fov; @@ -2828,10 +2823,10 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) if (special_splitscreen) { used_fov = (float)(atan(tan(used_fov * M_PIl / 360) * 0.8) * 360 / M_PIl); - GLPerspective((GLfloat)used_fov, 2*ASPECT_RATIO); + GL_Perspective((GLfloat)used_fov, 2*ASPECT_RATIO); } else - GLPerspective((GLfloat)used_fov, ASPECT_RATIO); + GL_Perspective((GLfloat)used_fov, ASPECT_RATIO); pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) pglMatrixMode(GL_MODELVIEW); @@ -2839,7 +2834,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) } -EXPORT INT32 HWRAPI(GetTextureUsed) (void) +INT32 GL_GetTextureUsed(void) { FTextureInfo *tmp = TexCacheHead; INT32 res = 0; @@ -2864,7 +2859,7 @@ EXPORT INT32 HWRAPI(GetTextureUsed) (void) return res; } -EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) +void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]) { INT32 x, y; float float_x, float_y, float_nextx, float_nexty; @@ -2901,9 +2896,9 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - for(x=0;x Date: Sun, 8 Dec 2024 03:13:50 +0100 Subject: [PATCH 02/14] delet this --- src/hardware/hw_drv.h | 142 ----------------------------------------- src/hardware/hw_main.c | 5 +- 2 files changed, 2 insertions(+), 145 deletions(-) delete mode 100644 src/hardware/hw_drv.h diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h deleted file mode 100644 index 78fb53d1e..000000000 --- a/src/hardware/hw_drv.h +++ /dev/null @@ -1,142 +0,0 @@ -// SONIC ROBO BLAST 2 -//----------------------------------------------------------------------------- -// Copyright (C) 1993-1996 by id Software, Inc. -// Copyright (C) 1998-2000 by DooM Legacy Team. -// Copyright (C) 1999-2019 by Sonic Team Junior. -// -// This program is free software distributed under the -// terms of the GNU General Public License, version 2. -// See the 'LICENSE' file for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief imports/exports for the GPU hardware low-level interface API - -#ifndef __HWR_DRV_H__ -#define __HWR_DRV_H__ - -// this must be here 19991024 by Kin -#include "../screen.h" -#include "hw_data.h" -#include "hw_defs.h" -#include "hw_md2.h" - -#include "hw_dll.h" -#include "../doomdef.h" - -// ========================================================================== -// STANDARD DLL EXPORTS -// ========================================================================== - -EXPORT boolean HWRAPI(Init) (void); -EXPORT void HWRAPI(SetupGLInfo) (void); -EXPORT void HWRAPI(SetTexturePalette) (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, unsigned int *IndexArray); -EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags); -EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat *ClearColor); -EXPORT void HWRAPI(SetTexture) (GLMipmap_t *TexInfo); -EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *TexInfo); -EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *TexInfo); -EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data); -EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip); -EXPORT void HWRAPI(ClearMipMapCache) (void); - -//Hurdler: added for backward compatibility -EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); - -//Hurdler: added for new development - -EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface); - -EXPORT void HWRAPI(CreateModelVBOs) (model_t *model); -EXPORT void HWRAPI(SetTransform) (FTransform *stransform); -EXPORT INT32 HWRAPI(GetTextureUsed) (void); - -EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky); - -EXPORT void HWRAPI(FlushScreenTextures) (void); -EXPORT void HWRAPI(DoScreenWipe) (int wipeStart, int wipeEnd); -EXPORT void HWRAPI(DrawScreenTexture) (int tex, FSurfaceInfo *surf, FBITFIELD polyflags); -EXPORT void HWRAPI(MakeScreenTexture) (int tex); -EXPORT void HWRAPI(DrawScreenFinalTexture) (int tex, INT32 width, INT32 height, boolean useshader); - -EXPORT void HWRAPI(RenderVhsEffect) (fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); - -#define SCREENVERTS 10 -EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]); - -// jimita -EXPORT boolean HWRAPI(InitShaders) (void); -EXPORT void HWRAPI(LoadShader) (int slot, char *code, hwdshaderstage_t stage); -EXPORT boolean HWRAPI(CompileShader) (int slot); -EXPORT void HWRAPI(SetShader) (int slot); -EXPORT void HWRAPI(UnSetShader) (void); - -EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value); - -EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut); -EXPORT UINT32 HWRAPI(CreateLightTable)(RGBA_t *hw_lighttable); -EXPORT void HWRAPI(ClearLightTables)(void); -EXPORT void HWRAPI(SetScreenPalette)(RGBA_t *palette); - -// ========================================================================== -// HWR DRIVER OBJECT, FOR CLIENT PROGRAM -// ========================================================================== - -#if !defined (_CREATE_DLL_) - -struct hwdriver_s -{ - Init pfnInit; - SetupGLInfo pfnSetupGLInfo; - SetTexturePalette pfnSetTexturePalette; - FinishUpdate pfnFinishUpdate; - Draw2DLine pfnDraw2DLine; - DrawPolygon pfnDrawPolygon; - DrawIndexedTriangles pfnDrawIndexedTriangles; - SetBlend pfnSetBlend; - ClearBuffer pfnClearBuffer; - SetTexture pfnSetTexture; - UpdateTexture pfnUpdateTexture; - DeleteTexture pfnDeleteTexture; - ReadScreenTexture pfnReadScreenTexture; - GClipRect pfnGClipRect; - ClearMipMapCache pfnClearMipMapCache; - SetSpecialState pfnSetSpecialState; - DrawModel pfnDrawModel; - CreateModelVBOs pfnCreateModelVBOs; - SetTransform pfnSetTransform; - GetTextureUsed pfnGetTextureUsed; - PostImgRedraw pfnPostImgRedraw; - FlushScreenTextures pfnFlushScreenTextures; - DoScreenWipe pfnDoScreenWipe; - DrawScreenTexture pfnDrawScreenTexture; - MakeScreenTexture pfnMakeScreenTexture; - RenderVhsEffect pfnRenderVhsEffect; - DrawScreenFinalTexture pfnDrawScreenFinalTexture; - - RenderSkyDome pfnRenderSkyDome; - - InitShaders pfnInitShaders; - LoadShader pfnLoadShader; - CompileShader pfnCompileShader; - SetShader pfnSetShader; - UnSetShader pfnUnSetShader; - - SetShaderInfo pfnSetShaderInfo; - - SetPaletteLookup pfnSetPaletteLookup; - CreateLightTable pfnCreateLightTable; - ClearLightTables pfnClearLightTables; - SetScreenPalette pfnSetScreenPalette; -}; - -extern struct hwdriver_s hwdriver; - -#define HWD hwdriver - -#endif //not defined _CREATE_DLL_ - -#endif //__HWR_DRV_H__ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e084b78f6..cbac939c4 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5438,10 +5438,9 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) GL_ClearBuffer(true, false, false, &ClearColor); } - if (HWR_UseShader()) + if (HWR_UseShader() && cv_ripplewater.value) { - if (cv_ripplewater.value) - GL_SetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. + GL_SetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. } if (viewnumber > 3) -- 2.54.0 From e5b12ece358463df647e38fec1e3f72e89a16b4d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 03:15:14 +0100 Subject: [PATCH 03/14] change this --- src/sdl/ogl_sdl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index a5d171107..cfa6683bd 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -261,8 +261,7 @@ void OglSdlFinishUpdate(boolean waitvbl) } #endif - //HWR_DrawScreenFinalTexture(sdlw, sdlh); - GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, sdlw, sdlh, true); + GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, sdlw, sdlh, HWR_ShouldUsePaletteRendering()); #ifdef USE_FBO_OGL if (UseScreenFBO()) -- 2.54.0 From c1b771fdc84bb61ff0fc4a727fa6852a4561a062 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 03:16:13 +0100 Subject: [PATCH 04/14] fix make files --- src/CMakeLists.txt | 2 +- src/Makefile | 4 ++-- src/sdl/macosx/Srb2mac.pbproj/project.pbxproj | 4 ++-- src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8fde277c7..35669ce52 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -487,7 +487,7 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_drv.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_gpu.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_portal.h diff --git a/src/Makefile b/src/Makefile index 4df4e1fe8..b2cac197e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -738,7 +738,7 @@ else ifdef SDL ifdef MINGW $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ - doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_gpu.h screen.h \ command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \ hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h hardware/hw_portal.h\ hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ @@ -747,7 +747,7 @@ $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ else $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ - doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_gpu.h screen.h \ command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \ hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h hardware/hw_portal.h \ hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ diff --git a/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj index ee0bf4697..3d8c7a82e 100644 --- a/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj @@ -1060,8 +1060,8 @@ 8417773A085A106C000C01D8 = { fileEncoding = 30; isa = PBXFileReference; - name = hw_drv.h; - path = ../../hardware/hw_drv.h; + name = hw_gpu.h; + path = ../../hardware/hw_gpu.h; refType = 2; }; 8417773C085A106C000C01D8 = { diff --git a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj index 00930bfb3..8a2f00c9c 100644 --- a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj @@ -180,7 +180,7 @@ 1E44AE630B67CC2B00BAD059 /* hw3sound.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw3sound.c; path = ../../hardware/hw3sound.c; sourceTree = SOURCE_ROOT; }; 1E44AE640B67CC2B00BAD059 /* hw_cache.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_cache.c; path = ../../hardware/hw_cache.c; sourceTree = SOURCE_ROOT; }; 1E44AE650B67CC2B00BAD059 /* hw_dll.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_dll.h; path = ../../hardware/hw_dll.h; sourceTree = SOURCE_ROOT; }; - 1E44AE660B67CC2B00BAD059 /* hw_drv.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_drv.h; path = ../../hardware/hw_drv.h; sourceTree = SOURCE_ROOT; }; + 1E44AE660B67CC2B00BAD059 /* hw_gpu.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_gpu.h; path = ../../hardware/hw_gpu.h; sourceTree = SOURCE_ROOT; }; 1E44AE680B67CC2B00BAD059 /* hw_light.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_light.c; path = ../../hardware/hw_light.c; sourceTree = SOURCE_ROOT; }; 1E44AE690B67CC2B00BAD059 /* hw_light.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_light.h; path = ../../hardware/hw_light.h; sourceTree = SOURCE_ROOT; }; 1E44AE6A0B67CC2B00BAD059 /* hw3sound.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw3sound.h; path = ../../hardware/hw3sound.h; sourceTree = SOURCE_ROOT; }; @@ -533,7 +533,7 @@ 1E44AE630B67CC2B00BAD059 /* hw3sound.c */, 1E44AE640B67CC2B00BAD059 /* hw_cache.c */, 1E44AE650B67CC2B00BAD059 /* hw_dll.h */, - 1E44AE660B67CC2B00BAD059 /* hw_drv.h */, + 1E44AE660B67CC2B00BAD059 /* hw_gpu.h */, 1E44AE680B67CC2B00BAD059 /* hw_light.c */, 1E44AE690B67CC2B00BAD059 /* hw_light.h */, 1E44AE6A0B67CC2B00BAD059 /* hw3sound.h */, -- 2.54.0 From 3f16f42adfe2f8beeefb31e6e2a412b94330f84e Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 05:03:36 +0100 Subject: [PATCH 05/14] forgor --- src/sdl/ogl_sdl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index cfa6683bd..95b05d583 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -281,10 +281,8 @@ void OglSdlFinishUpdate(boolean waitvbl) && (!UseScreenFBO()) #endif ) - HWR_DrawScreenFinalTexture(realwidth, realheight, false); - - //HWR_DrawScreenFinalTexture(realwidth, realheight); - //GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, realwidth, realheight); + //HWR_DrawScreenFinalTexture(realwidth, realheight, false); + GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, realwidth, realheight, false); } #endif //HWRENDER -- 2.54.0 From cd9ee7d1394c0a47df49f6037436416a072167b7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 15:31:28 +0100 Subject: [PATCH 06/14] smol cleanup --- src/hardware/hw_gpu.h | 73 +++++++++++++++++--------------- src/hardware/r_opengl/r_opengl.h | 2 - 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/hardware/hw_gpu.h b/src/hardware/hw_gpu.h index 384587b37..0d63296c6 100644 --- a/src/hardware/hw_gpu.h +++ b/src/hardware/hw_gpu.h @@ -13,64 +13,67 @@ #define __HWR_GPU_H__ #include "../screen.h" + #include "hw_data.h" #include "hw_defs.h" #include "hw_md2.h" #define SCREENVERTS 10 -boolean GL_Init (void); -void GL_FinishUpdate (INT32 waitvbl); -void SetupGLInfo (void); +boolean GL_Init(void); +void GL_FinishUpdate(INT32 waitvbl); +void SetupGLInfo(void); -void GL_SetSpecialState (hwdspecialstate_t IdState, INT32 Value); -void GL_SetTransform (FTransform *stransform); -void GL_SetBlend (FBITFIELD PolyFlags); -void GL_SetPalette (RGBA_t *palette); -void GL_ClearBuffer (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat * ClearColor); +void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value); +void GL_SetTransform(FTransform *stransform); +void GL_SetBlend(FBITFIELD PolyFlags); +void GL_SetPalette(RGBA_t *palette); +void GL_ClearBuffer(FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat * ClearColor); + +void GL_DrawPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags); +void GL_DrawIndexedTriangles(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray); +void GL_Draw2DLine(F2DCoord *v1, F2DCoord *v2, RGBA_t Color); -void GL_DrawPolygon (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags); -void GL_DrawIndexedTriangles (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray); -void GL_Draw2DLine (F2DCoord *v1, F2DCoord *v2, RGBA_t Color); void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface); #define GL_DrawModel(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface) GL_DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface) -void GL_RenderSkyDome (gl_sky_t *sky); -void GL_SetTexture (GLMipmap_t *pTexInfo); -void GL_UpdateTexture (GLMipmap_t *pTexInfo); -void GL_DeleteTexture (GLMipmap_t *pTexInfo); +void GL_RenderSkyDome(gl_sky_t *sky); + +void GL_SetTexture(GLMipmap_t *pTexInfo); +void GL_UpdateTexture(GLMipmap_t *pTexInfo); +void GL_DeleteTexture(GLMipmap_t *pTexInfo); void GL_Flush(void); #define GL_ClearMipMapCache GL_Flush -INT32 GL_GetTextureUsed (void); +INT32 GL_GetTextureUsed(void); -void GL_CreateModelVBOs (model_t *model); +void GL_CreateModelVBOs(model_t *model); -void GL_ReadScreenTexture (int tex, UINT16 *dst_data); -void GL_GClipRect (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip); +void GL_ReadScreenTexture(int tex, UINT16 *dst_data); +void GL_GClipRect(INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip); -void GL_MakeScreenTexture (int tex); -void GL_FlushScreenTextures (void); +void GL_MakeScreenTexture(int tex); +void GL_FlushScreenTextures(void); void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags); -void GL_DoScreenWipe (int wipeStart, int wipeEnd); -void GL_RenderVhsEffect (fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); -void GL_DrawScreenFinalTexture (int tex, INT32 width, INT32 height, boolean useshader); +void GL_DoScreenWipe(int wipeStart, int wipeEnd); +void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); +void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean useshader); -void GL_PostImgRedraw (float points[SCREENVERTS][SCREENVERTS][2]); +void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]); -boolean GL_InitShaders (void); -void GL_LoadShader (int slot, char *code, hwdshaderstage_t stage); -boolean GL_CompileShader (int slot); -void GL_SetShader (int slot); -void GL_UnSetShader (void); +boolean GL_InitShaders(void); +void GL_LoadShader(int slot, char *code, hwdshaderstage_t stage); +boolean GL_CompileShader(int slot); +void GL_SetShader(int slot); +void GL_UnSetShader(void); -void GL_SetShaderInfo (hwdshaderinfo_t info, INT32 value); +void GL_SetShaderInfo(hwdshaderinfo_t info, INT32 value); -void GL_SetPaletteLookup (UINT8 *lut); -UINT32 GL_CreateLightTable (RGBA_t *hw_lighttable); -void GL_ClearLightTables (void); -void GL_SetScreenPalette (RGBA_t *palette); +void GL_SetPaletteLookup(UINT8 *lut); +UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable); +void GL_ClearLightTables(void); +void GL_SetScreenPalette(RGBA_t *palette); #endif // __HWR_GPU_H__ diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index a03febd3c..c453e4ebf 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -130,8 +130,6 @@ extern GLbyte screen_depth; extern GLint maximumAnisotropy; extern boolean supportMipMap; -extern struct GPURenderingAPI GLInterfaceAPI; - /** \brief OpenGL flags for video driver */ extern INT32 oglflags; -- 2.54.0 From b03e74c366ec66532617bc9653819d758ba0189e Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 15:39:52 +0100 Subject: [PATCH 07/14] rename to "hw_gl" --- src/CMakeLists.txt | 2 +- src/Makefile | 4 ++-- src/hardware/hw_batching.h | 2 +- src/hardware/hw_cache.c | 3 ++- src/hardware/hw_draw.c | 3 ++- src/hardware/{hw_gpu.h => hw_gl.h} | 13 +++++++------ src/hardware/hw_main.c | 7 ++++--- src/hardware/hw_md2.c | 5 +++-- src/hardware/hw_portal.c | 2 +- src/hardware/hw_shaders.c | 2 +- src/hardware/r_opengl/r_opengl.h | 3 ++- src/sdl/Srb2SDL.dsp | 2 +- src/sdl/i_video.c | 10 ++++++---- src/sdl/macosx/Srb2mac.pbproj/project.pbxproj | 4 ++-- src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj | 4 ++-- src/sdl/ogl_sdl.c | 2 +- 16 files changed, 38 insertions(+), 30 deletions(-) rename src/hardware/{hw_gpu.h => hw_gl.h} (93%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 35669ce52..f31a9bd26 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -487,7 +487,7 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_gpu.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_gl.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_portal.h diff --git a/src/Makefile b/src/Makefile index b2cac197e..fcdb34d46 100644 --- a/src/Makefile +++ b/src/Makefile @@ -738,7 +738,7 @@ else ifdef SDL ifdef MINGW $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ - doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_gpu.h screen.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_gl.h screen.h \ command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \ hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h hardware/hw_portal.h\ hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ @@ -747,7 +747,7 @@ $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ else $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ - doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_gpu.h screen.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_gl.h screen.h \ command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \ hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h hardware/hw_portal.h \ hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index 2825b0820..7f418fc77 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -15,7 +15,7 @@ #include "hw_defs.h" #include "hw_data.h" -#include "hw_gpu.h" +#include "hw_gl.h" extern boolean currently_batching; diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index bfb1df1f1..4df24bd16 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -14,9 +14,10 @@ #include "../doomdef.h" #ifdef HWRENDER + #include "hw_main.h" #include "hw_glob.h" -#include "hw_gpu.h" +#include "hw_gl.h" #include "hw_batching.h" #include "../doomstat.h" //gamemode diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index bfb1909e5..e38300309 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -18,9 +18,10 @@ #include "../doomdef.h" #ifdef HWRENDER + #include "hw_main.h" #include "hw_glob.h" -#include "hw_gpu.h" +#include "hw_gl.h" #include "../m_misc.h" //FIL_WriteFile() #include "../r_draw.h" //viewborderlump diff --git a/src/hardware/hw_gpu.h b/src/hardware/hw_gl.h similarity index 93% rename from src/hardware/hw_gpu.h rename to src/hardware/hw_gl.h index 0d63296c6..aacb1b1fb 100644 --- a/src/hardware/hw_gpu.h +++ b/src/hardware/hw_gl.h @@ -1,16 +1,17 @@ -// SONIC ROBO BLAST 2 +// SONIC ROBO BLAST 2 Kart //----------------------------------------------------------------------------- // Copyright (C) 2020 by Jaime "Lactozilla" Passos. +// Copyright (C) 2020 by Sonic Team Junior. // // This program is free software distributed under the // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- -/// \file hw_gpu.h -/// \brief GPU low-level interface API +/// \file hw_gl.h +/// \brief OpenGL low-level interface API -#ifndef __HWR_GPU_H__ -#define __HWR_GPU_H__ +#ifndef __HWR_GL_H__ +#define __HWR_GL_H__ #include "../screen.h" @@ -76,4 +77,4 @@ UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable); void GL_ClearLightTables(void); void GL_SetScreenPalette(RGBA_t *palette); -#endif // __HWR_GPU_H__ +#endif // __HWR_GL_H__ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index cbac939c4..77045a723 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -16,12 +16,11 @@ #include "../doomstat.h" #include "../doomdef.h" -#include "../qs22j.h" - #ifdef HWRENDER + #include "hw_main.h" #include "hw_glob.h" -#include "hw_gpu.h" +#include "hw_gl.h" #include "hw_batching.h" #include "hw_md2.h" #include "hw_clip.h" @@ -57,6 +56,8 @@ #include "../w_wad.h" #include "../z_zone.h" +#include "../qs22j.h" // fast qsort + // ========================================================================== // Globals // ========================================================================== diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 5018496dd..0612b8e65 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -25,7 +25,8 @@ #include "../doomstat.h" #ifdef HWRENDER -#include "hw_gpu.h" + +#include "hw_gl.h" #include "hw_md2.h" #include "../d_main.h" #include "../r_bsp.h" @@ -44,8 +45,8 @@ #include "hw_main.h" #include "../v_video.h" -#ifdef HAVE_PNG +#ifdef HAVE_PNG #ifndef _MSC_VER #ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index 7b5f93b97..f26e71331 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -23,7 +23,7 @@ #include "../z_zone.h" #include "hw_clip.h" -#include "hw_gpu.h" +#include "hw_gl.h" #include "hw_defs.h" #include "hw_main.h" #include "hw_portal.h" diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 2068cbb99..31ee2c066 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -13,7 +13,7 @@ #include "hw_main.h" #include "hw_glob.h" -#include "hw_gpu.h" +#include "hw_gl.h" #include "hw_shaders.h" #include "../z_zone.h" diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index c453e4ebf..dfa754f1e 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -43,8 +43,9 @@ #endif #define _CREATE_DLL_ // necessary for Unix AND Windows + #include "../../doomdef.h" -#include "../hw_gpu.h" +#include "../hw_gl.h" #include "../../z_zone.h" // ========================================================================== diff --git a/src/sdl/Srb2SDL.dsp b/src/sdl/Srb2SDL.dsp index 92821295d..6f799f4fb 100644 --- a/src/sdl/Srb2SDL.dsp +++ b/src/sdl/Srb2SDL.dsp @@ -572,7 +572,7 @@ SOURCE=..\hardware\hw_draw.c # End Source File # Begin Source File -SOURCE=..\hardware\hw_drv.h +SOURCE=..\hardware\hw_gl.h # End Source File # Begin Source File diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index af8faea41..c880eb263 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -74,15 +74,17 @@ #include "../i_video.h" #include "../console.h" #include "../command.h" -#include "sdlmain.h" #include "../i_system.h" #include "../hu_stuff.h" // for chat_on + +#include "sdlmain.h" + #ifdef HWRENDER #include "../hardware/hw_main.h" -#include "../hardware/hw_gpu.h" +#include "../hardware/hw_gl.h" #include "../hardware/r_opengl/r_opengl.h" //for supportFBO -// For dynamic referencing of HW rendering functions -#include "hwsym_sdl.h" + +#include "hwsym_sdl.h" // For dynamic referencing of HW rendering functions #include "ogl_sdl.h" #endif diff --git a/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj index 3d8c7a82e..a4888ec50 100644 --- a/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj @@ -1060,8 +1060,8 @@ 8417773A085A106C000C01D8 = { fileEncoding = 30; isa = PBXFileReference; - name = hw_gpu.h; - path = ../../hardware/hw_gpu.h; + name = hw_gl.h; + path = ../../hardware/hw_gl.h; refType = 2; }; 8417773C085A106C000C01D8 = { diff --git a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj index 8a2f00c9c..9ec22ebcc 100644 --- a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj @@ -180,7 +180,7 @@ 1E44AE630B67CC2B00BAD059 /* hw3sound.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw3sound.c; path = ../../hardware/hw3sound.c; sourceTree = SOURCE_ROOT; }; 1E44AE640B67CC2B00BAD059 /* hw_cache.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_cache.c; path = ../../hardware/hw_cache.c; sourceTree = SOURCE_ROOT; }; 1E44AE650B67CC2B00BAD059 /* hw_dll.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_dll.h; path = ../../hardware/hw_dll.h; sourceTree = SOURCE_ROOT; }; - 1E44AE660B67CC2B00BAD059 /* hw_gpu.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_gpu.h; path = ../../hardware/hw_gpu.h; sourceTree = SOURCE_ROOT; }; + 1E44AE660B67CC2B00BAD059 /* hw_gl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_gl.h; path = ../../hardware/hw_gl.h; sourceTree = SOURCE_ROOT; }; 1E44AE680B67CC2B00BAD059 /* hw_light.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_light.c; path = ../../hardware/hw_light.c; sourceTree = SOURCE_ROOT; }; 1E44AE690B67CC2B00BAD059 /* hw_light.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_light.h; path = ../../hardware/hw_light.h; sourceTree = SOURCE_ROOT; }; 1E44AE6A0B67CC2B00BAD059 /* hw3sound.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw3sound.h; path = ../../hardware/hw3sound.h; sourceTree = SOURCE_ROOT; }; @@ -533,7 +533,7 @@ 1E44AE630B67CC2B00BAD059 /* hw3sound.c */, 1E44AE640B67CC2B00BAD059 /* hw_cache.c */, 1E44AE650B67CC2B00BAD059 /* hw_dll.h */, - 1E44AE660B67CC2B00BAD059 /* hw_gpu.h */, + 1E44AE660B67CC2B00BAD059 /* hw_gl.h */, 1E44AE680B67CC2B00BAD059 /* hw_light.c */, 1E44AE690B67CC2B00BAD059 /* hw_light.h */, 1E44AE6A0B67CC2B00BAD059 /* hw3sound.h */, diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 95b05d583..006ad87fb 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -38,7 +38,7 @@ #ifdef HWRENDER #include "../hardware/r_opengl/r_opengl.h" #include "../hardware/hw_main.h" -#include "../hardware/hw_gpu.h" +#include "../hardware/hw_gl.h" #include "ogl_sdl.h" #include "../i_system.h" #include "hwsym_sdl.h" -- 2.54.0 From 74088c1d2683a6751d91884d1f7d0e4de83d6979 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 15:43:46 +0100 Subject: [PATCH 08/14] use loop instead of memcpy for setpalette idk last time this died with models for some reason kek --- src/hardware/r_opengl/r_opengl.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 37ce52cae..29c6f2ba2 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1297,13 +1297,17 @@ void GL_ReadScreenTexture(int tex, UINT16 *dst_data) // -----------------+ void GL_SetPalette(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)) + INT32 i; + + for (i = 0; i < 256; i++) { - memcpy(&myPaletteData, palette, palsize); - GL_Flush(); + myPaletteData[i].s.red = palette[i].s.red; + myPaletteData[i].s.green = palette[i].s.green; + myPaletteData[i].s.blue = palette[i].s.blue; + myPaletteData[i].s.alpha = palette[i].s.alpha; } + + GL_Flush(); } // -----------------+ -- 2.54.0 From f3d1bf1106a629fb63a6cfc41fc3e9625754e814 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 04:35:43 +0100 Subject: [PATCH 09/14] clean up GL_UpdateTexture use switches and reduce code dupe --- src/hardware/r_opengl/r_opengl.c | 216 +++++++++++++------------------ 1 file changed, 90 insertions(+), 126 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 29c6f2ba2..ffd00fa59 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1578,6 +1578,8 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) const GLvoid *ptex = NULL; RGBA_t *tex = NULL; + GLint texformat = 0; + // Generate a new texture name. if (!num) { @@ -1588,85 +1590,86 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) //GL_DBG_Printf("UpdateTexture %d %x\n", (INT32)num, pImgData); - if ((pTexInfo->format == GL_TEXFMT_P_8) || (pTexInfo->format == GL_TEXFMT_AP_88)) + switch (pTexInfo->format) { - GL_AllocTextureBuffer(pTexInfo); - ptex = tex = textureBuffer; + case GL_TEXFMT_P_8: + case GL_TEXFMT_AP_88: + GL_AllocTextureBuffer(pTexInfo); + ptex = tex = textureBuffer; - for (j = 0; j < h; j++) - { - for (i = 0; i < w; i++) + for (j = 0; j < h; j++) { - if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && - (pTexInfo->flags & TF_CHROMAKEYED)) + for (i = 0; i < w; i++) { - 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; - 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; - } + if ((*pImgData == HWR_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; + 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; + } - pImgData++; + pImgData++; - if (pTexInfo->format == GL_TEXFMT_AP_88) + if (pTexInfo->format == GL_TEXFMT_AP_88) + { + if (!(pTexInfo->flags & TF_CHROMAKEYED)) + tex[w*j+i].s.alpha = *pImgData; + pImgData++; + } + } + } + break; + case GL_TEXFMT_RGBA: + // Directly upload the texture data without any kind of conversion. + ptex = pImgData; + break; + case GL_TEXFMT_ALPHA_INTENSITY_88: + GL_AllocTextureBuffer(pTexInfo); + ptex = tex = textureBuffer; + + for (j = 0; j < h; j++) + { + for (i = 0; i < w; i++) { - if (!(pTexInfo->flags & TF_CHROMAKEYED)) - tex[w*j+i].s.alpha = *pImgData; + tex[w*j+i].s.red = *pImgData; + tex[w*j+i].s.green = *pImgData; + tex[w*j+i].s.blue = *pImgData; + pImgData++; + tex[w*j+i].s.alpha = *pImgData; pImgData++; } } - } - } - else if (pTexInfo->format == GL_TEXFMT_RGBA) - { - // Directly upload the texture data without any kind of conversion. - ptex = pImgData; - } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) - { - GL_AllocTextureBuffer(pTexInfo); - ptex = tex = textureBuffer; + break; + case GL_TEXFMT_ALPHA_8: // Used for fade masks + GL_AllocTextureBuffer(pTexInfo); + ptex = tex = textureBuffer; - for (j = 0; j < h; j++) - { - for (i = 0; i < w; i++) + for (j = 0; j < h; j++) { - tex[w*j+i].s.red = *pImgData; - tex[w*j+i].s.green = *pImgData; - tex[w*j+i].s.blue = *pImgData; - pImgData++; - tex[w*j+i].s.alpha = *pImgData; - pImgData++; + 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; + pImgData++; + } } - } + break; + default: + GL_MSG_Warning("UpdateTexture: bad format %d\n", pTexInfo->format); + break; } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) // Used for fade masks - { - GL_AllocTextureBuffer(pTexInfo); - ptex = tex = textureBuffer; - - for (j = 0; j < h; j++) - { - 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; - pImgData++; - } - } - } - else - GL_MSG_Warning("UpdateTexture: bad format %d\n", pTexInfo->format); pglBindTexture(GL_TEXTURE_2D, num); tex_downloaded = num; @@ -1683,73 +1686,34 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); } - if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) + switch (pTexInfo->format) { - //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - if (MipMap) - { - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, 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 (update) - 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); - } + case GL_TEXFMT_ALPHA_INTENSITY_88: + texformat = GL_LUMINANCE_ALPHA; + break; + case GL_TEXFMT_ALPHA_8: + texformat = GL_ALPHA; + break; + default: + texformat = textureformatGL; + break; } - 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) - { - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, 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 (update) - 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 (MipMap) + { + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, texformat, w, h, 0, 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 higher the detail + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (pTexInfo->flags & TF_TRANSPARENT) ? 0 : 4); // No mipmaps on transparent stuff } else { - if (MipMap) - { - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, 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); - } + if (update) + pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); else - { - if (update) - 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); - } + pglTexImage2D(GL_TEXTURE_2D, 0, texformat, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); } if (pTexInfo->flags & TF_WRAPX) @@ -2256,7 +2220,7 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) break; case HWD_SET_TEXTUREANISOTROPICMODE: - anisotropic_filter = min(Value,maximumAnisotropy); + anisotropic_filter = min(Value, maximumAnisotropy); if (maximumAnisotropy) GL_Flush(); //??? if we want to change filter mode by texture, remove this break; -- 2.54.0 From 37649a0d3cc984142efd5d002d8b763efb6081a8 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 14:23:28 +0100 Subject: [PATCH 10/14] more cleanup GL_UpdateTexture also some optimizations --- src/hardware/r_opengl/r_opengl.c | 90 +++++++++++++++++--------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index ffd00fa59..c42335d4d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1590,6 +1590,8 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) //GL_DBG_Printf("UpdateTexture %d %x\n", (INT32)num, pImgData); + texformat = textureformatGL; + switch (pTexInfo->format) { case GL_TEXFMT_P_8: @@ -1597,35 +1599,36 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; + const int chromakeyed = (pTexInfo->flags & TF_CHROMAKEYED); + for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { - if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && - (pTexInfo->flags & TF_CHROMAKEYED)) + int idx = (w*j+i); + + if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && 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; + tex[idx].s.red = 0; + tex[idx].s.green = 0; + tex[idx].s.blue = 0; + tex[idx].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; + tex[idx].s = myPaletteData[*pImgData].s; } pImgData++; - if (pTexInfo->format == GL_TEXFMT_AP_88) - { - if (!(pTexInfo->flags & TF_CHROMAKEYED)) - tex[w*j+i].s.alpha = *pImgData; - pImgData++; - } + if (pTexInfo->format != GL_TEXFMT_AP_88) + continue; + if (chromakeyed) + continue; + + tex[idx].s.alpha = *pImgData; + pImgData++; } } break; @@ -1636,16 +1639,19 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) case GL_TEXFMT_ALPHA_INTENSITY_88: GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; + texformat = GL_LUMINANCE_ALPHA; for (j = 0; j < h; j++) { 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; + int idx = (w*j+i); + + tex[idx].s.red = *pImgData; + tex[idx].s.green = *pImgData; + tex[idx].s.blue = *pImgData; pImgData++; - tex[w*j+i].s.alpha = *pImgData; + tex[idx].s.alpha = *pImgData; pImgData++; } } @@ -1653,15 +1659,18 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) case GL_TEXFMT_ALPHA_8: // Used for fade masks GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; + texformat = GL_ALPHA; for (j = 0; j < h; j++) { 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; + int idx = (w*j+i); + + tex[idx].s.red = 255; // 255 because the fade mask is modulated with the screen texture, so alpha affects it while the colours don't + tex[idx].s.green = 255; + tex[idx].s.blue = 255; + tex[idx].s.alpha = *pImgData; pImgData++; } } @@ -1674,8 +1683,10 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) pglBindTexture(GL_TEXTURE_2D, num); tex_downloaded = num; + const int transparent = (pTexInfo->flags & TF_TRANSPARENT); + // disable texture filtering on any texture that has holes so there's no dumb borders or blending issues - if (pTexInfo->flags & TF_TRANSPARENT) + if (transparent) { pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -1686,27 +1697,18 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); } - switch (pTexInfo->format) - { - case GL_TEXFMT_ALPHA_INTENSITY_88: - texformat = GL_LUMINANCE_ALPHA; - break; - case GL_TEXFMT_ALPHA_8: - texformat = GL_ALPHA; - break; - default: - texformat = textureformatGL; - break; - } - - if (MipMap) + if (MipMap && !transparent) // No mipmaps on transparent stuff { pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, texformat, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + + if (update) + pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + else + pglTexImage2D(GL_TEXTURE_2D, 0, texformat, w, h, 0, 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 higher the detail - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (pTexInfo->flags & TF_TRANSPARENT) ? 0 : 4); // No mipmaps on transparent stuff + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); } else { @@ -2167,6 +2169,7 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) gl_allowshaders = Value; break; case HWD_SET_TEXTUREFILTERMODE: + switch (Value) { case HWD_SET_TEXTUREFILTER_TRILINEAR: @@ -2198,9 +2201,10 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) MipMap = GL_TRUE; break; default: - mag_filter = GL_LINEAR; min_filter = GL_NEAREST; + mag_filter = GL_LINEAR; } + if (!supportMipMap) { MipMap = GL_FALSE; -- 2.54.0 From 1ab20814e97e977339ecf3736032af415f1c6609 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 14:39:24 +0100 Subject: [PATCH 11/14] simplify GL_SetPalette can just copy the whole struct --- src/hardware/r_opengl/r_opengl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index c42335d4d..d33dfd560 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1301,10 +1301,7 @@ void GL_SetPalette(RGBA_t *palette) for (i = 0; i < 256; i++) { - myPaletteData[i].s.red = palette[i].s.red; - myPaletteData[i].s.green = palette[i].s.green; - myPaletteData[i].s.blue = palette[i].s.blue; - myPaletteData[i].s.alpha = palette[i].s.alpha; + myPaletteData[i].s = palette[i].s; } GL_Flush(); -- 2.54.0 From 8e273a1f19b3b3cbf5a7e1f3eb6f1417f6be9da2 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 21:58:45 +0100 Subject: [PATCH 12/14] GL_UpdateTexture can be static --- src/hardware/hw_gl.h | 1 - src/hardware/r_opengl/r_opengl.c | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_gl.h b/src/hardware/hw_gl.h index aacb1b1fb..c2a88854f 100644 --- a/src/hardware/hw_gl.h +++ b/src/hardware/hw_gl.h @@ -41,7 +41,6 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics void GL_RenderSkyDome(gl_sky_t *sky); void GL_SetTexture(GLMipmap_t *pTexInfo); -void GL_UpdateTexture(GLMipmap_t *pTexInfo); void GL_DeleteTexture(GLMipmap_t *pTexInfo); void GL_Flush(void); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index d33dfd560..061a1430e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1562,7 +1562,7 @@ static void GL_AllocTextureBuffer(GLMipmap_t *pTexInfo) // -----------------+ // UpdateTexture : Updates texture data. // -----------------+ -void GL_UpdateTexture(GLMipmap_t *pTexInfo) +static void GL_UpdateTexture(GLMipmap_t *pTexInfo) { // Upload a texture GLuint num = pTexInfo->downloaded; @@ -2865,9 +2865,10 @@ void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]) pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - for(x = 0; x < SCREENVERTS-1;x ++) + + for (x = 0; x < SCREENVERTS-1;x ++) { - for(y = 0; y < SCREENVERTS-1; y++) + for (y = 0; y < SCREENVERTS-1; y++) { float stCoords[8]; float vertCoords[12]; -- 2.54.0 From 3dec352245b1939b1479578e9fe4e3731446c371 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 22:14:06 +0100 Subject: [PATCH 13/14] smol cleanup GL_SetBlend use early return since i likeit more --- src/hardware/r_opengl/r_opengl.c | 244 ++++++++++++++++--------------- 1 file changed, 126 insertions(+), 118 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 061a1430e..989b4ed1e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1417,139 +1417,148 @@ static void Clamp2D(GLenum pname) // is it faster when pixels are discarded ? void GL_SetBlend(FBITFIELD PolyFlags) { - FBITFIELD 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|PF_NoAlphaTest)) + const FBITFIELD 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|PF_NoAlphaTest))) { - if (Xor&(PF_Blending)) // if blending mode must be changed - { - switch (PolyFlags & PF_Blending) { - case PF_Translucent & PF_Blending: - pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha = level of transparency - pglAlphaFunc(GL_NOTEQUAL, 0.0f); - break; - case PF_Masked & PF_Blending: - // Hurdler: does that mean lighting is only made by alpha src? - // it sounds ok, but not for polygonsmooth - pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); // 0 alpha = holes in texture - pglAlphaFunc(GL_GREATER, 0.5f); - break; - case PF_Additive & PF_Blending: - pglBlendFunc(GL_SRC_ALPHA, GL_ONE); // src * alpha + dest - pglAlphaFunc(GL_NOTEQUAL, 0.0f); - break; - case PF_Environment & PF_Blending: - pglBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - pglAlphaFunc(GL_NOTEQUAL, 0.0f); - break; - case PF_Substractive & PF_Blending: - // good for shadow - // not really but what else ? - pglBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); - pglAlphaFunc(GL_NOTEQUAL, 0.0f); - break; - case PF_Fog & PF_Fog: - // Sryder: Fog - // multiplies input colour by input alpha, and destination colour by input colour, then adds them - pglBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR); - pglAlphaFunc(GL_ALWAYS, 0.0f); // Don't discard zero alpha fragments - break; - default : // must be 0, otherwise it's an error - // No blending - pglBlendFunc(GL_ONE, GL_ZERO); // the same as no blending - pglAlphaFunc(GL_GREATER, 0.5f); - break; - } - } - if (Xor & PF_NoAlphaTest) - { - if (PolyFlags & PF_NoAlphaTest) - pglDisable(GL_ALPHA_TEST); - else - pglEnable(GL_ALPHA_TEST); // discard 0 alpha pixels (holes in texture) - } + CurrentPolyFlags = PolyFlags; + return; + } - if (Xor & PF_Decal) + if (Xor & PF_Blending) // if blending mode must be changed + { + switch (PolyFlags & PF_Blending) { - if (PolyFlags & PF_Decal) - pglEnable(GL_POLYGON_OFFSET_FILL); - else - pglDisable(GL_POLYGON_OFFSET_FILL); - } - if (Xor&PF_NoDepthTest) - { - if (PolyFlags & PF_NoDepthTest) - pglDepthFunc(GL_ALWAYS); //pglDisable(GL_DEPTH_TEST); - else - pglDepthFunc(GL_LEQUAL); //pglEnable(GL_DEPTH_TEST); + case (PF_Translucent & PF_Blending): + pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha = level of transparency + pglAlphaFunc(GL_NOTEQUAL, 0.0f); + break; + case (PF_Masked & PF_Blending): + // Hurdler: does that mean lighting is only made by alpha src? + // it sounds ok, but not for polygonsmooth + pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); // 0 alpha = holes in texture + pglAlphaFunc(GL_GREATER, 0.5f); + break; + case (PF_Additive & PF_Blending): + pglBlendFunc(GL_SRC_ALPHA, GL_ONE); // src * alpha + dest + pglAlphaFunc(GL_NOTEQUAL, 0.0f); + break; + case (PF_Environment & PF_Blending): + pglBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + pglAlphaFunc(GL_NOTEQUAL, 0.0f); + break; + case (PF_Substractive & PF_Blending): + // good for shadow + // not really but what else ? + pglBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); + pglAlphaFunc(GL_NOTEQUAL, 0.0f); + break; + case (PF_Fog & PF_Fog): + // Sryder: Fog + // multiplies input colour by input alpha, and destination colour by input colour, then adds them + pglBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR); + pglAlphaFunc(GL_ALWAYS, 0.0f); // Don't discard zero alpha fragments + break; + default : // must be 0, otherwise it's an error + // No blending + pglBlendFunc(GL_ONE, GL_ZERO); // the same as no blending + pglAlphaFunc(GL_GREATER, 0.5f); + break; } + } - if (Xor&PF_RemoveYWrap) - { - if (PolyFlags & PF_RemoveYWrap) - Clamp2D(GL_TEXTURE_WRAP_T); - } + if (Xor & PF_NoAlphaTest) + { + if (PolyFlags & PF_NoAlphaTest) + pglDisable(GL_ALPHA_TEST); + else + pglEnable(GL_ALPHA_TEST); // discard 0 alpha pixels (holes in texture) + } - if (Xor&PF_ForceWrapX) - { - if (PolyFlags & PF_ForceWrapX) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - } + if (Xor & PF_Decal) + { + if (PolyFlags & PF_Decal) + pglEnable(GL_POLYGON_OFFSET_FILL); + else + pglDisable(GL_POLYGON_OFFSET_FILL); + } + if (Xor & PF_NoDepthTest) + { + if (PolyFlags & PF_NoDepthTest) + pglDepthFunc(GL_ALWAYS); //pglDisable(GL_DEPTH_TEST); + else + pglDepthFunc(GL_LEQUAL); //pglEnable(GL_DEPTH_TEST); + } - if (Xor&PF_ForceWrapY) - { - if (PolyFlags & PF_ForceWrapY) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - } + if (Xor & PF_RemoveYWrap) + { + if (PolyFlags & PF_RemoveYWrap) + Clamp2D(GL_TEXTURE_WRAP_T); + } - if (Xor&PF_Modulated) - { + if (Xor & PF_ForceWrapX) + { + if (PolyFlags & PF_ForceWrapX) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + } + + if (Xor & PF_ForceWrapY) + { + if (PolyFlags & PF_ForceWrapY) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } + + if (Xor & PF_Modulated) + { #if defined (__unix__) || defined (UNIXCOMMON) - if (oglflags & GLF_NOTEXENV) - { - if (!(PolyFlags & PF_Modulated)) - pglColor4ubv(white); - } - else + if (oglflags & GLF_NOTEXENV) + { + if (!(PolyFlags & PF_Modulated)) + pglColor4ubv(white); + } + else #endif - // mix texture colour with Surface->PolyColor - if (PolyFlags & PF_Modulated) - pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - // colour from texture is unchanged before blending - else - pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - } - - if (Xor & PF_Occlude) // depth test but (no) depth write - { - if (PolyFlags&PF_Occlude) - pglDepthMask(1); - else - pglDepthMask(0); - } - ////Hurdler: not used if we don't define POLYSKY - if (Xor & PF_Invisible) - { - if (PolyFlags&PF_Invisible) - pglBlendFunc(GL_ZERO, GL_ONE); // transparent blending - else - { // big hack: (TODO: manage that better) - // we test only for PF_Masked because PF_Invisible is only used - // (for now) with it (yeah, that's crappy, sorry) - if ((PolyFlags&PF_Blending)==PF_Masked) - pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); - } - } - if (PolyFlags & PF_NoTexture) - GL_SetNoTexture(); + // mix texture colour with Surface->PolyColor + if (PolyFlags & PF_Modulated) + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + // colour from texture is unchanged before blending + else + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } + + if (Xor & PF_Occlude) // depth test but (no) depth write + { + if (PolyFlags & PF_Occlude) + pglDepthMask(1); + else + pglDepthMask(0); + } + + ////Hurdler: not used if we don't define POLYSKY + if (Xor & PF_Invisible) + { + if (PolyFlags&PF_Invisible) + pglBlendFunc(GL_ZERO, GL_ONE); // transparent blending + else + { // big hack: (TODO: manage that better) + // we test only for PF_Masked because PF_Invisible is only used + // (for now) with it (yeah, that's crappy, sorry) + if ((PolyFlags & PF_Blending) == PF_Masked) + pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); + } + } + + if (PolyFlags & PF_NoTexture) + GL_SetNoTexture(); + CurrentPolyFlags = PolyFlags; } static void GL_AllocTextureBuffer(GLMipmap_t *pTexInfo) { size_t size = pTexInfo->width * pTexInfo->height; + if (size > textureBufferSize) { textureBuffer = realloc(textureBuffer, size * sizeof(RGBA_t)); @@ -2865,10 +2874,9 @@ void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]) pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - - for (x = 0; x < SCREENVERTS-1;x ++) + for(x = 0; x < SCREENVERTS-1;x ++) { - for (y = 0; y < SCREENVERTS-1; y++) + for(y = 0; y < SCREENVERTS-1; y++) { float stCoords[8]; float vertCoords[12]; -- 2.54.0 From 99e4870a524272f16218e33d6bd69ef90580e9ed Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 12 Dec 2024 02:31:44 +0100 Subject: [PATCH 14/14] check for the flag first --- src/hardware/r_opengl/r_opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 989b4ed1e..077bdbbbe 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1613,7 +1613,7 @@ static void GL_UpdateTexture(GLMipmap_t *pTexInfo) { int idx = (w*j+i); - if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && chromakeyed) + if (chromakeyed && (*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX)) { tex[idx].s.red = 0; tex[idx].s.green = 0; -- 2.54.0