From 200d971d35789c1114a671c13c49ebff8d854b47 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:05:48 +0100 Subject: [PATCH 01/24] Toggle to render to screenFBO fixes downsampling from higher resolutions TODO: make this activate automatically if game detects it runs at higher res than desktop res --- src/hardware/hw_defs.h | 1 + src/hardware/hw_main.c | 13 ++ src/hardware/hw_main.h | 1 + src/hardware/r_opengl/r_opengl.c | 213 +++++++++++++++++++++++++++++-- src/hardware/r_opengl/r_opengl.h | 12 ++ src/i_video.h | 2 + src/sdl/i_video.c | 7 + src/sdl/ogl_sdl.c | 44 ++++++- 8 files changed, 278 insertions(+), 15 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index b7c46b2e1..83bb70fde 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -277,6 +277,7 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { + HWD_SET_FRAMEBUFFER, HWD_SET_SHADERS, HWD_SET_TEXTUREFILTERMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 131775c53..3634d1e9d 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,6 +69,7 @@ static boolean gr_palette_rendering_state = false; // Commands and console variables // ========================================================================== +static void CV_grframebuffer_OnChange(void); static void CV_filtermode_ONChange(void); static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); @@ -96,6 +97,8 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grframebuffer = {"gr_framebuffer", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, CV_grframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_fofzfightfix = {"fofzfightfix", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -161,6 +164,13 @@ consvar_t cv_grhorizonlines = {"gr_horizonlines", "On", CV_SAVE, CV_OnOff, NULL, #define ONLY_IF_GL_LOADED if (vid.glstate != VID_GL_LIBRARY_LOADED) return; +static void CV_grframebuffer_OnChange(void) +{ + ONLY_IF_GL_LOADED + HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); + RefreshSDLSurface(); +} + static void CV_filtermode_ONChange(void) { ONLY_IF_GL_LOADED @@ -5936,6 +5946,7 @@ void HWR_TogglePaletteRendering(void) //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { + CV_RegisterVar(&cv_grframebuffer); CV_RegisterVar(&cv_grfiltermode); CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grsolvetjoin); @@ -5998,6 +6009,8 @@ void HWR_Startup(void) HWR_LoadAllCustomShaders(); HWR_TogglePaletteRendering(); + + HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); if (msaa) { diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 3530c2915..4a9b1d434 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -154,6 +154,7 @@ void HWR_SetShaderState(void); // Console variables extern consvar_t cv_grshaders; +extern consvar_t cv_grframebuffer; extern consvar_t cv_grfofcut; extern consvar_t cv_fofzfightfix; extern consvar_t cv_splitwallfix; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 9fcf90a62..78b34c63f 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -114,6 +114,11 @@ static GLfloat modelMatrix[16]; GLfloat projMatrix[16]; static GLint viewport[4]; +static boolean GLFramebuffer_IsFuncAvailible(void); + + +GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; +GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels @@ -426,12 +431,32 @@ typedef void (APIENTRY * PFNglCopyTexImage2D) (GLenum target, GLint level, GLenu static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; -#endif /* 3.0 functions */ -#ifdef GL_VERSION_3_0 typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target); static PFNglGenerateMipmap pglGenerateMipmap; + +/* 3.0 functions for framebuffers and renderbuffers */ +typedef void (APIENTRY * PFNglGenFramebuffers) (GLsizei n, GLuint *ids); +static PFNglGenFramebuffers pglGenFramebuffers; +typedef void (APIENTRY * PFNglBindFramebuffer) (GLenum target, GLuint framebuffer); +static PFNglBindFramebuffer pglBindFramebuffer; +typedef void (APIENTRY * PFNglDeleteFramebuffers) (GLsizei n, GLuint *ids); +static PFNglDeleteFramebuffers pglDeleteFramebuffers; +typedef void (APIENTRY * PFNglFramebufferTexture2D) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +static PFNglFramebufferTexture2D pglFramebufferTexture2D; +typedef GLenum (APIENTRY * PFNglCheckFramebufferStatus) (GLenum target); +static PFNglCheckFramebufferStatus pglCheckFramebufferStatus; +typedef void (APIENTRY * PFNglGenRenderbuffers) (GLsizei n, GLuint *renderbuffers); +static PFNglGenRenderbuffers pglGenRenderbuffers; +typedef void (APIENTRY * PFNglBindRenderbuffer) (GLenum target, GLuint renderbuffer); +static PFNglBindRenderbuffer pglBindRenderbuffer; +typedef void (APIENTRY * PFNglDeleteRenderbuffers) (GLsizei n, GLuint *renderbuffers); +static PFNglDeleteRenderbuffers pglDeleteRenderbuffers; +typedef void (APIENTRY * PFNglRenderbufferStorage) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +static PFNglRenderbufferStorage pglRenderbufferStorage; +typedef void (APIENTRY * PFNglFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLenum renderbuffer); +static PFNglFramebufferRenderbuffer pglFramebufferRenderbuffer; #endif /* 1.2 functions for 3D textures */ @@ -717,9 +742,28 @@ void SetupGLFunc4(void) pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); -#ifdef GL_VERSION_3_0 pglGenerateMipmap = GetGLFunc("glGenerateMipmap"); -#endif + + if (GLFramebuffer_IsFuncAvailible()) + { + pglGenFramebuffers = GetGLFunc("glGenFramebuffers"); + pglBindFramebuffer = GetGLFunc("glBindFramebuffer"); + pglDeleteFramebuffers = GetGLFunc("glDeleteFramebuffers"); + pglFramebufferTexture2D = GetGLFunc("glFramebufferTexture2D"); + pglCheckFramebufferStatus = GetGLFunc("glCheckFramebufferStatus"); + pglGenRenderbuffers = GetGLFunc("glGenRenderbuffers"); + pglBindRenderbuffer = GetGLFunc("glBindRenderbuffer"); + pglDeleteRenderbuffers = GetGLFunc("glDeleteRenderbuffers"); + pglRenderbufferStorage = GetGLFunc("glRenderbufferStorage"); + pglFramebufferRenderbuffer = GetGLFunc("glFramebufferRenderbuffer"); + } +} + +static boolean GLFramebuffer_IsFuncAvailible(void) +{ + return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && + (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && + (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); } EXPORT boolean HWRAPI(InitShaders) (void) @@ -897,13 +941,6 @@ void SetModelView(GLint w, GLint h) { //GL_DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h); - // The screen textures need to be flushed if the width or height change so that they be remade for the correct size - if (screen_width != w || screen_height != h) - FlushScreenTextures(); - - screen_width = w; - screen_height = h; - pglViewport(0, 0, w, h); pglMatrixMode(GL_PROJECTION); @@ -935,7 +972,7 @@ void SetStates(void) pglEnable(GL_STENCIL_TEST); pglEnable(GL_DEPTH_TEST); // check the depth buffer - pglDepthMask(GL_TRUE); // enable writing to depth buffer + pglDepthMask(GL_TRUE); // enable writing to depth buffer pglClearDepth(1.0f); pglDepthRange(0.0f, 1.0f); pglDepthFunc(GL_LEQUAL); @@ -955,6 +992,151 @@ void SetStates(void) pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) } +void GLFramebuffer_Generate(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + // Generate the framebuffer + if (FramebufferObject == 0) + pglGenFramebuffers(1, &FramebufferObject); + + if (pglCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) + GLFramebuffer_GenerateAttachments(); +} + +void GLFramebuffer_Delete(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + // Unbind the framebuffer + pglBindFramebuffer(GL_FRAMEBUFFER, 0); + + if (FramebufferObject) + pglDeleteFramebuffers(1, &FramebufferObject); + + GLFramebuffer_DeleteAttachments(); + FramebufferObject = 0; +} + +void GLFramebuffer_GenerateAttachments(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + // Bind the framebuffer + pglBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject); + + // Generate the framebuffer texture + if (FramebufferTexture == 0) + { + pglGenTextures(1, &FramebufferTexture); + pglBindTexture(GL_TEXTURE_2D, FramebufferTexture); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen_width, screen_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + pglBindTexture(GL_TEXTURE_2D, 0); + + // Attach the framebuffer texture to the framebuffer + pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, FramebufferTexture, 0); + } + + // Generate the renderbuffer + if (RenderbufferObject == 0) + { + pglGenRenderbuffers(1, &RenderbufferObject); + + pglBindRenderbuffer(GL_RENDERBUFFER, RenderbufferObject); + pglRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, screen_width, screen_height); + pglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, RenderbufferObject); + + // Clear the renderbuffer + ClearBuffer(true, true, true, NULL); + + pglBindRenderbuffer(GL_RENDERBUFFER, 0); + } + + // Unbind the framebuffer + pglBindFramebuffer(GL_FRAMEBUFFER, 0); +} + +void GLFramebuffer_DeleteAttachments(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + // Unbind the framebuffer + pglBindFramebuffer(GL_FRAMEBUFFER, 0); + + if (FramebufferTexture) + pglDeleteTextures(1, &FramebufferTexture); + + if (RenderbufferObject) + pglDeleteRenderbuffers(1, &RenderbufferObject); + + FramebufferTexture = 0; + RenderbufferObject = 0; +} + +void GLFramebuffer_Enable(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + if (FramebufferObject == 0) + GLFramebuffer_Generate(); + else if (FramebufferTexture == 0 || RenderbufferObject == 0) + GLFramebuffer_GenerateAttachments(); + + pglBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject); + pglBindRenderbuffer(GL_RENDERBUFFER, RenderbufferObject); +} + +void GLFramebuffer_Disable(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + pglBindFramebuffer(GL_FRAMEBUFFER, 0); + pglBindRenderbuffer(GL_RENDERBUFFER, 0); +} + +// -----------------+ +// DeleteTexture : Deletes a texture from the GPU and frees its data +// -----------------+ +EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) +{ + FTextureInfo *head = TexCacheHead; + + if (!pTexInfo) + return; + else if (pTexInfo->downloaded) + pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded); + + while (head) + { + if (head->downloaded == pTexInfo->downloaded) + { + if (head->next) + head->next->prev = head->prev; + else // no next -> tail is being deleted -> update TexCacheTail + TexCacheTail = head->prev; + if (head->prev) + head->prev->next = head->next; + else // no prev -> head is being deleted -> update TexCacheHead + TexCacheHead = head->next; + free(head); + break; + } + + head = head->next; + } + + pTexInfo->downloaded = 0; +} + + // -----------------+ // Flush : flush OpenGL textures // : Clear list of downloaded mipmaps @@ -2140,6 +2322,13 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_SHADERS: gl_allowshaders = Value; break; + + case HWD_SET_FRAMEBUFFER: + FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; + + if (!GLFramebuffer_IsFuncAvailible()) + FrameBufferEnabled = GL_FALSE; + break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 34b2d3cf7..d8b2a12fc 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -104,6 +104,18 @@ static PFNglEnableClientState pglEnableClientState; #endif #endif +void GLFramebuffer_Generate(void); +void GLFramebuffer_Delete(void); + +void GLFramebuffer_GenerateAttachments(void); +void GLFramebuffer_DeleteAttachments(void); + +void GLFramebuffer_Enable(void); +void GLFramebuffer_Disable(void); + +extern GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; +extern GLboolean FrameBufferEnabled, RenderToFramebuffer; + // ========================================================================== // GLOBAL // ========================================================================== diff --git a/src/i_video.h b/src/i_video.h index 602522871..2f08e4b1f 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -137,4 +137,6 @@ void I_EndRead(void); UINT32 I_GetRefreshRate(void); +void RefreshSDLSurface(void); + #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a1dd8bef6..4591b6ad6 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -203,6 +203,13 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); +#ifdef HWRENDER +void RefreshSDLSurface(void) +{ + OglSdlSurface(vid.width, vid.height); +} +#endif + static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { static SDL_bool wasfullscreen = SDL_FALSE; diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 00e3896ed..71e7fcdab 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -163,11 +163,35 @@ boolean OglSdlSurface(INT32 w, INT32 h) granisotropicmode_cons_t[1].value = maximumAnisotropy; - SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); + if (cv_vidwait.value) + { + if (SDL_GL_SetSwapInterval(-1) != 0) // try async vsync + SDL_GL_SetSwapInterval(1); // normal vsync + } + else + SDL_GL_SetSwapInterval(0); + + //SDL_GL_SetSwapInterval(cv_vidwait.value ? -1 : 0); + + // The screen textures need to be flushed if the width or height change so that they be remade for the correct size + if (screen_width != w || screen_height != h) + { + FlushScreenTextures(); + GLFramebuffer_DeleteAttachments(); + } + + screen_width = (GLint)w; + screen_height = (GLint)h; SetModelView(w, h); SetStates(); pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); + + RenderToFramebuffer = FrameBufferEnabled; + GLFramebuffer_Disable(); + + if (RenderToFramebuffer) + GLFramebuffer_Enable(); HWR_Startup(); textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; @@ -187,15 +211,29 @@ void OglSdlFinishUpdate(boolean waitvbl) int sdlw, sdlh; if (oldwaitvbl != waitvbl) { - SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); + if (waitvbl) + { + if (SDL_GL_SetSwapInterval(-1) != 0) // try async vsync + SDL_GL_SetSwapInterval(1); // normal vsync + } + else + SDL_GL_SetSwapInterval(0); + //SDL_GL_SetSwapInterval(waitvbl ? -1 : 0); } oldwaitvbl = waitvbl; SDL_GetWindowSize(window, &sdlw, &sdlh); - HWR_MakeScreenFinalTexture(); + + GLFramebuffer_Disable(); + RenderToFramebuffer = FrameBufferEnabled; + HWR_DrawScreenFinalTexture(sdlw, sdlh); + + if (RenderToFramebuffer) + GLFramebuffer_Enable(); + SDL_GL_SwapWindow(window); GClipRect(0, 0, realwidth, realheight, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); -- 2.54.0 From 91a3b288eff25ad58c1fcba29fec93f84d0374e9 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:08:09 +0100 Subject: [PATCH 02/24] conflict moment --- src/hardware/r_opengl/r_opengl.c | 38 ++++---------------------------- src/sdl/ogl_sdl.c | 19 ++-------------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 78b34c63f..d17c29e04 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -432,9 +432,11 @@ static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; +#ifdef GL_VERSION_3_0 /* 3.0 functions */ typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target); static PFNglGenerateMipmap pglGenerateMipmap; +#endif /* 3.0 functions for framebuffers and renderbuffers */ typedef void (APIENTRY * PFNglGenFramebuffers) (GLsizei n, GLuint *ids); @@ -742,7 +744,9 @@ void SetupGLFunc4(void) pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); +#ifdef GL_VERSION_3_0 pglGenerateMipmap = GetGLFunc("glGenerateMipmap"); +#endif if (GLFramebuffer_IsFuncAvailible()) { @@ -1102,40 +1106,6 @@ void GLFramebuffer_Disable(void) pglBindRenderbuffer(GL_RENDERBUFFER, 0); } -// -----------------+ -// DeleteTexture : Deletes a texture from the GPU and frees its data -// -----------------+ -EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) -{ - FTextureInfo *head = TexCacheHead; - - if (!pTexInfo) - return; - else if (pTexInfo->downloaded) - pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded); - - while (head) - { - if (head->downloaded == pTexInfo->downloaded) - { - if (head->next) - head->next->prev = head->prev; - else // no next -> tail is being deleted -> update TexCacheTail - TexCacheTail = head->prev; - if (head->prev) - head->prev->next = head->next; - else // no prev -> head is being deleted -> update TexCacheHead - TexCacheHead = head->next; - free(head); - break; - } - - head = head->next; - } - - pTexInfo->downloaded = 0; -} - // -----------------+ // Flush : flush OpenGL textures diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 71e7fcdab..06fb5df27 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -162,16 +162,8 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetupGLFunc4(); granisotropicmode_cons_t[1].value = maximumAnisotropy; - - if (cv_vidwait.value) - { - if (SDL_GL_SetSwapInterval(-1) != 0) // try async vsync - SDL_GL_SetSwapInterval(1); // normal vsync - } - else - SDL_GL_SetSwapInterval(0); - //SDL_GL_SetSwapInterval(cv_vidwait.value ? -1 : 0); + SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); // The screen textures need to be flushed if the width or height change so that they be remade for the correct size if (screen_width != w || screen_height != h) @@ -211,14 +203,7 @@ void OglSdlFinishUpdate(boolean waitvbl) int sdlw, sdlh; if (oldwaitvbl != waitvbl) { - if (waitvbl) - { - if (SDL_GL_SetSwapInterval(-1) != 0) // try async vsync - SDL_GL_SetSwapInterval(1); // normal vsync - } - else - SDL_GL_SetSwapInterval(0); - //SDL_GL_SetSwapInterval(waitvbl ? -1 : 0); + SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); } oldwaitvbl = waitvbl; -- 2.54.0 From a28f025d401e92505a470e441940f293d8a6cfe1 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:33:29 +0100 Subject: [PATCH 03/24] Stuff from displaycrap branch to detect downsampling automatically --- src/i_video.h | 2 ++ src/sdl/i_video.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++- src/sdl/ogl_sdl.c | 29 ++++++++-------- 3 files changed, 104 insertions(+), 15 deletions(-) diff --git a/src/i_video.h b/src/i_video.h index 2f08e4b1f..098d65cf6 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,4 +139,6 @@ UINT32 I_GetRefreshRate(void); void RefreshSDLSurface(void); +extern boolean downsample; + #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 4591b6ad6..031842874 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -159,6 +159,11 @@ static SDL_bool exposevideo = SDL_FALSE; static SDL_bool usesdl2soft = SDL_FALSE; static SDL_bool borderlesswindow = SDL_FALSE; +static boolean displayinit = false; +static int currentDisplayIndex = -1; +static int previousDisplayIndex = -1; +static int numDisplays = -1; + // SDL2 vars SDL_Window *window; SDL_Renderer *renderer; @@ -166,6 +171,12 @@ static SDL_Texture *texture; static SDL_bool havefocus = SDL_TRUE; static const char *fallback_resolution_name = "Fallback"; +static void ScaleQuality_OnChange(void) +{ + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, cv_scalequality.string); + COM_ImmedExecute(va("vid_mode %d", vid.modenum)); // Hack to make it apply without restarting +} + // windowed video modes from which to choose from. static INT32 windowedModes[MAXWINMODES][2] = { @@ -203,7 +214,8 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); -#ifdef HWRENDER +boolean downsample = false; + void RefreshSDLSurface(void) { OglSdlSurface(vid.width, vid.height); @@ -769,11 +781,23 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } +static void SDL_CheckDisplays(void) +{ + if (!displayinit) + { + numDisplays = SDL_GetNumVideoDisplays(); + displayinit = true; + } + + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); +} + static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; + static SDL_bool windowmoved = SDL_FALSE; switch (evt.event) { @@ -793,6 +817,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; + case SDL_WINDOWEVENT_MOVED: + windowmoved = SDL_TRUE; + break; } if (mousefocus && kbfocus) @@ -832,6 +859,43 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } } + if (windowmoved) + { + SDL_CheckDisplays(); + if (numDisplays > 1) + { + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + if (currentDisplayIndex != previousDisplayIndex) + { + for (int i = 0; i < numDisplays; ++i) + { + if (currentDisplayIndex == i) + { + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) + { + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge + { + downsample = true; + RefreshSDLSurface(); + } + else + downsample = false; + + if (cv_fullscreen.value == 2) //exclusive + SDLSetMode(curmode.w, curmode.h, true); + else if (cv_fullscreen.value == 1) //borderless sdl thing + SDLSetMode(vid.width, vid.height, true); + else //windowed mode + SDLSetMode(vid.width, vid.height, false); + } + break; // found our current display break outta here + } + } + previousDisplayIndex = currentDisplayIndex; + } + } + } } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) @@ -1908,6 +1972,25 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); + for (int i = 0; i < numDisplays; ++i) + { + if (currentDisplayIndex == i) + { + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) + { + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge + { + downsample = true; + RefreshSDLSurface(); + } + else + downsample = false; + } + break; // found our current display break outta here + } + } + SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); Impl_VideoSetupBuffer(); @@ -2318,6 +2401,9 @@ void I_StartupGraphics(void) // Fury: we do window initialization after GL setup to allow // SDL_GL_LoadLibrary to work well on Windows + //check for display things + SDL_CheckDisplays(); + // Create window //Impl_CreateWindow(USE_FULLSCREEN); //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 06fb5df27..719bd48d1 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -42,6 +42,7 @@ #include "../i_system.h" #include "hwsym_sdl.h" #include "../m_argv.h" +#include "../i_video.h" #ifdef DEBUG_TO_FILE #include @@ -149,22 +150,22 @@ boolean OglSdlSurface(INT32 w, INT32 h) "- GPU vendor has dropped OpenGL support on your GPU and OS. (Old GPU?)\n" "- GPU drivers are missing or broken. You may need to update your drivers."); } + + if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) + pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); + else + maximumAnisotropy = 1; + + SetupGLInfo(); + + SetupGLFunc4(); + + granisotropicmode_cons_t[1].value = maximumAnisotropy; } first_init = true; - if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) - pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); - else - maximumAnisotropy = 1; - - SetupGLInfo(); - - SetupGLFunc4(); - - granisotropicmode_cons_t[1].value = maximumAnisotropy; - SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); - + // The screen textures need to be flushed if the width or height change so that they be remade for the correct size if (screen_width != w || screen_height != h) { @@ -182,7 +183,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) RenderToFramebuffer = FrameBufferEnabled; GLFramebuffer_Disable(); - if (RenderToFramebuffer) + if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); HWR_Startup(); @@ -216,7 +217,7 @@ void OglSdlFinishUpdate(boolean waitvbl) HWR_DrawScreenFinalTexture(sdlw, sdlh); - if (RenderToFramebuffer) + if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); SDL_GL_SwapWindow(window); -- 2.54.0 From c7a258f32ff075f1cc86e3ad582b58cce5402b93 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:34:58 +0100 Subject: [PATCH 04/24] clean up --- src/sdl/i_video.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 031842874..f62195ebc 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -171,12 +171,6 @@ static SDL_Texture *texture; static SDL_bool havefocus = SDL_TRUE; static const char *fallback_resolution_name = "Fallback"; -static void ScaleQuality_OnChange(void) -{ - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, cv_scalequality.string); - COM_ImmedExecute(va("vid_mode %d", vid.modenum)); // Hack to make it apply without restarting -} - // windowed video modes from which to choose from. static INT32 windowedModes[MAXWINMODES][2] = { @@ -216,6 +210,7 @@ static void Impl_SetWindowIcon(void); boolean downsample = false; +#ifdef HWRENDER void RefreshSDLSurface(void) { OglSdlSurface(vid.width, vid.height); @@ -881,13 +876,6 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } else downsample = false; - - if (cv_fullscreen.value == 2) //exclusive - SDLSetMode(curmode.w, curmode.h, true); - else if (cv_fullscreen.value == 1) //borderless sdl thing - SDLSetMode(vid.width, vid.height, true); - else //windowed mode - SDLSetMode(vid.width, vid.height, false); } break; // found our current display break outta here } -- 2.54.0 From 23cc0dfc3a37639bd1379759da2652d58f10af78 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:44:32 +0100 Subject: [PATCH 05/24] add some comments cause i WILL forger what this crap even does --- src/sdl/i_video.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f62195ebc..6476e3276 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -778,13 +778,13 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) static void SDL_CheckDisplays(void) { - if (!displayinit) + if (!displayinit) // only do this once, dont think someone ever unplugs or adds a new display during gaming lul { - numDisplays = SDL_GetNumVideoDisplays(); + numDisplays = SDL_GetNumVideoDisplays(); // get all available displays displayinit = true; } - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // this is the current display our game window resides in } static void Impl_HandleWindowEvent(SDL_WindowEvent evt) @@ -859,15 +859,15 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) SDL_CheckDisplays(); if (numDisplays > 1) { - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); - if (currentDisplayIndex != previousDisplayIndex) + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // check the display index + if (currentDisplayIndex != previousDisplayIndex) // did the display change from previous index entry? { - for (int i = 0; i < numDisplays; ++i) + for (int i = 0; i < numDisplays; ++i) // go through all detected displays { - if (currentDisplayIndex == i) + if (currentDisplayIndex == i) // found our current display? { SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) + if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) // get info for the current display { if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { @@ -880,7 +880,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; // found our current display break outta here } } - previousDisplayIndex = currentDisplayIndex; + previousDisplayIndex = currentDisplayIndex; // set current display to index } } } @@ -1960,17 +1960,17 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); - for (int i = 0; i < numDisplays; ++i) + for (int i = 0; i < numDisplays; ++i) // go through all displays again { - if (currentDisplayIndex == i) + if (currentDisplayIndex == i) // find the current display { SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) + if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) // get the info on current display { if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { downsample = true; - RefreshSDLSurface(); + RefreshSDLSurface(); // refresh crap so our fbo and screentextures dont break } else downsample = false; -- 2.54.0 From a779191febc3a967b44d602be45c8c68ce5a267a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:45:59 +0100 Subject: [PATCH 06/24] beter --- src/sdl/i_video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6476e3276..8772f2da2 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1960,7 +1960,7 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); - for (int i = 0; i < numDisplays; ++i) // go through all displays again + for (int i = 0; i < numDisplays; ++i) // go through all displays again cause our vidya mode changed { if (currentDisplayIndex == i) // find the current display { @@ -1975,7 +1975,7 @@ INT32 VID_SetMode(INT32 modeNum) else downsample = false; } - break; // found our current display break outta here + break; // did everything so done lul } } -- 2.54.0 From 40c356395a649816741d452dbf030b05d8f3e2b1 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 07:02:03 +0200 Subject: [PATCH 07/24] simplify this crap --- src/sdl/i_video.c | 72 +++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 8772f2da2..a6605e701 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -159,10 +159,7 @@ static SDL_bool exposevideo = SDL_FALSE; static SDL_bool usesdl2soft = SDL_FALSE; static SDL_bool borderlesswindow = SDL_FALSE; -static boolean displayinit = false; static int currentDisplayIndex = -1; -static int previousDisplayIndex = -1; -static int numDisplays = -1; // SDL2 vars SDL_Window *window; @@ -776,17 +773,6 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } -static void SDL_CheckDisplays(void) -{ - if (!displayinit) // only do this once, dont think someone ever unplugs or adds a new display during gaming lul - { - numDisplays = SDL_GetNumVideoDisplays(); // get all available displays - displayinit = true; - } - - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // this is the current display our game window resides in -} - static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { static SDL_bool firsttimeonmouse = SDL_TRUE; @@ -856,32 +842,23 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (windowmoved) { - SDL_CheckDisplays(); - if (numDisplays > 1) + if (cv_grframebuffer.value) { - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // check the display index - if (currentDisplayIndex != previousDisplayIndex) // did the display change from previous index entry? + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { - for (int i = 0; i < numDisplays; ++i) // go through all detected displays + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { - if (currentDisplayIndex == i) // found our current display? - { - SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) // get info for the current display - { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge - { - downsample = true; - RefreshSDLSurface(); - } - else - downsample = false; - } - break; // found our current display break outta here - } + downsample = true; + RefreshSDLSurface(); } - previousDisplayIndex = currentDisplayIndex; // set current display to index + else + downsample = false; } + else + downsample = false; // couldnt get display info so turn the thing off } } } @@ -1960,23 +1937,21 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); - for (int i = 0; i < numDisplays; ++i) // go through all displays again cause our vidya mode changed + if (cv_grframebuffer.value) { - if (currentDisplayIndex == i) // find the current display + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { - SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) // get the info on current display + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge - { - downsample = true; - RefreshSDLSurface(); // refresh crap so our fbo and screentextures dont break - } - else - downsample = false; + downsample = true; + RefreshSDLSurface(); // refresh crap so our fbo and screentextures dont break } - break; // did everything so done lul + else + downsample = false; } + else + downsample = false; } SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); @@ -2389,9 +2364,6 @@ void I_StartupGraphics(void) // Fury: we do window initialization after GL setup to allow // SDL_GL_LoadLibrary to work well on Windows - //check for display things - SDL_CheckDisplays(); - // Create window //Impl_CreateWindow(USE_FULLSCREEN); //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); -- 2.54.0 From 955f73d9e80892a242c4484c98c2a5208a66f52e Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:24:46 +0200 Subject: [PATCH 08/24] throw stuff into own function, also check on game start --- src/i_video.h | 2 ++ src/sdl/i_video.c | 67 ++++++++++++++++++++++------------------------- src/sdl/ogl_sdl.c | 2 ++ 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/i_video.h b/src/i_video.h index 098d65cf6..0c2bfc4e4 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,6 +139,8 @@ UINT32 I_GetRefreshRate(void); void RefreshSDLSurface(void); + +void I_DownSample(void); extern boolean downsample; #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a6605e701..a175a2534 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -159,8 +159,6 @@ static SDL_bool exposevideo = SDL_FALSE; static SDL_bool usesdl2soft = SDL_FALSE; static SDL_bool borderlesswindow = SDL_FALSE; -static int currentDisplayIndex = -1; - // SDL2 vars SDL_Window *window; SDL_Renderer *renderer; @@ -773,6 +771,35 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } +void I_DownSample(void) +{ + if (!cv_grframebuffer.value) + { + downsample = false; + return; + } + + int currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) + { + CONS_Printf(" Width: %d\n", curmode.w); + CONS_Printf(" Height: %d\n", curmode.h); + CONS_Printf(" Refresh Rate: %d Hz\n", curmode.refresh_rate); + CONS_Printf(" Display Index: %d\n", currentDisplayIndex); + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge + { + downsample = true; + RefreshSDLSurface(); + } + else + downsample = false; + } + else + downsample = false; // couldnt get display info so turn the thing off +} + static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { static SDL_bool firsttimeonmouse = SDL_TRUE; @@ -842,24 +869,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (windowmoved) { - if (cv_grframebuffer.value) - { - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); - - SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) - { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge - { - downsample = true; - RefreshSDLSurface(); - } - else - downsample = false; - } - else - downsample = false; // couldnt get display info so turn the thing off - } + I_DownSample(); } } @@ -1937,22 +1947,7 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); - if (cv_grframebuffer.value) - { - SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) - { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge - { - downsample = true; - RefreshSDLSurface(); // refresh crap so our fbo and screentextures dont break - } - else - downsample = false; - } - else - downsample = false; - } + I_DownSample(); SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); Impl_VideoSetupBuffer(); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 719bd48d1..ff37435c8 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -161,6 +161,8 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetupGLFunc4(); granisotropicmode_cons_t[1].value = maximumAnisotropy; + + I_DownSample(); } first_init = true; -- 2.54.0 From 64f10c36fa40ce98164eb419ee04555f118266c9 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:29:08 +0200 Subject: [PATCH 09/24] should throw that into onchange oops --- src/sdl/i_video.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a175a2534..5772de21e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -208,6 +208,7 @@ boolean downsample = false; #ifdef HWRENDER void RefreshSDLSurface(void) { + I_DownSample(); OglSdlSurface(vid.width, vid.height); } #endif -- 2.54.0 From 94340e66342949d80370d71979839bb2c5e17726 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:32:06 +0200 Subject: [PATCH 10/24] forgor to remove those Zzz... --- src/sdl/i_video.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 5772de21e..8a0ca0e51 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -785,10 +785,6 @@ void I_DownSample(void) SDL_DisplayMode curmode; if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { - CONS_Printf(" Width: %d\n", curmode.w); - CONS_Printf(" Height: %d\n", curmode.h); - CONS_Printf(" Refresh Rate: %d Hz\n", curmode.refresh_rate); - CONS_Printf(" Display Index: %d\n", currentDisplayIndex); if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { downsample = true; -- 2.54.0 From 1391e556d6e3c0e34f512d75744780812968542e Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:40:35 +0200 Subject: [PATCH 11/24] that wasnt the onchange im sleepy --- src/hardware/hw_main.c | 1 + src/sdl/i_video.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3634d1e9d..b9b9ba6be 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -168,6 +168,7 @@ static void CV_grframebuffer_OnChange(void) { ONLY_IF_GL_LOADED HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); + I_DownSample(); RefreshSDLSurface(); } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 8a0ca0e51..62073fe78 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -208,7 +208,6 @@ boolean downsample = false; #ifdef HWRENDER void RefreshSDLSurface(void) { - I_DownSample(); OglSdlSurface(vid.width, vid.height); } #endif @@ -781,8 +780,8 @@ void I_DownSample(void) } int currentDisplayIndex = SDL_GetWindowDisplayIndex(window); - SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge -- 2.54.0 From 1df6c4d4da7e2f2a70d2078d1329a44646bc455c Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:47:37 +0200 Subject: [PATCH 12/24] move this to first init too --- src/sdl/ogl_sdl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index a65a708ee..1d30da827 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -150,7 +150,12 @@ boolean OglSdlSurface(INT32 w, INT32 h) "- GPU vendor has dropped OpenGL support on your GPU and OS. (Old GPU?)\n" "- GPU drivers are missing or broken. You may need to update your drivers."); } - + + if (majorGL == 1 && minorGL <= 3) // GL_GENERATE_MIPMAP is unavailible for OGL 1.3 and below + supportMipMap = false; + else + supportMipMap = true; + if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); else @@ -175,11 +180,6 @@ boolean OglSdlSurface(INT32 w, INT32 h) GLFramebuffer_DeleteAttachments(); } - if (majorGL == 1 && minorGL <= 3) // GL_GENERATE_MIPMAP is unavailible for OGL 1.3 and below - supportMipMap = false; - else - supportMipMap = true; - screen_width = (GLint)w; screen_height = (GLint)h; -- 2.54.0 From 6a3987c8f786862fdb5569bd405806c29c8789c5 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:57:55 +0200 Subject: [PATCH 13/24] fix ifdefs --- src/hardware/hw_defs.h | 2 ++ src/hardware/hw_main.c | 28 +++++++++++++++++++--------- src/hardware/hw_main.h | 2 ++ src/hardware/r_opengl/r_opengl.c | 15 ++++++++++----- src/hardware/r_opengl/r_opengl.h | 2 ++ src/i_video.h | 4 ++++ src/sdl/i_video.c | 25 +++++++++++++++++++++++-- src/sdl/ogl_sdl.c | 18 ++++++++++++++---- 8 files changed, 76 insertions(+), 20 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 85b6b58a2..e57bbb0af 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -287,7 +287,9 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { +#ifdef GL_VERSION_3_0 HWD_SET_FRAMEBUFFER, +#endif HWD_SET_SHADERS, HWD_SET_TEXTUREFILTERMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ebd8c417d..4acdaf61c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,7 +69,9 @@ static boolean gr_palette_rendering_state = false; // Commands and console variables // ========================================================================== +#ifdef GL_VERSION_3_0 static void CV_grframebuffer_OnChange(void); +#endif static void CV_filtermode_ONChange(void); static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); @@ -97,7 +99,9 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +#ifdef GL_VERSION_3_0 consvar_t cv_grframebuffer = {"gr_framebuffer", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, CV_grframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#endif consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -165,14 +169,6 @@ consvar_t cv_grhorizonlines = {"gr_horizonlines", "On", CV_SAVE, CV_OnOff, NULL, #define ONLY_IF_GL_LOADED if (vid.glstate != VID_GL_LIBRARY_LOADED) return; -static void CV_grframebuffer_OnChange(void) -{ - ONLY_IF_GL_LOADED - HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); - I_DownSample(); - RefreshSDLSurface(); -} - static void CV_filtermode_ONChange(void) { ONLY_IF_GL_LOADED @@ -219,6 +215,16 @@ static void CV_grpalettedepth_OnChange(void) HWR_SetPalette(pLocalPalette); } +#ifdef GL_VERSION_3_0 +static void CV_grframebuffer_OnChange(void) +{ + ONLY_IF_GL_LOADED + HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); + I_DownSample(); + RefreshSDLSurface(); +} +#endif + // // Sets the shader state. // @@ -5947,7 +5953,9 @@ void HWR_TogglePaletteRendering(void) //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { +#ifdef GL_VERSION_3_0 CV_RegisterVar(&cv_grframebuffer); +#endif CV_RegisterVar(&cv_grfiltermode); CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grsolvetjoin); @@ -6010,8 +6018,10 @@ void HWR_Startup(void) HWR_LoadAllCustomShaders(); HWR_TogglePaletteRendering(); - + +#ifdef GL_VERSION_3_0 HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); +#endif if (msaa) { diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 8cc80a34e..0c1b6a958 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -152,7 +152,9 @@ void HWR_SetShaderState(void); // Console variables extern consvar_t cv_grshaders; +#ifdef GL_VERSION_3_0 extern consvar_t cv_grframebuffer; +#endif extern consvar_t cv_grfofcut; extern consvar_t cv_fofzfightfix; extern consvar_t cv_splitwallfix; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 8811be798..872d50c4e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -119,11 +119,12 @@ static GLfloat modelMatrix[16]; GLfloat projMatrix[16]; static GLint viewport[4]; +#ifdef GL_VERSION_3_0 static boolean GLFramebuffer_IsFuncAvailible(void); - GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; +#endif // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels @@ -457,6 +458,7 @@ static PFNglRenderbufferStorage pglRenderbufferStorage; typedef void (APIENTRY * PFNglFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLenum renderbuffer); static PFNglFramebufferRenderbuffer pglFramebufferRenderbuffer; #endif +#endif //!STATIC_OPENGL /* 1.2 functions for 3D textures */ typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); @@ -740,6 +742,7 @@ void SetupGLFunc4(void) pglUniform2fv = GetGLFunc("glUniform2fv"); pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); + #ifdef GL_VERSION_3_0 if (GLFramebuffer_IsFuncAvailible()) { @@ -757,12 +760,14 @@ void SetupGLFunc4(void) #endif } +#ifdef GL_VERSION_3_0 static boolean GLFramebuffer_IsFuncAvailible(void) { return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); } +#endif EXPORT boolean HWRAPI(InitShaders) (void) { @@ -1023,7 +1028,7 @@ EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) pTexInfo->downloaded = 0; } - +#ifdef GL_VERSION_3_0 void GLFramebuffer_Generate(void) { if (!GLFramebuffer_IsFuncAvailible()) @@ -1133,7 +1138,7 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); } - +#endif // -----------------+ // Flush : flush OpenGL textures @@ -2310,14 +2315,14 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_SHADERS: gl_allowshaders = Value; break; - +#ifdef GL_VERSION_3_0 case HWD_SET_FRAMEBUFFER: FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; if (!GLFramebuffer_IsFuncAvailible()) FrameBufferEnabled = GL_FALSE; break; - +#endif case HWD_SET_TEXTUREFILTERMODE: switch (Value) { diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index c481e7abd..303f95301 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -104,6 +104,7 @@ static PFNglEnableClientState pglEnableClientState; #endif #endif +#ifdef GL_VERSION_3_0 void GLFramebuffer_Generate(void); void GLFramebuffer_Delete(void); @@ -115,6 +116,7 @@ void GLFramebuffer_Disable(void); extern GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; extern GLboolean FrameBufferEnabled, RenderToFramebuffer; +#endif // ========================================================================== // GLOBAL diff --git a/src/i_video.h b/src/i_video.h index e81922bc8..8f9eaae38 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,8 +139,12 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 void RefreshSDLSurface(void); void I_DownSample(void); extern boolean downsample; +#endif +#endif #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 774e75f23..f58cfcac7 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -215,14 +215,15 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); -boolean downsample = false; - #ifdef HWRENDER +#ifdef GL_VERSION_3_0 +boolean downsample = false; void RefreshSDLSurface(void) { OglSdlSurface(vid.width, vid.height); } #endif +#endif static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { @@ -745,6 +746,8 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 void I_DownSample(void) { if (!cv_grframebuffer.value) @@ -769,13 +772,19 @@ void I_DownSample(void) else downsample = false; // couldnt get display info so turn the thing off } +#endif +#endif static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 static SDL_bool windowmoved = SDL_FALSE; +#endif +#endif switch (evt.event) { @@ -795,9 +804,13 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 case SDL_WINDOWEVENT_MOVED: windowmoved = SDL_TRUE; break; +#endif +#endif } if (mousefocus && kbfocus) @@ -837,10 +850,14 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } } +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 if (windowmoved) { I_DownSample(); } +#endif +#endif } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) @@ -1919,7 +1936,11 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 I_DownSample(); +#endif +#endif SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); Impl_VideoSetupBuffer(); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 1d30da827..45ae7d135 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -166,8 +166,10 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetupGLFunc4(); granisotropicmode_cons_t[1].value = maximumAnisotropy; - + +#ifdef GL_VERSION_3_0 I_DownSample(); +#endif } first_init = true; @@ -177,7 +179,9 @@ boolean OglSdlSurface(INT32 w, INT32 h) if (screen_width != w || screen_height != h) { FlushScreenTextures(); +#ifdef GL_VERSION_3_0 GLFramebuffer_DeleteAttachments(); +#endif } screen_width = (GLint)w; @@ -186,12 +190,14 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetModelView(w, h); SetStates(); pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); - + +#ifdef GL_VERSION_3_0 RenderToFramebuffer = FrameBufferEnabled; GLFramebuffer_Disable(); if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); +#endif HWR_Startup(); textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; @@ -218,14 +224,18 @@ void OglSdlFinishUpdate(boolean waitvbl) SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); - + +#ifdef GL_VERSION_3_0 GLFramebuffer_Disable(); RenderToFramebuffer = FrameBufferEnabled; +#endif HWR_DrawScreenFinalTexture(sdlw, sdlh); - + +#ifdef GL_VERSION_3_0 if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); +#endif SDL_GL_SwapWindow(window); -- 2.54.0 From 4a1523da573bb1fb8daca0051c79f87c8a206904 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 18:15:29 +0200 Subject: [PATCH 14/24] Zzz... --- src/i_video.h | 2 -- src/sdl/i_video.c | 12 ------------ 2 files changed, 14 deletions(-) diff --git a/src/i_video.h b/src/i_video.h index 8f9eaae38..76a06be91 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -140,11 +140,9 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); #ifdef HWRENDER -#ifdef GL_VERSION_3_0 void RefreshSDLSurface(void); void I_DownSample(void); extern boolean downsample; #endif -#endif #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f58cfcac7..c415a063a 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -216,14 +216,12 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); static void Impl_SetWindowIcon(void); #ifdef HWRENDER -#ifdef GL_VERSION_3_0 boolean downsample = false; void RefreshSDLSurface(void) { OglSdlSurface(vid.width, vid.height); } #endif -#endif static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { @@ -747,7 +745,6 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) } #ifdef HWRENDER -#ifdef GL_VERSION_3_0 void I_DownSample(void) { if (!cv_grframebuffer.value) @@ -773,7 +770,6 @@ void I_DownSample(void) downsample = false; // couldnt get display info so turn the thing off } #endif -#endif static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { @@ -781,9 +777,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; #ifdef HWRENDER -#ifdef GL_VERSION_3_0 static SDL_bool windowmoved = SDL_FALSE; -#endif #endif switch (evt.event) @@ -805,11 +799,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) case SDL_WINDOWEVENT_MAXIMIZED: break; #ifdef HWRENDER -#ifdef GL_VERSION_3_0 case SDL_WINDOWEVENT_MOVED: windowmoved = SDL_TRUE; break; -#endif #endif } @@ -851,13 +843,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } #ifdef HWRENDER -#ifdef GL_VERSION_3_0 if (windowmoved) { I_DownSample(); } #endif -#endif } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) @@ -1937,9 +1927,7 @@ INT32 VID_SetMode(INT32 modeNum) //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); #ifdef HWRENDER -#ifdef GL_VERSION_3_0 I_DownSample(); -#endif #endif SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); -- 2.54.0 From 9e104a8632ecdafbe687a0734b7dce91867d4e01 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 18:18:47 +0200 Subject: [PATCH 15/24] ok dont use this at all then --- src/hardware/hw_defs.h | 2 -- src/hardware/hw_main.c | 12 +----------- src/hardware/hw_main.h | 2 -- src/hardware/r_opengl/r_opengl.c | 12 ------------ src/sdl/ogl_sdl.c | 10 ---------- 5 files changed, 1 insertion(+), 37 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index e57bbb0af..85b6b58a2 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -287,9 +287,7 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { -#ifdef GL_VERSION_3_0 HWD_SET_FRAMEBUFFER, -#endif HWD_SET_SHADERS, HWD_SET_TEXTUREFILTERMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 4acdaf61c..b1a960870 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,9 +69,7 @@ static boolean gr_palette_rendering_state = false; // Commands and console variables // ========================================================================== -#ifdef GL_VERSION_3_0 static void CV_grframebuffer_OnChange(void); -#endif static void CV_filtermode_ONChange(void); static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); @@ -99,9 +97,7 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -#ifdef GL_VERSION_3_0 consvar_t cv_grframebuffer = {"gr_framebuffer", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, CV_grframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL}; -#endif consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -215,7 +211,6 @@ static void CV_grpalettedepth_OnChange(void) HWR_SetPalette(pLocalPalette); } -#ifdef GL_VERSION_3_0 static void CV_grframebuffer_OnChange(void) { ONLY_IF_GL_LOADED @@ -223,7 +218,6 @@ static void CV_grframebuffer_OnChange(void) I_DownSample(); RefreshSDLSurface(); } -#endif // // Sets the shader state. @@ -5953,9 +5947,7 @@ void HWR_TogglePaletteRendering(void) //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { -#ifdef GL_VERSION_3_0 CV_RegisterVar(&cv_grframebuffer); -#endif CV_RegisterVar(&cv_grfiltermode); CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grsolvetjoin); @@ -6018,10 +6010,8 @@ void HWR_Startup(void) HWR_LoadAllCustomShaders(); HWR_TogglePaletteRendering(); - -#ifdef GL_VERSION_3_0 + HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); -#endif if (msaa) { diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 0c1b6a958..8cc80a34e 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -152,9 +152,7 @@ void HWR_SetShaderState(void); // Console variables extern consvar_t cv_grshaders; -#ifdef GL_VERSION_3_0 extern consvar_t cv_grframebuffer; -#endif extern consvar_t cv_grfofcut; extern consvar_t cv_fofzfightfix; extern consvar_t cv_splitwallfix; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 872d50c4e..85ca35641 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -119,12 +119,10 @@ static GLfloat modelMatrix[16]; GLfloat projMatrix[16]; static GLint viewport[4]; -#ifdef GL_VERSION_3_0 static boolean GLFramebuffer_IsFuncAvailible(void); GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; -#endif // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels @@ -435,7 +433,6 @@ static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; -#ifdef GL_VERSION_3_0 /* 3.0 functions for framebuffers and renderbuffers */ typedef void (APIENTRY * PFNglGenFramebuffers) (GLsizei n, GLuint *ids); static PFNglGenFramebuffers pglGenFramebuffers; @@ -457,7 +454,6 @@ typedef void (APIENTRY * PFNglRenderbufferStorage) (GLenum target, GLenum intern static PFNglRenderbufferStorage pglRenderbufferStorage; typedef void (APIENTRY * PFNglFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLenum renderbuffer); static PFNglFramebufferRenderbuffer pglFramebufferRenderbuffer; -#endif #endif //!STATIC_OPENGL /* 1.2 functions for 3D textures */ @@ -743,7 +739,6 @@ void SetupGLFunc4(void) pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); -#ifdef GL_VERSION_3_0 if (GLFramebuffer_IsFuncAvailible()) { pglGenFramebuffers = GetGLFunc("glGenFramebuffers"); @@ -757,17 +752,14 @@ void SetupGLFunc4(void) pglRenderbufferStorage = GetGLFunc("glRenderbufferStorage"); pglFramebufferRenderbuffer = GetGLFunc("glFramebufferRenderbuffer"); } -#endif } -#ifdef GL_VERSION_3_0 static boolean GLFramebuffer_IsFuncAvailible(void) { return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); } -#endif EXPORT boolean HWRAPI(InitShaders) (void) { @@ -1028,7 +1020,6 @@ EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) pTexInfo->downloaded = 0; } -#ifdef GL_VERSION_3_0 void GLFramebuffer_Generate(void) { if (!GLFramebuffer_IsFuncAvailible()) @@ -1138,7 +1129,6 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); } -#endif // -----------------+ // Flush : flush OpenGL textures @@ -2315,14 +2305,12 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_SHADERS: gl_allowshaders = Value; break; -#ifdef GL_VERSION_3_0 case HWD_SET_FRAMEBUFFER: FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; if (!GLFramebuffer_IsFuncAvailible()) FrameBufferEnabled = GL_FALSE; break; -#endif case HWD_SET_TEXTUREFILTERMODE: switch (Value) { diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 45ae7d135..dc8b479e7 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -167,9 +167,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) granisotropicmode_cons_t[1].value = maximumAnisotropy; -#ifdef GL_VERSION_3_0 I_DownSample(); -#endif } first_init = true; @@ -179,9 +177,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) if (screen_width != w || screen_height != h) { FlushScreenTextures(); -#ifdef GL_VERSION_3_0 GLFramebuffer_DeleteAttachments(); -#endif } screen_width = (GLint)w; @@ -191,13 +187,11 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetStates(); pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); -#ifdef GL_VERSION_3_0 RenderToFramebuffer = FrameBufferEnabled; GLFramebuffer_Disable(); if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); -#endif HWR_Startup(); textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; @@ -225,17 +219,13 @@ void OglSdlFinishUpdate(boolean waitvbl) SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); -#ifdef GL_VERSION_3_0 GLFramebuffer_Disable(); RenderToFramebuffer = FrameBufferEnabled; -#endif HWR_DrawScreenFinalTexture(sdlw, sdlh); -#ifdef GL_VERSION_3_0 if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); -#endif SDL_GL_SwapWindow(window); -- 2.54.0 From c92ef4d757ef22bb1c9f1f497a13b90292da56ba Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 12 Apr 2024 20:41:10 +0200 Subject: [PATCH 16/24] fix software crash Zzz... --- src/sdl/i_video.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c415a063a..4597871b8 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -219,7 +219,8 @@ static void Impl_SetWindowIcon(void); boolean downsample = false; void RefreshSDLSurface(void) { - OglSdlSurface(vid.width, vid.height); + if (rendermode == render_opengl) + OglSdlSurface(vid.width, vid.height); } #endif @@ -747,7 +748,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) #ifdef HWRENDER void I_DownSample(void) { - if (!cv_grframebuffer.value) + if (!cv_grframebuffer.value || !rendermode == render_opengl) { downsample = false; return; @@ -843,7 +844,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } #ifdef HWRENDER - if (windowmoved) + if (windowmoved && rendermode == render_opengl) { I_DownSample(); } @@ -1927,7 +1928,8 @@ INT32 VID_SetMode(INT32 modeNum) //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); #ifdef HWRENDER - I_DownSample(); + if (rendermode == render_opengl) + I_DownSample(); #endif SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); -- 2.54.0 From dacfe376e124823defe2031e7f317f9ec8de11f8 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 12 Apr 2024 21:55:45 +0200 Subject: [PATCH 17/24] smth smth paranthesis --- src/sdl/i_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 4597871b8..ef6f743d1 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -748,7 +748,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) #ifdef HWRENDER void I_DownSample(void) { - if (!cv_grframebuffer.value || !rendermode == render_opengl) + if (!cv_grframebuffer.value || !(rendermode == render_opengl)) { downsample = false; return; -- 2.54.0 From 978cc57889a7799368c6f660686d74a04007f274 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 22:57:25 +0200 Subject: [PATCH 18/24] Add NOSCREENFBO compiler flag to be able to build without fbo support --- src/CMakeLists.txt | 6 ++++++ src/Makefile | 8 ++++++++ src/hardware/hw_defs.h | 2 ++ src/hardware/hw_main.c | 12 +++++++++++- src/hardware/hw_main.h | 2 ++ src/hardware/r_opengl/r_opengl.c | 13 +++++++++++++ src/hardware/r_opengl/r_opengl.h | 2 +- src/sdl/i_video.c | 12 ++++++------ src/sdl/ogl_sdl.c | 11 ++++++++++- 9 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca94f1b95..74833b216 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -216,6 +216,8 @@ set(SRB2_CONFIG_HWRENDER ON CACHE BOOL "Enable hardware rendering through OpenGL.") set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL "Use statically linked OpenGL. NOT RECOMMENDED.") +set(SRB2_CONFIG_USE_FBO_OGL ON CACHE BOOL + "Enable OpenGL FBO Downsampling support.") ### use internal libraries? if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only @@ -510,6 +512,10 @@ if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) endif() endif() +if(${SRB2_CONFIG_USE_FBO_OGL}) + set(SRB2_USE_FBO_OGL ON) + add_definitions(-DUSE_FBO_OGL) +endif() # Targets diff --git a/src/Makefile b/src/Makefile index bc4eb6f3d..72a083b88 100644 --- a/src/Makefile +++ b/src/Makefile @@ -199,6 +199,10 @@ ifndef NOOPENMPT HAVE_OPENMPT=1 endif +ifndef NOSCREENFBO +USE_FBO_OGL=1 +endif + ifdef MINGW include win32/Makefile.cfg endif #ifdef MINGW @@ -372,6 +376,10 @@ ifdef STATIC LIBS:=-static $(LIBS) endif +ifdef USE_FBO_OGL +OPTS+=-DUSE_FBO_OGL +endif + ifdef HAVE_MINIUPNPC ifdef NONET HAVE_MINIUPNPC='' diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 85b6b58a2..b55c10bb9 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -287,7 +287,9 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { +#ifdef USE_FBO_OGL HWD_SET_FRAMEBUFFER, +#endif HWD_SET_SHADERS, HWD_SET_TEXTUREFILTERMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 0e4b22499..b52612582 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,7 +69,9 @@ static boolean gr_palette_rendering_state = false; // Commands and console variables // ========================================================================== +#ifdef USE_FBO_OGL static void CV_grframebuffer_OnChange(void); +#endif static void CV_filtermode_ONChange(void); static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); @@ -97,7 +99,9 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +#ifdef USE_FBO_OGL consvar_t cv_grframebuffer = {"gr_framebuffer", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, CV_grframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#endif consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -213,6 +217,7 @@ static void CV_grpalettedepth_OnChange(void) HWR_SetPalette(pLocalPalette); } +#ifdef USE_FBO_OGL static void CV_grframebuffer_OnChange(void) { ONLY_IF_GL_LOADED @@ -220,6 +225,7 @@ static void CV_grframebuffer_OnChange(void) I_DownSample(); RefreshSDLSurface(); } +#endif // // Sets the shader state. @@ -5976,7 +5982,9 @@ void HWR_TogglePaletteRendering(void) //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { +#ifdef USE_FBO_OGL CV_RegisterVar(&cv_grframebuffer); +#endif CV_RegisterVar(&cv_grfiltermode); CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grsolvetjoin); @@ -6039,8 +6047,10 @@ void HWR_Startup(void) HWR_LoadAllCustomShaders(); HWR_TogglePaletteRendering(); - + +#ifdef USE_FBO_OGL HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); +#endif if (msaa) { diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 8cc80a34e..1c51e2981 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -152,7 +152,9 @@ void HWR_SetShaderState(void); // Console variables extern consvar_t cv_grshaders; +#ifdef USE_FBO_OGL extern consvar_t cv_grframebuffer; +#endif extern consvar_t cv_grfofcut; extern consvar_t cv_fofzfightfix; extern consvar_t cv_splitwallfix; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 85ca35641..9a0eac7b5 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -119,10 +119,12 @@ static GLfloat modelMatrix[16]; GLfloat projMatrix[16]; static GLint viewport[4]; +#ifdef USE_FBO_OGL static boolean GLFramebuffer_IsFuncAvailible(void); GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; +#endif // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels @@ -433,6 +435,7 @@ static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; +#ifdef USE_FBO_OGL /* 3.0 functions for framebuffers and renderbuffers */ typedef void (APIENTRY * PFNglGenFramebuffers) (GLsizei n, GLuint *ids); static PFNglGenFramebuffers pglGenFramebuffers; @@ -454,6 +457,8 @@ typedef void (APIENTRY * PFNglRenderbufferStorage) (GLenum target, GLenum intern static PFNglRenderbufferStorage pglRenderbufferStorage; typedef void (APIENTRY * PFNglFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLenum renderbuffer); static PFNglFramebufferRenderbuffer pglFramebufferRenderbuffer; +#endif // USE_FBO_OGL + #endif //!STATIC_OPENGL /* 1.2 functions for 3D textures */ @@ -739,6 +744,7 @@ void SetupGLFunc4(void) pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); +#ifdef USE_FBO_OGL if (GLFramebuffer_IsFuncAvailible()) { pglGenFramebuffers = GetGLFunc("glGenFramebuffers"); @@ -752,14 +758,17 @@ void SetupGLFunc4(void) pglRenderbufferStorage = GetGLFunc("glRenderbufferStorage"); pglFramebufferRenderbuffer = GetGLFunc("glFramebufferRenderbuffer"); } +#endif } +#ifdef USE_FBO_OGL static boolean GLFramebuffer_IsFuncAvailible(void) { return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); } +#endif EXPORT boolean HWRAPI(InitShaders) (void) { @@ -1020,6 +1029,7 @@ EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) pTexInfo->downloaded = 0; } +#ifdef USE_FBO_OGL void GLFramebuffer_Generate(void) { if (!GLFramebuffer_IsFuncAvailible()) @@ -1129,6 +1139,7 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); } +#endif // -----------------+ // Flush : flush OpenGL textures @@ -2305,12 +2316,14 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_SHADERS: gl_allowshaders = Value; break; +#ifdef USE_FBO_OGL case HWD_SET_FRAMEBUFFER: FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; if (!GLFramebuffer_IsFuncAvailible()) FrameBufferEnabled = GL_FALSE; break; +#endif case HWD_SET_TEXTUREFILTERMODE: switch (Value) { diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 303f95301..a4d8819e3 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -104,7 +104,7 @@ static PFNglEnableClientState pglEnableClientState; #endif #endif -#ifdef GL_VERSION_3_0 +#ifdef USE_FBO_OGL void GLFramebuffer_Generate(void); void GLFramebuffer_Delete(void); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index ef6f743d1..b898a8e48 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -215,7 +215,7 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); -#ifdef HWRENDER +#ifdef USE_FBO_OGL boolean downsample = false; void RefreshSDLSurface(void) { @@ -745,7 +745,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } -#ifdef HWRENDER +#ifdef USE_FBO_OGL void I_DownSample(void) { if (!cv_grframebuffer.value || !(rendermode == render_opengl)) @@ -777,7 +777,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; -#ifdef HWRENDER +#ifdef USE_FBO_OGL static SDL_bool windowmoved = SDL_FALSE; #endif @@ -799,7 +799,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; -#ifdef HWRENDER +#ifdef USE_FBO_OGL case SDL_WINDOWEVENT_MOVED: windowmoved = SDL_TRUE; break; @@ -843,7 +843,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } } -#ifdef HWRENDER +#ifdef USE_FBO_OGL if (windowmoved && rendermode == render_opengl) { I_DownSample(); @@ -1927,7 +1927,7 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); -#ifdef HWRENDER +#ifdef USE_FBO_OGL if (rendermode == render_opengl) I_DownSample(); #endif diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index dc8b479e7..edc9cdb6b 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -166,8 +166,9 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetupGLFunc4(); granisotropicmode_cons_t[1].value = maximumAnisotropy; - +#ifdef USE_FBO_OGL I_DownSample(); +#endif } first_init = true; @@ -177,7 +178,9 @@ boolean OglSdlSurface(INT32 w, INT32 h) if (screen_width != w || screen_height != h) { FlushScreenTextures(); +#ifdef USE_FBO_OGL GLFramebuffer_DeleteAttachments(); +#endif } screen_width = (GLint)w; @@ -187,11 +190,13 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetStates(); pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); +#ifdef USE_FBO_OGL RenderToFramebuffer = FrameBufferEnabled; GLFramebuffer_Disable(); if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); +#endif HWR_Startup(); textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; @@ -219,13 +224,17 @@ void OglSdlFinishUpdate(boolean waitvbl) SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); +#ifdef USE_FBO_OGL GLFramebuffer_Disable(); RenderToFramebuffer = FrameBufferEnabled; +#endif HWR_DrawScreenFinalTexture(sdlw, sdlh); +#ifdef USE_FBO_OGL if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); +#endif SDL_GL_SwapWindow(window); -- 2.54.0 From eaeb2575f7fcada0129ada3fd8ccbf5391959cc1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:22:30 +0200 Subject: [PATCH 19/24] add stuff to experimental menu --- src/m_menu.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index f4ce5cf38..dfdd26b2d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1458,19 +1458,22 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Skyboxes", &cv_skybox, 70}, - {IT_STRING | IT_CVAR, NULL, "Clipping R_PointToAngle Version", &cv_pointoangleexor64, 85}, + {IT_STRING | IT_CVAR, NULL, "Clipping R_PointToAngle Version", &cv_pointoangleexor64, 90}, - {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 95}, - {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 105}, + {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 105}, + {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 115}, #ifdef HWRENDER - {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 95}, + {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 105}, +#ifdef USE_FBO_OGL + {IT_STRING | IT_CVAR, NULL, "FBO Downsampling support", &cv_grframebuffer, 115}, +#endif - {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_grpalettedepth, 105}, + {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_grpalettedepth, 135}, - {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 125}, - {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 135}, - {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 145}, - {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 155}, + {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 155}, + {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 165}, + {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 175}, + {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 185}, #endif }; @@ -1487,6 +1490,9 @@ static const char* OP_ExpTooltips[] = "Hides Sprites which are not visible\npotentially resulting in a performance boost.", #ifdef HWRENDER "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", +#ifdef USE_FBO_OGL + "Allows the game to downsample from a higher resolution than your display in OpenGL renderer mode\nrequires a GPU with atleast OpenGL 3.0 support.", +#endif "Change the depth of the Palette in Palette rendering mod\n 16 bits is like software looks ingame\nwhile 24 bits is how software looks in screenshots.", "Fixes issues that resulted in Textures sticking from the ground sometimes.\n This may be CPU heavy and result in worse performance in some cases.", "Fixes issues that resulted in Textures not being properly skewed\n example: Fences on slopes that didnt show proper.\n This may be CPU heavy and result in worse performance in some cases.", @@ -1508,6 +1514,10 @@ enum op_exp_sprclip, #ifdef HWRENDER op_exp_grscrtx, +#ifdef USE_FBO_OGL + op_exp_fbo, +#endif + op_exp_paldepth, op_exp_spltwal, op_exp_pegging, op_exp_fofzfight, @@ -2909,7 +2919,7 @@ menu_t OP_MonitorToggleDef = menu_t OP_OpenGLOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_OpenGLOptionsMenu, &OP_VideoOptionsDef, 30, 30); #endif -menu_t OP_ExpOptionsDef = DEFAULTMENUSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 20); +menu_t OP_ExpOptionsDef = DEFAULTMENUSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 10); menu_t OP_DataOptionsDef = DEFAULTMENUSTYLE("M_DATA", OP_DataOptionsMenu, &OP_MainDef, 60, 30); menu_t OP_ScreenshotOptionsDef = DEFAULTMENUSTYLE("M_SCSHOT", OP_ScreenshotOptionsMenu, &OP_DataOptionsDef, 30, 30); @@ -4468,12 +4478,15 @@ void M_Init(void) { OP_VideoOptionsMenu[op_video_ogl].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_grscrtx].status = IT_DISABLED; +#ifdef USE_FBO_OGL + OP_ExpOptionsMenu[op_exp_fbo].status = IT_DISABLED; +#endif OP_ExpOptionsMenu[op_exp_spltwal].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_pegging].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_fofzfight].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_fofcut].status = IT_DISABLED; } - + if (rendermode == render_opengl) { OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED; -- 2.54.0 From 3c8c273e51fb09bbcf3f1e9b67c7b2a098e9a7ac Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:34:27 +0200 Subject: [PATCH 20/24] add ogl version check + grey out in menu + turn it off when not avilible --- src/hardware/r_opengl/r_opengl.c | 16 ++++++++++++++-- src/hardware/r_opengl/r_opengl.h | 1 + src/m_menu.c | 5 +++++ src/sdl/ogl_sdl.c | 8 ++++---- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 9a0eac7b5..0ea12a793 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -124,6 +124,8 @@ static boolean GLFramebuffer_IsFuncAvailible(void); GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; + +boolean supportFBO = false; #endif // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing @@ -764,9 +766,15 @@ void SetupGLFunc4(void) #ifdef USE_FBO_OGL static boolean GLFramebuffer_IsFuncAvailible(void) { + //this stuff needs atleast OGL 3.0 + if (majorGL < 3) + return false; + return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); + + return false; } #endif @@ -2319,9 +2327,13 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) #ifdef USE_FBO_OGL case HWD_SET_FRAMEBUFFER: FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; - - if (!GLFramebuffer_IsFuncAvailible()) + supportFBO = GLFramebuffer_IsFuncAvailible(); + + if (!supportFBO) + { FrameBufferEnabled = GL_FALSE; + CV_Set(&cv_grframebuffer, "Off"); + } break; #endif case HWD_SET_TEXTUREFILTERMODE: diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index a4d8819e3..255969d5a 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -116,6 +116,7 @@ void GLFramebuffer_Disable(void); extern GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; extern GLboolean FrameBufferEnabled, RenderToFramebuffer; +extern boolean supportFBO; #endif // ========================================================================== diff --git a/src/m_menu.c b/src/m_menu.c index dfdd26b2d..5c25b209d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -58,6 +58,7 @@ #ifdef HWRENDER #include "hardware/hw_main.h" +#include "hardware/r_opengl/r_opengl.h" #endif #include "d_net.h" @@ -4491,6 +4492,10 @@ void M_Init(void) { OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_sprclip].status = IT_DISABLED; +#ifdef USE_FBO_OGL + if (!supportFBO) + OP_ExpOptionsMenu[op_exp_fbo].status = IT_GRAYEDOUT; +#endif } #endif diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index edc9cdb6b..5bb6b7347 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -151,6 +151,10 @@ boolean OglSdlSurface(INT32 w, INT32 h) "- GPU drivers are missing or broken. You may need to update your drivers."); } + SetupGLInfo(); + + SetupGLFunc4(); + if (majorGL == 1 && minorGL <= 3) // GL_GENERATE_MIPMAP is unavailible for OGL 1.3 and below supportMipMap = false; else @@ -161,10 +165,6 @@ boolean OglSdlSurface(INT32 w, INT32 h) else maximumAnisotropy = 1; - SetupGLInfo(); - - SetupGLFunc4(); - granisotropicmode_cons_t[1].value = maximumAnisotropy; #ifdef USE_FBO_OGL I_DownSample(); -- 2.54.0 From c966b5defbbcca20977641b51f1c94aeb303db04 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:38:04 +0200 Subject: [PATCH 21/24] forgor --- src/i_video.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i_video.h b/src/i_video.h index 76a06be91..c39186d54 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,7 +139,7 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); -#ifdef HWRENDER +#ifdef USE_FBO_OGL void RefreshSDLSurface(void); void I_DownSample(void); extern boolean downsample; -- 2.54.0 From de6511abe0157aab44c98c5b47a3cf2156bb8a98 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:40:28 +0200 Subject: [PATCH 22/24] dont compile with that with NOHW --- src/CMakeLists.txt | 8 +++++--- src/Makefile | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 74833b216..b4bb035af 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -512,9 +512,11 @@ if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) endif() endif() -if(${SRB2_CONFIG_USE_FBO_OGL}) - set(SRB2_USE_FBO_OGL ON) - add_definitions(-DUSE_FBO_OGL) +if(${SRB2_CONFIG_HWRENDER}) + if(${SRB2_CONFIG_USE_FBO_OGL}) + set(SRB2_USE_FBO_OGL ON) + add_definitions(-DUSE_FBO_OGL) + endif() endif() # Targets diff --git a/src/Makefile b/src/Makefile index 72a083b88..af8dd67b0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -376,9 +376,11 @@ ifdef STATIC LIBS:=-static $(LIBS) endif +ifndef NOHW ifdef USE_FBO_OGL OPTS+=-DUSE_FBO_OGL endif +endif ifdef HAVE_MINIUPNPC ifdef NONET -- 2.54.0 From c6059064084da72a94b6f3ca2241d1265c4d6f49 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:49:36 +0200 Subject: [PATCH 23/24] some stuffs --- src/sdl/i_video.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b898a8e48..bbeeef03f 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -80,6 +80,7 @@ #ifdef HWRENDER #include "../hardware/hw_main.h" #include "../hardware/hw_drv.h" +#include "../hardware/r_opengl/r_opengl.h" //for supportFBO // For dynamic referencing of HW rendering functions #include "hwsym_sdl.h" #include "ogl_sdl.h" @@ -748,7 +749,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) #ifdef USE_FBO_OGL void I_DownSample(void) { - if (!cv_grframebuffer.value || !(rendermode == render_opengl)) + if (!cv_grframebuffer.value || !(rendermode == render_opengl) || (!supportFBO)) //no sense to do this crap if we cant benefit from it { downsample = false; return; @@ -759,13 +760,13 @@ void I_DownSample(void) if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge + if ((vid.width > curmode.w) || (vid.height > curmode.h)) //check if current resolution is higher than current display resolution { downsample = true; RefreshSDLSurface(); } else - downsample = false; + downsample = false; // its not so no need to do crap } else downsample = false; // couldnt get display info so turn the thing off -- 2.54.0 From 6fcea2f98e83d761632748e9e4b4940a963ce255 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:52:05 +0200 Subject: [PATCH 24/24] RefreshOGLSDLSurface to make it a little more clearer this is ogl only --- src/hardware/hw_main.c | 2 +- src/i_video.h | 2 +- src/sdl/i_video.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b52612582..53f0e8786 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -223,7 +223,7 @@ static void CV_grframebuffer_OnChange(void) ONLY_IF_GL_LOADED HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); I_DownSample(); - RefreshSDLSurface(); + RefreshOGLSDLSurface(); } #endif diff --git a/src/i_video.h b/src/i_video.h index c39186d54..708fde03c 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -140,7 +140,7 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); #ifdef USE_FBO_OGL -void RefreshSDLSurface(void); +void RefreshOGLSDLSurface(void); void I_DownSample(void); extern boolean downsample; #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index bbeeef03f..f90f5bb18 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -218,7 +218,7 @@ static void Impl_SetWindowIcon(void); #ifdef USE_FBO_OGL boolean downsample = false; -void RefreshSDLSurface(void) +void RefreshOGLSDLSurface(void) { if (rendermode == render_opengl) OglSdlSurface(vid.width, vid.height); @@ -763,7 +763,7 @@ void I_DownSample(void) if ((vid.width > curmode.w) || (vid.height > curmode.h)) //check if current resolution is higher than current display resolution { downsample = true; - RefreshSDLSurface(); + RefreshOGLSDLSurface(); } else downsample = false; // its not so no need to do crap -- 2.54.0