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 Vector3d center;
public float radius; public float radius;
public float feather; public float feather;
public float fade;
public float strength = 1; public float strength = 1;
public boolean hsv; public boolean hsv;
@ -146,6 +147,11 @@ public class SphereFilterProgram extends GlProgram {
return this; return this;
} }
public FilterSphere setFade(float fade) {
this.fade = fade;
return this;
}
public FilterSphere setStrength(float strength) { public FilterSphere setStrength(float strength) {
this.strength = strength; this.strength = strength;
return this; return this;
@ -168,9 +174,9 @@ public class SphereFilterProgram extends GlProgram {
(float) center.z, (float) center.z,
radius, radius,
feather, feather,
fade,
strength, strength,
hsv ? 1f : 0f, hsv ? 1f : 0f,
0 // padding, we could add more parameters here
}); });
buf.put(RenderUtil.writeMatrix(filter)); buf.put(RenderUtil.writeMatrix(filter));

View file

@ -48,15 +48,15 @@ public class GlBuffer extends GlObject {
} }
public void map(int length, Consumer<ByteBuffer> upload) { 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) { 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) { 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) { protected void deleteInternal(int handle) {

View file

@ -6,15 +6,15 @@ import com.simibubi.create.foundation.render.backend.Backend;
public class GlVertexArray extends GlObject { public class GlVertexArray extends GlObject {
public GlVertexArray() { public GlVertexArray() {
setHandle(Backend.compat.genVertexArrays()); setHandle(Backend.compat.vao.genVertexArrays());
} }
public void bind() { public void bind() {
Backend.compat.bindVertexArray(handle()); Backend.compat.vao.bindVertexArray(handle());
} }
public void unbind() { public void unbind() {
Backend.compat.bindVertexArray(0); Backend.compat.vao.bindVertexArray(0);
} }
public void with(Consumer<GlVertexArray> action) { public void with(Consumer<GlVertexArray> action) {
@ -24,6 +24,6 @@ public class GlVertexArray extends GlObject {
} }
protected void deleteInternal(int handle) { 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.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import java.util.function.Consumer;
import org.lwjgl.PointerBuffer; import org.lwjgl.PointerBuffer;
import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL20C;
@ -10,58 +9,44 @@ import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil; 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 * An instance of this class stores information
* about what OpenGL features are available. * about what OpenGL features are available.
* * <p>
* Each field stores an enum variant that provides access to the * Each field stores an enum variant that provides access to the
* most appropriate version of a feature for the current system. * most appropriate version of a feature for the current system.
*/ */
public class GlCompat { public class GlCompat {
public final MapBuffer mapBuffer; public final MapBuffer mapBuffer;
public final VertexArrayObject vertexArrayObject; public final VertexArrayObject vao;
public final InstancedArrays instancedArrays; public final InstancedArrays instancedArrays;
public final DrawInstanced drawInstanced; public final DrawInstanced drawInstanced;
public final Blit blit;
public final Framebuffer fbo;
public final RGPixelFormat pixelFormat; public final RGPixelFormat pixelFormat;
public GlCompat(GLCapabilities caps) { public GlCompat(GLCapabilities caps) {
mapBuffer = getLatest(MapBuffer.class, caps); mapBuffer = getLatest(MapBuffer.class, caps);
vertexArrayObject = getLatest(VertexArrayObject.class, caps); vao = getLatest(VertexArrayObject.class, caps);
instancedArrays = getLatest(InstancedArrays.class, caps); instancedArrays = getLatest(InstancedArrays.class, caps);
drawInstanced = getLatest(DrawInstanced.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 void vertexAttribDivisor(int index, int divisor) {
instancedArrays.vertexAttribDivisor(index, divisor);
}
public void drawArraysInstanced(int mode, int first, int count, int primcount) {
drawInstanced.drawArraysInstanced(mode, first, count, primcount);
}
public int genVertexArrays() {
return vertexArrayObject.genVertexArrays();
}
public void deleteVertexArrays(int array) {
vertexArrayObject.deleteVertexArrays(array);
}
public void bindVertexArray(int array) {
vertexArrayObject.bindVertexArray(array);
}
public boolean vertexArrayObjectsSupported() { public boolean vertexArrayObjectsSupported() {
return vertexArrayObject != VertexArrayObject.UNSUPPORTED; return vao != VertexArrayObject.UNSUPPORTED;
} }
public boolean instancedArraysSupported() { public boolean instancedArraysSupported() {
@ -72,6 +57,14 @@ public class GlCompat {
return drawInstanced != DrawInstanced.UNSUPPORTED; return drawInstanced != DrawInstanced.UNSUPPORTED;
} }
public boolean fbosSupported() {
return fbo != Framebuffer.UNSUPPORTED;
}
public boolean blitSupported() {
return blit != Blit.UNSUPPORTED;
}
/** /**
* Get the most compatible version of a specific OpenGL feature by iterating over enum constants in order. * Get the most compatible version of a specific OpenGL feature by iterating over enum constants in order.
* *

View file

@ -1,10 +1,12 @@
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.ARBDrawInstanced;
import org.lwjgl.opengl.EXTDrawInstanced; import org.lwjgl.opengl.EXTDrawInstanced;
import org.lwjgl.opengl.GL31; import org.lwjgl.opengl.GL31;
import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.opengl.GLCapabilities;
import com.simibubi.create.foundation.render.backend.gl.versioned.GlVersioned;
public enum DrawInstanced implements GlVersioned { public enum DrawInstanced implements GlVersioned {
GL31_DRAW_INSTANCED { GL31_DRAW_INSTANCED {
@Override @Override

View file

@ -1,9 +1,11 @@
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.ARBInstancedArrays;
import org.lwjgl.opengl.GL33; import org.lwjgl.opengl.GL33;
import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.opengl.GLCapabilities;
import com.simibubi.create.foundation.render.backend.gl.versioned.GlVersioned;
public enum InstancedArrays implements GlVersioned { public enum InstancedArrays implements GlVersioned {
GL33_INSTANCED_ARRAYS { GL33_INSTANCED_ARRAYS {
@Override @Override

View file

@ -1,9 +1,11 @@
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.ARBVertexArrayObject;
import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.opengl.GLCapabilities;
import com.simibubi.create.foundation.render.backend.gl.versioned.GlVersioned;
public enum VertexArrayObject implements GlVersioned { public enum VertexArrayObject implements GlVersioned {
GL30_VAO { GL30_VAO {
@Override @Override

View file

@ -83,7 +83,7 @@ public abstract class InstancedModel<D extends InstanceData> extends BufferedMod
renderSetup(); renderSetup();
if (glInstanceCount > 0) if (glInstanceCount > 0)
Backend.compat.drawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); Backend.compat.drawInstanced.drawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount);
}); });
} }
@ -118,7 +118,7 @@ public abstract class InstancedModel<D extends InstanceData> extends BufferedMod
getInstanceFormat().vertexAttribPointers(staticAttributes); getInstanceFormat().vertexAttribPointers(staticAttributes);
for (int i = 0; i < getInstanceFormat().getShaderAttributeCount(); i++) { for (int i = 0; i < getInstanceFormat().getShaderAttributeCount(); i++) {
Backend.compat.vertexAttribDivisor(i + staticAttributes, 1); Backend.compat.instancedArrays.vertexAttribDivisor(i + staticAttributes, 1);
} }
} }