1 /* void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) */
2 static void
android_glGetShaderSource__II_3II_3BI(JNIEnv * _env,jobject _this,jint shader,jint bufsize,jintArray length_ref,jint lengthOffset,jbyteArray source_ref,jint sourceOffset)3 android_glGetShaderSource__II_3II_3BI
4   (JNIEnv *_env, jobject _this, jint shader, jint bufsize, jintArray length_ref, jint lengthOffset, jbyteArray source_ref, jint sourceOffset) {
5     jint _exception = 0;
6     const char * _exceptionType;
7     const char * _exceptionMessage;
8     GLsizei *length_base = (GLsizei *) 0;
9     jint _lengthRemaining;
10     GLsizei *length = (GLsizei *) 0;
11     char *source_base = (char *) 0;
12     jint _sourceRemaining;
13     char *source = (char *) 0;
14 
15     if (length_ref) {
16         if (lengthOffset < 0) {
17             _exception = 1;
18             _exceptionType = "java/lang/IllegalArgumentException";
19             _exceptionMessage = "lengthOffset < 0";
20             goto exit;
21         }
22         _lengthRemaining = _env->GetArrayLength(length_ref) - lengthOffset;
23         length_base = (GLsizei *)
24             _env->GetIntArrayElements(length_ref, (jboolean *)0);
25         length = length_base + lengthOffset;
26     }
27 
28     if (!source_ref) {
29         _exception = 1;
30         _exceptionType = "java/lang/IllegalArgumentException";
31         _exceptionMessage = "source == null";
32         goto exit;
33     }
34     if (sourceOffset < 0) {
35         _exception = 1;
36         _exceptionType = "java/lang/IllegalArgumentException";
37         _exceptionMessage = "sourceOffset < 0";
38         goto exit;
39     }
40     _sourceRemaining = _env->GetArrayLength(source_ref) - sourceOffset;
41     source_base = (char *)
42         _env->GetByteArrayElements(source_ref, (jboolean *)0);
43     source = source_base + sourceOffset;
44 
45     glGetShaderSource(
46         (GLuint)shader,
47         (GLsizei)bufsize,
48         (GLsizei *)length,
49         (char *)source
50     );
51 
52 exit:
53     if (source_base) {
54         _env->ReleaseByteArrayElements(source_ref, (jbyte*)source_base,
55             _exception ? JNI_ABORT: 0);
56     }
57     if (length_base) {
58         _env->ReleaseIntArrayElements(length_ref, (jint*)length_base,
59             _exception ? JNI_ABORT: 0);
60     }
61     if (_exception) {
62         jniThrowException(_env, _exceptionType, _exceptionMessage);
63     }
64 }
65 
66 /* void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) */
67 static void
android_glGetShaderSource__IILjava_nio_IntBuffer_2B(JNIEnv * _env,jobject _this,jint shader,jint bufsize,jobject length_buf,jbyte source)68 android_glGetShaderSource__IILjava_nio_IntBuffer_2B
69   (JNIEnv *_env, jobject _this, jint shader, jint bufsize, jobject length_buf, jbyte source) {
70     jintArray _array = (jintArray) 0;
71     jint _bufferOffset = (jint) 0;
72     jint _remaining;
73     GLsizei *length = (GLsizei *) 0;
74 
75     length = (GLsizei *)getPointer(_env, length_buf, (jarray*)&_array, &_remaining, &_bufferOffset);
76     if (length == NULL) {
77         char * _lengthBase = (char *)_env->GetIntArrayElements(_array, (jboolean *) 0);
78         length = (GLsizei *) (_lengthBase + _bufferOffset);
79     }
80     glGetShaderSource(
81         (GLuint)shader,
82         (GLsizei)bufsize,
83         (GLsizei *)length,
84         reinterpret_cast<char *>(source)
85     );
86     if (_array) {
87         releaseArrayPointer<jintArray, jint*, IntArrayReleaser>(_env, _array, (jint*)length, JNI_TRUE);
88     }
89 }
90 
91 /* void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) */
android_glGetShaderSource(JNIEnv * _env,jobject,jint shader)92 static jstring android_glGetShaderSource(JNIEnv *_env, jobject, jint shader) {
93     GLint shaderLen = 0;
94     glGetShaderiv((GLuint)shader, GL_SHADER_SOURCE_LENGTH, &shaderLen);
95     if (!shaderLen) {
96         return _env->NewStringUTF("");
97     }
98     char* buf = (char*) malloc(shaderLen);
99     if (buf == NULL) {
100         jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory");
101         return NULL;
102     }
103     glGetShaderSource(shader, shaderLen, NULL, buf);
104     jstring result = _env->NewStringUTF(buf);
105     free(buf);
106     return result;
107 }
108