summaryrefslogtreecommitdiffstats
path: root/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.cpp
blob: 13ef01e290bfec25ec4a99c4d82538d94c4678a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* void glGetUniformIndices ( GLuint program, GLsizei uniformCount, const GLchar *const *uniformNames, GLuint *uniformIndices ) */
static
void
android_glGetUniformIndices_array
    (JNIEnv *_env, jobject _this, jint program, jobjectArray uniformNames_ref, jintArray uniformIndices_ref, jint uniformIndicesOffset) {
    jint _exception = 0;
    const char* _exceptionType = NULL;
    const char* _exceptionMessage = NULL;
    jint _count = 0;
    jint _i;
    const char** _names = NULL;
    GLuint* _indices_base = NULL;
    GLuint* _indices = NULL;

    if (!uniformNames_ref) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "uniformNames == null";
        goto exit;
    }
    _count = _env->GetArrayLength(uniformNames_ref);
    _names = (const char**)calloc(_count, sizeof(const char*));
    for (_i = 0; _i < _count; _i++) {
        jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
        if (!_name) {
            _exception = 1;
            _exceptionType = "java/lang/IllegalArgumentException";
            _exceptionMessage = "null uniformNames element";
            goto exit;
        }
        _names[_i] = _env->GetStringUTFChars(_name, 0);
    }

    if (!uniformIndices_ref) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "uniformIndices == null";
        goto exit;
    }
    if (uniformIndicesOffset < 0) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "uniformIndicesOffset < 0";
        goto exit;
    }
    if (_env->GetArrayLength(uniformIndices_ref) - uniformIndicesOffset < _count) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "not enough space in uniformIndices";
        goto exit;
    }
    _indices_base = (GLuint*)_env->GetIntArrayElements(
            uniformIndices_ref, 0);
    _indices = _indices_base + uniformIndicesOffset;

    glGetUniformIndices(program, _count, _names, _indices);

exit:
    if (_indices_base) {
        _env->ReleaseIntArrayElements(uniformIndices_ref, (jint*)_indices_base,
            _exception ? JNI_ABORT : 0);
    }
    for (_i = _count - 1; _i >= 0; _i--) {
        if (_names[_i]) {
            jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
            if (_name) {
                _env->ReleaseStringUTFChars(_name, _names[_i]);
            }
        }
    }
    free(_names);
    if (_exception) {
        jniThrowException(_env, _exceptionType, _exceptionMessage);
    }
}

/* void glGetUniformIndices ( GLuint program, GLsizei uniformCount, const GLchar *const *uniformNames, GLuint *uniformIndices ) */
static
void
android_glGetUniformIndices_buffer
    (JNIEnv *_env, jobject _this, jint program, jobjectArray uniformNames_ref, jobject uniformIndices_buf) {
    jint _exception = 0;
    const char* _exceptionType = NULL;
    const char* _exceptionMessage = NULL;
    jint _count = 0;
    jint _i;
    const char** _names = NULL;
    jintArray _uniformIndicesArray = (jintArray)0;
    jint _uniformIndicesRemaining;
    jint _uniformIndicesOffset = 0;
    GLuint* _indices = NULL;
    char* _indicesBase = NULL;

    if (!uniformNames_ref) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "uniformNames == null";
        goto exit;
    }
    if (!uniformIndices_buf) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "uniformIndices == null";
        goto exit;
    }

    _count = _env->GetArrayLength(uniformNames_ref);
    _names = (const char**)calloc(_count, sizeof(const char*));
    for (_i = 0; _i < _count; _i++) {
        jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
        if (!_name) {
            _exception = 1;
            _exceptionType = "java/lang/IllegalArgumentException";
            _exceptionMessage = "null uniformNames element";
            goto exit;
        }
        _names[_i] = _env->GetStringUTFChars(_name, 0);
    }

    _indices = (GLuint*)getPointer(_env, uniformIndices_buf,
            (jarray*)&_uniformIndicesArray, &_uniformIndicesRemaining,
            &_uniformIndicesOffset);
    if (!_indices) {
        _indicesBase = (char*)_env->GetIntArrayElements(
            _uniformIndicesArray, 0);
        _indices = (GLuint*)(_indicesBase + _uniformIndicesOffset);
    }
    if (_uniformIndicesRemaining < _count) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "not enough space in uniformIndices";
        goto exit;
    }

    glGetUniformIndices(program, _count, _names, _indices);

exit:
    if (_uniformIndicesArray) {
        releaseArrayPointer<jintArray, jint*, IntArrayReleaser>(
            _env, _uniformIndicesArray, (jint*)_indicesBase, JNI_TRUE);
    }
    for (_i = _count - 1; _i >= 0; _i--) {
        if (_names[_i]) {
            jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
            if (_name) {
                _env->ReleaseStringUTFChars(_name, _names[_i]);
            }
        }
    }
    free(_names);
    if (_exception) {
        jniThrowException(_env, _exceptionType, _exceptionMessage);
    }
}