116f03928743b01638419874e2b6300b52da6eb4cJesse Hall/* GLuint glCreateShaderProgramv ( GLenum type, GLsizei count, const GLchar *const *strings ) */
216f03928743b01638419874e2b6300b52da6eb4cJesse Hallstatic jint
316f03928743b01638419874e2b6300b52da6eb4cJesse Hallandroid_glCreateShaderProgramv
416f03928743b01638419874e2b6300b52da6eb4cJesse Hall  (JNIEnv *_env, jobject _this, jint type, jobjectArray strings) {
5eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    jint _exception = 0;
6eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    const char * _exceptionType = NULL;
7eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    const char * _exceptionMessage = NULL;
8eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    GLsizei _count;
9eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    const GLchar** _strings = NULL;
10eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    jstring* _jstrings = NULL;
11eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    GLuint _returnValue = 0;
1216f03928743b01638419874e2b6300b52da6eb4cJesse Hall
13eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    if (!strings) {
14eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _exception = 1;
15eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _exceptionType = "java/lang/IllegalArgumentException";
16eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _exceptionMessage = "strings == null";
17eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        goto exit;
18eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    }
19eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos
20eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    _count = _env->GetArrayLength(strings);
21eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos
22eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    _strings = (const GLchar**) calloc(_count, sizeof(const GLchar*));
23eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    if (!_strings) {
24eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _exception = 1;
25eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _exceptionType = "java/lang/OutOfMemoryError";
26eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _exceptionMessage = "out of memory";
27eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        goto exit;
28eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    }
29eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos
30eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    _jstrings = (jstring*) calloc(_count, sizeof(jstring));
31eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    if (!_jstrings) {
32eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _exception = 1;
33eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _exceptionType = "java/lang/OutOfMemoryError";
34eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _exceptionMessage = "out of memory";
35eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        goto exit;
36eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    }
37eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos
38eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    for(int i = 0; i < _count; i++) {
39eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _jstrings[i] = (jstring) _env->GetObjectArrayElement(strings, i);
40eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        if (!_jstrings[i]) {
41eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos            _exception = 1;
42eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos            _exceptionType = "java/lang/IllegalArgumentException";
43eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos            _exceptionMessage = "strings == null";
44eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos            goto exit;
45eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        }
46eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        _strings[i] = _env->GetStringUTFChars(_jstrings[i], 0);
47eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    }
48eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos
49eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    _returnValue = glCreateShaderProgramv((GLenum)type, _count, _strings);
50eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballosexit:
51eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    if (_strings && _jstrings) {
52eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        for(int i = 0; i < _count; i++) {
53eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos            if (_strings[i] && _jstrings[i]) {
54eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos                _env->ReleaseStringUTFChars(_jstrings[i], _strings[i]);
55eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos            }
56eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        }
57eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    }
58eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    if (_strings) {
59eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        free(_strings);
60eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    }
61eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    if (_jstrings) {
62eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        free(_jstrings);
63eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    }
64eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    if (_exception) {
65eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos        jniThrowException(_env, _exceptionType, _exceptionMessage);
66eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    }
67eec5db2bedbceae5d94083c5487446995a4f3468Pablo Ceballos    return (jint)_returnValue;
6816f03928743b01638419874e2b6300b52da6eb4cJesse Hall}
69