1/* void glGetUniformIndices ( GLuint program, GLsizei uniformCount, const GLchar *const *uniformNames, GLuint *uniformIndices ) */
2static
3void
4android_glGetUniformIndices_array
5    (JNIEnv *_env, jobject _this, jint program, jobjectArray uniformNames_ref, jintArray uniformIndices_ref, jint uniformIndicesOffset) {
6    jint _exception = 0;
7    const char* _exceptionType = NULL;
8    const char* _exceptionMessage = NULL;
9    jint _count = 0;
10    jint _i;
11    const char** _names = NULL;
12    GLuint* _indices_base = NULL;
13    GLuint* _indices = NULL;
14
15    if (!uniformNames_ref) {
16        _exception = 1;
17        _exceptionType = "java/lang/IllegalArgumentException";
18        _exceptionMessage = "uniformNames == null";
19        goto exit;
20    }
21    _count = _env->GetArrayLength(uniformNames_ref);
22    _names = (const char**)calloc(_count, sizeof(const char*));
23    for (_i = 0; _i < _count; _i++) {
24        jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
25        if (!_name) {
26            _exception = 1;
27            _exceptionType = "java/lang/IllegalArgumentException";
28            _exceptionMessage = "null uniformNames element";
29            goto exit;
30        }
31        _names[_i] = _env->GetStringUTFChars(_name, 0);
32    }
33
34    if (!uniformIndices_ref) {
35        _exception = 1;
36        _exceptionType = "java/lang/IllegalArgumentException";
37        _exceptionMessage = "uniformIndices == null";
38        goto exit;
39    }
40    if (uniformIndicesOffset < 0) {
41        _exception = 1;
42        _exceptionType = "java/lang/IllegalArgumentException";
43        _exceptionMessage = "uniformIndicesOffset < 0";
44        goto exit;
45    }
46    if (_env->GetArrayLength(uniformIndices_ref) - uniformIndicesOffset < _count) {
47        _exception = 1;
48        _exceptionType = "java/lang/IllegalArgumentException";
49        _exceptionMessage = "not enough space in uniformIndices";
50        goto exit;
51    }
52    _indices_base = (GLuint*)_env->GetIntArrayElements(
53            uniformIndices_ref, 0);
54    _indices = _indices_base + uniformIndicesOffset;
55
56    glGetUniformIndices(program, _count, _names, _indices);
57
58exit:
59    if (_indices_base) {
60        _env->ReleaseIntArrayElements(uniformIndices_ref, (jint*)_indices_base,
61            _exception ? JNI_ABORT : 0);
62    }
63    for (_i = _count - 1; _i >= 0; _i--) {
64        if (_names[_i]) {
65            jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
66            if (_name) {
67                _env->ReleaseStringUTFChars(_name, _names[_i]);
68            }
69        }
70    }
71    free(_names);
72    if (_exception) {
73        jniThrowException(_env, _exceptionType, _exceptionMessage);
74    }
75}
76
77/* void glGetUniformIndices ( GLuint program, GLsizei uniformCount, const GLchar *const *uniformNames, GLuint *uniformIndices ) */
78static
79void
80android_glGetUniformIndices_buffer
81    (JNIEnv *_env, jobject _this, jint program, jobjectArray uniformNames_ref, jobject uniformIndices_buf) {
82    jint _exception = 0;
83    const char* _exceptionType = NULL;
84    const char* _exceptionMessage = NULL;
85    jint _count = 0;
86    jint _i;
87    const char** _names = NULL;
88    jintArray _uniformIndicesArray = (jintArray)0;
89    jint _uniformIndicesRemaining;
90    jint _uniformIndicesOffset = 0;
91    GLuint* _indices = NULL;
92    char* _indicesBase = NULL;
93
94    if (!uniformNames_ref) {
95        _exception = 1;
96        _exceptionType = "java/lang/IllegalArgumentException";
97        _exceptionMessage = "uniformNames == null";
98        goto exit;
99    }
100    if (!uniformIndices_buf) {
101        _exception = 1;
102        _exceptionType = "java/lang/IllegalArgumentException";
103        _exceptionMessage = "uniformIndices == null";
104        goto exit;
105    }
106
107    _count = _env->GetArrayLength(uniformNames_ref);
108    _names = (const char**)calloc(_count, sizeof(const char*));
109    for (_i = 0; _i < _count; _i++) {
110        jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
111        if (!_name) {
112            _exception = 1;
113            _exceptionType = "java/lang/IllegalArgumentException";
114            _exceptionMessage = "null uniformNames element";
115            goto exit;
116        }
117        _names[_i] = _env->GetStringUTFChars(_name, 0);
118    }
119
120    _indices = (GLuint*)getPointer(_env, uniformIndices_buf,
121            (jarray*)&_uniformIndicesArray, &_uniformIndicesRemaining,
122            &_uniformIndicesOffset);
123    if (!_indices) {
124        _indicesBase = (char*)_env->GetIntArrayElements(
125            _uniformIndicesArray, 0);
126        _indices = (GLuint*)(_indicesBase + _uniformIndicesOffset);
127    }
128    if (_uniformIndicesRemaining < _count) {
129        _exception = 1;
130        _exceptionType = "java/lang/IllegalArgumentException";
131        _exceptionMessage = "not enough space in uniformIndices";
132        goto exit;
133    }
134
135    glGetUniformIndices(program, _count, _names, _indices);
136
137exit:
138    if (_uniformIndicesArray) {
139        releaseArrayPointer<jintArray, jint*, IntArrayReleaser>(
140            _env, _uniformIndicesArray, (jint*)_indicesBase, JNI_TRUE);
141    }
142    for (_i = _count - 1; _i >= 0; _i--) {
143        if (_names[_i]) {
144            jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
145            if (_name) {
146                _env->ReleaseStringUTFChars(_name, _names[_i]);
147            }
148        }
149    }
150    free(_names);
151    if (_exception) {
152        jniThrowException(_env, _exceptionType, _exceptionMessage);
153    }
154}
155