From 66089a33ea4efda711a3a5180f0b001bdac48dcf Mon Sep 17 00:00:00 2001 From: Jack Palevich Date: Tue, 8 Dec 2009 15:43:51 +0800 Subject: [PATCH] Implement Matrix Palette extension. Adds support for formerly-unimplemented methods: glCurrentPaletteMatrixOES glLoadPaletteFromModelViewMatrixOES glMatrixIndexPointerOES glWeightPointerOES The bulk of the changes are related to implementing the two PointerOES methods, which are implemented pretty much the same way as the existing Pointer methods were implemented. This change also changes the way glPointSizePointerOES is implemented, making it act like all the other Pointer methods. (Previously it was not handling non-direct-buffer arguments correctly.) Fixes bug 2308625 "Support matrix palette skinning in JSR239 and related APIs" Also updated GLLogWraper to fix two bugs in GLLogWrapper that were discovered while testing matrix palette skinning support: a) Handle trying to print the contents of null-but-enabled buffers. (It's not legal to draw with null-but-enabled buffers, and in fact some OpenGL drivers will crash if you try to render in this state, but there's no reason the GLLogWrapper should crash while trying to debug this situation. b) Don't read off the end of a vertex buffer with non-zero position when printing the entire contents of the vertex buffer. Now we only print from the current position to the end of the buffer. --- opengl/libs/GLES_CM/gl.cpp | 21 +++++++++ opengl/tools/glgen/specs/gles11/checks.spec | 4 -- opengl/tools/glgen/specs/jsr239/glspec-checks | 4 -- opengl/tools/glgen/src/JniCodeEmitter.java | 45 ++++++++++++++++--- .../stubs/gles11/GLES11ExtHeader.java-if | 10 ++++- .../glgen/stubs/gles11/GLES11ExtcHeader.cpp | 21 +++++++++ .../glgen/stubs/gles11/GLES11Header.java-if | 1 + .../glgen/stubs/gles11/GLES11cHeader.cpp | 20 +++++++++ .../glgen/stubs/gles11/GLES20Header.java-if | 1 - opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp | 6 +++ .../glgen/stubs/jsr239/GLImplHeader.java-impl | 3 ++ 11 files changed, 119 insertions(+), 17 deletions(-) diff --git a/opengl/libs/GLES_CM/gl.cpp b/opengl/libs/GLES_CM/gl.cpp index 0c9352ec7..e7757a8fe 100644 --- a/opengl/libs/GLES_CM/gl.cpp +++ b/opengl/libs/GLES_CM/gl.cpp @@ -47,6 +47,12 @@ GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count); GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count); +GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, + GLsizei stride, const GLvoid *pointer, GLsizei count); +GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer, GLsizei count); +GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer, GLsizei count); } void glColorPointerBounds(GLint size, GLenum type, GLsizei stride, @@ -66,6 +72,21 @@ void glVertexPointerBounds(GLint size, GLenum type, glVertexPointer(size, type, stride, pointer); } +void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, + GLsizei stride, const GLvoid *pointer, GLsizei count) { + glPointSizePointerOES(type, stride, pointer); +} + +GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer, GLsizei count) { + glMatrixIndexPointerOES(size, type, stride, pointer); +} + +GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer, GLsizei count) { + glWeightPointerOES(size, type, stride, pointer); +} + // ---------------------------------------------------------------------------- // Actual GL entry-points // ---------------------------------------------------------------------------- diff --git a/opengl/tools/glgen/specs/gles11/checks.spec b/opengl/tools/glgen/specs/gles11/checks.spec index 1468ab979..f91712848 100644 --- a/opengl/tools/glgen/specs/gles11/checks.spec +++ b/opengl/tools/glgen/specs/gles11/checks.spec @@ -37,7 +37,6 @@ glBlendEquation unsupported glBlendEquationSeparate unsupported glBlendFuncSeparate unsupported glCheckFramebufferStatusOES unsupported return 0 -glCurrentPaletteMatrixOES unsupported glDeleteFramebuffersOES unsupported glDeleteRenderbuffersOES unsupported glFramebufferRenderbufferOES unsupported @@ -52,11 +51,8 @@ glGetRenderbufferParameterivOES unsupported glGetTexGen unsupported glIsFramebufferOES unsupported return JNI_FALSE glIsRenderbufferOES unsupported return JNI_FALSE -glLoadPaletteFromModelViewMatrixOES unsupported -glMatrixIndexPointerOES unsupported glRenderbufferStorageOES unsupported return false glTexGen unsupported glTexGenf unsupported glTexGeni unsupported glTexGenx unsupported -glWeightPointerOES unsupported diff --git a/opengl/tools/glgen/specs/jsr239/glspec-checks b/opengl/tools/glgen/specs/jsr239/glspec-checks index 063cdc74a..c28e40300 100644 --- a/opengl/tools/glgen/specs/jsr239/glspec-checks +++ b/opengl/tools/glgen/specs/jsr239/glspec-checks @@ -35,7 +35,6 @@ glBlendEquation unsupported glBlendEquationSeparate unsupported glBlendFuncSeparate unsupported glCheckFramebufferStatusOES unsupported return 0 -glCurrentPaletteMatrixOES unsupported glDeleteFramebuffersOES unsupported glDeleteRenderbuffersOES unsupported glFramebufferRenderbufferOES unsupported @@ -50,11 +49,8 @@ glGetRenderbufferParameterivOES unsupported glGetTexGen unsupported glIsFramebufferOES unsupported return JNI_FALSE glIsRenderbufferOES unsupported return JNI_FALSE -glLoadPaletteFromModelViewMatrixOES unsupported -glMatrixIndexPointerOES unsupported glRenderbufferStorageOES unsupported return false glTexGen unsupported glTexGenf unsupported glTexGeni unsupported glTexGenx unsupported -glWeightPointerOES unsupported diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java index 4c1814a7e..e79170a28 100644 --- a/opengl/tools/glgen/src/JniCodeEmitter.java +++ b/opengl/tools/glgen/src/JniCodeEmitter.java @@ -119,10 +119,15 @@ public class JniCodeEmitter { emitFunction(jfunc, out, false, false); } + boolean isPointerFunc(JFunc jfunc) { + String name = jfunc.getName(); + return (name.endsWith("Pointer") || name.endsWith("PointerOES")) + && jfunc.getCFunc().hasPointerArg(); + } + void emitFunctionCall(JFunc jfunc, PrintStream out, String iii, boolean grabArray) { boolean isVoid = jfunc.getType().isVoid(); - boolean isPointerFunc = jfunc.getName().endsWith("Pointer") && - jfunc.getCFunc().hasPointerArg(); + boolean isPointerFunc = isPointerFunc(jfunc); if (!isVoid) { out.println(iii + @@ -406,9 +411,7 @@ public class JniCodeEmitter { * if !interfaceDecl: public func(args) { body } */ void emitFunction(JFunc jfunc, PrintStream out, boolean nativeDecl, boolean interfaceDecl) { - boolean isPointerFunc = - jfunc.getName().endsWith("Pointer") && - jfunc.getCFunc().hasPointerArg(); + boolean isPointerFunc = isPointerFunc(jfunc); if (!nativeDecl && !interfaceDecl && !isPointerFunc) { // If it's not a pointer function, we've already emitted it @@ -510,6 +513,34 @@ public class JniCodeEmitter { out.println(iii + " (stride >= 0)) {"); out.println(iii + indent + "_vertexPointer = pointer;"); out.println(iii + "}"); + } else if (fname.equals("glPointSizePointerOES")) { + out.println(iii + "if (((type == GL_FLOAT) ||"); + out.println(iii + " (type == GL_FIXED)) &&"); + out.println(iii + " (stride >= 0)) {"); + out.println(iii + indent + "_pointSizePointerOES = pointer;"); + out.println(iii + "}"); + } else if (fname.equals("glMatrixIndexPointerOES")) { + out.println(iii + "if (((size == 2) ||"); + out.println(iii + " (size == 3) ||"); + out.println(iii + " (size == 4)) &&"); + out.println(iii + " ((type == GL_FLOAT) ||"); + out.println(iii + " (type == GL_BYTE) ||"); + out.println(iii + " (type == GL_SHORT) ||"); + out.println(iii + " (type == GL_FIXED)) &&"); + out.println(iii + " (stride >= 0)) {"); + out.println(iii + indent + "_matrixIndexPointerOES = pointer;"); + out.println(iii + "}"); + } else if (fname.equals("glWeightPointer")) { + out.println(iii + "if (((size == 2) ||"); + out.println(iii + " (size == 3) ||"); + out.println(iii + " (size == 4)) &&"); + out.println(iii + " ((type == GL_FLOAT) ||"); + out.println(iii + " (type == GL_BYTE) ||"); + out.println(iii + " (type == GL_SHORT) ||"); + out.println(iii + " (type == GL_FIXED)) &&"); + out.println(iii + " (stride >= 0)) {"); + out.println(iii + indent + "_weightPointerOES = pointer;"); + out.println(iii + "}"); } } @@ -609,9 +640,9 @@ public class JniCodeEmitter { // String outName = "android_" + jfunc.getName(); - boolean isPointerFunc = outName.endsWith("Pointer") && - jfunc.getCFunc().hasPointerArg(); + boolean isPointerFunc = isPointerFunc(jfunc); boolean isVBOPointerFunc = (outName.endsWith("Pointer") || + outName.endsWith("PointerOES") || outName.endsWith("DrawElements")) && !jfunc.getCFunc().hasPointerArg(); if (isPointerFunc) { diff --git a/opengl/tools/glgen/stubs/gles11/GLES11ExtHeader.java-if b/opengl/tools/glgen/stubs/gles11/GLES11ExtHeader.java-if index 428ccee66..c5e34cd1b 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11ExtHeader.java-if +++ b/opengl/tools/glgen/stubs/gles11/GLES11ExtHeader.java-if @@ -18,6 +18,8 @@ package android.opengl; +import java.nio.Buffer; + public class GLES11Ext { public static final int GL_BLEND_EQUATION_RGB_OES = 0x8009; public static final int GL_BLEND_EQUATION_ALPHA_OES = 0x883D; @@ -127,4 +129,10 @@ public class GLES11Ext { static { _nativeClassInit(); } - \ No newline at end of file + + private static final int GL_BYTE = GLES10.GL_BYTE; + private static final int GL_FIXED = GLES10.GL_FIXED; + private static final int GL_FLOAT = GLES10.GL_FLOAT; + private static final int GL_SHORT = GLES10.GL_SHORT; + + private static Buffer _matrixIndexPointerOES; \ No newline at end of file diff --git a/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp index 294d1ce82..2548b32a2 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp @@ -23,6 +23,15 @@ #include #include +/* special calls implemented in Android's GLES wrapper used to more + * efficiently bound-check passed arrays */ +extern "C" { +GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, GLsizei stride, + const GLvoid *ptr, GLsizei count); +GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, GLsizei stride, + const GLvoid *ptr, GLsizei count); +} + static int initialized = 0; static jclass nioAccessClass; @@ -121,5 +130,17 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) commit ? 0 : JNI_ABORT); } +static void * +getDirectBufferPointer(JNIEnv *_env, jobject buffer) { + char* buf = (char*) _env->GetDirectBufferAddress(buffer); + if (buf) { + jint position = _env->GetIntField(buffer, positionID); + jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + buf += position << elementSizeShift; + } else { + _env->ThrowNew(IAEClass, "Must use a native order direct Buffer"); + } + return (void*) buf; +} // -------------------------------------------------------------------------- diff --git a/opengl/tools/glgen/stubs/gles11/GLES11Header.java-if b/opengl/tools/glgen/stubs/gles11/GLES11Header.java-if index 26f466fae..81572d26a 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11Header.java-if +++ b/opengl/tools/glgen/stubs/gles11/GLES11Header.java-if @@ -149,3 +149,4 @@ public class GLES11 extends GLES10 { _nativeClassInit(); } + private static Buffer _pointSizePointerOES; diff --git a/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp index 294d1ce82..4c297f786 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp @@ -23,6 +23,13 @@ #include #include +/* special calls implemented in Android's GLES wrapper used to more + * efficiently bound-check passed arrays */ +extern "C" { +GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, GLsizei stride, + const GLvoid *ptr, GLsizei count); +} + static int initialized = 0; static jclass nioAccessClass; @@ -121,5 +128,18 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) commit ? 0 : JNI_ABORT); } +static void * +getDirectBufferPointer(JNIEnv *_env, jobject buffer) { + char* buf = (char*) _env->GetDirectBufferAddress(buffer); + if (buf) { + jint position = _env->GetIntField(buffer, positionID); + jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + buf += position << elementSizeShift; + } else { + _env->ThrowNew(IAEClass, "Must use a native order direct Buffer"); + } + return (void*) buf; +} + // -------------------------------------------------------------------------- diff --git a/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if b/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if index 7504509fe..b615e0a5f 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if +++ b/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if @@ -19,7 +19,6 @@ package android.opengl; /** OpenGL ES 2.0 - * @hide */ public class GLES20 { public static final int GL_ACTIVE_TEXTURE = 0x84E0; diff --git a/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp index 4494643bf..b3d1c6cb1 100644 --- a/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp +++ b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp @@ -34,6 +34,12 @@ GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count); GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLsizei count); +GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, + GLsizei stride, const GLvoid *pointer, GLsizei count); +GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer, GLsizei count); +GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer, GLsizei count); } static int initialized = 0; diff --git a/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl b/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl index fe60c5d50..76fea3f6a 100644 --- a/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl +++ b/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl @@ -44,6 +44,9 @@ public class GLImpl implements GL10, GL10Ext, GL11, GL11Ext, GL11ExtensionPack { Buffer _normalPointer = null; Buffer _texCoordPointer = null; Buffer _vertexPointer = null; + Buffer _pointSizePointerOES = null; + Buffer _matrixIndexPointerOES = null; + Buffer _weightPointerOES = null; public GLImpl() { }