| 1 | // SPDX-FileCopyrightText: 2016 Gaetan Allaert |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <boost/utility.hpp> |
| 7 | #include <string> |
| 8 | |
| 9 | #include <EGL/egl.h> |
| 10 | #include <EGL/eglext.h> |
| 11 | #include <GLES2/gl2.h> |
| 12 | |
| 13 | |
| 14 | class GLES_utils : private boost::noncopyable { |
| 15 | public: |
| 16 | static GLES_utils& instance (); |
| 17 | |
| 18 | void init (const std::string &title); |
| 19 | |
| 20 | void register_display_func (void (*display_func) ()); |
| 21 | void register_idle_func (void (*idle_func) ()); |
| 22 | void register_keyboard_func (void (*keyboard_func) (unsigned char, int, int)); |
| 23 | void register_reshape_func (void (*reshape_func) (int, int)); |
| 24 | |
| 25 | void main_loop (); |
| 26 | |
| 27 | private: |
| 28 | explicit GLES_utils (); |
| 29 | virtual ~GLES_utils (); |
| 30 | |
| 31 | typedef struct { |
| 32 | #ifdef _RPI |
| 33 | EGL_DISPMANX_WINDOW_T native_window; |
| 34 | #else |
| 35 | EGLNativeWindowType native_window; |
| 36 | Display *x_display; |
| 37 | GLint width; |
| 38 | GLint height; |
| 39 | #endif |
| 40 | EGLint major_version; |
| 41 | EGLint minor_version; |
| 42 | EGLint num_configs; |
| 43 | EGLDisplay display; |
| 44 | EGLSurface surface; |
| 45 | EGLContext context; |
| 46 | EGLConfig config; |
| 47 | } EGL_STATE_T; |
| 48 | |
| 49 | EGL_STATE_T m_State; |
| 50 | |
| 51 | void (*display_func) (); |
| 52 | void (*idle_func) (); |
| 53 | void (*keyboard_func) (unsigned char, int, int); |
| 54 | void (*reshape_func) (int, int); |
| 55 | |
| 56 | void print_config_info (const int n, const EGLDisplay &display, EGLConfig &config); |
| 57 | void init_egl (EGL_STATE_T &state, const GLuint flags); |
| 58 | #ifdef _RPI |
| 59 | void init_dispmanx (EGL_DISPMANX_WINDOW_T &native_window); |
| 60 | #else |
| 61 | void init_display (EGL_STATE_T &state, const std::string &title); |
| 62 | #endif |
| 63 | GLboolean user_interrupt (); |
| 64 | }; |