summaryrefslogtreecommitdiff
path: root/GLES_common/yagl_gles_array.h
blob: 84e1fe52803db807edf0ebd3a011b66ca984a372 (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
/*
 * 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_GLES_ARRAY_H_
#define _YAGL_GLES_ARRAY_H_

#include "yagl_types.h"

/*
 * This structure represents GLES array, such arrays are
 * typically set up by calls to 'glColorPointer', 'glVertexPointer',
 * 'glVertexAttribPointer', etc.
 *
 * Note that we can't call host 'glVertexAttribPointer' right away
 * when target 'glVertexAttribPointer' call is made. We can't just
 * transfer the data from target to host and feed it to
 * host 'glVertexAttribPointer' since the data that pointer points to
 * may be changed later, thus, we must do the transfer right before host
 * OpenGL will attempt to use it. Host OpenGL will attempt to use
 * the array pointer on 'glDrawArrays' and 'glDrawElements', thus, we must
 * do the transfer right before those calls. For this to work, we'll
 * store 'apply' function together with an array, this function will be
 * responsible for calling host 'glVertexAttribPointer', 'glColorPointer'
 * or whatever.
 */

struct yagl_gles_array;
struct yagl_gles_buffer;

/*
 * Calls the corresponding host array function.
 */
typedef void (*yagl_gles_array_apply_func)(struct yagl_gles_array */*array*/,
                                           uint32_t /*first*/,
                                           uint32_t /*count*/,
                                           const GLvoid */*ptr*/,
                                           void */*user_data*/);

struct yagl_gles_array
{
    GLuint index;
    GLint size;
    GLenum type;
    GLenum actual_type;
    int el_size;
    int actual_el_size;
    GLboolean normalized;
    GLsizei stride;
    GLsizei actual_stride;
    GLuint divisor;
    int integer;

    /*
     * Specifies if array data needs to be converted before transferring to
     * host OpenGL occurs.
     * This could be used with GL_FIXED or GL_BYTE types, then data is
     * converted to GL_FLOAT or GL_SHORT respectively. Setting this flag
     * when yagl_gles_array::type is not either GL_FIXED or GL_FLOAT is
     * programming error.
     */
    int need_convert;

    /*
     * Is array enabled by 'glEnableClientState'/'glEnableVertexAttribArray'.
     */
    int enabled;

    struct yagl_gles_buffer *vbo;

    union
    {
        const GLvoid *ptr;
        struct
        {
            GLintptr offset;
            GLintptr actual_offset;
        };
    };

    yagl_gles_array_apply_func apply;
    void *user_data;
};

void yagl_gles_array_init(struct yagl_gles_array *array,
                          GLuint index,
                          yagl_gles_array_apply_func apply,
                          void *user_data);

void yagl_gles_array_cleanup(struct yagl_gles_array *array);

void yagl_gles_array_enable(struct yagl_gles_array *array, int enable);

int yagl_gles_array_update(struct yagl_gles_array *array,
                           GLint size,
                           GLenum type,
                           int need_convert,
                           GLboolean normalized,
                           GLsizei stride,
                           const GLvoid *ptr,
                           int integer);

int yagl_gles_array_update_vbo(struct yagl_gles_array *array,
                               GLint size,
                               GLenum type,
                               int need_convert,
                               GLboolean normalized,
                               GLsizei stride,
                               struct yagl_gles_buffer *vbo,
                               GLintptr offset,
                               int integer);

void yagl_gles_array_apply(struct yagl_gles_array *array);

void yagl_gles_array_set_divisor(struct yagl_gles_array *array, GLuint divisor);

void yagl_gles_array_transfer(struct yagl_gles_array *array,
                              uint32_t first,
                              uint32_t count,
                              GLsizei primcount);

#endif