Remove compat layer wrapper functions

This commit is contained in:
JozsefA 2021-04-17 18:54:57 -07:00
parent 83dc241cd2
commit 128a2c2e06
8 changed files with 132 additions and 127 deletions

View file

@ -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));

View file

@ -48,15 +48,15 @@ public class GlBuffer extends GlObject {
}
public void map(int length, Consumer<ByteBuffer> upload) {
Backend.compat.mapBuffer(bufferType, 0, length, upload);
Backend.compat.mapBuffer.mapBuffer(bufferType, 0, length, upload);
}
public void map(int offset, int length, Consumer<ByteBuffer> 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<ByteBuffer> upload) {
Backend.compat.mapBuffer(type, offset, length, upload);
Backend.compat.mapBuffer.mapBuffer(type, offset, length, upload);
}
protected void deleteInternal(int handle) {

View file

@ -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<GlVertexArray> 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);
}
}

View file

@ -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.
*
* <p>
* 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<ByteBuffer> 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 <V> The type of the versioning enum.
* @return The first defined enum variant to return true.
*/
public static <V extends Enum<V> & GlVersioned> V getLatest(Class<V> 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 <V> The type of the versioning enum.
* @return The first defined enum variant to return true.
*/
public static <V extends Enum<V> & GlVersioned> V getLatest(Class<V> 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:
* <br> https://github.com/grondag/canvas/commit/820bf754092ccaf8d0c169620c2ff575722d7d96
/**
* Copied from:
* <br> https://github.com/grondag/canvas/commit/820bf754092ccaf8d0c169620c2ff575722d7d96
*
* <p>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

View file

@ -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

View file

@ -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

View file

@ -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);
}
},

View file

@ -83,7 +83,7 @@ public abstract class InstancedModel<D extends InstanceData> 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<D extends InstanceData> 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() {