duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

opengl_context_egl_x11.cpp (1751B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
      3 
      4 #include "opengl_context_egl_x11.h"
      5 
      6 #include "common/error.h"
      7 
      8 OpenGLContextEGLX11::OpenGLContextEGLX11(const WindowInfo& wi) : OpenGLContextEGL(wi)
      9 {
     10 }
     11 
     12 OpenGLContextEGLX11::~OpenGLContextEGLX11() = default;
     13 
     14 std::unique_ptr<OpenGLContext> OpenGLContextEGLX11::Create(const WindowInfo& wi,
     15                                                            std::span<const Version> versions_to_try, Error* error)
     16 {
     17   std::unique_ptr<OpenGLContextEGLX11> context = std::make_unique<OpenGLContextEGLX11>(wi);
     18   if (!context->Initialize(versions_to_try, error))
     19     return nullptr;
     20 
     21   return context;
     22 }
     23 
     24 std::unique_ptr<OpenGLContext> OpenGLContextEGLX11::CreateSharedContext(const WindowInfo& wi, Error* error)
     25 {
     26   std::unique_ptr<OpenGLContextEGLX11> context = std::make_unique<OpenGLContextEGLX11>(wi);
     27   context->m_display = m_display;
     28 
     29   if (!context->CreateContextAndSurface(m_version, m_context, false))
     30     return nullptr;
     31 
     32   return context;
     33 }
     34 
     35 EGLDisplay OpenGLContextEGLX11::GetPlatformDisplay(Error* error)
     36 {
     37   EGLDisplay dpy = TryGetPlatformDisplay(EGL_PLATFORM_X11_KHR, "EGL_EXT_platform_x11");
     38   if (dpy == EGL_NO_DISPLAY)
     39     dpy = GetFallbackDisplay(error);
     40 
     41   return dpy;
     42 }
     43 
     44 EGLSurface OpenGLContextEGLX11::CreatePlatformSurface(EGLConfig config, void* win, Error* error)
     45 {
     46   // This is hideous.. the EXT version requires a pointer to the window, whereas the base
     47   // version requires the window itself, casted to void*...
     48   EGLSurface surface = TryCreatePlatformSurface(config, &win, error);
     49   if (surface == EGL_NO_SURFACE)
     50     surface = CreateFallbackSurface(config, win, error);
     51 
     52   return surface;
     53 }