diff --git a/src/java/org/lwjgl/opengl/BaseReferences.java b/src/java/org/lwjgl/opengl/BaseReferences.java new file mode 100644 index 00000000..78b4d884 --- /dev/null +++ b/src/java/org/lwjgl/opengl/BaseReferences.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +class BaseReferences { + + int elementArrayBuffer; + int arrayBuffer; + + void clear() { + this.elementArrayBuffer = 0; + this.arrayBuffer = 0; + } + + void copy(BaseReferences references) { + this.elementArrayBuffer = references.elementArrayBuffer; + this.arrayBuffer = references.arrayBuffer; + } +} diff --git a/src/java/org/lwjgl/opengl/GLChecks.java b/src/java/org/lwjgl/opengl/GLChecks.java index dc052a19..0914f705 100644 --- a/src/java/org/lwjgl/opengl/GLChecks.java +++ b/src/java/org/lwjgl/opengl/GLChecks.java @@ -80,25 +80,25 @@ class GLChecks { /** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ static void ensureArrayVBOdisabled(ContextCapabilities caps) { - if ((caps.OpenGL15 || caps.GL_ARB_vertex_buffer_object) && !checkBufferObject(caps, GL15.GL_ARRAY_BUFFER_BINDING, false)) + if(StateTracker.getReferencesStack(caps).getReferences().arrayBuffer != 0) 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(ContextCapabilities caps) { - if ((caps.OpenGL15 || caps.GL_ARB_vertex_buffer_object) && !checkBufferObject(caps, GL15.GL_ARRAY_BUFFER_BINDING, true)) + if(StateTracker.getReferencesStack(caps).getReferences().arrayBuffer == 0) 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(ContextCapabilities caps) { - if ((caps.OpenGL15 || caps.GL_ARB_vertex_buffer_object) && !checkBufferObject(caps, GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING, false)) + if(StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer != 0) 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(ContextCapabilities caps) { - if ((caps.OpenGL15 || caps.GL_ARB_vertex_buffer_object) && !checkBufferObject(caps, GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING, true)) + if(StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer == 0) throw new OpenGLException("Cannot use offsets when Element Array Buffer Object is disabled"); } diff --git a/src/java/org/lwjgl/opengl/StateTracker.java b/src/java/org/lwjgl/opengl/StateTracker.java index 8cc2ef5d..6d27af3f 100644 --- a/src/java/org/lwjgl/opengl/StateTracker.java +++ b/src/java/org/lwjgl/opengl/StateTracker.java @@ -64,4 +64,16 @@ final class StateTracker { static ReferencesStack getReferencesStack(ContextCapabilities caps) { return caps.tracker.references_stack; } + + static void bindBuffer(ContextCapabilities caps, int target, int buffer) { + ReferencesStack references_stack = getReferencesStack(caps); + switch(target) { + case GL15.GL_ELEMENT_ARRAY_BUFFER: + references_stack.getReferences().elementArrayBuffer = buffer; + break; + case GL15.GL_ARRAY_BUFFER: + references_stack.getReferences().arrayBuffer = buffer; + break; + } + } } diff --git a/src/java/org/lwjgl/util/generator/ReferencesGeneratorProcessorFactory.java b/src/java/org/lwjgl/util/generator/ReferencesGeneratorProcessorFactory.java index d1ad925a..32bf83df 100644 --- a/src/java/org/lwjgl/util/generator/ReferencesGeneratorProcessorFactory.java +++ b/src/java/org/lwjgl/util/generator/ReferencesGeneratorProcessorFactory.java @@ -166,7 +166,7 @@ public class ReferencesGeneratorProcessorFactory implements AnnotationProcessorF writer.println(); writer.println("package org.lwjgl.opengl;"); writer.println(); - writer.println("class " + REFERENCES_CLASS_NAME + " {"); + writer.println("class " + REFERENCES_CLASS_NAME + " extends BaseReferences {"); DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class); Collection interface_decls = filter.filter(env.getSpecifiedTypeDeclarations()); for (TypeDeclaration typedecl : interface_decls) { @@ -175,12 +175,14 @@ public class ReferencesGeneratorProcessorFactory implements AnnotationProcessorF } writer.println(); writer.println("\tvoid copy(" + REFERENCES_CLASS_NAME + " " + REFERENCES_PARAMETER_NAME + ") {"); + writer.println("\t\tsuper.copy(" + REFERENCES_PARAMETER_NAME + ");"); for (TypeDeclaration typedecl : interface_decls) { InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl; generateCopiesFromMethods(writer, interface_decl); } writer.println("\t}"); writer.println("\tvoid clear() {"); + writer.println("\t\tsuper.clear();"); for (TypeDeclaration typedecl : interface_decls) { InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl; generateClearsFromMethods(writer, interface_decl); diff --git a/src/templates/org/lwjgl/opengl/ARB_buffer_object.java b/src/templates/org/lwjgl/opengl/ARB_buffer_object.java index 38f24125..41670ffa 100644 --- a/src/templates/org/lwjgl/opengl/ARB_buffer_object.java +++ b/src/templates/org/lwjgl/opengl/ARB_buffer_object.java @@ -67,6 +67,7 @@ public interface ARB_buffer_object { int GL_BUFFER_MAPPED_ARB = 0x88BC; int GL_BUFFER_MAP_POINTER_ARB = 0x88BD; + @Code(" StateTracker.bindBuffer(caps, target, buffer);") void glBindBufferARB(@GLenum int target, @GLuint int buffer); void glDeleteBuffersARB(@AutoSize("buffers") @GLsizei int n, @Const @GLuint IntBuffer buffers); diff --git a/src/templates/org/lwjgl/opengl/GL15.java b/src/templates/org/lwjgl/opengl/GL15.java index edcaa54f..b5fc0f33 100644 --- a/src/templates/org/lwjgl/opengl/GL15.java +++ b/src/templates/org/lwjgl/opengl/GL15.java @@ -72,6 +72,7 @@ public interface GL15 { int GL_BUFFER_MAPPED = 0x88BC; int GL_BUFFER_MAP_POINTER = 0x88BD; + @Code(" StateTracker.bindBuffer(caps, target, buffer);") void glBindBuffer(@GLenum int target, @GLuint int buffer); void glDeleteBuffers(@AutoSize("buffers") @GLsizei int n, @Const @GLuint IntBuffer buffers);