opengl_context.h (1608B)
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 "window_info.h" 7 8 #include "common/types.h" 9 10 #include <memory> 11 #include <span> 12 13 class Error; 14 15 class OpenGLContext 16 { 17 public: 18 OpenGLContext(const WindowInfo& wi); 19 virtual ~OpenGLContext(); 20 21 enum class Profile 22 { 23 NoProfile, 24 Core, 25 ES 26 }; 27 28 struct Version 29 { 30 Profile profile; 31 int major_version; 32 int minor_version; 33 }; 34 35 ALWAYS_INLINE const WindowInfo& GetWindowInfo() const { return m_wi; } 36 ALWAYS_INLINE bool IsGLES() const { return (m_version.profile == Profile::ES); } 37 ALWAYS_INLINE u32 GetSurfaceWidth() const { return m_wi.surface_width; } 38 ALWAYS_INLINE u32 GetSurfaceHeight() const { return m_wi.surface_height; } 39 ALWAYS_INLINE GPUTexture::Format GetSurfaceFormat() const { return m_wi.surface_format; } 40 41 virtual void* GetProcAddress(const char* name) = 0; 42 virtual bool ChangeSurface(const WindowInfo& new_wi) = 0; 43 virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) = 0; 44 virtual bool SwapBuffers() = 0; 45 virtual bool IsCurrent() const = 0; 46 virtual bool MakeCurrent() = 0; 47 virtual bool DoneCurrent() = 0; 48 virtual bool SupportsNegativeSwapInterval() const = 0; 49 virtual bool SetSwapInterval(s32 interval) = 0; 50 virtual std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) = 0; 51 52 static std::unique_ptr<OpenGLContext> Create(const WindowInfo& wi, Error* error); 53 54 protected: 55 WindowInfo m_wi; 56 Version m_version = {}; 57 };