SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_metal.h
1#ifndef SDL3PP_METAL_H_
2#define SDL3PP_METAL_H_
3
4#include <SDL3/SDL_metal.h>
5#include "SDL3pp_video.h"
6
7namespace SDL {
8
20
21// Forward decl
22struct MetalView;
23
25using MetalViewRaw = SDL_MetalView;
26
33
41struct MetalView : ResourceBase<MetalViewRaw>
42{
44
52 constexpr explicit MetalView(MetalViewRaw resource) noexcept
53 : ResourceBase(resource)
54 {
55 }
56
58 constexpr MetalView(const MetalView& other) = delete;
59
61 constexpr MetalView(MetalView&& other) noexcept
62 : MetalView(other.release())
63 {
64 }
65
66 constexpr MetalView(const MetalViewRef& other) = delete;
67
68 constexpr MetalView(MetalViewRef&& other) = delete;
69
90 MetalView(WindowRef window);
91
93 ~MetalView() { SDL_Metal_DestroyView(get()); }
94
96 constexpr MetalView& operator=(MetalView&& other) noexcept
97 {
98 swap(*this, other);
99 return *this;
100 }
101
103 MetalView& operator=(const MetalView& other) = delete;
104
117 void Destroy();
118
128 void* GetLayer();
129};
130
152{
153 return MetalView(window);
154}
155
157 : MetalView(SDL_Metal_CreateView(window))
158{
159}
160
176{
177 SDL_Metal_DestroyView(view);
178}
179
181
192inline void* Metal_GetLayer(MetalViewRef view)
193{
194 return SDL_Metal_GetLayer(view);
195}
196
197inline void* MetalView::GetLayer() { return SDL::Metal_GetLayer(get()); }
198
200
201} // namespace SDL
202
203#endif /* SDL3PP_METAL_H_ */
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
ResourceRef< MetalView > MetalViewRef
Reference for MetalView.
Definition SDL3pp_metal.h:32
SDL_MetalView MetalViewRaw
Alias to raw representation for MetalView.
Definition SDL3pp_metal.h:25
void * Metal_GetLayer(MetalViewRef view)
Get a pointer to the backing CAMetalLayer for the given view.
Definition SDL3pp_metal.h:192
void Destroy()
Destroy an existing MetalView object.
Definition SDL3pp_metal.h:180
void * GetLayer()
Get a pointer to the backing CAMetalLayer for the given view.
Definition SDL3pp_metal.h:197
MetalView Metal_CreateView(WindowRef window)
Create a CAMetalLayer-backed NSView/UIView and attach it to the specified window.
Definition SDL3pp_metal.h:151
void Metal_DestroyView(MetalViewRaw view)
Destroy an existing MetalView object.
Definition SDL3pp_metal.h:175
ResourceRef< Window > WindowRef
Reference for Window.
Definition SDL3pp_video.h:54
Main include header for the SDL3pp library.
A handle to a CAMetalLayer-backed NSView (macOS) or UIView (iOS/tvOS).
Definition SDL3pp_metal.h:42
MetalView & operator=(const MetalView &other)=delete
Assignment operator.
constexpr MetalView(MetalView &&other) noexcept
Move constructor.
Definition SDL3pp_metal.h:61
constexpr MetalView(const MetalView &other)=delete
Copy constructor.
constexpr MetalView & operator=(MetalView &&other) noexcept
Assignment operator.
Definition SDL3pp_metal.h:96
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr MetalView(MetalViewRaw resource) noexcept
Constructs from raw MetalView.
Definition SDL3pp_metal.h:52
~MetalView()
Destructor.
Definition SDL3pp_metal.h:93
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156