blob: da7d0f01928ff45a6b05a4d97afe3fb8420aceb2 [file] [log] [blame]
Jack Palevich27f80022009-04-15 19:13:17 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -07005** 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
Jack Palevich27f80022009-04-15 19:13:17 -07008**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -07009** http://www.apache.org/licenses/LICENSE-2.0
Jack Palevich27f80022009-04-15 19:13:17 -070010**
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070011** 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
Jack Palevich27f80022009-04-15 19:13:17 -070015** limitations under the License.
16*/
17
18// This source file is automatically generated
19
Andreas Gampebfe63332014-11-12 14:12:45 -080020#pragma GCC diagnostic ignored "-Wunused-variable"
Andreas Gampebfe63332014-11-12 14:12:45 -080021#pragma GCC diagnostic ignored "-Wunused-function"
22
Mathias Agopian2ad04772013-02-23 03:12:30 -080023#include <GLES/gl.h>
24#include <GLES/glext.h>
25
Jesse Hall9626f822014-05-19 20:57:49 -070026#include <jni.h>
Steven Moreland2279b252017-07-19 09:50:45 -070027#include <nativehelper/JNIHelp.h>
Jack Palevich27f80022009-04-15 19:13:17 -070028#include <android_runtime/AndroidRuntime.h>
29#include <utils/misc.h>
Jack Palevich27f80022009-04-15 19:13:17 -070030#include <assert.h>
Jack Palevich27f80022009-04-15 19:13:17 -070031
32static int initialized = 0;
33
34static jclass nioAccessClass;
35static jclass bufferClass;
Jack Palevich27f80022009-04-15 19:13:17 -070036static jmethodID getBasePointerID;
37static jmethodID getBaseArrayID;
38static jmethodID getBaseArrayOffsetID;
39static jfieldID positionID;
40static jfieldID limitID;
41static jfieldID elementSizeShiftID;
42
Mathias Agopian2ad04772013-02-23 03:12:30 -080043
44/* special calls implemented in Android's GLES wrapper used to more
45 * efficiently bound-check passed arrays */
46extern "C" {
47#ifdef GL_VERSION_ES_CM_1_1
48GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
49 const GLvoid *ptr, GLsizei count);
50GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride,
51 const GLvoid *pointer, GLsizei count);
52GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type,
53 GLsizei stride, const GLvoid *pointer, GLsizei count);
54GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type,
55 GLsizei stride, const GLvoid *pointer, GLsizei count);
56GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type,
57 GLsizei stride, const GLvoid *pointer, GLsizei count);
58GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type,
59 GLsizei stride, const GLvoid *pointer, GLsizei count);
60GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
61 GLsizei stride, const GLvoid *pointer, GLsizei count);
62#endif
63#ifdef GL_ES_VERSION_2_0
64static void glVertexAttribPointerBounds(GLuint indx, GLint size, GLenum type,
65 GLboolean normalized, GLsizei stride, const GLvoid *pointer, GLsizei count) {
66 glVertexAttribPointer(indx, size, type, normalized, stride, pointer);
67}
68#endif
Andy McFaddencee51982013-04-25 16:08:31 -070069#ifdef GL_ES_VERSION_3_0
70static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type,
71 GLsizei stride, const GLvoid *pointer, GLsizei count) {
72 glVertexAttribIPointer(indx, size, type, stride, pointer);
73}
74#endif
Mathias Agopian2ad04772013-02-23 03:12:30 -080075}
76
Jack Palevich27f80022009-04-15 19:13:17 -070077/* Cache method IDs each time the class is loaded. */
78
79static void
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070080nativeClassInit(JNIEnv *_env, jclass glImplClass)
Jack Palevich27f80022009-04-15 19:13:17 -070081{
82 jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess");
83 nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal);
84
85 jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
86 bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
87
88 getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
89 "getBasePointer", "(Ljava/nio/Buffer;)J");
90 getBaseArrayID = _env->GetStaticMethodID(nioAccessClass,
91 "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
92 getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass,
93 "getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
94
95 positionID = _env->GetFieldID(bufferClass, "position", "I");
96 limitID = _env->GetFieldID(bufferClass, "limit", "I");
97 elementSizeShiftID =
98 _env->GetFieldID(bufferClass, "_elementSizeShift", "I");
99}
100
Jack Palevich27f80022009-04-15 19:13:17 -0700101static void *
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700102getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset)
Jack Palevich27f80022009-04-15 19:13:17 -0700103{
104 jint position;
105 jint limit;
106 jint elementSizeShift;
107 jlong pointer;
Jack Palevich27f80022009-04-15 19:13:17 -0700108
109 position = _env->GetIntField(buffer, positionID);
110 limit = _env->GetIntField(buffer, limitID);
111 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
112 *remaining = (limit - position) << elementSizeShift;
113 pointer = _env->CallStaticLongMethod(nioAccessClass,
114 getBasePointerID, buffer);
115 if (pointer != 0L) {
116 *array = NULL;
Ashok Bhat01c26ea2014-02-24 09:49:07 +0000117 return reinterpret_cast<void*>(pointer);
Jack Palevich27f80022009-04-15 19:13:17 -0700118 }
Elliott Hughes24ce5fb2011-04-08 20:01:01 -0700119
Jack Palevich27f80022009-04-15 19:13:17 -0700120 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
121 getBaseArrayID, buffer);
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700122 *offset = _env->CallStaticIntMethod(nioAccessClass,
Jack Palevich27f80022009-04-15 19:13:17 -0700123 getBaseArrayOffsetID, buffer);
Elliott Hughes24ce5fb2011-04-08 20:01:01 -0700124
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700125 return NULL;
Jack Palevich27f80022009-04-15 19:13:17 -0700126}
127
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700128class ByteArrayGetter {
129public:
130 static void* Get(JNIEnv* _env, jbyteArray array, jboolean* is_copy) {
131 return _env->GetByteArrayElements(array, is_copy);
132 }
133};
134class BooleanArrayGetter {
135public:
136 static void* Get(JNIEnv* _env, jbooleanArray array, jboolean* is_copy) {
137 return _env->GetBooleanArrayElements(array, is_copy);
138 }
139};
140class CharArrayGetter {
141public:
142 static void* Get(JNIEnv* _env, jcharArray array, jboolean* is_copy) {
143 return _env->GetCharArrayElements(array, is_copy);
144 }
145};
146class ShortArrayGetter {
147public:
148 static void* Get(JNIEnv* _env, jshortArray array, jboolean* is_copy) {
149 return _env->GetShortArrayElements(array, is_copy);
150 }
151};
152class IntArrayGetter {
153public:
154 static void* Get(JNIEnv* _env, jintArray array, jboolean* is_copy) {
155 return _env->GetIntArrayElements(array, is_copy);
156 }
157};
158class LongArrayGetter {
159public:
160 static void* Get(JNIEnv* _env, jlongArray array, jboolean* is_copy) {
161 return _env->GetLongArrayElements(array, is_copy);
162 }
163};
164class FloatArrayGetter {
165public:
166 static void* Get(JNIEnv* _env, jfloatArray array, jboolean* is_copy) {
167 return _env->GetFloatArrayElements(array, is_copy);
168 }
169};
170class DoubleArrayGetter {
171public:
172 static void* Get(JNIEnv* _env, jdoubleArray array, jboolean* is_copy) {
173 return _env->GetDoubleArrayElements(array, is_copy);
174 }
175};
176
177template<typename JTYPEARRAY, typename ARRAYGETTER>
178static void*
179getArrayPointer(JNIEnv *_env, JTYPEARRAY array, jboolean* is_copy) {
180 return ARRAYGETTER::Get(_env, array, is_copy);
181}
182
183class ByteArrayReleaser {
184public:
185 static void Release(JNIEnv* _env, jbyteArray array, jbyte* data, jboolean commit) {
186 _env->ReleaseByteArrayElements(array, data, commit ? 0 : JNI_ABORT);
187 }
188};
189class BooleanArrayReleaser {
190public:
191 static void Release(JNIEnv* _env, jbooleanArray array, jboolean* data, jboolean commit) {
192 _env->ReleaseBooleanArrayElements(array, data, commit ? 0 : JNI_ABORT);
193 }
194};
195class CharArrayReleaser {
196public:
197 static void Release(JNIEnv* _env, jcharArray array, jchar* data, jboolean commit) {
198 _env->ReleaseCharArrayElements(array, data, commit ? 0 : JNI_ABORT);
199 }
200};
201class ShortArrayReleaser {
202public:
203 static void Release(JNIEnv* _env, jshortArray array, jshort* data, jboolean commit) {
204 _env->ReleaseShortArrayElements(array, data, commit ? 0 : JNI_ABORT);
205 }
206};
207class IntArrayReleaser {
208public:
209 static void Release(JNIEnv* _env, jintArray array, jint* data, jboolean commit) {
210 _env->ReleaseIntArrayElements(array, data, commit ? 0 : JNI_ABORT);
211 }
212};
213class LongArrayReleaser {
214public:
215 static void Release(JNIEnv* _env, jlongArray array, jlong* data, jboolean commit) {
216 _env->ReleaseLongArrayElements(array, data, commit ? 0 : JNI_ABORT);
217 }
218};
219class FloatArrayReleaser {
220public:
221 static void Release(JNIEnv* _env, jfloatArray array, jfloat* data, jboolean commit) {
222 _env->ReleaseFloatArrayElements(array, data, commit ? 0 : JNI_ABORT);
223 }
224};
225class DoubleArrayReleaser {
226public:
227 static void Release(JNIEnv* _env, jdoubleArray array, jdouble* data, jboolean commit) {
228 _env->ReleaseDoubleArrayElements(array, data, commit ? 0 : JNI_ABORT);
229 }
230};
231
232template<typename JTYPEARRAY, typename NTYPEARRAY, typename ARRAYRELEASER>
233static void
234releaseArrayPointer(JNIEnv *_env, JTYPEARRAY array, NTYPEARRAY data, jboolean commit) {
235 ARRAYRELEASER::Release(_env, array, data, commit);
236}
237
Jack Palevich27f80022009-04-15 19:13:17 -0700238static void
239releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
240{
241 _env->ReleasePrimitiveArrayCritical(array, data,
Mathias Agopian2ad04772013-02-23 03:12:30 -0800242 commit ? 0 : JNI_ABORT);
243}
244
245static void *
246getDirectBufferPointer(JNIEnv *_env, jobject buffer) {
247 char* buf = (char*) _env->GetDirectBufferAddress(buffer);
248 if (buf) {
249 jint position = _env->GetIntField(buffer, positionID);
250 jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
251 buf += position << elementSizeShift;
252 } else {
253 jniThrowException(_env, "java/lang/IllegalArgumentException",
254 "Must use a native order direct Buffer");
255 }
256 return (void*) buf;
257}
258
259// --------------------------------------------------------------------------
260
261/*
262 * returns the number of values glGet returns for a given pname.
263 *
264 * The code below is written such that pnames requiring only one values
265 * are the default (and are not explicitely tested for). This makes the
266 * checking code much shorter/readable/efficient.
267 *
268 * This means that unknown pnames (e.g.: extensions) will default to 1. If
269 * that unknown pname needs more than 1 value, then the validation check
270 * is incomplete and the app may crash if it passed the wrong number params.
271 */
272static int getNeededCount(GLint pname) {
273 int needed = 1;
Romain Guydc43a6c2017-02-17 19:54:25 -0800274#ifdef GL_ES_VERSION_3_0
275 // GLES 3.x pnames
276 switch (pname) {
277 case GL_MAX_VIEWPORT_DIMS:
278 needed = 2;
279 break;
280
281 case GL_PROGRAM_BINARY_FORMATS:
282 glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &needed);
283 break;
284 }
285#endif
286
Mathias Agopian2ad04772013-02-23 03:12:30 -0800287#ifdef GL_ES_VERSION_2_0
288 // GLES 2.x pnames
289 switch (pname) {
290 case GL_ALIASED_LINE_WIDTH_RANGE:
291 case GL_ALIASED_POINT_SIZE_RANGE:
292 needed = 2;
293 break;
294
295 case GL_BLEND_COLOR:
296 case GL_COLOR_CLEAR_VALUE:
297 case GL_COLOR_WRITEMASK:
298 case GL_SCISSOR_BOX:
299 case GL_VIEWPORT:
300 needed = 4;
301 break;
302
303 case GL_COMPRESSED_TEXTURE_FORMATS:
304 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed);
305 break;
306
307 case GL_SHADER_BINARY_FORMATS:
308 glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &needed);
309 break;
310 }
311#endif
312
313#ifdef GL_VERSION_ES_CM_1_1
314 // GLES 1.x pnames
315 switch (pname) {
316 case GL_ALIASED_LINE_WIDTH_RANGE:
317 case GL_ALIASED_POINT_SIZE_RANGE:
318 case GL_DEPTH_RANGE:
319 case GL_SMOOTH_LINE_WIDTH_RANGE:
320 case GL_SMOOTH_POINT_SIZE_RANGE:
321 needed = 2;
322 break;
323
324 case GL_CURRENT_NORMAL:
325 case GL_POINT_DISTANCE_ATTENUATION:
326 needed = 3;
327 break;
328
329 case GL_COLOR_CLEAR_VALUE:
330 case GL_COLOR_WRITEMASK:
331 case GL_CURRENT_COLOR:
332 case GL_CURRENT_TEXTURE_COORDS:
333 case GL_FOG_COLOR:
334 case GL_LIGHT_MODEL_AMBIENT:
335 case GL_SCISSOR_BOX:
336 case GL_VIEWPORT:
337 needed = 4;
338 break;
339
340 case GL_MODELVIEW_MATRIX:
341 case GL_PROJECTION_MATRIX:
342 case GL_TEXTURE_MATRIX:
343 needed = 16;
344 break;
345
346 case GL_COMPRESSED_TEXTURE_FORMATS:
347 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed);
348 break;
349 }
350#endif
351 return needed;
352}
353
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700354template <typename JTYPEARRAY, typename ARRAYGETTER, typename NTYPEARRAY,
355 typename ARRAYRELEASER, typename CTYPE, void GET(GLenum, CTYPE*)>
Mathias Agopian2ad04772013-02-23 03:12:30 -0800356static void
357get
358 (JNIEnv *_env, jobject _this, jint pname, JTYPEARRAY params_ref, jint offset) {
359 jint _exception = 0;
360 const char * _exceptionType;
361 const char * _exceptionMessage;
362 CTYPE *params_base = (CTYPE *) 0;
363 jint _remaining;
364 CTYPE *params = (CTYPE *) 0;
365 int _needed = 0;
366
367 if (!params_ref) {
368 _exception = 1;
369 _exceptionType = "java/lang/IllegalArgumentException";
370 _exceptionMessage = "params == null";
371 goto exit;
372 }
373 if (offset < 0) {
374 _exception = 1;
375 _exceptionType = "java/lang/IllegalArgumentException";
376 _exceptionMessage = "offset < 0";
377 goto exit;
378 }
379 _remaining = _env->GetArrayLength(params_ref) - offset;
380 _needed = getNeededCount(pname);
381 // if we didn't find this pname, we just assume the user passed
382 // an array of the right size -- this might happen with extensions
383 // or if we forget an enum here.
384 if (_remaining < _needed) {
385 _exception = 1;
386 _exceptionType = "java/lang/IllegalArgumentException";
387 _exceptionMessage = "length - offset < needed";
388 goto exit;
389 }
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700390 params_base = (CTYPE *) getArrayPointer<JTYPEARRAY, ARRAYGETTER>(
391 _env, params_ref, (jboolean *)0);
Mathias Agopian2ad04772013-02-23 03:12:30 -0800392 params = params_base + offset;
393
394 GET(
395 (GLenum)pname,
396 (CTYPE *)params
397 );
398
399exit:
400 if (params_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700401 releaseArrayPointer<JTYPEARRAY, NTYPEARRAY, ARRAYRELEASER>(
402 _env, params_ref, params_base, !_exception);
Mathias Agopian2ad04772013-02-23 03:12:30 -0800403 }
404 if (_exception) {
405 jniThrowException(_env, _exceptionType, _exceptionMessage);
406 }
407}
408
409
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700410template <typename CTYPE, typename JTYPEARRAY, typename ARRAYGETTER, typename NTYPEARRAY,
411 typename ARRAYRELEASER, void GET(GLenum, CTYPE*)>
Mathias Agopian2ad04772013-02-23 03:12:30 -0800412static void
413getarray
414 (JNIEnv *_env, jobject _this, jint pname, jobject params_buf) {
415 jint _exception = 0;
416 const char * _exceptionType;
417 const char * _exceptionMessage;
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700418 JTYPEARRAY _array = (JTYPEARRAY) 0;
Mathias Agopian2ad04772013-02-23 03:12:30 -0800419 jint _bufferOffset = (jint) 0;
420 jint _remaining;
421 CTYPE *params = (CTYPE *) 0;
422 int _needed = 0;
423
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700424 params = (CTYPE *)getPointer(_env, params_buf, (jarray*)&_array, &_remaining, &_bufferOffset);
Andy McFaddencee51982013-04-25 16:08:31 -0700425 _remaining /= sizeof(CTYPE); // convert from bytes to item count
Mathias Agopian2ad04772013-02-23 03:12:30 -0800426 _needed = getNeededCount(pname);
427 // if we didn't find this pname, we just assume the user passed
428 // an array of the right size -- this might happen with extensions
429 // or if we forget an enum here.
430 if (_needed>0 && _remaining < _needed) {
431 _exception = 1;
432 _exceptionType = "java/lang/IllegalArgumentException";
433 _exceptionMessage = "remaining() < needed";
434 goto exit;
435 }
436 if (params == NULL) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700437 char * _paramsBase = (char *) getArrayPointer<JTYPEARRAY, ARRAYGETTER>(
438 _env, _array, (jboolean *) 0);
Mathias Agopian2ad04772013-02-23 03:12:30 -0800439 params = (CTYPE *) (_paramsBase + _bufferOffset);
440 }
441 GET(
442 (GLenum)pname,
443 (CTYPE *)params
444 );
445
446exit:
447 if (_array) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700448 releaseArrayPointer<JTYPEARRAY, NTYPEARRAY, ARRAYRELEASER>(
449 _env, _array, (NTYPEARRAY)params, _exception ? JNI_FALSE : JNI_TRUE);
Mathias Agopian2ad04772013-02-23 03:12:30 -0800450 }
451 if (_exception) {
452 jniThrowException(_env, _exceptionType, _exceptionMessage);
453 }
Jack Palevich27f80022009-04-15 19:13:17 -0700454}
455
456// --------------------------------------------------------------------------
Jack Palevich27f80022009-04-15 19:13:17 -0700457/* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
458static jint
459android_glQueryMatrixxOES___3II_3II
460 (JNIEnv *_env, jobject _this, jintArray mantissa_ref, jint mantissaOffset, jintArray exponent_ref, jint exponentOffset) {
461 jint _exception = 0;
Mathias Agopian2ad04772013-02-23 03:12:30 -0800462 const char * _exceptionType = NULL;
463 const char * _exceptionMessage = NULL;
Jack Palevich27f80022009-04-15 19:13:17 -0700464 GLbitfield _returnValue = -1;
465 GLfixed *mantissa_base = (GLfixed *) 0;
466 jint _mantissaRemaining;
467 GLfixed *mantissa = (GLfixed *) 0;
468 GLint *exponent_base = (GLint *) 0;
469 jint _exponentRemaining;
470 GLint *exponent = (GLint *) 0;
471
472 if (!mantissa_ref) {
473 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700474 _exceptionType = "java/lang/IllegalArgumentException";
475 _exceptionMessage = "mantissa == null";
Jack Palevich27f80022009-04-15 19:13:17 -0700476 goto exit;
477 }
478 if (mantissaOffset < 0) {
479 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700480 _exceptionType = "java/lang/IllegalArgumentException";
481 _exceptionMessage = "mantissaOffset < 0";
Jack Palevich27f80022009-04-15 19:13:17 -0700482 goto exit;
483 }
484 _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset;
485 if (_mantissaRemaining < 16) {
486 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700487 _exceptionType = "java/lang/IllegalArgumentException";
488 _exceptionMessage = "length - mantissaOffset < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700489 goto exit;
490 }
491 mantissa_base = (GLfixed *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700492 _env->GetIntArrayElements(mantissa_ref, (jboolean *)0);
Jack Palevich27f80022009-04-15 19:13:17 -0700493 mantissa = mantissa_base + mantissaOffset;
494
495 if (!exponent_ref) {
496 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700497 _exceptionType = "java/lang/IllegalArgumentException";
498 _exceptionMessage = "exponent == null";
Jack Palevich27f80022009-04-15 19:13:17 -0700499 goto exit;
500 }
501 if (exponentOffset < 0) {
502 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700503 _exceptionType = "java/lang/IllegalArgumentException";
504 _exceptionMessage = "exponentOffset < 0";
Jack Palevich27f80022009-04-15 19:13:17 -0700505 goto exit;
506 }
507 _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset;
508 if (_exponentRemaining < 16) {
509 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700510 _exceptionType = "java/lang/IllegalArgumentException";
511 _exceptionMessage = "length - exponentOffset < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700512 goto exit;
513 }
514 exponent_base = (GLint *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700515 _env->GetIntArrayElements(exponent_ref, (jboolean *)0);
Jack Palevich27f80022009-04-15 19:13:17 -0700516 exponent = exponent_base + exponentOffset;
517
518 _returnValue = glQueryMatrixxOES(
519 (GLfixed *)mantissa,
520 (GLint *)exponent
521 );
522
523exit:
524 if (exponent_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700525 _env->ReleaseIntArrayElements(exponent_ref, (jint*)exponent_base,
Jack Palevich27f80022009-04-15 19:13:17 -0700526 _exception ? JNI_ABORT: 0);
527 }
528 if (mantissa_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700529 _env->ReleaseIntArrayElements(mantissa_ref, (jint*)mantissa_base,
Jack Palevich27f80022009-04-15 19:13:17 -0700530 _exception ? JNI_ABORT: 0);
531 }
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700532 if (_exception) {
533 jniThrowException(_env, _exceptionType, _exceptionMessage);
534 }
Andy McFaddencee51982013-04-25 16:08:31 -0700535 return (jint)_returnValue;
Jack Palevich27f80022009-04-15 19:13:17 -0700536}
537
538/* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
539static jint
540android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2
541 (JNIEnv *_env, jobject _this, jobject mantissa_buf, jobject exponent_buf) {
542 jint _exception = 0;
Mathias Agopian2ad04772013-02-23 03:12:30 -0800543 const char * _exceptionType = NULL;
544 const char * _exceptionMessage = NULL;
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700545 jintArray _mantissaArray = (jintArray) 0;
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700546 jint _mantissaBufferOffset = (jint) 0;
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700547 jintArray _exponentArray = (jintArray) 0;
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700548 jint _exponentBufferOffset = (jint) 0;
Jack Palevich27f80022009-04-15 19:13:17 -0700549 GLbitfield _returnValue = -1;
550 jint _mantissaRemaining;
551 GLfixed *mantissa = (GLfixed *) 0;
552 jint _exponentRemaining;
553 GLint *exponent = (GLint *) 0;
554
Romain Guy84cac202016-12-05 12:26:02 -0800555 if (!mantissa_buf) {
556 _exception = 1;
557 _exceptionType = "java/lang/IllegalArgumentException";
558 _exceptionMessage = "mantissa == null";
559 goto exit;
560 }
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700561 mantissa = (GLfixed *)getPointer(_env, mantissa_buf, (jarray*)&_mantissaArray, &_mantissaRemaining, &_mantissaBufferOffset);
Jack Palevich27f80022009-04-15 19:13:17 -0700562 if (_mantissaRemaining < 16) {
563 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700564 _exceptionType = "java/lang/IllegalArgumentException";
565 _exceptionMessage = "remaining() < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700566 goto exit;
567 }
Romain Guy84cac202016-12-05 12:26:02 -0800568 if (!exponent_buf) {
569 _exception = 1;
570 _exceptionType = "java/lang/IllegalArgumentException";
571 _exceptionMessage = "exponent == null";
572 goto exit;
573 }
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700574 exponent = (GLint *)getPointer(_env, exponent_buf, (jarray*)&_exponentArray, &_exponentRemaining, &_exponentBufferOffset);
Jack Palevich27f80022009-04-15 19:13:17 -0700575 if (_exponentRemaining < 16) {
576 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700577 _exceptionType = "java/lang/IllegalArgumentException";
578 _exceptionMessage = "remaining() < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700579 goto exit;
580 }
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700581 if (mantissa == NULL) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700582 char * _mantissaBase = (char *)_env->GetIntArrayElements(_mantissaArray, (jboolean *) 0);
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700583 mantissa = (GLfixed *) (_mantissaBase + _mantissaBufferOffset);
584 }
585 if (exponent == NULL) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700586 char * _exponentBase = (char *)_env->GetIntArrayElements(_exponentArray, (jboolean *) 0);
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700587 exponent = (GLint *) (_exponentBase + _exponentBufferOffset);
588 }
Jack Palevich27f80022009-04-15 19:13:17 -0700589 _returnValue = glQueryMatrixxOES(
590 (GLfixed *)mantissa,
591 (GLint *)exponent
592 );
593
594exit:
Jack Palevich27f80022009-04-15 19:13:17 -0700595 if (_exponentArray) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700596 _env->ReleaseIntArrayElements(_exponentArray, (jint*)exponent, _exception ? JNI_ABORT : 0);
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700597 }
598 if (_mantissaArray) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700599 _env->ReleaseIntArrayElements(_mantissaArray, (jint*)mantissa, _exception ? JNI_ABORT : 0);
Jack Palevich27f80022009-04-15 19:13:17 -0700600 }
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700601 if (_exception) {
602 jniThrowException(_env, _exceptionType, _exceptionMessage);
603 }
Andy McFaddencee51982013-04-25 16:08:31 -0700604 return (jint)_returnValue;
Jack Palevich27f80022009-04-15 19:13:17 -0700605}
606
607static const char *classPathName = "android/opengl/GLES10Ext";
608
Daniel Micay76f6a862015-09-19 17:31:01 -0400609static const JNINativeMethod methods[] = {
Jack Palevich27f80022009-04-15 19:13:17 -0700610{"_nativeClassInit", "()V", (void*)nativeClassInit },
611{"glQueryMatrixxOES", "([II[II)I", (void *) android_glQueryMatrixxOES___3II_3II },
612{"glQueryMatrixxOES", "(Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)I", (void *) android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 },
613};
614
615int register_android_opengl_jni_GLES10Ext(JNIEnv *_env)
616{
617 int err;
618 err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));
619 return err;
620}