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 MetalViewBase;
23
24// Forward decl
25struct MetalView;
26
28using MetalViewRaw = SDL_MetalView;
29
36
42struct MetalViewBase : ResourceBaseT<MetalViewRaw>
43{
45
58 void Destroy();
59
69 void* GetLayer();
70};
71
80{
81 using MetalViewBase::MetalViewBase;
82
90 constexpr explicit MetalView(MetalViewRaw resource) noexcept
91 : MetalViewBase(resource)
92 {
93 }
94
96 constexpr MetalView(MetalView&& other) noexcept
97 : MetalView(other.release())
98 {
99 }
100
121 MetalView(WindowRef window);
122
124 ~MetalView() { SDL_Metal_DestroyView(get()); }
125
127 constexpr MetalView& operator=(MetalView&& other) noexcept
128 {
129 swap(*this, other);
130 return *this;
131 }
132};
133
155{
156 return MetalView(window);
157}
158
160 : MetalView(SDL_Metal_CreateView(window))
161{
162}
163
179{
180 SDL_Metal_DestroyView(view);
181}
182
184
195inline void* Metal_GetLayer(MetalViewRef view)
196{
197 return SDL_Metal_GetLayer(view);
198}
199
201
203
204} // namespace SDL
205
206#endif /* SDL3PP_METAL_H_ */
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
void Destroy()
Destroy an existing MetalView object.
Definition SDL3pp_metal.h:183
SDL_MetalView MetalViewRaw
Alias to raw representation for MetalView.
Definition SDL3pp_metal.h:28
ResourceRefT< MetalViewBase > MetalViewRef
Reference for MetalView.
Definition SDL3pp_metal.h:35
void * Metal_GetLayer(MetalViewRef view)
Get a pointer to the backing CAMetalLayer for the given view.
Definition SDL3pp_metal.h:195
void * GetLayer()
Get a pointer to the backing CAMetalLayer for the given view.
Definition SDL3pp_metal.h:200
MetalView Metal_CreateView(WindowRef window)
Create a CAMetalLayer-backed NSView/UIView and attach it to the specified window.
Definition SDL3pp_metal.h:154
void Metal_DestroyView(MetalViewRaw view)
Destroy an existing MetalView object.
Definition SDL3pp_metal.h:178
ResourceRefT< WindowBase > WindowRef
Reference for Window.
Definition SDL3pp_video.h:57
Main include header for the SDL3pp library.
Base class to MetalView.
Definition SDL3pp_metal.h:43
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A handle to a CAMetalLayer-backed NSView (macOS) or UIView (iOS/tvOS).
Definition SDL3pp_metal.h:80
constexpr MetalView(MetalView &&other) noexcept
Move constructor.
Definition SDL3pp_metal.h:96
constexpr MetalView & operator=(MetalView &&other) noexcept
Assignment operator.
Definition SDL3pp_metal.h:127
constexpr MetalView(MetalViewRaw resource) noexcept
Constructs from raw MetalView.
Definition SDL3pp_metal.h:90
~MetalView()
Destructor.
Definition SDL3pp_metal.h:124
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93