| 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 | #ifndef GLXX_CLIENT_H |
| 29 | #define GLXX_CLIENT_H |
| 30 | |
| 31 | #include "interface/khronos/common/khrn_client.h" |
| 32 | #include "interface/khronos/common/khrn_client_platform.h" |
| 33 | #include "interface/khronos/common/khrn_client_cache.h" |
| 34 | |
| 35 | #include "interface/khronos/egl/egl_client_context.h" |
| 36 | |
| 37 | #include "interface/khronos/glxx/glxx_int_attrib.h" |
| 38 | #include "interface/khronos/glxx/glxx_int_config.h" |
| 39 | |
| 40 | /* |
| 41 | Called just before a rendering command (i.e. anything which could modify |
| 42 | the draw surface) is executed |
| 43 | */ |
| 44 | typedef void (*GL_RENDER_CALLBACK_T)(void); |
| 45 | |
| 46 | /* |
| 47 | Called just after rendering has been compeleted (i.e. flush or finish). |
| 48 | wait should be true for finish-like behaviour, false for flush-like |
| 49 | behaviour |
| 50 | */ |
| 51 | typedef void (*GL_FLUSH_CALLBACK_T)(bool wait); |
| 52 | |
| 53 | /* |
| 54 | GL 1.1 and 2.0 client state structure |
| 55 | */ |
| 56 | |
| 57 | typedef struct buffer_info { |
| 58 | GLuint id; |
| 59 | GLsizeiptr cached_size; |
| 60 | void * mapped_pointer; |
| 61 | GLsizeiptr mapped_size; |
| 62 | } GLXX_BUFFER_INFO_T; |
| 63 | |
| 64 | typedef struct { |
| 65 | |
| 66 | GLenum error; |
| 67 | |
| 68 | /* |
| 69 | Open GL version |
| 70 | |
| 71 | Invariants: |
| 72 | |
| 73 | OPENGL_ES_11 or OPENGL_ES_20 |
| 74 | */ |
| 75 | |
| 76 | unsigned int type; |
| 77 | |
| 78 | /* |
| 79 | alignments |
| 80 | |
| 81 | used to work out how much data to send for glTexImage2D() |
| 82 | */ |
| 83 | |
| 84 | struct { |
| 85 | GLint pack; |
| 86 | GLint unpack; |
| 87 | } alignment; |
| 88 | |
| 89 | struct { |
| 90 | GLuint array; |
| 91 | GLuint element_array; |
| 92 | } bound_buffer; |
| 93 | |
| 94 | GLXX_ATTRIB_T attrib[GLXX_CONFIG_MAX_VERTEX_ATTRIBS]; |
| 95 | |
| 96 | GL_RENDER_CALLBACK_T render_callback; |
| 97 | GL_FLUSH_CALLBACK_T flush_callback; |
| 98 | |
| 99 | KHRN_CACHE_T cache; |
| 100 | |
| 101 | //gl 1.1 specific |
| 102 | struct { |
| 103 | GLenum client; |
| 104 | GLenum server; |
| 105 | } active_texture; |
| 106 | |
| 107 | //gl 2.0 specific |
| 108 | bool default_framebuffer; //render_callback only called if we're rendering to default framebuffer |
| 109 | |
| 110 | KHRN_POINTER_MAP_T buffers; |
| 111 | |
| 112 | } GLXX_CLIENT_STATE_T; |
| 113 | |
| 114 | extern int gl11_client_state_init(GLXX_CLIENT_STATE_T *state); |
| 115 | extern int gl20_client_state_init(GLXX_CLIENT_STATE_T *state); |
| 116 | |
| 117 | extern void glxx_client_state_free(GLXX_CLIENT_STATE_T *state); |
| 118 | |
| 119 | #define GLXX_GET_CLIENT_STATE(thread) glxx_get_client_state(thread) |
| 120 | |
| 121 | static INLINE GLXX_CLIENT_STATE_T *glxx_get_client_state(CLIENT_THREAD_STATE_T *thread) |
| 122 | { |
| 123 | EGL_CONTEXT_T *context = thread->opengl.context; |
| 124 | GLXX_CLIENT_STATE_T * state; |
| 125 | vcos_assert( context != NULL ); |
| 126 | vcos_assert(context->type == OPENGL_ES_11 || context->type == OPENGL_ES_20); |
| 127 | state = (GLXX_CLIENT_STATE_T *)context->state; |
| 128 | vcos_assert(context->type == state->type); |
| 129 | return state; |
| 130 | } |
| 131 | |
| 132 | #define GLXX_API_11 (1<<(OPENGL_ES_11)) |
| 133 | #define GLXX_API_20 (1<<(OPENGL_ES_20)) |
| 134 | #define GLXX_API_11_OR_20 (GLXX_API_11|GLXX_API_20) |
| 135 | |
| 136 | static INLINE bool glxx_api_ok(uint32_t api, EGL_CONTEXT_TYPE_T type) |
| 137 | { |
| 138 | return !!(api & (1<<type)); |
| 139 | } |
| 140 | |
| 141 | #define IS_OPENGLES_11(thread) is_opengles_api(thread, GLXX_API_11) |
| 142 | #define IS_OPENGLES_20(thread) is_opengles_api(thread, GLXX_API_20) |
| 143 | #define IS_OPENGLES_11_OR_20(thread) is_opengles_api(thread, GLXX_API_11_OR_20) |
| 144 | #define IS_OPENGLES_API(thread, api) is_opengles_api(thread, api) |
| 145 | |
| 146 | static INLINE bool is_opengles_api(CLIENT_THREAD_STATE_T *thread, uint32_t api) |
| 147 | { |
| 148 | EGL_CONTEXT_T *context = thread->opengl.context; |
| 149 | return context && glxx_api_ok(api, context->type); |
| 150 | } |
| 151 | |
| 152 | extern void glxx_buffer_info_get(GLXX_CLIENT_STATE_T *state, GLenum target, GLXX_BUFFER_INFO_T* buffer); |
| 153 | extern void glxx_buffer_info_set(GLXX_CLIENT_STATE_T *state, GLenum target, GLXX_BUFFER_INFO_T* buffer); |
| 154 | extern void glxx_set_error(GLXX_CLIENT_STATE_T *state, GLenum error); |
| 155 | extern void glxx_set_error_api(uint32_t api, GLenum error); |
| 156 | |
| 157 | /* Fake GL API calls */ |
| 158 | void glintAttribPointer (uint32_t api, uint32_t indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *ptr); |
| 159 | void glintAttrib (uint32_t api, uint32_t indx, float x, float y, float z, float w); |
| 160 | void glintColor(float red, float green, float blue, float alpha); |
| 161 | void glintAttribEnable(uint32_t api, uint32_t indx, bool enabled); |
| 162 | void *glintAttribGetPointer(uint32_t api, uint32_t indx); |
| 163 | |
| 164 | #endif |
| 165 | |