From 9680753f5e5d81476447c454e49bf899a6f786e2 Mon Sep 17 00:00:00 2001 From: MatthewBeshay <92357869+MatthewBeshay@users.noreply.github.com> Date: Sat, 28 Mar 2026 18:00:47 +1100 Subject: [PATCH] fix(linux): restore UI GL state handoff for core renderer --- .../Common/UI/UIScene_EnchantingMenu.cpp | 2 - .../Platform/Linux/Iggy/gdraw/gdraw.c | 3 +- Minecraft.Client/Platform/Linux/LinuxGL.cpp | 13 ++++- .../Platform/Linux/Linux_UIController.cpp | 56 ++++++++----------- Minecraft.Client/Rendering/FrustumData.cpp | 2 +- Minecraft.Client/Rendering/GameRenderer.cpp | 1 + Minecraft.Client/Rendering/LevelRenderer.cpp | 8 +-- 7 files changed, 43 insertions(+), 42 deletions(-) diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp index 78fca71e5..0affa127f 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp @@ -5,8 +5,6 @@ #include "../../Minecraft.Client/Minecraft.h" #include "UIScene_EnchantingMenu.h" -#include - UIScene_EnchantingMenu::UIScene_EnchantingMenu(int iPad, void* _initData, UILayer* parentLayer) : UIScene_AbstractContainerMenu(iPad, parentLayer) { diff --git a/Minecraft.Client/Platform/Linux/Iggy/gdraw/gdraw.c b/Minecraft.Client/Platform/Linux/Iggy/gdraw/gdraw.c index 0c2cea4d5..fc037dcbf 100644 --- a/Minecraft.Client/Platform/Linux/Iggy/gdraw/gdraw.c +++ b/Minecraft.Client/Platform/Linux/Iggy/gdraw/gdraw.c @@ -776,6 +776,7 @@ GDrawFunctions* gdraw_GL_CreateContext(S32 w, S32 h, S32 msaa_samples) { real_RenderingBegin = funcs->RenderingBegin; funcs->RenderingBegin = hooked_RenderingBegin; + funcs->ClearID = gdraw_ClearID; gdraw->tex_formats = tex_formats; gdraw->has_mapbuffer = true; @@ -815,4 +816,4 @@ void gdraw_GL_BeginCustomDraw_4J(IggyCustomDrawCallbackRegion* region, void gdraw_GL_CalculateCustomDraw_4J(IggyCustomDrawCallbackRegion* region, F32* matrix) { gdraw_GetObjectSpaceMatrix(matrix, region->o2w, gdraw->projection, 0.0f, 0); -} \ No newline at end of file +} diff --git a/Minecraft.Client/Platform/Linux/LinuxGL.cpp b/Minecraft.Client/Platform/Linux/LinuxGL.cpp index 1333b5114..a1d992ee3 100644 --- a/Minecraft.Client/Platform/Linux/LinuxGL.cpp +++ b/Minecraft.Client/Platform/Linux/LinuxGL.cpp @@ -28,6 +28,12 @@ #undef glActiveTexture // _4j suffix shit (todo: make ts better) +int glGenTextures() { + GLuint id = 0; + ::glGenTextures(1, &id); + return (int)id; +} + void glGenTextures_4J(IntBuffer* buf) { GLuint id = 0; ::glGenTextures(1, &id); @@ -35,6 +41,11 @@ void glGenTextures_4J(IntBuffer* buf) { buf->flip(); } +void glDeleteTextures(int id) { + GLuint uid = (GLuint)id; + ::glDeleteTextures(1, &uid); +} + void glDeleteTextures_4J(IntBuffer* buf) { if (buf && buf->limit() > 0) { int id = buf->get(0); @@ -218,4 +229,4 @@ void LinuxGLLogLightmapState(const char* stage, int textureId, unit1Enabled ? 1 : 0); } -#endif \ No newline at end of file +#endif diff --git a/Minecraft.Client/Platform/Linux/Linux_UIController.cpp b/Minecraft.Client/Platform/Linux/Linux_UIController.cpp index 5b6524c9f..e2c1c17c7 100644 --- a/Minecraft.Client/Platform/Linux/Linux_UIController.cpp +++ b/Minecraft.Client/Platform/Linux/Linux_UIController.cpp @@ -1,42 +1,35 @@ -// should we keep Linux_UIController.cpp?* #include "../../../Minecraft.World/Platform/stdafx.h" #include "Linux_UIController.h" -// Temp -#include "../../Minecraft.h" -#include "../../Textures/Textures.h" - // GDraw GL backend for Linux #include "Iggy/gdraw/gdraw.h" -#include "4J_Render.h" ConsoleUIController ui; static void restoreFixedFunctionStateAfterIggy() { - RenderManager.StateSetColour(1.0f, 1.0f, 1.0f, 1.0f); - RenderManager.StateSetAlphaTestEnable(true); - RenderManager.StateSetAlphaFunc(GL_GREATER, 0.1f); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.1f); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); - RenderManager.StateSetDepthTestEnable(true); - RenderManager.StateSetDepthFunc(GL_LEQUAL); - RenderManager.StateSetDepthMask(true); + glClientActiveTexture(GL_TEXTURE1); + glActiveTexture(GL_TEXTURE1); + glDisable(GL_TEXTURE_2D); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); - RenderManager.StateSetFaceCull(true); - RenderManager.StateSetActiveTexture(GL_TEXTURE1); - RenderManager.StateSetTextureEnable(false); - RenderManager.MatrixMode(GL_TEXTURE); - RenderManager.MatrixSetIdentity(); + glClientActiveTexture(GL_TEXTURE0); + glActiveTexture(GL_TEXTURE0); + glEnable(GL_TEXTURE_2D); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); - RenderManager.StateSetActiveTexture(GL_TEXTURE0); - RenderManager.StateSetTextureEnable(true); - RenderManager.MatrixMode(GL_TEXTURE); - - RenderManager.MatrixSetIdentity(); - RenderManager.MatrixMode(GL_MODELVIEW); - glDisable(GL_SCISSOR_TEST); // iggy is mean - RenderManager.Set_matrixDirty(); - Minecraft::GetInstance()->textures->clearLastBoundId(); - // 4jcraft: clears the last bound id, dumb fix but fine + glMatrixMode(GL_MODELVIEW); } void ConsoleUIController::init(S32 w, S32 h) { @@ -69,11 +62,8 @@ void ConsoleUIController::render() { if (!gdraw_funcs) return; gdraw_GL_SetTileOrigin(0, 0, 0); - if (!app.GetGameStarted()) { - glDisable(GL_SCISSOR_TEST); - glClearDepth(1.0); - glDepthMask(GL_TRUE); - glClear(GL_DEPTH_BUFFER_BIT); + if (!app.GetGameStarted() && gdraw_funcs->ClearID) { + gdraw_funcs->ClearID(); } // render @@ -144,4 +134,4 @@ void ConsoleUIController::shutdown() { gdraw_funcs = nullptr; } #endif -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/FrustumData.cpp b/Minecraft.Client/Rendering/FrustumData.cpp index 098243a75..140fa4772 100644 --- a/Minecraft.Client/Rendering/FrustumData.cpp +++ b/Minecraft.Client/Rendering/FrustumData.cpp @@ -130,4 +130,4 @@ bool FrustumData::cubeInFrustum(double x1, double y1, double z1, double x2, bool FrustumData::isVisible(AABB* aabb) { return cubeInFrustum(aabb->x0, aabb->y0, aabb->z0, aabb->x1, aabb->y1, aabb->z1); -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/GameRenderer.cpp b/Minecraft.Client/Rendering/GameRenderer.cpp index 3e5763087..61171598e 100644 --- a/Minecraft.Client/Rendering/GameRenderer.cpp +++ b/Minecraft.Client/Rendering/GameRenderer.cpp @@ -1779,6 +1779,7 @@ void GameRenderer::renderSnowAndRain(float a) { #endif t->offset(0, 0, 0); t->end(); + } else { if (mode != 1) { if (mode >= 0) t->end(); diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index 9cf3dfdd3..627a46f47 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -2472,7 +2472,7 @@ void LevelRenderer::renderHitOutline(std::shared_ptr player, // 4J-PB - If Display HUD is false, don't render the hit outline if (app.GetGameSettings(iPad, eGameSetting_DisplayHUD) == 0) return; RenderManager.StateSetLightingEnable(false); - RenderManager.StateSetTextureEnable(false); + glDisable(GL_TEXTURE_2D); // draw hit outline RenderManager.StateSetColour(0.0f, 0.0f, 0.0f, 0.4f); @@ -2502,7 +2502,7 @@ void LevelRenderer::renderHitOutline(std::shared_ptr player, // restore glDisable(GL_POLYGON_OFFSET_LINE); RenderManager.StateSetColour(1.0f, 1.0f, 1.0f, 1.0f); - RenderManager.StateSetTextureEnable(true); + glEnable(GL_TEXTURE_2D); RenderManager.StateSetLightingEnable(true); } } @@ -2510,7 +2510,7 @@ void LevelRenderer::renderHitOutline(std::shared_ptr player, void LevelRenderer::render(AABB* b) { Tesselator* t = Tesselator::getInstance(); RenderManager.StateSetLightingEnable(false); - RenderManager.StateSetTextureEnable(false); + glDisable(GL_TEXTURE_2D); RenderManager.StateSetColour(0.0f, 0.0f, 0.0f, 0.4f); // prevent zfight @@ -2541,7 +2541,7 @@ void LevelRenderer::render(AABB* b) { t->end(); glDisable(GL_POLYGON_OFFSET_LINE); RenderManager.StateSetLightingEnable(true); - RenderManager.StateSetTextureEnable(true); + glEnable(GL_TEXTURE_2D); RenderManager.StateSetColour(1.0f, 1.0f, 1.0f, 1.0f); }