wxwidgets/include/wx/unix/glx11.h
Vadim Zeitlin 3dde6bdeb0 Disable swap interval in GLX wxGLCanvas implementation too
We need to do it when using XWayland for the same reasons as we had to
do it in the EGL version when using either XWayland or Wayland directly:
without this, we can block for up to 1 second in glXSwapBuffers() if the
window is hidden, see #23512.

Closes #24163.

Closes #24165.
2024-01-05 01:05:30 +01:00

131 lines
3.7 KiB
C++

///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/glx11.h
// Purpose: class common for all X11-based wxGLCanvas implementations
// Author: Vadim Zeitlin
// Created: 2007-04-15
// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_GLX11_H_
#define _WX_UNIX_GLX11_H_
#include <GL/gl.h>
typedef struct __GLXcontextRec* GLXContext;
typedef struct __GLXFBConfigRec* GLXFBConfig;
// ----------------------------------------------------------------------------
// wxGLContext
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
{
public:
wxGLContext(wxGLCanvas *win,
const wxGLContext *other = nullptr,
const wxGLContextAttrs *ctxAttrs = nullptr);
virtual ~wxGLContext();
virtual bool SetCurrent(const wxGLCanvas& win) const override;
private:
GLXContext m_glContext;
wxDECLARE_CLASS(wxGLContext);
};
// ----------------------------------------------------------------------------
// wxGLCanvasX11
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLCanvasX11 : public wxGLCanvasBase
{
public:
// initialization and dtor
// -----------------------
// default ctor doesn't do anything, InitVisual() must be called
wxGLCanvasX11();
// initializes GLXFBConfig and XVisualInfo corresponding to the given attributes
bool InitVisual(const wxGLAttributes& dispAttrs);
// frees XVisualInfo info
virtual ~wxGLCanvasX11();
// implement wxGLCanvasBase methods
// --------------------------------
virtual bool SwapBuffers() override;
// X11-specific methods
// --------------------
// return GLX version: 13 means 1.3 &c
static int GetGLXVersion();
// return true if multisample extension is available
static bool IsGLXMultiSampleAvailable();
// get the X11 handle of this window
virtual unsigned long GetXWindow() const = 0;
// GLX-specific methods
// --------------------
// 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 override;
// implementation only from now on
// -------------------------------
// get the GLXFBConfig/XVisualInfo we use
GLXFBConfig *GetGLXFBConfig() const { return m_fbc; }
void* GetXVisualInfo() const { return m_vi; }
// initialize the global default GL visual, return false if matching visual
// not found
static bool InitDefaultVisualInfo(const int *attribList);
private:
GLXFBConfig *m_fbc;
void* m_vi;
bool m_swapIntervalSet = false;
};
// ----------------------------------------------------------------------------
// 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:
virtual bool InitGLVisual(const int *attribList) override;
// 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() override;
// and override this wxApp method to clean up
virtual int OnExit() override;
private:
wxDECLARE_DYNAMIC_CLASS(wxGLApp);
};
#endif // _WX_UNIX_GLX11_H_