3 ** Copyright 2009, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
18 // This source file is automatically generated
21 #include <GLES/glext.h>
25 #include <android_runtime/AndroidRuntime.h>
26 #include <utils/misc.h>
29 static int initialized = 0;
31 static jclass nioAccessClass;
32 static jclass bufferClass;
33 static jmethodID getBasePointerID;
34 static jmethodID getBaseArrayID;
35 static jmethodID getBaseArrayOffsetID;
36 static jfieldID positionID;
37 static jfieldID limitID;
38 static jfieldID elementSizeShiftID;
41 /* special calls implemented in Android's GLES wrapper used to more
42 * efficiently bound-check passed arrays */
44 #ifdef GL_VERSION_ES_CM_1_1
45 GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
46 const GLvoid *ptr, GLsizei count);
47 GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride,
48 const GLvoid *pointer, GLsizei count);
49 GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type,
50 GLsizei stride, const GLvoid *pointer, GLsizei count);
51 GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type,
52 GLsizei stride, const GLvoid *pointer, GLsizei count);
53 GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type,
54 GLsizei stride, const GLvoid *pointer, GLsizei count);
55 GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type,
56 GLsizei stride, const GLvoid *pointer, GLsizei count);
57 GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
58 GLsizei stride, const GLvoid *pointer, GLsizei count);
60 #ifdef GL_ES_VERSION_2_0
61 static void glVertexAttribPointerBounds(GLuint indx, GLint size, GLenum type,
62 GLboolean normalized, GLsizei stride, const GLvoid *pointer, GLsizei count) {
63 glVertexAttribPointer(indx, size, type, normalized, stride, pointer);
66 #ifdef GL_ES_VERSION_3_0
67 static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type,
68 GLsizei stride, const GLvoid *pointer, GLsizei count) {
69 glVertexAttribIPointer(indx, size, type, stride, pointer);
74 /* Cache method IDs each time the class is loaded. */
77 nativeClassInit(JNIEnv *_env, jclass glImplClass)
79 jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess");
80 nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal);
82 jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
83 bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
85 getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
86 "getBasePointer", "(Ljava/nio/Buffer;)J");
87 getBaseArrayID = _env->GetStaticMethodID(nioAccessClass,
88 "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
89 getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass,
90 "getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
92 positionID = _env->GetFieldID(bufferClass, "position", "I");
93 limitID = _env->GetFieldID(bufferClass, "limit", "I");
95 _env->GetFieldID(bufferClass, "_elementSizeShift", "I");
99 getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset)
103 jint elementSizeShift;
106 position = _env->GetIntField(buffer, positionID);
107 limit = _env->GetIntField(buffer, limitID);
108 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
109 *remaining = (limit - position) << elementSizeShift;
110 pointer = _env->CallStaticLongMethod(nioAccessClass,
111 getBasePointerID, buffer);
114 return (void *) (jint) pointer;
117 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
118 getBaseArrayID, buffer);
119 *offset = _env->CallStaticIntMethod(nioAccessClass,
120 getBaseArrayOffsetID, buffer);
126 releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
128 _env->ReleasePrimitiveArrayCritical(array, data,
129 commit ? 0 : JNI_ABORT);
133 getDirectBufferPointer(JNIEnv *_env, jobject buffer) {
134 char* buf = (char*) _env->GetDirectBufferAddress(buffer);
136 jint position = _env->GetIntField(buffer, positionID);
137 jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
138 buf += position << elementSizeShift;
140 jniThrowException(_env, "java/lang/IllegalArgumentException",
141 "Must use a native order direct Buffer");
146 // --------------------------------------------------------------------------
149 * returns the number of values glGet returns for a given pname.
151 * The code below is written such that pnames requiring only one values
152 * are the default (and are not explicitely tested for). This makes the
153 * checking code much shorter/readable/efficient.
155 * This means that unknown pnames (e.g.: extensions) will default to 1. If
156 * that unknown pname needs more than 1 value, then the validation check
157 * is incomplete and the app may crash if it passed the wrong number params.
159 static int getNeededCount(GLint pname) {
161 #ifdef GL_ES_VERSION_2_0
164 case GL_ALIASED_LINE_WIDTH_RANGE:
165 case GL_ALIASED_POINT_SIZE_RANGE:
170 case GL_COLOR_CLEAR_VALUE:
171 case GL_COLOR_WRITEMASK:
177 case GL_COMPRESSED_TEXTURE_FORMATS:
178 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed);
181 case GL_SHADER_BINARY_FORMATS:
182 glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &needed);
187 #ifdef GL_VERSION_ES_CM_1_1
190 case GL_ALIASED_LINE_WIDTH_RANGE:
191 case GL_ALIASED_POINT_SIZE_RANGE:
193 case GL_SMOOTH_LINE_WIDTH_RANGE:
194 case GL_SMOOTH_POINT_SIZE_RANGE:
198 case GL_CURRENT_NORMAL:
199 case GL_POINT_DISTANCE_ATTENUATION:
203 case GL_COLOR_CLEAR_VALUE:
204 case GL_COLOR_WRITEMASK:
205 case GL_CURRENT_COLOR:
206 case GL_CURRENT_TEXTURE_COORDS:
208 case GL_LIGHT_MODEL_AMBIENT:
214 case GL_MODELVIEW_MATRIX:
215 case GL_PROJECTION_MATRIX:
216 case GL_TEXTURE_MATRIX:
220 case GL_COMPRESSED_TEXTURE_FORMATS:
221 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed);
228 template <typename JTYPEARRAY, typename CTYPE, void GET(GLenum, CTYPE*)>
231 (JNIEnv *_env, jobject _this, jint pname, JTYPEARRAY params_ref, jint offset) {
233 const char * _exceptionType;
234 const char * _exceptionMessage;
235 CTYPE *params_base = (CTYPE *) 0;
237 CTYPE *params = (CTYPE *) 0;
242 _exceptionType = "java/lang/IllegalArgumentException";
243 _exceptionMessage = "params == null";
248 _exceptionType = "java/lang/IllegalArgumentException";
249 _exceptionMessage = "offset < 0";
252 _remaining = _env->GetArrayLength(params_ref) - offset;
253 _needed = getNeededCount(pname);
254 // if we didn't find this pname, we just assume the user passed
255 // an array of the right size -- this might happen with extensions
256 // or if we forget an enum here.
257 if (_remaining < _needed) {
259 _exceptionType = "java/lang/IllegalArgumentException";
260 _exceptionMessage = "length - offset < needed";
263 params_base = (CTYPE *)
264 _env->GetPrimitiveArrayCritical(params_ref, (jboolean *)0);
265 params = params_base + offset;
274 _env->ReleasePrimitiveArrayCritical(params_ref, params_base,
275 _exception ? JNI_ABORT: 0);
278 jniThrowException(_env, _exceptionType, _exceptionMessage);
283 template <typename CTYPE, void GET(GLenum, CTYPE*)>
286 (JNIEnv *_env, jobject _this, jint pname, jobject params_buf) {
288 const char * _exceptionType;
289 const char * _exceptionMessage;
290 jarray _array = (jarray) 0;
291 jint _bufferOffset = (jint) 0;
293 CTYPE *params = (CTYPE *) 0;
296 params = (CTYPE *)getPointer(_env, params_buf, &_array, &_remaining, &_bufferOffset);
297 _remaining /= sizeof(CTYPE); // convert from bytes to item count
298 _needed = getNeededCount(pname);
299 // if we didn't find this pname, we just assume the user passed
300 // an array of the right size -- this might happen with extensions
301 // or if we forget an enum here.
302 if (_needed>0 && _remaining < _needed) {
304 _exceptionType = "java/lang/IllegalArgumentException";
305 _exceptionMessage = "remaining() < needed";
308 if (params == NULL) {
309 char * _paramsBase = (char *)_env->GetPrimitiveArrayCritical(_array, (jboolean *) 0);
310 params = (CTYPE *) (_paramsBase + _bufferOffset);
319 releasePointer(_env, _array, params, _exception ? JNI_FALSE : JNI_TRUE);
322 jniThrowException(_env, _exceptionType, _exceptionMessage);
326 // --------------------------------------------------------------------------
327 /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
329 android_glQueryMatrixxOES___3II_3II
330 (JNIEnv *_env, jobject _this, jintArray mantissa_ref, jint mantissaOffset, jintArray exponent_ref, jint exponentOffset) {
332 const char * _exceptionType = NULL;
333 const char * _exceptionMessage = NULL;
334 GLbitfield _returnValue = -1;
335 GLfixed *mantissa_base = (GLfixed *) 0;
336 jint _mantissaRemaining;
337 GLfixed *mantissa = (GLfixed *) 0;
338 GLint *exponent_base = (GLint *) 0;
339 jint _exponentRemaining;
340 GLint *exponent = (GLint *) 0;
344 _exceptionType = "java/lang/IllegalArgumentException";
345 _exceptionMessage = "mantissa == null";
348 if (mantissaOffset < 0) {
350 _exceptionType = "java/lang/IllegalArgumentException";
351 _exceptionMessage = "mantissaOffset < 0";
354 _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset;
355 if (_mantissaRemaining < 16) {
357 _exceptionType = "java/lang/IllegalArgumentException";
358 _exceptionMessage = "length - mantissaOffset < 16 < needed";
361 mantissa_base = (GLfixed *)
362 _env->GetPrimitiveArrayCritical(mantissa_ref, (jboolean *)0);
363 mantissa = mantissa_base + mantissaOffset;
367 _exceptionType = "java/lang/IllegalArgumentException";
368 _exceptionMessage = "exponent == null";
371 if (exponentOffset < 0) {
373 _exceptionType = "java/lang/IllegalArgumentException";
374 _exceptionMessage = "exponentOffset < 0";
377 _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset;
378 if (_exponentRemaining < 16) {
380 _exceptionType = "java/lang/IllegalArgumentException";
381 _exceptionMessage = "length - exponentOffset < 16 < needed";
384 exponent_base = (GLint *)
385 _env->GetPrimitiveArrayCritical(exponent_ref, (jboolean *)0);
386 exponent = exponent_base + exponentOffset;
388 _returnValue = glQueryMatrixxOES(
395 _env->ReleasePrimitiveArrayCritical(exponent_ref, exponent_base,
396 _exception ? JNI_ABORT: 0);
399 _env->ReleasePrimitiveArrayCritical(mantissa_ref, mantissa_base,
400 _exception ? JNI_ABORT: 0);
403 jniThrowException(_env, _exceptionType, _exceptionMessage);
405 return (jint)_returnValue;
408 /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
410 android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2
411 (JNIEnv *_env, jobject _this, jobject mantissa_buf, jobject exponent_buf) {
413 const char * _exceptionType = NULL;
414 const char * _exceptionMessage = NULL;
415 jarray _mantissaArray = (jarray) 0;
416 jint _mantissaBufferOffset = (jint) 0;
417 jarray _exponentArray = (jarray) 0;
418 jint _exponentBufferOffset = (jint) 0;
419 GLbitfield _returnValue = -1;
420 jint _mantissaRemaining;
421 GLfixed *mantissa = (GLfixed *) 0;
422 jint _exponentRemaining;
423 GLint *exponent = (GLint *) 0;
425 mantissa = (GLfixed *)getPointer(_env, mantissa_buf, &_mantissaArray, &_mantissaRemaining, &_mantissaBufferOffset);
426 if (_mantissaRemaining < 16) {
428 _exceptionType = "java/lang/IllegalArgumentException";
429 _exceptionMessage = "remaining() < 16 < needed";
432 exponent = (GLint *)getPointer(_env, exponent_buf, &_exponentArray, &_exponentRemaining, &_exponentBufferOffset);
433 if (_exponentRemaining < 16) {
435 _exceptionType = "java/lang/IllegalArgumentException";
436 _exceptionMessage = "remaining() < 16 < needed";
439 if (mantissa == NULL) {
440 char * _mantissaBase = (char *)_env->GetPrimitiveArrayCritical(_mantissaArray, (jboolean *) 0);
441 mantissa = (GLfixed *) (_mantissaBase + _mantissaBufferOffset);
443 if (exponent == NULL) {
444 char * _exponentBase = (char *)_env->GetPrimitiveArrayCritical(_exponentArray, (jboolean *) 0);
445 exponent = (GLint *) (_exponentBase + _exponentBufferOffset);
447 _returnValue = glQueryMatrixxOES(
453 if (_exponentArray) {
454 releasePointer(_env, _exponentArray, exponent, _exception ? JNI_FALSE : JNI_TRUE);
456 if (_mantissaArray) {
457 releasePointer(_env, _mantissaArray, mantissa, _exception ? JNI_FALSE : JNI_TRUE);
460 jniThrowException(_env, _exceptionType, _exceptionMessage);
462 return (jint)_returnValue;
465 static const char *classPathName = "android/opengl/GLES10Ext";
467 static JNINativeMethod methods[] = {
468 {"_nativeClassInit", "()V", (void*)nativeClassInit },
469 {"glQueryMatrixxOES", "([II[II)I", (void *) android_glQueryMatrixxOES___3II_3II },
470 {"glQueryMatrixxOES", "(Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)I", (void *) android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 },
473 int register_android_opengl_jni_GLES10Ext(JNIEnv *_env)
476 err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));