diff options
Diffstat (limited to 'core/jni/com_google_android_gles_jni_GLImpl.cpp')
-rw-r--r-- | core/jni/com_google_android_gles_jni_GLImpl.cpp | 113 |
1 files changed, 76 insertions, 37 deletions
diff --git a/core/jni/com_google_android_gles_jni_GLImpl.cpp b/core/jni/com_google_android_gles_jni_GLImpl.cpp index 9b09c9b..11822e0 100644 --- a/core/jni/com_google_android_gles_jni_GLImpl.cpp +++ b/core/jni/com_google_android_gles_jni_GLImpl.cpp @@ -22,11 +22,20 @@ #include <assert.h> #include <GLES/gl.h> +#include <GLES/glext.h> -#include <private/opengles/gl_context.h> - -#define _NUM_COMPRESSED_TEXTURE_FORMATS \ - (::android::OGLES_NUM_COMPRESSED_TEXTURE_FORMATS) +/* special calls implemented in Android's GLES wrapper used to more + * efficiently bound-check passed arrays */ +extern "C" { +GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride, + const GLvoid *ptr, GLsizei count); +GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride, + const GLvoid *pointer, GLsizei count); +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); +} static int initialized = 0; @@ -45,7 +54,7 @@ static jfieldID elementSizeShiftID; /* Cache method IDs each time the class is loaded. */ -void +static void nativeClassInitBuffer(JNIEnv *_env) { jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); @@ -67,7 +76,6 @@ nativeClassInitBuffer(JNIEnv *_env) _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); } - static void nativeClassInit(JNIEnv *_env, jclass glImplClass) { @@ -118,7 +126,6 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) return (void *) ((char *) data + offset); } - static void releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) { @@ -126,6 +133,13 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) commit ? 0 : JNI_ABORT); } +static int +getNumCompressedTextureFormats() { + int numCompressedTextureFormats = 0; + glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats); + return numCompressedTextureFormats; +} + // -------------------------------------------------------------------------- /* void glActiveTexture ( GLenum texture ) */ @@ -290,7 +304,13 @@ android_glColorPointerBounds__IIILjava_nio_Buffer_2I jint _remaining; GLvoid *pointer = (GLvoid *) 0; - pointer = (GLvoid *)getPointer(_env, pointer_buf, &_array, &_remaining); + if (pointer_buf) { + pointer = (GLvoid *) _env->GetDirectBufferAddress(pointer_buf); + if ( ! pointer ) { + _env->ThrowNew(IAEClass, "Must use a native order direct Buffer"); + return; + } + } glColorPointerBounds( (GLint)size, (GLenum)type, @@ -298,9 +318,6 @@ android_glColorPointerBounds__IIILjava_nio_Buffer_2I (GLvoid *)pointer, (GLsizei)remaining ); - if (_array) { - releasePointer(_env, _array, pointer, JNI_FALSE); - } } /* void glCompressedTexImage2D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data ) */ @@ -1022,6 +1039,12 @@ android_glGetIntegerv__I_3II #if defined(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES) case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES: #endif // defined(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES) +#if defined(GL_LIGHT_MODEL_COLOR_CONTROL) + case GL_LIGHT_MODEL_COLOR_CONTROL: +#endif // defined(GL_LIGHT_MODEL_COLOR_CONTROL) +#if defined(GL_LIGHT_MODEL_LOCAL_VIEWER) + case GL_LIGHT_MODEL_LOCAL_VIEWER: +#endif // defined(GL_LIGHT_MODEL_LOCAL_VIEWER) #if defined(GL_LIGHT_MODEL_TWO_SIDE) case GL_LIGHT_MODEL_TWO_SIDE: #endif // defined(GL_LIGHT_MODEL_TWO_SIDE) @@ -1236,6 +1259,12 @@ android_glGetIntegerv__I_3II #if defined(GL_COLOR_WRITEMASK) case GL_COLOR_WRITEMASK: #endif // defined(GL_COLOR_WRITEMASK) +#if defined(GL_FOG_COLOR) + case GL_FOG_COLOR: +#endif // defined(GL_FOG_COLOR) +#if defined(GL_LIGHT_MODEL_AMBIENT) + case GL_LIGHT_MODEL_AMBIENT: +#endif // defined(GL_LIGHT_MODEL_AMBIENT) #if defined(GL_SCISSOR_BOX) case GL_SCISSOR_BOX: #endif // defined(GL_SCISSOR_BOX) @@ -1267,13 +1296,7 @@ android_glGetIntegerv__I_3II #if defined(GL_COMPRESSED_TEXTURE_FORMATS) case GL_COMPRESSED_TEXTURE_FORMATS: #endif // defined(GL_COMPRESSED_TEXTURE_FORMATS) -#if defined(GL_FOG_COLOR) - case GL_FOG_COLOR: -#endif // defined(GL_FOG_COLOR) -#if defined(GL_LIGHT_MODEL_AMBIENT) - case GL_LIGHT_MODEL_AMBIENT: -#endif // defined(GL_LIGHT_MODEL_AMBIENT) - _needed = _NUM_COMPRESSED_TEXTURE_FORMATS; + _needed = getNumCompressedTextureFormats(); break; default: _needed = 0; @@ -1378,6 +1401,12 @@ android_glGetIntegerv__ILjava_nio_IntBuffer_2 #if defined(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES) case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES: #endif // defined(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES) +#if defined(GL_LIGHT_MODEL_COLOR_CONTROL) + case GL_LIGHT_MODEL_COLOR_CONTROL: +#endif // defined(GL_LIGHT_MODEL_COLOR_CONTROL) +#if defined(GL_LIGHT_MODEL_LOCAL_VIEWER) + case GL_LIGHT_MODEL_LOCAL_VIEWER: +#endif // defined(GL_LIGHT_MODEL_LOCAL_VIEWER) #if defined(GL_LIGHT_MODEL_TWO_SIDE) case GL_LIGHT_MODEL_TWO_SIDE: #endif // defined(GL_LIGHT_MODEL_TWO_SIDE) @@ -1592,6 +1621,12 @@ android_glGetIntegerv__ILjava_nio_IntBuffer_2 #if defined(GL_COLOR_WRITEMASK) case GL_COLOR_WRITEMASK: #endif // defined(GL_COLOR_WRITEMASK) +#if defined(GL_FOG_COLOR) + case GL_FOG_COLOR: +#endif // defined(GL_FOG_COLOR) +#if defined(GL_LIGHT_MODEL_AMBIENT) + case GL_LIGHT_MODEL_AMBIENT: +#endif // defined(GL_LIGHT_MODEL_AMBIENT) #if defined(GL_SCISSOR_BOX) case GL_SCISSOR_BOX: #endif // defined(GL_SCISSOR_BOX) @@ -1623,13 +1658,7 @@ android_glGetIntegerv__ILjava_nio_IntBuffer_2 #if defined(GL_COMPRESSED_TEXTURE_FORMATS) case GL_COMPRESSED_TEXTURE_FORMATS: #endif // defined(GL_COMPRESSED_TEXTURE_FORMATS) -#if defined(GL_FOG_COLOR) - case GL_FOG_COLOR: -#endif // defined(GL_FOG_COLOR) -#if defined(GL_LIGHT_MODEL_AMBIENT) - case GL_LIGHT_MODEL_AMBIENT: -#endif // defined(GL_LIGHT_MODEL_AMBIENT) - _needed = _NUM_COMPRESSED_TEXTURE_FORMATS; + _needed = getNumCompressedTextureFormats(); break; default: _needed = 0; @@ -1654,6 +1683,7 @@ exit: #include <string.h> /* const GLubyte * glGetString ( GLenum name ) */ +static jstring android_glGetString (JNIEnv *_env, jobject _this, jint name) { @@ -2748,16 +2778,19 @@ android_glNormalPointerBounds__IILjava_nio_Buffer_2I jint _remaining; GLvoid *pointer = (GLvoid *) 0; - pointer = (GLvoid *)getPointer(_env, pointer_buf, &_array, &_remaining); + if (pointer_buf) { + pointer = (GLvoid *) _env->GetDirectBufferAddress(pointer_buf); + if ( ! pointer ) { + _env->ThrowNew(IAEClass, "Must use a native order direct Buffer"); + return; + } + } glNormalPointerBounds( (GLenum)type, (GLsizei)stride, (GLvoid *)pointer, (GLsizei)remaining ); - if (_array) { - releasePointer(_env, _array, pointer, JNI_FALSE); - } } /* void glOrthof ( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ) */ @@ -3000,7 +3033,13 @@ android_glTexCoordPointerBounds__IIILjava_nio_Buffer_2I jint _remaining; GLvoid *pointer = (GLvoid *) 0; - pointer = (GLvoid *)getPointer(_env, pointer_buf, &_array, &_remaining); + if (pointer_buf) { + pointer = (GLvoid *) _env->GetDirectBufferAddress(pointer_buf); + if ( ! pointer ) { + _env->ThrowNew(IAEClass, "Must use a native order direct Buffer"); + return; + } + } glTexCoordPointerBounds( (GLint)size, (GLenum)type, @@ -3008,9 +3047,6 @@ android_glTexCoordPointerBounds__IIILjava_nio_Buffer_2I (GLvoid *)pointer, (GLsizei)remaining ); - if (_array) { - releasePointer(_env, _array, pointer, JNI_FALSE); - } } /* void glTexEnvf ( GLenum target, GLenum pname, GLfloat param ) */ @@ -3355,7 +3391,13 @@ android_glVertexPointerBounds__IIILjava_nio_Buffer_2I jint _remaining; GLvoid *pointer = (GLvoid *) 0; - pointer = (GLvoid *)getPointer(_env, pointer_buf, &_array, &_remaining); + if (pointer_buf) { + pointer = (GLvoid *) _env->GetDirectBufferAddress(pointer_buf); + if ( ! pointer ) { + _env->ThrowNew(IAEClass, "Must use a native order direct Buffer"); + return; + } + } glVertexPointerBounds( (GLint)size, (GLenum)type, @@ -3363,9 +3405,6 @@ android_glVertexPointerBounds__IIILjava_nio_Buffer_2I (GLvoid *)pointer, (GLsizei)remaining ); - if (_array) { - releasePointer(_env, _array, pointer, JNI_FALSE); - } } /* void glViewport ( GLint x, GLint y, GLsizei width, GLsizei height ) */ |