opengl_context_egl.h (2237B)
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 #pragma once 5 6 #include "opengl_context.h" 7 8 #include "glad/egl.h" 9 10 class OpenGLContextEGL : public OpenGLContext 11 { 12 public: 13 OpenGLContextEGL(const WindowInfo& wi); 14 ~OpenGLContextEGL() override; 15 16 static std::unique_ptr<OpenGLContext> Create(const WindowInfo& wi, std::span<const Version> versions_to_try, 17 Error* error); 18 19 void* GetProcAddress(const char* name) override; 20 virtual bool ChangeSurface(const WindowInfo& new_wi) override; 21 virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; 22 bool SwapBuffers() override; 23 bool IsCurrent() const override; 24 bool MakeCurrent() override; 25 bool DoneCurrent() override; 26 bool SupportsNegativeSwapInterval() const override; 27 bool SetSwapInterval(s32 interval) override; 28 virtual std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) override; 29 30 protected: 31 virtual EGLDisplay GetPlatformDisplay(Error* error); 32 virtual EGLSurface CreatePlatformSurface(EGLConfig config, void* win, Error* error); 33 34 EGLDisplay TryGetPlatformDisplay(EGLenum platform, const char* platform_ext); 35 EGLSurface TryCreatePlatformSurface(EGLConfig config, void* window, Error* error); 36 EGLDisplay GetFallbackDisplay(Error* error); 37 EGLSurface CreateFallbackSurface(EGLConfig config, void* window, Error* error); 38 39 bool Initialize(std::span<const Version> versions_to_try, Error* error); 40 bool CreateContext(const Version& version, EGLContext share_context); 41 bool CreateContextAndSurface(const Version& version, EGLContext share_context, bool make_current); 42 bool CreateSurface(); 43 bool CreatePBufferSurface(); 44 bool CheckConfigSurfaceFormat(EGLConfig config, GPUTexture::Format format); 45 GPUTexture::Format GetSurfaceTextureFormat() const; 46 void DestroyContext(); 47 void DestroySurface(); 48 49 EGLDisplay m_display = EGL_NO_DISPLAY; 50 EGLSurface m_surface = EGL_NO_SURFACE; 51 EGLContext m_context = EGL_NO_CONTEXT; 52 53 EGLConfig m_config = {}; 54 55 bool m_use_ext_platform_base = false; 56 bool m_supports_negative_swap_interval = false; 57 };