aboutsummaryrefslogtreecommitdiffstats
path: root/make
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2006-11-26 06:02:27 +0000
committerKenneth Russel <[email protected]>2006-11-26 06:02:27 +0000
commit3d445e164c242fb050dc6ecc8ca736731f7bcc67 (patch)
tree70b7ad77ca6090583fb6bc8a016c6b8ffaad1b40 /make
parent643849d65648411b55281ea5c87878e148dda97b (diff)
Fixed another performance problem related to buffer objects pointed
out by John Burkey. glGetBufferParameterivARB call in glMapBuffer was too expensive at least with Apple's multithreaded OpenGL implementation. Now track both bound buffer state (refactored into GLBufferStateTracker) as well as cache created buffers' sizes (expressed in GLBufferSizeTracker) and query the cache instead of OpenGL directly. Verified with VertexBufferObject demo that now no glGet queries are made at run-time. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1003 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'make')
-rw-r--r--make/gl-common.cfg10
-rw-r--r--make/gl-impl-CustomJavaCode.java119
2 files changed, 30 insertions, 99 deletions
diff --git a/make/gl-common.cfg b/make/gl-common.cfg
index 984d0f45a..137d69a83 100644
--- a/make/gl-common.cfg
+++ b/make/gl-common.cfg
@@ -262,10 +262,12 @@ ArgumentIsString glGetAttribLocationARB 1
#
JavaPrologue glBegin inBeginEndPair = true;
JavaEpilogue glEnd inBeginEndPair = false;
-JavaEpilogue glBindBuffer setBoundBufferObject({0}, {1});
-JavaEpilogue glBindBufferARB setBoundBufferObject({0}, {1});
-JavaEpilogue glPushClientAttrib clearBufferObjectState();
-JavaEpilogue glPopClientAttrib clearBufferObjectState();
+JavaEpilogue glBindBuffer bufferStateTracker.setBoundBufferObject({0}, {1});
+JavaEpilogue glBindBufferARB bufferStateTracker.setBoundBufferObject({0}, {1});
+JavaEpilogue glPushClientAttrib bufferStateTracker.clearBufferObjectState();
+JavaEpilogue glPopClientAttrib bufferStateTracker.clearBufferObjectState();
+JavaEpilogue glBufferData bufferSizeTracker.setBufferSize(bufferStateTracker, {0}, this, {1});
+JavaEpilogue glBufferDataARB bufferSizeTracker.setBufferSize(bufferStateTracker, {0}, this, {1});
BufferObjectKind UnpackPixel glBitmap
BufferObjectKind UnpackPixel glColorTable
BufferObjectKind UnpackPixel glColorSubTable
diff --git a/make/gl-impl-CustomJavaCode.java b/make/gl-impl-CustomJavaCode.java
index ac2c1eab5..85e441069 100644
--- a/make/gl-impl-CustomJavaCode.java
+++ b/make/gl-impl-CustomJavaCode.java
@@ -9,6 +9,7 @@ private GLObjectTracker tracker;
public GLImpl(GLContextImpl context) {
this._context = context;
+ this.bufferSizeTracker = context.getBufferSizeTracker();
}
public boolean isFunctionAvailable(String glFunctionName) {
@@ -148,15 +149,14 @@ private int imageSizeInBytes(int format, int type, int w, int h, int d) {
return (elements * esize * w * h * d);
}
-private int[] bufTmp = new int[1];
private boolean bufferObjectExtensionsInitialized = false;
private boolean haveARBPixelBufferObject;
private boolean haveEXTPixelBufferObject;
private boolean haveGL15;
private boolean haveGL21;
private boolean haveARBVertexBufferObject;
-private boolean[] bufferBindingsKnown = new boolean[4];
-private int[] bufferBindings = new int[4];
+private GLBufferStateTracker bufferStateTracker = new GLBufferStateTracker();
+private GLBufferSizeTracker bufferSizeTracker;
private void initBufferObjectExtensionChecks() {
if (bufferObjectExtensionsInitialized)
@@ -169,79 +169,6 @@ private void initBufferObjectExtensionChecks() {
haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object");
}
-// Might want to call this from GLContext.makeCurrent() in the future
-// to possibly increase the robustness of these caches
-private void clearBufferObjectState() {
- for (int i = 0; i < bufferBindingsKnown.length; i++) {
- bufferBindingsKnown[i] = false;
- }
-}
-
-// Called by glBindBuffer
-private void setBoundBufferObject(int state, int buffer) {
- switch (state) {
- case GL.GL_ARRAY_BUFFER:
- bufferBindingsKnown[0] = true;
- bufferBindings[0] = buffer;
- break;
-
- case GL.GL_ELEMENT_ARRAY_BUFFER:
- bufferBindingsKnown[1] = true;
- bufferBindings[1] = buffer;
- break;
-
- case GL.GL_PIXEL_PACK_BUFFER:
- bufferBindingsKnown[2] = true;
- bufferBindings[2] = buffer;
- break;
-
- case GL.GL_PIXEL_UNPACK_BUFFER:
- bufferBindingsKnown[3] = true;
- bufferBindings[3] = buffer;
- break;
-
- default:
- // There are other enumerants now supported as arguments to
- // glBindBuffer(); e.g., GL_TRANSFORM_FEEDBACK_BUFFER_NV. It is
- // likely this code will need to be updated in the future, but
- // for now it is believed that there are no other enumerants
- // that need to be supported in order to support the buffer
- // object checking necessary for class GL.
- break;
- }
-}
-
-private int getBoundBufferObject(int state) {
- // Compute the index we need
- int index = -1;
- switch (state) {
- case GL.GL_ARRAY_BUFFER_BINDING:
- index = 0;
- break;
- case GL.GL_ELEMENT_ARRAY_BUFFER_BINDING:
- index = 1;
- break;
- case GL.GL_PIXEL_PACK_BUFFER_BINDING:
- index = 2;
- break;
- case GL.GL_PIXEL_UNPACK_BUFFER_BINDING:
- index = 3;
- break;
- default:
- // No other currently supported enumerants; return early
- break;
- }
- if (index < 0)
- return 0;
- if (!bufferBindingsKnown[index]) {
- // Get the state and cache it
- glGetIntegerv(state, bufTmp, 0);
- bufferBindingsKnown[index] = true;
- bufferBindings[index] = bufTmp[0];
- }
- return bufferBindings[index];
-}
-
private void checkBufferObject(boolean extension1,
boolean extension2,
boolean extension3,
@@ -257,7 +184,7 @@ private void checkBufferObject(boolean extension1,
return;
throw new GLException("Required extensions not available to call this function");
}
- int buffer = getBoundBufferObject(state);
+ int buffer = bufferStateTracker.getBoundBufferObject(state, this);
if (enabled) {
if (buffer == 0) {
throw new GLException(kind + " must be enabled to call this method");
@@ -275,7 +202,7 @@ private void checkUnpackPBODisabled() {
haveEXTPixelBufferObject,
haveGL21,
false,
- GL.GL_PIXEL_UNPACK_BUFFER_BINDING_ARB,
+ GL.GL_PIXEL_UNPACK_BUFFER,
"unpack pixel_buffer_object");
}
@@ -285,7 +212,7 @@ private void checkUnpackPBOEnabled() {
haveEXTPixelBufferObject,
haveGL21,
true,
- GL.GL_PIXEL_UNPACK_BUFFER_BINDING_ARB,
+ GL.GL_PIXEL_UNPACK_BUFFER,
"unpack pixel_buffer_object");
}
@@ -295,7 +222,7 @@ private void checkPackPBODisabled() {
haveEXTPixelBufferObject,
haveGL21,
false,
- GL.GL_PIXEL_PACK_BUFFER_BINDING_ARB,
+ GL.GL_PIXEL_PACK_BUFFER,
"pack pixel_buffer_object");
}
@@ -305,7 +232,7 @@ private void checkPackPBOEnabled() {
haveEXTPixelBufferObject,
haveGL21,
true,
- GL.GL_PIXEL_PACK_BUFFER_BINDING_ARB,
+ GL.GL_PIXEL_PACK_BUFFER,
"pack pixel_buffer_object");
}
@@ -316,7 +243,7 @@ private void checkArrayVBODisabled() {
haveARBVertexBufferObject,
false,
false,
- GL.GL_ARRAY_BUFFER_BINDING,
+ GL.GL_ARRAY_BUFFER,
"array vertex_buffer_object");
}
@@ -326,7 +253,7 @@ private void checkArrayVBOEnabled() {
haveARBVertexBufferObject,
false,
true,
- GL.GL_ARRAY_BUFFER_BINDING,
+ GL.GL_ARRAY_BUFFER,
"array vertex_buffer_object");
}
@@ -336,7 +263,7 @@ private void checkElementVBODisabled() {
haveARBVertexBufferObject,
false,
false,
- GL.GL_ELEMENT_ARRAY_BUFFER_BINDING,
+ GL.GL_ELEMENT_ARRAY_BUFFER,
"element vertex_buffer_object");
}
@@ -346,7 +273,7 @@ private void checkElementVBOEnabled() {
haveARBVertexBufferObject,
false,
true,
- GL.GL_ELEMENT_ARRAY_BUFFER_BINDING,
+ GL.GL_ELEMENT_ARRAY_BUFFER,
"element vertex_buffer_object");
}
@@ -383,17 +310,18 @@ public java.nio.ByteBuffer glMapBuffer(int target, int access) {
if (__addr_ == 0) {
throw new GLException("Method \"glMapBuffer\" not available");
}
- int[] sz = new int[1];
- glGetBufferParameteriv(target, GL_BUFFER_SIZE_ARB, sz, 0);
+ int sz = bufferSizeTracker.getBufferSize(bufferStateTracker,
+ target,
+ this);
long addr;
addr = dispatch_glMapBuffer(target, access, __addr_);
- if (addr == 0 || sz[0] == 0) {
+ if (addr == 0 || sz == 0) {
return null;
}
- ARBVBOKey key = new ARBVBOKey(addr, sz[0]);
+ ARBVBOKey key = new ARBVBOKey(addr, sz);
ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key);
if (_res == null) {
- _res = InternalBufferUtils.newDirectByteBuffer(addr, sz[0]);
+ _res = InternalBufferUtils.newDirectByteBuffer(addr, sz);
_res.order(ByteOrder.nativeOrder());
arbVBOCache.put(key, _res);
}
@@ -407,17 +335,18 @@ public java.nio.ByteBuffer glMapBufferARB(int target, int access) {
if (__addr_ == 0) {
throw new GLException("Method \"glMapBufferARB\" not available");
}
- int[] sz = new int[1];
- glGetBufferParameterivARB(target, GL_BUFFER_SIZE_ARB, sz, 0);
+ int sz = bufferSizeTracker.getBufferSize(bufferStateTracker,
+ target,
+ this);
long addr;
addr = dispatch_glMapBufferARB(target, access, __addr_);
- if (addr == 0 || sz[0] == 0) {
+ if (addr == 0 || sz == 0) {
return null;
}
- ARBVBOKey key = new ARBVBOKey(addr, sz[0]);
+ ARBVBOKey key = new ARBVBOKey(addr, sz);
ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key);
if (_res == null) {
- _res = InternalBufferUtils.newDirectByteBuffer(addr, sz[0]);
+ _res = InternalBufferUtils.newDirectByteBuffer(addr, sz);
_res.order(ByteOrder.nativeOrder());
arbVBOCache.put(key, _res);
}