diff --git a/client_version b/client_version index 41915701..471a6eb2 100644 --- a/client_version +++ b/client_version @@ -1 +1 @@ -u52 \ No newline at end of file +u53 \ No newline at end of file diff --git a/patches/minecraft/net/minecraft/client/Minecraft.edit.java b/patches/minecraft/net/minecraft/client/Minecraft.edit.java index a85fdf85..e7005191 100644 --- a/patches/minecraft/net/minecraft/client/Minecraft.edit.java +++ b/patches/minecraft/net/minecraft/client/Minecraft.edit.java @@ -598,7 +598,7 @@ ~ GlStateManager.viewport(0, 0, this.displayWidth, this.displayHeight); ~ GlStateManager.clearColor(0.0f, 0.0f, 0.0f, 1.0f); -> DELETE 2 @ 2 : 4 +> DELETE 1 @ 1 : 4 > DELETE 5 @ 5 : 6 diff --git a/patches/minecraft/net/minecraft/client/renderer/entity/RenderFallingBlock.edit.java b/patches/minecraft/net/minecraft/client/renderer/entity/RenderFallingBlock.edit.java index 688c5d49..78c720b3 100644 --- a/patches/minecraft/net/minecraft/client/renderer/entity/RenderFallingBlock.edit.java +++ b/patches/minecraft/net/minecraft/client/renderer/entity/RenderFallingBlock.edit.java @@ -5,13 +5,12 @@ # Version: 1.0 # Author: lax1dude -> INSERT 2 : 7 @ 2 +> INSERT 2 : 6 @ 2 + import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager; + import net.lax1dude.eaglercraft.v1_8.opengl.VertexFormat; + import net.lax1dude.eaglercraft.v1_8.opengl.WorldRenderer; + import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.DeferredStateManager; -+ import net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights.DynamicLightsStateManager; > DELETE 4 @ 4 : 5 diff --git a/patches/minecraft/net/minecraft/crash/CrashReport.edit.java b/patches/minecraft/net/minecraft/crash/CrashReport.edit.java index 56319320..e3387ed7 100644 --- a/patches/minecraft/net/minecraft/crash/CrashReport.edit.java +++ b/patches/minecraft/net/minecraft/crash/CrashReport.edit.java @@ -89,7 +89,17 @@ ~ stackTrace.append("\tat ").append(s).append('\n'); ~ }); -> CHANGE 1 : 2 @ 1 : 12 +> CHANGE 1 : 8 @ 1 : 9 + +~ Throwable t = this.cause.getCause(); +~ while (t != null) { +~ stackTrace.append("Caused by: " + t.toString()).append('\n'); +~ EagRuntime.getStackTrace(t, (s) -> { +~ stackTrace.append("\tat ").append(s).append('\n'); +~ }); +~ t = t.getCause(); + +> CHANGE 2 : 3 @ 2 : 3 ~ return stackTrace.toString(); diff --git a/patches/resources/assets/minecraft/lang/en_US.edit.lang b/patches/resources/assets/minecraft/lang/en_US.edit.lang index 8cfb6304..59de5761 100644 --- a/patches/resources/assets/minecraft/lang/en_US.edit.lang +++ b/patches/resources/assets/minecraft/lang/en_US.edit.lang @@ -16,7 +16,7 @@ ~ eaglercraft.resourcePack.load.loading=Loading resource pack... ~ eaglercraft.resourcePack.load.deleting=Deleting resource pack... -> INSERT 1 : 247 @ 1 +> INSERT 1 : 243 @ 1 + eaglercraft.gui.exitKey=Use '%s' to close this screen! + eaglercraft.gui.exitKeyRetarded=Use Backtick (`) to close this screen! @@ -213,10 +213,6 @@ + eaglercraft.shaders.gui.option.SCREEN_SPACE_REFLECTIONS.desc.6=ON: enable raytracing (slower) + eaglercraft.shaders.gui.option.SCREEN_SPACE_REFLECTIONS.desc.7=OFF: disable raytracing (faster) + -+ eaglercraft.shaders.gui.option.LIGHT_SHAFTS.desc.0=Render god rays (light shafts) for sunlight and moonlight shadows -+ eaglercraft.shaders.gui.option.LIGHT_SHAFTS.desc.2=ON: render god rays (slower) -+ eaglercraft.shaders.gui.option.LIGHT_SHAFTS.desc.3=OFF: disable god rays (faster) -+ + eaglercraft.shaders.gui.option.POST_LENS_DISTORION.label=Lens Distort + + eaglercraft.shaders.gui.option.POST_LENS_DISTORION.desc.0=Renders chromatic abberation and lens distorion diff --git a/sources/lwjgl/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformOpenGL.java b/sources/lwjgl/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformOpenGL.java index 8a98382f..7e516be8 100644 --- a/sources/lwjgl/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformOpenGL.java +++ b/sources/lwjgl/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformOpenGL.java @@ -573,6 +573,10 @@ public class PlatformOpenGL { glDrawElements(mode, count, type, offset); } + public static void _wglDrawRangeElements(int mode, int start, int end, int count, int type, int offset) { + glDrawRangeElements(mode, start, end, count, type, offset); + } + public static void _wglDrawElementsInstanced(int mode, int count, int type, int offset, int instanced) { switch(instancingImpl) { case INSTANCE_IMPL_CORE: 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 ef38ad90..c645ce7b 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java @@ -10,7 +10,7 @@ public class EaglercraftVersion { /// Customize these to fit your fork: public static final String projectForkName = "EaglercraftX"; - public static final String projectForkVersion = "u52"; + public static final String projectForkVersion = "u53"; public static final String projectForkVendor = "lax1dude"; public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; @@ -20,20 +20,20 @@ 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 = "u52"; + public static final String projectOriginVersion = "u53"; public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace // EPK Version Identifier - public static final String EPKVersionIdentifier = "u52"; // Set to null to disable EPK version check + public static final String EPKVersionIdentifier = "u53"; // Set to null to disable EPK version check // Updating configuration public static final boolean enableUpdateService = true; public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client"; - public static final int updateBundlePackageVersionInt = 52; + public static final int updateBundlePackageVersionInt = 53; public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/mojang/authlib/GameProfile.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/mojang/authlib/GameProfile.java index 87c9bc3b..d5cbca74 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/mojang/authlib/GameProfile.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/mojang/authlib/GameProfile.java @@ -19,7 +19,6 @@ package net.lax1dude.eaglercraft.v1_8.mojang.authlib; import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; import com.google.common.collect.Multimap; import com.google.common.collect.MultimapBuilder; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/mojang/authlib/TexturesProperty.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/mojang/authlib/TexturesProperty.java index f26fd641..50797b04 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/mojang/authlib/TexturesProperty.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/mojang/authlib/TexturesProperty.java @@ -94,7 +94,7 @@ public class TexturesProperty { if(meta != null) { String modelStr = meta.optString("model"); if(modelStr != null && modelStr.equalsIgnoreCase("slim")) { - model = SkinModel.STEVE; + model = SkinModel.ALEX; } } } diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/DisplayList.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/DisplayList.java index 8e16c1c3..d411d80b 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/DisplayList.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/DisplayList.java @@ -26,7 +26,6 @@ class DisplayList { int attribs = -1; int mode = -1; int count = 0; - boolean bindQuad16 = false; - boolean bindQuad32 = false; + byte bindQuad = 0; } \ No newline at end of file diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EaglercraftGPU.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EaglercraftGPU.java index d933bff6..974a7019 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EaglercraftGPU.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EaglercraftGPU.java @@ -40,7 +40,7 @@ import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*; public class EaglercraftGPU { - static final GLObjectRecycler arrayBufferRecycler = new GLObjectRecycler(32) { + static final GLObjectRecycler arrayBufferRecycler = new GLObjectRecycler(256) { @Override protected IBufferGL create() { @@ -49,7 +49,14 @@ public class EaglercraftGPU { @Override protected void invalidate(IBufferGL object) { - // Don't bother + IBufferGL old = currentArrayBuffer; + if (old != object) { + _wglBindBuffer(GL_ARRAY_BUFFER, object); + } + _wglBufferData(GL_ARRAY_BUFFER, 0, GL_STATIC_DRAW); + if (old != object) { + _wglBindBuffer(GL_ARRAY_BUFFER, old); + } } @Override @@ -59,7 +66,7 @@ public class EaglercraftGPU { }; - static final GLObjectRecycler elementArrayBufferRecycler = new GLObjectRecycler(32) { + static final GLObjectRecycler elementArrayBufferRecycler = new GLObjectRecycler(256) { @Override protected IBufferGL create() { @@ -68,7 +75,22 @@ public class EaglercraftGPU { @Override protected void invalidate(IBufferGL object) { - // Don't bother + IVertexArrayGL oldArray = currentVertexArray; + boolean vao = !emulatedVAOs; + if (vao && vertexArrayCapable && oldArray != null) { + _wglBindVertexArray(null); + } + IBufferGL old = currentEmulatedVAOIndexBuffer; + if (vao || old != object) { + _wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object); + } + _wglBufferData(GL_ELEMENT_ARRAY_BUFFER, 0, GL_STATIC_DRAW); + if (!vao && old != object) { + _wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, old); + } + if (vao && vertexArrayCapable && oldArray != null) { + _wglBindVertexArray(oldArray); + } } @Override @@ -211,8 +233,7 @@ public class EaglercraftGPU { if(dp.vertexArray == null) { dp.vertexArray = createGLVertexArray(); - dp.bindQuad16 = false; - dp.bindQuad32 = false; + dp.bindQuad = 0; } if(dp.vertexBuffer == null) { dp.vertexBuffer = createGLArrayBuffer(); @@ -252,8 +273,7 @@ public class EaglercraftGPU { if(dp.vertexArray == null) { dp.vertexArray = createGLVertexArray(); - dp.bindQuad16 = false; - dp.bindQuad32 = false; + dp.bindQuad = 0; } if(dp.vertexBuffer == null) { dp.vertexBuffer = createGLArrayBuffer(); @@ -280,21 +300,19 @@ public class EaglercraftGPU { if(dp.mode == GL_QUADS) { int cnt = dp.count; if(cnt > quad16MaxVertices) { - if(!dp.bindQuad32) { - dp.bindQuad16 = false; - dp.bindQuad32 = true; + if(dp.bindQuad != 32) { + dp.bindQuad = 32; attachQuad32EmulationBuffer(cnt, true); }else { attachQuad32EmulationBuffer(cnt, false); } - p.drawElements(GL_TRIANGLES, (cnt >> 2) * 6, GL_UNSIGNED_INT, 0); + p.drawRangeElements(GL_TRIANGLES, 0, cnt - 1, (cnt >> 2) * 6, GL_UNSIGNED_INT, 0); }else { - if(!dp.bindQuad16) { - dp.bindQuad16 = true; - dp.bindQuad32 = false; + if(dp.bindQuad != 16) { + dp.bindQuad = 16; attachQuad16EmulationBuffer(true); } - p.drawElements(GL_TRIANGLES, (cnt >> 2) * 6, GL_UNSIGNED_SHORT, 0); + p.drawRangeElements(GL_TRIANGLES, 0, cnt - 1, (cnt >> 2) * 6, GL_UNSIGNED_SHORT, 0); } }else { p.drawArrays(dp.mode, 0, dp.count); @@ -560,6 +578,21 @@ public class EaglercraftGPU { _wglDrawElements(mode, count, type, offset); } + public static void drawRangeElements(int mode, int start, int end, int count, int type, int offset) { + if(emulatedVAOs) { + if(currentVertexArray == null) { + logger.warn("Skipping draw call with emulated VAO because no known VAO is bound!"); + return; + } + ((SoftGLVertexArray)currentVertexArray).transitionToState(emulatedVAOState, true); + } + if(glesVers >= 300) { + _wglDrawRangeElements(mode, start, end, count, type, offset); + }else { + _wglDrawElements(mode, count, type, offset); + } + } + public static void drawArraysInstanced(int mode, int first, int count, int instances) { if(emulatedVAOs) { if(currentVertexArray == null) { @@ -768,7 +801,7 @@ public class EaglercraftGPU { displayListBuffer.put(buffer); lastRender = null; }else { - lastRender = FixedFunctionPipeline.setupDirect(buffer, attrib).update(); + lastRender = FixedFunctionPipeline.setupDirect(buffer, attrib, mode == GL_QUADS).update(); lastRender.drawDirectArrays(mode, 0, count); lastMode = mode; lastCount = count; @@ -845,7 +878,7 @@ public class EaglercraftGPU { v3 = v2 + 1; v4 = v3 + 1; buf.put(v1 | (v2 << 16)); - buf.put(v4 | (v2 << 16)); + buf.put(v3 | (v1 << 16)); buf.put(v3 | (v4 << 16)); } buf.flip(); @@ -862,7 +895,7 @@ public class EaglercraftGPU { v3 = v2 + 1; v4 = v3 + 1; buf.put(v1); buf.put(v2); - buf.put(v4); buf.put(v2); + buf.put(v3); buf.put(v1); buf.put(v3); buf.put(v4); } buf.flip(); @@ -891,7 +924,7 @@ public class EaglercraftGPU { } FixedFunctionPipeline p = FixedFunctionPipeline.setupRenderDisplayList(mesh.getAttribBits()).update(); EaglercraftGPU.bindGLVertexArray(mesh.vertexArray); - p.drawElements(GL_TRIANGLES, mesh.indexCount, GL_UNSIGNED_SHORT, 0); + p.drawRangeElements(GL_TRIANGLES, 0, mesh.vertexCount - 1, mesh.indexCount, GL_UNSIGNED_SHORT, 0); } static int glesVers = -1; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/FixedFunctionPipeline.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/FixedFunctionPipeline.java index 2abd6c34..35a721f1 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/FixedFunctionPipeline.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/FixedFunctionPipeline.java @@ -30,12 +30,9 @@ import net.lax1dude.eaglercraft.v1_8.internal.IVertexArrayGL; import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL; import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL; import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL; -import net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL; import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime; import net.lax1dude.eaglercraft.v1_8.log4j.LogManager; import net.lax1dude.eaglercraft.v1_8.log4j.Logger; -import net.lax1dude.eaglercraft.v1_8.opengl.StreamBuffer.StreamBufferInstance; -import net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights.DynamicLightsStateManager; import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f; import net.lax1dude.eaglercraft.v1_8.vector.Vector4f; import net.minecraft.util.MathHelper; @@ -61,7 +58,7 @@ public class FixedFunctionPipeline { (GlStateManager.stateEnableShaderBlendColor ? STATE_ENABLE_BLEND_ADD : 0); } - static FixedFunctionPipeline setupDirect(ByteBuffer buffer, int attrib) { + static FixedFunctionPipeline setupDirect(ByteBuffer buffer, int attrib, boolean quads) { FixedFunctionPipeline self; int baseState = attrib | getFragmentState(); if(GlStateManager.stateUseExtensionPipeline) { @@ -74,13 +71,13 @@ public class FixedFunctionPipeline { self = getPipelineInstanceCore(baseState); } - StreamBufferInstance sb = self.streamBuffer.getBuffer(buffer.remaining()); - self.currentVertexArray = sb; + EaglercraftGPU.bindGLVertexArray(self.getDirectModeVertexArray()); - EaglercraftGPU.bindGLVertexArray(sb.getVertexArray()); - EaglercraftGPU.bindGLArrayBuffer(sb.getVertexBuffer()); + int off = StreamBuffer.uploadData(self.attribStride, buffer.remaining() / self.attribStride, quads); - _wglBufferSubData(GL_ARRAY_BUFFER, 0, buffer); + _wglBufferSubData(GL_ARRAY_BUFFER, off * self.attribStride, buffer); + + self.directBaseOffset = off; return self; } @@ -132,16 +129,19 @@ public class FixedFunctionPipeline { } static FixedFunctionPipeline setupRenderDisplayList(int attribs) { + FixedFunctionPipeline self; int baseState = attribs | getFragmentState(); if(GlStateManager.stateUseExtensionPipeline) { if(extensionProvider != null) { - return getPipelineInstanceExt(baseState, extensionProvider.getCurrentExtensionStateBits(baseState)); + self = getPipelineInstanceExt(baseState, extensionProvider.getCurrentExtensionStateBits(baseState)); }else { throw new IllegalStateException("No extension pipeline is available!"); } }else { - return getPipelineInstanceCore(baseState); + self = getPipelineInstanceCore(baseState); } + + return self; } void drawArrays(int mode, int offset, int count) { @@ -151,24 +151,26 @@ public class FixedFunctionPipeline { void drawDirectArrays(int mode, int offset, int count) { EaglercraftGPU.bindGLShaderProgram(shaderProgram); + offset += directBaseOffset; if(mode == GL_QUADS) { - StreamBufferInstance sb = currentVertexArray; - if(count > EaglercraftGPU.quad16MaxVertices) { - if(!sb.bindQuad32) { - sb.bindQuad16 = false; - sb.bindQuad32 = true; + int offset2 = (offset >> 2) * 6; + int count2 = (count >> 2) * 6; + if(offset + count > EaglercraftGPU.quad16MaxVertices) { + if(directQuads != 32) { + directQuads = 32; EaglercraftGPU.attachQuad32EmulationBuffer(count, true); }else { EaglercraftGPU.attachQuad32EmulationBuffer(count, false); } - EaglercraftGPU.drawElements(GL_TRIANGLES, (count >> 2) * 6, GL_UNSIGNED_INT, 0); + EaglercraftGPU.drawRangeElements(GL_TRIANGLES, offset, offset + count - 1, count2, GL_UNSIGNED_INT, + offset2 << 2); }else { - if(!sb.bindQuad16) { - sb.bindQuad16 = true; - sb.bindQuad32 = false; + if(directQuads != 16) { + directQuads = 16; EaglercraftGPU.attachQuad16EmulationBuffer(true); } - EaglercraftGPU.drawElements(GL_TRIANGLES, (count >> 2) * 6, GL_UNSIGNED_SHORT, 0); + EaglercraftGPU.drawRangeElements(GL_TRIANGLES, offset, offset + count - 1, count2, GL_UNSIGNED_SHORT, + offset2 << 1); } }else { EaglercraftGPU.drawArrays(mode, offset, count); @@ -180,6 +182,11 @@ public class FixedFunctionPipeline { EaglercraftGPU.drawElements(mode, count, type, offset); } + void drawRangeElements(int mode, int start, int end, int count, int type, int offset) { + EaglercraftGPU.bindGLShaderProgram(shaderProgram); + EaglercraftGPU.drawRangeElements(mode, start, end, count, type, offset); + } + private static IExtPipelineCompiler extensionProvider; public static void loadExtensionPipeline(IExtPipelineCompiler provider) { @@ -423,9 +430,9 @@ public class FixedFunctionPipeline { private float stateAlphaTestRef = -999.0f; private final IUniformGL stateLightsEnabledUniform1i; - private final IUniformGL[] stateLightsVectorsArrayUniform4f = new IUniformGL[4]; + private final IUniformGL[] stateLightsVectorsArrayUniform4f = new IUniformGL[2]; private int stateLightsEnabled = -1; - private final Vector4f[] stateLightsVectors = new Vector4f[4]; + private final Vector4f[] stateLightsVectors = new Vector4f[2]; private int stateLightingSerial = -1; private final IUniformGL stateLightingAmbientUniform3f; @@ -496,8 +503,9 @@ public class FixedFunctionPipeline { private float stateAnisotropicFixH = -999.0f; private float stateAnisotropicFixSerial = 0; - private final StreamBuffer streamBuffer; - private StreamBufferInstance currentVertexArray = null; + private IVertexArrayGL directVertexArray; + private int directBaseOffset; + private byte directQuads; private static FloatBuffer matrixCopyBuffer = null; @@ -572,39 +580,6 @@ public class FixedFunctionPipeline { } throw new IllegalStateException("Program could not be linked!"); } - - streamBuffer = new StreamBuffer((vertexArray, vertexBuffer) -> { - EaglercraftGPU.bindGLVertexArray(vertexArray); - EaglercraftGPU.bindVAOGLArrayBuffer(vertexBuffer); - - EaglercraftGPU.enableVertexAttribArray(0); - EaglercraftGPU.vertexAttribPointer(0, VertexFormat.COMPONENT_POSITION_SIZE, - VertexFormat.COMPONENT_POSITION_FORMAT, false, attribStride, 0); - - if(attribTextureIndex != -1) { - EaglercraftGPU.enableVertexAttribArray(attribTextureIndex); - EaglercraftGPU.vertexAttribPointer(attribTextureIndex, VertexFormat.COMPONENT_TEX_SIZE, - VertexFormat.COMPONENT_TEX_FORMAT, false, attribStride, attribTextureOffset); - } - - if(attribColorIndex != -1) { - EaglercraftGPU.enableVertexAttribArray(attribColorIndex); - EaglercraftGPU.vertexAttribPointer(attribColorIndex, VertexFormat.COMPONENT_COLOR_SIZE, - VertexFormat.COMPONENT_COLOR_FORMAT, true, attribStride, attribColorOffset); - } - - if(attribNormalIndex != -1) { - EaglercraftGPU.enableVertexAttribArray(attribNormalIndex); - EaglercraftGPU.vertexAttribPointer(attribNormalIndex, VertexFormat.COMPONENT_NORMAL_SIZE, - VertexFormat.COMPONENT_NORMAL_FORMAT, true, attribStride, attribNormalOffset); - } - - if(attribLightmapIndex != -1) { - EaglercraftGPU.enableVertexAttribArray(attribLightmapIndex); - EaglercraftGPU.vertexAttribPointer(attribLightmapIndex, VertexFormat.COMPONENT_LIGHTMAP_SIZE, - VertexFormat.COMPONENT_LIGHTMAP_FORMAT, false, attribStride, attribLightmapOffset); - } - }); stateEnableTexture2D = (bits & STATE_ENABLE_TEXTURE2D) != 0; stateEnableLightmap = (bits & STATE_ENABLE_LIGHTMAP) != 0; @@ -899,9 +874,7 @@ public class FixedFunctionPipeline { _wglUniform3f(stateLightingAmbientUniform3f, r, g, b); } } - } - - if(stateEnableMCLighting || DynamicLightsStateManager.isInDynamicLightsPass()) { + if(!stateHasAttribNormal) { serial = GlStateManager.stateNormalSerial; if(stateNormalSerial != serial) { @@ -1089,13 +1062,51 @@ public class FixedFunctionPipeline { } pipelineListTracker.clear(); } - - public void destroy() { - PlatformOpenGL._wglDeleteProgram(shaderProgram); - streamBuffer.destroy(); - } - + public IVertexArrayGL getDirectModeVertexArray() { - return currentVertexArray.vertexArray; + if (directVertexArray == null) { + directVertexArray = EaglercraftGPU.createGLVertexArray(); + EaglercraftGPU.bindGLVertexArray(directVertexArray); + EaglercraftGPU.bindVAOGLArrayBuffer(StreamBuffer.getBuffer()); + + EaglercraftGPU.enableVertexAttribArray(0); + EaglercraftGPU.vertexAttribPointer(0, VertexFormat.COMPONENT_POSITION_SIZE, + VertexFormat.COMPONENT_POSITION_FORMAT, false, attribStride, 0); + + if (attribTextureIndex != -1) { + EaglercraftGPU.enableVertexAttribArray(attribTextureIndex); + EaglercraftGPU.vertexAttribPointer(attribTextureIndex, VertexFormat.COMPONENT_TEX_SIZE, + VertexFormat.COMPONENT_TEX_FORMAT, false, attribStride, attribTextureOffset); + } + + if (attribColorIndex != -1) { + EaglercraftGPU.enableVertexAttribArray(attribColorIndex); + EaglercraftGPU.vertexAttribPointer(attribColorIndex, VertexFormat.COMPONENT_COLOR_SIZE, + VertexFormat.COMPONENT_COLOR_FORMAT, true, attribStride, attribColorOffset); + } + + if (attribNormalIndex != -1) { + EaglercraftGPU.enableVertexAttribArray(attribNormalIndex); + EaglercraftGPU.vertexAttribPointer(attribNormalIndex, VertexFormat.COMPONENT_NORMAL_SIZE, + VertexFormat.COMPONENT_NORMAL_FORMAT, true, attribStride, attribNormalOffset); + } + + if (attribLightmapIndex != -1) { + EaglercraftGPU.enableVertexAttribArray(attribLightmapIndex); + EaglercraftGPU.vertexAttribPointer(attribLightmapIndex, VertexFormat.COMPONENT_LIGHTMAP_SIZE, + VertexFormat.COMPONENT_LIGHTMAP_FORMAT, false, attribStride, attribLightmapOffset); + } + + return directVertexArray; + } + return directVertexArray; } + + public void destroy() { + _wglDeleteProgram(shaderProgram); + if (directVertexArray != null) { + EaglercraftGPU.destroyGLVertexArray(directVertexArray); + } + } + } \ No newline at end of file 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 f6d9f342..dc9c6da0 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 @@ -44,7 +44,7 @@ public class FixedFunctionShader { public static final String FILENAME_VSH = "/assets/eagler/glsl/core.vsh"; public static final String FILENAME_FSH = "/assets/eagler/glsl/core.fsh"; - public static final String PRECISION_INT = "lowp"; + public static final String PRECISION_INT = "mediump"; public static final String PRECISION_FLOAT = "highp"; public static final String PRECISION_SAMPLER = "mediump"; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GlStateManager.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GlStateManager.java index 76ec9a12..ce0b8258 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GlStateManager.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GlStateManager.java @@ -76,9 +76,9 @@ public class GlStateManager { static boolean stateMaterial = false; static boolean stateLighting = false; static int stateLightsStackPointer = 0; - static final boolean[][] stateLightsEnabled = new boolean[4][8]; - static final Vector4f[][] stateLightsStack = new Vector4f[4][8]; - static final int[] stateLightingSerial = new int[4]; + static final boolean[][] stateLightsEnabled = new boolean[2][8]; + static final Vector4f[][] stateLightsStack = new Vector4f[2][8]; + static final int[] stateLightingSerial = new int[2]; static float stateLightingAmbientR = 0.0f; static float stateLightingAmbientG = 0.0f; 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 5256ac09..4ab85505 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 @@ -206,8 +206,7 @@ public class InstancedFontRenderer { EaglercraftGPU.vertexAttribPointer(0, 3, GL_FLOAT, false, 12, 0); EaglercraftGPU.vertexAttribDivisor(0, 0); - EaglercraftGPU.bindVAOGLArrayBufferNow(instancesBuffer); - _wglBufferData(GL_ARRAY_BUFFER, fontDataBuffer.capacity(), GL_STREAM_DRAW); + EaglercraftGPU.bindVAOGLArrayBuffer(instancesBuffer); EaglercraftGPU.enableVertexAttribArray(1); EaglercraftGPU.vertexAttribPointer(1, 2, GL_SHORT, false, 10, 0); @@ -381,7 +380,7 @@ public class InstancedFontRenderer { int l = fontDataBuffer.limit(); fontDataBuffer.flip(); - _wglBufferData(GL_ARRAY_BUFFER, fontDataBuffer.capacity(), GL_STREAM_DRAW); + _wglBufferData(GL_ARRAY_BUFFER, (fontDataBuffer.remaining() + 0x3FF) & 0xFFFFFC00, GL_STREAM_DRAW); _wglBufferSubData(GL_ARRAY_BUFFER, 0, fontDataBuffer); fontDataBuffer.position(p); @@ -395,7 +394,7 @@ public class InstancedFontRenderer { int l = fontBoldDataBuffer.limit(); fontBoldDataBuffer.flip(); - _wglBufferData(GL_ARRAY_BUFFER, fontBoldDataBuffer.capacity(), GL_STREAM_DRAW); + _wglBufferData(GL_ARRAY_BUFFER, (fontBoldDataBuffer.remaining() + 0x3FF) & 0xFFFFFC00, GL_STREAM_DRAW); _wglBufferSubData(GL_ARRAY_BUFFER, 0, fontBoldDataBuffer); fontBoldDataBuffer.position(p); 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 a3f1d052..e9f8e8e0 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 @@ -187,8 +187,7 @@ public class InstancedParticleRenderer { EaglercraftGPU.vertexAttribPointer(0, 2, GL_FLOAT, false, 8, 0); EaglercraftGPU.vertexAttribDivisor(0, 0); - EaglercraftGPU.bindVAOGLArrayBufferNow(instancesBuffer); - _wglBufferData(GL_ARRAY_BUFFER, particleBuffer.capacity(), GL_STREAM_DRAW); + EaglercraftGPU.bindVAOGLArrayBuffer(instancesBuffer); EaglercraftGPU.enableVertexAttribArray(1); EaglercraftGPU.vertexAttribPointer(1, 3, GL_FLOAT, false, 24, 0); @@ -315,7 +314,7 @@ public class InstancedParticleRenderer { int l = particleBuffer.limit(); particleBuffer.flip(); - _wglBufferData(GL_ARRAY_BUFFER, particleBuffer.capacity(), GL_STREAM_DRAW); + _wglBufferData(GL_ARRAY_BUFFER, (particleBuffer.remaining() + 0xFFF) & 0xFFFFF000, GL_STREAM_DRAW); _wglBufferSubData(GL_ARRAY_BUFFER, 0, particleBuffer); particleBuffer.position(p); diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/StreamBuffer.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/StreamBuffer.java index 5629753c..1a52cae6 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/StreamBuffer.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/StreamBuffer.java @@ -16,108 +16,53 @@ package net.lax1dude.eaglercraft.v1_8.opengl; -import net.lax1dude.eaglercraft.v1_8.internal.IVertexArrayGL; import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL; import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*; import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*; +/** + * This streaming implementation was designed by reverse engineering the OpenGL + * driver that powers most Intel-based Chromebooks, performance may vary on + * other platforms + */ public class StreamBuffer { - public static final int poolSize = 4; + protected static IBufferGL buffer = null; - protected static final PoolInstance[] pool = new PoolInstance[poolSize]; - protected static int poolBufferID = 0; + protected static int currentOffset = 0; + protected static int currentSize = 0; - static { - for(int i = 0; i < poolSize; ++i) { - pool[i] = new PoolInstance(); - } - } - - protected static class PoolInstance { - - protected IBufferGL vertexBuffer = null; - protected int vertexBufferSize = 0; - - } - - private static void resizeInstance(PoolInstance instance, int requiredMemory) { - IBufferGL buffer = instance.vertexBuffer; + public static IBufferGL getBuffer() { if (buffer == null) { - buffer = _wglGenBuffers(); - instance.vertexBuffer = buffer; + return buffer = _wglGenBuffers(); } - int newSize = instance.vertexBufferSize; - if (newSize < requiredMemory) { - newSize = (requiredMemory + 0xFFFF) & 0xFFFF0000; - instance.vertexBufferSize = newSize; - } - EaglercraftGPU.bindGLArrayBuffer(buffer); - _wglBufferData(GL_ARRAY_BUFFER, newSize, GL_STREAM_DRAW); + return buffer; } - protected StreamBufferInstance[] buffers; - - protected final IStreamBufferInitializer initializer; - - public static class StreamBufferInstance { - - protected PoolInstance poolInstance = null; - protected IVertexArrayGL vertexArray = null; - - public boolean bindQuad16 = false; - public boolean bindQuad32 = false; - - public IVertexArrayGL getVertexArray() { - return vertexArray; + public static int uploadData(int elSize, int elCount, boolean quads) { + EaglercraftGPU.bindGLArrayBuffer(getBuffer()); + int off = (currentOffset + elSize - 1) / elSize; + if (quads) { + off = (off + 3) & -4; } - - public IBufferGL getVertexBuffer() { - return poolInstance.vertexBuffer; - } - - } - - public static interface IStreamBufferInitializer { - void initialize(IVertexArrayGL vertexArray, IBufferGL vertexBuffer); - } - - public StreamBuffer(IStreamBufferInitializer initializer) { - this.buffers = new StreamBufferInstance[poolSize]; - for(int i = 0; i < this.buffers.length; ++i) { - StreamBufferInstance j = new StreamBufferInstance(); - j.poolInstance = pool[i]; - this.buffers[i] = j; - } - this.initializer = initializer; - } - - public StreamBufferInstance getBuffer(int requiredMemory) { - StreamBufferInstance next = buffers[poolBufferID++ % buffers.length]; - resizeInstance(next.poolInstance, requiredMemory); - if(next.vertexArray == null) { - next.vertexArray = EaglercraftGPU.createGLVertexArray(); - initializer.initialize(next.vertexArray, next.poolInstance.vertexBuffer); - } - return next; - } - - public void destroy() { - for(int i = 0; i < buffers.length; ++i) { - StreamBufferInstance next = buffers[i]; - if(next.vertexArray != null) { - EaglercraftGPU.destroyGLVertexArray(next.vertexArray); - } + int offBytes = off * elSize; + int reqBytes = elCount * elSize; + if (currentSize - offBytes >= reqBytes) { + currentOffset = offBytes + reqBytes; + return off; + } else { + currentOffset = 0; + currentSize = (reqBytes + 0xFFFF) & 0xFFFFF000; + _wglBufferData(GL_ARRAY_BUFFER, currentSize, GL_STREAM_DRAW); + return 0; } } public static void destroyPool() { - for(int i = 0; i < pool.length; ++i) { - if(pool[i].vertexBuffer != null) { - _wglDeleteBuffers(pool[i].vertexBuffer); - pool[i].vertexBuffer = null; - } + if (buffer != null) { + _wglDeleteBuffers(buffer); + buffer = null; } } diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/deferred/LensFlareMeshRenderer.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/deferred/LensFlareMeshRenderer.java index 3236b284..bedb57aa 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/deferred/LensFlareMeshRenderer.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/deferred/LensFlareMeshRenderer.java @@ -316,7 +316,8 @@ public class LensFlareMeshRenderer { _wglUniform3f(streaksProgram.uniforms.u_flareColor3f, v.x * mag * 0.5f, v.y * mag * 0.5f, v.z * mag * 0.5f); EaglercraftGPU.bindGLVertexArray(streaksVertexArray); - _wglDrawElements(GL_TRIANGLES, streaksVertexCount + (streaksVertexCount >> 1), GL_UNSIGNED_SHORT, 0); + _wglDrawRangeElements(GL_TRIANGLES, 0, streaksVertexCount - 1, streaksVertexCount + (streaksVertexCount >> 1), + GL_UNSIGNED_SHORT, 0); ghostsProgram.useProgram(); diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/dynamiclights/DynamicLightBucketLoader.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/dynamiclights/DynamicLightBucketLoader.java index 9c421864..7a9bbb71 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/dynamiclights/DynamicLightBucketLoader.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/dynamiclights/DynamicLightBucketLoader.java @@ -46,8 +46,8 @@ public class DynamicLightBucketLoader { private int currentLightSourceBucketId = -1; private int lightingBufferSliceLength = -1; - public static final int MAX_LIGHTS_PER_CHUNK = 12; - public static final int LIGHTING_BUFFER_LENGTH = 16 * MAX_LIGHTS_PER_CHUNK + 16; + public static final int MAX_LIGHTS_PER_CHUNK = 8; + public static final int LIGHTING_BUFFER_LENGTH = 8 * MAX_LIGHTS_PER_CHUNK + 16; private final int lightSourceBucketsWidth; private final int lightSourceBucketsHeight; @@ -114,26 +114,36 @@ public class DynamicLightBucketLoader { int ser = currentLightSourceBucket.getEaglerSerial(); int max = currentLightSourceBucket.size(); if(max > 0) { + if(max > MAX_LIGHTS_PER_CHUNK) { + max = MAX_LIGHTS_PER_CHUNK; + } EaglercraftGPU.bindGLUniformBuffer(buffer_chunkLightingData); int offset = currentLightSourceBucketId * lightingBufferSliceLength; if (lightSourceBucketsSerials[currentLightSourceBucketId] != ser || lightSourceRenderPosSerials[currentLightSourceBucketId] != currentRenderPosSerial) { lightSourceBucketsSerials[currentLightSourceBucketId] = ser; lightSourceRenderPosSerials[currentLightSourceBucketId] = currentRenderPosSerial; - if(max > MAX_LIGHTS_PER_CHUNK) { - max = MAX_LIGHTS_PER_CHUNK; - } + int bucketXOff = -relativeBlockX & -16; + int bucketYOff = -relativeBlockY & -16; + int bucketZOff = -relativeBlockZ & -16; chunkLightingDataCopyBuffer.clear(); + chunkLightingDataCopyBuffer.putInt( + ((bucketXOff & 0xFF) << 8) | + ((bucketYOff & 0xFF) << 16) | + ((bucketZOff & 0xFF) << 24) + ); chunkLightingDataCopyBuffer.putInt(max); - chunkLightingDataCopyBuffer.putInt(0); //padding - chunkLightingDataCopyBuffer.putInt(0); //padding - chunkLightingDataCopyBuffer.putInt(0); //padding + chunkLightingDataCopyBuffer.putInt(0); // padding + chunkLightingDataCopyBuffer.putInt(0); // padding for(int i = 0; i < max; ++i) { DynamicLightInstance dl = currentLightSourceBucket.get(i); - chunkLightingDataCopyBuffer.putFloat((float)(dl.posX - currentRenderX)); - chunkLightingDataCopyBuffer.putFloat((float)(dl.posY - currentRenderY)); - chunkLightingDataCopyBuffer.putFloat((float)(dl.posZ - currentRenderZ)); - chunkLightingDataCopyBuffer.putFloat(dl.radius); + int x = (int)((dl.posX - currentRenderX + bucketXOff) * (1.0f / 0.0009765923f)); + int y = (int)((dl.posY - currentRenderY + bucketYOff) * (1.0f / 0.0009765923f)); + int z = (int)((dl.posZ - currentRenderZ + bucketZOff) * (1.0f / 0.0009765923f)); + int r = (int)(dl.radius * (1.0f / 0.0009765923f)); + if (r > 32767) r = 32767; + chunkLightingDataCopyBuffer.putInt((x & 0xFFFF) | (z << 16)); + chunkLightingDataCopyBuffer.putInt((y & 0xFFFF) | (r << 16)); } chunkLightingDataCopyBuffer.flip(); _wglBufferSubData(_GL_UNIFORM_BUFFER, offset, chunkLightingDataCopyBuffer); diff --git a/sources/platform-api/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformOpenGL.java b/sources/platform-api/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformOpenGL.java index b8459b2d..06dfff7e 100644 --- a/sources/platform-api/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformOpenGL.java +++ b/sources/platform-api/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformOpenGL.java @@ -204,6 +204,8 @@ public class PlatformOpenGL { public static native void _wglDrawElements(int mode, int count, int type, int offset); + public static native void _wglDrawRangeElements(int mode, int start, int end, int count, int type, int offset); + public static native void _wglDrawArraysInstanced(int mode, int first, int count, int instanced); public static native void _wglDrawElementsInstanced(int mode, int count, int type, int offset, int instanced); diff --git a/sources/resources/EPKVersionIdentifier.txt b/sources/resources/EPKVersionIdentifier.txt index 41915701..471a6eb2 100644 --- a/sources/resources/EPKVersionIdentifier.txt +++ b/sources/resources/EPKVersionIdentifier.txt @@ -1 +1 @@ -u52 \ No newline at end of file +u53 \ No newline at end of file diff --git a/sources/resources/assets/eagler/glsl/core.fsh b/sources/resources/assets/eagler/glsl/core.fsh index 660bc913..fa495f1d 100644 --- a/sources/resources/assets/eagler/glsl/core.fsh +++ b/sources/resources/assets/eagler/glsl/core.fsh @@ -63,7 +63,7 @@ uniform float u_alphaTestRef1f; #ifdef COMPILE_ENABLE_MC_LIGHTING uniform int u_lightsEnabled1i; -uniform vec4 u_lightsDirections4fv[4]; +uniform vec4 u_lightsDirections4fv[2]; uniform vec3 u_lightsAmbient3f; #ifndef COMPILE_NORMAL_ATTRIB uniform vec3 u_uniformNormal3f; @@ -166,20 +166,14 @@ void main() { #else vec3 normal = u_uniformNormal3f; #endif - float diffuse = 0.0; vec4 light; -#ifdef EAGLER_HAS_GLES_300 - for(int i = 0; i < u_lightsEnabled1i; ++i) { -#else - for(int i = 0; i < 4; ++i) { -#endif - light = u_lightsDirections4fv[i]; - diffuse += max(dot(light.xyz, normal), 0.0) * light.w; -#ifndef EAGLER_HAS_GLES_300 - if(i + 1 >= u_lightsEnabled1i) { + float diffuse = 0.0; + for(int i = 0; i < 2; ++i) { + if(i >= u_lightsEnabled1i) { break; } -#endif + light = u_lightsDirections4fv[i]; + diffuse += max(dot(light.xyz, normal), 0.0) * light.w; } color.rgb *= min(u_lightsAmbient3f + vec3(diffuse), 1.0); #endif diff --git a/sources/resources/assets/eagler/glsl/dynamiclights/accel_particle_dynamiclights.fsh b/sources/resources/assets/eagler/glsl/dynamiclights/accel_particle_dynamiclights.fsh index 0cf02c74..8b44fb15 100644 --- a/sources/resources/assets/eagler/glsl/dynamiclights/accel_particle_dynamiclights.fsh +++ b/sources/resources/assets/eagler/glsl/dynamiclights/accel_particle_dynamiclights.fsh @@ -20,7 +20,6 @@ precision lowp int; precision mediump float; precision mediump sampler2D; -in vec4 v_position4f; in vec2 v_texCoord2f; in vec4 v_color4f; in vec2 v_lightmap2f; @@ -30,16 +29,6 @@ layout(location = 0) out vec4 output4f; uniform sampler2D u_inputTexture; uniform sampler2D u_lightmapTexture; -uniform mat4 u_inverseViewMatrix4f; - -layout(std140) uniform u_chunkLightingData { - mediump int u_dynamicLightCount1i; - mediump int _paddingA_; - mediump int _paddingB_; - mediump int _paddingC_; - mediump vec4 u_dynamicLightArray[12]; -}; - void main() { vec4 color = texture(u_inputTexture, v_texCoord2f) * v_color4f; @@ -47,20 +36,7 @@ void main() { discard; } - vec4 dlight; - float blockLight = v_lightmap2f.x; - if(u_dynamicLightCount1i > 0) { - vec4 worldPosition4f = u_inverseViewMatrix4f * v_position4f; - worldPosition4f.xyz /= worldPosition4f.w; - int safeLightCount = u_dynamicLightCount1i > 12 ? 0 : u_dynamicLightCount1i; - for(int i = 0; i < safeLightCount; ++i) { - dlight = u_dynamicLightArray[i]; - dlight.xyz = dlight.xyz - worldPosition4f.xyz; - blockLight = max((dlight.w - length(dlight.xyz)) * 0.066667, blockLight); - } - } - - color *= texture(u_lightmapTexture, vec2(blockLight, v_lightmap2f.y)); + color *= texture(u_lightmapTexture, v_lightmap2f); output4f = color; } diff --git a/sources/resources/assets/eagler/glsl/dynamiclights/accel_particle_dynamiclights.vsh b/sources/resources/assets/eagler/glsl/dynamiclights/accel_particle_dynamiclights.vsh index 202bd153..fc637da2 100644 --- a/sources/resources/assets/eagler/glsl/dynamiclights/accel_particle_dynamiclights.vsh +++ b/sources/resources/assets/eagler/glsl/dynamiclights/accel_particle_dynamiclights.vsh @@ -28,21 +28,27 @@ layout(location = 3) in vec2 p_lightMap2f; layout(location = 4) in vec2 p_particleSize_texCoordsSize_2i; layout(location = 5) in vec4 p_color4f; -out vec4 v_position4f; out vec2 v_texCoord2f; out vec4 v_color4f; out vec2 v_lightmap2f; uniform mat4 u_modelViewMatrix4f; uniform mat4 u_projectionMatrix4f; +uniform mat4 u_inverseViewMatrix4f; uniform vec3 u_texCoordSize2f_particleSize1f; uniform vec3 u_transformParam_1_2_5_f; uniform vec2 u_transformParam_3_4_f; uniform vec4 u_color4f; +layout(std140) uniform u_chunkLightingData { + mediump uvec2 u_dynamicLightOffsetCount2i; + mediump int _paddingA_; + mediump int _paddingB_; + mediump uvec4 u_dynamicLightArray[4]; +}; + void main() { v_color4f = u_color4f * p_color4f.bgra; - v_lightmap2f = p_lightMap2f; vec2 tex2f = a_position2f * 0.5 + 0.5; tex2f.y = 1.0 - tex2f.y; @@ -56,6 +62,40 @@ void main() { pos3f += u_transformParam_1_2_5_f * spos2f.xyy; pos3f.zx += u_transformParam_3_4_f * spos2f; - v_position4f = u_modelViewMatrix4f * vec4(pos3f, 1.0); - gl_Position = u_projectionMatrix4f * v_position4f; + vec4 pos4f = u_modelViewMatrix4f * vec4(pos3f, 1.0); + gl_Position = u_projectionMatrix4f * pos4f; + + float blockLight = 0.0; + + vec4 dlight; + uvec4 dlighti1, dlighti2; + if(u_dynamicLightOffsetCount2i.y > 0u) { + vec3 dlightOffset = vec3(ivec3( + int(u_dynamicLightOffsetCount2i.x << 16), + int(u_dynamicLightOffsetCount2i.x << 8), + int(u_dynamicLightOffsetCount2i.x) + ) >> 24); + vec4 worldPosition4f = u_inverseViewMatrix4f * pos4f; + worldPosition4f.xyz = worldPosition4f.xyz / worldPosition4f.w + dlightOffset; + for(uint i = 0u; i < 4u; ++i) { + dlighti1 = u_dynamicLightArray[i]; + dlighti2 = dlighti1 << 16; + + dlight = vec4(ivec4(ivec2(dlighti2.xy), ivec2(dlighti1.xy)) >> 16) * 0.0009765923; + dlight.xyz = dlight.xyz - worldPosition4f.xyz; + blockLight = max((dlight.w - length(dlight.xyz)) * 0.066667, blockLight); + if(i * 2u + 1u >= u_dynamicLightOffsetCount2i.y) { + break; + } + + dlight = vec4(ivec4(ivec2(dlighti2.zw), ivec2(dlighti1.zw)) >> 16) * 0.0009765923; + dlight.xyz = dlight.xyz - worldPosition4f.xyz; + blockLight = max((dlight.w - length(dlight.xyz)) * 0.066667, blockLight); + if(i * 2u + 2u >= u_dynamicLightOffsetCount2i.y) { + break; + } + } + } + + v_lightmap2f = vec2(max(p_lightMap2f.x, blockLight), p_lightMap2f.y); } diff --git a/sources/resources/assets/eagler/glsl/dynamiclights/core_dynamiclights.fsh b/sources/resources/assets/eagler/glsl/dynamiclights/core_dynamiclights.fsh index 42897792..5097be27 100644 --- a/sources/resources/assets/eagler/glsl/dynamiclights/core_dynamiclights.fsh +++ b/sources/resources/assets/eagler/glsl/dynamiclights/core_dynamiclights.fsh @@ -16,7 +16,9 @@ * */ +#if defined(COMPILE_ENABLE_TEX_GEN) || defined(COMPILE_ENABLE_FOG) in vec4 v_position4f; +#endif #ifdef COMPILE_TEXTURE_ATTRIB in vec2 v_texture2f; @@ -61,7 +63,7 @@ uniform float u_alphaTestRef1f; #ifdef COMPILE_ENABLE_MC_LIGHTING uniform int u_lightsEnabled1i; -uniform vec4 u_lightsDirections4fv[4]; +uniform vec4 u_lightsDirections4fv[2]; uniform vec3 u_lightsAmbient3f; #endif @@ -88,15 +90,9 @@ uniform mat4 u_textureMat4f01; uniform vec2 u_textureAnisotropicFix; #endif -uniform mat4 u_inverseViewMatrix4f; - -layout(std140) uniform u_chunkLightingData { - mediump int u_dynamicLightCount1i; - mediump int _paddingA_; - mediump int _paddingB_; - mediump int _paddingC_; - mediump vec4 u_dynamicLightArray[12]; -}; +#ifdef COMPILE_ENABLE_LIGHTMAP +in float v_dynamicLight1f; +#endif layout(location = 0) out vec4 output4f; @@ -151,17 +147,9 @@ void main() { #else float blockLight = u_textureCoords02.x; #endif - vec4 dlight; - if(u_dynamicLightCount1i > 0) { - vec4 worldPosition4f = u_inverseViewMatrix4f * v_position4f; - worldPosition4f.xyz /= worldPosition4f.w; - int safeLightCount = u_dynamicLightCount1i > 12 ? 0 : u_dynamicLightCount1i; - for(int i = 0; i < safeLightCount; ++i) { - dlight = u_dynamicLightArray[i]; - dlight.xyz = dlight.xyz - worldPosition4f.xyz; - blockLight = max((dlight.w - length(dlight.xyz)) * 0.066667, blockLight); - } - } + + blockLight = max(blockLight, v_dynamicLight1f); + #ifdef COMPILE_LIGHTMAP_ATTRIB color *= texture(u_samplerLightmap, vec2(blockLight, v_lightmap2f.y)); #else @@ -179,16 +167,18 @@ void main() { #endif +#ifdef COMPILE_ENABLE_MC_LIGHTING #ifdef COMPILE_NORMAL_ATTRIB vec3 normal = v_normal3f; #else vec3 normal = u_uniformNormal3f; #endif - -#ifdef COMPILE_ENABLE_MC_LIGHTING vec4 light; float diffuse = 0.0; - for(int i = 0; i < u_lightsEnabled1i; ++i) { + for(int i = 0; i < 2; ++i) { + if(i >= u_lightsEnabled1i) { + break; + } light = u_lightsDirections4fv[i]; diffuse += max(dot(light.xyz, normal), 0.0) * light.w; } diff --git a/sources/resources/assets/eagler/glsl/dynamiclights/core_dynamiclights.vsh b/sources/resources/assets/eagler/glsl/dynamiclights/core_dynamiclights.vsh index 023b204f..6ecb9dee 100644 --- a/sources/resources/assets/eagler/glsl/dynamiclights/core_dynamiclights.vsh +++ b/sources/resources/assets/eagler/glsl/dynamiclights/core_dynamiclights.vsh @@ -18,7 +18,13 @@ in vec3 a_position3f; +#if defined(COMPILE_ENABLE_TEX_GEN) || defined(COMPILE_ENABLE_FOG) +#define _COMPILE_VARYING_POSITION +#endif + +#ifdef _COMPILE_VARYING_POSITION out vec4 v_position4f; +#endif #ifdef COMPILE_ENABLE_TEX_GEN out vec3 v_objectPosition3f; @@ -46,16 +52,32 @@ out vec2 v_lightmap2f; uniform mat4 u_textureMat4f02; #endif +#ifdef COMPILE_ENABLE_LIGHTMAP +out float v_dynamicLight1f; +#endif + uniform mat4 u_modelviewMat4f; uniform mat4 u_projectionMat4f; +uniform mat4 u_inverseViewMatrix4f; #define TEX_MAT3(mat4In) mat3(mat4In[0].xyw,mat4In[1].xyw,mat4In[3].xyw) +layout(std140) uniform u_chunkLightingData { + mediump uvec2 u_dynamicLightOffsetCount2i; + mediump int _paddingA_; + mediump int _paddingB_; + mediump uvec4 u_dynamicLightArray[4]; +}; + void main() { #ifdef COMPILE_ENABLE_TEX_GEN v_objectPosition3f = a_position3f; #endif +#ifndef _COMPILE_VARYING_POSITION + vec4 v_position4f; +#endif + v_position4f = u_modelviewMat4f * vec4(a_position3f, 1.0); #ifdef COMPILE_TEXTURE_ATTRIB @@ -75,6 +97,42 @@ void main() { vec3 v_lightmapTmp3f = TEX_MAT3(u_textureMat4f02) * vec3(a_lightmap2f, 1.0); v_lightmap2f = v_lightmapTmp3f.xy / v_lightmapTmp3f.z; #endif - + gl_Position = u_projectionMat4f * v_position4f; + +#ifdef COMPILE_ENABLE_LIGHTMAP + float blockLight = 0.0; + + vec4 dlight; + uvec4 dlighti1, dlighti2; + if(u_dynamicLightOffsetCount2i.y > 0u) { + vec3 dlightOffset = vec3(ivec3( + int(u_dynamicLightOffsetCount2i.x << 16), + int(u_dynamicLightOffsetCount2i.x << 8), + int(u_dynamicLightOffsetCount2i.x) + ) >> 24); + vec4 worldPosition4f = u_inverseViewMatrix4f * v_position4f; + worldPosition4f.xyz = worldPosition4f.xyz / worldPosition4f.w + dlightOffset; + for(uint i = 0u; i < 4u; ++i) { + dlighti1 = u_dynamicLightArray[i]; + dlighti2 = dlighti1 << 16; + + dlight = vec4(ivec4(ivec2(dlighti2.xy), ivec2(dlighti1.xy)) >> 16) * 0.0009765923; + dlight.xyz = dlight.xyz - worldPosition4f.xyz; + blockLight = max((dlight.w - length(dlight.xyz)) * 0.066667, blockLight); + if(i * 2u + 1u >= u_dynamicLightOffsetCount2i.y) { + break; + } + + dlight = vec4(ivec4(ivec2(dlighti2.zw), ivec2(dlighti1.zw)) >> 16) * 0.0009765923; + dlight.xyz = dlight.xyz - worldPosition4f.xyz; + blockLight = max((dlight.w - length(dlight.xyz)) * 0.066667, blockLight); + if(i * 2u + 2u >= u_dynamicLightOffsetCount2i.y) { + break; + } + } + } + + v_dynamicLight1f = blockLight; +#endif } diff --git a/sources/resources/assets/eagler/silence_loop.wav b/sources/resources/assets/eagler/silence_loop.wav index d1eee0e8..e3a005ef 100644 Binary files a/sources/resources/assets/eagler/silence_loop.wav and b/sources/resources/assets/eagler/silence_loop.wav differ diff --git a/sources/setup/workspace_template/target_teavm_wasm_gc/javascript/enableJSPIScreen.html b/sources/setup/workspace_template/target_teavm_wasm_gc/javascript/enableJSPIScreen.html index 278002d3..ee193505 100644 --- a/sources/setup/workspace_template/target_teavm_wasm_gc/javascript/enableJSPIScreen.html +++ b/sources/setup/workspace_template/target_teavm_wasm_gc/javascript/enableJSPIScreen.html @@ -64,7 +64,7 @@