mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-05 22:45:50 +00:00
PBO/VBO checks now query OpenGL directly instead of keeping track of the currently bound buffers
This commit is contained in:
parent
1d521cf604
commit
d633986260
13 changed files with 54 additions and 109 deletions
|
|
@ -32,6 +32,7 @@
|
|||
package org.lwjgl.opengl;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
|
|
@ -57,51 +58,66 @@ class GLChecks {
|
|||
return StateTracker.getReferencesStack().getReferences();
|
||||
}
|
||||
|
||||
private static boolean checkBufferObject(int buffer_enum, boolean state) {
|
||||
IntBuffer scratch_buffer = GLContext.getCapabilities().scratch_int_buffer;
|
||||
GL11.glGetInteger(buffer_enum, scratch_buffer);
|
||||
boolean is_enabled = scratch_buffer.get(0) != 0;
|
||||
return state == is_enabled;
|
||||
}
|
||||
|
||||
/** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
|
||||
static void ensureArrayVBOdisabled() {
|
||||
if (StateTracker.getVBOArrayStack().getState() != 0)
|
||||
if ((GLContext.getCapabilities().OpenGL15 && !checkBufferObject(GL15.GL_ARRAY_BUFFER_BINDING, false) ||
|
||||
(GLContext.getCapabilities().GL_ARB_vertex_buffer_object && !checkBufferObject(ARBVertexBufferObject.GL_ARRAY_BUFFER_BINDING_ARB, false))))
|
||||
throw new OpenGLException("Cannot use Buffers when Array Buffer Object is enabled");
|
||||
}
|
||||
|
||||
/** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
|
||||
static void ensureArrayVBOenabled() {
|
||||
if (StateTracker.getVBOArrayStack().getState() == 0)
|
||||
if ((GLContext.getCapabilities().OpenGL15 && !checkBufferObject(GL15.GL_ARRAY_BUFFER_BINDING, true) ||
|
||||
(GLContext.getCapabilities().GL_ARB_vertex_buffer_object && !checkBufferObject(ARBVertexBufferObject.GL_ARRAY_BUFFER_BINDING_ARB, true))))
|
||||
throw new OpenGLException("Cannot use offsets when Array Buffer Object is disabled");
|
||||
}
|
||||
|
||||
/** Helper method to ensure that element array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
|
||||
static void ensureElementVBOdisabled() {
|
||||
if (StateTracker.getVBOElementStack().getState() != 0)
|
||||
if ((GLContext.getCapabilities().OpenGL15 && !checkBufferObject(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING, false) ||
|
||||
(GLContext.getCapabilities().GL_ARB_vertex_buffer_object && !checkBufferObject(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, false))))
|
||||
throw new OpenGLException("Cannot use Buffers when Element Array Buffer Object is enabled");
|
||||
}
|
||||
|
||||
/** Helper method to ensure that element array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
|
||||
static void ensureElementVBOenabled() {
|
||||
if (StateTracker.getVBOElementStack().getState() == 0)
|
||||
if ((GLContext.getCapabilities().OpenGL15 && !checkBufferObject(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING, true) ||
|
||||
(GLContext.getCapabilities().GL_ARB_vertex_buffer_object && !checkBufferObject(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, true))))
|
||||
throw new OpenGLException("Cannot use offsets when Element Array Buffer Object is disabled");
|
||||
}
|
||||
|
||||
/** Helper method to ensure that pixel pack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
|
||||
static void ensurePackPBOdisabled() {
|
||||
if (StateTracker.getPBOPackStack().getState() != 0)
|
||||
if ((GLContext.getCapabilities().GL_ARB_pixel_buffer_object && !checkBufferObject(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_BINDING_ARB, false) ||
|
||||
(GLContext.getCapabilities().GL_EXT_pixel_buffer_object && !checkBufferObject(EXTPixelBufferObject.GL_PIXEL_PACK_BUFFER_BINDING_EXT, false))))
|
||||
throw new OpenGLException("Cannot use Buffers when Pixel Pack Buffer Object is enabled");
|
||||
}
|
||||
|
||||
/** Helper method to ensure that pixel pack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
|
||||
static void ensurePackPBOenabled() {
|
||||
if (StateTracker.getPBOPackStack().getState() == 0)
|
||||
if ((GLContext.getCapabilities().GL_ARB_pixel_buffer_object && !checkBufferObject(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_BINDING_ARB, true) ||
|
||||
(GLContext.getCapabilities().GL_EXT_pixel_buffer_object && !checkBufferObject(EXTPixelBufferObject.GL_PIXEL_PACK_BUFFER_BINDING_EXT, true))))
|
||||
throw new OpenGLException("Cannot use offsets when Pixel Pack Buffer Object is disabled");
|
||||
}
|
||||
|
||||
/** Helper method to ensure that pixel unpack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
|
||||
static void ensureUnpackPBOdisabled() {
|
||||
if (StateTracker.getPBOUnpackStack().getState() != 0)
|
||||
if ((GLContext.getCapabilities().GL_ARB_pixel_buffer_object && !checkBufferObject(ARBPixelBufferObject.GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, false) ||
|
||||
(GLContext.getCapabilities().GL_EXT_pixel_buffer_object && !checkBufferObject(EXTPixelBufferObject.GL_PIXEL_UNPACK_BUFFER_BINDING_EXT, false))))
|
||||
throw new OpenGLException("Cannot use Buffers when Pixel Unpack Buffer Object is enabled");
|
||||
}
|
||||
|
||||
/** Helper method to ensure that pixel unpack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
|
||||
static void ensureUnpackPBOenabled() {
|
||||
if (StateTracker.getPBOUnpackStack().getState() == 0)
|
||||
if ((GLContext.getCapabilities().GL_ARB_pixel_buffer_object && !checkBufferObject(ARBPixelBufferObject.GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, true) ||
|
||||
(GLContext.getCapabilities().GL_EXT_pixel_buffer_object && !checkBufferObject(EXTPixelBufferObject.GL_PIXEL_UNPACK_BUFFER_BINDING_EXT, true))))
|
||||
throw new OpenGLException("Cannot use offsets when Pixel Unpack Buffer Object is disabled");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,12 +35,6 @@ import java.nio.IntBuffer;
|
|||
|
||||
/** Track Vertex Buffer Objects by context. */
|
||||
final class StateTracker {
|
||||
private final StateStack vbo_array_stack;
|
||||
private final StateStack vbo_element_stack;
|
||||
|
||||
private final StateStack pbo_pack_stack;
|
||||
private final StateStack pbo_unpack_stack;
|
||||
|
||||
private final ReferencesStack references_stack;
|
||||
|
||||
private final StateStack attrib_stack;
|
||||
|
|
@ -48,12 +42,6 @@ final class StateTracker {
|
|||
StateTracker() {
|
||||
int stack_size = Math.max(1, Util.glGetInteger(GL11.GL_MAX_CLIENT_ATTRIB_STACK_DEPTH));
|
||||
|
||||
vbo_array_stack = new StateStack(stack_size, 0);
|
||||
vbo_element_stack = new StateStack(stack_size, 0);
|
||||
|
||||
pbo_pack_stack = new StateStack(stack_size, 0);
|
||||
pbo_unpack_stack = new StateStack(stack_size, 0);
|
||||
|
||||
references_stack = new ReferencesStack(stack_size);
|
||||
|
||||
attrib_stack = new StateStack(stack_size, 0);
|
||||
|
|
@ -61,10 +49,6 @@ final class StateTracker {
|
|||
|
||||
static void popAttrib() {
|
||||
if ((getClientAttribStack().popState() & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0) {
|
||||
getVBOArrayStack().popState();
|
||||
getVBOElementStack().popState();
|
||||
getPBOPackStack().popState();
|
||||
getPBOUnpackStack().popState();
|
||||
getReferencesStack().popState();
|
||||
}
|
||||
}
|
||||
|
|
@ -73,63 +57,10 @@ final class StateTracker {
|
|||
getClientAttribStack().pushState();
|
||||
getClientAttribStack().setState(mask);
|
||||
if ((mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0) {
|
||||
getVBOArrayStack().pushState();
|
||||
getVBOElementStack().pushState();
|
||||
getPBOPackStack().pushState();
|
||||
getPBOUnpackStack().pushState();
|
||||
getReferencesStack().pushState();
|
||||
}
|
||||
}
|
||||
|
||||
static void deleteBuffers(IntBuffer buffers) {
|
||||
for (int i = buffers.position(); i < buffers.limit(); i++) {
|
||||
int buffer_handle = buffers.get(i);
|
||||
if (getVBOArrayStack().getState() == buffer_handle)
|
||||
getVBOArrayStack().setState(0);
|
||||
if (getVBOElementStack().getState() == buffer_handle)
|
||||
getVBOElementStack().setState(0);
|
||||
if (getPBOPackStack().getState() == buffer_handle)
|
||||
getPBOPackStack().setState(0);
|
||||
if (getPBOUnpackStack().getState() == buffer_handle)
|
||||
getPBOUnpackStack().setState(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void bindBuffer(int target, int buffer) {
|
||||
switch ( target ) {
|
||||
case ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB:
|
||||
getVBOArrayStack().setState(buffer);
|
||||
break;
|
||||
case ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB:
|
||||
getVBOElementStack().setState(buffer);
|
||||
break;
|
||||
case ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB:
|
||||
getPBOPackStack().setState(buffer);
|
||||
break;
|
||||
case ARBPixelBufferObject.GL_PIXEL_UNPACK_BUFFER_ARB:
|
||||
getPBOUnpackStack().setState(buffer);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported VBO target " + target);
|
||||
}
|
||||
}
|
||||
|
||||
static StateStack getVBOArrayStack() {
|
||||
return GLContext.getCapabilities().tracker.vbo_array_stack;
|
||||
}
|
||||
|
||||
static StateStack getVBOElementStack() {
|
||||
return GLContext.getCapabilities().tracker.vbo_element_stack;
|
||||
}
|
||||
|
||||
static StateStack getPBOPackStack() {
|
||||
return GLContext.getCapabilities().tracker.pbo_pack_stack;
|
||||
}
|
||||
|
||||
static StateStack getPBOUnpackStack() {
|
||||
return GLContext.getCapabilities().tracker.pbo_unpack_stack;
|
||||
}
|
||||
|
||||
static ReferencesStack getReferencesStack() {
|
||||
return GLContext.getCapabilities().tracker.references_stack;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ public class ContextCapabilitiesGenerator {
|
|||
public static void generateClassPrologue(PrintWriter writer, boolean context_specific) {
|
||||
writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {");
|
||||
writer.println("\tfinal StateTracker tracker;");
|
||||
writer.println("\tfinal IntBuffer scratch_int_buffer = BufferUtils.createIntBuffer(16);");
|
||||
writer.println();
|
||||
if (!context_specific) {
|
||||
writer.println("\tprivate static boolean " + STUBS_LOADED_NAME + " = false;");
|
||||
|
|
|
|||
|
|
@ -111,7 +111,9 @@ public class ContextGeneratorProcessorFactory implements AnnotationProcessorFact
|
|||
writer.println("package org.lwjgl.opengl;");
|
||||
writer.println();
|
||||
writer.println("import org.lwjgl.LWJGLException;");
|
||||
writer.println("import org.lwjgl.BufferUtils;");
|
||||
writer.println("import java.util.Set;");
|
||||
writer.println("import java.nio.IntBuffer;");
|
||||
writer.println();
|
||||
ContextCapabilitiesGenerator.generateClassPrologue(writer, context_specific);
|
||||
DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue