1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/glegl.h
// Purpose: class common for all EGL-based wxGLCanvas implementations
// Author: Scott Talbert
// Created: 2017-12-26
// Copyright: (c) 2017 Scott Talbert <swt@techie.net>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_GLEGL_H_
#define _WX_UNIX_GLEGL_H_
#include <GL/gl.h>
// This is to avoid including Wayland & EGL headers here to pollute namespace
struct wl_compositor;
struct wl_subcompositor;
struct wl_callback;
struct wl_egl_window;
struct wl_surface;
struct wl_region;
struct wl_subsurface;
typedef void *EGLDisplay;
typedef void *EGLConfig;
typedef void *EGLSurface;
typedef void *EGLContext;
class wxGLContextAttrs;
class wxGLAttributes;
// ----------------------------------------------------------------------------
// wxGLContext
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
{
public:
wxGLContext(wxGLCanvas *win,
const wxGLContext *other = NULL,
const wxGLContextAttrs *ctxAttrs = NULL);
virtual ~wxGLContext();
virtual bool SetCurrent(const wxGLCanvas& win) const wxOVERRIDE;
private:
EGLContext m_glContext;
wxDECLARE_CLASS(wxGLContext);
};
// ----------------------------------------------------------------------------
// wxGLCanvasEGL
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLCanvasEGL : public wxGLCanvasBase
{
public:
// initialization and dtor
// -----------------------
// default ctor doesn't do anything, InitConfig() must be called
wxGLCanvasEGL();
// initializes EGLConfig corresponding to the given attributes
bool InitVisual(const wxGLAttributes& dispAttrs);
// creates EGLSurface
bool CreateSurface();
virtual ~wxGLCanvasEGL();
// implement wxGLCanvasBase methods
// --------------------------------
virtual bool SwapBuffers() wxOVERRIDE;
// X11-specific methods
// --------------------
// get the X11 handle of this window
virtual unsigned long GetXWindow() const = 0;
// override some wxWindow methods
// ------------------------------
// return true only if the window is realized: OpenGL context can't be
// created until we are
virtual bool IsShownOnScreen() const wxOVERRIDE;
// implementation only from now on
// -------------------------------
// get the EGLConfig we use
EGLConfig *GetEGLConfig() const { return m_config; }
EGLDisplay GetEGLDisplay() const { return m_display; }
EGLSurface GetEGLSurface() const { return m_surface; }
static EGLDisplay GetDisplay();
// initialize the global default GL config, return false if matching config
// not found
static bool InitDefaultConfig(const int *attribList);
// get the default EGL Config (may be NULL, shouldn't be freed by caller)
static EGLConfig *GetDefaultConfig() { return ms_glEGLConfig; }
// free the global GL visual, called by wxGLApp
static void FreeDefaultConfig();
// initializes EGLConfig
//
// returns NULL if EGLConfig couldn't be initialized, otherwise caller
// is responsible for freeing the pointer
static EGLConfig *InitConfig(const wxGLAttributes& dispAttrs);
// private Wayland-specific callbacks
#if wxABI_VERSION >= 30203
void CreateWaylandSubsurface();
void DestroyWaylandSubsurface();
void OnWLFrameCallback();
#endif // wxABI_VERSION >= 3.2.3
bool m_readyToDraw;
wl_compositor *m_wlCompositor;
wl_subcompositor *m_wlSubcompositor;
wl_callback *m_wlFrameCallbackHandler;
wl_egl_window *m_wlEGLWindow;
private:
EGLConfig *m_config;
EGLDisplay m_display;
EGLSurface m_surface;
unsigned long m_xwindow;
wl_surface *m_wlSurface;
wl_region *m_wlRegion;
wl_subsurface *m_wlSubsurface;
// the global/default versions of the above
static EGLConfig *ms_glEGLConfig;
friend void wxEGLUpdatePosition(wxGLCanvasEGL* win);
};
// ----------------------------------------------------------------------------
// wxGLApp
// ----------------------------------------------------------------------------
// this is used in wx/glcanvas.h, prevent it from defining a generic wxGLApp
#define wxGL_APP_DEFINED
class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
{
public:
wxGLApp() : wxGLAppBase() { }
// implement wxGLAppBase method
virtual bool InitGLVisual(const int *attribList) wxOVERRIDE
{
return wxGLCanvasEGL::InitDefaultConfig(attribList);
}
// This method is not currently used by the library itself, but remains for
// backwards compatibility and also because wxGTK has it we could start
// using it for the same purpose in wxX11 too some day.
virtual void* GetXVisualInfo() wxOVERRIDE
{
return wxGLCanvasEGL::GetDefaultConfig();
}
// and override this wxApp method to clean up
virtual int OnExit() wxOVERRIDE
{
wxGLCanvasEGL::FreeDefaultConfig();
return wxGLAppBase::OnExit();
}
private:
wxDECLARE_DYNAMIC_CLASS(wxGLApp);
};
#endif // _WX_UNIX_GLEGL_H_
|