opengl_context_wgl.h (1913B)
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 #include "opengl_loader.h" 8 9 #include "common/windows_headers.h" 10 11 #include "glad/wgl.h" 12 13 #include <optional> 14 15 class OpenGLContextWGL final : public OpenGLContext 16 { 17 public: 18 OpenGLContextWGL(const WindowInfo& wi); 19 ~OpenGLContextWGL() override; 20 21 static std::unique_ptr<OpenGLContext> Create(const WindowInfo& wi, std::span<const Version> versions_to_try, 22 Error* error); 23 24 void* GetProcAddress(const char* name) override; 25 bool ChangeSurface(const WindowInfo& new_wi) override; 26 void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; 27 bool SwapBuffers() override; 28 bool IsCurrent() const override; 29 bool MakeCurrent() override; 30 bool DoneCurrent() override; 31 bool SupportsNegativeSwapInterval() const override; 32 bool SetSwapInterval(s32 interval) override; 33 std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) override; 34 35 private: 36 ALWAYS_INLINE HWND GetHWND() const { return static_cast<HWND>(m_wi.window_handle); } 37 38 HDC GetDCAndSetPixelFormat(HWND hwnd, Error* error); 39 40 bool Initialize(std::span<const Version> versions_to_try, Error* error); 41 bool InitializeDC(Error* error); 42 void ReleaseDC(); 43 bool CreatePBuffer(Error* error); 44 bool CreateAnyContext(HGLRC share_context, bool make_current, Error* error); 45 bool CreateVersionContext(const Version& version, HGLRC share_context, bool make_current, Error* error); 46 47 HDC m_dc = {}; 48 HGLRC m_rc = {}; 49 50 // Can't change pixel format once it's set for a RC. 51 std::optional<int> m_pixel_format; 52 53 // Dummy window for creating a PBuffer off when we're surfaceless. 54 HWND m_dummy_window = {}; 55 HDC m_dummy_dc = {}; 56 HPBUFFERARB m_pbuffer = {}; 57 };