lower opengl requirement to 2.1 when higher versions are unsupported #21

Closed
rdh wants to merge 10 commits from rdh/celeritas:stonecutter into stonecutter
pull from: rdh/celeritas:stonecutter
4 changed files with 190 additions and 5 deletions
Showing only changes of commit d70456f172 - Show all commits

No files matched your search

@@ -1,7 +1,7 @@
package org.embeddedt.embeddium.impl.gl.array;
import org.embeddedt.embeddium.impl.gl.GlObject;
import org.lwjgl.opengl.GL30C;
import org.embeddedt.embeddium.impl.gl.util.VAOUtil;
/**
* Provides Vertex Array functionality on supported platforms.
@@ -10,11 +10,11 @@ public class GlVertexArray extends GlObject {
public static final int NULL_ARRAY_ID = 0;
public GlVertexArray() {
this.setHandle(GL30C.glGenVertexArrays());
this.setHandle(VAOUtil.glGenVertexArrays());
}
@Override
protected void destroyInternal() {
GL30C.glDeleteVertexArrays(this.handle());
VAOUtil.glDeleteVertexArrays(this.handle());
}
}
@@ -7,6 +7,7 @@ import org.embeddedt.embeddium.impl.gl.state.GlStateTracker;
import org.embeddedt.embeddium.impl.gl.sync.GlFence;
import org.embeddedt.embeddium.impl.gl.tessellation.*;
import org.embeddedt.embeddium.impl.gl.util.EnumBitField;
import org.embeddedt.embeddium.impl.gl.util.VAOUtil;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.*;
import java.nio.ByteBuffer;
@@ -86,7 +87,7 @@ public class GLRenderDevice implements RenderDevice {
@Override
public void bindVertexArray(GlVertexArray array) {
if (this.stateTracker.makeVertexArrayActive(array)) {
GL30C.glBindVertexArray(array.handle());
VAOUtil.glBindVertexArray(array.handle());
}
}
@@ -141,7 +142,7 @@ public class GLRenderDevice implements RenderDevice {
@Override
public void unbindVertexArray() {
if (this.stateTracker.makeVertexArrayActive(null)) {
GL30C.glBindVertexArray(GlVertexArray.NULL_ARRAY_ID);
VAOUtil.glBindVertexArray(GlVertexArray.NULL_ARRAY_ID);
}
}
@@ -0,0 +1,69 @@
package org.embeddedt.embeddium.impl.gl.util;
import org.lwjgl.opengl.GL;
import org.lwjgl.system.JNI;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.NativeType;
import java.nio.IntBuffer;
import static org.lwjgl.system.MemoryStack.stackGet;
import static org.lwjgl.system.MemoryUtil.memAddress;
/**
* Native bindings to the <a href="https://registry.khronos.org/OpenGL/extensions/APPLE/APPLE_vertex_array_object.txt">APPLE_vertex_array_object</a> extension.
*/
public class APPLEVertexArrayObject {
private static final long bindVertexArray = GL.getFunctionProvider().getFunctionAddress("glBindVertexArrayAPPLE");
private static final long deleteVertexArrays = GL.getFunctionProvider().getFunctionAddress("glDeleteVertexArrays");
private static final long genVertexArrays = GL.getFunctionProvider().getFunctionAddress("glGenVertexArraysAPPLE");
private static final long isVertexArray = GL.getFunctionProvider().getFunctionAddress("glIsVertexArrayAPPLE");
public static final boolean supported = bindVertexArray != 0;
public static void glBindVertexArray(@NativeType("GLuint") int array) {
JNI.callV(array, bindVertexArray);
}
public static void nglDeleteVertexArrays(int n, long arrays) {
JNI.callPV(n, arrays, deleteVertexArrays);
}
public static void glDeleteVertexArrays(@NativeType("GLuint const *") IntBuffer arrays) {
nglDeleteVertexArrays(arrays.remaining(), memAddress(arrays));
}
public static void glDeleteVertexArrays(@NativeType("GLuint const *") int array) {
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
try {
IntBuffer arrays = stack.callocInt(1);
arrays.put(0, array);
nglDeleteVertexArrays(1, memAddress(arrays));
} finally {
stack.setPointer(stackPointer);
}
}
public static void nglGenVertexArrays(int n, long arrays) {
JNI.callPV(n, arrays, genVertexArrays);
}
public static void glGenVertexArrays(@NativeType("GLuint *") IntBuffer arrays) {
nglGenVertexArrays(arrays.remaining(), memAddress(arrays));
}
public static int glGenVertexArrays() {
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
try {
IntBuffer arrays = stack.callocInt(1);
nglGenVertexArrays(1, memAddress(arrays));
return arrays.get(0);
} finally {
stack.setPointer(stackPointer);
}
}
public static boolean glIsVertexArrayAPPLE(@NativeType("GLuint") int array) {
return JNI.callZ(array, isVertexArray);
}
}
@@ -0,0 +1,115 @@
package org.embeddedt.embeddium.impl.gl.util;
import org.lwjgl.opengl.ARBVertexArrayObject;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.system.NativeType;
import java.nio.IntBuffer;
/**
* Provides an abstraction over various VAO implementations.
*/
public class VAOUtil {
public static final boolean coreSupported = GL.getCapabilities().OpenGL32;
public static final boolean arbSupported = GL.getCapabilities().GL_ARB_vertex_array_object;
public static final boolean appleSupported = APPLEVertexArrayObject.supported;
public static final boolean supported = coreSupported || arbSupported || appleSupported;
public static void glBindVertexArray(@NativeType("GLuint") int array) {
if (coreSupported) {
GL30C.glBindVertexArray(array);
} else if (arbSupported) {
ARBVertexArrayObject.glBindVertexArray(array);
} else if (appleSupported) {
APPLEVertexArrayObject.glBindVertexArray(array);
} else {
throw new UnsupportedOperationException("VAO not supported");
}
}
public static void nglDeleteVertexArrays(int n, long arrays) {
if (coreSupported) {
GL30C.nglDeleteVertexArrays(n, arrays);
} else if (arbSupported) {
ARBVertexArrayObject.nglDeleteVertexArrays(n, arrays);
} else if (appleSupported) {
APPLEVertexArrayObject.nglDeleteVertexArrays(n, arrays);
} else {
throw new UnsupportedOperationException("VAO not supported");
}
}
public static void glDeleteVertexArrays(@NativeType("GLuint const *") IntBuffer arrays) {
if (coreSupported) {
GL30C.glDeleteVertexArrays(arrays);
} else if (arbSupported) {
ARBVertexArrayObject.glDeleteVertexArrays(arrays);
} else if (appleSupported) {
APPLEVertexArrayObject.glDeleteVertexArrays(arrays);
} else {
throw new UnsupportedOperationException("VAO not supported");
}
}
public static void glDeleteVertexArrays(@NativeType("GLuint const *") int array) {
if (coreSupported) {
GL30C.glDeleteVertexArrays(array);
} else if (arbSupported) {
ARBVertexArrayObject.glDeleteVertexArrays(array);
} else if (appleSupported) {
APPLEVertexArrayObject.glDeleteVertexArrays(array);
} else {
throw new UnsupportedOperationException("VAO not supported");
}
}
public static void nglGenVertexArrays(int n, long arrays) {
if (coreSupported) {
GL30C.nglGenVertexArrays(n, arrays);
} else if (arbSupported) {
ARBVertexArrayObject.nglGenVertexArrays(n, arrays);
} else if (appleSupported) {
APPLEVertexArrayObject.nglGenVertexArrays(n, arrays);
} else {
throw new UnsupportedOperationException("VAO not supported");
}
}
public static void glGenVertexArrays(@NativeType("GLuint *") IntBuffer arrays) {
if (coreSupported) {
GL30C.glGenVertexArrays(arrays);
} else if (arbSupported) {
ARBVertexArrayObject.glGenVertexArrays(arrays);
} else if (appleSupported) {
APPLEVertexArrayObject.glGenVertexArrays(arrays);
} else {
throw new UnsupportedOperationException("VAO not supported");
}
}
public static int glGenVertexArrays() {
if (coreSupported) {
return GL30C.glGenVertexArrays();
} else if (arbSupported) {
return ARBVertexArrayObject.glGenVertexArrays();
} else if (appleSupported) {
return APPLEVertexArrayObject.glGenVertexArrays();
} else {
throw new UnsupportedOperationException("VAO not supported");
}
}
public static boolean glIsVertexArray(@NativeType("GLuint") int array) {
if (coreSupported) {
return GL30C.glIsVertexArray(array);
} else if (arbSupported) {
return ARBVertexArrayObject.glIsVertexArray(array);
} else if (appleSupported) {
return APPLEVertexArrayObject.glIsVertexArrayAPPLE(array);
} else {
throw new UnsupportedOperationException("VAO not supported");
}
}
}