| 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 | |
| 29 | #define GL_GLEXT_PROTOTYPES /* we want the prototypes so the compiler will check that the signatures match */ |
| 30 | |
| 31 | #include "interface/khronos/common/khrn_int_common.h" |
| 32 | |
| 33 | #include "interface/khronos/glxx/glxx_client.h" |
| 34 | #include "interface/khronos/common/khrn_client_rpc.h" |
| 35 | |
| 36 | #ifdef RPC_DIRECT |
| 37 | #include "interface/khronos/glxx/glxx_int_impl.h" |
| 38 | #include "interface/khronos/glxx/gl11_int_impl.h" |
| 39 | #endif |
| 40 | |
| 41 | #include "interface/khronos/include/GLES/gl.h" |
| 42 | #include "interface/khronos/include/GLES/glext.h" |
| 43 | |
| 44 | |
| 45 | GL_API void* GL_APIENTRY glMapBufferOES (GLenum target, GLenum access) |
| 46 | { |
| 47 | CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); |
| 48 | void *pointer = 0; |
| 49 | if (IS_OPENGLES_11_OR_20(thread)) { |
| 50 | |
| 51 | GLXX_CLIENT_STATE_T *state = GLXX_GET_CLIENT_STATE(thread); |
| 52 | |
| 53 | if(target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) |
| 54 | { |
| 55 | glxx_set_error(state, GL_INVALID_ENUM); |
| 56 | } |
| 57 | else if(access != GL_WRITE_ONLY_OES) |
| 58 | { |
| 59 | glxx_set_error(state, GL_INVALID_ENUM); |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | GLXX_BUFFER_INFO_T buffer; |
| 64 | glxx_buffer_info_get(state, target, &buffer); |
| 65 | |
| 66 | if(buffer.id !=0 && buffer.cached_size > 0) |
| 67 | { |
| 68 | if(buffer.mapped_pointer != 0) |
| 69 | { |
| 70 | /* already mapped */ |
| 71 | glxx_set_error(state, GL_INVALID_OPERATION); |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | |
| 76 | pointer = khrn_platform_malloc(buffer.cached_size,"glxx_mapped_buffer" ); |
| 77 | |
| 78 | if(pointer != 0) |
| 79 | { |
| 80 | buffer.mapped_pointer = pointer; |
| 81 | buffer.mapped_size = buffer.cached_size; |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | buffer.mapped_pointer = 0; |
| 86 | buffer.mapped_size = 0; |
| 87 | glxx_set_error(state, GL_OUT_OF_MEMORY); |
| 88 | } |
| 89 | glxx_buffer_info_set(state, target, &buffer); |
| 90 | } |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | glxx_set_error(state, GL_INVALID_OPERATION); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | /* |
| 99 | RPC_CALL3_OUT_CTRL(glMapBufferOES_impl, |
| 100 | thread, |
| 101 | GLMAPBUFFEROES_ID, |
| 102 | RPC_ENUM(target), |
| 103 | RPC_ENUM(access), |
| 104 | &pointer); |
| 105 | */ |
| 106 | |
| 107 | return pointer; |
| 108 | } |
| 109 | |
| 110 | GL_API GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target) |
| 111 | { |
| 112 | CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); |
| 113 | GLboolean success = GL_FALSE; |
| 114 | |
| 115 | if (IS_OPENGLES_11_OR_20(thread)) { |
| 116 | //use buffer sub data to flush through |
| 117 | GLXX_CLIENT_STATE_T *state = GLXX_GET_CLIENT_STATE(thread); |
| 118 | |
| 119 | if(target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) |
| 120 | { |
| 121 | glxx_set_error(state, GL_INVALID_ENUM); |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | GLXX_BUFFER_INFO_T buffer; |
| 126 | glxx_buffer_info_get(state, target, &buffer); |
| 127 | |
| 128 | if(buffer.id !=0) |
| 129 | { |
| 130 | if(buffer.mapped_pointer) |
| 131 | { |
| 132 | void * p = buffer.mapped_pointer; |
| 133 | GLsizeiptr size = buffer.mapped_size; |
| 134 | |
| 135 | buffer.mapped_pointer = 0; |
| 136 | buffer.mapped_size = 0; |
| 137 | glxx_buffer_info_set(state, target, &buffer); |
| 138 | |
| 139 | glBufferSubData (target, 0, size, p); |
| 140 | khrn_platform_free(p); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | if (IS_OPENGLES_11_OR_20(thread)) { |
| 148 | success = RPC_BOOLEAN_RES(RPC_CALL1_RES(glUnmapBufferOES_impl, |
| 149 | thread, |
| 150 | GLUNMAPBUFFEROES_ID, |
| 151 | RPC_ENUM(target))); |
| 152 | */ |
| 153 | |
| 154 | return success; |
| 155 | } |
| 156 | |
| 157 | GL_API void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, GLvoid ** params) |
| 158 | { |
| 159 | CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); |
| 160 | |
| 161 | params[0] = (void *)0; |
| 162 | |
| 163 | if (IS_OPENGLES_11_OR_20(thread)) { |
| 164 | GLXX_CLIENT_STATE_T *state = GLXX_GET_CLIENT_STATE(thread); |
| 165 | if(target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) |
| 166 | { |
| 167 | glxx_set_error(state, GL_INVALID_ENUM); |
| 168 | } |
| 169 | else if(pname != GL_BUFFER_MAP_POINTER_OES) |
| 170 | { |
| 171 | glxx_set_error(state, GL_INVALID_ENUM); |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | GLXX_BUFFER_INFO_T buffer; |
| 176 | glxx_buffer_info_get(state, target, &buffer); |
| 177 | |
| 178 | if(buffer.id !=0) |
| 179 | { |
| 180 | params[0] = (void *)buffer.mapped_pointer; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | |
| 187 | RPC_CALL3_OUT_CTRL(glGetBufferPointervOES_impl, |
| 188 | thread, |
| 189 | GLGETBUFFERPOINTERVOES_ID, |
| 190 | RPC_ENUM(target), |
| 191 | RPC_ENUM(pname), |
| 192 | params); |
| 193 | |
| 194 | */ |
| 195 | } |
| 196 | |