summaryrefslogtreecommitdiff
path: root/GLESv2/yagl_gles2_program.h
blob: 50880133bd0bcb35d109c9c21ad2f492c09407c2 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/*
 * YaGL
 *
 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact :
 * Stanislav Vorobiov <s.vorobiov@samsung.com>
 * Jinhyung Jo <jinhyung.jo@samsung.com>
 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Contributors:
 * - S-Core Co., Ltd
 *
 */

#ifndef _YAGL_GLES2_PROGRAM_H_
#define _YAGL_GLES2_PROGRAM_H_

#include "yagl_types.h"
#include "yagl_object.h"
#include "yagl_list.h"
#include "yagl_vector.h"

struct yagl_gles2_shader;

struct yagl_gles2_location_l
{
    struct yagl_list list;

    int location;

    GLchar *name;
};

struct yagl_gles2_attrib_variable
{
    int fetched;

    GLchar *name;

    GLint name_size;

    GLenum type;
    GLint size;
};

struct yagl_gles2_uniform_variable
{
    int name_fetched;
    int generic_fetched;
    int extended_fetched;

    /*
     * Common parameters, present when
     * 'name_fetched', 'generic_fetched' or 'extended_fetched' is true.
     * @{
     */
    GLint name_size;
    /*
     * @}
     */

    /*
     * Common parameters, present when
     * 'generic_fetched' or 'extended_fetched' is true.
     * @{
     */
    GLenum type;
    GLint size;
    /*
     * @}
     */

    /*
     * 'name_fetched' or 'generic_fetched'.
     * @{
     */
    GLchar *name;
    /*
     * @}
     */

    /*
     * 'extended_fetched'.
     * @{
     */
    GLint block_index;
    GLint block_offset;
    GLint array_stride;
    GLint matrix_stride;
    GLint is_row_major;
    /*
     * @}
     */
};

struct yagl_gles2_uniform_block
{
    int name_fetched;
    int params_fetched;

    GLuint binding;

    /*
     * Present when 'name_fetched' or 'params_fetched' is true.
     * @{
     */
    GLint name_size;
    /*
     * @}
     */

    /*
     * 'name_fetched'.
     * @{
     */
    GLchar *name;
    /*
     * @}
     */

    /*
     * 'params_fetched'.
     * @{
     */
    GLuint num_active_uniform_indices;
    GLint data_size;
    GLint referenced_by_vertex_shader;
    GLint referenced_by_fragment_shader;
    /*
     * @}
     */

    GLuint *active_uniform_indices;
};

struct yagl_gles2_transform_feedback_varying
{
    /*
     * Valid when struct yagl_gles2_transform_feedback_info::fetched is true.
     * @{
     */

    /*
     * These will be set on link and
     * updated on fetch.
     * @{
     */
    GLchar *name;
    GLint name_size;
    /*
     * @}
     */

    GLenum type;
    GLint size;

    /*
     * @}
     */
};

struct yagl_gles2_transform_feedback_info
{
    int fetched;

    struct yagl_gles2_transform_feedback_varying *varyings;
    GLuint num_varyings;
    GLenum buffer_mode;
    GLint max_varying_bufsize;
};

struct yagl_gles2_program_sampler_info
{
    int fetched;

    int have_samplerexternaloes;
    struct yagl_vector samplers_ExternalOES;
    struct yagl_vector samplers_2D;
};

struct yagl_gles2_program
{
    /*
     * These members must be exactly as in yagl_gles2_shader
     * @{
     */
    struct yagl_object base;

    int is_shader;
    /*
     * @}
     */

    /*
     * Generate uniform locations ourselves or vmexit
     * and ask host.
     */
    int gen_locations;

    yagl_object_name global_name;

    struct yagl_gles2_shader *vertex_shader;

    struct yagl_gles2_shader *fragment_shader;

    struct yagl_gles2_program_sampler_info vertex_shader_sampler_info;

    struct yagl_gles2_program_sampler_info fragment_shader_sampler_info;

    union
    {
        struct yagl_list uniform_locations_l;
        struct yagl_vector uniform_locations_v;
    };

    struct yagl_list attrib_locations;

    struct yagl_list frag_data_locations;

    struct yagl_gles2_attrib_variable *active_attribs;
    GLuint num_active_attribs;
    GLint max_active_attrib_bufsize;

    struct yagl_gles2_uniform_variable *active_uniforms;
    GLuint num_active_uniforms;
    GLint max_active_uniform_bufsize;

    struct yagl_gles2_uniform_block *active_uniform_blocks;
    GLuint num_active_uniform_blocks;
    GLint max_active_uniform_block_bufsize;

    /*
     * Transform feedback info specified via glTransformFeedbackVaryings.
     */
    struct yagl_gles2_transform_feedback_info transform_feedback_info;

    /*
     * Actual transform feedback info after program link.
     */
    struct yagl_gles2_transform_feedback_info linked_transform_feedback_info;

    int linked;

    GLint link_status;
    GLint info_log_length;
};

int yagl_gles2_program_translate_location(struct yagl_gles2_program *program,
                                          GLint location,
                                          uint32_t *global_location);

void yagl_gles2_transform_feedback_info_reset(
    struct yagl_gles2_transform_feedback_info *transform_feedback_info);

struct yagl_gles2_program *yagl_gles2_program_create(int gen_locations);

int yagl_gles2_program_attach_shader(struct yagl_gles2_program *program,
                                     struct yagl_gles2_shader *shader);

int yagl_gles2_program_detach_shader(struct yagl_gles2_program *program,
                                     struct yagl_gles2_shader *shader);

void yagl_gles2_program_link(struct yagl_gles2_program *program);

int yagl_gles2_program_get_uniform_location(struct yagl_gles2_program *program,
                                            const GLchar *name);

int yagl_gles2_program_get_attrib_location(struct yagl_gles2_program *program,
                                           const GLchar *name);

void yagl_gles2_program_get_active_uniform(struct yagl_gles2_program *program,
                                           GLuint index,
                                           GLsizei bufsize,
                                           GLsizei *length,
                                           GLint *size,
                                           GLenum *type,
                                           GLchar *name);

void yagl_gles2_program_get_active_attrib(struct yagl_gles2_program *program,
                                          GLuint index,
                                          GLsizei bufsize,
                                          GLsizei *length,
                                          GLint *size,
                                          GLenum *type,
                                          GLchar *name);

int yagl_gles2_program_get_uniformfv(struct yagl_gles2_program *program,
                                     GLint location,
                                     GLfloat *params);

int yagl_gles2_program_get_uniformiv(struct yagl_gles2_program *program,
                                     GLint location,
                                     GLint *params);

int yagl_gles2_program_uniform1f(struct yagl_gles2_program *program,
                                 GLint location,
                                 GLfloat x);

int yagl_gles2_program_uniform1fv(struct yagl_gles2_program *program,
                                  GLint location,
                                  GLsizei count,
                                  const GLfloat *v);

int yagl_gles2_program_uniform1i(struct yagl_gles2_program *program,
                                 GLint location,
                                 GLint x);

int yagl_gles2_program_uniform1iv(struct yagl_gles2_program *program,
                                  GLint location,
                                  GLsizei count,
                                  const GLint *v);

int yagl_gles2_program_uniform2f(struct yagl_gles2_program *program,
                                 GLint location,
                                 GLfloat x,
                                 GLfloat y);

int yagl_gles2_program_uniform2fv(struct yagl_gles2_program *program,
                                  GLint location,
                                  GLsizei count,
                                  const GLfloat *v);

int yagl_gles2_program_uniform2i(struct yagl_gles2_program *program,
                                 GLint location,
                                 GLint x,
                                 GLint y);

int yagl_gles2_program_uniform2iv(struct yagl_gles2_program *program,
                                  GLint location,
                                  GLsizei count,
                                  const GLint *v);

int yagl_gles2_program_uniform3f(struct yagl_gles2_program *program,
                                 GLint location,
                                 GLfloat x,
                                 GLfloat y,
                                 GLfloat z);

int yagl_gles2_program_uniform3fv(struct yagl_gles2_program *program,
                                  GLint location,
                                  GLsizei count,
                                  const GLfloat *v);

int yagl_gles2_program_uniform3i(struct yagl_gles2_program *program,
                                 GLint location,
                                 GLint x,
                                 GLint y,
                                 GLint z);

int yagl_gles2_program_uniform3iv(struct yagl_gles2_program *program,
                                  GLint location,
                                  GLsizei count,
                                  const GLint *v);

int yagl_gles2_program_uniform4f(struct yagl_gles2_program *program,
                                 GLint location,
                                 GLfloat x,
                                 GLfloat y,
                                 GLfloat z,
                                 GLfloat w);

int yagl_gles2_program_uniform4fv(struct yagl_gles2_program *program,
                                  GLint location,
                                  GLsizei count,
                                  const GLfloat *v);

int yagl_gles2_program_uniform4i(struct yagl_gles2_program *program,
                                 GLint location,
                                 GLint x,
                                 GLint y,
                                 GLint z,
                                 GLint w);

int yagl_gles2_program_uniform4iv(struct yagl_gles2_program *program,
                                  GLint location,
                                  GLsizei count,
                                  const GLint *v);

int yagl_gles2_program_uniform_matrix2fv(struct yagl_gles2_program *program,
                                         GLint location,
                                         GLsizei count,
                                         GLboolean transpose,
                                         const GLfloat *value);

int yagl_gles2_program_uniform_matrix3fv(struct yagl_gles2_program *program,
                                         GLint location,
                                         GLsizei count,
                                         GLboolean transpose,
                                         const GLfloat *value);

int yagl_gles2_program_uniform_matrix4fv(struct yagl_gles2_program *program,
                                         GLint location,
                                         GLsizei count,
                                         GLboolean transpose,
                                         const GLfloat *value);
/*
 * Passing NULL won't hurt, this is for convenience.
 */
void yagl_gles2_program_acquire(struct yagl_gles2_program *program);

/*
 * Passing NULL won't hurt, this is for convenience.
 */
void yagl_gles2_program_release(struct yagl_gles2_program *program);

#endif