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