From 48ba6f6176349e5cbf269cafe5055ae6ce3282d1 Mon Sep 17 00:00:00 2001 From: LAX1DUDE Date: Wed, 18 Jan 2023 04:46:49 -0800 Subject: [PATCH] Update #13 - Big FPS boost for most players The hotbar, chat, and debug overlays in the game have been optimized and now only require a fraction as much CPU/GPU usage to be displayed on screen --- client_version | 2 +- .../minecraft/client/gui/GuiIngame.edit.java | 105 +++++++++++++++++- .../client/gui/GuiOverlayDebug.edit.java | 68 +----------- .../client/renderer/EntityRenderer.edit.java | 63 +++++++++-- .../client/settings/GameSettings.edit.java | 2 +- .../eaglercraft/v1_8/EaglercraftVersion.java | 6 +- .../v1_8/opengl/EffectPipelineFXAA.java | 2 - .../v1_8/opengl/FixedFunctionShader.java | 2 +- .../v1_8/opengl/GameOverlayFramebuffer.java | 95 ++++++++++++++++ .../v1_8/opengl/InstancedFontRenderer.java | 5 - .../opengl/InstancedParticleRenderer.java | 7 -- .../v1_8/opengl/SpriteLevelMixer.java | 2 - .../assets/eagler/glsl/accel_font.fsh | 4 +- .../assets/eagler/glsl/accel_font.vsh | 10 +- .../assets/eagler/glsl/accel_particle.fsh | 6 +- .../assets/eagler/glsl/accel_particle.vsh | 14 +-- sources/resources/assets/eagler/glsl/core.fsh | 2 +- .../resources/assets/eagler/glsl/local.vsh | 2 +- .../assets/eagler/glsl/post_fxaa.fsh | 6 +- .../assets/eagler/glsl/texture_mix.fsh | 4 +- 20 files changed, 285 insertions(+), 122 deletions(-) create mode 100644 sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GameOverlayFramebuffer.java diff --git a/client_version b/client_version index 85c77cc..dd52d77 100644 --- a/client_version +++ b/client_version @@ -1 +1 @@ -u12 \ No newline at end of file +u13 \ No newline at end of file diff --git a/patches/minecraft/net/minecraft/client/gui/GuiIngame.edit.java b/patches/minecraft/net/minecraft/client/gui/GuiIngame.edit.java index a7c6e78..52fe734 100644 --- a/patches/minecraft/net/minecraft/client/gui/GuiIngame.edit.java +++ b/patches/minecraft/net/minecraft/client/gui/GuiIngame.edit.java @@ -14,17 +14,20 @@ + import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite; + -> CHANGE 3 : 6 @ 3 : 6 +> CHANGE 3 : 7 @ 3 : 6 ~ ~ import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager; +~ import net.lax1dude.eaglercraft.v1_8.opengl.OpenGlHelper; ~ import net.lax1dude.eaglercraft.v1_8.opengl.WorldRenderer; > DELETE 2 @ 2 : 11 > DELETE 2 @ 2 : 3 -> DELETE 1 @ 1 : 2 +> CHANGE 1 : 2 @ 1 : 2 + +~ import net.minecraft.client.renderer.entity.RenderManager; > CHANGE 32 : 33 @ 32 : 33 @@ -34,9 +37,15 @@ > DELETE 27 @ 27 : 28 -> CHANGE 95 : 96 @ 95 : 98 +> CHANGE 16 : 17 @ 16 : 21 -~ this.overlayDebug.renderDebugInfo(scaledresolution, partialTicks); +~ GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + +> DELETE 21 @ 21 : 30 + +> CHANGE 44 : 45 @ 44 : 47 + +~ this.overlayDebug.renderDebugInfo(scaledresolution); > INSERT 87 : 90 @ 87 @@ -44,7 +53,21 @@ + j -= 10; + } -> DELETE 166 @ 166 : 170 +> INSERT 19 : 30 @ 19 + ++ public void renderGameOverlayCrosshairs(int scaledResWidth, int scaledResHeight) { ++ if (this.showCrosshair()) { ++ GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); ++ this.mc.getTextureManager().bindTexture(icons); ++ GlStateManager.enableBlend(); ++ GlStateManager.tryBlendFuncSeparate(775, 769, 1, 0); ++ GlStateManager.enableAlpha(); ++ this.drawTexturedModalRect(scaledResWidth / 2 - 7, scaledResHeight / 2 - 7, 0, 0, 16, 16); ++ } ++ } ++ + +> DELETE 147 @ 147 : 151 > CHANGE 17 : 18 @ 17 : 18 @@ -54,10 +77,80 @@ ~ for (Score score1 : (List) arraylist1) { -> CHANGE 343 : 344 @ 343 : 344 +> INSERT 64 : 65 @ 64 + ++ this.mc.getTextureManager().bindTexture(icons); + +> CHANGE 224 : 225 @ 224 : 225 + +~ public void renderVignette(float parFloat1, int scaledWidth, int scaledHeight) { + +> CHANGE 29 : 32 @ 29 : 33 + +~ worldrenderer.pos(0.0D, (double) scaledHeight, -90.0D).tex(0.0D, 1.0D).endVertex(); +~ worldrenderer.pos((double) scaledWidth, scaledHeight, -90.0D).tex(1.0D, 1.0D).endVertex(); +~ worldrenderer.pos((double) scaledWidth, 0.0D, -90.0D).tex(1.0D, 0.0D).endVertex(); + +> CHANGE 21 : 22 @ 21 : 22 ~ EaglerTextureAtlasSprite textureatlassprite = this.mc.getBlockRendererDispatcher().getBlockModelShapes() > DELETE 57 @ 57 : 58 +> INSERT 60 : 113 @ 60 + ++ public void drawEaglerPlayerOverlay(int x, int y, float partialTicks) { ++ Entity e = mc.getRenderViewEntity(); ++ if (e != null && e instanceof EntityLivingBase) { ++ EntityLivingBase ent = (EntityLivingBase) e; ++ GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); ++ GlStateManager.enableDepth(); ++ GlStateManager.enableColorMaterial(); ++ GlStateManager.pushMatrix(); ++ GlStateManager.translate((float) x - 10, (float) y + 36, 50.0F); ++ GlStateManager.scale(-17.0F, 17.0F, 17.0F); ++ GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); ++ float f = ent.renderYawOffset; ++ float f1 = ent.rotationYaw; ++ float f2 = ent.prevRotationYaw; ++ float f3 = ent.prevRotationYawHead; ++ float f4 = ent.rotationYawHead; ++ float f5 = ent.prevRenderYawOffset; ++ GlStateManager.rotate(115.0F, 0.0F, 1.0F, 0.0F); ++ RenderHelper.enableStandardItemLighting(); ++ float f6 = ent.prevRenderYawOffset + (ent.renderYawOffset - ent.prevRenderYawOffset) * partialTicks; ++ ent.rotationYawHead -= f6; ++ ent.prevRotationYawHead -= f6; ++ ent.rotationYawHead *= 0.5f; ++ ent.prevRotationYawHead *= 0.5f; ++ ent.renderYawOffset = 0.0f; ++ ent.prevRenderYawOffset = 0.0f; ++ ent.prevRotationYaw = 0.0f; ++ ent.rotationYaw = 0.0f; ++ GlStateManager.rotate(-135.0F ++ - (ent.prevRotationYawHead + (ent.rotationYawHead - ent.prevRotationYawHead) * partialTicks) * 0.5F, ++ 0.0F, 1.0F, 0.0F); ++ GlStateManager.rotate(ent.rotationPitch * 0.2f, 1.0F, 0.0F, 0.0F); ++ RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); ++ rendermanager.setPlayerViewY(180.0F); ++ rendermanager.setRenderShadow(false); ++ rendermanager.renderEntityWithPosYaw(ent, 0.0D, 0.0D, 0.0D, 0.0F, partialTicks); ++ rendermanager.setRenderShadow(true); ++ ent.renderYawOffset = f; ++ ent.rotationYaw = f1; ++ ent.prevRotationYaw = f2; ++ ent.prevRotationYawHead = f3; ++ ent.rotationYawHead = f4; ++ ent.prevRenderYawOffset = f5; ++ GlStateManager.popMatrix(); ++ RenderHelper.disableStandardItemLighting(); ++ GlStateManager.disableDepth(); ++ GlStateManager.disableRescaleNormal(); ++ GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); ++ GlStateManager.disableTexture2D(); ++ GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); ++ } ++ } ++ + > EOF diff --git a/patches/minecraft/net/minecraft/client/gui/GuiOverlayDebug.edit.java b/patches/minecraft/net/minecraft/client/gui/GuiOverlayDebug.edit.java index 188eaa5..248bef6 100644 --- a/patches/minecraft/net/minecraft/client/gui/GuiOverlayDebug.edit.java +++ b/patches/minecraft/net/minecraft/client/gui/GuiOverlayDebug.edit.java @@ -50,13 +50,12 @@ > DELETE 1 @ 1 : 3 -> CHANGE 10 : 13 @ 10 : 11 +> INSERT 11 : 13 @ 11 -~ public void renderDebugInfo(ScaledResolution scaledResolutionIn, float partialTicks) { -~ int ww = scaledResolutionIn.getScaledWidth(); -~ int hh = scaledResolutionIn.getScaledHeight(); ++ int ww = scaledResolutionIn.getScaledWidth(); ++ int hh = scaledResolutionIn.getScaledHeight(); -> CHANGE 1 : 24 @ 1 : 7 +> CHANGE 1 : 20 @ 1 : 7 ~ if (this.mc.gameSettings.showDebugInfo) { ~ GlStateManager.pushMatrix(); @@ -77,10 +76,6 @@ ~ if (this.mc.gameSettings.hudCoords) { ~ drawXYZ(2, i); ~ } -~ -~ if (this.mc.gameSettings.hudPlayer) { -~ drawPlayer(ww - 3, 3, partialTicks); -~ } > INSERT 2 : 26 @ 2 @@ -109,7 +104,7 @@ + } + -> INSERT 3 : 195 @ 3 +> INSERT 3 : 142 @ 3 + private void drawFPS(int x, int y) { + this.fontRenderer.drawStringWithShadow(this.mc.renderGlobal.getDebugInfoShort(), x, y, 0xFFFFFF); @@ -246,59 +241,6 @@ + this.fontRenderer.drawStringWithShadow(lightString + " " + tempString, x, y - 8, 0xFFFFFF); + } + -+ private void drawPlayer(int x, int y, float partialTicks) { -+ Entity e = mc.getRenderViewEntity(); -+ if (e != null && e instanceof EntityLivingBase) { -+ EntityLivingBase ent = (EntityLivingBase) e; -+ GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); -+ GlStateManager.enableDepth(); -+ GlStateManager.enableColorMaterial(); -+ GlStateManager.pushMatrix(); -+ GlStateManager.translate((float) x - 10, (float) y + 36, 50.0F); -+ GlStateManager.scale(-17.0F, 17.0F, 17.0F); -+ GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); -+ float f = ent.renderYawOffset; -+ float f1 = ent.rotationYaw; -+ float f2 = ent.prevRotationYaw; -+ float f3 = ent.prevRotationYawHead; -+ float f4 = ent.rotationYawHead; -+ float f5 = ent.prevRenderYawOffset; -+ GlStateManager.rotate(115.0F, 0.0F, 1.0F, 0.0F); -+ RenderHelper.enableStandardItemLighting(); -+ float f6 = ent.prevRenderYawOffset + (ent.renderYawOffset - ent.prevRenderYawOffset) * partialTicks; -+ ent.rotationYawHead -= f6; -+ ent.prevRotationYawHead -= f6; -+ ent.rotationYawHead *= 0.5f; -+ ent.prevRotationYawHead *= 0.5f; -+ ent.renderYawOffset = 0.0f; -+ ent.prevRenderYawOffset = 0.0f; -+ ent.prevRotationYaw = 0.0f; -+ ent.rotationYaw = 0.0f; -+ GlStateManager.rotate(-135.0F -+ - (ent.prevRotationYawHead + (ent.rotationYawHead - ent.prevRotationYawHead) * partialTicks) * 0.5F, -+ 0.0F, 1.0F, 0.0F); -+ GlStateManager.rotate(ent.rotationPitch * 0.2f, 1.0F, 0.0F, 0.0F); -+ RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); -+ rendermanager.setPlayerViewY(180.0F); -+ rendermanager.setRenderShadow(false); -+ rendermanager.renderEntityWithPosYaw(ent, 0.0D, 0.0D, 0.0D, 0.0F, partialTicks); -+ rendermanager.setRenderShadow(true); -+ ent.renderYawOffset = f; -+ ent.rotationYaw = f1; -+ ent.prevRotationYaw = f2; -+ ent.prevRotationYawHead = f3; -+ ent.rotationYawHead = f4; -+ ent.prevRenderYawOffset = f5; -+ GlStateManager.popMatrix(); -+ RenderHelper.disableStandardItemLighting(); -+ GlStateManager.disableDepth(); -+ GlStateManager.disableRescaleNormal(); -+ GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); -+ GlStateManager.disableTexture2D(); -+ GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); -+ } -+ } -+ + private void drawHideHUD(int x, int y, int fade) { + drawCenteredString(fontRenderer, I18n.format("options.hud.note"), x, y, 0xEECC00 | (fade << 24)); + } diff --git a/patches/minecraft/net/minecraft/client/renderer/EntityRenderer.edit.java b/patches/minecraft/net/minecraft/client/renderer/EntityRenderer.edit.java index 8a05b20..50315d1 100644 --- a/patches/minecraft/net/minecraft/client/renderer/EntityRenderer.edit.java +++ b/patches/minecraft/net/minecraft/client/renderer/EntityRenderer.edit.java @@ -14,7 +14,7 @@ ~ import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom; ~ import net.lax1dude.eaglercraft.v1_8.HString; -> INSERT 1 : 14 @ 1 +> INSERT 1 : 15 @ 1 + + import com.google.common.base.Predicate; @@ -26,6 +26,7 @@ + import net.lax1dude.eaglercraft.v1_8.log4j.Logger; + import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU; + import net.lax1dude.eaglercraft.v1_8.opengl.EffectPipelineFXAA; ++ import net.lax1dude.eaglercraft.v1_8.opengl.GameOverlayFramebuffer; + import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager; + import net.lax1dude.eaglercraft.v1_8.opengl.OpenGlHelper; + import net.lax1dude.eaglercraft.v1_8.opengl.WorldRenderer; @@ -42,9 +43,17 @@ ~ private EaglercraftRandom random = new EaglercraftRandom(); -> DELETE 43 @ 43 : 44 +> DELETE 43 @ 43 : 61 -> DELETE 30 @ 30 : 31 +> INSERT 1 : 2 @ 1 + ++ private GameOverlayFramebuffer overlayFramebuffer; + +> DELETE 2 @ 2 : 4 + +> CHANGE 8 : 9 @ 8 : 9 + +~ this.overlayFramebuffer = new GameOverlayFramebuffer(); > INSERT 1 : 10 @ 1 @@ -64,13 +73,13 @@ > DELETE 3 @ 3 : 9 -> DELETE 7 @ 7 : 22 +> DELETE 3 @ 3 : 4 > DELETE 3 @ 3 : 18 -> CHANGE 3 : 4 @ 3 : 18 +> DELETE 3 @ 3 : 18 -~ this.useShader = false; +> DELETE 3 @ 3 : 18 > DELETE 3 @ 3 : 14 @@ -129,7 +138,47 @@ > DELETE 39 @ 39 : 52 -> CHANGE 28 : 29 @ 28 : 29 +> CHANGE 4 : 41 @ 4 : 5 + +~ long framebufferAge = this.overlayFramebuffer.getAge(); +~ if (framebufferAge == -1l || framebufferAge > (Minecraft.getDebugFPS() < 25 ? 125l : 75l)) { +~ this.overlayFramebuffer.beginRender(mc.displayWidth, mc.displayHeight); +~ GlStateManager.colorMask(true, true, true, true); +~ GlStateManager.clearColor(0.0f, 0.0f, 0.0f, 0.0f); +~ GlStateManager.clear(16640); +~ this.mc.ingameGUI.renderGameOverlay(parFloat1); +~ this.overlayFramebuffer.endRender(); +~ } +~ this.setupOverlayRendering(); +~ GlStateManager.enableBlend(); +~ if (Minecraft.isFancyGraphicsEnabled()) { +~ this.mc.ingameGUI.renderVignette(parFloat1, l, i1); +~ } +~ this.mc.ingameGUI.renderGameOverlayCrosshairs(l, i1); +~ GlStateManager.bindTexture(this.overlayFramebuffer.getTexture()); +~ GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); +~ GlStateManager.enableBlend(); +~ GlStateManager.blendFunc(770, 771); +~ GlStateManager.disableAlpha(); +~ GlStateManager.disableDepth(); +~ GlStateManager.depthMask(false); +~ Tessellator tessellator = Tessellator.getInstance(); +~ WorldRenderer worldrenderer = tessellator.getWorldRenderer(); +~ worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); +~ worldrenderer.pos(0.0D, (double) i1, -90.0D).tex(0.0D, 0.0D).endVertex(); +~ worldrenderer.pos((double) l, (double) i1, -90.0D).tex(1.0D, 0.0D).endVertex(); +~ worldrenderer.pos((double) l, 0.0D, -90.0D).tex(1.0D, 1.0D).endVertex(); +~ worldrenderer.pos(0.0D, 0.0D, -90.0D).tex(0.0D, 1.0D).endVertex(); +~ tessellator.draw(); +~ GlStateManager.depthMask(true); +~ GlStateManager.enableDepth(); +~ GlStateManager.enableAlpha(); +~ GlStateManager.disableBlend(); +~ if (this.mc.gameSettings.hudPlayer) { // give the player model HUD good fps +~ this.mc.ingameGUI.drawEaglerPlayerOverlay(l - 3, 3, parFloat1); +~ } + +> CHANGE 23 : 24 @ 23 : 24 ~ return EntityRenderer.this.mc.currentScreen.getClass().getName(); diff --git a/patches/minecraft/net/minecraft/client/settings/GameSettings.edit.java b/patches/minecraft/net/minecraft/client/settings/GameSettings.edit.java index 19bb493..f400289 100644 --- a/patches/minecraft/net/minecraft/client/settings/GameSettings.edit.java +++ b/patches/minecraft/net/minecraft/client/settings/GameSettings.edit.java @@ -77,7 +77,7 @@ + public boolean hudFps = true; + public boolean hudCoords = true; -+ public boolean hudPlayer = true; ++ public boolean hudPlayer = false; + public boolean hudWorld = false; + public boolean hudStats = false; + public boolean hud24h = false; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java index b2af499..2a8fe97 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java @@ -8,7 +8,7 @@ public class EaglercraftVersion { /// Customize these to fit your fork: public static final String projectForkName = "EaglercraftX"; - public static final String projectForkVersion = "u12"; + public static final String projectForkVersion = "u13"; public static final String projectForkVendor = "lax1dude"; public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; @@ -23,7 +23,7 @@ public class EaglercraftVersion { public static final String projectOriginName = "EaglercraftX"; public static final String projectOriginAuthor = "lax1dude"; public static final String projectOriginRevision = "1.8"; - public static final String projectOriginVersion = "u12"; + public static final String projectOriginVersion = "u13"; public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; @@ -33,7 +33,7 @@ public class EaglercraftVersion { public static final String mainMenuStringA = "Minecraft 1.8.8"; public static final String mainMenuStringB = projectOriginName + " " + projectOriginRevision + "-" + projectOriginVersion; - public static final String mainMenuStringC = "Rewritten by " + projectOriginAuthor; + public static final String mainMenuStringC = null; public static final String mainMenuStringD = "Resources Copyright Mojang AB"; public static final String mainMenuStringE = projectForkName + " " + projectForkVersion; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EffectPipelineFXAA.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EffectPipelineFXAA.java index 7d507a9..d466365 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EffectPipelineFXAA.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EffectPipelineFXAA.java @@ -78,8 +78,6 @@ public class EffectPipelineFXAA { _wglAttachShader(shaderProgram, SpriteLevelMixer.vshLocal); _wglAttachShader(shaderProgram, frag); - _wglBindAttribLocation(shaderProgram, 0, "a_position2f"); - _wglLinkProgram(shaderProgram); _wglDetachShader(shaderProgram, SpriteLevelMixer.vshLocal); diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/FixedFunctionShader.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/FixedFunctionShader.java index ca800a5..c990efe 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/FixedFunctionShader.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/FixedFunctionShader.java @@ -22,7 +22,7 @@ class FixedFunctionShader { static final String FILENAME_FSH = "/assets/eagler/glsl/core.fsh"; static final String PRECISION_INT = "lowp"; - static final String PRECISION_FLOAT = "highp"; + static final String PRECISION_FLOAT = "mediump"; static final String PRECISION_SAMPLER = "lowp"; static final String MACRO_ATTRIB_TEXTURE = "COMPILE_TEXTURE_ATTRIB"; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GameOverlayFramebuffer.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GameOverlayFramebuffer.java new file mode 100644 index 0000000..95cd90c --- /dev/null +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GameOverlayFramebuffer.java @@ -0,0 +1,95 @@ +package net.lax1dude.eaglercraft.v1_8.opengl; + +import net.lax1dude.eaglercraft.v1_8.internal.IFramebufferGL; +import net.lax1dude.eaglercraft.v1_8.internal.IRenderbufferGL; +import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer; + +import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*; +import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*; + +/** + * Copyright (c) 2023 LAX1DUDE. All Rights Reserved. + * + * WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES + * NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED + * TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE + * SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR. + * + * NOT FOR COMMERCIAL OR MALICIOUS USE + * + * (please read the 'LICENSE' file this repo's root directory for more info) + * + */ +public class GameOverlayFramebuffer { + + private static final int _GL_FRAMEBUFFER = 0x8D40; + private static final int _GL_RENDERBUFFER = 0x8D41; + private static final int _GL_COLOR_ATTACHMENT0 = 0x8CE0; + private static final int _GL_DEPTH_ATTACHMENT = 0x8D00; + private static final int _GL_DEPTH_COMPONENT16 = 0x81A5; + + private long age = -1l; + + private int currentWidth = -1; + private int currentHeight = -1; + + private IFramebufferGL framebuffer = null; + private IRenderbufferGL depthBuffer = null; + + private int framebufferColor = -1; + + public void beginRender(int width, int height) { + if(framebuffer == null) { + framebuffer = _wglCreateFramebuffer(); + depthBuffer = _wglCreateRenderbuffer(); + framebufferColor = GlStateManager.generateTexture(); + _wglBindFramebuffer(_GL_FRAMEBUFFER, framebuffer); + GlStateManager.bindTexture(framebufferColor); + _wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + _wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + _wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + _wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + _wglFramebufferTexture2D(_GL_FRAMEBUFFER, _GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, EaglercraftGPU.getNativeTexture(framebufferColor), 0); + _wglBindRenderbuffer(_GL_RENDERBUFFER, depthBuffer); + _wglFramebufferRenderbuffer(_GL_FRAMEBUFFER, _GL_DEPTH_ATTACHMENT, _GL_RENDERBUFFER, depthBuffer); + } + + if(currentWidth != width || currentHeight != height) { + currentWidth = width; + currentHeight = height; + GlStateManager.bindTexture(framebufferColor); + _wglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer)null); + _wglBindRenderbuffer(_GL_RENDERBUFFER, depthBuffer); + _wglRenderbufferStorage(_GL_RENDERBUFFER, _GL_DEPTH_COMPONENT16, width, height); + } + + _wglBindFramebuffer(_GL_FRAMEBUFFER, framebuffer); + } + + public void endRender() { + _wglBindFramebuffer(_GL_FRAMEBUFFER, null); + age = System.currentTimeMillis(); + } + + public long getAge() { + return age == -1l ? -1l : (System.currentTimeMillis() - age); + } + + public int getTexture() { + return framebufferColor; + } + + public void destroy() { + if(framebuffer != null) { + _wglDeleteFramebuffer(framebuffer); + _wglDeleteRenderbuffer(depthBuffer); + GlStateManager.deleteTexture(framebufferColor); + framebuffer = null; + depthBuffer = null; + framebufferColor = -1; + age = -1l; + _wglBindFramebuffer(_GL_FRAMEBUFFER, null); + } + } + +} diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/InstancedFontRenderer.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/InstancedFontRenderer.java index 2410f06..2effd2d 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/InstancedFontRenderer.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/InstancedFontRenderer.java @@ -124,11 +124,6 @@ public class InstancedFontRenderer { _wglAttachShader(shaderProgram, vert); _wglAttachShader(shaderProgram, frag); - _wglBindAttribLocation(shaderProgram, 0, "a_position2f"); - _wglBindAttribLocation(shaderProgram, 1, "c_position2i"); - _wglBindAttribLocation(shaderProgram, 2, "c_coords2i"); - _wglBindAttribLocation(shaderProgram, 3, "c_color4f"); - _wglLinkProgram(shaderProgram); _wglDetachShader(shaderProgram, vert); diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/InstancedParticleRenderer.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/InstancedParticleRenderer.java index d8ddff1..59d23b2 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/InstancedParticleRenderer.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/InstancedParticleRenderer.java @@ -125,13 +125,6 @@ public class InstancedParticleRenderer { _wglAttachShader(shaderProgram, vert); _wglAttachShader(shaderProgram, frag); - _wglBindAttribLocation(shaderProgram, 0, "a_position2f"); - _wglBindAttribLocation(shaderProgram, 1, "p_position3f"); - _wglBindAttribLocation(shaderProgram, 2, "p_texCoords2i"); - _wglBindAttribLocation(shaderProgram, 3, "p_lightMap2f"); - _wglBindAttribLocation(shaderProgram, 4, "p_particleSize_texCoordsSize_2i"); - _wglBindAttribLocation(shaderProgram, 5, "p_color4f"); - _wglLinkProgram(shaderProgram); _wglDetachShader(shaderProgram, vert); diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/SpriteLevelMixer.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/SpriteLevelMixer.java index 81c1059..ca98228 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/SpriteLevelMixer.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/SpriteLevelMixer.java @@ -115,8 +115,6 @@ public class SpriteLevelMixer { _wglAttachShader(shaderProgram, vshLocal); _wglAttachShader(shaderProgram, frag); - _wglBindAttribLocation(shaderProgram, 0, "a_position2f"); - _wglLinkProgram(shaderProgram); _wglDetachShader(shaderProgram, vshLocal); diff --git a/sources/resources/assets/eagler/glsl/accel_font.fsh b/sources/resources/assets/eagler/glsl/accel_font.fsh index df3d379..6fe1e21 100644 --- a/sources/resources/assets/eagler/glsl/accel_font.fsh +++ b/sources/resources/assets/eagler/glsl/accel_font.fsh @@ -15,13 +15,13 @@ */ precision lowp int; -precision highp float; +precision lowp float; precision lowp sampler2D; in vec2 v_texCoord2f; in vec4 v_color4f; -out vec4 output4f; +layout(location = 0) out vec4 output4f; uniform sampler2D u_inputTexture; uniform vec4 u_colorBias4f; diff --git a/sources/resources/assets/eagler/glsl/accel_font.vsh b/sources/resources/assets/eagler/glsl/accel_font.vsh index f660f00..5c31fe7 100644 --- a/sources/resources/assets/eagler/glsl/accel_font.vsh +++ b/sources/resources/assets/eagler/glsl/accel_font.vsh @@ -15,14 +15,14 @@ */ precision lowp int; -precision highp float; +precision lowp float; precision lowp sampler2D; -in vec3 a_position3f; +layout(location = 0) in vec3 a_position3f; -in vec2 c_position2i; -in vec2 c_coords2i; -in vec4 c_color4f; +layout(location = 1) in vec2 c_position2i; +layout(location = 2) in vec2 c_coords2i; +layout(location = 3) in vec4 c_color4f; out vec2 v_texCoord2f; out vec4 v_color4f; diff --git a/sources/resources/assets/eagler/glsl/accel_particle.fsh b/sources/resources/assets/eagler/glsl/accel_particle.fsh index d26e258..3a92266 100644 --- a/sources/resources/assets/eagler/glsl/accel_particle.fsh +++ b/sources/resources/assets/eagler/glsl/accel_particle.fsh @@ -15,13 +15,13 @@ */ precision lowp int; -precision highp float; -precision highp sampler2D; +precision lowp float; +precision lowp sampler2D; in vec2 v_texCoord2f; in vec4 v_color4f; -out vec4 output4f; +layout(location = 0) out vec4 output4f; uniform sampler2D u_inputTexture; diff --git a/sources/resources/assets/eagler/glsl/accel_particle.vsh b/sources/resources/assets/eagler/glsl/accel_particle.vsh index 152736e..ce714bb 100644 --- a/sources/resources/assets/eagler/glsl/accel_particle.vsh +++ b/sources/resources/assets/eagler/glsl/accel_particle.vsh @@ -15,16 +15,16 @@ */ precision lowp int; -precision highp float; +precision lowp float; precision lowp sampler2D; -in vec2 a_position2f; +layout(location = 0) in vec2 a_position2f; -in vec3 p_position3f; -in vec2 p_texCoords2i; -in vec2 p_lightMap2f; -in vec2 p_particleSize_texCoordsSize_2i; -in vec4 p_color4f; +layout(location = 1) in vec3 p_position3f; +layout(location = 2) in vec2 p_texCoords2i; +layout(location = 3) in vec2 p_lightMap2f; +layout(location = 4) in vec2 p_particleSize_texCoordsSize_2i; +layout(location = 5) in vec4 p_color4f; out vec2 v_texCoord2f; out vec4 v_color4f; diff --git a/sources/resources/assets/eagler/glsl/core.fsh b/sources/resources/assets/eagler/glsl/core.fsh index 3ab7622..b491e06 100644 --- a/sources/resources/assets/eagler/glsl/core.fsh +++ b/sources/resources/assets/eagler/glsl/core.fsh @@ -87,7 +87,7 @@ uniform mat4 u_textureMat4f01; uniform vec2 u_textureAnisotropicFix; #endif -out vec4 output4f; +layout(location = 0) out vec4 output4f; void main() { diff --git a/sources/resources/assets/eagler/glsl/local.vsh b/sources/resources/assets/eagler/glsl/local.vsh index d52cb5a..6cb7523 100644 --- a/sources/resources/assets/eagler/glsl/local.vsh +++ b/sources/resources/assets/eagler/glsl/local.vsh @@ -18,7 +18,7 @@ precision lowp int; precision lowp float; precision lowp sampler2D; -in vec2 a_position2f; +layout(location = 0) in vec2 a_position2f; out vec2 v_position2f; diff --git a/sources/resources/assets/eagler/glsl/post_fxaa.fsh b/sources/resources/assets/eagler/glsl/post_fxaa.fsh index 03e562e..a3628a9 100644 --- a/sources/resources/assets/eagler/glsl/post_fxaa.fsh +++ b/sources/resources/assets/eagler/glsl/post_fxaa.fsh @@ -47,12 +47,12 @@ */ precision lowp int; -precision highp float; -precision highp sampler2D; +precision mediump float; +precision lowp sampler2D; in vec2 v_position2f; -out vec4 output4f; +layout(location = 0) out vec4 output4f; uniform sampler2D u_screenTexture; uniform vec2 u_screenSize2f; diff --git a/sources/resources/assets/eagler/glsl/texture_mix.fsh b/sources/resources/assets/eagler/glsl/texture_mix.fsh index 1771754..523bc6b 100644 --- a/sources/resources/assets/eagler/glsl/texture_mix.fsh +++ b/sources/resources/assets/eagler/glsl/texture_mix.fsh @@ -15,12 +15,12 @@ */ precision lowp int; -precision highp float; +precision lowp float; precision lowp sampler2D; in vec2 v_position2f; -out vec4 output4f; +layout(location = 0) out vec4 output4f; uniform sampler2D u_inputTexture; uniform float u_textureLod1f;