Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Instance.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "utils/webgpu.hpp"
4
5namespace Graphic::Resource {
6class Instance {
7 public:
8 explicit Instance(wgpu::Instance wgpuInstance_) : wgpuInstance(wgpuInstance_) {}
10 {
11 if (wgpuInstance)
12 {
13 wgpuInstance.release();
14 wgpuInstance = nullptr;
15 }
16 }
17
18 Instance(Instance &other) = delete;
19 Instance &operator=(Instance &other) = delete;
20
21 // @note While using && ctor, you're destroying the previous Instance and will be invalid
22 Instance(Instance &&other) noexcept : wgpuInstance(other.wgpuInstance) { other.wgpuInstance = nullptr; }
23
24 // @note While using && assignement, you're destroying the previous Instance and will be invalid
25 Instance &operator=(Instance &&other) noexcept
26 {
27 if (this != &other)
28 {
29 if (wgpuInstance)
30 {
31 wgpuInstance.release();
32 }
33 wgpuInstance = std::move(other.wgpuInstance);
34 other.wgpuInstance = nullptr;
35 }
36 return *this;
37 }
38
39 wgpu::Instance &operator*(void) { return wgpuInstance; };
40 wgpu::Instance *operator->(void) { return &wgpuInstance; };
41
42 const wgpu::Instance &operator*(void) const { return wgpuInstance; };
43 const wgpu::Instance *operator->(void) const { return &wgpuInstance; };
44
45 private:
46 // @note We will assume that Instance is not null all the time
47 wgpu::Instance wgpuInstance = nullptr;
48};
49} // namespace Graphic::Resource
Instance(wgpu::Instance wgpuInstance_)
Definition Instance.hpp:8
Instance & operator=(Instance &&other) noexcept
Definition Instance.hpp:25
const wgpu::Instance & operator*(void) const
Definition Instance.hpp:42
Instance(Instance &other)=delete
Instance(Instance &&other) noexcept
Definition Instance.hpp:22
wgpu::Instance & operator*(void)
Definition Instance.hpp:39
wgpu::Instance wgpuInstance
Definition Instance.hpp:47
wgpu::Instance * operator->(void)
Definition Instance.hpp:40
~Instance()
Definition Instance.hpp:9
Instance & operator=(Instance &other)=delete
const wgpu::Instance * operator->(void) const
Definition Instance.hpp:43
Definition Adapter.hpp:5