CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
WebGPU.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
13
15
16#import <webgpu.h>
17
18#define CE_WG_SAFE_CAST
19
20#define CE_WG_POOLED(T) \
21 using Allocator = VKObjectAllocator; \
22 [[nodiscard]] static Allocator& getAllocator() noexcept; \
23 [[nodiscard]] static void* operator new(size_t size) noexcept; \
24 static void operator delete(void* p, std::size_t size) noexcept;
25
26namespace CeresEngine {
27
28#define CE_WG_RENDER_API_OBJECT_FORWARD(N) \
29 class WG##N; \
30 using WG##N##Ptr = RC<WG##N>;
32#undef CE_WG_RENDER_API_OBJECT_FORWARD
33
34 template<typename ChildTypeName, typename ParentType = void> class WGObject {
35 public:
41#if defined(CE_WG_SAFE_CAST)
42 return RC<ChildTypeName>(static_cast<ChildTypeName*>(ptr.get()));
43#else
44 return safeCast<ChildTypeName>(ptr);
45#endif
46 }
47
53 return RC<ChildTypeName>(dynamic_cast<ChildTypeName*>(ptr.get()));
54 }
55
60 [[nodiscard]] static ChildTypeName& cast(ParentType& object) {
61#if defined(CE_WG_SAFE_CAST)
62 return static_cast<ChildTypeName&>(object);
63#else
64 return dynamic_cast<ChildTypeName&>(object);
65#endif
66 }
67
72 [[nodiscard]] static const ChildTypeName& cast(const ParentType& object) {
73#if defined(CE_WG_SAFE_CAST)
74 return static_cast<const ChildTypeName&>(object);
75#else
76 return dynamic_cast<const ChildTypeName&>(object);
77#endif
78 }
79
84 [[nodiscard]] static ChildTypeName* cast(ParentType* object) {
85#if defined(CE_WG_SAFE_CAST)
86 return static_cast<ChildTypeName*>(object);
87#else
88 return safeCast<ChildTypeName*>(object);
89#endif
90 }
91
96 [[nodiscard]] static const ChildTypeName* cast(const ParentType* object) {
97#if defined(CE_WG_SAFE_CAST)
98 return static_cast<const ChildTypeName*>(object);
99#else
100 return safeCast<const ChildTypeName*>(object);
101#endif
102 }
103
108 [[nodiscard]] static ChildTypeName* safeCast(ParentType* object) { return dynamic_cast<ChildTypeName*>(object); }
109
114 [[nodiscard]] static const ChildTypeName* safeCast(const ParentType* object) { return dynamic_cast<const ChildTypeName*>(object); }
115 };
116
117 template<typename ChildTypeName> class WGObject<ChildTypeName, void> {};
118
119 template<typename ChildTypeName, typename ParentType = void> class WGDeviceObject : public WGObject<ChildTypeName, ParentType> {
120 protected:
123
124 protected:
127 explicit WGDeviceObject(WGDevicePtr device) : deviceWG(*device) {}
128 };
129
131
135
136} // namespace CeresEngine
#define CE_RENDER_API_OBJECT_EACH(F)
A macro that invokes the function-macro F for every RenderAPI object type.
Definition Forward.hpp:18
#define CE_WG_RENDER_API_OBJECT_FORWARD(N)
Definition WebGPU.hpp:28
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Pointer get() const noexcept
Definition SmartPtr.hpp:244
WebGPU RenderAPI device object.
Definition WGDevice.hpp:32
Definition WebGPU.hpp:119
WGDeviceObject(WGDevicePtr device)
Creates a new WGDeviceObject from the given device.
Definition WebGPU.hpp:127
WGDevice & deviceWG
The owning WGDevice instance.
Definition WebGPU.hpp:122
Definition WebGPU.hpp:34
static const ChildTypeName * safeCast(const ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition WebGPU.hpp:114
static ChildTypeName & cast(ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition WebGPU.hpp:60
static RC< ChildTypeName > safeCast(const RC< ParentType > &ptr)
Safely casts a RC containing a ParentType pointer to a pointer to a pointer to a ChildTypeName.
Definition WebGPU.hpp:52
static const ChildTypeName * cast(const ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition WebGPU.hpp:96
static ChildTypeName * safeCast(ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition WebGPU.hpp:108
static const ChildTypeName & cast(const ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition WebGPU.hpp:72
static RC< ChildTypeName > cast(const RC< ParentType > &ptr)
Casts a RC containing a ParentType pointer to a pointer to a pointer to a ChildTypeName.
Definition WebGPU.hpp:40
static ChildTypeName * cast(ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition WebGPU.hpp:84
Definition Application.hpp:19
WGLResourceOptions WGResourceOptions(const GPUMemoryProperties &memoryProperty)
WGLViewport WGViewport(const Viewport &viewport)
void WGNotImplemented()
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
WGLScissorRect WGScissorRect(const Scissor &scissor)
Definition GPUGraphicsPipeline.hpp:281
Definition GPUGraphicsPipeline.hpp:214