Skip to content

Commit

Permalink
Fix corrupted transparent objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jan 14, 2024
1 parent c7cbbc6 commit 528ea47
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Plugins/Renderer/gl_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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.
/*
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Renderer/gl_rmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
31 changes: 16 additions & 15 deletions Plugins/Renderer/gl_studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Plugins/Renderer/gl_studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 528ea47

Please sign in to comment.