From bf13ba5e77804ca7466acb7100cdaf7c14cc0fb7 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 22 Feb 2013 19:34:06 -0800 Subject: [PATCH] add some missing parameter validation in GLES java bindings - added support for comments in checks.spec - added most missing checks - added and commented with // special-cased functions - added and commented with # functions that are still missing validation checks - moved glGet* to a special case and updated all the "pnames" from the khronos spec - changed ifcheck to default to 1 value. this allows us to simplify the checks.spec file and handle unknown pnames automatically (they'll be validated against 1 value, if it happens to need more, the call will go through but the validation will not happen). - refactored the cpp headers in to a common header + GLES version specific header Bug: 7402895 Change-Id: Ib5c68ca0ca416407b4cfa36e3a21901b2d6263ab --- opengl/tools/glgen/gen | 4 +- opengl/tools/glgen/specs/gles11/checks.spec | 80 ++++- opengl/tools/glgen/src/GenerateGLES.java | 4 +- opengl/tools/glgen/src/JniCodeEmitter.java | 42 +-- opengl/tools/glgen/src/ParameterChecker.java | 17 +- .../stubs/gles11/GLES10ExtHeader.java-if | 1 + .../glgen/stubs/gles11/GLES10ExtcHeader.cpp | 79 +---- .../glgen/stubs/gles11/GLES10Header.java-if | 1 + .../glgen/stubs/gles11/GLES10cHeader.cpp | 111 +------ .../stubs/gles11/GLES11ExtHeader.java-if | 1 + .../glgen/stubs/gles11/GLES11ExtcHeader.cpp | 100 +----- .../glgen/stubs/gles11/GLES11Header.java-if | 1 + .../glgen/stubs/gles11/GLES11cHeader.cpp | 100 +----- .../glgen/stubs/gles11/GLES20Header.java-if | 1 + .../glgen/stubs/gles11/GLES20cHeader.cpp | 105 +------ opengl/tools/glgen/stubs/gles11/common.cpp | 297 ++++++++++++++++++ .../glgen/stubs/gles11/glGetBooleanv.cpp | 13 + .../glgen/stubs/gles11/glGetBooleanv.java | 15 + .../stubs/gles11/glGetBooleanv.nativeReg | 2 + .../tools/glgen/stubs/gles11/glGetFloatv.cpp | 13 + .../tools/glgen/stubs/gles11/glGetFloatv.java | 15 + .../glgen/stubs/gles11/glGetFloatv.nativeReg | 2 + .../glgen/stubs/gles11/glGetIntegerv.cpp | 14 + .../glgen/stubs/gles11/glGetIntegerv.java | 15 + .../stubs/gles11/glGetIntegerv.nativeReg | 2 + .../stubs/gles11/glGetProgramInfoLog.java | 16 - .../stubs/gles11/glGetShaderInfoLog.java | 16 - .../tools/glgen/stubs/gles11/glGetString.java | 16 - .../glgen/stubs/gles11/glShaderSource.java | 16 - 29 files changed, 506 insertions(+), 593 deletions(-) create mode 100644 opengl/tools/glgen/stubs/gles11/common.cpp create mode 100644 opengl/tools/glgen/stubs/gles11/glGetBooleanv.cpp create mode 100644 opengl/tools/glgen/stubs/gles11/glGetBooleanv.java create mode 100644 opengl/tools/glgen/stubs/gles11/glGetBooleanv.nativeReg create mode 100644 opengl/tools/glgen/stubs/gles11/glGetFloatv.cpp create mode 100644 opengl/tools/glgen/stubs/gles11/glGetFloatv.java create mode 100644 opengl/tools/glgen/stubs/gles11/glGetFloatv.nativeReg create mode 100644 opengl/tools/glgen/stubs/gles11/glGetIntegerv.cpp create mode 100644 opengl/tools/glgen/stubs/gles11/glGetIntegerv.java create mode 100644 opengl/tools/glgen/stubs/gles11/glGetIntegerv.nativeReg diff --git a/opengl/tools/glgen/gen b/opengl/tools/glgen/gen index fb3c3a951..7cb5a2d04 100755 --- a/opengl/tools/glgen/gen +++ b/opengl/tools/glgen/gen @@ -70,7 +70,7 @@ if [ $JAVA_RESULT -ne 0 ]; then exit $JAVA_RESULT fi -echo "Generating static OpenGLES 1.1 bindings" +echo "Generating static OpenGLES bindings" java -classpath src GenerateGLES JAVA_RESULT=$? if [ $JAVA_RESULT -ne 0 ]; then @@ -78,7 +78,7 @@ if [ $JAVA_RESULT -ne 0 ]; then exit $JAVA_RESULT fi -echo "Generating static EGL 1.4 bindings" +echo "Generating static EGL bindings" java -classpath src GenerateEGL JAVA_RESULT=$? if [ $JAVA_RESULT -ne 0 ]; then diff --git a/opengl/tools/glgen/specs/gles11/checks.spec b/opengl/tools/glgen/specs/gles11/checks.spec index 165d0b415..9eb00702d 100644 --- a/opengl/tools/glgen/specs/gles11/checks.spec +++ b/opengl/tools/glgen/specs/gles11/checks.spec @@ -1,9 +1,34 @@ +# Copyright (C) 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# ifcheck defaults to 1 so we don't explicitly list pnames requiring +# a single value. unknown pnames will be validated against one value, which +# is not perfect but better than nothing. +# + glBufferData nullAllowed check data size glBufferSubData check data size +# glCompressedTexImage2D +# glCompressedTexSubImage2D glClipPlanef check eqn 4 glClipPlanex check eqn 4 glDeleteBuffers check buffers n +glDeleteFramebuffers check framebuffers n glDeleteFramebuffersOES check framebuffers n +glDeleteRenderbuffers check renderbuffers n glDeleteRenderbuffersOES check renderbuffers n glDeleteTextures check textures n glDrawElements check_AIOOBE indices count @@ -11,31 +36,64 @@ glDrawTexfvOES check coords 5 glDrawTexivOES check coords 5 glDrawTexsvOES check coords 5 glDrawTexxvOES check coords 5 -glFog ifcheck params 1 pname GL_FOG_MODE,GL_FOG_DENSITY,GL_FOG_START,GL_FOG_END ifcheck params 4 pname GL_FOG_COLOR +glFog ifcheck params 4 pname GL_FOG_COLOR glGenBuffers check buffers n glGenFramebuffersOES check framebuffers n +glGenFramebuffers check framebuffers n glGenRenderbuffersOES check renderbuffers n +glGenRenderbuffers check renderbuffers n glGenTextures check textures n +// glGetActiveAttrib +// glGetActiveUniform +glGetAttachedShaders nullAllowed check count 1 check shaders maxcount +// glGetBooleanv glGetBufferParameter check params 1 -glGetClipPlane check eqn 4 +glGetClipPlanef check eqn 4 +glGetClipPlanex check eqn 4 glGetClipPlanefOES check eqn 4 glGetClipPlanexOES check eqn 4 +// glGetFloatv glGetFramebufferAttachmentParameterivOES check params 1 -glGetIntegerv ifcheck params 1 pname GL_ALPHA_BITS,GL_ALPHA_TEST_FUNC,GL_ALPHA_TEST_REF,GL_BLEND_DST,GL_BLUE_BITS,GL_COLOR_ARRAY_BUFFER_BINDING,GL_COLOR_ARRAY_SIZE,GL_COLOR_ARRAY_STRIDE,GL_COLOR_ARRAY_TYPE,GL_CULL_FACE,GL_DEPTH_BITS,GL_DEPTH_CLEAR_VALUE,GL_DEPTH_FUNC,GL_DEPTH_WRITEMASK,GL_FOG_DENSITY,GL_FOG_END,GL_FOG_MODE,GL_FOG_START,GL_FRONT_FACE,GL_GREEN_BITS,GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES,GL_IMPLEMENTATION_COLOR_READ_TYPE_OES,GL_LIGHT_MODEL_COLOR_CONTROL,GL_LIGHT_MODEL_LOCAL_VIEWER,GL_LIGHT_MODEL_TWO_SIDE,GL_LINE_SMOOTH_HINT,GL_LINE_WIDTH,GL_LOGIC_OP_MODE,GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES,GL_MATRIX_INDEX_ARRAY_SIZE_OES,GL_MATRIX_INDEX_ARRAY_STRIDE_OES,GL_MATRIX_INDEX_ARRAY_TYPE_OES,GL_MATRIX_MODE,GL_MAX_CLIP_PLANES,GL_MAX_ELEMENTS_INDICES,GL_MAX_ELEMENTS_VERTICES,GL_MAX_LIGHTS,GL_MAX_MODELVIEW_STACK_DEPTH,GL_MAX_PALETTE_MATRICES_OES,GL_MAX_PROJECTION_STACK_DEPTH,GL_MAX_TEXTURE_SIZE,GL_MAX_TEXTURE_STACK_DEPTH,GL_MAX_TEXTURE_UNITS,GL_MAX_VERTEX_UNITS_OES,GL_MODELVIEW_STACK_DEPTH,GL_NORMAL_ARRAY_BUFFER_BINDING,GL_NORMAL_ARRAY_STRIDE,GL_NORMAL_ARRAY_TYPE,GL_NUM_COMPRESSED_TEXTURE_FORMATS,GL_PACK_ALIGNMENT,GL_PERSPECTIVE_CORRECTION_HINT,GL_POINT_SIZE,GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES,GL_POINT_SIZE_ARRAY_STRIDE_OES,GL_POINT_SIZE_ARRAY_TYPE_OES,GL_POINT_SMOOTH_HINT,GL_POLYGON_OFFSET_FACTOR,GL_POLYGON_OFFSET_UNITS,GL_PROJECTION_STACK_DEPTH,GL_RED_BITS,GL_SHADE_MODEL,GL_STENCIL_BITS,GL_STENCIL_CLEAR_VALUE,GL_STENCIL_FAIL,GL_STENCIL_FUNC,GL_STENCIL_PASS_DEPTH_FAIL,GL_STENCIL_PASS_DEPTH_PASS,GL_STENCIL_REF,GL_STENCIL_VALUE_MASK,GL_STENCIL_WRITEMASK,GL_SUBPIXEL_BITS,GL_TEXTURE_BINDING_2D,GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING,GL_TEXTURE_COORD_ARRAY_SIZE,GL_TEXTURE_COORD_ARRAY_STRIDE,GL_TEXTURE_COORD_ARRAY_TYPE,GL_TEXTURE_STACK_DEPTH,GL_UNPACK_ALIGNMENT,GL_VERTEX_ARRAY_BUFFER_BINDING,GL_VERTEX_ARRAY_SIZE,GL_VERTEX_ARRAY_STRIDE,GL_VERTEX_ARRAY_TYPE,GL_WEIGHT_ARRAY_BUFFER_BINDING_OES,GL_WEIGHT_ARRAY_SIZE_OES,GL_WEIGHT_ARRAY_STRIDE_OES,GL_WEIGHT_ARRAY_TYPE_OES ifcheck params 2 pname GL_ALIASED_POINT_SIZE_RANGE,GL_ALIASED_LINE_WIDTH_RANGE,GL_DEPTH_RANGE,GL_MAX_VIEWPORT_DIMS,GL_SMOOTH_LINE_WIDTH_RANGE,GL_SMOOTH_POINT_SIZE_RANGE ifcheck params 4 pname GL_COLOR_CLEAR_VALUE,GL_COLOR_WRITEMASK,GL_FOG_COLOR,GL_LIGHT_MODEL_AMBIENT,GL_SCISSOR_BOX,GL_VIEWPORT ifcheck params 16 pname GL_MODELVIEW_MATRIX,GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES,GL_PROJECTION_MATRIX,GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES,GL_TEXTURE_MATRIX,GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES ifcheck params getNumCompressedTextureFormats() pname GL_COMPRESSED_TEXTURE_FORMATS -glGetLight ifcheck params 1 pname GL_SPOT_EXPONENT,GL_SPOT_CUTOFF,GL_CONSTANT_ATTENUATION,GL_LINEAR_ATTENUATION,GL_QUADRATIC_ATTENUATION ifcheck params 3 pname GL_SPOT_DIRECTION ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION -glGetMaterial ifcheck params 1 pname GL_SHININESS ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION,GL_AMBIENT_AND_DIFFUSE +// glGetIntegerv +glGetLight ifcheck params 3 pname GL_SPOT_DIRECTION ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION +glGetMaterial ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION,GL_AMBIENT_AND_DIFFUSE +// glGetProgramInfoLog +glGetProgramiv check params 1 +glGetRenderbufferParameteriv check params 1 glGetRenderbufferParameterivOES check params 1 -glGetTexEnv ifcheck params 1 pname GL_TEXTURE_ENV_MODE,GL_COMBINE_RGB,GL_COMBINE_ALPHA ifcheck params 4 pname GL_TEXTURE_ENV_COLOR -glGetTexGen ifcheck params 1 pname GL_TEXTURE_GEN_MODE ifcheck params 4 pname GL_OBJECT_PLANE,GL_EYE_PLANE +// glGetShaderInfoLog +glGetShaderiv check params 1 +glGetShaderPrecisionFormat check range 1 check precision 1 +// glGetShaderSource +// glGetString +glGetTexEnv ifcheck params 4 pname GL_TEXTURE_ENV_COLOR +glGetTexGen ifcheck params 4 pname GL_OBJECT_PLANE,GL_EYE_PLANE glGetTexParameter check params 1 -glLight ifcheck params 1 pname GL_SPOT_EXPONENT,GL_SPOT_CUTOFF,GL_CONSTANT_ATTENUATION,GL_LINEAR_ATTENUATION,GL_QUADRATIC_ATTENUATION ifcheck params 3 pname GL_SPOT_DIRECTION ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION -glLightModel ifcheck params 1 pname GL_LIGHT_MODEL_TWO_SIDE ifcheck params 4 pname GL_LIGHT_MODEL_AMBIENT +glGetUniform check params 1 +glGetVertexAttrib ifcheck params 4 pname GL_CURRENT_VERTEX_ATTRIB +glLight ifcheck params 3 pname GL_SPOT_DIRECTION ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION +glLightModel ifcheck params 4 pname GL_LIGHT_MODEL_AMBIENT glLoadMatrix check m 16 -glMaterial ifcheck params 1 pname GL_SHININESS ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION,GL_AMBIENT_AND_DIFFUSE +glMaterial ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION,GL_AMBIENT_AND_DIFFUSE glMultMatrix check m 16 glPointParameter check params 1 glQueryMatrixxOES check mantissa 16 check exponent 16 return -1 -glTexEnv ifcheck params 1 pname GL_TEXTURE_ENV_MODE,GL_COMBINE_RGB,GL_COMBINE_ALPHA ifcheck params 4 pname GL_TEXTURE_ENV_COLOR +# glReadPixels +glShaderBinary check binary length +// glShaderSource +glTexEnv ifcheck params 4 pname GL_TEXTURE_ENV_COLOR glTexImage2D nullAllowed glTexParameter check params 1 glTexSubImage2D nullAllowed +glUniform1 check v count +glUniform2 check v count*2 +glUniform3 check v count*3 +glUniform4 check v count*4 +glUniformMatrix2 check value count*4 +glUniformMatrix3 check value count*9 +glUniformMatrix4 check value count*16 +glVertexAttrib1 check values 1 +glVertexAttrib2 check values 2 +glVertexAttrib3 check values 3 +glVertexAttrib4 check values 4 +# glVertexAttribPointer diff --git a/opengl/tools/glgen/src/GenerateGLES.java b/opengl/tools/glgen/src/GenerateGLES.java index 646895757..6f9da5d8d 100644 --- a/opengl/tools/glgen/src/GenerateGLES.java +++ b/opengl/tools/glgen/src/GenerateGLES.java @@ -42,7 +42,6 @@ public class GenerateGLES { } CFunc cfunc = CFunc.parseCFunc(s); - String fname = cfunc.getName(); String stubRoot = "stubs/gles11/" + fname; String javaPath = stubRoot + ".java"; @@ -96,10 +95,9 @@ public class GenerateGLES { new PrintStream(new FileOutputStream("out/" + gl11Filename)); PrintStream gl11cStream = new PrintStream(new FileOutputStream("out/" + gl11cFilename)); - gl11Stream.println("/*"); - gl11cStream.println("/*"); copy("stubs/gles11/" + suffix + "Header.java-if", gl11Stream); copy("stubs/gles11/" + suffix + "cHeader.cpp", gl11cStream); + copy("stubs/gles11/common.cpp", gl11cStream); GLESCodeEmitter emitter = new GLESCodeEmitter( "android/opengl/" + suffix, checker, gl11Stream, gl11cStream); diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java index 774f40c90..01c5c48cc 100644 --- a/opengl/tools/glgen/src/JniCodeEmitter.java +++ b/opengl/tools/glgen/src/JniCodeEmitter.java @@ -197,30 +197,30 @@ public class JniCodeEmitter { void printIfcheckPostamble(PrintStream out, boolean isBuffer, boolean emitExceptionCheck, String iii) { - printIfcheckPostamble(out, isBuffer, emitExceptionCheck, - "offset", "_remaining", iii); - } + printIfcheckPostamble(out, isBuffer, emitExceptionCheck, + "offset", "_remaining", iii); + } void printIfcheckPostamble(PrintStream out, boolean isBuffer, boolean emitExceptionCheck, String offset, String remaining, String iii) { - out.println(iii + " default:"); - out.println(iii + " _needed = 0;"); - out.println(iii + " break;"); - out.println(iii + "}"); + out.println(iii + " default:"); + out.println(iii + " _needed = 1;"); + out.println(iii + " break;"); + out.println(iii + "}"); - out.println(iii + "if (" + remaining + " < _needed) {"); - out.println(iii + indent + "_exception = 1;"); - out.println(iii + indent + - "_exceptionType = \"java/lang/IllegalArgumentException\";"); - out.println(iii + indent + - "_exceptionMessage = \"" + - (isBuffer ? "remaining()" : "length - " + offset) + - " < needed\";"); - out.println(iii + indent + "goto exit;"); - out.println(iii + "}"); + out.println(iii + "if (" + remaining + " < _needed) {"); + out.println(iii + indent + "_exception = 1;"); + out.println(iii + indent + + "_exceptionType = \"java/lang/IllegalArgumentException\";"); + out.println(iii + indent + + "_exceptionMessage = \"" + + (isBuffer ? "remaining()" : "length - " + offset) + + " < needed\";"); + out.println(iii + indent + "goto exit;"); + out.println(iii + "}"); - needsExit = true; - } + needsExit = true; + } boolean isNullAllowed(CFunc cfunc) { String[] checks = mChecker.getChecks(cfunc.getName()); @@ -932,8 +932,8 @@ public class JniCodeEmitter { // Emit an _exeption variable if there will be error checks if (emitExceptionCheck) { out.println(indent + "jint _exception = 0;"); - out.println(indent + "const char * _exceptionType;"); - out.println(indent + "const char * _exceptionMessage;"); + out.println(indent + "const char * _exceptionType = NULL;"); + out.println(indent + "const char * _exceptionMessage = NULL;"); } // Emit a single _array or multiple _XXXArray variables diff --git a/opengl/tools/glgen/src/ParameterChecker.java b/opengl/tools/glgen/src/ParameterChecker.java index bff6d86d5..fbc47fbbc 100644 --- a/opengl/tools/glgen/src/ParameterChecker.java +++ b/opengl/tools/glgen/src/ParameterChecker.java @@ -22,8 +22,21 @@ public class ParameterChecker { HashMap map = new HashMap(); public ParameterChecker(BufferedReader reader) throws Exception { - String s; - while ((s = reader.readLine()) != null) { + String line; + while ((line = reader.readLine()) != null) { + String s = line.trim(); + + // skip empty lines + if (s.isEmpty()) { + continue; + } + + // skip single-line comments + if (s.startsWith("//") || + s.startsWith("#")) { + continue; + } + String[] tokens = s.split("\\s"); map.put(tokens[0], tokens); } diff --git a/opengl/tools/glgen/stubs/gles11/GLES10ExtHeader.java-if b/opengl/tools/glgen/stubs/gles11/GLES10ExtHeader.java-if index 42891eae3..146d8831b 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES10ExtHeader.java-if +++ b/opengl/tools/glgen/stubs/gles11/GLES10ExtHeader.java-if @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** diff --git a/opengl/tools/glgen/stubs/gles11/GLES10ExtcHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES10ExtcHeader.cpp index 172c0e798..8a1d5edb0 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES10ExtcHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES10ExtcHeader.cpp @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** @@ -16,84 +17,6 @@ // This source file is automatically generated -#include "jni.h" -#include "JNIHelp.h" -#include -#include - -#include #include #include -static int initialized = 0; - -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - -/* Cache method IDs each time the class is loaded. */ - -static void -nativeClassInit(JNIEnv *_env, jclass glImplClass) -{ - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); -} - - -static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) -{ - jint position; - jint limit; - jint elementSizeShift; - jlong pointer; - - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); - if (pointer != 0L) { - *array = NULL; - return (void *) (jint) pointer; - } - - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; -} - - -static void -releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) -{ - _env->ReleasePrimitiveArrayCritical(array, data, - commit ? 0 : JNI_ABORT); -} - -// -------------------------------------------------------------------------- diff --git a/opengl/tools/glgen/stubs/gles11/GLES10Header.java-if b/opengl/tools/glgen/stubs/gles11/GLES10Header.java-if index 4b2a83106..16cab04b0 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES10Header.java-if +++ b/opengl/tools/glgen/stubs/gles11/GLES10Header.java-if @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** diff --git a/opengl/tools/glgen/stubs/gles11/GLES10cHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES10cHeader.cpp index 4ef815bce..8a1d5edb0 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES10cHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES10cHeader.cpp @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** @@ -16,116 +17,6 @@ // This source file is automatically generated -#include "jni.h" -#include "JNIHelp.h" -#include -#include - -#include #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 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; - -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - -/* Cache method IDs each time the class is loaded. */ - -static void -nativeClassInit(JNIEnv *_env, jclass glImplClass) -{ - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); -} - -static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) -{ - jint position; - jint limit; - jint elementSizeShift; - jlong pointer; - - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); - if (pointer != 0L) { - *array = NULL; - return (void *) (jint) pointer; - } - - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; -} - -static void -releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) -{ - _env->ReleasePrimitiveArrayCritical(array, data, - 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 { - jniThrowException(_env, "java/lang/IllegalArgumentException", - "Must use a native order direct Buffer"); - } - return (void*) buf; -} - -static int -getNumCompressedTextureFormats() { - int numCompressedTextureFormats = 0; - glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats); - return numCompressedTextureFormats; -} - -// -------------------------------------------------------------------------- diff --git a/opengl/tools/glgen/stubs/gles11/GLES11ExtHeader.java-if b/opengl/tools/glgen/stubs/gles11/GLES11ExtHeader.java-if index 0c5fa04f1..efaf8671a 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11ExtHeader.java-if +++ b/opengl/tools/glgen/stubs/gles11/GLES11ExtHeader.java-if @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** diff --git a/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp index 0df95f4e1..8a1d5edb0 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** @@ -16,105 +17,6 @@ // This source file is automatically generated -#include "jni.h" -#include "JNIHelp.h" -#include -#include - -#include #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; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - -/* Cache method IDs each time the class is loaded. */ - -static void -nativeClassInit(JNIEnv *_env, jclass glImplClass) -{ - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); -} - - -static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) -{ - jint position; - jint limit; - jint elementSizeShift; - jlong pointer; - - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); - if (pointer != 0L) { - *array = NULL; - return (void *) (jint) pointer; - } - - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - return NULL; -} - - -static void -releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) -{ - _env->ReleasePrimitiveArrayCritical(array, data, - 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 { - jniThrowException(_env, "java/lang/IllegalArgumentException", - "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 81572d26a..e63d47019 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11Header.java-if +++ b/opengl/tools/glgen/stubs/gles11/GLES11Header.java-if @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** diff --git a/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp index dd860d5b3..8a1d5edb0 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** @@ -16,105 +17,6 @@ // This source file is automatically generated -#include "jni.h" -#include "JNIHelp.h" -#include -#include - -#include #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; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - -/* Cache method IDs each time the class is loaded. */ - -static void -nativeClassInit(JNIEnv *_env, jclass glImplClass) -{ - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); -} - - -static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) -{ - jint position; - jint limit; - jint elementSizeShift; - jlong pointer; - - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); - if (pointer != 0L) { - *array = NULL; - return (void *) (jint) pointer; - } - - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; -} - - -static void -releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) -{ - _env->ReleasePrimitiveArrayCritical(array, data, - 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 { - jniThrowException(_env, "java/lang/IllegalArgumentException", - "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 b615e0a5f..7a7dccdb5 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if +++ b/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** diff --git a/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp index 996f441cc..2389563f9 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp @@ -1,3 +1,4 @@ +/* ** ** Copyright 2009, The Android Open Source Project ** @@ -16,110 +17,6 @@ // This source file is automatically generated -#include "jni.h" -#include "JNIHelp.h" -#include -#include - -#include #include #include -static int initialized = 0; - -static jclass nioAccessClass; -static jclass bufferClass; -static jmethodID getBasePointerID; -static jmethodID getBaseArrayID; -static jmethodID getBaseArrayOffsetID; -static jfieldID positionID; -static jfieldID limitID; -static jfieldID elementSizeShiftID; - -/* Cache method IDs each time the class is loaded. */ - -static void -nativeClassInit(JNIEnv *_env, jclass glImplClass) -{ - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, - "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, - "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); -} - - -static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) -{ - jint position; - jint limit; - jint elementSizeShift; - jlong pointer; - - position = _env->GetIntField(buffer, positionID); - limit = _env->GetIntField(buffer, limitID); - elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); - *remaining = (limit - position) << elementSizeShift; - pointer = _env->CallStaticLongMethod(nioAccessClass, - getBasePointerID, buffer); - if (pointer != 0L) { - *array = NULL; - return (void *) (jint) pointer; - } - - *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, - getBaseArrayID, buffer); - *offset = _env->CallStaticIntMethod(nioAccessClass, - getBaseArrayOffsetID, buffer); - - return NULL; -} - - -static void -releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) -{ - _env->ReleasePrimitiveArrayCritical(array, data, - 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 { - jniThrowException(_env, "java/lang/IllegalArgumentException", - "Must use a native order direct Buffer"); - } - return (void*) buf; -} - -static int -getNumCompressedTextureFormats() { - int numCompressedTextureFormats = 0; - glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats); - return numCompressedTextureFormats; -} - -static void glVertexAttribPointerBounds(GLuint indx, GLint size, GLenum type, - GLboolean normalized, GLsizei stride, const GLvoid *pointer, GLsizei count) { - glVertexAttribPointer(indx, size, type, normalized, stride, pointer); -} - -// -------------------------------------------------------------------------- diff --git a/opengl/tools/glgen/stubs/gles11/common.cpp b/opengl/tools/glgen/stubs/gles11/common.cpp new file mode 100644 index 000000000..106dbdcc5 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/common.cpp @@ -0,0 +1,297 @@ +#include "jni.h" +#include "JNIHelp.h" +#include +#include +#include + +static int initialized = 0; + +static jclass nioAccessClass; +static jclass bufferClass; +static jmethodID getBasePointerID; +static jmethodID getBaseArrayID; +static jmethodID getBaseArrayOffsetID; +static jfieldID positionID; +static jfieldID limitID; +static jfieldID elementSizeShiftID; + + +/* special calls implemented in Android's GLES wrapper used to more + * efficiently bound-check passed arrays */ +extern "C" { +#ifdef GL_VERSION_ES_CM_1_1 +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); +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); +#endif +#ifdef GL_ES_VERSION_2_0 +static void glVertexAttribPointerBounds(GLuint indx, GLint size, GLenum type, + GLboolean normalized, GLsizei stride, const GLvoid *pointer, GLsizei count) { + glVertexAttribPointer(indx, size, type, normalized, stride, pointer); +} +#endif +} + +/* Cache method IDs each time the class is loaded. */ + +static void +nativeClassInit(JNIEnv *_env, jclass glImplClass) +{ + jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); + nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); + + jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); + bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); + + getBasePointerID = _env->GetStaticMethodID(nioAccessClass, + "getBasePointer", "(Ljava/nio/Buffer;)J"); + getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, + "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); + getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, + "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); + + positionID = _env->GetFieldID(bufferClass, "position", "I"); + limitID = _env->GetFieldID(bufferClass, "limit", "I"); + elementSizeShiftID = + _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); +} + +static void * +getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) +{ + jint position; + jint limit; + jint elementSizeShift; + jlong pointer; + + position = _env->GetIntField(buffer, positionID); + limit = _env->GetIntField(buffer, limitID); + elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID); + *remaining = (limit - position) << elementSizeShift; + pointer = _env->CallStaticLongMethod(nioAccessClass, + getBasePointerID, buffer); + if (pointer != 0L) { + *array = NULL; + return (void *) (jint) pointer; + } + + *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, + getBaseArrayID, buffer); + *offset = _env->CallStaticIntMethod(nioAccessClass, + getBaseArrayOffsetID, buffer); + + return NULL; +} + +static void +releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) +{ + _env->ReleasePrimitiveArrayCritical(array, data, + 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 { + jniThrowException(_env, "java/lang/IllegalArgumentException", + "Must use a native order direct Buffer"); + } + return (void*) buf; +} + +// -------------------------------------------------------------------------- + +/* + * returns the number of values glGet returns for a given pname. + * + * The code below is written such that pnames requiring only one values + * are the default (and are not explicitely tested for). This makes the + * checking code much shorter/readable/efficient. + * + * This means that unknown pnames (e.g.: extensions) will default to 1. If + * that unknown pname needs more than 1 value, then the validation check + * is incomplete and the app may crash if it passed the wrong number params. + */ +static int getNeededCount(GLint pname) { + int needed = 1; +#ifdef GL_ES_VERSION_2_0 + // GLES 2.x pnames + switch (pname) { + case GL_ALIASED_LINE_WIDTH_RANGE: + case GL_ALIASED_POINT_SIZE_RANGE: + needed = 2; + break; + + case GL_BLEND_COLOR: + case GL_COLOR_CLEAR_VALUE: + case GL_COLOR_WRITEMASK: + case GL_SCISSOR_BOX: + case GL_VIEWPORT: + needed = 4; + break; + + case GL_COMPRESSED_TEXTURE_FORMATS: + glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed); + break; + + case GL_SHADER_BINARY_FORMATS: + glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &needed); + break; + } +#endif + +#ifdef GL_VERSION_ES_CM_1_1 + // GLES 1.x pnames + switch (pname) { + case GL_ALIASED_LINE_WIDTH_RANGE: + case GL_ALIASED_POINT_SIZE_RANGE: + case GL_DEPTH_RANGE: + case GL_SMOOTH_LINE_WIDTH_RANGE: + case GL_SMOOTH_POINT_SIZE_RANGE: + needed = 2; + break; + + case GL_CURRENT_NORMAL: + case GL_POINT_DISTANCE_ATTENUATION: + needed = 3; + break; + + case GL_COLOR_CLEAR_VALUE: + case GL_COLOR_WRITEMASK: + case GL_CURRENT_COLOR: + case GL_CURRENT_TEXTURE_COORDS: + case GL_FOG_COLOR: + case GL_LIGHT_MODEL_AMBIENT: + case GL_SCISSOR_BOX: + case GL_VIEWPORT: + needed = 4; + break; + + case GL_MODELVIEW_MATRIX: + case GL_PROJECTION_MATRIX: + case GL_TEXTURE_MATRIX: + needed = 16; + break; + + case GL_COMPRESSED_TEXTURE_FORMATS: + glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed); + break; + } +#endif + return needed; +} + +template +static void +get + (JNIEnv *_env, jobject _this, jint pname, JTYPEARRAY params_ref, jint offset) { + jint _exception = 0; + const char * _exceptionType; + const char * _exceptionMessage; + CTYPE *params_base = (CTYPE *) 0; + jint _remaining; + CTYPE *params = (CTYPE *) 0; + int _needed = 0; + + if (!params_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "params == null"; + goto exit; + } + if (offset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "offset < 0"; + goto exit; + } + _remaining = _env->GetArrayLength(params_ref) - offset; + _needed = getNeededCount(pname); + // if we didn't find this pname, we just assume the user passed + // an array of the right size -- this might happen with extensions + // or if we forget an enum here. + if (_remaining < _needed) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "length - offset < needed"; + goto exit; + } + params_base = (CTYPE *) + _env->GetPrimitiveArrayCritical(params_ref, (jboolean *)0); + params = params_base + offset; + + GET( + (GLenum)pname, + (CTYPE *)params + ); + +exit: + if (params_base) { + _env->ReleasePrimitiveArrayCritical(params_ref, params_base, + _exception ? JNI_ABORT: 0); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } +} + + +template +static void +getarray + (JNIEnv *_env, jobject _this, jint pname, jobject params_buf) { + jint _exception = 0; + const char * _exceptionType; + const char * _exceptionMessage; + jarray _array = (jarray) 0; + jint _bufferOffset = (jint) 0; + jint _remaining; + CTYPE *params = (CTYPE *) 0; + int _needed = 0; + + params = (CTYPE *)getPointer(_env, params_buf, &_array, &_remaining, &_bufferOffset); + _needed = getNeededCount(pname); + // if we didn't find this pname, we just assume the user passed + // an array of the right size -- this might happen with extensions + // or if we forget an enum here. + if (_needed>0 && _remaining < _needed) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "remaining() < needed"; + goto exit; + } + if (params == NULL) { + char * _paramsBase = (char *)_env->GetPrimitiveArrayCritical(_array, (jboolean *) 0); + params = (CTYPE *) (_paramsBase + _bufferOffset); + } + GET( + (GLenum)pname, + (CTYPE *)params + ); + +exit: + if (_array) { + releasePointer(_env, _array, params, _exception ? JNI_FALSE : JNI_TRUE); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } +} + +// -------------------------------------------------------------------------- diff --git a/opengl/tools/glgen/stubs/gles11/glGetBooleanv.cpp b/opengl/tools/glgen/stubs/gles11/glGetBooleanv.cpp new file mode 100644 index 000000000..00c52af15 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetBooleanv.cpp @@ -0,0 +1,13 @@ +/* void glGetBooleanv ( GLenum pname, GLboolean *params ) */ +static void +android_glGetBooleanv__I_3ZI + (JNIEnv *_env, jobject _this, jint pname, jbooleanArray params_ref, jint offset) { + get(_env, _this, pname, params_ref, offset); +} + +/* void glGetBooleanv ( GLenum pname, GLboolean *params ) */ +static void +android_glGetBooleanv__ILjava_nio_IntBuffer_2 + (JNIEnv *_env, jobject _this, jint pname, jobject params_buf) { + getarray(_env, _this, pname, params_buf); +} diff --git a/opengl/tools/glgen/stubs/gles11/glGetBooleanv.java b/opengl/tools/glgen/stubs/gles11/glGetBooleanv.java new file mode 100644 index 000000000..3ec9b2429 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetBooleanv.java @@ -0,0 +1,15 @@ + // C function void glGetBooleanv ( GLenum pname, GLboolean *params ) + + public static native void glGetBooleanv( + int pname, + boolean[] params, + int offset + ); + + // C function void glGetBooleanv ( GLenum pname, GLboolean *params ) + + public static native void glGetBooleanv( + int pname, + java.nio.IntBuffer params + ); + diff --git a/opengl/tools/glgen/stubs/gles11/glGetBooleanv.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetBooleanv.nativeReg new file mode 100644 index 000000000..d0bc8b855 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetBooleanv.nativeReg @@ -0,0 +1,2 @@ +{"glGetBooleanv", "(I[ZI)V", (void *) android_glGetBooleanv__I_3ZI }, +{"glGetBooleanv", "(ILjava/nio/IntBuffer;)V", (void *) android_glGetBooleanv__ILjava_nio_IntBuffer_2 }, diff --git a/opengl/tools/glgen/stubs/gles11/glGetFloatv.cpp b/opengl/tools/glgen/stubs/gles11/glGetFloatv.cpp new file mode 100644 index 000000000..71c399de2 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetFloatv.cpp @@ -0,0 +1,13 @@ +/* void glGetFloatv ( GLenum pname, GLfloat *params ) */ +static void +android_glGetFloatv__I_3FI + (JNIEnv *_env, jobject _this, jint pname, jfloatArray params_ref, jint offset) { + get(_env, _this, pname, params_ref, offset); +} + +/* void glGetFloatv ( GLenum pname, GLfloat *params ) */ +static void +android_glGetFloatv__ILjava_nio_FloatBuffer_2 + (JNIEnv *_env, jobject _this, jint pname, jobject params_buf) { + getarray(_env, _this, pname, params_buf); +} diff --git a/opengl/tools/glgen/stubs/gles11/glGetFloatv.java b/opengl/tools/glgen/stubs/gles11/glGetFloatv.java new file mode 100644 index 000000000..53b5c0143 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetFloatv.java @@ -0,0 +1,15 @@ + // C function void glGetFloatv ( GLenum pname, GLfloat *params ) + + public static native void glGetFloatv( + int pname, + float[] params, + int offset + ); + + // C function void glGetFloatv ( GLenum pname, GLfloat *params ) + + public static native void glGetFloatv( + int pname, + java.nio.FloatBuffer params + ); + diff --git a/opengl/tools/glgen/stubs/gles11/glGetFloatv.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetFloatv.nativeReg new file mode 100644 index 000000000..93058c621 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetFloatv.nativeReg @@ -0,0 +1,2 @@ +{"glGetFloatv", "(I[FI)V", (void *) android_glGetFloatv__I_3FI }, +{"glGetFloatv", "(ILjava/nio/FloatBuffer;)V", (void *) android_glGetFloatv__ILjava_nio_FloatBuffer_2 }, diff --git a/opengl/tools/glgen/stubs/gles11/glGetIntegerv.cpp b/opengl/tools/glgen/stubs/gles11/glGetIntegerv.cpp new file mode 100644 index 000000000..9000ece83 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetIntegerv.cpp @@ -0,0 +1,14 @@ +/* void glGetIntegerv ( GLenum pname, GLint *params ) */ +static void +android_glGetIntegerv__I_3II + (JNIEnv *_env, jobject _this, jint pname, jintArray params_ref, jint offset) { + get(_env, _this, pname, params_ref, offset); +} + +/* void glGetIntegerv ( GLenum pname, GLint *params ) */ +static void +android_glGetIntegerv__ILjava_nio_IntBuffer_2 + (JNIEnv *_env, jobject _this, jint pname, jobject params_buf) { + getarray(_env, _this, pname, params_buf); +} + diff --git a/opengl/tools/glgen/stubs/gles11/glGetIntegerv.java b/opengl/tools/glgen/stubs/gles11/glGetIntegerv.java new file mode 100644 index 000000000..e8b42c900 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetIntegerv.java @@ -0,0 +1,15 @@ + // C function void glGetIntegerv ( GLenum pname, GLint *params ) + + public static native void glGetIntegerv( + int pname, + int[] params, + int offset + ); + + // C function void glGetIntegerv ( GLenum pname, GLint *params ) + + public static native void glGetIntegerv( + int pname, + java.nio.IntBuffer params + ); + diff --git a/opengl/tools/glgen/stubs/gles11/glGetIntegerv.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetIntegerv.nativeReg new file mode 100644 index 000000000..c39cd927b --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetIntegerv.nativeReg @@ -0,0 +1,2 @@ +{"glGetIntegerv", "(I[II)V", (void *) android_glGetIntegerv__I_3II }, +{"glGetIntegerv", "(ILjava/nio/IntBuffer;)V", (void *) android_glGetIntegerv__ILjava_nio_IntBuffer_2 }, diff --git a/opengl/tools/glgen/stubs/gles11/glGetProgramInfoLog.java b/opengl/tools/glgen/stubs/gles11/glGetProgramInfoLog.java index 762df39d3..19504f258 100644 --- a/opengl/tools/glgen/stubs/gles11/glGetProgramInfoLog.java +++ b/opengl/tools/glgen/stubs/gles11/glGetProgramInfoLog.java @@ -1,19 +1,3 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - // C function void glGetProgramInfoLog( GLuint program, GLsizei maxLength, GLsizei * length, // GLchar * infoLog); diff --git a/opengl/tools/glgen/stubs/gles11/glGetShaderInfoLog.java b/opengl/tools/glgen/stubs/gles11/glGetShaderInfoLog.java index af529c08c..1fac6beae 100644 --- a/opengl/tools/glgen/stubs/gles11/glGetShaderInfoLog.java +++ b/opengl/tools/glgen/stubs/gles11/glGetShaderInfoLog.java @@ -1,19 +1,3 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - // C function void glGetShaderInfoLog( GLuint shader, GLsizei maxLength, GLsizei * length, // GLchar * infoLog); diff --git a/opengl/tools/glgen/stubs/gles11/glGetString.java b/opengl/tools/glgen/stubs/gles11/glGetString.java index b02a0d197..3d4fe5b34 100644 --- a/opengl/tools/glgen/stubs/gles11/glGetString.java +++ b/opengl/tools/glgen/stubs/gles11/glGetString.java @@ -1,19 +1,3 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - // C function const GLubyte * glGetString ( GLenum name ) public static native String glGetString( diff --git a/opengl/tools/glgen/stubs/gles11/glShaderSource.java b/opengl/tools/glgen/stubs/gles11/glShaderSource.java index e9fcef383..a9c338ac2 100644 --- a/opengl/tools/glgen/stubs/gles11/glShaderSource.java +++ b/opengl/tools/glgen/stubs/gles11/glShaderSource.java @@ -1,19 +1,3 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - // C function void glShaderSource ( GLuint shader, GLsizei count, const GLchar ** string, const GLint* length ) public static native void glShaderSource(