diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 80f84a104..8dec512dc 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -161,6 +161,9 @@ static void COM_HWR_glinfo(void); // static void CV_screentextures_OnChange(void); +#ifdef USE_FBO_OGL +static void CV_glframebuffer_OnChange(void); +#endif static void CV_glshaders_OnChange(void); static void CV_gllightdithering_OnChange(void); static void CV_filtermode_OnChange(void); @@ -203,6 +206,10 @@ static CV_PossibleValue_t glpalettedepth_cons_t[] = {{16, "16 bits"}, {24, "24 b // - full screen scaling (use native resolution or windowed mode to avoid this) consvar_t cv_glscreentextures = {"gr_screentextures", "All", CV_CALL|CV_SAVE, glscreentextures_cons_t, CV_screentextures_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#ifdef USE_FBO_OGL +consvar_t cv_glframebuffer = {"gr_framebuffer", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, CV_glframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#endif + consvar_t cv_glmdls = {"gr_mdls", "Off", CV_SAVE|CV_CALL, CV_OnOff, M_UpdateOGLMenu, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_glfallbackplayermodel = {"gr_fallbackplayermodel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -246,11 +253,29 @@ static void CV_screentextures_OnChange(void) { if (cv_glpaletterendering.value != 0) CV_SetValue(&cv_glpaletterendering, 0); + +#ifdef USE_FBO_OGL + if (cv_glframebuffer.value != 0) + CV_SetValue(&cv_glframebuffer, 0); +#endif } GL_SetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_glscreentextures.value); M_UpdateOGLMenu(); } +#ifdef USE_FBO_OGL +static void CV_glframebuffer_OnChange(void) +{ + ONLY_IF_GL_LOADED + if ((cv_glframebuffer.value != 0 && cv_glscreentextures.value != 2) || (!supportFBO && cv_glframebuffer.value != 0)) // screen FBO needs screen textures + CV_SetValue(&cv_glframebuffer, 0); + + I_DownSample(); + RefreshOGLSDLSurface(); + M_UpdateOGLMenu(); +} +#endif + static void CV_glshaders_OnChange(void) { ONLY_IF_GL_LOADED @@ -5776,6 +5801,10 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_glscreentextures); +#ifdef USE_FBO_OGL + CV_RegisterVar(&cv_glframebuffer); +#endif + CV_RegisterVar(&cv_glmdls); CV_RegisterVar(&cv_glfallbackplayermodel); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 1ccf7eece..14ab66522 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -183,6 +183,9 @@ extern CV_PossibleValue_t glanisotropicmode_cons_t[]; extern consvar_t cv_gltexturedepth; extern consvar_t cv_glscreentextures; +#ifdef USE_FBO_OGL +extern consvar_t cv_glframebuffer; +#endif extern consvar_t cv_glmdls; extern consvar_t cv_glfallbackplayermodel; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 4da573a4d..c17180aab 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1265,7 +1265,7 @@ void GL_DeleteTexture(GLMipmap_t *pTexInfo) #ifdef USE_FBO_OGL static void GL_Framebuffer_GenerateAttachments(void) { - if (!supportFBO) + if (!supportFBO || !UseScreenFBO()) return; // Bind the framebuffer @@ -1347,7 +1347,7 @@ static void GL_Framebuffer_DeleteAttachments(void) static void GL_Framebuffer_Generate(void) { - if (!supportFBO) + if (!supportFBO || !UseScreenFBO()) return; // Generate the framebuffer @@ -1384,7 +1384,7 @@ void GL_Framebuffer_Unbind(void) void GL_Framebuffer_Enable(void) { - if (!supportFBO) + if (!supportFBO || !UseScreenFBO()) return; if (FramebufferObject == 0) diff --git a/src/i_video.h b/src/i_video.h index 927db786a..7850d664a 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -144,6 +144,14 @@ boolean I_CheckNativeRes(void); void I_SetBorderlessWindow(void); +#ifdef USE_FBO_OGL + +void RefreshOGLSDLSurface(void); +void I_DownSample(void); +boolean UseScreenFBO(void); +extern boolean downsample; +#endif + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/m_menu.c b/src/m_menu.c index f2e026741..8c459b1c0 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1825,10 +1825,17 @@ void M_Init(void) OP_VideoOptionsMenu[op_video_ogl].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_glscrtx].status = IT_DISABLED; +#ifdef USE_FBO_OGL + OP_ExpOptionsMenu[op_exp_fbo].status = IT_DISABLED; +#endif OP_ExpOptionsMenu[op_exp_paldepth].status = IT_DISABLED; } else if (rendermode == render_opengl) { +#ifdef USE_FBO_OGL + if (!supportFBO) + OP_ExpOptionsMenu[op_exp_fbo].status = IT_GRAYEDOUT; +#endif if (!gl_shadersavailable) { OP_OpenGLOptionsMenu[op_gl_shader].status = IT_GRAYEDOUT; diff --git a/src/m_menudefs.c b/src/m_menudefs.c index 4bd9b044a..d3d95a296 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -948,9 +948,15 @@ static menuitem_t OP_ExpOptionsMenu[] = #ifdef HWRENDER {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_glscreentextures, 70}, +#ifdef USE_FBO_OGL + {IT_STRING | IT_CVAR, NULL, "FBO Downsampling support", &cv_glframebuffer, 75}, + {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_glpalettedepth, 85}, + {IT_DISABLED, NULL, "", NULL, 95}, // dummy text +#else {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_glpalettedepth, 80}, {IT_DISABLED, NULL, "", NULL, 90}, // dummy text #endif +#endif }; static const char* OP_ExpTooltips[] = @@ -965,6 +971,9 @@ static const char* OP_ExpTooltips[] = "Different methods of scaling the votescreen backgrounds.", #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\nin OpenGL renderer mode. Requires a GPU with atleast OpenGL 3.0 support.", +#endif "Change the bit depth of the Lookup Palette in Palette rendering mode\n 16 bits is like software looks ingame\nwhile 24 bits is how software looks in screenshots.", #endif }; @@ -981,6 +990,9 @@ enum op_exp_votescrn, #ifdef HWRENDER op_exp_glscrtx, +#ifdef USE_FBO_OGL + op_exp_fbo, +#endif op_exp_paldepth, #endif }; @@ -2914,6 +2926,9 @@ void GameFocus_menu_Onchange(void) #ifdef HWRENDER void M_UpdateOGLMenu(void) { +#ifdef USE_FBO_OGL + OP_ExpOptionsMenu[op_exp_fbo].status = (!supportFBO || cv_glscreentextures.value != 2) ? IT_GRAYEDOUT : IT_STRING | IT_CVAR; +#endif OP_ExpOptionsMenu[op_exp_paldepth].status = (!HWR_ShouldUsePaletteRendering()) ? IT_GRAYEDOUT : IT_STRING | IT_CVAR; OP_OpenGLOptionsMenu[op_gl_falbckmdls].status = (!cv_glmdls.value) ? IT_GRAYEDOUT : IT_STRING | IT_CVAR; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 76f068678..7a6cb1743 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -133,6 +133,7 @@ static void Impl_SetVsync(void); static INT32 desktopwidth = 0, desktopheight = 0; static void I_CheckDesktopRes(void); + // synchronize page flipping with screen refresh consvar_t cv_vidwait = {"vid_wait", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Impl_SetVsync, 0, NULL, NULL, 0, 0, NULL}; static consvar_t cv_stretch = {"stretch", "Off", CV_SAVE|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -210,6 +211,15 @@ static void Impl_VideoSetupBuffer(void); static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); static void Impl_SetWindowIcon(void); +#ifdef USE_FBO_OGL +boolean downsample = false; +void RefreshOGLSDLSurface(void) +{ + if (rendermode == render_opengl) + OglSdlSurface(vid.width, vid.height); +} +#endif + void I_SetTextInput(void) { static boolean input_active = false; @@ -544,6 +554,43 @@ boolean I_CheckNativeRes(void) return (vid.width == desktopwidth && vid.height == desktopheight); } +#ifdef USE_FBO_OGL +void I_DownSample(void) +{ + boolean needrefresh = false; + + if (!cv_glframebuffer.value || !supportFBO || (cv_glscreentextures.value == 0)) // no sense to do this crap if we cant benefit from it + { + downsample = false; + return; + } + + if (I_CheckNativeRes() && (downsample == true)) + { + downsample = false; + RefreshOGLSDLSurface(); + return; + } + + if ((vid.width > desktopwidth) || (vid.height > desktopheight)) //check if current resolution is higher than current display resolution + { + downsample = true; + needrefresh = true; + } + else if (downsample == true) + { + downsample = false; + needrefresh = true; + } + + if (needrefresh) + { + RefreshOGLSDLSurface(); + needrefresh = false; + } +} +#endif + static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { #define FOCUSUNION (mousefocus | (kbfocus << 1) | (windowmoved << 2)) @@ -589,6 +636,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (windowmoved && rendermode == render_opengl) { I_CheckDesktopRes(); +#ifdef USE_FBO_OGL + I_DownSample(); +#endif } if (mousefocus && kbfocus) @@ -1239,6 +1289,9 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) if (rendermode == render_opengl) { I_CheckDesktopRes(); +#ifdef USE_FBO_OGL + I_DownSample(); +#endif OglSdlSurface(vid.width, vid.height); } #endif diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 272e8bbad..c8701506e 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -70,6 +70,22 @@ PFNglGetIntegerv pglGetIntegerv; PFNglGetString pglGetString; #endif +#ifdef USE_FBO_OGL + +#if defined (__unix__) +static boolean xwaylandcrap = false; +#endif + +boolean UseScreenFBO(void) +{ + return ((supportFBO && cv_glframebuffer.value && downsample) +#if defined (__unix__) + || (supportFBO && xwaylandcrap) +#endif + ); +} +#endif + /** \brief SDL video display surface */ INT32 oglflags = 0; @@ -191,6 +207,16 @@ boolean OglSdlSurface(INT32 w, INT32 h) maximumAnisotropy = 1; glanisotropicmode_cons_t[1].value = maximumAnisotropy; + +#if defined (__unix__) +#ifdef USE_FBO_OGL + char videodriver[4] = {'S','D','L',0}; + if (supportFBO && strstr((const char*)gl_renderer, "NVIDIA") + && (*strncpy(videodriver, SDL_GetCurrentVideoDriver(), sizeof(videodriver)-1) != '\0') + && (strncasecmp("x11",videodriver,4) == 0)) + xwaylandcrap = true; +#endif +#endif } SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); @@ -200,7 +226,10 @@ boolean OglSdlSurface(INT32 w, INT32 h) pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); #ifdef USE_FBO_OGL - GL_Framebuffer_Enable(); + if (UseScreenFBO()) + GL_Framebuffer_Enable(); + else + GL_Framebuffer_Disable(); #endif if (!first_init) @@ -222,6 +251,10 @@ void OglSdlFinishUpdate(boolean waitvbl) static boolean oldwaitvbl = false; int sdlw, sdlh; +#ifdef USE_FBO_OGL + const boolean usefbo = UseScreenFBO(); +#endif + if (oldwaitvbl != waitvbl) { SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); @@ -233,18 +266,41 @@ void OglSdlFinishUpdate(boolean waitvbl) HWR_MakeScreenFinalTexture(); #ifdef USE_FBO_OGL - GL_Framebuffer_Unbind(); + if (usefbo) + { + GL_Framebuffer_Unbind(); + } #endif HWR_DrawScreenFinalTexture(sdlw, sdlh, HWR_ShouldUsePaletteRendering()); #ifdef USE_FBO_OGL - GL_Framebuffer_Enable(); + if (usefbo) + { + GL_Framebuffer_Enable(); + } #endif SDL_GL_SwapWindow(window); GL_GClipRect(0, 0, realwidth, realheight, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); + + // Sryder: We need to draw the final screen texture again into the other buffer in the original position so that + // effects that want to take the old screen can do so after this + // well we dont need it on native res it seems +#ifdef USE_FBO_OGL + if ((!I_CheckNativeRes() && !usefbo) || WipeInAction) +#else + if (!I_CheckNativeRes() || WipeInAction) +#endif + HWR_DrawScreenFinalTexture(realwidth, realheight, false); + +#if defined (__unix__) +#ifdef USE_FBO_OGL + if (loaded_config) + xwaylandcrap = false; +#endif +#endif } #endif //HWRENDER