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
21// Forward decl
22struct MetalView;
23
25using MetalViewRaw = SDL_MetalView;
26
27// Forward decl
28struct MetalViewRef;
29
32{
34
37 : value(value)
38 {
39 }
40
42 constexpr MetalViewParam(std::nullptr_t _ = nullptr)
43 : value(0)
44 {
45 }
46
48 constexpr explicit operator bool() const { return !!value; }
49
51 constexpr auto operator<=>(const MetalViewParam& other) const = default;
52
54 constexpr operator MetalViewRaw() const { return value; }
55};
56
65{
66 MetalViewRaw m_resource = 0;
67
68public:
70 constexpr MetalView() = default;
71
79 constexpr explicit MetalView(const MetalViewRaw resource)
80 : m_resource(resource)
81 {
82 }
83
85 constexpr MetalView(const MetalView& other) = delete;
86
88 constexpr MetalView(MetalView&& other)
89 : MetalView(other.release())
90 {
91 }
92
93 constexpr MetalView(const MetalViewRef& other) = delete;
94
95 constexpr MetalView(MetalViewRef&& other) = delete;
96
116 : m_resource(SDL_Metal_CreateView(window))
117 {
118 }
119
121 ~MetalView() { SDL_Metal_DestroyView(m_resource); }
122
125 {
126 std::swap(m_resource, other.m_resource);
127 return *this;
128 }
129
131 constexpr MetalViewRaw get() const { return m_resource; }
132
135 {
136 auto r = m_resource;
137 m_resource = 0;
138 return r;
139 }
140
142 constexpr auto operator<=>(const MetalView& other) const = default;
143
145 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
146
148 constexpr explicit operator bool() const { return !!m_resource; }
149
151 constexpr operator MetalViewParam() const { return {m_resource}; }
152
164 void Destroy();
165
173 void* GetLayer();
174};
175
178{
187 : MetalView(resource.value)
188 {
189 }
190
193 : MetalView(other.get())
194 {
195 }
196
199};
200
220{
221 return MetalView(window);
222}
223
237{
238 SDL_Metal_DestroyView(view);
239}
240
242
252{
253 return SDL_Metal_GetLayer(view);
254}
255
256inline void* MetalView::GetLayer() { return SDL::Metal_GetLayer(m_resource); }
257
259
260} // namespace SDL
261
262#endif /* SDL3PP_METAL_H_ */
A handle to a CAMetalLayer-backed NSView (macOS) or UIView (iOS/tvOS).
Definition: SDL3pp_metal.h:65
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_metal.h:145
MetalView & operator=(MetalView other)
Assignment operator.
Definition: SDL3pp_metal.h:124
constexpr MetalView(const MetalView &other)=delete
Copy constructor.
constexpr MetalView(MetalView &&other)
Move constructor.
Definition: SDL3pp_metal.h:88
constexpr MetalView(const MetalViewRaw resource)
Constructs from MetalViewParam.
Definition: SDL3pp_metal.h:79
constexpr auto operator<=>(const MetalView &other) const =default
Comparison.
constexpr MetalViewRaw release()
Retrieves underlying MetalViewRaw and clear this.
Definition: SDL3pp_metal.h:134
~MetalView()
Destructor.
Definition: SDL3pp_metal.h:121
constexpr MetalViewRaw get() const
Retrieves underlying MetalViewRaw.
Definition: SDL3pp_metal.h:131
constexpr MetalView()=default
Default ctor.
MetalView(WindowParam window)
Create a CAMetalLayer-backed NSView/UIView and attach it to the specified window.
Definition: SDL3pp_metal.h:115
void * Metal_GetLayer(MetalViewParam view)
Get a pointer to the backing CAMetalLayer for the given view.
Definition: SDL3pp_metal.h:251
MetalView Metal_CreateView(WindowParam window)
Create a CAMetalLayer-backed NSView/UIView and attach it to the specified window.
Definition: SDL3pp_metal.h:219
void Destroy()
Destroy an existing MetalView object.
Definition: SDL3pp_metal.h:241
void * GetLayer()
Get a pointer to the backing CAMetalLayer for the given view.
Definition: SDL3pp_metal.h:256
SDL_MetalView MetalViewRaw
Alias to raw representation for MetalView.
Definition: SDL3pp_metal.h:25
void Metal_DestroyView(MetalViewRaw view)
Destroy an existing MetalView object.
Definition: SDL3pp_metal.h:236
Main include header for the SDL3pp library.
Safely wrap MetalView for non owning parameters.
Definition: SDL3pp_metal.h:32
constexpr MetalViewParam(MetalViewRaw value)
Constructs from MetalViewRaw.
Definition: SDL3pp_metal.h:36
constexpr MetalViewParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_metal.h:42
MetalViewRaw value
parameter's MetalViewRaw
Definition: SDL3pp_metal.h:33
constexpr auto operator<=>(const MetalViewParam &other) const =default
Comparison.
Semi-safe reference for MetalView.
Definition: SDL3pp_metal.h:178
MetalViewRef(const MetalViewRef &other)
Copy constructor.
Definition: SDL3pp_metal.h:192
~MetalViewRef()
Destructor.
Definition: SDL3pp_metal.h:198
MetalViewRef(MetalViewParam resource)
Constructs from MetalViewParam.
Definition: SDL3pp_metal.h:186
Safely wrap Window for non owning parameters.
Definition: SDL3pp_video.h:54