From: uis Date: Sun, 21 Jan 2024 01:41:53 +0000 (+0300) Subject: Experimental framebuffer invalidation X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c1d95aa27dabb8a5fa7a57983f0eeecc56e02cb8;p=xonotic%2Fdarkplaces.git Experimental framebuffer invalidation --- diff --git a/cl_screen.c b/cl_screen.c index 7abdcac7..32ea147b 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -2081,9 +2081,11 @@ static void SCR_DrawTouchscreenOverlay(void) } } +static const GLuint drawbuffers[6] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_STENCIL_ATTACHMENT, GL_DEPTH_ATTACHMENT}; void R_ClearScreen(qboolean fogcolor) { float clearcolor[4]; + qboolean invalidated = false; if (scr_screenshot_alpha.integer) // clear to transparency (so png screenshots can contain alpha channel, useful for building model pictures) Vector4Set(clearcolor, 0.0f, 0.0f, 0.0f, 0.0f); @@ -2100,7 +2102,11 @@ void R_ClearScreen(qboolean fogcolor) // to avoid clamping interfering with strange shadow volume // drawing orders // clear the screen - GL_Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | (vid.stencil ? GL_STENCIL_BUFFER_BIT : 0), clearcolor, 1.0f, 128); + if(r_sky.integer && !r_refdef.view.isoverlay && r_fbdiscard.integer && qglInvalidateFramebuffer) { + invalidated = true; + qglInvalidateFramebuffer(GL_FRAMEBUFFER, 6, drawbuffers); + } + GL_Clear((invalidated ? 0 : GL_COLOR_BUFFER_BIT) | GL_DEPTH_BUFFER_BIT | (vid.stencil ? GL_STENCIL_BUFFER_BIT : 0), clearcolor, 1.0f, 128); } int r_stereo_side; diff --git a/gl_rmain.c b/gl_rmain.c index 6816a108..9b460227 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -84,6 +84,7 @@ cvar_t r_equalize_entities_to = {CVAR_SAVE, "r_equalize_entities_to", "0.8", "li cvar_t r_depthfirst = {CVAR_SAVE, "r_depthfirst", "0", "renders a depth-only version of the scene before normal rendering begins to eliminate overdraw, values: 0 = off, 1 = world depth, 2 = world and model depth"}; cvar_t r_skylast = {CVAR_SAVE, "r_skylast", "0", "renders sky after normal rendering ends to eliminate overdraw, values: 0 = nodepth sky first, 1 = sky after depth pass(if enabled), 2 = sky after world, 3 = sky after entities"}; +cvar_t r_fbdiscard = {CVAR_SAVE, "r_fbdiscard", "0", "Discard color buffer, increases performance, but creates visual glitches in menu"}; cvar_t r_useinfinitefarclip = {CVAR_SAVE, "r_useinfinitefarclip", "1", "enables use of a special kind of projection matrix that has an extremely large farclip"}; cvar_t r_farclip_base = {0, "r_farclip_base", "65536", "farclip (furthest visible distance) for rendering when r_useinfinitefarclip is 0"}; cvar_t r_farclip_world = {0, "r_farclip_world", "2", "adds map size to farclip multiplied by this value"}; @@ -4233,6 +4234,7 @@ void GL_Main_Init(void) Cvar_RegisterVariable(&r_equalize_entities_to); Cvar_RegisterVariable(&r_depthfirst); Cvar_RegisterVariable(&r_skylast); + Cvar_RegisterVariable(&r_fbdiscard); Cvar_RegisterVariable(&r_useinfinitefarclip); Cvar_RegisterVariable(&r_farclip_base); Cvar_RegisterVariable(&r_farclip_world); diff --git a/glquake.h b/glquake.h index 1375c8e6..d87dda2b 100644 --- a/glquake.h +++ b/glquake.h @@ -1109,6 +1109,8 @@ extern void (GLAPIENTRY *qglSampleCoverageARB)(GLclampf value, GLboolean invert) extern void (GLAPIENTRY *qglPointSize)(GLfloat size); +extern void (GLAPIENTRY *qglInvalidateFramebuffer)(GLenum target, GLsizei numAttachments, const GLenum *attachments); + //GL_EXT_packed_depth_stencil #define GL_DEPTH_STENCIL_EXT 0x84F9 #define GL_UNSIGNED_INT_24_8_EXT 0x84FA diff --git a/r_sky.c b/r_sky.c index e5ffcd5f..a17db911 100644 --- a/r_sky.c +++ b/r_sky.c @@ -7,7 +7,6 @@ cvar_t r_sky = {CVAR_SAVE, "r_sky", "1", "enables sky rendering (black otherwise cvar_t r_skyscroll1 = {CVAR_SAVE, "r_skyscroll1", "1", "speed at which upper clouds layer scrolls in quake sky"}; cvar_t r_skyscroll2 = {CVAR_SAVE, "r_skyscroll2", "2", "speed at which lower clouds layer scrolls in quake sky"}; cvar_t r_sky_scissor = {0, "r_sky_scissor", "1", "limit rendering of sky to approximately the area of the sky surfaces"}; -extern cvar_t r_skylast; int skyrenderlater; int skyrendermasked; int skyscissor[4]; diff --git a/render.h b/render.h index 8f387103..9ad6805b 100644 --- a/render.h +++ b/render.h @@ -34,6 +34,7 @@ extern cvar_t r_sky; extern cvar_t r_skyscroll1; extern cvar_t r_skyscroll2; extern cvar_t r_sky_scissor; +extern cvar_t r_skylast; extern cvar_t r_q3bsp_renderskydepth; extern int skyrenderlater, skyrendermasked; extern int skyscissor[4]; @@ -216,6 +217,7 @@ void R_AnimCache_CacheVisibleEntities(void); extern cvar_t r_render; extern cvar_t r_renderview; extern cvar_t r_waterwarp; +extern cvar_t r_fbdiscard; extern cvar_t r_textureunits; diff --git a/vid_shared.c b/vid_shared.c index 9ac2ad7e..ad7f889e 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -358,6 +358,8 @@ void (GLAPIENTRY *qglPolygonStipple)(const GLubyte *mask); void (GLAPIENTRY *qglLineWidth)(GLfloat width); void (GLAPIENTRY *qglPointSize)(GLfloat size); +void (GLAPIENTRY *qglInvalidateFramebuffer)(GLenum target, GLsizei numAttachments, const GLenum *attachments); + void (GLAPIENTRY *qglBlendEquationEXT)(GLenum); void (GLAPIENTRY *qglStencilOpSeparate)(GLenum, GLenum, GLenum, GLenum); @@ -766,6 +768,11 @@ static dllfunction_t blendequationfuncs[] = {NULL, NULL} }; +static dllfunction_t invalidatesubdatafuncs[] = +{ + {"glInvalidateFramebuffer", (void**) &qglInvalidateFramebuffer}, + {NULL, NULL} +}; static dllfunction_t gl20shaderfuncs[] = { {"glDeleteShader", (void **) &qglDeleteShader}, @@ -1065,6 +1072,7 @@ void VID_CheckExtensions(void) vid.support.ati_separate_stencil = GL_CheckExtension("separatestencil", gl2separatestencilfuncs, "-noseparatestencil", true) || GL_CheckExtension("GL_ATI_separate_stencil", atiseparatestencilfuncs, "-noseparatestencil", false); vid.support.ext_blend_minmax = GL_CheckExtension("GL_EXT_blend_minmax", blendequationfuncs, "-noblendminmax", false); vid.support.ext_blend_subtract = GL_CheckExtension("GL_EXT_blend_subtract", blendequationfuncs, "-noblendsubtract", false); + GL_CheckExtension("GL_ARB_invalidate_subdata", invalidatesubdatafuncs, "-noinvalidate", false); vid.support.ext_blend_func_separate = GL_CheckExtension("GL_EXT_blend_func_separate", blendfuncseparatefuncs, "-noblendfuncseparate", false); vid.support.ext_draw_range_elements = GL_CheckExtension("drawrangeelements", drawrangeelementsfuncs, "-nodrawrangeelements", true) || GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false); vid.support.arb_framebuffer_object = GL_CheckExtension("GL_ARB_framebuffer_object", arbfbofuncs, "-nofbo", false);