1/* void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name ) */
2static void
3android_glGetTransformFeedbackVarying__III_3II_3II_3II_3BI
4  (JNIEnv *_env, jobject _this, jint program, jint index, jint bufsize, jintArray length_ref, jint lengthOffset, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset, jbyteArray name_ref, jint nameOffset) {
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    GLint *size_base = (GLint *) 0;
12    jint _sizeRemaining;
13    GLint *size = (GLint *) 0;
14    GLenum *type_base = (GLenum *) 0;
15    jint _typeRemaining;
16    GLenum *type = (GLenum *) 0;
17    char *name_base = (char *) 0;
18    jint _nameRemaining;
19    char *name = (char *) 0;
20
21    if (!length_ref) {
22        _exception = 1;
23        _exceptionType = "java/lang/IllegalArgumentException";
24        _exceptionMessage = "length == null";
25        goto exit;
26    }
27    if (lengthOffset < 0) {
28        _exception = 1;
29        _exceptionType = "java/lang/IllegalArgumentException";
30        _exceptionMessage = "lengthOffset < 0";
31        goto exit;
32    }
33    _lengthRemaining = _env->GetArrayLength(length_ref) - lengthOffset;
34    length_base = (GLsizei *)
35        _env->GetIntArrayElements(length_ref, (jboolean *)0);
36    length = length_base + lengthOffset;
37
38    if (!size_ref) {
39        _exception = 1;
40        _exceptionType = "java/lang/IllegalArgumentException";
41        _exceptionMessage = "size == null";
42        goto exit;
43    }
44    if (sizeOffset < 0) {
45        _exception = 1;
46        _exceptionType = "java/lang/IllegalArgumentException";
47        _exceptionMessage = "sizeOffset < 0";
48        goto exit;
49    }
50    _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset;
51    size_base = (GLint *)
52        _env->GetIntArrayElements(size_ref, (jboolean *)0);
53    size = size_base + sizeOffset;
54
55    if (!type_ref) {
56        _exception = 1;
57        _exceptionType = "java/lang/IllegalArgumentException";
58        _exceptionMessage = "type == null";
59        goto exit;
60    }
61    if (typeOffset < 0) {
62        _exception = 1;
63        _exceptionType = "java/lang/IllegalArgumentException";
64        _exceptionMessage = "typeOffset < 0";
65        goto exit;
66    }
67    _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset;
68    type_base = (GLenum *)
69        _env->GetIntArrayElements(type_ref, (jboolean *)0);
70    type = type_base + typeOffset;
71
72    if (!name_ref) {
73        _exception = 1;
74        _exceptionType = "java/lang/IllegalArgumentException";
75        _exceptionMessage = "name == null";
76        goto exit;
77    }
78    if (nameOffset < 0) {
79        _exception = 1;
80        _exceptionType = "java/lang/IllegalArgumentException";
81        _exceptionMessage = "nameOffset < 0";
82        goto exit;
83    }
84    _nameRemaining = _env->GetArrayLength(name_ref) - nameOffset;
85    name_base = (char *)
86        _env->GetByteArrayElements(name_ref, (jboolean *)0);
87    name = name_base + nameOffset;
88
89    glGetTransformFeedbackVarying(
90        (GLuint)program,
91        (GLuint)index,
92        (GLsizei)bufsize,
93        (GLsizei *)length,
94        (GLint *)size,
95        (GLenum *)type,
96        (char *)name
97    );
98
99exit:
100    if (name_base) {
101        _env->ReleaseByteArrayElements(name_ref, (jbyte*)name_base,
102            _exception ? JNI_ABORT: 0);
103    }
104    if (type_base) {
105        _env->ReleaseIntArrayElements(type_ref, (jint*)type_base,
106            _exception ? JNI_ABORT: 0);
107    }
108    if (size_base) {
109        _env->ReleaseIntArrayElements(size_ref, (jint*)size_base,
110            _exception ? JNI_ABORT: 0);
111    }
112    if (length_base) {
113        _env->ReleaseIntArrayElements(length_ref, (jint*)length_base,
114            _exception ? JNI_ABORT: 0);
115    }
116    if (_exception) {
117        jniThrowException(_env, _exceptionType, _exceptionMessage);
118    }
119}
120
121/* void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name ) */
122static void
123android_glGetTransformFeedbackVarying__IIILjava_nio_IntBuffer_2Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2B
124  (JNIEnv *_env, jobject _this, jint program, jint index, jint bufsize, jobject length_buf, jobject size_buf, jobject type_buf, jbyte name) {
125    jintArray _lengthArray = (jintArray) 0;
126    jint _lengthBufferOffset = (jint) 0;
127    jintArray _sizeArray = (jintArray) 0;
128    jint _sizeBufferOffset = (jint) 0;
129    jintArray _typeArray = (jintArray) 0;
130    jint _typeBufferOffset = (jint) 0;
131    jint _lengthRemaining;
132    GLsizei *length = (GLsizei *) 0;
133    jint _sizeRemaining;
134    GLint *size = (GLint *) 0;
135    jint _typeRemaining;
136    GLenum *type = (GLenum *) 0;
137
138    length = (GLsizei *)getPointer(_env, length_buf, (jarray*)&_lengthArray, &_lengthRemaining, &_lengthBufferOffset);
139    size = (GLint *)getPointer(_env, size_buf, (jarray*)&_sizeArray, &_sizeRemaining, &_sizeBufferOffset);
140    type = (GLenum *)getPointer(_env, type_buf, (jarray*)&_typeArray, &_typeRemaining, &_typeBufferOffset);
141    if (length == NULL) {
142        char * _lengthBase = (char *)_env->GetIntArrayElements(_lengthArray, (jboolean *) 0);
143        length = (GLsizei *) (_lengthBase + _lengthBufferOffset);
144    }
145    if (size == NULL) {
146        char * _sizeBase = (char *)_env->GetIntArrayElements(_sizeArray, (jboolean *) 0);
147        size = (GLint *) (_sizeBase + _sizeBufferOffset);
148    }
149    if (type == NULL) {
150        char * _typeBase = (char *)_env->GetIntArrayElements(_typeArray, (jboolean *) 0);
151        type = (GLenum *) (_typeBase + _typeBufferOffset);
152    }
153    glGetTransformFeedbackVarying(
154        (GLuint)program,
155        (GLuint)index,
156        (GLsizei)bufsize,
157        (GLsizei *)length,
158        (GLint *)size,
159        (GLenum *)type,
160        // The cast below is incorrect. The driver will end up writing to the
161        // address specified by name, which will always crash the process since
162        // it is guaranteed to be in low memory. The additional static_cast
163        // suppresses the warning for now. http://b/19478262
164        (char *)static_cast<uintptr_t>(name)
165    );
166    if (_typeArray) {
167        releaseArrayPointer<jintArray, jint*, IntArrayReleaser>(_env, _typeArray, (jint*)type, JNI_TRUE);
168    }
169    if (_sizeArray) {
170        releaseArrayPointer<jintArray, jint*, IntArrayReleaser>(_env, _sizeArray, (jint*)size, JNI_TRUE);
171    }
172    if (_lengthArray) {
173        releaseArrayPointer<jintArray, jint*, IntArrayReleaser>(_env, _lengthArray, (jint*)length, JNI_TRUE);
174    }
175}
176
177/* void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name ) */
178static jstring
179android_glGetTransformFeedbackVarying1
180  (JNIEnv *_env, jobject _this, jint program, jint index, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset) {
181    jint _exception = 0;
182    const char * _exceptionType;
183    const char * _exceptionMessage;
184    GLint *size_base = (GLint *) 0;
185    jint _sizeRemaining;
186    GLint *size = (GLint *) 0;
187    GLenum *type_base = (GLenum *) 0;
188    jint _typeRemaining;
189    GLenum *type = (GLenum *) 0;
190
191    jstring result = 0;
192
193    GLint len = 0;
194    glGetProgramiv((GLuint)program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len);
195    if (!len) {
196        return _env->NewStringUTF("");
197    }
198    char* buf = (char*) malloc(len);
199
200    if (buf == NULL) {
201        jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory");
202        return NULL;
203    }
204    if (!size_ref) {
205        _exception = 1;
206        _exceptionType = "java/lang/IllegalArgumentException";
207        _exceptionMessage = "size == null";
208        goto exit;
209    }
210    if (sizeOffset < 0) {
211        _exception = 1;
212        _exceptionType = "java/lang/IllegalArgumentException";
213        _exceptionMessage = "sizeOffset < 0";
214        goto exit;
215    }
216    _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset;
217    size_base = (GLint *)
218        _env->GetIntArrayElements(size_ref, (jboolean *)0);
219    size = size_base + sizeOffset;
220
221    if (!type_ref) {
222        _exception = 1;
223        _exceptionType = "java/lang/IllegalArgumentException";
224        _exceptionMessage = "type == null";
225        goto exit;
226    }
227    if (typeOffset < 0) {
228        _exception = 1;
229        _exceptionType = "java/lang/IllegalArgumentException";
230        _exceptionMessage = "typeOffset < 0";
231        goto exit;
232    }
233    _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset;
234    type_base = (GLenum *)
235        _env->GetIntArrayElements(type_ref, (jboolean *)0);
236    type = type_base + typeOffset;
237
238    glGetTransformFeedbackVarying(
239        (GLuint)program,
240        (GLuint)index,
241        (GLsizei)len,
242        NULL,
243        (GLint *)size,
244        (GLenum *)type,
245        (char *)buf
246    );
247exit:
248    if (type_base) {
249        _env->ReleaseIntArrayElements(type_ref, (jint*)type_base,
250            _exception ? JNI_ABORT: 0);
251    }
252    if (size_base) {
253        _env->ReleaseIntArrayElements(size_ref, (jint*)size_base,
254            _exception ? JNI_ABORT: 0);
255    }
256    if (_exception != 1) {
257        result = _env->NewStringUTF(buf);
258    }
259    if (buf) {
260        free(buf);
261    }
262    if (_exception) {
263        jniThrowException(_env, _exceptionType, _exceptionMessage);
264    }
265    if (result == 0) {
266        result = _env->NewStringUTF("");
267    }
268
269    return result;
270}
271
272/* void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name ) */
273static jstring
274android_glGetTransformFeedbackVarying2
275  (JNIEnv *_env, jobject _this, jint program, jint index, jobject size_buf, jobject type_buf) {
276    jintArray _sizeArray = (jintArray) 0;
277    jint _sizeBufferOffset = (jint) 0;
278    jintArray _typeArray = (jintArray) 0;
279    jint _typeBufferOffset = (jint) 0;
280    jint _lengthRemaining;
281    GLsizei *length = (GLsizei *) 0;
282    jint _sizeRemaining;
283    GLint *size = (GLint *) 0;
284    jint _typeRemaining;
285    GLenum *type = (GLenum *) 0;
286
287    jstring result = 0;
288
289    GLint len = 0;
290    glGetProgramiv((GLuint)program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len);
291    if (!len) {
292        return _env->NewStringUTF("");
293    }
294    char* buf = (char*) malloc(len);
295
296    if (buf == NULL) {
297        jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory");
298        return NULL;
299    }
300
301    size = (GLint *)getPointer(_env, size_buf, (jarray*)&_sizeArray, &_sizeRemaining, &_sizeBufferOffset);
302    type = (GLenum *)getPointer(_env, type_buf, (jarray*)&_typeArray, &_typeRemaining, &_typeBufferOffset);
303    if (size == NULL) {
304        char * _sizeBase = (char *)_env->GetIntArrayElements(_sizeArray, (jboolean *) 0);
305        size = (GLint *) (_sizeBase + _sizeBufferOffset);
306    }
307    if (type == NULL) {
308        char * _typeBase = (char *)_env->GetIntArrayElements(_typeArray, (jboolean *) 0);
309        type = (GLenum *) (_typeBase + _typeBufferOffset);
310    }
311    glGetTransformFeedbackVarying(
312        (GLuint)program,
313        (GLuint)index,
314        (GLsizei)len,
315        NULL,
316        (GLint *)size,
317        (GLenum *)type,
318        (char *)buf
319    );
320
321    if (_typeArray) {
322        releaseArrayPointer<jintArray, jint*, IntArrayReleaser>(_env, _typeArray, (jint*)type, JNI_TRUE);
323    }
324    if (_sizeArray) {
325        releaseArrayPointer<jintArray, jint*, IntArrayReleaser>(_env, _sizeArray, (jint*)size, JNI_TRUE);
326    }
327    result = _env->NewStringUTF(buf);
328    if (buf) {
329        free(buf);
330    }
331    return result;
332}
333