Cull legacy compat boilerplate

- Minecraft is on GL32 now!
This commit is contained in:
Jozufozu 2021-12-07 22:47:05 -08:00
parent fef41658d0
commit 89c96aa026
15 changed files with 23 additions and 456 deletions

View file

@ -133,7 +133,7 @@ public class Backend {
compat = new GlCompat(capabilities);
instancedArrays = compat.vertexArrayObjectsSupported() && compat.drawInstancedSupported() && compat.instancedArraysSupported();
instancedArrays = compat.instancedArraysSupported();
enabled = FlwConfig.get()
.enabled() && !OptifineHandler.usingShaders();

View file

@ -1,21 +1,21 @@
package com.jozufozu.flywheel.backend.gl;
import com.jozufozu.flywheel.backend.Backend;
import com.mojang.blaze3d.platform.GlStateManager;
public class GlVertexArray extends GlObject {
public GlVertexArray() {
setHandle(Backend.getInstance().compat.vao.genVertexArrays());
setHandle(GlStateManager._glGenVertexArrays());
}
public void bind() {
Backend.getInstance().compat.vao.bindVertexArray(handle());
GlStateManager._glBindVertexArray(handle());
}
public static void unbind() {
Backend.getInstance().compat.vao.bindVertexArray(0);
GlStateManager._glBindVertexArray(0);
}
protected void deleteInternal(int handle) {
Backend.getInstance().compat.vao.deleteVertexArrays(handle);
GlStateManager._glDeleteVertexArrays(handle);
}
}

View file

@ -9,13 +9,6 @@ import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.backend.gl.versioned.framebuffer.Blit;
import com.jozufozu.flywheel.backend.gl.versioned.framebuffer.Framebuffer;
import com.jozufozu.flywheel.backend.gl.versioned.instancing.BaseVertex;
import com.jozufozu.flywheel.backend.gl.versioned.instancing.DrawInstanced;
import com.jozufozu.flywheel.backend.gl.versioned.instancing.InstancedArrays;
import com.jozufozu.flywheel.backend.gl.versioned.instancing.VertexArrayObject;
/**
* An instance of this class stores information about what OpenGL features are available.
* <br>
@ -25,50 +18,20 @@ import com.jozufozu.flywheel.backend.gl.versioned.instancing.VertexArrayObject;
public class GlCompat {
public final MapBufferRange mapBufferRange;
public final VertexArrayObject vao;
public final InstancedArrays instancedArrays;
public final DrawInstanced drawInstanced;
public final Blit blit;
public final Framebuffer fbo;
public final BufferStorage bufferStorage;
public final RGPixelFormat pixelFormat;
public final BaseVertex baseVertex;
public GlCompat(GLCapabilities caps) {
mapBufferRange = getLatest(MapBufferRange.class, caps);
vao = getLatest(VertexArrayObject.class, caps);
instancedArrays = getLatest(InstancedArrays.class, caps);
drawInstanced = getLatest(DrawInstanced.class, caps);
baseVertex = getLatest(BaseVertex.class, caps);
blit = getLatest(Blit.class, caps);
fbo = getLatest(Framebuffer.class, caps);
bufferStorage = getLatest(BufferStorage.class, caps);
pixelFormat = getLatest(RGPixelFormat.class, caps);
}
public boolean vertexArrayObjectsSupported() {
return vao != VertexArrayObject.UNSUPPORTED;
}
public boolean instancedArraysSupported() {
return instancedArrays != InstancedArrays.UNSUPPORTED;
}
public boolean drawInstancedSupported() {
return drawInstanced != DrawInstanced.UNSUPPORTED;
}
public boolean fbosSupported() {
return fbo != Framebuffer.UNSUPPORTED;
}
public boolean blitSupported() {
return blit != Blit.UNSUPPORTED;
}
public boolean bufferStorageSupported() {
return bufferStorage != BufferStorage.UNSUPPORTED;
}

View file

@ -1,11 +1,9 @@
package com.jozufozu.flywheel.backend.gl.versioned.instancing;
package com.jozufozu.flywheel.backend.gl.versioned;
import org.lwjgl.opengl.ARBInstancedArrays;
import org.lwjgl.opengl.GL33;
import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.gl.versioned.GlVersioned;
public enum InstancedArrays implements GlVersioned {
GL33_INSTANCED_ARRAYS {
@Override

View file

@ -1,77 +0,0 @@
package com.jozufozu.flywheel.backend.gl.versioned;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GLCapabilities;
public enum RGPixelFormat implements GlVersioned {
GL30_RG {
@Override
public boolean supported(GLCapabilities caps) {
return caps.OpenGL30;
}
@Override
public int internalFormat() {
return GL30.GL_RG8;
}
@Override
public int format() {
return GL30.GL_RG;
}
@Override
public int byteCount() {
return 2;
}
},
GL11_RGB {
@Override
public boolean supported(GLCapabilities caps) {
return caps.OpenGL11;
}
@Override
public int internalFormat() {
return GL11.GL_RGB8;
}
@Override
public int format() {
return GL11.GL_RGB;
}
@Override
public int byteCount() {
return 3;
}
},
UNSUPPORTED {
@Override
public boolean supported(GLCapabilities caps) {
return true;
}
@Override
public int internalFormat() {
throw new UnsupportedOperationException();
}
@Override
public int format() {
throw new UnsupportedOperationException();
}
@Override
public int byteCount() {
throw new UnsupportedOperationException();
}
};
public abstract int internalFormat();
public abstract int format();
public abstract int byteCount();
}

View file

@ -1,45 +0,0 @@
package com.jozufozu.flywheel.backend.gl.versioned.framebuffer;
import org.lwjgl.opengl.EXTFramebufferBlit;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.gl.versioned.GlVersioned;
public enum Blit implements GlVersioned {
CORE {
@Override
public boolean supported(GLCapabilities caps) {
return caps.OpenGL30;
}
@Override
public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) {
GL30.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
}
},
EXT {
@Override
public boolean supported(GLCapabilities caps) {
return caps.GL_EXT_framebuffer_blit;
}
@Override
public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) {
EXTFramebufferBlit.glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
}
},
UNSUPPORTED {
@Override
public boolean supported(GLCapabilities caps) {
return true;
}
@Override
public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) {
throw new UnsupportedOperationException("Framebuffer blitting not supported.");
}
};
public abstract void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter);
}

View file

@ -1,57 +0,0 @@
package com.jozufozu.flywheel.backend.gl.versioned.framebuffer;
import org.lwjgl.opengl.ARBFramebufferObject;
import org.lwjgl.opengl.EXTFramebufferObject;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.gl.versioned.GlVersioned;
public enum Framebuffer implements GlVersioned {
CORE {
@Override
public boolean supported(GLCapabilities caps) {
return caps.OpenGL30;
}
@Override
public void bindFramebuffer(int target, int framebuffer) {
GL30C.glBindFramebuffer(target, framebuffer);
}
},
ARB {
@Override
public boolean supported(GLCapabilities caps) {
return caps.GL_ARB_framebuffer_object;
}
@Override
public void bindFramebuffer(int target, int framebuffer) {
ARBFramebufferObject.glBindFramebuffer(target, framebuffer);
}
},
EXT {
@Override
public boolean supported(GLCapabilities caps) {
return caps.GL_EXT_framebuffer_object;
}
@Override
public void bindFramebuffer(int target, int framebuffer) {
EXTFramebufferObject.glBindFramebufferEXT(target, framebuffer);
}
},
UNSUPPORTED {
@Override
public boolean supported(GLCapabilities caps) {
return true;
}
@Override
public void bindFramebuffer(int target, int framebuffer) {
throw new UnsupportedOperationException("Framebuffers not supported");
}
};
public abstract void bindFramebuffer(int target, int framebuffer);
}

View file

@ -1,60 +0,0 @@
package com.jozufozu.flywheel.backend.gl.versioned.instancing;
import org.lwjgl.opengl.ARBDrawElementsBaseVertex;
import org.lwjgl.opengl.GL32;
import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.gl.GlNumericType;
import com.jozufozu.flywheel.backend.gl.GlPrimitive;
import com.jozufozu.flywheel.backend.gl.versioned.GlVersioned;
public enum BaseVertex implements GlVersioned {
GL31_CORE {
@Override
public boolean supported(GLCapabilities caps) {
return caps.OpenGL31;
}
@Override
public void drawElementsInstancedBaseVertex(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int instanceCount, int baseVertex) {
GL32.glDrawElementsInstancedBaseVertex(mode.glEnum, elementCount, type.getGlEnum(), indices, instanceCount, baseVertex);
}
@Override
public void drawElementsBaseVertex(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int baseVertex) {
GL32.glDrawElementsBaseVertex(mode.glEnum, elementCount, type.getGlEnum(), indices, baseVertex);
}
},
ARB {
@Override
public boolean supported(GLCapabilities caps) {
return caps.GL_ARB_draw_elements_base_vertex;
}
@Override
public void drawElementsInstancedBaseVertex(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int instanceCount, int baseVertex) {
ARBDrawElementsBaseVertex.glDrawElementsInstancedBaseVertex(mode.glEnum, elementCount, type.getGlEnum(), indices, instanceCount, baseVertex);
}
@Override
public void drawElementsBaseVertex(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int baseVertex) {
ARBDrawElementsBaseVertex.glDrawElementsBaseVertex(mode.glEnum, elementCount, type.getGlEnum(), indices, baseVertex);
}
},
UNSUPPORTED {
@Override
public boolean supported(GLCapabilities caps) {
return true;
}
};
public void drawElementsInstancedBaseVertex(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int instanceCount, int baseVertex) {
throw new UnsupportedOperationException();
}
public void drawElementsBaseVertex(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int baseVertex) {
throw new UnsupportedOperationException();
}
}

View file

@ -1,76 +0,0 @@
package com.jozufozu.flywheel.backend.gl.versioned.instancing;
import org.lwjgl.opengl.ARBDrawInstanced;
import org.lwjgl.opengl.EXTDrawInstanced;
import org.lwjgl.opengl.GL31;
import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.gl.GlNumericType;
import com.jozufozu.flywheel.backend.gl.GlPrimitive;
import com.jozufozu.flywheel.backend.gl.versioned.GlVersioned;
public enum DrawInstanced implements GlVersioned {
GL31_CORE {
@Override
public boolean supported(GLCapabilities caps) {
return caps.OpenGL31;
}
@Override
public void drawArraysInstanced(GlPrimitive mode, int first, int count, int primcount) {
GL31.glDrawArraysInstanced(mode.glEnum, first, count, primcount);
}
@Override
public void drawElementsInstanced(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int primcount) {
GL31.glDrawElementsInstanced(mode.glEnum, elementCount, type.getGlEnum(), indices, primcount);
}
},
ARB {
@Override
public boolean supported(GLCapabilities caps) {
return caps.GL_ARB_draw_instanced;
}
@Override
public void drawArraysInstanced(GlPrimitive mode, int first, int count, int primcount) {
ARBDrawInstanced.glDrawArraysInstancedARB(mode.glEnum, first, count, primcount);
}
@Override
public void drawElementsInstanced(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int primcount) {
ARBDrawInstanced.glDrawElementsInstancedARB(mode.glEnum, elementCount, type.getGlEnum(), indices, primcount);
}
},
EXT {
@Override
public boolean supported(GLCapabilities caps) {
return caps.GL_EXT_draw_instanced;
}
@Override
public void drawArraysInstanced(GlPrimitive mode, int first, int count, int primcount) {
EXTDrawInstanced.glDrawArraysInstancedEXT(mode.glEnum, first, count, primcount);
}
@Override
public void drawElementsInstanced(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int primcount) {
EXTDrawInstanced.glDrawElementsInstancedEXT(mode.glEnum, elementCount, type.getGlEnum(), indices, primcount);
}
},
UNSUPPORTED {
@Override
public boolean supported(GLCapabilities caps) {
return true;
}
};
public void drawArraysInstanced(GlPrimitive mode, int first, int count, int primcount) {
throw new UnsupportedOperationException();
}
public void drawElementsInstanced(GlPrimitive mode, int elementCount, GlNumericType type, long indices, int primcount) {
throw new UnsupportedOperationException();
}
}

View file

@ -1,79 +0,0 @@
package com.jozufozu.flywheel.backend.gl.versioned.instancing;
import org.lwjgl.opengl.ARBVertexArrayObject;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.gl.versioned.GlVersioned;
public enum VertexArrayObject implements GlVersioned {
GL30_VAO {
@Override
public boolean supported(GLCapabilities caps) {
return caps.OpenGL30;
}
@Override
public int genVertexArrays() {
return GL30.glGenVertexArrays();
}
@Override
public void bindVertexArray(int array) {
GL30.glBindVertexArray(array);
}
@Override
public void deleteVertexArrays(int array) {
GL30.glDeleteVertexArrays(array);
}
},
ARB_VAO {
@Override
public boolean supported(GLCapabilities caps) {
return caps.GL_ARB_vertex_array_object;
}
@Override
public int genVertexArrays() {
return ARBVertexArrayObject.glGenVertexArrays();
}
@Override
public void bindVertexArray(int array) {
ARBVertexArrayObject.glBindVertexArray(array);
}
@Override
public void deleteVertexArrays(int array) {
ARBVertexArrayObject.glDeleteVertexArrays(array);
}
},
UNSUPPORTED {
@Override
public boolean supported(GLCapabilities caps) {
return true;
}
@Override
public int genVertexArrays() {
throw new UnsupportedOperationException();
}
@Override
public void bindVertexArray(int array) {
throw new UnsupportedOperationException();
}
@Override
public void deleteVertexArrays(int array) {
throw new UnsupportedOperationException();
}
};
public abstract int genVertexArrays();
public abstract void bindVertexArray(int array);
public abstract void deleteVertexArrays(int array);
}

View file

@ -3,8 +3,8 @@ package com.jozufozu.flywheel.backend.instancing;
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstanceManager;
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
import com.jozufozu.flywheel.backend.material.Engine;
import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine;
import com.jozufozu.flywheel.backend.material.batching.BatchingEngine;
import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine;
import com.jozufozu.flywheel.core.Contexts;
import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.event.BeginFrameEvent;
@ -28,7 +28,7 @@ public class InstanceWorld {
protected final InstanceManager<BlockEntity> tileEntityInstanceManager;
public InstanceWorld() {
// TODO: finish impl
if (false) {
engine = new BatchingEngine();

View file

@ -2,7 +2,8 @@ package com.jozufozu.flywheel.backend.model;
import static org.lwjgl.opengl.GL11.glDrawArrays;
import com.jozufozu.flywheel.backend.Backend;
import org.lwjgl.opengl.GL31;
import com.jozufozu.flywheel.backend.gl.GlPrimitive;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
@ -74,7 +75,7 @@ public class BufferedModel implements IBufferedModel {
public void drawInstances(int instanceCount) {
if (!valid()) return;
Backend.getInstance().compat.drawInstanced.drawArraysInstanced(primitiveMode, 0, getVertexCount(), instanceCount);
GL31.glDrawArraysInstanced(primitiveMode.glEnum, 0, getVertexCount(), instanceCount);
}
public void delete() {

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.backend.model;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL31;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.GlPrimitive;
import com.jozufozu.flywheel.core.model.IModel;
@ -43,6 +43,6 @@ public class IndexedModel extends BufferedModel {
public void drawInstances(int instanceCount) {
if (!valid()) return;
Backend.getInstance().compat.drawInstanced.drawElementsInstanced(primitiveMode, ebo.elementCount, ebo.eboIndexType, 0, instanceCount);
GL31.glDrawElementsInstanced(primitiveMode.glEnum, ebo.elementCount, ebo.eboIndexType.getGlEnum(), 0, instanceCount);
}
}

View file

@ -3,7 +3,8 @@ package com.jozufozu.flywheel.backend.model;
import java.util.ArrayList;
import java.util.List;
import com.jozufozu.flywheel.backend.Backend;
import org.lwjgl.opengl.GL32;
import com.jozufozu.flywheel.backend.gl.GlPrimitive;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
@ -195,7 +196,7 @@ public class ModelPool implements ModelAllocator {
@Override
public void drawCall() {
Backend.getInstance().compat.baseVertex.drawElementsBaseVertex(GlPrimitive.TRIANGLES, ebo.elementCount, ebo.eboIndexType, 0, first);
GL32.glDrawElementsBaseVertex(GlPrimitive.TRIANGLES.glEnum, ebo.elementCount, ebo.eboIndexType.getGlEnum(), 0, first);
}
@Override
@ -206,7 +207,7 @@ public class ModelPool implements ModelAllocator {
//Backend.log.info(StringUtil.args("drawElementsInstancedBaseVertex", GlPrimitive.TRIANGLES, ebo.elementCount, ebo.eboIndexType, 0, instanceCount, first));
Backend.getInstance().compat.baseVertex.drawElementsInstancedBaseVertex(GlPrimitive.TRIANGLES, ebo.elementCount, ebo.eboIndexType, 0, instanceCount, first);
GL32.glDrawElementsInstancedBaseVertex(GlPrimitive.TRIANGLES.glEnum, ebo.elementCount, ebo.eboIndexType.getGlEnum(), 0, instanceCount, first);
}
@Override

View file

@ -23,10 +23,10 @@ import static org.lwjgl.opengl.GL13.GL_TEXTURE4;
import static org.lwjgl.opengl.GL13.glActiveTexture;
import static org.lwjgl.opengl.GL14.GL_MIRRORED_REPEAT;
import com.jozufozu.flywheel.backend.Backend;
import org.lwjgl.opengl.GL30;
import com.jozufozu.flywheel.backend.gl.GlTexture;
import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
import com.jozufozu.flywheel.backend.gl.versioned.RGPixelFormat;
import net.minecraft.world.level.LightLayer;
@ -35,7 +35,6 @@ public class GPULightVolume extends LightVolume {
protected final GridAlignedBB sampleVolume = new GridAlignedBB();
private final GlTexture glTexture;
private final RGPixelFormat pixelFormat;
private final GlTextureUnit textureUnit = GlTextureUnit.T4;
protected boolean bufferDirty;
@ -43,7 +42,6 @@ public class GPULightVolume extends LightVolume {
super(sampleVolume);
this.sampleVolume.assign(sampleVolume);
pixelFormat = Backend.getInstance().compat.pixelFormat;
glTexture = new GlTexture(GL_TEXTURE_3D);
// allocate space for the texture
@ -53,7 +51,7 @@ public class GPULightVolume extends LightVolume {
int sizeX = box.sizeX();
int sizeY = box.sizeY();
int sizeZ = box.sizeZ();
glTexImage3D(GL_TEXTURE_3D, 0, pixelFormat.internalFormat(), sizeX, sizeY, sizeZ, 0, pixelFormat.format(), GL_UNSIGNED_BYTE, 0);
glTexImage3D(GL_TEXTURE_3D, 0, GL30.GL_RG8, sizeX, sizeY, sizeZ, 0, GL30.GL_RG, GL_UNSIGNED_BYTE, 0);
glTexture.unbind();
glActiveTexture(GL_TEXTURE0);
@ -94,7 +92,7 @@ public class GPULightVolume extends LightVolume {
int sizeY = box.sizeY();
int sizeZ = box.sizeZ();
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, sizeX, sizeY, sizeZ, pixelFormat.format(), GL_UNSIGNED_BYTE, lightData);
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, sizeX, sizeY, sizeZ, GL30.GL_RG, GL_UNSIGNED_BYTE, lightData);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4 is the default
bufferDirty = false;
@ -150,7 +148,7 @@ public class GPULightVolume extends LightVolume {
@Override
protected int getStride() {
return Backend.getInstance().compat.pixelFormat.byteCount();
return 2;
}
@Override