diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/effects/SphereFilterProgram.java b/src/main/java/com/simibubi/create/foundation/render/backend/effects/SphereFilterProgram.java index 5492c0b42..8b885b5b6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/effects/SphereFilterProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/effects/SphereFilterProgram.java @@ -126,6 +126,7 @@ public class SphereFilterProgram extends GlProgram { public Vector3d center; public float radius; public float feather; + public float fade; public float strength = 1; public boolean hsv; @@ -146,6 +147,11 @@ public class SphereFilterProgram extends GlProgram { return this; } + public FilterSphere setFade(float fade) { + this.fade = fade; + return this; + } + public FilterSphere setStrength(float strength) { this.strength = strength; return this; @@ -168,9 +174,9 @@ public class SphereFilterProgram extends GlProgram { (float) center.z, radius, feather, + fade, strength, hsv ? 1f : 0f, - 0 // padding, we could add more parameters here }); buf.put(RenderUtil.writeMatrix(filter)); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java index 7680f1790..af5f0db3f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java @@ -48,15 +48,15 @@ public class GlBuffer extends GlObject { } public void map(int length, Consumer upload) { - Backend.compat.mapBuffer(bufferType, 0, length, upload); + Backend.compat.mapBuffer.mapBuffer(bufferType, 0, length, upload); } public void map(int offset, int length, Consumer upload) { - Backend.compat.mapBuffer(bufferType, offset, length, upload); + Backend.compat.mapBuffer.mapBuffer(bufferType, offset, length, upload); } public void map(int type, int offset, int length, Consumer upload) { - Backend.compat.mapBuffer(type, offset, length, upload); + Backend.compat.mapBuffer.mapBuffer(type, offset, length, upload); } protected void deleteInternal(int handle) { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java index e4854990e..7cb3fb0de 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java @@ -6,16 +6,16 @@ import com.simibubi.create.foundation.render.backend.Backend; public class GlVertexArray extends GlObject { public GlVertexArray() { - setHandle(Backend.compat.genVertexArrays()); - } + setHandle(Backend.compat.vao.genVertexArrays()); + } public void bind() { - Backend.compat.bindVertexArray(handle()); - } + Backend.compat.vao.bindVertexArray(handle()); + } public void unbind() { - Backend.compat.bindVertexArray(0); - } + Backend.compat.vao.bindVertexArray(0); + } public void with(Consumer action) { bind(); @@ -24,6 +24,6 @@ public class GlVertexArray extends GlObject { } protected void deleteInternal(int handle) { - Backend.compat.deleteVertexArrays(handle); - } + Backend.compat.vao.deleteVertexArrays(handle); + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlCompat.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlCompat.java index 1c152fce3..13e3a2418 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlCompat.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlCompat.java @@ -2,7 +2,6 @@ package com.simibubi.create.foundation.render.backend.gl.versioned; import java.nio.ByteBuffer; import java.util.Arrays; -import java.util.function.Consumer; import org.lwjgl.PointerBuffer; import org.lwjgl.opengl.GL20C; @@ -10,89 +9,83 @@ import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryUtil; +import com.simibubi.create.foundation.render.backend.gl.versioned.framebuffer.Blit; +import com.simibubi.create.foundation.render.backend.gl.versioned.framebuffer.Framebuffer; +import com.simibubi.create.foundation.render.backend.gl.versioned.instancing.DrawInstanced; +import com.simibubi.create.foundation.render.backend.gl.versioned.instancing.InstancedArrays; +import com.simibubi.create.foundation.render.backend.gl.versioned.instancing.VertexArrayObject; + /** * An instance of this class stores information * about what OpenGL features are available. - * + *

* Each field stores an enum variant that provides access to the * most appropriate version of a feature for the current system. */ public class GlCompat { - public final MapBuffer mapBuffer; + public final MapBuffer mapBuffer; - public final VertexArrayObject vertexArrayObject; - public final InstancedArrays instancedArrays; - public final DrawInstanced drawInstanced; + public final VertexArrayObject vao; + public final InstancedArrays instancedArrays; + public final DrawInstanced drawInstanced; + public final Blit blit; + public final Framebuffer fbo; - public final RGPixelFormat pixelFormat; + public final RGPixelFormat pixelFormat; - public GlCompat(GLCapabilities caps) { - mapBuffer = getLatest(MapBuffer.class, caps); + public GlCompat(GLCapabilities caps) { + mapBuffer = getLatest(MapBuffer.class, caps); - vertexArrayObject = getLatest(VertexArrayObject.class, caps); - instancedArrays = getLatest(InstancedArrays.class, caps); - drawInstanced = getLatest(DrawInstanced.class, caps); + vao = getLatest(VertexArrayObject.class, caps); + instancedArrays = getLatest(InstancedArrays.class, caps); + drawInstanced = getLatest(DrawInstanced.class, caps); + blit = getLatest(Blit.class, caps); + fbo = getLatest(Framebuffer.class, caps); - pixelFormat = getLatest(RGPixelFormat.class, caps); - } + pixelFormat = getLatest(RGPixelFormat.class, caps); + } - public void mapBuffer(int target, int offset, int length, Consumer upload) { - mapBuffer.mapBuffer(target, offset, length, upload); - } + public boolean vertexArrayObjectsSupported() { + return vao != VertexArrayObject.UNSUPPORTED; + } - public void vertexAttribDivisor(int index, int divisor) { - instancedArrays.vertexAttribDivisor(index, divisor); - } + public boolean instancedArraysSupported() { + return instancedArrays != InstancedArrays.UNSUPPORTED; + } - public void drawArraysInstanced(int mode, int first, int count, int primcount) { - drawInstanced.drawArraysInstanced(mode, first, count, primcount); - } + public boolean drawInstancedSupported() { + return drawInstanced != DrawInstanced.UNSUPPORTED; + } - public int genVertexArrays() { - return vertexArrayObject.genVertexArrays(); - } + public boolean fbosSupported() { + return fbo != Framebuffer.UNSUPPORTED; + } - public void deleteVertexArrays(int array) { - vertexArrayObject.deleteVertexArrays(array); - } + public boolean blitSupported() { + return blit != Blit.UNSUPPORTED; + } - public void bindVertexArray(int array) { - vertexArrayObject.bindVertexArray(array); - } + /** + * Get the most compatible version of a specific OpenGL feature by iterating over enum constants in order. + * + * @param clazz The class of the versioning enum. + * @param caps The current system's supported features. + * @param The type of the versioning enum. + * @return The first defined enum variant to return true. + */ + public static & GlVersioned> V getLatest(Class clazz, GLCapabilities caps) { + V[] constants = clazz.getEnumConstants(); + V last = constants[constants.length - 1]; + if (!last.supported(caps)) { + throw new IllegalStateException(""); + } - public boolean vertexArrayObjectsSupported() { - return vertexArrayObject != VertexArrayObject.UNSUPPORTED; - } + return Arrays.stream(constants).filter(it -> it.supported(caps)).findFirst().get(); + } - public boolean instancedArraysSupported() { - return instancedArrays != InstancedArrays.UNSUPPORTED; - } - - public boolean drawInstancedSupported() { - return drawInstanced != DrawInstanced.UNSUPPORTED; - } - - /** - * Get the most compatible version of a specific OpenGL feature by iterating over enum constants in order. - * - * @param clazz The class of the versioning enum. - * @param caps The current system's supported features. - * @param The type of the versioning enum. - * @return The first defined enum variant to return true. - */ - public static & GlVersioned> V getLatest(Class clazz, GLCapabilities caps) { - V[] constants = clazz.getEnumConstants(); - V last = constants[constants.length - 1]; - if (!last.supported(caps)) { - throw new IllegalStateException(""); - } - - return Arrays.stream(constants).filter(it -> it.supported(caps)).findFirst().get(); - } - - /** - * Copied from: - *
https://github.com/grondag/canvas/commit/820bf754092ccaf8d0c169620c2ff575722d7d96 + /** + * Copied from: + *
https://github.com/grondag/canvas/commit/820bf754092ccaf8d0c169620c2ff575722d7d96 * *

Identical in function to {@link GL20C#glShaderSource(int, CharSequence)} but * passes a null pointer for string length to force the driver to rely on the null diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/DrawInstanced.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/instancing/DrawInstanced.java similarity index 71% rename from src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/DrawInstanced.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/instancing/DrawInstanced.java index d8cca0eb5..9d9070e15 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/DrawInstanced.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/instancing/DrawInstanced.java @@ -1,26 +1,28 @@ -package com.simibubi.create.foundation.render.backend.gl.versioned; +package com.simibubi.create.foundation.render.backend.gl.versioned.instancing; import org.lwjgl.opengl.ARBDrawInstanced; import org.lwjgl.opengl.EXTDrawInstanced; import org.lwjgl.opengl.GL31; import org.lwjgl.opengl.GLCapabilities; -public enum DrawInstanced implements GlVersioned { - GL31_DRAW_INSTANCED { - @Override - public boolean supported(GLCapabilities caps) { - return caps.OpenGL31; - } +import com.simibubi.create.foundation.render.backend.gl.versioned.GlVersioned; - @Override - public void drawArraysInstanced(int mode, int first, int count, int primcount) { - GL31.glDrawArraysInstanced(mode, first, count, primcount); - } - }, - ARB_DRAW_INSTANCED { - @Override - public boolean supported(GLCapabilities caps) { - return caps.GL_ARB_draw_instanced; +public enum DrawInstanced implements GlVersioned { + GL31_DRAW_INSTANCED { + @Override + public boolean supported(GLCapabilities caps) { + return caps.OpenGL31; + } + + @Override + public void drawArraysInstanced(int mode, int first, int count, int primcount) { + GL31.glDrawArraysInstanced(mode, first, count, primcount); + } + }, + ARB_DRAW_INSTANCED { + @Override + public boolean supported(GLCapabilities caps) { + return caps.GL_ARB_draw_instanced; } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/InstancedArrays.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/instancing/InstancedArrays.java similarity index 62% rename from src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/InstancedArrays.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/instancing/InstancedArrays.java index ee00f760f..be45f4896 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/InstancedArrays.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/instancing/InstancedArrays.java @@ -1,25 +1,27 @@ -package com.simibubi.create.foundation.render.backend.gl.versioned; +package com.simibubi.create.foundation.render.backend.gl.versioned.instancing; import org.lwjgl.opengl.ARBInstancedArrays; import org.lwjgl.opengl.GL33; import org.lwjgl.opengl.GLCapabilities; -public enum InstancedArrays implements GlVersioned { - GL33_INSTANCED_ARRAYS { - @Override - public boolean supported(GLCapabilities caps) { - return caps.OpenGL33; - } +import com.simibubi.create.foundation.render.backend.gl.versioned.GlVersioned; - @Override - public void vertexAttribDivisor(int index, int divisor) { - GL33.glVertexAttribDivisor(index, divisor); - } - }, - ARB_INSTANCED_ARRAYS { - @Override - public boolean supported(GLCapabilities caps) { - return caps.GL_ARB_instanced_arrays; +public enum InstancedArrays implements GlVersioned { + GL33_INSTANCED_ARRAYS { + @Override + public boolean supported(GLCapabilities caps) { + return caps.OpenGL33; + } + + @Override + public void vertexAttribDivisor(int index, int divisor) { + GL33.glVertexAttribDivisor(index, divisor); + } + }, + ARB_INSTANCED_ARRAYS { + @Override + public boolean supported(GLCapabilities caps) { + return caps.GL_ARB_instanced_arrays; } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/VertexArrayObject.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/instancing/VertexArrayObject.java similarity index 78% rename from src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/VertexArrayObject.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/instancing/VertexArrayObject.java index 356970877..28b8e013a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/VertexArrayObject.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/instancing/VertexArrayObject.java @@ -1,28 +1,30 @@ -package com.simibubi.create.foundation.render.backend.gl.versioned; +package com.simibubi.create.foundation.render.backend.gl.versioned.instancing; import org.lwjgl.opengl.ARBVertexArrayObject; import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GLCapabilities; +import com.simibubi.create.foundation.render.backend.gl.versioned.GlVersioned; + public enum VertexArrayObject implements GlVersioned { - GL30_VAO { - @Override - public boolean supported(GLCapabilities caps) { - return caps.OpenGL30; - } + GL30_VAO { + @Override + public boolean supported(GLCapabilities caps) { + return caps.OpenGL30; + } - @Override - public int genVertexArrays() { - return GL30.glGenVertexArrays(); - } + @Override + public int genVertexArrays() { + return GL30.glGenVertexArrays(); + } - @Override - public void bindVertexArray(int array) { - GL30.glBindVertexArray(array); - } + @Override + public void bindVertexArray(int array) { + GL30.glBindVertexArray(array); + } - @Override - public void deleteVertexArrays(int array) { + @Override + public void deleteVertexArrays(int array) { GL30.glDeleteVertexArrays(array); } }, diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java index 10f182d46..b6c16f21b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java @@ -83,7 +83,7 @@ public abstract class InstancedModel extends BufferedMod renderSetup(); if (glInstanceCount > 0) - Backend.compat.drawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); + Backend.compat.drawInstanced.drawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); }); } @@ -118,8 +118,8 @@ public abstract class InstancedModel extends BufferedMod getInstanceFormat().vertexAttribPointers(staticAttributes); for (int i = 0; i < getInstanceFormat().getShaderAttributeCount(); i++) { - Backend.compat.vertexAttribDivisor(i + staticAttributes, 1); - } + Backend.compat.instancedArrays.vertexAttribDivisor(i + staticAttributes, 1); + } } private void clearBufferTail() {