Re-implemented VBO buffer binding caches to speed up gl*Pointer calls. Patch by MatthiasM.
This commit is contained in:
parent
a4b67705a0
commit
c025a7c70f
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<TypeDeclaration> 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue