Initial version of libomxil-vc4 for RPI3
[platform/adaptation/broadcom/libomxil-vc4.git] / interface / khronos / ext / gl_oes_matrix_palette_client.c
1 /*
2 Copyright (c) 2012, Broadcom Europe Ltd
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above copyright
10       notice, this list of conditions and the following disclaimer in the
11       documentation and/or other materials provided with the distribution.
12     * Neither the name of the copyright holder nor the
13       names of its contributors may be used to endorse or promote products
14       derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #define GL_GLEXT_PROTOTYPES /* we want the prototypes so the compiler will check that the signatures match */
29
30 #include "interface/khronos/common/khrn_int_common.h"
31
32 #include "interface/khronos/glxx/glxx_client.h"
33 #include "interface/khronos/common/khrn_client_rpc.h"
34
35 #include "interface/khronos/glxx/gl11_int_config.h"
36
37 #include "interface/khronos/include/GLES/glext.h"
38
39 #ifdef RPC_DIRECT
40 #include "interface/khronos/glxx/gl11_int_impl.h"
41 #endif
42
43 #if GL_OES_matrix_palette
44
45 static void set_error(GLXX_CLIENT_STATE_T *state, GLenum e) {
46    if (state->error == GL_NO_ERROR) state->error = e;
47 }
48
49 static void set_client_state_error(GLenum e) {
50    CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE();
51    GLXX_CLIENT_STATE_T *state = GLXX_GET_CLIENT_STATE(thread);
52    set_error(state, e);
53 }
54
55 GL_API void GL_APIENTRY glCurrentPaletteMatrixOES(GLuint index) {
56    CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE();
57    if (IS_OPENGLES_11(thread)) {
58       if (index > GL11_CONFIG_MAX_PALETTE_MATRICES_OES - 1) set_client_state_error(GL_INVALID_VALUE);
59       else {
60          RPC_CALL1(glCurrentPaletteMatrixOES_impl,
61                    thread,
62                    GLCURRENTPALETTEMATRIXOES_ID_11,
63                    RPC_UINT(index)                 );
64       }
65    }
66 }
67
68 GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES() {
69    CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE();
70    if (IS_OPENGLES_11(thread)) {
71       RPC_CALL0(glLoadPaletteFromModelViewMatrixOES_impl,
72                 thread,
73                 GLLOADPALETTEFROMMODELVIEWMATRIXOES_ID_11);
74    }
75 }
76
77 static GLboolean is_matrix_index_type(GLenum type) {
78    return (type == GL_UNSIGNED_BYTE);
79 }
80
81 static GLboolean is_matrix_palette_size(GLint size) {
82    /* TODO: Should size 0 be allowed or not? */
83    return size > 0 && size <= GL11_CONFIG_MAX_VERTEX_UNITS_OES;
84 }
85
86 /* TODO: This is copied from glxx_client.c. Find a better method */
87 static GLboolean is_aligned( GLenum type, size_t value)
88 {
89    switch (type) {
90    case GL_BYTE:
91    case GL_UNSIGNED_BYTE:
92       return GL_TRUE;
93    case GL_SHORT:
94    case GL_UNSIGNED_SHORT:
95       return (value & 1) == 0;
96    case GL_FIXED:
97    case GL_FLOAT:
98       return (value & 3) == 0;
99    default:
100       UNREACHABLE();
101       return GL_FALSE;
102    }
103 }
104
105 GL_API void GL_APIENTRY glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
106 {
107    if (is_matrix_index_type(type)) {
108       if (is_matrix_palette_size(size) && is_aligned(type, (size_t)pointer) && is_aligned(type, (size_t)stride) && stride >= 0) {
109          glintAttribPointer(GLXX_API_11, GL11_IX_MATRIX_INDEX, size, type, GL_FALSE, stride, pointer);
110       } else
111          glxx_set_error_api(GLXX_API_11, GL_INVALID_VALUE);
112    } else
113       glxx_set_error_api(GLXX_API_11, GL_INVALID_ENUM);
114 }
115
116 static GLboolean is_matrix_weight_type(GLenum type) {
117    return type == GL_FIXED ||
118           type == GL_FLOAT;
119 }
120
121 GL_API void GL_APIENTRY glWeightPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
122 {
123    if (is_matrix_weight_type(type)) {
124       if (is_matrix_palette_size(size) && is_aligned(type, (size_t)pointer) && is_aligned(type, (size_t)stride) && stride >= 0) {
125          glintAttribPointer(GLXX_API_11, GL11_IX_MATRIX_WEIGHT, size, type, GL_FALSE, stride, pointer);
126       } else
127          glxx_set_error_api(GLXX_API_11, GL_INVALID_VALUE);
128    } else
129       glxx_set_error_api(GLXX_API_11, GL_INVALID_ENUM);
130 }
131
132 #endif /* GL_OES_matrix_palette */