From 528ea470d3b856bda56fa79c37d3868f5cd950c9 Mon Sep 17 00:00:00 2001 From: hzqst <113660872@qq.com> Date: Sun, 14 Jan 2024 14:11:57 +0800 Subject: [PATCH] Fix corrupted transparent objects. --- Plugins/Renderer/gl_hooks.cpp | 4 ++-- Plugins/Renderer/gl_rmain.cpp | 4 ++-- Plugins/Renderer/gl_studio.cpp | 31 ++++++++++++++++--------------- Plugins/Renderer/gl_studio.h | 1 + 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Plugins/Renderer/gl_hooks.cpp b/Plugins/Renderer/gl_hooks.cpp index b58bbbe4..c2da2736 100644 --- a/Plugins/Renderer/gl_hooks.cpp +++ b/Plugins/Renderer/gl_hooks.cpp @@ -7490,7 +7490,7 @@ void R_UninstallHooksForEngineDLL(void) Uninstall_Hook(triapi_RenderMode); Uninstall_Hook(Draw_MiptexTexture); Uninstall_Hook(BuildGammaTable); - Uninstall_Hook(R_CullBox); + //Uninstall_Hook(R_CullBox); if (gPrivateFuncs.SDL_GL_SetAttribute) { @@ -7538,7 +7538,7 @@ void R_InstallHooks(void) Install_InlineHook(triapi_RenderMode); Install_InlineHook(Draw_MiptexTexture); Install_InlineHook(BuildGammaTable); - Install_InlineHook(R_CullBox); + //Install_InlineHook(R_CullBox); //OpenGL4.2 was forced by HL25 engine which might ruin the renderer features. /* diff --git a/Plugins/Renderer/gl_rmain.cpp b/Plugins/Renderer/gl_rmain.cpp index 3636837d..3285bd0c 100644 --- a/Plugins/Renderer/gl_rmain.cpp +++ b/Plugins/Renderer/gl_rmain.cpp @@ -480,8 +480,7 @@ void R_DrawParticles(void) glEnable(GL_ALPHA_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); program_state_t LegacySpriteProgramState = 0; @@ -2072,6 +2071,7 @@ void R_RenderView_SvEngine(int viewIdx) //This will switch to final framebuffer (RGBA8) //TODO: Why not using GL_BlitFrameBufferToFrameBufferColorOnly? R_BlendFinalBuffer(&s_BackBufferFBO, &s_FinalBufferFBO); + GL_SetCurrentSceneFBO(NULL); if (!(*r_refdef.onlyClientDraws)) R_PolyBlend(); diff --git a/Plugins/Renderer/gl_studio.cpp b/Plugins/Renderer/gl_studio.cpp index de1b3c79..6a4c50db 100644 --- a/Plugins/Renderer/gl_studio.cpp +++ b/Plugins/Renderer/gl_studio.cpp @@ -644,6 +644,9 @@ void R_UseStudioProgram(program_state_t state, studio_program_t* progOutput) if (state & STUDIO_REVERT_NORMAL_ENABLED) defs << "#define REVERT_NORMAL_ENABLED\n"; + if (state & STUDIO_STENCIL_TEXTURE_ENABLED) + defs << "#define STENCIL_TEXTURE_ENABLED\n"; + if (glewIsSupported("GL_NV_bindless_texture")) defs << "#define NV_BINDLESS_ENABLED\n"; @@ -1076,7 +1079,8 @@ const program_state_mapping_t s_StudioProgramStateName[] = { { STUDIO_PACKED_PARALLAXTEXTURE_ENABLED ,"STUDIO_PACKED_PARALLAXTEXTURE_ENABLED" }, { STUDIO_PACKED_SPECULARTEXTURE_ENABLED ,"STUDIO_PACKED_SPECULARTEXTURE_ENABLED" }, { STUDIO_ANIMATED_TEXTURE_ENABLED ,"STUDIO_ANIMATED_TEXTURE_ENABLED" }, -{ STUDIO_REVERT_NORMAL_ENABLED ,"STUDIO_REVERT_NORMAL_ENABLED" }, +{ STUDIO_REVERT_NORMAL_ENABLED ,"STUDIO_REVERT_NORMAL_ENABLED" }, +{ STUDIO_STENCIL_TEXTURE_ENABLED ,"STUDIO_STENCIL_TEXTURE_ENABLED" }, { STUDIO_NF_FLATSHADE ,"STUDIO_NF_FLATSHADE" }, { STUDIO_NF_CHROME ,"STUDIO_NF_CHROME" }, @@ -2040,9 +2044,11 @@ void R_StudioDrawVBOMesh_DrawPass( //Texture unit 6 = Stencil texture if (s_BackBufferFBO2.s_hBackBufferStencilView) { - glActiveTexture(GL_TEXTURE6); + glActiveTexture(GL_TEXTURE0 + STUDIO_RESERVED_TEXTURE_STENCIL); glBindTexture(GL_TEXTURE_2D, s_BackBufferFBO2.s_hBackBufferStencilView); glActiveTexture(GL_TEXTURE0); + + StudioProgramState |= STUDIO_STENCIL_TEXTURE_ENABLED; } } } @@ -2307,29 +2313,24 @@ void R_StudioDrawVBOMesh_DrawPass( glBindTexture(GL_TEXTURE_2D_ARRAY, 0); } + if (StudioProgramState & STUDIO_STENCIL_TEXTURE_ENABLED) + { + //Texture unit 6 = Stencil texture + glActiveTexture(GL_TEXTURE0 + STUDIO_RESERVED_TEXTURE_STENCIL); + glBindTexture(GL_TEXTURE_2D, 0); + } + glActiveTexture((*oldtarget)); //Restore states glDepthMask(GL_TRUE); glDisable(GL_BLEND); - glEnable(GL_CULL_FACE); if (r_draw_opaque) { GL_EndStencil(); } - - if (StudioProgramState & STUDIO_NF_CELSHADE_FACE) - { - //Texture unit 6 = Stencil texture - if (s_GBufferFBO.s_hBackBufferStencilView) - { - glActiveTexture(GL_TEXTURE0 + STUDIO_RESERVED_TEXTURE_STENCIL); - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE0); - } - } } void R_StudioDrawVBOMesh( @@ -2740,7 +2741,7 @@ __forceinline void StudioRenderModel_Template(CallType pfnRenderModel, CallType if (r_draw_gbuffer) GL_BindFrameBuffer(&s_GBufferFBO); else - GL_BindFrameBuffer(&s_BackBufferFBO); + GL_BindFrameBuffer(GL_GetCurrentSceneFBO()); } if ((*currententity)->curstate.renderfx == kRenderFxGlowShell) diff --git a/Plugins/Renderer/gl_studio.h b/Plugins/Renderer/gl_studio.h index ba28256d..89bfa3ba 100644 --- a/Plugins/Renderer/gl_studio.h +++ b/Plugins/Renderer/gl_studio.h @@ -442,5 +442,6 @@ extern r_studio_interface_t **gpStudioInterface; #define STUDIO_PACKED_SPECULARTEXTURE_ENABLED 0x20000000000ull #define STUDIO_ANIMATED_TEXTURE_ENABLED 0x40000000000ull #define STUDIO_REVERT_NORMAL_ENABLED 0x80000000000ull +#define STUDIO_STENCIL_TEXTURE_ENABLED 0x100000000000ull #define STUDIO_PACKED_TEXTURE_ALLBITS (STUDIO_PACKED_DIFFUSETEXTURE_ENABLED | STUDIO_PACKED_NORMALTEXTURE_ENABLED | STUDIO_PACKED_PARALLAXTEXTURE_ENABLED | STUDIO_PACKED_SPECULARTEXTURE_ENABLED)