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_agl.h (1743B)


      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 #if defined(__APPLE__) && defined(__OBJC__)
     10 #import <AppKit/AppKit.h>
     11 #else
     12 struct NSOpenGLContext;
     13 struct NSOpenGLPixelFormat;
     14 struct NSView;
     15 #define __bridge
     16 #endif
     17 
     18 class OpenGLContextAGL final : public OpenGLContext
     19 {
     20 public:
     21   OpenGLContextAGL(const WindowInfo& wi);
     22   ~OpenGLContextAGL() override;
     23 
     24   static std::unique_ptr<OpenGLContext> Create(const WindowInfo& wi, std::span<const Version> versions_to_try,
     25                                                Error* error);
     26 
     27   void* GetProcAddress(const char* name) override;
     28   bool ChangeSurface(const WindowInfo& new_wi) override;
     29   void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
     30   bool SwapBuffers() override;
     31   bool IsCurrent() const override;
     32   bool MakeCurrent() override;
     33   bool DoneCurrent() override;
     34   bool SupportsNegativeSwapInterval() const override;
     35   bool SetSwapInterval(s32 interval) override;
     36   std::unique_ptr<OpenGLContext> CreateSharedContext(const WindowInfo& wi, Error* error) override;
     37 
     38 private:
     39   ALWAYS_INLINE NSView* GetView() const { return static_cast<NSView*>((__bridge NSView*)m_wi.window_handle); }
     40 
     41   bool Initialize(std::span<const Version> versions_to_try, Error* error);
     42   bool CreateContext(NSOpenGLContext* share_context, int profile, bool make_current, Error* error);
     43   void BindContextToView();
     44 
     45   // returns true if dimensions have changed
     46   bool UpdateDimensions();
     47 
     48   NSOpenGLContext* m_context = nullptr;
     49   NSOpenGLPixelFormat* m_pixel_format = nullptr;
     50   void* m_opengl_module_handle = nullptr;
     51 };