| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gate/graphics/gl_apis.hpp" | ||
| 2 | #include "gate/exceptions.hpp" | ||
| 3 | |||
| 4 | namespace gate | ||
| 5 | { | ||
| 6 | namespace graph | ||
| 7 | { | ||
| 8 | |||
| 9 | ✗ | GlApi::GlApi() | |
| 10 | { | ||
| 11 | ✗ | result_t result = gate_gl_api_init(); | |
| 12 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 13 | ✗ | } | |
| 14 | |||
| 15 | ✗ | GlApi::~GlApi() noexcept | |
| 16 | { | ||
| 17 | ✗ | } | |
| 18 | |||
| 19 | ✗ | void GlApi::setColor(real32_t r, real32_t g, real32_t b) | |
| 20 | { | ||
| 21 | ✗ | gate_gl_api_color3(r, g, b); | |
| 22 | ✗ | } | |
| 23 | ✗ | void GlApi::setColor(real32_t r, real32_t g, real32_t b, real32_t a) | |
| 24 | { | ||
| 25 | ✗ | gate_gl_api_color4(r, g, b, a); | |
| 26 | ✗ | } | |
| 27 | ✗ | void GlApi::setColorByte(uint8_t r, uint8_t g, uint8_t b) | |
| 28 | { | ||
| 29 | ✗ | gate_gl_api_color3b(r, g, b); | |
| 30 | ✗ | } | |
| 31 | ✗ | void GlApi::setColorByte(uint8_t r, uint8_t g, uint8_t b, uint8_t a) | |
| 32 | { | ||
| 33 | ✗ | gate_gl_api_color4b(r, g, b, a); | |
| 34 | ✗ | } | |
| 35 | ✗ | void GlApi::setVertexPointer(size_t coord_count, real32_t const* ptr_coords) | |
| 36 | { | ||
| 37 | ✗ | gate_gl_api_vertexpointer(coord_count, ptr_coords); | |
| 38 | ✗ | } | |
| 39 | ✗ | void GlApi::setTexCoordPointer(size_t coord_count, real32_t const* ptr_coords) | |
| 40 | { | ||
| 41 | ✗ | gate_gl_api_texcoordpointer(coord_count, ptr_coords); | |
| 42 | ✗ | } | |
| 43 | ✗ | void GlApi::setShadeModel(ShadeModelEnum model) | |
| 44 | { | ||
| 45 | ✗ | gate_gl_api_shademodel((gate_gl_api_shademodel_t)(int)model); | |
| 46 | ✗ | } | |
| 47 | ✗ | void GlApi::setBlendFunc(BlendEnum srcFunc, BlendEnum dstFunc) | |
| 48 | { | ||
| 49 | ✗ | gate_gl_api_blendfunc((gate_gl_api_blend_t)(int)srcFunc, (gate_gl_api_blend_t)(int)dstFunc); | |
| 50 | ✗ | } | |
| 51 | ✗ | void GlApi::setClearColor(real32_t r, real32_t g, real32_t b, real32_t a) | |
| 52 | { | ||
| 53 | ✗ | gate_gl_api_clearcolor(r, g, b, a); | |
| 54 | ✗ | } | |
| 55 | ✗ | void GlApi::setClearDepth(real32_t depth) | |
| 56 | { | ||
| 57 | ✗ | gate_gl_api_cleardepth(depth); | |
| 58 | ✗ | } | |
| 59 | ✗ | void GlApi::enableCapability(CapabilityEnum capability) | |
| 60 | { | ||
| 61 | ✗ | gate_gl_api_enable((gate_gl_api_capability_t)(int)capability); | |
| 62 | ✗ | } | |
| 63 | ✗ | void GlApi::disableCapability(CapabilityEnum capability) | |
| 64 | { | ||
| 65 | ✗ | gate_gl_api_disable((gate_gl_api_capability_t)(int)capability); | |
| 66 | ✗ | } | |
| 67 | ✗ | void GlApi::setDepthFunc(DepthEnum depthFunction) | |
| 68 | { | ||
| 69 | ✗ | gate_gl_api_depthfunc((gate_gl_api_depth_t)(int)depthFunction); | |
| 70 | ✗ | } | |
| 71 | ✗ | void GlApi::setDepthMask(bool_t enabled) | |
| 72 | { | ||
| 73 | ✗ | gate_gl_api_depthmask(enabled); | |
| 74 | ✗ | } | |
| 75 | |||
| 76 | ✗ | void GlApi::setHint(HintEnum hintType, HintModeEnum hintMode) | |
| 77 | { | ||
| 78 | ✗ | gate_gl_api_hint((gate_gl_api_hint_t)(int)hintType, (gate_gl_api_hintmode_t)(int)hintMode); | |
| 79 | ✗ | } | |
| 80 | ✗ | void GlApi::setViewport(int32_t x, int32_t y, int32_t width, int32_t height) | |
| 81 | { | ||
| 82 | ✗ | gate_gl_api_viewport(x, y, width, height); | |
| 83 | ✗ | } | |
| 84 | ✗ | void GlApi::setMatrixMode(MatrixModeEnum matrixMode) | |
| 85 | { | ||
| 86 | ✗ | gate_gl_api_matrixmode((gate_gl_api_matrixmode_t)(int)matrixMode); | |
| 87 | ✗ | } | |
| 88 | ✗ | void GlApi::loadIdentity() | |
| 89 | { | ||
| 90 | ✗ | gate_gl_api_loadidentity(); | |
| 91 | ✗ | } | |
| 92 | ✗ | void GlApi::mulMatrix(real32_t const matrix[16]) | |
| 93 | { | ||
| 94 | ✗ | gate_gl_api_multmatrix(matrix); | |
| 95 | ✗ | } | |
| 96 | ✗ | void GlApi::translate(real32_t x, real32_t y, real32_t z) | |
| 97 | { | ||
| 98 | ✗ | gate_gl_api_translate(x, y, z); | |
| 99 | ✗ | } | |
| 100 | ✗ | void GlApi::rotate(real32_t angle, real32_t x, real32_t y, real32_t z) | |
| 101 | { | ||
| 102 | ✗ | gate_gl_api_rotate(angle, x, y, z); | |
| 103 | ✗ | } | |
| 104 | |||
| 105 | ✗ | void GlApi::flush() | |
| 106 | { | ||
| 107 | ✗ | gate_gl_api_flush(); | |
| 108 | ✗ | } | |
| 109 | ✗ | void GlApi::finish() | |
| 110 | { | ||
| 111 | ✗ | gate_gl_api_finish(); | |
| 112 | ✗ | } | |
| 113 | ✗ | void GlApi::clear(unsigned clearBits) | |
| 114 | { | ||
| 115 | ✗ | gate_gl_api_clear(clearBits); | |
| 116 | ✗ | } | |
| 117 | ✗ | void GlApi::setPerspective(real32_t fovy, real32_t aspect, real32_t znear, real32_t zfar) | |
| 118 | { | ||
| 119 | ✗ | gate_gl_api_perspective(fovy, aspect, znear, zfar); | |
| 120 | ✗ | } | |
| 121 | ✗ | void GlApi::lookAt(real32_t eyeX, real32_t eyeY, real32_t eyeZ, real32_t lookX, real32_t lookY, real32_t lookZ, real32_t upX, real32_t upY, real32_t upZ) | |
| 122 | { | ||
| 123 | ✗ | gate_gl_api_lookat(eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ); | |
| 124 | ✗ | } | |
| 125 | ✗ | void GlApi::enableClientState(ClientStateEnum state) | |
| 126 | { | ||
| 127 | ✗ | gate_gl_api_enableclientstate((gate_gl_api_clientstate_t)(int)state); | |
| 128 | ✗ | } | |
| 129 | ✗ | void GlApi::disableClientState(ClientStateEnum state) | |
| 130 | { | ||
| 131 | ✗ | gate_gl_api_disableclientstate((gate_gl_api_clientstate_t)(int)state); | |
| 132 | ✗ | } | |
| 133 | ✗ | void GlApi::drawArrays(DrawModeEnum drawMode, int index, size_t vertex_count) | |
| 134 | { | ||
| 135 | ✗ | gate_gl_api_drawarrays((gate_gl_api_drawmode_t)(int)drawMode, index, vertex_count); | |
| 136 | ✗ | } | |
| 137 | ✗ | void* GlApi::createTexture(PixelFormatEnum pixelFormat, uint32_t width, uint32_t height, void const* data) | |
| 138 | { | ||
| 139 | ✗ | return gate_gl_api_createtexture((gate_gl_api_pixelformat_t)(int)pixelFormat, width, height, data); | |
| 140 | } | ||
| 141 | ✗ | void GlApi::deleteTexture(void* textureId) | |
| 142 | { | ||
| 143 | ✗ | gate_gl_api_deletetexture(textureId); | |
| 144 | ✗ | } | |
| 145 | ✗ | void GlApi::bindTexture(void* textureId) | |
| 146 | { | ||
| 147 | ✗ | gate_gl_api_bindtexture(textureId); | |
| 148 | ✗ | } | |
| 149 | ✗ | void GlApi::setCullFace(CullFaceEnum cullface) | |
| 150 | { | ||
| 151 | ✗ | gate_gl_api_cullface((gate_gl_api_cullface_t)cullface); | |
| 152 | ✗ | } | |
| 153 | |||
| 154 | |||
| 155 | #if defined(GATE_GRAPHICS_OPENGL2_SUPPORT) | ||
| 156 | uintptr_t GlApi::createShader(gate_gl2_api_shader_type_t type) | ||
| 157 | { | ||
| 158 | return gate_gl2_api_create_shader(type); | ||
| 159 | } | ||
| 160 | void GlApi::shaderSource(uintptr_t shader, size_t count, char const* const* code, size_t const* length) | ||
| 161 | { | ||
| 162 | gate_gl2_api_shader_source(shader, count, code, length); | ||
| 163 | } | ||
| 164 | void GlApi::compileShader(uintptr_t shader) | ||
| 165 | { | ||
| 166 | gate_gl2_api_compile_shader(shader); | ||
| 167 | } | ||
| 168 | void GlApi::getShaderIv(uintptr_t shader, gate_gl2_api_shader_param_t param_name, intptr_t* params) | ||
| 169 | { | ||
| 170 | gate_gl2_api_get_shader_iv(shader, param_name, params); | ||
| 171 | } | ||
| 172 | void GlApi::getShaderInfoLog(uintptr_t shader, size_t max_length, size_t& len_used, char* info_buffer) | ||
| 173 | { | ||
| 174 | gate_gl2_api_get_shader_info_log(shader, max_length, &len_used, info_buffer); | ||
| 175 | } | ||
| 176 | |||
| 177 | void GlApi::deleteShader(uintptr_t shader) | ||
| 178 | { | ||
| 179 | gate_gl2_api_delete_shader(shader); | ||
| 180 | } | ||
| 181 | |||
| 182 | uintptr_t GlApi::createProgram(void) | ||
| 183 | { | ||
| 184 | return gate_gl2_api_create_program(); | ||
| 185 | } | ||
| 186 | void GlApi::linkProgram(uintptr_t program) | ||
| 187 | { | ||
| 188 | gate_gl2_api_link_program(program); | ||
| 189 | } | ||
| 190 | void GlApi::getProgramIv(uintptr_t program, gate_gl2_api_program_param_t param_name, intptr_t* params) | ||
| 191 | { | ||
| 192 | gate_gl2_api_get_program_iv(program, param_name, params); | ||
| 193 | } | ||
| 194 | void GlApi::getProgramInfoLog(uintptr_t program, size_t bufSize, size_t* length, char* infoLog) | ||
| 195 | { | ||
| 196 | gate_gl2_api_get_program_info_log(program, bufSize, length, infoLog); | ||
| 197 | } | ||
| 198 | void GlApi::useProgram(uintptr_t program) | ||
| 199 | { | ||
| 200 | gate_gl2_api_use_program(program); | ||
| 201 | } | ||
| 202 | void GlApi::attachShader(uintptr_t program, uintptr_t shader) | ||
| 203 | { | ||
| 204 | gate_gl2_api_attach_shader(program, shader); | ||
| 205 | } | ||
| 206 | void GlApi::deleteProgram(uintptr_t program) | ||
| 207 | { | ||
| 208 | gate_gl2_api_delete_program(program); | ||
| 209 | } | ||
| 210 | void GlApi::bindAttribLocation(uintptr_t program, size_t index, char const* name) | ||
| 211 | { | ||
| 212 | gate_gl2_api_bind_attrib_location(program, index, name); | ||
| 213 | } | ||
| 214 | intptr_t GlApi::getAttribLocation(uintptr_t program, char const* name) | ||
| 215 | { | ||
| 216 | return gate_gl2_api_get_attrib_location(program, name); | ||
| 217 | } | ||
| 218 | intptr_t GlApi::getUniformLocation(uintptr_t program, char const* name) | ||
| 219 | { | ||
| 220 | return gate_gl2_api_get_uniform_location(program, name); | ||
| 221 | } | ||
| 222 | |||
| 223 | |||
| 224 | void GlApi::genBuffers(size_t n, unsigned int* buffers) | ||
| 225 | { | ||
| 226 | gate_gl2_api_gen_buffers(n, buffers); | ||
| 227 | } | ||
| 228 | void GlApi::deleteBuffers(size_t n, unsigned int* buffers) | ||
| 229 | { | ||
| 230 | gate_gl2_api_delete_buffers(n, buffers); | ||
| 231 | } | ||
| 232 | void GlApi::bindBuffers(gate_gl2_api_buffer_type_t target_type, unsigned int buffer) | ||
| 233 | { | ||
| 234 | gate_gl2_api_bind_buffers(target_type, buffer); | ||
| 235 | } | ||
| 236 | void GlApi::bufferData(gate_gl2_api_buffer_type_t target_type, size_t size, void const* data, gate_gl2_api_usage_type_t usage) | ||
| 237 | { | ||
| 238 | gate_gl2_api_buffer_data(target_type, size, data, usage); | ||
| 239 | } | ||
| 240 | /* | ||
| 241 | void GlApi::namedBufferData(unsigned int buffer, size_t size, void const* data, gate_gl2_api_usage_type_t usage) | ||
| 242 | { | ||
| 243 | gate_gl2_api_named_buffer_data(buffer, size, data, usage); | ||
| 244 | } | ||
| 245 | */ | ||
| 246 | void GlApi::vertexAttribPointer(uintptr_t index, size_t size, gate_gl2_api_vertex_attrib_type_t type, bool_t normalized, size_t stride, void const* pointer) | ||
| 247 | { | ||
| 248 | gate_gl2_api_vertex_attrib_pointer(index, size, type, normalized, stride, pointer); | ||
| 249 | } | ||
| 250 | void GlApi::enableVertexAttribArray(uintptr_t index) | ||
| 251 | { | ||
| 252 | gate_gl2_api_enable_vertex_attrib_array(index); | ||
| 253 | } | ||
| 254 | void GlApi::disableVertexAttribArray(uintptr_t index) | ||
| 255 | { | ||
| 256 | gate_gl2_api_disable_vertex_attrib_array(index); | ||
| 257 | } | ||
| 258 | void GlApi::activeTexture(uintptr_t texture_index) | ||
| 259 | { | ||
| 260 | gate_gl2_api_active_texture(texture_index); | ||
| 261 | } | ||
| 262 | |||
| 263 | |||
| 264 | void GlApi::uniform1f(intptr_t location, real32_t v0) | ||
| 265 | { | ||
| 266 | gate_gl2_api_uniform1f(location, v0); | ||
| 267 | } | ||
| 268 | void GlApi::uniform2f(intptr_t location, real32_t v0, real32_t v1) | ||
| 269 | { | ||
| 270 | gate_gl2_api_uniform2f(location, v0, v1); | ||
| 271 | } | ||
| 272 | void GlApi::uniform3f(intptr_t location, real32_t v0, real32_t v1, real32_t v2) | ||
| 273 | { | ||
| 274 | gate_gl2_api_uniform3f(location, v0, v1, v2); | ||
| 275 | } | ||
| 276 | void GlApi::uniform4f(intptr_t location, real32_t v0, real32_t v1, real32_t v2, real32_t v3) | ||
| 277 | { | ||
| 278 | gate_gl2_api_uniform4f(location, v0, v1, v2, v3); | ||
| 279 | } | ||
| 280 | void GlApi::uniform1fv(intptr_t location, size_t count, const real32_t *value) | ||
| 281 | { | ||
| 282 | gate_gl2_api_uniform1fv(location, count, value); | ||
| 283 | } | ||
| 284 | void GlApi::uniform2fv(intptr_t location, size_t count, const real32_t *value) | ||
| 285 | { | ||
| 286 | gate_gl2_api_uniform2fv(location, count, value); | ||
| 287 | } | ||
| 288 | void GlApi::uniform3fv(intptr_t location, size_t count, const real32_t *value) | ||
| 289 | { | ||
| 290 | gate_gl2_api_uniform3fv(location, count, value); | ||
| 291 | } | ||
| 292 | void GlApi::uniform4fv(intptr_t location, size_t count, const real32_t *value) | ||
| 293 | { | ||
| 294 | gate_gl2_api_uniform4fv(location, count, value); | ||
| 295 | } | ||
| 296 | void GlApi::uniform1i(intptr_t location, int v0) | ||
| 297 | { | ||
| 298 | gate_gl2_api_uniform1i(location, v0); | ||
| 299 | } | ||
| 300 | void GlApi::uniform2i(intptr_t location, int v0, int v1) | ||
| 301 | { | ||
| 302 | gate_gl2_api_uniform2i(location, v0, v1); | ||
| 303 | } | ||
| 304 | void GlApi::uniform3i(intptr_t location, int v0, int v1, int v2) | ||
| 305 | { | ||
| 306 | gate_gl2_api_uniform3i(location, v0, v1, v2); | ||
| 307 | } | ||
| 308 | void GlApi::uniform4i(intptr_t location, int v0, int v1, int v2, int v3) | ||
| 309 | { | ||
| 310 | gate_gl2_api_uniform4i(location, v0, v1, v2, v3); | ||
| 311 | } | ||
| 312 | void GlApi::uniform1iv(intptr_t location, size_t count, const int *value) | ||
| 313 | { | ||
| 314 | gate_gl2_api_uniform1iv(location, count, value); | ||
| 315 | } | ||
| 316 | void GlApi::uniform2iv(intptr_t location, size_t count, const int *value) | ||
| 317 | { | ||
| 318 | gate_gl2_api_uniform2iv(location, count, value); | ||
| 319 | } | ||
| 320 | void GlApi::uniform3iv(intptr_t location, size_t count, const int *value) | ||
| 321 | { | ||
| 322 | gate_gl2_api_uniform3iv(location, count, value); | ||
| 323 | } | ||
| 324 | void GlApi::uniform4iv(intptr_t location, size_t count, const int *value) | ||
| 325 | { | ||
| 326 | gate_gl2_api_uniform4iv(location, count, value); | ||
| 327 | } | ||
| 328 | |||
| 329 | void GlApi::uniform_matrix2fv(intptr_t location, size_t count, bool_t transpose, const real32_t *value) | ||
| 330 | { | ||
| 331 | gate_gl2_api_uniform_matrix2fv(location, count, transpose, value); | ||
| 332 | } | ||
| 333 | void GlApi::uniform_matrix3fv(intptr_t location, size_t count, bool_t transpose, const real32_t *value) | ||
| 334 | { | ||
| 335 | gate_gl2_api_uniform_matrix3fv(location, count, transpose, value); | ||
| 336 | } | ||
| 337 | void GlApi::uniform_matrix4fv(intptr_t location, size_t count, bool_t transpose, const real32_t *value) | ||
| 338 | { | ||
| 339 | gate_gl2_api_uniform_matrix4fv(location, count, transpose, value); | ||
| 340 | } | ||
| 341 | |||
| 342 | #endif | ||
| 343 | |||
| 344 | |||
| 345 | |||
| 346 | ✗ | GlSurfaceEventSink::GlSurfaceEventSink() | |
| 347 | ✗ | : surface_ptr(NULL) | |
| 348 | { | ||
| 349 | ✗ | } | |
| 350 | |||
| 351 | ✗ | GlSurfaceEventSink::~GlSurfaceEventSink() noexcept | |
| 352 | { | ||
| 353 | ✗ | } | |
| 354 | |||
| 355 | ✗ | GlSurface& GlSurfaceEventSink::getSurface() | |
| 356 | { | ||
| 357 | ✗ | if (!this->surface_ptr) | |
| 358 | { | ||
| 359 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
| 360 | } | ||
| 361 | ✗ | return *this->surface_ptr; | |
| 362 | } | ||
| 363 | ✗ | void GlSurfaceEventSink::connectSurface(GlSurface& surface) | |
| 364 | { | ||
| 365 | ✗ | this->surface_ptr = &surface; | |
| 366 | ✗ | } | |
| 367 | |||
| 368 | |||
| 369 | |||
| 370 | enumint_t const GlSurface::Flag_SoftwareRendering = GATE_GL_SURFACE_FLAG_SOFTWARE_RENDERING; | ||
| 371 | |||
| 372 | |||
| 373 | ✗ | GlSurface::GlSurface() | |
| 374 | { | ||
| 375 | ✗ | result_t result = gate_gl_surface_init(&this->impl); | |
| 376 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 377 | ✗ | } | |
| 378 | ✗ | GlSurface::~GlSurface() noexcept | |
| 379 | { | ||
| 380 | ✗ | gate_gl_surface_uninit(&this->impl); | |
| 381 | ✗ | } | |
| 382 | |||
| 383 | ✗ | void GlSurface::openScreen(uint32_t width, uint32_t height, enumint_t flags) | |
| 384 | { | ||
| 385 | ✗ | result_t result = gate_gl_surface_open(&this->impl, gate_gl_surface_type_screen, width, height, flags); | |
| 386 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 387 | ✗ | } | |
| 388 | ✗ | void GlSurface::openImage(uint32_t width, uint32_t height, enumint_t flags) | |
| 389 | { | ||
| 390 | ✗ | result_t result = gate_gl_surface_open(&this->impl, gate_gl_surface_type_image, width, height, flags); | |
| 391 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 392 | ✗ | } | |
| 393 | |||
| 394 | ✗ | void GlSurface::close() | |
| 395 | { | ||
| 396 | ✗ | result_t result = gate_gl_surface_close(&this->impl); | |
| 397 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 398 | ✗ | } | |
| 399 | |||
| 400 | ✗ | void GlSurface::getSize(uint32_t& width, uint32_t& height) | |
| 401 | { | ||
| 402 | ✗ | result_t result = gate_gl_surface_get_size(&this->impl, &width, &height); | |
| 403 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 404 | ✗ | } | |
| 405 | ✗ | void GlSurface::resize(uint32_t width, uint32_t height) | |
| 406 | { | ||
| 407 | ✗ | result_t result = gate_gl_surface_resize(&this->impl, width, height); | |
| 408 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 409 | ✗ | } | |
| 410 | |||
| 411 | ✗ | RasterImage GlSurface::printImage() | |
| 412 | { | ||
| 413 | ✗ | gate_rasterimage_t rasterimage = GATE_INIT_EMPTY; | |
| 414 | ✗ | result_t result = gate_gl_surface_print_image(&this->impl, &rasterimage); | |
| 415 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 416 | ✗ | RasterImage image(&rasterimage); | |
| 417 | ✗ | gate_rasterimage_release(&rasterimage); | |
| 418 | ✗ | return image; | |
| 419 | } | ||
| 420 | |||
| 421 | |||
| 422 | ✗ | static void surface_events_on_render(gate_gl_surface_t* surface, void* user_param) | |
| 423 | { | ||
| 424 | ✗ | GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param); | |
| 425 | try | ||
| 426 | { | ||
| 427 | ✗ | sink->onRender(sink->getSurface()); | |
| 428 | } | ||
| 429 | ✗ | catch (...) {} | |
| 430 | ✗ | } | |
| 431 | ✗ | static void surface_events_on_exit(gate_gl_surface_t* surface, void* user_param) | |
| 432 | { | ||
| 433 | ✗ | GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param); | |
| 434 | try | ||
| 435 | { | ||
| 436 | ✗ | sink->onExit(sink->getSurface()); | |
| 437 | } | ||
| 438 | ✗ | catch (...) {} | |
| 439 | ✗ | } | |
| 440 | ✗ | static void surface_events_on_resize(gate_gl_surface_t* surface, gate_uint32_t width, gate_uint32_t height, void* user_param) | |
| 441 | { | ||
| 442 | ✗ | GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param); | |
| 443 | try | ||
| 444 | { | ||
| 445 | ✗ | sink->onResize(sink->getSurface(), width, height); | |
| 446 | } | ||
| 447 | ✗ | catch (...) {} | |
| 448 | ✗ | } | |
| 449 | ✗ | static void surface_events_on_key_down(gate_gl_surface_t* surface, gate_input_keycode_t keyboard_key, | |
| 450 | gate_input_keystates_t keyboard_states, void* user_param) | ||
| 451 | { | ||
| 452 | ✗ | GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param); | |
| 453 | try | ||
| 454 | { | ||
| 455 | ✗ | sink->onKeyDown(sink->getSurface(), Keyboard::KeyEnum(keyboard_key), keyboard_states); | |
| 456 | } | ||
| 457 | ✗ | catch (...) {} | |
| 458 | ✗ | } | |
| 459 | ✗ | static void surface_events_on_key_up(gate_gl_surface_t* surface, gate_input_keycode_t keyboard_key, | |
| 460 | gate_input_keystates_t keyboard_states, void* user_param) | ||
| 461 | { | ||
| 462 | ✗ | GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param); | |
| 463 | try | ||
| 464 | { | ||
| 465 | ✗ | sink->onKeyUp(sink->getSurface(), Keyboard::KeyEnum(keyboard_key), keyboard_states); | |
| 466 | } | ||
| 467 | ✗ | catch (...) {} | |
| 468 | ✗ | } | |
| 469 | ✗ | static void surface_events_on_pointer_down(gate_gl_surface_t* surface, gate_uint32_t pointer_type, gate_real32_t x, gate_real32_t y, void* user_param) | |
| 470 | { | ||
| 471 | ✗ | GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param); | |
| 472 | try | ||
| 473 | { | ||
| 474 | ✗ | sink->onPointerDown(sink->getSurface(), pointer_type, x, y); | |
| 475 | } | ||
| 476 | ✗ | catch (...) {} | |
| 477 | ✗ | } | |
| 478 | ✗ | static void surface_events_on_pointer_move(gate_gl_surface_t* surface, gate_uint32_t pointer_type, gate_real32_t x, gate_real32_t y, void* user_param) | |
| 479 | { | ||
| 480 | ✗ | GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param); | |
| 481 | try | ||
| 482 | { | ||
| 483 | ✗ | sink->onPointerMove(sink->getSurface(), pointer_type, x, y); | |
| 484 | } | ||
| 485 | ✗ | catch (...) {} | |
| 486 | ✗ | } | |
| 487 | ✗ | static void surface_events_on_pointer_up(gate_gl_surface_t* surface, gate_uint32_t pointer_type, gate_real32_t x, gate_real32_t y, void* user_param) | |
| 488 | { | ||
| 489 | ✗ | GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param); | |
| 490 | try | ||
| 491 | { | ||
| 492 | ✗ | sink->onPointerUp(sink->getSurface(), pointer_type, x, y); | |
| 493 | } | ||
| 494 | ✗ | catch (...) {} | |
| 495 | ✗ | } | |
| 496 | ✗ | static void surface_events_on_scroll(gate_gl_surface_t* surface, gate_int32_t x_direction, gate_int32_t y_direction, void* user_param) | |
| 497 | { | ||
| 498 | ✗ | GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param); | |
| 499 | try | ||
| 500 | { | ||
| 501 | ✗ | sink->onScroll(sink->getSurface(), x_direction, y_direction); | |
| 502 | } | ||
| 503 | ✗ | catch (...) {} | |
| 504 | ✗ | } | |
| 505 | |||
| 506 | static gate_gl_surface_events_t cpp_dispatcher = | ||
| 507 | { | ||
| 508 | &surface_events_on_resize, | ||
| 509 | &surface_events_on_render, | ||
| 510 | &surface_events_on_exit, | ||
| 511 | |||
| 512 | &surface_events_on_key_down, | ||
| 513 | &surface_events_on_key_up, | ||
| 514 | &surface_events_on_pointer_down, | ||
| 515 | &surface_events_on_pointer_move, | ||
| 516 | &surface_events_on_pointer_up, | ||
| 517 | &surface_events_on_scroll | ||
| 518 | }; | ||
| 519 | |||
| 520 | ✗ | void GlSurface::runEventLoop(GlSurfaceEventSink& eventHandler) | |
| 521 | { | ||
| 522 | ✗ | eventHandler.connectSurface(*this); | |
| 523 | ✗ | result_t result = gate_gl_surface_run_event_loop(&this->impl, &cpp_dispatcher, static_cast<void*>(&eventHandler)); | |
| 524 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 525 | ✗ | } | |
| 526 | ✗ | void GlSurface::exitEventLoop() | |
| 527 | { | ||
| 528 | ✗ | result_t result = gate_gl_surface_exit_event_loop(&this->impl); | |
| 529 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 530 | ✗ | } | |
| 531 | ✗ | void GlSurface::swapBuffers() | |
| 532 | { | ||
| 533 | ✗ | result_t result = gate_gl_surface_swap_buffers(&this->impl); | |
| 534 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 535 | ✗ | } | |
| 536 | |||
| 537 | ✗ | GlApi& GlSurface::getGlApi() | |
| 538 | { | ||
| 539 | ✗ | return this->api; | |
| 540 | } | ||
| 541 | |||
| 542 | } // end of namespace graph | ||
| 543 | } // end of namespace gate | ||
| 544 |