CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Metal.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#if defined(__OBJC__)
17#import <MetalKit/MetalKit.h>
18#define CE_MT_HANDLE(T) id<T>
19#else
20#define CE_MT_HANDLE(T) void*
21#endif
22
23#define CE_MT_SAFE_CAST
24
25#define CE_MT_POOLED(T) \
26 using Allocator = VKObjectAllocator; \
27 [[nodiscard]] static Allocator& getAllocator() noexcept; \
28 [[nodiscard]] static void* operator new(size_t size) noexcept; \
29 static void operator delete(void* p, std::size_t size) noexcept;
30
31namespace CeresEngine {
32
33#define CE_MT_RENDER_API_OBJECT_FORWARD(N) \
34 class MT##N; \
35 using MT##N##Ptr = RC<MT##N>;
37#undef CE_MT_RENDER_API_OBJECT_FORWARD
38
39 template<typename ChildTypeName, typename ParentType = void> class MTObject {
40 public:
46#if defined(CE_MT_SAFE_CAST)
47 return RC<ChildTypeName>(static_cast<ChildTypeName*>(ptr.get()));
48#else
49 return safeCast<ChildTypeName>(ptr);
50#endif
51 }
52
58 return RC<ChildTypeName>(dynamic_cast<ChildTypeName*>(ptr.get()));
59 }
60
65 [[nodiscard]] static ChildTypeName& cast(ParentType& object) {
66#if defined(CE_MT_SAFE_CAST)
67 return static_cast<ChildTypeName&>(object);
68#else
69 return dynamic_cast<ChildTypeName&>(object);
70#endif
71 }
72
77 [[nodiscard]] static const ChildTypeName& cast(const ParentType& object) {
78#if defined(CE_MT_SAFE_CAST)
79 return static_cast<const ChildTypeName&>(object);
80#else
81 return dynamic_cast<const ChildTypeName&>(object);
82#endif
83 }
84
89 [[nodiscard]] static ChildTypeName* cast(ParentType* object) {
90#if defined(CE_MT_SAFE_CAST)
91 return static_cast<ChildTypeName*>(object);
92#else
93 return safeCast<ChildTypeName*>(object);
94#endif
95 }
96
101 [[nodiscard]] static const ChildTypeName* cast(const ParentType* object) {
102#if defined(CE_MT_SAFE_CAST)
103 return static_cast<const ChildTypeName*>(object);
104#else
105 return safeCast<const ChildTypeName*>(object);
106#endif
107 }
108
113 [[nodiscard]] static ChildTypeName* safeCast(ParentType* object) { return dynamic_cast<ChildTypeName*>(object); }
114
119 [[nodiscard]] static const ChildTypeName* safeCast(const ParentType* object) { return dynamic_cast<const ChildTypeName*>(object); }
120 };
121
122 template<typename ChildTypeName> class MTObject<ChildTypeName, void> {};
123
124 template<typename ChildTypeName, typename ParentType = void> class MTDeviceObject : public MTObject<ChildTypeName, ParentType> {
125 protected:
128
129 protected:
132 explicit MTDeviceObject(MTDevicePtr device) : deviceMT(*device) {}
133 };
134
136
137#if defined(__OBJC__)
138 [[nodiscard]] NSString* MTString(const String& string);
139 [[nodiscard]] NSString* MTString(const StringView& string);
140
142 [[nodiscard]] MTLViewport MTViewport(const Viewport& viewport);
143 [[nodiscard]] MTLScissorRect MTScissorRect(const Scissor& scissor);
144#endif
145
146} // namespace CeresEngine
#define CE_MT_RENDER_API_OBJECT_FORWARD(N)
Definition Metal.hpp:33
#define CE_RENDER_API_OBJECT_EACH(F)
A macro that invokes the function-macro F for every RenderAPI object type.
Definition Forward.hpp:18
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Pointer get() const noexcept
Definition SmartPtr.hpp:244
Metal RenderAPI device object.
Definition MTDevice.hpp:32
Definition Metal.hpp:124
MTDevice & deviceMT
The owning MTDevice instance.
Definition Metal.hpp:127
MTDeviceObject(MTDevicePtr device)
Creates a new MTDeviceObject from the given device.
Definition Metal.hpp:132
Definition Metal.hpp:39
static const ChildTypeName & cast(const ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition Metal.hpp:77
static ChildTypeName * safeCast(ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition Metal.hpp:113
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 Metal.hpp:57
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 Metal.hpp:45
static ChildTypeName & cast(ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition Metal.hpp:65
static ChildTypeName * cast(ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition Metal.hpp:89
static const ChildTypeName * cast(const ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition Metal.hpp:101
static const ChildTypeName * safeCast(const ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition Metal.hpp:119
Definition Application.hpp:19
void MTNotImplemented()
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition GPUGraphicsPipeline.hpp:281
Definition GPUGraphicsPipeline.hpp:214