blob: 38f7ba6485ce0dc085b2af601ae518c5a605a5a5 [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"
21#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
22#pragma GCC diagnostic ignored "-Wunused-function"
23
Mathias Agopian2ad04772013-02-23 03:12:30 -080024#include <GLES/gl.h>
25#include <GLES/glext.h>
26
Jesse Hall9626f822014-05-19 20:57:49 -070027#include <jni.h>
28#include <JNIHelp.h>
Jack Palevich27f80022009-04-15 19:13:17 -070029#include <android_runtime/AndroidRuntime.h>
30#include <utils/misc.h>
Jack Palevich27f80022009-04-15 19:13:17 -070031#include <assert.h>
Jack Palevich27f80022009-04-15 19:13:17 -070032
33static int initialized = 0;
34
35static jclass nioAccessClass;
36static jclass bufferClass;
Jack Palevich27f80022009-04-15 19:13:17 -070037static jmethodID getBasePointerID;
38static jmethodID getBaseArrayID;
39static jmethodID getBaseArrayOffsetID;
40static jfieldID positionID;
41static jfieldID limitID;
42static jfieldID elementSizeShiftID;
43
Mathias Agopian2ad04772013-02-23 03:12:30 -080044
45/* special calls implemented in Android's GLES wrapper used to more
46 * efficiently bound-check passed arrays */
47extern "C" {
48#ifdef GL_VERSION_ES_CM_1_1
49GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
50 const GLvoid *ptr, GLsizei count);
51GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride,
52 const GLvoid *pointer, GLsizei count);
53GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type,
54 GLsizei stride, const GLvoid *pointer, GLsizei count);
55GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type,
56 GLsizei stride, const GLvoid *pointer, GLsizei count);
57GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type,
58 GLsizei stride, const GLvoid *pointer, GLsizei count);
59GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type,
60 GLsizei stride, const GLvoid *pointer, GLsizei count);
61GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
62 GLsizei stride, const GLvoid *pointer, GLsizei count);
63#endif
64#ifdef GL_ES_VERSION_2_0
65static void glVertexAttribPointerBounds(GLuint indx, GLint size, GLenum type,
66 GLboolean normalized, GLsizei stride, const GLvoid *pointer, GLsizei count) {
67 glVertexAttribPointer(indx, size, type, normalized, stride, pointer);
68}
69#endif
Andy McFaddencee51982013-04-25 16:08:31 -070070#ifdef GL_ES_VERSION_3_0
71static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type,
72 GLsizei stride, const GLvoid *pointer, GLsizei count) {
73 glVertexAttribIPointer(indx, size, type, stride, pointer);
74}
75#endif
Mathias Agopian2ad04772013-02-23 03:12:30 -080076}
77
Jack Palevich27f80022009-04-15 19:13:17 -070078/* Cache method IDs each time the class is loaded. */
79
80static void
Elliott Hughes24ce5fb2011-04-08 20:01:01 -070081nativeClassInit(JNIEnv *_env, jclass glImplClass)
Jack Palevich27f80022009-04-15 19:13:17 -070082{
83 jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess");
84 nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal);
85
86 jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
87 bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
88
89 getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
90 "getBasePointer", "(Ljava/nio/Buffer;)J");
91 getBaseArrayID = _env->GetStaticMethodID(nioAccessClass,
92 "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
93 getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass,
94 "getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
95
96 positionID = _env->GetFieldID(bufferClass, "position", "I");
97 limitID = _env->GetFieldID(bufferClass, "limit", "I");
98 elementSizeShiftID =
99 _env->GetFieldID(bufferClass, "_elementSizeShift", "I");
100}
101
Jack Palevich27f80022009-04-15 19:13:17 -0700102static void *
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700103getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset)
Jack Palevich27f80022009-04-15 19:13:17 -0700104{
105 jint position;
106 jint limit;
107 jint elementSizeShift;
108 jlong pointer;
Jack Palevich27f80022009-04-15 19:13:17 -0700109
110 position = _env->GetIntField(buffer, positionID);
111 limit = _env->GetIntField(buffer, limitID);
112 elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
113 *remaining = (limit - position) << elementSizeShift;
114 pointer = _env->CallStaticLongMethod(nioAccessClass,
115 getBasePointerID, buffer);
116 if (pointer != 0L) {
117 *array = NULL;
Ashok Bhat01c26ea2014-02-24 09:49:07 +0000118 return reinterpret_cast<void*>(pointer);
Jack Palevich27f80022009-04-15 19:13:17 -0700119 }
Elliott Hughes24ce5fb2011-04-08 20:01:01 -0700120
Jack Palevich27f80022009-04-15 19:13:17 -0700121 *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
122 getBaseArrayID, buffer);
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700123 *offset = _env->CallStaticIntMethod(nioAccessClass,
Jack Palevich27f80022009-04-15 19:13:17 -0700124 getBaseArrayOffsetID, buffer);
Elliott Hughes24ce5fb2011-04-08 20:01:01 -0700125
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700126 return NULL;
Jack Palevich27f80022009-04-15 19:13:17 -0700127}
128
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700129class ByteArrayGetter {
130public:
131 static void* Get(JNIEnv* _env, jbyteArray array, jboolean* is_copy) {
132 return _env->GetByteArrayElements(array, is_copy);
133 }
134};
135class BooleanArrayGetter {
136public:
137 static void* Get(JNIEnv* _env, jbooleanArray array, jboolean* is_copy) {
138 return _env->GetBooleanArrayElements(array, is_copy);
139 }
140};
141class CharArrayGetter {
142public:
143 static void* Get(JNIEnv* _env, jcharArray array, jboolean* is_copy) {
144 return _env->GetCharArrayElements(array, is_copy);
145 }
146};
147class ShortArrayGetter {
148public:
149 static void* Get(JNIEnv* _env, jshortArray array, jboolean* is_copy) {
150 return _env->GetShortArrayElements(array, is_copy);
151 }
152};
153class IntArrayGetter {
154public:
155 static void* Get(JNIEnv* _env, jintArray array, jboolean* is_copy) {
156 return _env->GetIntArrayElements(array, is_copy);
157 }
158};
159class LongArrayGetter {
160public:
161 static void* Get(JNIEnv* _env, jlongArray array, jboolean* is_copy) {
162 return _env->GetLongArrayElements(array, is_copy);
163 }
164};
165class FloatArrayGetter {
166public:
167 static void* Get(JNIEnv* _env, jfloatArray array, jboolean* is_copy) {
168 return _env->GetFloatArrayElements(array, is_copy);
169 }
170};
171class DoubleArrayGetter {
172public:
173 static void* Get(JNIEnv* _env, jdoubleArray array, jboolean* is_copy) {
174 return _env->GetDoubleArrayElements(array, is_copy);
175 }
176};
177
178template<typename JTYPEARRAY, typename ARRAYGETTER>
179static void*
180getArrayPointer(JNIEnv *_env, JTYPEARRAY array, jboolean* is_copy) {
181 return ARRAYGETTER::Get(_env, array, is_copy);
182}
183
184class ByteArrayReleaser {
185public:
186 static void Release(JNIEnv* _env, jbyteArray array, jbyte* data, jboolean commit) {
187 _env->ReleaseByteArrayElements(array, data, commit ? 0 : JNI_ABORT);
188 }
189};
190class BooleanArrayReleaser {
191public:
192 static void Release(JNIEnv* _env, jbooleanArray array, jboolean* data, jboolean commit) {
193 _env->ReleaseBooleanArrayElements(array, data, commit ? 0 : JNI_ABORT);
194 }
195};
196class CharArrayReleaser {
197public:
198 static void Release(JNIEnv* _env, jcharArray array, jchar* data, jboolean commit) {
199 _env->ReleaseCharArrayElements(array, data, commit ? 0 : JNI_ABORT);
200 }
201};
202class ShortArrayReleaser {
203public:
204 static void Release(JNIEnv* _env, jshortArray array, jshort* data, jboolean commit) {
205 _env->ReleaseShortArrayElements(array, data, commit ? 0 : JNI_ABORT);
206 }
207};
208class IntArrayReleaser {
209public:
210 static void Release(JNIEnv* _env, jintArray array, jint* data, jboolean commit) {
211 _env->ReleaseIntArrayElements(array, data, commit ? 0 : JNI_ABORT);
212 }
213};
214class LongArrayReleaser {
215public:
216 static void Release(JNIEnv* _env, jlongArray array, jlong* data, jboolean commit) {
217 _env->ReleaseLongArrayElements(array, data, commit ? 0 : JNI_ABORT);
218 }
219};
220class FloatArrayReleaser {
221public:
222 static void Release(JNIEnv* _env, jfloatArray array, jfloat* data, jboolean commit) {
223 _env->ReleaseFloatArrayElements(array, data, commit ? 0 : JNI_ABORT);
224 }
225};
226class DoubleArrayReleaser {
227public:
228 static void Release(JNIEnv* _env, jdoubleArray array, jdouble* data, jboolean commit) {
229 _env->ReleaseDoubleArrayElements(array, data, commit ? 0 : JNI_ABORT);
230 }
231};
232
233template<typename JTYPEARRAY, typename NTYPEARRAY, typename ARRAYRELEASER>
234static void
235releaseArrayPointer(JNIEnv *_env, JTYPEARRAY array, NTYPEARRAY data, jboolean commit) {
236 ARRAYRELEASER::Release(_env, array, data, commit);
237}
238
Jack Palevich27f80022009-04-15 19:13:17 -0700239static void
240releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
241{
242 _env->ReleasePrimitiveArrayCritical(array, data,
Mathias Agopian2ad04772013-02-23 03:12:30 -0800243 commit ? 0 : JNI_ABORT);
244}
245
246static void *
247getDirectBufferPointer(JNIEnv *_env, jobject buffer) {
248 char* buf = (char*) _env->GetDirectBufferAddress(buffer);
249 if (buf) {
250 jint position = _env->GetIntField(buffer, positionID);
251 jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
252 buf += position << elementSizeShift;
253 } else {
254 jniThrowException(_env, "java/lang/IllegalArgumentException",
255 "Must use a native order direct Buffer");
256 }
257 return (void*) buf;
258}
259
260// --------------------------------------------------------------------------
261
262/*
263 * returns the number of values glGet returns for a given pname.
264 *
265 * The code below is written such that pnames requiring only one values
266 * are the default (and are not explicitely tested for). This makes the
267 * checking code much shorter/readable/efficient.
268 *
269 * This means that unknown pnames (e.g.: extensions) will default to 1. If
270 * that unknown pname needs more than 1 value, then the validation check
271 * is incomplete and the app may crash if it passed the wrong number params.
272 */
273static int getNeededCount(GLint pname) {
274 int needed = 1;
Romain Guydc43a6c2017-02-17 19:54:25 -0800275#ifdef GL_ES_VERSION_3_0
276 // GLES 3.x pnames
277 switch (pname) {
278 case GL_MAX_VIEWPORT_DIMS:
279 needed = 2;
280 break;
281
282 case GL_PROGRAM_BINARY_FORMATS:
283 glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &needed);
284 break;
285 }
286#endif
287
Mathias Agopian2ad04772013-02-23 03:12:30 -0800288#ifdef GL_ES_VERSION_2_0
289 // GLES 2.x pnames
290 switch (pname) {
291 case GL_ALIASED_LINE_WIDTH_RANGE:
292 case GL_ALIASED_POINT_SIZE_RANGE:
293 needed = 2;
294 break;
295
296 case GL_BLEND_COLOR:
297 case GL_COLOR_CLEAR_VALUE:
298 case GL_COLOR_WRITEMASK:
299 case GL_SCISSOR_BOX:
300 case GL_VIEWPORT:
301 needed = 4;
302 break;
303
304 case GL_COMPRESSED_TEXTURE_FORMATS:
305 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed);
306 break;
307
308 case GL_SHADER_BINARY_FORMATS:
309 glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &needed);
310 break;
311 }
312#endif
313
314#ifdef GL_VERSION_ES_CM_1_1
315 // GLES 1.x pnames
316 switch (pname) {
317 case GL_ALIASED_LINE_WIDTH_RANGE:
318 case GL_ALIASED_POINT_SIZE_RANGE:
319 case GL_DEPTH_RANGE:
320 case GL_SMOOTH_LINE_WIDTH_RANGE:
321 case GL_SMOOTH_POINT_SIZE_RANGE:
322 needed = 2;
323 break;
324
325 case GL_CURRENT_NORMAL:
326 case GL_POINT_DISTANCE_ATTENUATION:
327 needed = 3;
328 break;
329
330 case GL_COLOR_CLEAR_VALUE:
331 case GL_COLOR_WRITEMASK:
332 case GL_CURRENT_COLOR:
333 case GL_CURRENT_TEXTURE_COORDS:
334 case GL_FOG_COLOR:
335 case GL_LIGHT_MODEL_AMBIENT:
336 case GL_SCISSOR_BOX:
337 case GL_VIEWPORT:
338 needed = 4;
339 break;
340
341 case GL_MODELVIEW_MATRIX:
342 case GL_PROJECTION_MATRIX:
343 case GL_TEXTURE_MATRIX:
344 needed = 16;
345 break;
346
347 case GL_COMPRESSED_TEXTURE_FORMATS:
348 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &needed);
349 break;
350 }
351#endif
352 return needed;
353}
354
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700355template <typename JTYPEARRAY, typename ARRAYGETTER, typename NTYPEARRAY,
356 typename ARRAYRELEASER, typename CTYPE, void GET(GLenum, CTYPE*)>
Mathias Agopian2ad04772013-02-23 03:12:30 -0800357static void
358get
359 (JNIEnv *_env, jobject _this, jint pname, JTYPEARRAY params_ref, jint offset) {
360 jint _exception = 0;
361 const char * _exceptionType;
362 const char * _exceptionMessage;
363 CTYPE *params_base = (CTYPE *) 0;
364 jint _remaining;
365 CTYPE *params = (CTYPE *) 0;
366 int _needed = 0;
367
368 if (!params_ref) {
369 _exception = 1;
370 _exceptionType = "java/lang/IllegalArgumentException";
371 _exceptionMessage = "params == null";
372 goto exit;
373 }
374 if (offset < 0) {
375 _exception = 1;
376 _exceptionType = "java/lang/IllegalArgumentException";
377 _exceptionMessage = "offset < 0";
378 goto exit;
379 }
380 _remaining = _env->GetArrayLength(params_ref) - offset;
381 _needed = getNeededCount(pname);
382 // if we didn't find this pname, we just assume the user passed
383 // an array of the right size -- this might happen with extensions
384 // or if we forget an enum here.
385 if (_remaining < _needed) {
386 _exception = 1;
387 _exceptionType = "java/lang/IllegalArgumentException";
388 _exceptionMessage = "length - offset < needed";
389 goto exit;
390 }
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700391 params_base = (CTYPE *) getArrayPointer<JTYPEARRAY, ARRAYGETTER>(
392 _env, params_ref, (jboolean *)0);
Mathias Agopian2ad04772013-02-23 03:12:30 -0800393 params = params_base + offset;
394
395 GET(
396 (GLenum)pname,
397 (CTYPE *)params
398 );
399
400exit:
401 if (params_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700402 releaseArrayPointer<JTYPEARRAY, NTYPEARRAY, ARRAYRELEASER>(
403 _env, params_ref, params_base, !_exception);
Mathias Agopian2ad04772013-02-23 03:12:30 -0800404 }
405 if (_exception) {
406 jniThrowException(_env, _exceptionType, _exceptionMessage);
407 }
408}
409
410
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700411template <typename CTYPE, typename JTYPEARRAY, typename ARRAYGETTER, typename NTYPEARRAY,
412 typename ARRAYRELEASER, void GET(GLenum, CTYPE*)>
Mathias Agopian2ad04772013-02-23 03:12:30 -0800413static void
414getarray
415 (JNIEnv *_env, jobject _this, jint pname, jobject params_buf) {
416 jint _exception = 0;
417 const char * _exceptionType;
418 const char * _exceptionMessage;
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700419 JTYPEARRAY _array = (JTYPEARRAY) 0;
Mathias Agopian2ad04772013-02-23 03:12:30 -0800420 jint _bufferOffset = (jint) 0;
421 jint _remaining;
422 CTYPE *params = (CTYPE *) 0;
423 int _needed = 0;
424
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700425 params = (CTYPE *)getPointer(_env, params_buf, (jarray*)&_array, &_remaining, &_bufferOffset);
Andy McFaddencee51982013-04-25 16:08:31 -0700426 _remaining /= sizeof(CTYPE); // convert from bytes to item count
Mathias Agopian2ad04772013-02-23 03:12:30 -0800427 _needed = getNeededCount(pname);
428 // if we didn't find this pname, we just assume the user passed
429 // an array of the right size -- this might happen with extensions
430 // or if we forget an enum here.
431 if (_needed>0 && _remaining < _needed) {
432 _exception = 1;
433 _exceptionType = "java/lang/IllegalArgumentException";
434 _exceptionMessage = "remaining() < needed";
435 goto exit;
436 }
437 if (params == NULL) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700438 char * _paramsBase = (char *) getArrayPointer<JTYPEARRAY, ARRAYGETTER>(
439 _env, _array, (jboolean *) 0);
Mathias Agopian2ad04772013-02-23 03:12:30 -0800440 params = (CTYPE *) (_paramsBase + _bufferOffset);
441 }
442 GET(
443 (GLenum)pname,
444 (CTYPE *)params
445 );
446
447exit:
448 if (_array) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700449 releaseArrayPointer<JTYPEARRAY, NTYPEARRAY, ARRAYRELEASER>(
450 _env, _array, (NTYPEARRAY)params, _exception ? JNI_FALSE : JNI_TRUE);
Mathias Agopian2ad04772013-02-23 03:12:30 -0800451 }
452 if (_exception) {
453 jniThrowException(_env, _exceptionType, _exceptionMessage);
454 }
Jack Palevich27f80022009-04-15 19:13:17 -0700455}
456
457// --------------------------------------------------------------------------
Jack Palevich27f80022009-04-15 19:13:17 -0700458/* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
459static jint
460android_glQueryMatrixxOES___3II_3II
461 (JNIEnv *_env, jobject _this, jintArray mantissa_ref, jint mantissaOffset, jintArray exponent_ref, jint exponentOffset) {
462 jint _exception = 0;
Mathias Agopian2ad04772013-02-23 03:12:30 -0800463 const char * _exceptionType = NULL;
464 const char * _exceptionMessage = NULL;
Jack Palevich27f80022009-04-15 19:13:17 -0700465 GLbitfield _returnValue = -1;
466 GLfixed *mantissa_base = (GLfixed *) 0;
467 jint _mantissaRemaining;
468 GLfixed *mantissa = (GLfixed *) 0;
469 GLint *exponent_base = (GLint *) 0;
470 jint _exponentRemaining;
471 GLint *exponent = (GLint *) 0;
472
473 if (!mantissa_ref) {
474 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700475 _exceptionType = "java/lang/IllegalArgumentException";
476 _exceptionMessage = "mantissa == null";
Jack Palevich27f80022009-04-15 19:13:17 -0700477 goto exit;
478 }
479 if (mantissaOffset < 0) {
480 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700481 _exceptionType = "java/lang/IllegalArgumentException";
482 _exceptionMessage = "mantissaOffset < 0";
Jack Palevich27f80022009-04-15 19:13:17 -0700483 goto exit;
484 }
485 _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset;
486 if (_mantissaRemaining < 16) {
487 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700488 _exceptionType = "java/lang/IllegalArgumentException";
489 _exceptionMessage = "length - mantissaOffset < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700490 goto exit;
491 }
492 mantissa_base = (GLfixed *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700493 _env->GetIntArrayElements(mantissa_ref, (jboolean *)0);
Jack Palevich27f80022009-04-15 19:13:17 -0700494 mantissa = mantissa_base + mantissaOffset;
495
496 if (!exponent_ref) {
497 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700498 _exceptionType = "java/lang/IllegalArgumentException";
499 _exceptionMessage = "exponent == null";
Jack Palevich27f80022009-04-15 19:13:17 -0700500 goto exit;
501 }
502 if (exponentOffset < 0) {
503 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700504 _exceptionType = "java/lang/IllegalArgumentException";
505 _exceptionMessage = "exponentOffset < 0";
Jack Palevich27f80022009-04-15 19:13:17 -0700506 goto exit;
507 }
508 _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset;
509 if (_exponentRemaining < 16) {
510 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700511 _exceptionType = "java/lang/IllegalArgumentException";
512 _exceptionMessage = "length - exponentOffset < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700513 goto exit;
514 }
515 exponent_base = (GLint *)
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700516 _env->GetIntArrayElements(exponent_ref, (jboolean *)0);
Jack Palevich27f80022009-04-15 19:13:17 -0700517 exponent = exponent_base + exponentOffset;
518
519 _returnValue = glQueryMatrixxOES(
520 (GLfixed *)mantissa,
521 (GLint *)exponent
522 );
523
524exit:
525 if (exponent_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700526 _env->ReleaseIntArrayElements(exponent_ref, (jint*)exponent_base,
Jack Palevich27f80022009-04-15 19:13:17 -0700527 _exception ? JNI_ABORT: 0);
528 }
529 if (mantissa_base) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700530 _env->ReleaseIntArrayElements(mantissa_ref, (jint*)mantissa_base,
Jack Palevich27f80022009-04-15 19:13:17 -0700531 _exception ? JNI_ABORT: 0);
532 }
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700533 if (_exception) {
534 jniThrowException(_env, _exceptionType, _exceptionMessage);
535 }
Andy McFaddencee51982013-04-25 16:08:31 -0700536 return (jint)_returnValue;
Jack Palevich27f80022009-04-15 19:13:17 -0700537}
538
539/* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */
540static jint
541android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2
542 (JNIEnv *_env, jobject _this, jobject mantissa_buf, jobject exponent_buf) {
543 jint _exception = 0;
Mathias Agopian2ad04772013-02-23 03:12:30 -0800544 const char * _exceptionType = NULL;
545 const char * _exceptionMessage = NULL;
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700546 jintArray _mantissaArray = (jintArray) 0;
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700547 jint _mantissaBufferOffset = (jint) 0;
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700548 jintArray _exponentArray = (jintArray) 0;
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700549 jint _exponentBufferOffset = (jint) 0;
Jack Palevich27f80022009-04-15 19:13:17 -0700550 GLbitfield _returnValue = -1;
551 jint _mantissaRemaining;
552 GLfixed *mantissa = (GLfixed *) 0;
553 jint _exponentRemaining;
554 GLint *exponent = (GLint *) 0;
555
Romain Guy84cac202016-12-05 12:26:02 -0800556 if (!mantissa_buf) {
557 _exception = 1;
558 _exceptionType = "java/lang/IllegalArgumentException";
559 _exceptionMessage = "mantissa == null";
560 goto exit;
561 }
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700562 mantissa = (GLfixed *)getPointer(_env, mantissa_buf, (jarray*)&_mantissaArray, &_mantissaRemaining, &_mantissaBufferOffset);
Jack Palevich27f80022009-04-15 19:13:17 -0700563 if (_mantissaRemaining < 16) {
564 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700565 _exceptionType = "java/lang/IllegalArgumentException";
566 _exceptionMessage = "remaining() < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700567 goto exit;
568 }
Romain Guy84cac202016-12-05 12:26:02 -0800569 if (!exponent_buf) {
570 _exception = 1;
571 _exceptionType = "java/lang/IllegalArgumentException";
572 _exceptionMessage = "exponent == null";
573 goto exit;
574 }
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700575 exponent = (GLint *)getPointer(_env, exponent_buf, (jarray*)&_exponentArray, &_exponentRemaining, &_exponentBufferOffset);
Jack Palevich27f80022009-04-15 19:13:17 -0700576 if (_exponentRemaining < 16) {
577 _exception = 1;
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700578 _exceptionType = "java/lang/IllegalArgumentException";
579 _exceptionMessage = "remaining() < 16 < needed";
Jack Palevich27f80022009-04-15 19:13:17 -0700580 goto exit;
581 }
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700582 if (mantissa == NULL) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700583 char * _mantissaBase = (char *)_env->GetIntArrayElements(_mantissaArray, (jboolean *) 0);
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700584 mantissa = (GLfixed *) (_mantissaBase + _mantissaBufferOffset);
585 }
586 if (exponent == NULL) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700587 char * _exponentBase = (char *)_env->GetIntArrayElements(_exponentArray, (jboolean *) 0);
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700588 exponent = (GLint *) (_exponentBase + _exponentBufferOffset);
589 }
Jack Palevich27f80022009-04-15 19:13:17 -0700590 _returnValue = glQueryMatrixxOES(
591 (GLfixed *)mantissa,
592 (GLint *)exponent
593 );
594
595exit:
Jack Palevich27f80022009-04-15 19:13:17 -0700596 if (_exponentArray) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700597 _env->ReleaseIntArrayElements(_exponentArray, (jint*)exponent, _exception ? JNI_ABORT : 0);
Thomas Tafertshofer17045a12012-07-12 13:55:55 -0700598 }
599 if (_mantissaArray) {
Hiroshi Yamauchi3b1d46e2015-05-13 13:10:33 -0700600 _env->ReleaseIntArrayElements(_mantissaArray, (jint*)mantissa, _exception ? JNI_ABORT : 0);
Jack Palevich27f80022009-04-15 19:13:17 -0700601 }
Thomas Tafertshofer2545b322012-06-27 16:33:26 -0700602 if (_exception) {
603 jniThrowException(_env, _exceptionType, _exceptionMessage);
604 }
Andy McFaddencee51982013-04-25 16:08:31 -0700605 return (jint)_returnValue;
Jack Palevich27f80022009-04-15 19:13:17 -0700606}
607
608static const char *classPathName = "android/opengl/GLES10Ext";
609
Daniel Micay76f6a862015-09-19 17:31:01 -0400610static const JNINativeMethod methods[] = {
Jack Palevich27f80022009-04-15 19:13:17 -0700611{"_nativeClassInit", "()V", (void*)nativeClassInit },
612{"glQueryMatrixxOES", "([II[II)I", (void *) android_glQueryMatrixxOES___3II_3II },
613{"glQueryMatrixxOES", "(Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)I", (void *) android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 },
614};
615
616int register_android_opengl_jni_GLES10Ext(JNIEnv *_env)
617{
618 int err;
619 err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));
620 return err;
621}