candlewick 0.10.0
A tiny cross-platform renderer based on SDL3
Loading...
Searching...
No Matches
Device.h
Go to the documentation of this file.
1#pragma once
2
3#include "Core.h"
4#include "Tags.h"
5#include <SDL3/SDL_gpu.h>
6
7namespace candlewick {
8
13SDL_GPUShaderFormat
14auto_detect_shader_format_subset(const char *name = nullptr);
15
17struct Device {
18
19 explicit Device(NoInitT) noexcept;
20 explicit Device(SDL_GPUShaderFormat format_flags, bool debug_mode = false);
21 Device(const Device &) = delete;
22 Device(Device &&other) noexcept {
23 _device = other._device;
24 other._device = nullptr;
25 }
26
27 Device &operator=(const Device &) = delete;
28 Device &operator=(Device &&other) noexcept {
29 if (this != &other) {
30 this->destroy();
31 _device = other._device;
32 other._device = nullptr;
33 }
34 return *this;
35 }
36
37 void create(SDL_GPUShaderFormat format_flags, bool debug_mode = false);
38
39 operator SDL_GPUDevice *() const { return _device; }
40 operator bool() const { return _device; }
41
42 const char *driverName() const noexcept;
43
44 SDL_GPUShaderFormat shaderFormats() const {
45 return SDL_GetGPUShaderFormats(_device);
46 }
47
49 SDL_GPUDevice *release() noexcept {
50 auto *p = _device;
51 _device = nullptr;
52 return p;
53 }
54 void destroy() noexcept;
55
56 bool operator==(const Device &other) const {
57 return _device && (_device == other._device);
58 }
59
60private:
61 SDL_GPUDevice *_device;
62};
63
64inline Device::Device(NoInitT) noexcept : _device(nullptr) {}
65
66} // namespace candlewick
Definition Camera.h:8
SDL_GPUShaderFormat auto_detect_shader_format_subset(const char *name=nullptr)
Automatically detect which subset of shader formats (MSL, SPIR-V) are compatible with the device.
Device & operator=(const Device &)=delete
const char * driverName() const noexcept
SDL_GPUShaderFormat shaderFormats() const
Definition Device.h:44
Device(Device &&other) noexcept
Definition Device.h:22
Device(const Device &)=delete
Device(NoInitT) noexcept
Definition Device.h:64
SDL_GPUDevice * release() noexcept
Release ownership of and return the SDL_GPUDevice handle.
Definition Device.h:49
Device & operator=(Device &&other) noexcept
Definition Device.h:28
void create(SDL_GPUShaderFormat format_flags, bool debug_mode=false)
Device(SDL_GPUShaderFormat format_flags, bool debug_mode=false)
void destroy() noexcept
Tag type for non-initializing constructors (for e.g. RAII classes)
Definition Tags.h:6