From 09fc7aa5539731bb0fba835caee61f6eb837ecff Mon Sep 17 00:00:00 2001
From: Sven Gothel
+MethodJavadoc glBufferData * Throws a {@link GLException} if GL-function constraints are not met or the native GL-function fails.
+MethodJavadoc glBufferData *
+MethodJavadoc glBufferData * @throws GLException if buffer is not bound to target
+MethodJavadoc glBufferData * @throws GLException if size is less-than zero
+MethodJavadoc glBufferData * @throws GLException if a native GL-Error occurs
+MethodJavadoc glBufferData *
+#MethodJavadoc glBufferStorage * Throws a {@link GLException} if GL-function constraints are not met or the native GL-function fails.
+#MethodJavadoc glBufferStorage *
+#MethodJavadoc glBufferStorage * @throws GLException if buffer is not bound to target
+#MethodJavadoc glBufferStorage * @throws GLException if size is less-or-equal zero
+#MethodJavadoc glBufferStorage * @throws GLException if a native GL-Error occurs
+#MethodJavadoc glBufferStorage *
+MethodJavadoc glMapBuffer * Throws a {@link GLException} if GL-function constraints are not met.
+MethodJavadoc glMapBuffer *
+MethodJavadoc glMapBuffer * Returns {@link GL#mapBuffer(int, int)}'s {@link GLBufferStorage#getMappedBuffer()}.
+MethodJavadoc glMapBuffer *
+MethodJavadoc glMapBufferRange * Throws a {@link GLException} if GL-function constraints are not met. +MethodJavadoc glMapBufferRange *
+MethodJavadoc glMapBufferRange *+MethodJavadoc glMapBufferRange * Returns {@link GL#mapBufferRange(int, long, long, int)}'s {@link GLBufferStorage#getMappedBuffer()}. +MethodJavadoc glMapBufferRange *
+MethodJavadoc glMapBufferRange *+MethodJavadoc glMapBufferRange * @throws GLException if buffer is not bound to target +MethodJavadoc glMapBufferRange * @throws GLException if buffer is not tracked +MethodJavadoc glMapBufferRange * @throws GLException if buffer is already mapped +MethodJavadoc glMapBufferRange * @throws GLException if buffer has invalid store size, i.e. less-than zero +MethodJavadoc glMapBufferRange * @throws GLException if buffer mapping range does not fit, incl. offset +MethodJavadoc glMapBufferRange *
+ +ManuallyImplement glUnmapBuffer +ForceProcAddressGen glUnmapBuffer # Ignore the ATI_map_object_buffer extension for now unless someone # claims they need it, as it will undoubtedly require a similar @@ -550,15 +604,18 @@ JavaEpilogue glBindFramebuffer _context.setBoundFramebuffer(target, framebuffer # JavaPrologue glBegin inBeginEndPair = true; JavaEpilogue glEnd inBeginEndPair = false; -JavaEpilogue glBindBuffer bufferStateTracker.setBoundBufferObject({0}, {1}); -JavaEpilogue glBindBufferARB bufferStateTracker.setBoundBufferObject({0}, {1}); -JavaEpilogue glBindVertexArray bufferStateTracker.setBoundBufferObject(GL2GL3.GL_VERTEX_ARRAY_BINDING, {0}); -JavaEpilogue glPushClientAttrib bufferStateTracker.clearBufferObjectState(); -JavaEpilogue glPushClientAttrib glStateTracker.pushAttrib(mask); -JavaEpilogue glPopClientAttrib bufferStateTracker.clearBufferObjectState(); -JavaEpilogue glPopClientAttrib glStateTracker.popAttrib(); -JavaPrologue glBufferData synchronized(bufferSizeTracker) { -JavaEpilogue glBufferData bufferSizeTracker.setBufferSize(bufferStateTracker, {0}, this, {1}); } + +JavaEpilogue glBindBuffer bufferStateTracker.setBoundBufferObject({0}, {1}); +JavaEpilogue glBindBufferARB bufferStateTracker.setBoundBufferObject({0}, {1}); +JavaEpilogue glBindBufferBase bufferStateTracker.setBoundBufferObject({0}, {2}); +JavaEpilogue glBindBufferRange bufferStateTracker.setBoundBufferObject({0}, {2}); +JavaEpilogue glBindVertexArray bufferStateTracker.setBoundBufferObject(GL2GL3.GL_VERTEX_ARRAY_BINDING, {0}); +JavaEpilogue glPushClientAttrib bufferStateTracker.clear(); +JavaEpilogue glPushClientAttrib glStateTracker.pushAttrib(mask); +JavaEpilogue glPopClientAttrib bufferStateTracker.clear(); +JavaEpilogue glPopClientAttrib glStateTracker.popAttrib(); + +JavaPrologue glDeleteBuffers bufferObjectTracker.notifyBuffersDeleted({0}, {1}); BufferObjectKind Array glColorPointer BufferObjectKind Array glEdgeFlagPointer diff --git a/make/config/jogl/gl-gl4bc.cfg b/make/config/jogl/gl-gl4bc.cfg index 48ecb7378..6ccbace44 100644 --- a/make/config/jogl/gl-gl4bc.cfg +++ b/make/config/jogl/gl-gl4bc.cfg @@ -55,12 +55,51 @@ Include gl3-desktop.cfg Include gl3-common.cfg Include gl2_es2-CustomJavaCode.cfg -# Manually implement glMapNamedBufferEXT as the size of the returned buffer -# can only be computed by calling another routine +# +# Manually implement following GL functions to be redirected +# to GLBufferObjectTracker. +# +ManuallyImplement glNamedBufferDataEXT +ForceProcAddressGen glNamedBufferDataEXT +MethodJavadoc glNamedBufferDataEXT *+MethodJavadoc glNamedBufferDataEXT * Throws a {@link GLException} if GL-function constraints are not met or the native GL-function fails. +MethodJavadoc glNamedBufferDataEXT *
+MethodJavadoc glNamedBufferDataEXT *+MethodJavadoc glNamedBufferDataEXT * @throws GLException if size is less-than zero +MethodJavadoc glNamedBufferDataEXT * @throws GLException if a native GL-Error occurs +MethodJavadoc glNamedBufferDataEXT *
+ ManuallyImplement glMapNamedBufferEXT ForceProcAddressGen glMapNamedBufferEXT -JavaPrologue glNamedBufferDataEXT synchronized(bufferSizeTracker) { -JavaEpilogue glNamedBufferDataEXT bufferSizeTracker.setDirectStateBufferSize({0}, this, {1}); } +MethodJavadoc glMapNamedBufferEXT *+MethodJavadoc glMapNamedBufferEXT * Throws a {@link GLException} if GL-function constraints are not met. +MethodJavadoc glMapNamedBufferEXT *
+MethodJavadoc glMapNamedBufferEXT *+MethodJavadoc glMapNamedBufferEXT * Returns {@link GL2#mapNamedBuffer(int, int)}'s {@link GLBufferStorage#getMappedBuffer()}. +MethodJavadoc glMapNamedBufferEXT *
+MethodJavadoc glMapNamedBufferEXT *+MethodJavadoc glMapNamedBufferEXT * @throws GLException if buffer is not tracked +MethodJavadoc glMapNamedBufferEXT * @throws GLException if buffer is already mapped +MethodJavadoc glMapNamedBufferEXT * @throws GLException if buffer has invalid store size, i.e. less-than zero +MethodJavadoc glMapNamedBufferEXT *
+ +ManuallyImplement glMapNamedBufferRangeEXT +ForceProcAddressGen glMapNamedBufferRangeEXT +MethodJavadoc glMapNamedBufferRangeEXT *+MethodJavadoc glMapNamedBufferRangeEXT * Throws a {@link GLException} if GL-function constraints are not met. +MethodJavadoc glMapNamedBufferRangeEXT *
+MethodJavadoc glMapNamedBufferRangeEXT *+MethodJavadoc glMapNamedBufferRangeEXT * Returns {@link GL2#mapNamedBufferRange(int, long, long, int)}'s {@link GLBufferStorage#getMappedBuffer()}. +MethodJavadoc glMapNamedBufferRangeEXT *
+MethodJavadoc glMapNamedBufferRangeEXT *+MethodJavadoc glMapNamedBufferRangeEXT * @throws GLException if buffer is not tracked +MethodJavadoc glMapNamedBufferRangeEXT * @throws GLException if buffer is already mapped +MethodJavadoc glMapNamedBufferRangeEXT * @throws GLException if buffer has invalid store size, i.e. less-than zero +MethodJavadoc glMapNamedBufferRangeEXT * @throws GLException if buffer mapping range does not fit, incl. offset +MethodJavadoc glMapNamedBufferRangeEXT *
+ +ManuallyImplement glUnmapNamedBufferEXT +ForceProcAddressGen glUnmapNamedBufferEXT # Manuall implement glDebugMessageCallback* using the proc address resolver ForceProcAddressGen glDebugMessageCallback diff --git a/make/config/jogl/gl-if-CustomJavaCode-es3.java b/make/config/jogl/gl-if-CustomJavaCode-es3.java index b68b5123a..3f976d514 100644 --- a/make/config/jogl/gl-if-CustomJavaCode-es3.java +++ b/make/config/jogl/gl-if-CustomJavaCode-es3.java @@ -8,7 +8,11 @@ public static final long GL_TIMEOUT_IGNORED = 0xFFFFFFFFFFFFFFFFL ; /** Part ofGL_ARB_shader_image_load_store
*/
public static final int GL_ALL_BARRIER_BITS = 0xFFFFFFFF ;
+/** @deprecated Avoid original GL API namespace conflict. Use {@link #isPBOPackBound()} */
public boolean glIsPBOPackBound();
+public boolean isPBOPackBound();
+/** @deprecated Avoid original GL API namespace conflict. Use {@link #isPBOUnpackBound()} */
public boolean glIsPBOUnpackBound();
+public boolean isPBOUnpackBound();
diff --git a/make/config/jogl/gl-if-gl2.cfg b/make/config/jogl/gl-if-gl2.cfg
index 37f7b6feb..0120bd674 100644
--- a/make/config/jogl/gl-if-gl2.cfg
+++ b/make/config/jogl/gl-if-gl2.cfg
@@ -26,6 +26,7 @@ Include gl-desktop.cfg
Include gl-if-gl3-ignores.cfg
Include gl-if-gl4-ignores.cfg
+IncludeAs CustomJavaCode GL2 gl-if-CustomJavaCode-gl2.java
IncludeAs CustomJavaCode GL2 gl-if-CustomJavaCode-gl_compat.java
IncludeAs CustomJavaCode GL2 gl2_es2-common-cpubufferJavaCode.java
IncludeAs CustomJavaCode GL2 gl2-common-cpubufferJavaCode.java
diff --git a/make/config/jogl/gl-impl-CustomCCode-gl4bc.c b/make/config/jogl/gl-impl-CustomCCode-gl4bc.c
index 4ddc27bf2..42e5700ab 100644
--- a/make/config/jogl/gl-impl-CustomCCode-gl4bc.c
+++ b/make/config/jogl/gl-impl-CustomCCode-gl4bc.c
@@ -1,6 +1,77 @@
/* Java->C glue code:
* Java package: jogamp.opengl.gl4.GL4bcImpl
- * Java method: long dispatch_glMapBuffer(int target, int access)
+ * Java method: void dispatch_glBufferData(int target, long size, java.nio.Buffer data, int usage)
+ * C function: void glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
+ */
+JNIEXPORT void JNICALL
+Java_jogamp_opengl_gl4_GL4bcImpl_dispatch_1glBufferData(JNIEnv *env, jobject _unused, jint target, jlong size, jobject data, jint data_byte_offset, jboolean data_is_nio, jint usage, jlong procAddress) {
+ typedef void (APIENTRY*_local_PFNGLBUFFERDATAPROC)(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
+ _local_PFNGLBUFFERDATAPROC ptr_glBufferData;
+ GLvoid * _data_ptr = NULL;
+ if ( NULL != data ) {
+ _data_ptr = (GLvoid *) ( JNI_TRUE == data_is_nio ? (*env)->GetDirectBufferAddress(env, data) : (*env)->GetPrimitiveArrayCritical(env, data, NULL) ); }
+ ptr_glBufferData = (_local_PFNGLBUFFERDATAPROC) (intptr_t) procAddress;
+ assert(ptr_glBufferData != NULL);
+ (* ptr_glBufferData) ((GLenum) target, (GLsizeiptr) size, (GLvoid *) (((char *) _data_ptr) + data_byte_offset), (GLenum) usage);
+ if ( JNI_FALSE == data_is_nio && NULL != data ) {
+ (*env)->ReleasePrimitiveArrayCritical(env, data, _data_ptr, JNI_ABORT); }
+}
+
+/** FIXME Add for OpenGL 4.4: glBufferStorage */
+
+/* Java->C glue code:
+ * Java package: jogamp.opengl.gl4.GL4bcImpl
+ * Java method: void dispatch_glNamedBufferDataEXT(int buffer, long size, java.nio.Buffer data, int usage)
+ * C function: void glNamedBufferDataEXT(GLuint buffer, GLsizeiptr size, const GLvoid * data, GLenum usage);
+ */
+JNIEXPORT void JNICALL
+Java_jogamp_opengl_gl4_GL4bcImpl_dispatch_1glNamedBufferDataEXT(JNIEnv *env, jobject _unused, jint buffer, jlong size, jobject data, jint data_byte_offset, jboolean data_is_nio, jint usage, jlong procAddress) {
+ typedef void (APIENTRY*_local_PFNGLNAMEDBUFFERDATAEXTPROC)(GLuint buffer, GLsizeiptr size, const GLvoid * data, GLenum usage);
+ _local_PFNGLNAMEDBUFFERDATAEXTPROC ptr_glNamedBufferDataEXT;
+ GLvoid * _data_ptr = NULL;
+ if ( NULL != data ) {
+ _data_ptr = (GLvoid *) ( JNI_TRUE == data_is_nio ? (*env)->GetDirectBufferAddress(env, data) : (*env)->GetPrimitiveArrayCritical(env, data, NULL) ); }
+ ptr_glNamedBufferDataEXT = (_local_PFNGLNAMEDBUFFERDATAEXTPROC) (intptr_t) procAddress;
+ assert(ptr_glNamedBufferDataEXT != NULL);
+ (* ptr_glNamedBufferDataEXT) ((GLuint) buffer, (GLsizeiptr) size, (GLvoid *) (((char *) _data_ptr) + data_byte_offset), (GLenum) usage);
+ if ( JNI_FALSE == data_is_nio && NULL != data ) {
+ (*env)->ReleasePrimitiveArrayCritical(env, data, _data_ptr, JNI_ABORT); }
+}
+
+/* Java->C glue code:
+ * Java package: jogamp.opengl.gl4.GL4bcImpl
+ * Java method: boolean dispatch_glUnmapBuffer(int target)
+ * C function: GLboolean glUnmapBuffer(GLenum target);
+ */
+JNIEXPORT jboolean JNICALL
+Java_jogamp_opengl_gl4_GL4bcImpl_dispatch_1glUnmapBuffer(JNIEnv *env, jobject _unused, jint target, jlong procAddress) {
+ typedef GLboolean (APIENTRY*_local_PFNGLUNMAPBUFFERPROC)(GLenum target);
+ _local_PFNGLUNMAPBUFFERPROC ptr_glUnmapBuffer;
+ GLboolean _res;
+ ptr_glUnmapBuffer = (_local_PFNGLUNMAPBUFFERPROC) (intptr_t) procAddress;
+ assert(ptr_glUnmapBuffer != NULL);
+ _res = (* ptr_glUnmapBuffer) ((GLenum) target);
+ return _res;
+}
+
+/* Java->C glue code:
+ * Java package: jogamp.opengl.gl4.GL4bcImpl
+ * Java method: boolean dispatch_glUnmapNamedBufferEXT(int buffer)
+ * C function: GLboolean glUnmapNamedBufferEXT(GLuint buffer);
+ */
+JNIEXPORT jboolean JNICALL
+Java_jogamp_opengl_gl4_GL4bcImpl_dispatch_1glUnmapNamedBufferEXT(JNIEnv *env, jobject _unused, jint buffer, jlong procAddress) {
+ typedef GLboolean (APIENTRY*_local_PFNGLUNMAPNAMEDBUFFEREXTPROC)(GLuint buffer);
+ _local_PFNGLUNMAPNAMEDBUFFEREXTPROC ptr_glUnmapNamedBufferEXT;
+ GLboolean _res;
+ ptr_glUnmapNamedBufferEXT = (_local_PFNGLUNMAPNAMEDBUFFEREXTPROC) (intptr_t) procAddress;
+ assert(ptr_glUnmapNamedBufferEXT != NULL);
+ _res = (* ptr_glUnmapNamedBufferEXT) ((GLuint) buffer);
+ return _res;
+}
+
+/* Java->C glue code:
+ * Java package: jogamp.opengl.gl4.GL4bcImpl * Java method: long dispatch_glMapBuffer(int target, int access)
* C function: void * glMapBuffer(GLenum target, GLenum access);
*/
JNIEXPORT jlong JNICALL
@@ -40,10 +111,26 @@ Java_jogamp_opengl_gl4_GL4bcImpl_dispatch_1glMapNamedBufferEXT(JNIEnv *env, jobj
void * _res;
ptr_glMapNamedBufferEXT = (PFNGLMAPNAMEDBUFFEREXTPROC) (intptr_t) glProcAddress;
assert(ptr_glMapNamedBufferEXT != NULL);
- _res = (* ptr_glMapNamedBufferEXT) ((GLenum) target, (GLenum) access);
+ _res = (* ptr_glMapNamedBufferEXT) ((GLuint) target, (GLenum) access);
+ return (jlong) (intptr_t) _res;
+}
+
+/* Java->C glue code:
+ * Java package: jogamp.opengl.gl4.GL4bcImpl
+ * Java method: java.nio.ByteBuffer dispatch_glMapNamedBufferRangeEXT(int buffer, long offset, long length, int access)
+ * C function: void * glMapNamedBufferRangeEXT(GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access);
+ */
+JNIEXPORT jlong JNICALL
+Java_jogamp_opengl_gl4_GL4bcImpl_dispatch_1glMapNamedBufferRangeEXT(JNIEnv *env, jobject _unused, jint buffer, jlong offset, jlong length, jint access, jlong procAddress) {
+ PFNGLMAPNAMEDBUFFERRANGEEXTPROC ptr_glMapNamedBufferRangeEXT;
+ void * _res;
+ ptr_glMapNamedBufferRangeEXT = (PFNGLMAPNAMEDBUFFERRANGEEXTPROC) (intptr_t) procAddress;
+ assert(ptr_glMapNamedBufferRangeEXT != NULL);
+ _res = (* ptr_glMapNamedBufferRangeEXT) ((GLuint) buffer, (GLintptr) offset, (GLsizeiptr) length, (GLbitfield) access);
return (jlong) (intptr_t) _res;
}
+
/* Java->C glue code:
* Java package: jogamp.opengl.gl4.GL4bcImpl
* Java method: ByteBuffer newDirectByteBuffer(long addr, long capacity);
diff --git a/make/config/jogl/gl-impl-CustomCCode-gles1.c b/make/config/jogl/gl-impl-CustomCCode-gles1.c
index 88cfe4418..83b8c7586 100644
--- a/make/config/jogl/gl-impl-CustomCCode-gles1.c
+++ b/make/config/jogl/gl-impl-CustomCCode-gles1.c
@@ -1,3 +1,38 @@
+/* Java->C glue code:
+ * Java package: jogamp.opengl.es1.GLES1Impl
+ * Java method: void dispatch_glBufferData(int target, long size, java.nio.Buffer data, int usage)
+ * C function: void glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
+ */
+JNIEXPORT void JNICALL
+Java_jogamp_opengl_es1_GLES1Impl_dispatch_1glBufferData(JNIEnv *env, jobject _unused, jint target, jlong size, jobject data, jint data_byte_offset, jboolean data_is_nio, jint usage, jlong procAddress) {
+ typedef void (GL_APIENTRY*_local_PFNGLBUFFERDATAPROC)(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
+ _local_PFNGLBUFFERDATAPROC ptr_glBufferData;
+ GLvoid * _data_ptr = NULL;
+ if ( NULL != data ) {
+ _data_ptr = (GLvoid *) ( JNI_TRUE == data_is_nio ? (*env)->GetDirectBufferAddress(env, data) : (*env)->GetPrimitiveArrayCritical(env, data, NULL) ); }
+ ptr_glBufferData = (_local_PFNGLBUFFERDATAPROC) (intptr_t) procAddress;
+ assert(ptr_glBufferData != NULL);
+ (* ptr_glBufferData) ((GLenum) target, (GLsizeiptr) size, (GLvoid *) (((char *) _data_ptr) + data_byte_offset), (GLenum) usage);
+ if ( JNI_FALSE == data_is_nio && NULL != data ) {
+ (*env)->ReleasePrimitiveArrayCritical(env, data, _data_ptr, JNI_ABORT); }
+}
+
+/* Java->C glue code:
+ * Java package: jogamp.opengl.es1.GLES1Impl
+ * Java method: boolean dispatch_glUnmapBuffer(int target)
+ * C function: GLboolean glUnmapBufferOES(GLenum target);
+ */
+JNIEXPORT jboolean JNICALL
+Java_jogamp_opengl_es1_GLES1Impl_dispatch_1glUnmapBuffer(JNIEnv *env, jobject _unused, jint target, jlong procAddress) {
+ typedef GLboolean (GL_APIENTRY*_local_PFNGLUNMAPBUFFEROESPROC)(GLenum target);
+ _local_PFNGLUNMAPBUFFEROESPROC ptr_glUnmapBufferOES;
+ GLboolean _res;
+ ptr_glUnmapBufferOES = (_local_PFNGLUNMAPBUFFEROESPROC) (intptr_t) procAddress;
+ assert(ptr_glUnmapBufferOES != NULL);
+ _res = (* ptr_glUnmapBufferOES) ((GLenum) target);
+ return _res;
+}
+
typedef GLvoid* (GL_APIENTRY* PFNGLMAPBUFFERPROC) (GLenum target, GLenum access);
/* Java->C glue code:
* Java package: jogamp.opengl.es1.GLES1Impl
diff --git a/make/config/jogl/gl-impl-CustomCCode-gles3.c b/make/config/jogl/gl-impl-CustomCCode-gles3.c
index 2f3329bfa..ff1d42e23 100644
--- a/make/config/jogl/gl-impl-CustomCCode-gles3.c
+++ b/make/config/jogl/gl-impl-CustomCCode-gles3.c
@@ -1,4 +1,40 @@
+/* Java->C glue code:
+ * Java package: jogamp.opengl.es3.GLES3Impl
+ * Java method: void dispatch_glBufferData(int target, long size, java.nio.Buffer data, int usage)
+ * C function: void glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
+ */
+JNIEXPORT void JNICALL
+Java_jogamp_opengl_es3_GLES3Impl_dispatch_1glBufferData(JNIEnv *env, jobject _unused, jint target, jlong size, jobject data, jint data_byte_offset, jboolean data_is_nio, jint usage, jlong procAddress) {
+ typedef void (GL_APIENTRY*_local_PFNGLBUFFERDATAPROC)(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
+ _local_PFNGLBUFFERDATAPROC ptr_glBufferData;
+ GLvoid * _data_ptr = NULL;
+ if ( NULL != data ) {
+ _data_ptr = (GLvoid *) ( JNI_TRUE == data_is_nio ? (*env)->GetDirectBufferAddress(env, data) : (*env)->GetPrimitiveArrayCritical(env, data, NULL) ); }
+ ptr_glBufferData = (_local_PFNGLBUFFERDATAPROC) (intptr_t) procAddress;
+ assert(ptr_glBufferData != NULL);
+ (* ptr_glBufferData) ((GLenum) target, (GLsizeiptr) size, (GLvoid *) (((char *) _data_ptr) + data_byte_offset), (GLenum) usage);
+ if ( JNI_FALSE == data_is_nio && NULL != data ) {
+ (*env)->ReleasePrimitiveArrayCritical(env, data, _data_ptr, JNI_ABORT); }
+}
+
+/* Java->C glue code:
+ * Java package: jogamp.opengl.es3.GLES3Impl
+ * Java method: boolean dispatch_glUnmapBuffer(int target)
+ * C function: GLboolean glUnmapBuffer(GLenum target);
+ */
+JNIEXPORT jboolean JNICALL
+Java_jogamp_opengl_es3_GLES3Impl_dispatch_1glUnmapBuffer(JNIEnv *env, jobject _unused, jint target, jlong procAddress) {
+ typedef GLboolean (GL_APIENTRY*_local_PFNGLUNMAPBUFFERPROC)(GLenum target);
+ _local_PFNGLUNMAPBUFFERPROC ptr_glUnmapBuffer;
+ GLboolean _res;
+ ptr_glUnmapBuffer = (_local_PFNGLUNMAPBUFFERPROC) (intptr_t) procAddress;
+ assert(ptr_glUnmapBuffer != NULL);
+ _res = (* ptr_glUnmapBuffer) ((GLenum) target);
+ return _res;
+}
+
typedef GLvoid* (GL_APIENTRY* PFNGLMAPBUFFERPROC) (GLenum target, GLenum access);
+
/* Java->C glue code:
* Java package: jogamp.opengl.es3.GLES3Impl
* Java method: long dispatch_glMapBuffer(int target, int access)
diff --git a/make/config/jogl/gl-impl-CustomJavaCode-common.java b/make/config/jogl/gl-impl-CustomJavaCode-common.java
index 4b1fc0977..f0246355e 100644
--- a/make/config/jogl/gl-impl-CustomJavaCode-common.java
+++ b/make/config/jogl/gl-impl-CustomJavaCode-common.java
@@ -6,23 +6,37 @@
@Override
public final int glGetBoundBuffer(int target) {
+ return getBoundBuffer(target);
+ }
+ @Override
+ public final int getBoundBuffer(int target) {
return bufferStateTracker.getBoundBufferObject(target, this);
}
@Override
- public final long glGetBufferSize(int buffer) {
- synchronized(bufferSizeTracker) {
- return bufferSizeTracker.getDirectStateBufferSize(buffer, this);
- }
+ public final long glGetBufferSize(int bufferName) {
+ return bufferObjectTracker.getBufferSize(bufferName);
+ }
+ @Override
+ public final GLBufferStorage getBufferStorage(int bufferName) {
+ return bufferObjectTracker.getBufferStorage(bufferName);
}
@Override
public final boolean glIsVBOArrayBound() {
+ return isVBOArrayBound();
+ }
+ @Override
+ public final boolean isVBOArrayBound() {
return checkArrayVBOBound(false);
}
@Override
public final boolean glIsVBOElementArrayBound() {
+ return isVBOElementArrayBound();
+ }
+ @Override
+ public final boolean isVBOElementArrayBound() {
return checkElementVBOBound(false);
}
@@ -130,101 +144,60 @@
return _context.getDefaultReadBuffer();
}
- private final HashMap void * {@native glMapBuffer}(GLenum target, GLenum access);
GL_VERSION_1_5
; GL_OES_mapbuffer
*/
- private final java.nio.ByteBuffer glMapBufferImpl(int target, boolean useRange, long offset, long length, int access, long glProcAddress) {
- if (glProcAddress == 0) {
- throw new GLException("Method \""+(useRange?"glMapBufferRange":"glMapBuffer")+"\" not available");
- }
- final long addr, sz;
- synchronized(bufferSizeTracker) {
- sz = bufferSizeTracker.getBufferSize(bufferStateTracker, target, this);
- if (0 == sz) {
- return null;
- }
- if( !useRange ) {
- length = sz;
- offset = 0;
- } else {
- if( length + offset > sz ) {
- throw new GLException("Out of range: offset "+offset+" + length "+length+" > size "+sz);
- }
- if( 0 > length || 0 > offset ) {
- throw new GLException("Invalid values: offset "+offset+", length "+length);
+ private final GLStateTracker glStateTracker;
+
+ //
+ // GLBufferObjectTracker Redirects
+ //
+ private final GLBufferObjectTracker bufferObjectTracker;
+ private final GLBufferStateTracker bufferStateTracker;
+
+ private final jogamp.opengl.GLBufferObjectTracker.CreateStorageDispatch createBoundMutableStorageDispatch =
+ new jogamp.opengl.GLBufferObjectTracker.CreateStorageDispatch() {
+ public final void create(final int target, final long size, final Buffer data, final int mutableUsage, final long glProcAddress) {
+ final boolean data_is_direct = Buffers.isDirect(data);
+ dispatch_glBufferData(target, size,
+ data_is_direct ? data : Buffers.getArray(data),
+ data_is_direct ? Buffers.getDirectBufferByteOffset(data) : Buffers.getIndirectBufferByteOffset(data),
+ data_is_direct, mutableUsage, glProcAddress);
}
- if( 0 == length ) {
- return null;
+ };
+ private native void dispatch_glBufferData(int target, long size, Object data, int data_byte_offset, boolean data_is_direct, int usage, long procAddress);
+
+ private final jogamp.opengl.GLBufferObjectTracker.UnmapBufferDispatch unmapBoundBufferDispatch =
+ new jogamp.opengl.GLBufferObjectTracker.UnmapBufferDispatch() {
+ public final boolean unmap(final int target, final long glProcAddress) {
+ return dispatch_glUnmapBuffer(target, glProcAddress);
}
- }
- addr = useRange ? dispatch_glMapBufferRange(target, offset, length, access, glProcAddress) :
- dispatch_glMapBuffer(target, access, glProcAddress);
- }
- if (0 == addr) {
- return null;
- }
- final ByteBuffer buffer;
- final MemoryObject memObj0 = new MemoryObject(addr, length); // object and key
- final MemoryObject memObj1 = MemoryObject.getOrAddSafe(arbMemCache, memObj0);
- if(memObj0 == memObj1) {
- // just added ..
- if(null != memObj0.getBuffer()) {
- throw new InternalError();
- }
- buffer = newDirectByteBuffer(addr, length);
- Buffers.nativeOrder(buffer);
- memObj0.setBuffer(buffer);
- } else {
- // already mapped
- buffer = memObj1.getBuffer();
- if(null == buffer) {
- throw new InternalError();
- }
- }
- buffer.position(0);
- return buffer;
+ };
+ private native boolean dispatch_glUnmapBuffer(int target, long procAddress);
+
+ @Override
+ public final java.nio.ByteBuffer glMapBuffer(int target, int access) {
+ return mapBuffer(target, access).getMappedBuffer();
+ }
+
+ @Override
+ public final ByteBuffer glMapBufferRange(int target, long offset, long length, int access) {
+ return mapBufferRange(target, offset, length, access).getMappedBuffer();
}
+
+ private final jogamp.opengl.GLBufferObjectTracker.MapBufferAllDispatch mapBoundBufferAllDispatch =
+ new jogamp.opengl.GLBufferObjectTracker.MapBufferAllDispatch() {
+ public final ByteBuffer allocNioByteBuffer(final long addr, final long length) { return newDirectByteBuffer(addr, length); }
+ public final long mapBuffer(final int target, final int access, final long glProcAddress) {
+ return dispatch_glMapBuffer(target, access, glProcAddress);
+ }
+ };
private native long dispatch_glMapBuffer(int target, int access, long glProcAddress);
- private native long dispatch_glMapBufferRange(int target, long offset, long length, int access, long procAddress);
-
-
- /** Entry point to C language function: GLvoid * {@native glMapNamedBufferEXT}(GLuint buffer, GLenum access);
GL_EXT_direct_state_access
*/
- private final java.nio.ByteBuffer glMapNamedBufferImpl(int bufferName, int access, long glProcAddress) {
- if (glProcAddress == 0) {
- throw new GLException("Method \"glMapNamedBufferEXT\" not available");
- }
- final long addr, sz;
- synchronized(bufferSizeTracker) {
- sz = bufferSizeTracker.getDirectStateBufferSize(bufferName, this);
- if (0 == sz) {
- return null;
- }
- addr = dispatch_glMapNamedBufferEXT(bufferName, access, glProcAddress);
- }
- if (0 == addr) {
- return null;
- }
- final ByteBuffer buffer;
- final MemoryObject memObj0 = new MemoryObject(addr, sz); // object and key
- final MemoryObject memObj1 = MemoryObject.getOrAddSafe(arbMemCache, memObj0);
- if(memObj0 == memObj1) {
- // just added ..
- if(null != memObj0.getBuffer()) {
- throw new InternalError();
- }
- buffer = newDirectByteBuffer(addr, sz);
- Buffers.nativeOrder(buffer);
- memObj0.setBuffer(buffer);
- } else {
- // already mapped
- buffer = memObj1.getBuffer();
- if(null == buffer) {
- throw new InternalError();
- }
- }
- buffer.position(0);
- return buffer;
- }
- private native long dispatch_glMapNamedBufferEXT(int buffer, int access, long procAddress);
+
+ private final jogamp.opengl.GLBufferObjectTracker.MapBufferRangeDispatch mapBoundBufferRangeDispatch =
+ new jogamp.opengl.GLBufferObjectTracker.MapBufferRangeDispatch() {
+ public final ByteBuffer allocNioByteBuffer(final long addr, final long length) { return newDirectByteBuffer(addr, length); }
+ public final long mapBuffer(final int target, final long offset, final long length, final int access, final long glProcAddress) {
+ return dispatch_glMapBufferRange(target, offset, length, access, glProcAddress);
+ }
+ };
+ private native long dispatch_glMapBufferRange(int target, long offset, long length, int access, long glProcAddress);
private native ByteBuffer newDirectByteBuffer(long addr, long capacity);
diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java
index e7389de10..f0adb5328 100644
--- a/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java
+++ b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java
@@ -18,11 +18,11 @@ public void setObjectTracker(GLObjectTracker tracker) {
public GL4bcImpl(GLProfile glp, GLContextImpl context) {
this._context = context;
if(null != context) {
- this.bufferSizeTracker = context.getBufferSizeTracker();
+ this.bufferObjectTracker = context.getBufferObjectTracker();
this.bufferStateTracker = context.getBufferStateTracker();
this.glStateTracker = context.getGLStateTracker();
} else {
- this.bufferSizeTracker = null;
+ this.bufferObjectTracker = null;
this.bufferStateTracker = null;
this.glStateTracker = null;
}
@@ -280,10 +280,6 @@ public final void glFreeMemoryNV(java.nio.ByteBuffer pointer) {
// Helpers for ensuring the correct amount of texture data
//
-private final GLBufferSizeTracker bufferSizeTracker;
-private final GLBufferStateTracker bufferStateTracker;
-private final GLStateTracker glStateTracker;
-
private boolean haveARBPixelBufferObject;
private boolean haveEXTPixelBufferObject;
private boolean haveGL15;
@@ -431,67 +427,207 @@ private final boolean checkPackPBOBound(boolean throwException) {
@Override
public final boolean glIsPBOPackBound() {
+ return isPBOPackBound();
+}
+@Override
+public final boolean isPBOPackBound() {
return checkPackPBOBound(false);
}
@Override
public final boolean glIsPBOUnpackBound() {
+ return isPBOUnpackBound();
+}
+@Override
+public final boolean isPBOUnpackBound() {
return checkUnpackPBOBound(false);
}
-/** Entry point to C language function: void * {@native glMapBuffer}(GLenum target, GLenum access);
GL_VERSION_1_5
; GL_OES_mapbuffer
*/
-public final java.nio.ByteBuffer glMapBuffer(int target, int access) {
- return glMapBufferImpl(target, false, 0, 0, access, ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer);
+@Override
+public final void glVertexPointer(GLArrayData array) {
+ if(array.getComponentCount()==0) return;
+ if(array.isVBO()) {
+ glVertexPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getVBOOffset());
+ } else {
+ glVertexPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getBuffer());
+ }
}
+@Override
+public final void glColorPointer(GLArrayData array) {
+ if(array.getComponentCount()==0) return;
+ if(array.isVBO()) {
+ glColorPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getVBOOffset());
+ } else {
+ glColorPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getBuffer());
+ }
-/** Entry point to C language function: void * {@native glMapBufferRange}(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
GL_ES_VERSION_3_0
, GL_VERSION_3_0
; GL_EXT_map_buffer_range
*/
-public final ByteBuffer glMapBufferRange(int target, long offset, long length, int access) {
- return glMapBufferImpl(target, true, offset, length, access, ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBufferRange);
}
-
-/** Entry point to C language function: GLvoid * {@native glMapNamedBufferEXT}(GLuint buffer, GLenum access);
GL_EXT_direct_state_access
*/
-public final java.nio.ByteBuffer glMapNamedBufferEXT(int bufferName, int access) {
- return glMapNamedBufferImpl(bufferName, access, ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapNamedBufferEXT);
+@Override
+public final void glNormalPointer(GLArrayData array) {
+ if(array.getComponentCount()==0) return;
+ if(array.getComponentCount()!=3) {
+ throw new GLException("Only 3 components per normal allowed");
+ }
+ if(array.isVBO()) {
+ glNormalPointer(array.getComponentType(), array.getStride(), array.getVBOOffset());
+ } else {
+ glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer());
+ }
+}
+@Override
+public final void glTexCoordPointer(GLArrayData array) {
+ if(array.getComponentCount()==0) return;
+ if(array.isVBO()) {
+ glTexCoordPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getVBOOffset());
+ } else {
+ glTexCoordPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getBuffer());
+ }
}
- @Override
- public final void glVertexPointer(GLArrayData array) {
- if(array.getComponentCount()==0) return;
- if(array.isVBO()) {
- glVertexPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getVBOOffset());
- } else {
- glVertexPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getBuffer());
- }
+//
+// GLBufferObjectTracker Redirects
+//
+
+@Override
+public final void glBufferData(int target, long size, Buffer data, int usage) {
+ final long glProcAddress = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glBufferData;
+ if ( 0 == glProcAddress ) {
+ throw new GLException(String.format("Method \"%s\" not available", "glBufferData"));
+ }
+ bufferObjectTracker.createBufferStorage(bufferStateTracker, this,
+ target, size, data, usage, 0 /* immutableFlags */,
+ createBoundMutableStorageDispatch, glProcAddress);
+}
+/** FIXME Add for OpenGL 4.4
+@Override
+public final void glBufferStorage(int target, long size, Buffer data, int flags) {
+ final long glProcAddress = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glBufferStorage;
+ if ( 0 == glProcAddress ) {
+ throw new GLException(String.format("Method \"%s\" not available", "glBufferStorage"));
}
- @Override
- public final void glColorPointer(GLArrayData array) {
- if(array.getComponentCount()==0) return;
- if(array.isVBO()) {
- glColorPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getVBOOffset());
- } else {
- glColorPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getBuffer());
- }
+ bufferObjectTracker.createBufferStorage(bufferStateTracker, this,
+ target, size, data, 0 * mutableUsage *, flags,
+ createBoundImmutableStorageDispatch, glProcAddress);
+}
+private final jogamp.opengl.GLBufferObjectTracker.CreateStorageDispatch createBoundImmutableStorageDispatch =
+ new jogamp.opengl.GLBufferObjectTracker.CreateStorageDispatch() {
+ public final void create(final int target, final long size, final Buffer data, final int immutableFlags, final long glProcAddress) {
+ final boolean data_is_direct = Buffers.isDirect(data);
+ dispatch_glBufferStorage(target, size,
+ data_is_direct ? data : Buffers.getArray(data),
+ data_is_direct ? Buffers.getDirectBufferByteOffset(data) : Buffers.getIndirectBufferByteOffset(data),
+ data_is_direct, immutableFlags, glProcAddress);
+ }
+ };
+private native void dispatch_glBufferStorage(int target, long size, Object data, int data_byte_offset, boolean data_is_direct, int flags, long procAddress);
+ */
+@Override
+public final void glNamedBufferDataEXT(int buffer, long size, Buffer data, int usage) {
+ final long glProcAddress = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glNamedBufferDataEXT;
+ if ( 0 == glProcAddress ) {
+ throw new GLException(String.format("Method \"%s\" not available", "glNamedBufferDataEXT"));
}
- @Override
- public final void glNormalPointer(GLArrayData array) {
- if(array.getComponentCount()==0) return;
- if(array.getComponentCount()!=3) {
- throw new GLException("Only 3 components per normal allowed");
- }
- if(array.isVBO()) {
- glNormalPointer(array.getComponentType(), array.getStride(), array.getVBOOffset());
- } else {
- glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer());
- }
+ bufferObjectTracker.createBufferStorage(this,
+ buffer, size, data, usage, 0 /* immutableFlags */,
+ createNamedStorageDispatch, glProcAddress);
+}
+private final jogamp.opengl.GLBufferObjectTracker.CreateStorageDispatch createNamedStorageDispatch =
+ new jogamp.opengl.GLBufferObjectTracker.CreateStorageDispatch() {
+ public final void create(final int buffer, final long size, final Buffer data, final int mutableUsage, final long glProcAddress) {
+ final boolean data_is_direct = Buffers.isDirect(data);
+ dispatch_glNamedBufferDataEXT(buffer, size,
+ data_is_direct ? data : Buffers.getArray(data),
+ data_is_direct ? Buffers.getDirectBufferByteOffset(data) : Buffers.getIndirectBufferByteOffset(data),
+ data_is_direct, mutableUsage, glProcAddress);
+ }
+ };
+private native void dispatch_glNamedBufferDataEXT(int buffer, long size, Object data, int data_byte_offset, boolean data_is_direct, int usage, long procAddress);
+
+@Override
+public boolean glUnmapBuffer(int target) {
+ final long glProcAddress = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glUnmapBuffer;
+ if ( 0 == glProcAddress ) {
+ throw new GLException(String.format("Method \"%s\" not available", "glUnmapBuffer"));
}
- @Override
- public final void glTexCoordPointer(GLArrayData array) {
- if(array.getComponentCount()==0) return;
- if(array.isVBO()) {
- glTexCoordPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getVBOOffset());
- } else {
- glTexCoordPointer(array.getComponentCount(), array.getComponentType(), array.getStride(), array.getBuffer());
- }
+ return bufferObjectTracker.unmapBuffer(bufferStateTracker, this, target, unmapBoundBufferDispatch, glProcAddress);
+}
+
+@Override
+public boolean glUnmapNamedBufferEXT(int buffer) {
+ final long glProcAddress = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glUnmapNamedBufferEXT;
+ if ( 0 == glProcAddress ) {
+ throw new GLException(String.format("Method \"%s\" not available", "glUnmapNamedBufferEXT"));
}
+ return bufferObjectTracker.unmapBuffer(buffer, unmapNamedBufferDispatch, glProcAddress);
+}
+private final jogamp.opengl.GLBufferObjectTracker.UnmapBufferDispatch unmapNamedBufferDispatch =
+ new jogamp.opengl.GLBufferObjectTracker.UnmapBufferDispatch() {
+ public final boolean unmap(final int buffer, final long glProcAddress) {
+ return dispatch_glUnmapNamedBufferEXT(buffer, glProcAddress);
+ }
+ };
+private native boolean dispatch_glUnmapNamedBufferEXT(int buffer, long procAddress);
+
+@Override
+public final GLBufferStorage mapBuffer(final int target, final int access) {
+ final long glProcAddress = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer;
+ if ( 0 == glProcAddress ) {
+ throw new GLException("Method \"glMapBuffer\" not available");
+ }
+ return bufferObjectTracker.mapBuffer(bufferStateTracker, this, target, access, mapBoundBufferAllDispatch, glProcAddress);
+}
+@Override
+public final GLBufferStorage mapBufferRange(final int target, final long offset, final long length, final int access) {
+ final long glProcAddress = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBufferRange;
+ if ( 0 == glProcAddress ) {
+ throw new GLException("Method \"glMapBufferRange\" not available");
+ }
+ return bufferObjectTracker.mapBuffer(bufferStateTracker, this, target, offset, length, access, mapBoundBufferRangeDispatch, glProcAddress);
+}
+
+@Override
+public final GLBufferStorage mapNamedBuffer(final int bufferName, final int access) {
+ final long glProcAddress = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapNamedBufferEXT;
+ if ( 0 == glProcAddress ) {
+ throw new GLException("Method \"glMapNamedBufferEXT\" not available");
+ }
+ return bufferObjectTracker.mapBuffer(bufferName, access, mapNamedBufferAllDispatch, glProcAddress);
+}
+private final jogamp.opengl.GLBufferObjectTracker.MapBufferAllDispatch mapNamedBufferAllDispatch =
+ new jogamp.opengl.GLBufferObjectTracker.MapBufferAllDispatch() {
+ public final ByteBuffer allocNioByteBuffer(final long addr, final long length) { return newDirectByteBuffer(addr, length); }
+ public final long mapBuffer(final int bufferName, final int access, final long glProcAddress) {
+ return dispatch_glMapNamedBufferEXT(bufferName, access, glProcAddress);
+ }
+ };
+private native long dispatch_glMapNamedBufferEXT(int buffer, int access, long glProcAddress);
+
+@Override
+public final GLBufferStorage mapNamedBufferRange(final int bufferName, final long offset, final long length, final int access) {
+ final long glProcAddress = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapNamedBufferRangeEXT;
+ if ( 0 == glProcAddress ) {
+ throw new GLException("Method \"glMapNamedBufferRangeEXT\" not available");
+ }
+ return bufferObjectTracker.mapBuffer(bufferName, offset, length, access, mapNamedBufferRangeDispatch, glProcAddress);
+}
+private final jogamp.opengl.GLBufferObjectTracker.MapBufferRangeDispatch mapNamedBufferRangeDispatch =
+ new jogamp.opengl.GLBufferObjectTracker.MapBufferRangeDispatch() {
+ public final ByteBuffer allocNioByteBuffer(final long addr, final long length) { return newDirectByteBuffer(addr, length); }
+ public final long mapBuffer(final int bufferName, final long offset, final long length, final int access, final long glProcAddress) {
+ return dispatch_glMapNamedBufferRangeEXT(bufferName, offset, length, access, glProcAddress);
+ }
+ };
+private native long dispatch_glMapNamedBufferRangeEXT(int buffer, long offset, long length, int access, long procAddress);
+
+@Override
+public final java.nio.ByteBuffer glMapNamedBufferEXT(int bufferName, int access) {
+ return mapNamedBuffer(bufferName, access).getMappedBuffer();
+}
+
+@Override
+public final ByteBuffer glMapNamedBufferRangeEXT(int bufferName, long offset, long length, int access) {
+ return mapNamedBufferRange(bufferName, offset, length, access).getMappedBuffer();
+}
+
diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java
index 8d5dcc7a5..6a7e12ca1 100644
--- a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java
+++ b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java
@@ -1,11 +1,11 @@
public GLES1Impl(GLProfile glp, GLContextImpl context) {
this._context = context;
if(null != context) {
- this.bufferSizeTracker = context.getBufferSizeTracker();
+ this.bufferObjectTracker = context.getBufferObjectTracker();
this.bufferStateTracker = context.getBufferStateTracker();
this.glStateTracker = context.getGLStateTracker();
} else {
- this.bufferSizeTracker = null;
+ this.bufferObjectTracker = null;
this.bufferStateTracker = null;
this.glStateTracker = null;
}
@@ -199,10 +199,6 @@ public final GL2GL3 getGL2GL3() throws GLException {
// Helpers for ensuring the correct amount of texture data
//
-private final GLBufferSizeTracker bufferSizeTracker;
-private final GLBufferStateTracker bufferStateTracker;
-private final GLStateTracker glStateTracker;
-
private final boolean checkBufferObject(boolean bound,
int state,
String kind, boolean throwException) {
@@ -269,16 +265,6 @@ private final boolean checkPackPBOBound(boolean throwException) {
return false;
}
-/** Entry point to C language function: void * {@native glMapBuffer}(GLenum target, GLenum access);
GL_VERSION_1_5
; GL_OES_mapbuffer
*/
-public final java.nio.ByteBuffer glMapBuffer(int target, int access) {
- return glMapBufferImpl(target, false, 0, 0, access, ((GLES1ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer);
-}
-
-/** Entry point to C language function: void * {@native glMapBufferRange}(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
GL_ES_VERSION_3_0
, GL_VERSION_3_0
; GL_EXT_map_buffer_range
*/
-public final ByteBuffer glMapBufferRange(int target, long offset, long length, int access) {
- return glMapBufferImpl(target, true, offset, length, access, ((GLES1ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBufferRange);
-}
-
@Override
public final void glVertexPointer(GLArrayData array) {
if(array.getComponentCount()==0) return;
@@ -320,3 +306,44 @@ public final void glTexCoordPointer(GLArrayData array) {
}
}
+//
+// GLBufferObjectTracker Redirects
+//
+
+@Override
+public final void glBufferData(int target, long size, Buffer data, int usage) {
+ final long glProcAddress = ((GLES1ProcAddressTable)_context.getGLProcAddressTable())._addressof_glBufferData;
+ if ( 0 == glProcAddress ) {
+ throw new GLException(String.format("Method \"%s\" not available", "glBufferData"));
+ }
+ bufferObjectTracker.createBufferStorage(bufferStateTracker, this,
+ target, size, data, usage, 0 /* immutableFlags */,
+ createBoundMutableStorageDispatch, glProcAddress);
+}
+
+@Override
+public boolean glUnmapBuffer(int target) {
+ final long glProcAddress = ((GLES1ProcAddressTable)_context.getGLProcAddressTable())._addressof_glUnmapBuffer;
+ if ( 0 == glProcAddress ) {
+ throw new GLException(String.format("Method \"%s\" not available", "glUnmapBuffer"));
+ }
+ return bufferObjectTracker.unmapBuffer(bufferStateTracker, this, target, unmapBoundBufferDispatch, glProcAddress);
+}
+
+@Override
+public final GLBufferStorage mapBuffer(final int target, final int access) {
+ final long glProcAddress = ((GLES1ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer;
+ if ( 0 == glProcAddress ) {
+ throw new GLException("Method \"glMapBuffer\" not available");
+ }
+ return bufferObjectTracker.mapBuffer(bufferStateTracker, this, target, access, mapBoundBufferAllDispatch, glProcAddress);
+}
+@Override
+public final GLBufferStorage mapBufferRange(final int target, final long offset, final long length, final int access) {
+ final long glProcAddress = ((GLES1ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBufferRange;
+ if ( 0 == glProcAddress ) {
+ throw new GLException("Method \"glMapBufferRange\" not available");
+ }
+ return bufferObjectTracker.mapBuffer(bufferStateTracker, this, target, offset, length, access, mapBoundBufferRangeDispatch, glProcAddress);
+}
+
diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles3.java b/make/config/jogl/gl-impl-CustomJavaCode-gles3.java
index d5ad16873..a5c0d1998 100644
--- a/make/config/jogl/gl-impl-CustomJavaCode-gles3.java
+++ b/make/config/jogl/gl-impl-CustomJavaCode-gles3.java
@@ -2,11 +2,11 @@
public GLES3Impl(GLProfile glp, GLContextImpl context) {
this._context = context;
if(null != context) {
- this.bufferSizeTracker = context.getBufferSizeTracker();
+ this.bufferObjectTracker = context.getBufferObjectTracker();
this.bufferStateTracker = context.getBufferStateTracker();
this.glStateTracker = context.getGLStateTracker();
} else {
- this.bufferSizeTracker = null;
+ this.bufferObjectTracker = null;
this.bufferStateTracker = null;
this.glStateTracker = null;
}
@@ -211,9 +211,6 @@ public final GL2GL3 getGL2GL3() throws GLException {
//
private final boolean _isES3;
-private final GLBufferSizeTracker bufferSizeTracker;
-private final GLBufferStateTracker bufferStateTracker;
-private final GLStateTracker glStateTracker;
private final boolean checkBufferObject(boolean extensionAvail,
boolean allowVAO,
@@ -333,22 +330,20 @@ private final boolean checkPackPBOBound(boolean throwException) {
@Override
public final boolean glIsPBOPackBound() {
+ return isPBOPackBound();
+}
+@Override
+public final boolean isPBOPackBound() {
return checkPackPBOBound(false);
}
@Override
public final boolean glIsPBOUnpackBound() {
- return checkUnpackPBOBound(false);
+ return isPBOUnpackBound();
}
-
-/** Entry point to C language function: void * {@native glMapBuffer}(GLenum target, GLenum access);
GL_VERSION_1_5
; GL_OES_mapbuffer
*/
-public final java.nio.ByteBuffer glMapBuffer(int target, int access) {
- return glMapBufferImpl(target, false, 0, 0, access, ((GLES3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer);
-}
-
-/** Entry point to C language function: void * {@native glMapBufferRange}(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
GL_ES_VERSION_3_0
, GL_VERSION_3_0
; GL_EXT_map_buffer_range
*/
-public final ByteBuffer glMapBufferRange(int target, long offset, long length, int access) {
- return glMapBufferImpl(target, true, offset, length, access, ((GLES3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBufferRange);
+@Override
+public final boolean isPBOUnpackBound() {
+ return checkUnpackPBOBound(false);
}
@Override
@@ -361,3 +356,45 @@ public final void glDepthRange(double zNear, double zFar) {
glDepthRangef((float)zNear, (float)zFar);
}
+//
+// GLBufferObjectTracker Redirects
+//
+
+@Override
+public final void glBufferData(int target, long size, Buffer data, int usage) {
+ final long glProcAddress = ((GLES3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glBufferData;
+ if ( 0 == glProcAddress ) {
+ throw new GLException(String.format("Method \"%s\" not available", "glBufferData"));
+ }
+ bufferObjectTracker.createBufferStorage(bufferStateTracker, this,
+ target, size, data, usage, 0 /* immutableFlags */,
+ createBoundMutableStorageDispatch, glProcAddress);
+}
+
+@Override
+public boolean glUnmapBuffer(int target) {
+ final long glProcAddress = ((GLES3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glUnmapBuffer;
+ if ( 0 == glProcAddress ) {
+ throw new GLException(String.format("Method \"%s\" not available", "glUnmapBuffer"));
+ }
+ return bufferObjectTracker.unmapBuffer(bufferStateTracker, this, target, unmapBoundBufferDispatch, glProcAddress);
+}
+
+@Override
+public final GLBufferStorage mapBuffer(final int target, final int access) {
+ final long glProcAddress = ((GLES3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer;
+ if ( 0 == glProcAddress ) {
+ throw new GLException("Method \"glMapBuffer\" not available");
+ }
+ return bufferObjectTracker.mapBuffer(bufferStateTracker, this, target, access, mapBoundBufferAllDispatch, glProcAddress);
+}
+@Override
+public final GLBufferStorage mapBufferRange(final int target, final long offset, final long length, final int access) {
+ final long glProcAddress = ((GLES3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBufferRange;
+ if ( 0 == glProcAddress ) {
+ throw new GLException("Method \"glMapBufferRange\" not available");
+ }
+ return bufferObjectTracker.mapBuffer(bufferStateTracker, this, target, offset, length, access, mapBoundBufferRangeDispatch, glProcAddress);
+}
+
+
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 649256393..6bc1d4eb3 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -103,13 +103,17 @@ function jrun() {
#D_ARGS="-Djogl.debug.DebugGL -Djogl.debug.FBObject"
#D_ARGS="-Djogl.debug.FBObject -Djogl.debug.TraceGL -Djogl.debug.GLBufferStateTracker"
#D_ARGS="-Djogl.debug.FBObject"
+ #D_ARGS="-Djogl.debug.GLBufferStateTracker -Djogl.debug.GLBufferObjectTracker -Djogamp.debug.Lock -Djogamp.common.utils.locks.Lock.timeout=600000 -Dnewt.debug.EDT"
+ #D_ARGS="-Djogl.debug.GLBufferStateTracker -Djogl.debug.GLBufferObjectTracker"
+ #D_ARGS="-Djogl.debug.GLBufferObjectTracker"
+ #D_ARGS="-Djogl.debug.GLBufferObjectTracker -Djogl.debug.GLArrayData -Djogl.debug.TraceGL -Djogl.debug.DebugGL"
#D_ARGS="-Djogl.debug.GLSLCode"
#D_ARGS="-Djogl.debug.GLSLCode -Djogl.debug.DebugGL"
#D_ARGS="-Dnativewindow.debug.X11Util -Dnativewindow.debug.X11Util.TraceDisplayLifecycle -Djogl.debug.EGLDisplayUtil -Djogl.debug.GLDrawable"
#D_ARGS="-Djogl.debug.GLContext -Dnativewindow.debug.JAWT -Dnewt.debug.Window"
#D_ARGS="-Dnativewindow.debug.JAWT -Djogl.debug.GLCanvas"
#D_ARGS="-Dnativewindow.debug.JAWT -Djogamp.debug.TaskBase.TraceSource"
- D_ARGS="-Dnativewindow.debug.JAWT"
+ #D_ARGS="-Dnativewindow.debug.JAWT"
#D_ARGS="-Djogl.debug.GLContext.TraceSwitch"
#D_ARGS="-Djogl.debug.GLContext -Djogl.debug.GLContext.TraceSwitch"
#D_ARGS="-Djogl.debug.FixedFuncPipeline -Djogl.debug.GLSLCode"
@@ -208,6 +212,7 @@ function jrun() {
#D_ARGS="-Xprof"
#D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Java2D -Djogl.debug.GLJPanel"
#D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Java2D -Djogl.debug.GLJPanel -Djogl.gljpanel.noglsl"
+ #D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Java2D -Djogl.debug.GLJPanel -Djogl.gljpanel.noglsl -Djogl.gljpanel.awtverticalflip"
#D_ARGS="-Djogl.debug.GLJPanel -Djogl.debug.DebugGL"
#D_ARGS="-Djogl.gljpanel.noverticalflip"
#D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Animator"
@@ -390,7 +395,13 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLDebug00NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLDebug01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGPUMemSec01NEWT $*
+
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMapBufferRead01NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestRedSquareES2NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES2NEWT0 $*
+testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES2NEWT3 $*
+
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestBug669RecursiveGLContext01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestBug669RecursiveGLContext02NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestBug692GL3VAONEWT $*
@@ -536,7 +547,7 @@ function testawtswt() {
# OK (X11, OSX)
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug816OSXCALayerPos03cB849AWT $*
-testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug816OSXCALayerPos01AWT $*
+#testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug816OSXCALayerPos01AWT $*
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug816OSXCALayerPos02AWT $*
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug816GLCanvasFrameHoppingB849B889AWT $*
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug816OSXCALayerPos04aAWT $*
diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java
index df60d2f73..023913d7b 100644
--- a/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java
+++ b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java
@@ -41,6 +41,7 @@ package com.jogamp.gluegen.opengl;
import com.jogamp.gluegen.CodeGenUtils;
import com.jogamp.gluegen.JavaType;
+
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
@@ -50,6 +51,7 @@ import java.lang.reflect.Method;
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -82,6 +84,16 @@ public class BuildComposablePipeline {
*/
public static final int GEN_GL_IDENTITY_BY_ASSIGNABLE_CLASS = 1 << 4;
+ private static final HashMap+ * {@link GL#glMapBuffer(int, int)} wrapper calls this method and returns {@link GLBufferStorage#getMappedBuffer()}. + *
+ *+ * A zero {@link GLBufferStorage#getSize()} will avoid a native call and returns the unmapped {@link GLBufferStorage}. + *
+ *+ * A null native mapping result indicating an error will + * not cause a GLException but returns the unmapped {@link GLBufferStorage}. + * This allows the user to handle this case. + *
+ * @param target denotes the buffer via it's bound target + * @param access the mapping access mode + * @throws GLException if buffer is not bound to target + * @throws GLException if buffer is not tracked + * @throws GLException if buffer is already mapped + * @throws GLException if buffer has invalid store size, i.e. less-than zero + */ + public GLBufferStorage mapBuffer(int target, int access) throws GLException; + + /** + * Returns the {@link GLBufferStorage} instance as mapped via OpenGL's native {@link GL#glMapBufferRange(int, long, long, int) glMapBufferRange(..)} implementation. + *+ * Throws a {@link GLException} if GL-function constraints are not met. + *
+ *+ * {@link GL#glMapBufferRange(int, long, long, int)} wrapper calls this method and returns {@link GLBufferStorage#getMappedBuffer()}. + *
+ *+ * A zero {@link GLBufferStorage#getSize()} will avoid a native call and returns the unmapped {@link GLBufferStorage}. + *
+ *+ * A null native mapping result indicating an error will + * not cause a GLException but returns the unmapped {@link GLBufferStorage}. + * This allows the user to handle this case. + *
+ * @param target denotes the buffer via it's bound target + * @param offset offset of the mapped buffer's storage + * @param length length of the mapped buffer's storage + * @param access the mapping access mode + * @throws GLException if buffer is not bound to target + * @throws GLException if buffer is not tracked + * @throws GLException if buffer is already mapped + * @throws GLException if buffer has invalid store size, i.e. less-than zero + * @throws GLException if buffer mapping range does not fit, incl. offset + */ + public GLBufferStorage mapBufferRange(final int target, final long offset, final long length, final int access) throws GLException; + + /** + * @deprecated Avoid original GL API namespace conflict. Use {@link #isVBOArrayBound()} */ public boolean glIsVBOArrayBound(); + /** + * @return true if a VBO is bound to {@link GL#GL_ARRAY_BUFFER} via {@link GL#glBindBuffer(int, int)}, otherwise false + */ + public boolean isVBOArrayBound(); /** - * @return true if a VBO is bound to {@link GL#GL_ELEMENT_ARRAY_BUFFER} via {@link GL#glBindBuffer(int, int)}, otherwise false + * @deprecated Avoid original GL API namespace conflict. Use {@link #isVBOElementArrayBound()} */ public boolean glIsVBOElementArrayBound(); + /** + * @return true if a VBO is bound to {@link GL#GL_ELEMENT_ARRAY_BUFFER} via {@link GL#glBindBuffer(int, int)}, otherwise false + */ + public boolean isVBOElementArrayBound(); /** * Return the framebuffer name bound to this context, diff --git a/src/jogl/classes/javax/media/opengl/GLBufferStorage.java b/src/jogl/classes/javax/media/opengl/GLBufferStorage.java new file mode 100644 index 000000000..929ecf60a --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLBufferStorage.java @@ -0,0 +1,150 @@ +/** + * Copyright 2014 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``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 JogAmp Community 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. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package javax.media.opengl; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +/** + * OpenGL buffer storage object reflecting it's + *+ * Buffer storage is created via: + *
glBufferStorage
- storage creation with target+ * Buffer storage is disposed via: + *
+ * GL buffer storage is mapped via + *
+ * GL buffer storage is unmapped via + *
true
if buffer's storage is mutable, i.e.
+ * created via {@link GL#glBufferData(int, long, java.nio.Buffer, int)}.
+ *
+ * Returns false
if buffer's storage is immutable, i.e.
+ * created via glBufferStorage
. FIXME: Add GL 4.4 support!
+ *
+ * See {@link GLBufferStorage} for generic details. + *
+ *+ * Buffer storage is created via + *
glBufferStorage
- storage creation with target via {@link #createBufferStorage(GLBufferStateTracker, GL, int, long, Buffer, int, int, CreateStorageDispatch, long)}+ * Buffers storage is disposed via + *
+ * Implementation throws a {@link GLException} in all construction methods as listed below,
+ * if GL-function constraints are not met. createBufferStorage
also throws an exception
+ * if the native GL-function fails.
+ *
+ * Buffer mapping methods like {@link GL#mapBuffer(int, int)} ..., + * require knowledge of the buffer's storage size as determined via it's creation with + * {@link GL#glBufferData(int, long, java.nio.Buffer, int)} .... + *
+ *+ * Hence we track the OpenGL buffer's {@link GLBufferStorage} to be able to + * access the buffer's storage size. The tracked {@link GLBufferStorage} instances + * also allow users to conveniently access details of their created and maybe mapped buffer storage. + *
+ *+ * The {@link GLBufferObjectTracker} and it's tracked {@link GLBufferStorage} instances + * maybe shared across multiple OpenGL context, hence this class is thread safe and employs synchronization. + *
+ *+ * Implementation requires and utilizes a local {@link GLBufferStateTracker} + * to resolve the actual buffer-name bound to the given target. + *
+ *+ * Note: This tracker requires to be notified about all OpenGL buffer storage operations, + * as well as the local {@link GLBufferStateTracker} to be notified about all + * OpenGL buffer binding operations. + * Hence buffer storage cannot be accessed properly if managed via native code. + *
+ */ +public class GLBufferObjectTracker { + protected static final boolean DEBUG; + + static { + Debug.initSingleton(); + DEBUG = Debug.isPropertyDefined("jogl.debug.GLBufferObjectTracker", true); + } + + static final class GLBufferStorageImpl extends GLBufferStorage { + GLBufferStorageImpl(final int name, final long size, final int mutableUsage, final int immutableFlags) { + super(name, size, mutableUsage, immutableFlags); + } + final void setMappedBuffer(final ByteBuffer bb) { + if (DEBUG) { + System.err.printf("%s.GLBufferStorage.setMappedBuffer: %s: %s -> %s%n", msgClazzName, toString(true), mappedBuffer, bb); + } + mappedBuffer = bb; + } + } + + /** + * Map from buffer names to GLBufferObject. + */ + private final IntObjectHashMap bufferName2StorageMap; + + public GLBufferObjectTracker() { + bufferName2StorageMap = new IntObjectHashMap(); + bufferName2StorageMap.setKeyNotFoundValue(null); + } + + public static interface CreateStorageDispatch { + void create(final int targetOrBufferName, final long size, final Buffer data, final int mutableUsageOrImmutableFlags, final long glProcAddress); + } + + /** + * Must be called when [re]creating the GL buffer object viaglBufferStorage
and {@link GL#glBufferData(int, long, java.nio.Buffer, int)},
+ * i.e. implies destruction of the buffer.
+ *
+ * @param bufferStateTracker
+ * @param caller
+ * @param target
+ * @param size
+ * @param mutableUsage glBufferData
, glNamedBufferDataEXT
usage
+ * @param immutableFlags glBufferStorage
flags
+ * @throws GLException if buffer is not bound to target
+ * @throws GLException if size is less-or-eqaul zero for glBufferStorage
, or size is less-than zero otherwise
+ * @throws GLException if a native GL-Error occurs
+ */
+ public synchronized final void createBufferStorage(final GLBufferStateTracker bufferStateTracker, final GL caller,
+ final int target, final long size, final Buffer data, int mutableUsage, int immutableFlags,
+ final CreateStorageDispatch dispatch, final long glProcAddress) throws GLException {
+ final int glerrPre = caller.glGetError(); // clear
+ if (DEBUG && GL.GL_NO_ERROR != glerrPre) {
+ System.err.printf("%s.%s glerr-pre 0x%X%n", msgClazzName, msgCreateBound, glerrPre);
+ }
+ final int bufferName = bufferStateTracker.getBoundBufferObject(target, caller);
+ if ( 0 == bufferName ) {
+ throw new GLException(String.format("%s: Buffer for target 0x%X not bound", GL_INVALID_OPERATION, target));
+ }
+ final boolean mutableBuffer = 0 != mutableUsage;
+ final boolean invalidSize = ( mutableBuffer && 0 > size ) // glBufferData, glNamedBufferDataEXT
+ || ( !mutableBuffer && 0 >= size ); // glBufferStorage
+ if( invalidSize ) {
+ throw new GLException(String.format("%s: Invalid size %d for buffer %d on target 0x%X", GL_INVALID_VALUE, size, bufferName, target));
+ }
+
+ dispatch.create(target, size, data, mutableBuffer ? mutableUsage : immutableFlags, glProcAddress);
+ final int glerrPost = caller.glGetError(); // be safe, catch failure!
+ if(GL.GL_NO_ERROR != glerrPost) {
+ throw new GLException(String.format("GL-Error 0x%X while creating %s storage for target 0x%X -> buffer %d of size %d with data %s",
+ glerrPost, mutableBuffer ? "mutable" : "immutable", target, bufferName, size, data));
+ }
+ final GLBufferStorageImpl objNew = new GLBufferStorageImpl(bufferName, size, mutableUsage, immutableFlags);
+ final GLBufferStorageImpl objOld = (GLBufferStorageImpl) bufferName2StorageMap.put(bufferName, objNew);
+ if (DEBUG) {
+ System.err.printf("%s.%s target: 0x%X -> %d: %s -> %s%n", msgClazzName, msgCreateBound, target, bufferName, objOld, objNew);
+ }
+ if( null != objOld ) {
+ objOld.setMappedBuffer(null);
+ }
+ }
+
+ /**
+ * Must be called when [re]creating the GL buffer object via {@link GL2#glNamedBufferDataEXT(int, long, java.nio.Buffer, int)},
+ * i.e. implies destruction of the buffer.
+ *
+ * @param bufferName
+ * @param size
+ * @param mutableUsage
+ * @throws GLException if size is less-than zero
+ * @throws GLException if a native GL-Error occurs
+ */
+ public synchronized final void createBufferStorage(final GL caller,
+ final int bufferName, final long size, final Buffer data, final int mutableUsage, int immutableFlags,
+ final CreateStorageDispatch dispatch, final long glProcAddress) throws GLException {
+ final int glerrPre = caller.glGetError(); // clear
+ if (DEBUG && GL.GL_NO_ERROR != glerrPre) {
+ System.err.printf("%s.%s glerr-pre 0x%X%n", msgClazzName, msgCreateNamed, glerrPre);
+ }
+ if ( 0 > size ) { // glBufferData, glNamedBufferDataEXT
+ throw new GLException(String.format("%s: Invalid size %d for buffer %d", GL_INVALID_VALUE, size, bufferName));
+ }
+ final boolean mutableBuffer = 0 != mutableUsage;
+ if( !mutableBuffer ) {
+ throw new InternalError("Immutable glNamedBufferStorageEXT not supported yet");
+ }
+ dispatch.create(bufferName, size, data, mutableUsage, glProcAddress);
+ final int glerrPost = caller.glGetError(); // be safe, catch failure!
+ if(GL.GL_NO_ERROR != glerrPost) {
+ throw new GLException(String.format("GL-Error 0x%X while creating %s storage for buffer %d of size %d with data %s",
+ glerrPost, "mutable", bufferName, size, data));
+ }
+ final GLBufferStorageImpl objNew = new GLBufferStorageImpl(bufferName, size, mutableUsage, 0 /* immutableFlags */);
+ final GLBufferStorageImpl objOld = (GLBufferStorageImpl) bufferName2StorageMap.put(bufferName, objNew);
+ if (DEBUG) {
+ System.err.printf("%s.%s direct: %d: %s -> %s%n", msgClazzName, msgCreateNamed, bufferName, objOld, objNew);
+ }
+ if( null != objOld ) {
+ objOld.setMappedBuffer(null);
+ }
+ }
+
+ /**
+ * Must be called when deleting GL buffer objects vis glDeleteBuffers
.
+ * @param count
+ * @param bufferNames
+ * @param offset
+ */
+ public synchronized final void notifyBuffersDeleted(final int count, final int[] bufferNames, final int offset) {
+ for(int i=0; i+ * A zero store size will avoid a native call and returns the unmapped {@link GLBufferStorage}. + *
+ *+ * A null native mapping result indicating an error will + * not cause a GLException but returns the unmapped {@link GLBufferStorage}. + * This allows the user to handle this case. + *
+ * @throws GLException if buffer is not tracked + * @throws GLException if buffer is already mapped + * @throws GLException if buffer has invalid store size, i.e. less-than zero + * @throws GLException if buffer mapping range does not fit, incl. optional offset + */ + private synchronized final GLBufferStorage mapBufferImpl(final int target, final int bufferName, final boolean isNamedBuffer, final boolean useRange, long offset, + long length, final int access, final MapBufferDispatch dispatch, + final long glProcAddress) throws GLException { + final GLBufferStorageImpl store = (GLBufferStorageImpl)bufferName2StorageMap.get(bufferName); + if ( null == store ) { + throw new GLException("Buffer with name "+bufferName+" not tracked"); + } + if( null != store.getMappedBuffer() ) { + throw new GLException(String.format("%s.%s: %s Buffer storage of target 0x%X -> %d: %s is already mapped", msgClazzName, msgMapBuffer, GL_INVALID_OPERATION, target, bufferName, store)); + } + final long storeSize = store.getSize(); + if ( 0 > storeSize ) { + throw new GLException(String.format("%s.%s: %s Buffer storage of target 0x%X -> %d: %s is of less-than zero", msgClazzName, msgMapBuffer, GL_INVALID_OPERATION, target, bufferName, store)); + } + if( !useRange ) { + length = storeSize; + offset = 0; + } + if( length + offset > storeSize ) { + throw new GLException(String.format("%s.%s: %s Out of range: offset %d, length %d, buffer storage of target 0x%X -> %d: %s", msgClazzName, msgMapBuffer, GL_INVALID_VALUE, offset, length, target, bufferName, store)); + } + if( 0 >= length || 0 > offset ) { + throw new GLException(String.format("%s.%s: %s Invalid values: offset %d, length %d, buffer storage of target 0x%X -> %d: %s", msgClazzName, msgMapBuffer, GL_INVALID_VALUE, offset, length, target, bufferName, store)); + } + if( 0 == storeSize ) { + return store; + } + final long addr; + if( isNamedBuffer ) { + if( useRange ) { + addr = ((MapBufferRangeDispatch)dispatch).mapBuffer(bufferName, offset, length, access, glProcAddress); + } else { + addr = ((MapBufferAllDispatch)dispatch).mapBuffer(bufferName, access, glProcAddress); + } + } else { + if( useRange ) { + addr = ((MapBufferRangeDispatch)dispatch).mapBuffer(target, offset, length, access, glProcAddress); + } else { + addr = ((MapBufferAllDispatch)dispatch).mapBuffer(target, access, glProcAddress); + } + } + // GL's map-buffer implementation always returns NULL on error, + // user shall validate the result and the corresponding getGLError() value! + if ( 0 == addr ) { + if( DEBUG ) { + System.err.printf("%s.%s: %s MapBuffer null result for target 0x%X -> %d: %s, off %d, len %d, acc 0x%X%n", msgClazzName, msgMapBuffer, warning, target, bufferName, store, offset, length, access); + Thread.dumpStack(); + } + // User shall handle the glError ! + } else { + final ByteBuffer buffer = dispatch.allocNioByteBuffer(addr, length); + Buffers.nativeOrder(buffer); + if( DEBUG ) { + System.err.printf("%s.%s: Target 0x%X -> %d: %s, off %d, len %d, acc 0x%X%n", msgClazzName, msgClazzName, target, bufferName, store.toString(false), offset, length, access); + } + store.setMappedBuffer(buffer); + } + return store; + } + + public static interface UnmapBufferDispatch { + boolean unmap(final int targetOrBufferName, final long glProcAddress); + } + + /** + * Must be called when unmapping GL buffer objects via {@link GL#glUnmapBuffer(int)}. + *+ * Only clear mapped buffer reference of {@link GLBufferStorage} + * if native unmapping was successful. + *
+ */ + public synchronized final boolean unmapBuffer(final GLBufferStateTracker bufferStateTracker, final GL caller, + final int target, + final UnmapBufferDispatch dispatch, final long glProcAddress) { + final int bufferName = bufferStateTracker.getBoundBufferObject(target, caller); + final GLBufferStorageImpl store; + if( 0 == bufferName ) { + if (DEBUG) { + System.err.printf("%s: %s.%s: Buffer for target 0x%X not bound%n", warning, msgClazzName, msgUnmapped, target); + Thread.dumpStack(); + } + store = null; + } else { + store = (GLBufferStorageImpl) bufferName2StorageMap.get(bufferName); + if( DEBUG && null == store ) { + System.err.printf("%s: %s.%s: Buffer %d not tracked%n", warning, msgClazzName, msgUnmapped, bufferName); + Thread.dumpStack(); + } + } + final boolean res = dispatch.unmap(target, glProcAddress); + if( res && null != store ) { + store.setMappedBuffer(null); + } + if( DEBUG ) { + System.err.printf("%s.%s %s target: 0x%X -> %d: %s%n", msgClazzName, msgUnmapped, res ? "OK" : "Failed", target, bufferName, store.toString(false)); + if(!res) { + Thread.dumpStack(); + } + } + return res; + } + /** + * Must be called when unmapping GL buffer objects via {@link GL2#glUnmapNamedBufferEXT(int)}. + *+ * Only clear mapped buffer reference of {@link GLBufferStorage} + * if native unmapping was successful. + *
+ */ + public synchronized final boolean unmapBuffer(final int bufferName, + final UnmapBufferDispatch dispatch, final long glProcAddress) { + final GLBufferStorageImpl store = (GLBufferStorageImpl) bufferName2StorageMap.get(bufferName); + if (DEBUG && null == store ) { + System.err.printf("%s: %s.%s: Buffer %d not tracked%n", warning, msgClazzName, msgUnmapped, bufferName); + Thread.dumpStack(); + } + final boolean res = dispatch.unmap(bufferName, glProcAddress); + if( res && null != store ) { + store.setMappedBuffer(null); + } + if (DEBUG) { + System.err.printf("%s.%s %s %d: %s%n", msgClazzName, msgUnmapped, res ? "OK" : "Failed", bufferName, store.toString(false)); + if(!res) { + Thread.dumpStack(); + } + } + return res; + } + + public synchronized final long getBufferSize(final int bufferName) { + final GLBufferStorageImpl store = (GLBufferStorageImpl)bufferName2StorageMap.get(bufferName); + if ( null == store ) { + if (DEBUG) { + System.err.printf("%s: %s.getBufferSize(): Buffer %d not tracked%n", warning, msgClazzName, bufferName); + Thread.dumpStack(); + } + return 0; + } + return store.getSize(); + } + + public synchronized final GLBufferStorage getBufferStorage(final int bufferName) { + return (GLBufferStorageImpl)bufferName2StorageMap.get(bufferName); + } + + /** + * Clear all tracked buffer object knowledge. + *+ * Shall only be called at GLContext destruction iff + * there are no other shared GLContext instances left. + *
+ */ + public synchronized final void clear() { + if (DEBUG) { + System.err.printf("%s.clear() - Thread %s%n", msgClazzName, Thread.currentThread().getName()); + // Thread.dumpStack(); + } + bufferName2StorageMap.clear(); + } + + private static final String warning = "WARNING"; + private static final String msgClazzName = "GLBufferObjectTracker"; + private static final String msgUnmapped = "notifyBufferUnmapped()"; + private static final String msgCreateBound = "createBoundBufferStorage()"; + private static final String msgCreateNamed = "createNamedBufferStorage()"; + private static final String msgMapBuffer = "mapBuffer()"; +} diff --git a/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java b/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java deleted file mode 100644 index b6d9b5682..000000000 --- a/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution 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 Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package jogamp.opengl; - -import javax.media.opengl.*; -import com.jogamp.common.util.IntLongHashMap; - -/** - * Tracks as closely as possible the sizes of allocated OpenGL buffer - * objects. - *
- * glMapBuffer
or glMapBufferRange
etc
- * returns a java.nio.ByteBuffer
- * instance reflecting the returned native address of respective calls
- * and the actual buffer size.
- *
- * In case the buffer size is unknown, we need to compute this size by using
- * glGetBufferParameteriv
with a pname of GL_BUFFER_SIZE
.
- * The latter appears to be problematic due to the returned int
value,
- * where size should be of type long
.
- * Further more, this query appears to be costly for each glMapBuffer call
- * at for Apple's new multithreaded OpenGL implementation.
- *
- * The buffer size state is shared across all shared OpenGL context, - * hence we share the GLBufferSizeTracker instance across all shared GLContexts. - * Hence utilizing this instance must be synchronized to be thread safe due to multithreading usage. - *
- *
- * We track the sizes of allocated buffer objects.
- * We track calls to glBindBuffer
etc to see which buffer is bound to
- * which target and to glBufferData
to see how large the buffer's
- * allocated size is. When glMapBuffer
is called, we consult our table
- * of buffer sizes to see if we can return an answer without a glGet
- * call.
- *
- * In the face of calls to glPushClientAttrib / glPopClientAttrib we currently punt
- * and re-fetch the bound buffer object for the state in question;
- * see, for example, glVertexPointer
and the calls down to
- * GLBufferStateTracker.getBoundBufferObject()
. Note that we currently
- * ignore new binding targets such as GL_TRANSFORM_FEEDBACK_BUFFER_NV
;
- * the fact that new binding targets may be added in the future makes
- * it impossible to cache state for these new targets.
- *
- * Ignoring new binding targets, the primary situation in which we may
- * not be able to return a cached answer is in the case of an error,
- * where glBindBuffer
may not have been called before trying to call
- * glBufferData
. Also, if external native code modifies a buffer
- * object, we may return an incorrect answer. (FIXME: this case
- * requires more thought, and perhaps stochastic and
- * exponential-fallback checking. However, note that it can only occur
- * in the face of external native code which requires that the
- * application be signed anyway, so there is no security risk in this
- * area.)
- *
glBindBuffer
glBindBufferBase
glBindBufferRange