From 48000d09707a7f795a18dae04089c3c3fc35d61e Mon Sep 17 00:00:00 2001 From: hzqst <113660872@qq.com> Date: Fri, 23 Feb 2024 12:31:12 +0800 Subject: [PATCH] 1 --- Plugins/Renderer/gl_draw.cpp | 14 ++++ Plugins/Renderer/gl_hud.cpp | 13 ++-- Plugins/Renderer/gl_light.cpp | 8 +- Plugins/Renderer/gl_local.h | 7 +- Plugins/Renderer/gl_rmain.cpp | 137 +++++++++++++-------------------- Plugins/Renderer/gl_rsurf.cpp | 2 +- Plugins/Renderer/gl_shadow.cpp | 29 +++---- Plugins/Renderer/gl_sprite.cpp | 2 +- Plugins/Renderer/gl_studio.cpp | 19 ++--- Plugins/Renderer/gl_warp.cpp | 2 +- Plugins/Renderer/gl_water.cpp | 17 ++-- Plugins/Renderer/gl_wsurf.cpp | 47 +++-------- 12 files changed, 126 insertions(+), 171 deletions(-) diff --git a/Plugins/Renderer/gl_draw.cpp b/Plugins/Renderer/gl_draw.cpp index 532e25ad..b9760cef 100644 --- a/Plugins/Renderer/gl_draw.cpp +++ b/Plugins/Renderer/gl_draw.cpp @@ -378,6 +378,20 @@ void GL_BindVAO(GLuint VAO) glBindVertexArray(VAO); } +void GL_UploadSubDataToUBO(GLuint UBO, size_t offset, size_t size, const void* data) +{ + if (glNamedBufferSubData) + { + glNamedBufferSubData(UBO, offset, size, data); + } + else + { + glBindBuffer(GL_UNIFORM_BUFFER, UBO); + glBufferSubData(GL_UNIFORM_BUFFER, offset, size, data); + glBindBuffer(GL_UNIFORM_BUFFER, 0); + } +} + void GL_UploadDataToVBOStaticDraw(GLuint VBO, size_t size, const void* data) { glBindBuffer(GL_ARRAY_BUFFER, VBO); diff --git a/Plugins/Renderer/gl_hud.cpp b/Plugins/Renderer/gl_hud.cpp index 8121644e..6ee64d3e 100644 --- a/Plugins/Renderer/gl_hud.cpp +++ b/Plugins/Renderer/gl_hud.cpp @@ -336,9 +336,6 @@ void GL_BlitFrameFufferToScreen(FBO_Container_t *src) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_READ_FRAMEBUFFER, src->s_hBackBufferFBO); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); - glBlitFramebuffer(0, 0, src->iWidth, src->iHeight, 0, 0, glwidth, glheight, GL_COLOR_BUFFER_BIT, GL_LINEAR); } @@ -781,13 +778,13 @@ bool R_IsGammaBlendEnabled() { if (r_gamma_blend->value > 0) { - if (r_draw_shadowcaster) + if ((*r_refdef.onlyClientDraws)) return false; - if (r_draw_reflectview) + if (R_IsRenderingShadowView()) return false; - if ((*r_refdef.onlyClientDraws)) + if (R_IsRenderingWaterView()) return false; if (R_IsRenderingPortal()) @@ -907,10 +904,10 @@ bool R_IsAmbientOcclusionEnabled(void) if ((*r_refdef.onlyClientDraws)) return false; - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return false; - if (r_draw_reflectview) + if (R_IsRenderingWaterView()) return false; if (R_IsRenderingPortal()) diff --git a/Plugins/Renderer/gl_light.cpp b/Plugins/Renderer/gl_light.cpp index 726ab469..434f2990 100644 --- a/Plugins/Renderer/gl_light.cpp +++ b/Plugins/Renderer/gl_light.cpp @@ -512,10 +512,14 @@ bool R_IsDeferredRenderingEnabled(void) if (!r_light_dynamic->value) return false; - if (r_draw_shadowcaster) + //TODO: really? + if ((*r_refdef.onlyClientDraws)) return false; - if (r_draw_reflectview) + if (R_IsRenderingShadowView()) + return false; + + if (R_IsRenderingWaterView()) return false; if (R_IsRenderingPortal()) diff --git a/Plugins/Renderer/gl_local.h b/Plugins/Renderer/gl_local.h index c75f8ea4..5a7bf203 100644 --- a/Plugins/Renderer/gl_local.h +++ b/Plugins/Renderer/gl_local.h @@ -253,6 +253,7 @@ extern cvar_t *r_shadows; extern cvar_t *r_mirroralpha; extern cvar_t *r_wateralpha; extern cvar_t *r_dynamic; +extern cvar_t* r_novis; extern cvar_t *r_mmx; extern cvar_t *r_traceglow; extern cvar_t *r_wadtextures; @@ -334,7 +335,6 @@ void V_RenderView(void); void R_RenderView(void); void R_RenderScene(void); void R_RenderView_SvEngine(int a1); -bool R_IsRenderingPortal(void); qboolean R_CullBox(vec3_t mins, vec3_t maxs); qboolean Host_IsSinglePlayerGame(); bool AllowCheats(); @@ -390,6 +390,7 @@ void GL_DeleteTexture(GLuint tex); void GL_DeleteBuffer(GLuint buf); void GL_DeleteVAO(GLuint VAO); void GL_BindVAO(GLuint VAO); +void GL_UploadSubDataToUBO(GLuint UBO, size_t offset, size_t size, const void* data); void GL_UploadDataToVBOStaticDraw(GLuint VBO, size_t size, const void* data); void GL_UploadDataToVBODynamicDraw(GLuint VBO, size_t size, const void* data); void GL_UploadSubDataToVBODynamicDraw(GLuint VBO, size_t offset, size_t size, const void* data); @@ -496,6 +497,9 @@ void GL_PushFrameBuffer(void); void GL_PopFrameBuffer(void); bool R_IsRenderingGBuffer(); +bool R_IsRenderingShadowView(void); +bool R_IsRenderingWaterView(void); +bool R_IsRenderingPortal(void); //Fog bool R_IsRenderingFog(); @@ -587,6 +591,7 @@ extern bool r_draw_oitblend; extern bool r_draw_gammablend; extern bool r_draw_legacysprite; extern bool r_draw_reflectview; +extern bool r_draw_refractview; extern bool r_draw_portalview; extern int r_renderview_pass; diff --git a/Plugins/Renderer/gl_rmain.cpp b/Plugins/Renderer/gl_rmain.cpp index f3514731..69df1be1 100644 --- a/Plugins/Renderer/gl_rmain.cpp +++ b/Plugins/Renderer/gl_rmain.cpp @@ -198,6 +198,7 @@ bool r_draw_oitblend = false; bool r_draw_gammablend = false; bool r_draw_legacysprite = false; bool r_draw_reflectview = false; +bool r_draw_refractview = false; bool r_draw_portalview = false; int r_renderview_pass = 0; @@ -334,7 +335,7 @@ bool R_CanRenderFog() if (CL_IsDevOverviewMode()) return false; - if (r_draw_reflectview) + if (R_IsRenderingWaterView()) return false; return true; @@ -358,6 +359,33 @@ bool R_IsRenderingGBuffer() return GL_GetCurrentRenderingFBO() == &s_GBufferFBO; } +/* + Purpose : Check if we are rendering Shadow Pass +*/ + +bool R_IsRenderingShadowView(void) +{ + return r_draw_shadowcaster; +} + +/* + Purpose : Check if we are rendering Water Pass +*/ + +bool R_IsRenderingWaterView(void) +{ + return r_draw_reflectview || r_draw_refractview; +} + +/* + Purpose : Check if we are rendering Portal Pass +*/ + +bool R_IsRenderingPortal(void) +{ + return g_bRenderingPortals_SCClient && (*g_bRenderingPortals_SCClient) == 1; +} + /* Purpose : Check if we are in SinglePlayer game */ @@ -1013,7 +1041,7 @@ void ClientDLL_DrawTransparentTriangles(void) void R_DrawTransEntities(int onlyClientDraw) { - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return; GL_BeginProfile(&Profile_DrawTransEntities); @@ -1101,7 +1129,7 @@ void R_DrawTransEntities(int onlyClientDraw) void R_AddTEntity(cl_entity_t *ent) { - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return; if (!ent->model) @@ -1678,6 +1706,7 @@ void GL_GenerateFrameBuffers(void) GL_FrameBufferColorTexture(&s_LuminFBO[i], GL_R32F); vec4_t clearColor = { 0, 0, 0, 0 }; + GL_ClearColor(clearColor); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) @@ -1699,6 +1728,7 @@ void GL_GenerateFrameBuffers(void) GL_FrameBufferColorTexture(&s_Lumin1x1FBO[i], GL_R32F); vec4_t clearColor = { 0, 0, 0, 0 }; + GL_ClearColor(clearColor); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) @@ -1866,8 +1896,8 @@ void GL_FlushFinalBuffer() { GL_BindFrameBuffer(&s_FinalBufferFBO); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + vec4_t vecClearColor = { 0, 0, 0, 0 }; + GL_ClearColorDepthStencil(vecClearColor, 1, STENCIL_MASK_SKY, STENCIL_MASK_ALL); } bool SCR_IsLoadingVisible() @@ -1972,38 +2002,6 @@ void R_PreRenderView() r_sprite_drawcall = 0; r_sprite_polys = 0; -#if 0 - //Capture OpenGL fog settings committed by client dll or engine dll. - r_fog_mode = 0; - - //TODO use client dll settings... - if (glIsEnabled(GL_FOG)) - { - glGetIntegerv(GL_FOG_MODE, &r_fog_mode); - - if (r_fog_mode == GL_LINEAR) - { - glGetFloatv(GL_FOG_START, &r_fog_control[0]); - glGetFloatv(GL_FOG_END, &r_fog_control[1]); - glGetFloatv(GL_FOG_COLOR, r_fog_color); - } - else if (r_fog_mode == GL_EXP) - { - glGetFloatv(GL_FOG_START, &r_fog_control[0]); - glGetFloatv(GL_FOG_END, &r_fog_control[1]); - glGetFloatv(GL_FOG_DENSITY, &r_fog_control[2]); - glGetFloatv(GL_FOG_COLOR, r_fog_color); - } - else if (r_fog_mode == GL_EXP2) - { - glGetFloatv(GL_FOG_START, &r_fog_control[0]); - glGetFloatv(GL_FOG_END, &r_fog_control[1]); - glGetFloatv(GL_FOG_DENSITY, &r_fog_control[2]); - glGetFloatv(GL_FOG_COLOR, r_fog_color); - } - } -#endif - //Always force GammaBlend to be disabled when rendering opaques. r_draw_gammablend = false; @@ -2029,7 +2027,8 @@ void R_PreRenderView() R_ParseCvarAsColor3(gl_clearcolor, vecClearColor); } - //TODO: Gamma correction for the clear color ? + GammaToLinear(vecClearColor); + GL_ClearColorDepthStencil(vecClearColor, 1, STENCIL_MASK_WORLD, STENCIL_MASK_ALL); glDepthFunc(GL_LEQUAL); @@ -2165,11 +2164,6 @@ void R_PreDrawViewModel(void) r_draw_predrawviewmodel = false; } -bool R_IsRenderingPortal(void) -{ - return g_bRenderingPortals_SCClient && (*g_bRenderingPortals_SCClient) == 1; -} - void R_ClearPortalClipPlanes(void) { for (int i = 0; i < 6; ++i) @@ -2346,8 +2340,8 @@ void GL_EndRendering(void) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_READ_FRAMEBUFFER, s_FinalBufferFBO.s_hBackBufferFBO); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); + vec4_t vecClearColor = { 0, 0, 0, 0 }; + GL_ClearColor(vecClearColor); glBlitFramebuffer(0, 0, srcW, srcH, dstX1, dstY1, dstX2, dstY2, GL_COLOR_BUFFER_BIT, GL_LINEAR); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); @@ -2542,7 +2536,7 @@ void R_Shutdown(void) void R_ForceCVars(qboolean mp) { - if (r_draw_reflectview) + if (R_IsRenderingWaterView()) return; if (gPrivateFuncs.R_ForceCVars) @@ -3045,18 +3039,8 @@ void R_UploadProjMatrixForViewModel(void) memcpy(SceneUBO.projMatrix, r_viewmodel_projection_matrix, sizeof(mat4)); memcpy(SceneUBO.invProjMatrix, r_viewmodel_projection_matrix_inv, sizeof(mat4)); - if (glNamedBufferSubData) - { - glNamedBufferSubData(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, projMatrix), sizeof(mat4), &SceneUBO.projMatrix); - glNamedBufferSubData(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, invProjMatrix), sizeof(mat4), &SceneUBO.invProjMatrix); - } - else - { - glBindBuffer(GL_UNIFORM_BUFFER, r_wsurf.hSceneUBO); - glBufferSubData(GL_UNIFORM_BUFFER, offsetof(scene_ubo_t, projMatrix), sizeof(mat4), &SceneUBO.projMatrix); - glBufferSubData(GL_UNIFORM_BUFFER, offsetof(scene_ubo_t, invProjMatrix), sizeof(mat4), &SceneUBO.invProjMatrix); - glBindBuffer(GL_UNIFORM_BUFFER, 0); - } + GL_UploadSubDataToUBO(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, projMatrix), sizeof(mat4), &SceneUBO.projMatrix); + GL_UploadSubDataToUBO(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, invProjMatrix), sizeof(mat4), &SceneUBO.invProjMatrix); } void R_LoadProjMatrixForWorld(void) @@ -3065,18 +3049,8 @@ void R_LoadProjMatrixForWorld(void) memcpy(SceneUBO.projMatrix, r_projection_matrix, sizeof(mat4)); memcpy(SceneUBO.invProjMatrix, r_projection_matrix_inv, sizeof(mat4)); - if (glNamedBufferSubData) - { - glNamedBufferSubData(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, projMatrix), sizeof(mat4), &SceneUBO.projMatrix); - glNamedBufferSubData(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, invProjMatrix), sizeof(mat4), &SceneUBO.invProjMatrix); - } - else - { - glBindBuffer(GL_UNIFORM_BUFFER, r_wsurf.hSceneUBO); - glBufferSubData(GL_UNIFORM_BUFFER, offsetof(scene_ubo_t, projMatrix), sizeof(mat4), &SceneUBO.projMatrix); - glBufferSubData(GL_UNIFORM_BUFFER, offsetof(scene_ubo_t, invProjMatrix), sizeof(mat4), &SceneUBO.invProjMatrix); - glBindBuffer(GL_UNIFORM_BUFFER, 0); - } + GL_UploadSubDataToUBO(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, projMatrix), sizeof(mat4), &SceneUBO.projMatrix); + GL_UploadSubDataToUBO(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, invProjMatrix), sizeof(mat4), &SceneUBO.invProjMatrix); } void R_SetupGLForViewModel(void) @@ -3159,14 +3133,14 @@ void R_SetupGL(void) glwidth = gl_envmapsize->value; } - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) { r_viewport[0] = 0; r_viewport[1] = 0; r_viewport[2] = current_shadow_texture->size; r_viewport[3] = current_shadow_texture->size; } - else if (r_draw_reflectview) + else if (R_IsRenderingWaterView()) { r_viewport[0] = 0; r_viewport[1] = 0; @@ -3183,7 +3157,7 @@ void R_SetupGL(void) glViewport(r_viewport[0], r_viewport[1], r_viewport[2], r_viewport[3]); - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) { float cone_fov = current_shadow_texture->cone_angle * 2 * 360 / (M_PI * 2); R_SetupPerspective(cone_fov, cone_fov, 4.0f, current_shadow_texture->distance); @@ -3338,7 +3312,7 @@ void R_SetupFrame(void) (*r_oldviewleaf) = (*r_viewleaf); - if (r_draw_reflectview) + if (R_IsRenderingWaterView()) { (*r_viewleaf) = Mod_PointInLeaf(g_CurrentCameraView, r_worldmodel); } @@ -3455,7 +3429,7 @@ void R_DrawEntitiesOnList(void) void R_AddTEntityForViewModel(cl_entity_t* ent) { - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return; if (!ent->model) @@ -3565,21 +3539,14 @@ void R_DrawTEntitiesForViewModel(void) void R_SetupFog(void) { scene_ubo_t SceneUBO; + memcpy(SceneUBO.fogColor, r_fog_color, sizeof(vec4_t)); + SceneUBO.fogStart = r_fog_control[0]; SceneUBO.fogEnd = r_fog_control[1]; SceneUBO.fogDensity = r_fog_control[2]; - if (glNamedBufferSubData) - { - glNamedBufferSubData(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, fogColor), offsetof(scene_ubo_t, time) - offsetof(scene_ubo_t, fogColor), &SceneUBO.fogColor); - } - else - { - glBindBuffer(GL_UNIFORM_BUFFER, r_wsurf.hSceneUBO); - glBufferSubData(GL_UNIFORM_BUFFER, offsetof(scene_ubo_t, fogColor), offsetof(scene_ubo_t, time) - offsetof(scene_ubo_t, fogColor), &SceneUBO.fogColor); - glBindBuffer(GL_UNIFORM_BUFFER, 0); - } + GL_UploadSubDataToUBO(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, fogColor), offsetof(scene_ubo_t, time) - offsetof(scene_ubo_t, fogColor), &SceneUBO.fogColor); glEnable(GL_FOG); glFogi(GL_FOG_MODE, r_fog_mode); diff --git a/Plugins/Renderer/gl_rsurf.cpp b/Plugins/Renderer/gl_rsurf.cpp index 7c894bd3..21ae5754 100644 --- a/Plugins/Renderer/gl_rsurf.cpp +++ b/Plugins/Renderer/gl_rsurf.cpp @@ -995,7 +995,7 @@ void R_DrawDecals(cl_entity_t *ent) if (CL_IsDevOverviewMode()) return; - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return; if (g_iEngineType == ENGINE_SVENGINE) diff --git a/Plugins/Renderer/gl_shadow.cpp b/Plugins/Renderer/gl_shadow.cpp index 81f72e13..9b69eb5e 100644 --- a/Plugins/Renderer/gl_shadow.cpp +++ b/Plugins/Renderer/gl_shadow.cpp @@ -233,10 +233,10 @@ void R_ShutdownShadow(void) bool R_ShouldRenderShadow(void) { - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return false; - if (r_draw_reflectview) + if (R_IsRenderingWaterView()) return false; if (R_IsRenderingPortal()) @@ -395,20 +395,11 @@ void R_RenderShadowScene(void) glViewport(0, 0, r_shadow_texture.size, r_shadow_texture.size); vec4_t vecClearColor = { -99999, -99999, -99999, 1 }; + GL_ClearColorDepthStencil(vecClearColor, 0, STENCIL_MASK_SKY, STENCIL_MASK_ALL); - if (glNamedBufferSubData) - { - glNamedBufferSubData(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, viewMatrix), sizeof(mat4), shadow_mvmatrix[i]); - glNamedBufferSubData(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, projMatrix), sizeof(mat4), shadow_projmatrix[i]); - } - else - { - glBindBuffer(GL_UNIFORM_BUFFER, r_wsurf.hSceneUBO); - glBufferSubData(GL_UNIFORM_BUFFER, offsetof(scene_ubo_t, viewMatrix), sizeof(mat4), shadow_mvmatrix[i]); - glBufferSubData(GL_UNIFORM_BUFFER, offsetof(scene_ubo_t, projMatrix), sizeof(mat4), shadow_projmatrix[i]); - glBindBuffer(GL_UNIFORM_BUFFER, 0); - } + GL_UploadSubDataToUBO(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, viewMatrix), sizeof(mat4), shadow_mvmatrix[i]); + GL_UploadSubDataToUBO(r_wsurf.hSceneUBO, offsetof(scene_ubo_t, projMatrix), sizeof(mat4), shadow_projmatrix[i]); cl_entity_t *backup_curentity = (*currententity); @@ -502,16 +493,18 @@ void R_RenderShadowDynamicLights(void) (*r_refdef.viewangles)[1] = angle[1]; (*r_refdef.viewangles)[2] = angle[2]; - if (gEngfuncs.GetLocalPlayer()->model) + auto pLocalPlayer = gEngfuncs.GetLocalPlayer(); + + if (pLocalPlayer->model) { - auto save_localplayer_model = gEngfuncs.GetLocalPlayer()->model; + auto save_localplayer_model = pLocalPlayer->model; //This stops local player from being rendered - gEngfuncs.GetLocalPlayer()->model = NULL; + pLocalPlayer->model = NULL; R_RenderScene(); - gEngfuncs.GetLocalPlayer()->model = save_localplayer_model; + pLocalPlayer->model = save_localplayer_model; } else { diff --git a/Plugins/Renderer/gl_sprite.cpp b/Plugins/Renderer/gl_sprite.cpp index d74b8295..6de40abc 100644 --- a/Plugins/Renderer/gl_sprite.cpp +++ b/Plugins/Renderer/gl_sprite.cpp @@ -713,7 +713,7 @@ void R_DrawSpriteModelInterpFrames(cl_entity_t* ent, msprite_t* pSprite, msprite void R_DrawSpriteModel(cl_entity_t *ent) { - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return; auto pSprite = (msprite_t *)ent->model->cache.data; diff --git a/Plugins/Renderer/gl_studio.cpp b/Plugins/Renderer/gl_studio.cpp index cdd70adf..0ccb70dd 100644 --- a/Plugins/Renderer/gl_studio.cpp +++ b/Plugins/Renderer/gl_studio.cpp @@ -130,7 +130,7 @@ bool R_StudioHasOutline() bool R_StudioHasHairShadow() { - return r_draw_hashair && r_draw_hasface && r_studio_hair_shadow->value > 0 && !r_draw_shadowcaster; + return r_draw_hashair && r_draw_hasface && r_studio_hair_shadow->value > 0 && !R_IsRenderingShadowView(); } void R_StudioClearAllBoneCaches() @@ -1859,16 +1859,7 @@ void R_StudioDrawVBOBegin(studio_vbo_t* VBOData) memcpy(StudioUBO.bonematrix, (*pbonetransform), sizeof(mat3x4) * 128); - if (glNamedBufferSubData) - { - glNamedBufferSubData(VBOData->hStudioUBO, 0, sizeof(StudioUBO), &StudioUBO); - } - else - { - glBindBuffer(GL_UNIFORM_BUFFER, VBOData->hStudioUBO); - glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(StudioUBO), &StudioUBO); - glBindBuffer(GL_UNIFORM_BUFFER, 0); - } + GL_UploadSubDataToUBO(r_wsurf.hSceneUBO, 0, sizeof(StudioUBO), &StudioUBO); glBindBufferBase(GL_UNIFORM_BUFFER, BINDING_POINT_STUDIO_UBO, VBOData->hStudioUBO); @@ -1893,7 +1884,7 @@ void R_StudioDrawVBOMesh_AnalyzePass( const int flags) { //Analysis pass - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) { } @@ -1949,7 +1940,7 @@ void R_StudioDrawVBOMesh_DrawPass( { program_state_t StudioProgramState = flags; - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) { StudioProgramState |= STUDIO_SHADOW_CASTER_ENABLED; } @@ -2651,7 +2642,7 @@ __forceinline void StudioRenderFinal_Template(CallType pfnRenderFinal, void* pth template __forceinline void StudioRenderModel_Template(CallType pfnRenderModel, CallType pfnRenderFinal, void* pthis = nullptr, int dummy = 0) { - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) { pfnRenderModel(pthis, dummy); return; diff --git a/Plugins/Renderer/gl_warp.cpp b/Plugins/Renderer/gl_warp.cpp index 9c018183..a3c86c6c 100644 --- a/Plugins/Renderer/gl_warp.cpp +++ b/Plugins/Renderer/gl_warp.cpp @@ -16,7 +16,7 @@ void R_DrawSkyBox(void) if (CL_IsDevOverviewMode()) return; - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return; if (!r_wsurf.vSkyboxTextureId[0]) diff --git a/Plugins/Renderer/gl_water.cpp b/Plugins/Renderer/gl_water.cpp index 43eb12d7..a99df87c 100644 --- a/Plugins/Renderer/gl_water.cpp +++ b/Plugins/Renderer/gl_water.cpp @@ -437,7 +437,7 @@ water_control_t *R_FindWaterControl(msurface_t *surf) void R_UpdateRippleTexture(water_vbo_t *VBOCache, int framecount) { - if (r_draw_reflectview) + if (R_IsRenderingWaterView()) return; #define RANDOM_BYTES_SIZE 256 @@ -699,6 +699,9 @@ void R_RenderReflectView(water_reflect_cache_t *ReflectCache) GL_SetCurrentSceneFBO(&s_BackBufferFBO); vec4_t vecClearColor = { ReflectCache->color.r / 255.0f, ReflectCache->color.g / 255.0f, ReflectCache->color.b / 255.0f, 0 }; + + GammaToLinear(vecClearColor); + GL_ClearColorDepthStencil(vecClearColor, 1, STENCIL_MASK_SKY, STENCIL_MASK_ALL); R_PushRefDef(); @@ -726,7 +729,10 @@ void R_RenderReflectView(water_reflect_cache_t *ReflectCache) auto saved_cl_waterlevel = *cl_waterlevel; *cl_waterlevel = 0; - + + auto saved_r_novis = r_novis->value; + r_novis->value = 1; + auto saved_r_drawentities = r_drawentities->value; if (g_CurrentReflectCache->level == WATER_LEVEL_REFLECT_ENTITY) @@ -741,6 +747,7 @@ void R_RenderReflectView(water_reflect_cache_t *ReflectCache) R_RenderScene(); r_drawentities->value = saved_r_drawentities; + r_novis->value = saved_r_novis; *cl_waterlevel = saved_cl_waterlevel; R_PopRefDef(); @@ -753,7 +760,7 @@ void R_RenderReflectView(water_reflect_cache_t *ReflectCache) void R_RenderWaterPass(void) { - if (r_draw_reflectview) + if (R_IsRenderingWaterView()) return; GL_BeginProfile(&Profile_RenderWaterPass); @@ -1298,10 +1305,10 @@ void R_DrawWaterVBO(water_vbo_t *WaterVBO, water_reflect_cache_t *ReflectCache, void R_DrawWaters(wsurf_vbo_leaf_t *vboleaf, cl_entity_t *ent) { - if (r_draw_reflectview) + if (R_IsRenderingWaterView()) return; - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return; if (!vboleaf->vWaterVBO.size()) diff --git a/Plugins/Renderer/gl_wsurf.cpp b/Plugins/Renderer/gl_wsurf.cpp index 03536bd5..eac9d2ee 100644 --- a/Plugins/Renderer/gl_wsurf.cpp +++ b/Plugins/Renderer/gl_wsurf.cpp @@ -1667,7 +1667,7 @@ void R_DrawWSurfVBOSolid(wsurf_vbo_leaf_t *vboleaf) WSurfProgramState |= WSURF_GBUFFER_ENABLED; } - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) { WSurfProgramState |= WSURF_SHADOW_CASTER_ENABLED; } @@ -1806,7 +1806,7 @@ void R_DrawWSurfVBOStatic(wsurf_vbo_leaf_t * vboleaf, bool bUseZPrePass) } } - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) { WSurfProgramState |= WSURF_SHADOW_CASTER_ENABLED; } @@ -1985,7 +1985,7 @@ void R_DrawWSurfVBOStatic(wsurf_vbo_leaf_t * vboleaf, bool bUseZPrePass) } } - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) { WSurfProgramState |= WSURF_SHADOW_CASTER_ENABLED; } @@ -2226,7 +2226,7 @@ void R_DrawWSurfVBOAnim(wsurf_vbo_leaf_t *vboleaf, bool bUseZPrePass) WSurfProgramState |= WSURF_OIT_BLEND_ENABLED; } - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) { WSurfProgramState |= WSURF_SHADOW_CASTER_ENABLED; } @@ -2257,7 +2257,7 @@ float R_ScrollSpeed(void) bool R_ShouldDrawZPrePass(void) { - if (r_draw_shadowcaster) + if (R_IsRenderingShadowView()) return false; return (r_wsurf_zprepass->value > 0) ? true : false; @@ -2271,16 +2271,7 @@ void R_DrawWSurfVBO(wsurf_vbo_t *modvbo, cl_entity_t *ent) memcpy(EntityUBO.color, r_entity_color, sizeof(vec4)); EntityUBO.scrollSpeed = R_ScrollSpeed(); - if (glNamedBufferSubData) - { - glNamedBufferSubData(modvbo->hEntityUBO, 0, sizeof(EntityUBO), &EntityUBO); - } - else - { - glBindBuffer(GL_UNIFORM_BUFFER, modvbo->hEntityUBO); - glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(EntityUBO), &EntityUBO); - glBindBuffer(GL_UNIFORM_BUFFER, 0); - } + GL_UploadSubDataToUBO(modvbo->hEntityUBO, 0, sizeof(EntityUBO), &EntityUBO); if (bUseBindless) { @@ -4075,6 +4066,10 @@ void R_SetupSceneUBO(void) { memcpy(SceneUBO.clipPlane, g_PortalClipPlane[0], sizeof(vec4_t)); } + else + { + memset(SceneUBO.clipPlane, 0, sizeof(vec4_t)); + } //Fog colors are converted to linear space before use. memcpy(SceneUBO.fogColor, r_fog_color, sizeof(vec4_t)); @@ -4123,16 +4118,7 @@ void R_SetupSceneUBO(void) SceneUBO.r_lightstylevalue[i / 4][i % 4] = d_lightstylevalue[i] * (1.0f / 264.0f); } - if (glNamedBufferSubData) - { - glNamedBufferSubData(r_wsurf.hSceneUBO, 0, sizeof(SceneUBO), &SceneUBO); - } - else - { - glBindBuffer(GL_UNIFORM_BUFFER, r_wsurf.hSceneUBO); - glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(SceneUBO), &SceneUBO); - glBindBuffer(GL_UNIFORM_BUFFER, 0); - } + GL_UploadSubDataToUBO(r_wsurf.hSceneUBO, 0, sizeof(SceneUBO), &SceneUBO); } void R_SetupDLightUBO(void) @@ -4168,16 +4154,7 @@ void R_SetupDLightUBO(void) DLightUBO.active_dlights[0] = r_wsurf.iLightmapLegacyDLights; - if (glNamedBufferSubData) - { - glNamedBufferSubData(r_wsurf.hDLightUBO, 0, sizeof(DLightUBO), &DLightUBO); - } - else - { - glBindBuffer(GL_UNIFORM_BUFFER, r_wsurf.hDLightUBO); - glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(DLightUBO), &DLightUBO); - glBindBuffer(GL_UNIFORM_BUFFER, 0); - } + GL_UploadSubDataToUBO(r_wsurf.hDLightUBO, 0, sizeof(DLightUBO), &DLightUBO); } /*