From 5e8e2f4b3a1555e7c6ccd6a9c102bd94e632f587 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:59:41 +0200 Subject: [PATCH] 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 | 12 +++++++++--- src/hardware/r_opengl/r_opengl.h | 2 ++ src/i_video.h | 5 +++++ src/sdl/i_video.c | 25 +++++++++++++++++++++++-- src/sdl/ogl_sdl.c | 18 ++++++++++++++---- 8 files changed, 76 insertions(+), 18 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 e2577bc69..54922c0fc 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -70,7 +70,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); @@ -98,7 +100,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}; @@ -166,14 +170,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 @@ -220,6 +216,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. // @@ -5948,7 +5954,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); @@ -6011,8 +6019,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 b9893538b..fc7318bd0 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -150,7 +150,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 6cc26fcbe..ee94e5144 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 @@ -456,6 +457,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) pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); +#ifdef GL_VERSION_3_0 if (GLFramebuffer_IsFuncAvailible()) { pglGenFramebuffers = GetGLFunc("glGenFramebuffers"); @@ -755,12 +758,14 @@ void SetupGLFunc4(void) } } +#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) { @@ -1097,6 +1102,7 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); } +#endif // -----------------+ // DeleteTexture : Deletes a texture from the GPU and frees its data @@ -2308,14 +2314,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 25be9ead6..1e1916dc9 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -141,7 +141,12 @@ void RefreshSDLSurface(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 f3fef167d..9f1d02f7c 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 bf17113e0..4ac503c10 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -171,8 +171,10 @@ boolean OglSdlSurface(INT32 w, INT32 h) supportMipMap = true; granisotropicmode_cons_t[1].value = maximumAnisotropy; - + +#ifdef GL_VERSION_3_0 I_DownSample(); +#endif } first_init = true; @@ -190,7 +192,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; @@ -199,12 +203,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; @@ -239,14 +245,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);