29#define __DeclarePluginContext() \
31 static Graphics::GraphicsContextState __state;\
32 static Graphics::GraphicsContextFunctionBundle __bundle;\
34 static void RegisterEntity(const Graphics::GraphicsEntityId id);\
35 static void DeregisterEntity(const Graphics::GraphicsEntityId id);\
36 static bool IsEntityRegistered(const Graphics::GraphicsEntityId id);\
37 static void Destroy(); \
38 static Graphics::ContextEntityId GetContextId(const Graphics::GraphicsEntityId id); \
39 static const Graphics::ContextEntityId& GetContextIdRef(const Graphics::GraphicsEntityId id); \
40 static void BeginBulkRegister(); \
41 static void EndBulkRegister(); \
44#define __DeclareContext() \
45 __DeclarePluginContext(); \
46 static void Defragment();
49#define __ImplementPluginContext(ctx) \
50Graphics::GraphicsContextState ctx::__state; \
51Graphics::GraphicsContextFunctionBundle ctx::__bundle; \
52void ctx::RegisterEntity(const Graphics::GraphicsEntityId id) \
54 Graphics::GraphicsContext::InternalRegisterEntity(id, std::forward<Graphics::GraphicsContextState>(__state));\
57void ctx::DeregisterEntity(const Graphics::GraphicsEntityId id)\
59 Graphics::GraphicsContext::InternalDeregisterEntity(id, std::forward<Graphics::GraphicsContextState>(__state));\
62bool ctx::IsEntityRegistered(const Graphics::GraphicsEntityId id)\
64 return __state.entitySliceMap.Contains(id);\
68 Graphics::GraphicsServer::Instance()->UnregisterGraphicsContext(&__bundle);\
70Graphics::ContextEntityId ctx::GetContextId(const Graphics::GraphicsEntityId id)\
72 IndexT idx = __state.entitySliceMap.FindIndex(id); \
73 if (idx == InvalidIndex) return Graphics::InvalidContextEntityId; \
74 else return __state.entitySliceMap.ValueAtIndex(id, idx); \
76const Graphics::ContextEntityId& ctx::GetContextIdRef(const Graphics::GraphicsEntityId id)\
78 IndexT idx = __state.entitySliceMap.FindIndex(id); \
79 n_assert(idx != InvalidIndex); \
80 return __state.entitySliceMap.ValueAtIndex(id, idx); \
82void ctx::BeginBulkRegister()\
84 __state.entitySliceMap.BeginBulkAdd();\
86void ctx::EndBulkRegister()\
88 __state.entitySliceMap.EndBulkAdd();\
91#define __ImplementContext(ctx, idAllocator) \
92__ImplementPluginContext(ctx);\
93void ctx::Defragment()\
95 Graphics::GraphicsContext::InternalDefragment(idAllocator, std::forward<Graphics::GraphicsContextState>(__state));\
98#define __CreatePluginContext() \
99 __state.Alloc = Alloc; \
100 __state.Dealloc = Dealloc;
102#define __CreateContext() \
103 __CreatePluginContext() \
104 __state.Defragment = Defragment;
145 void(*OnInstanceMoved)(uint32_t toIndex, uint32_t fromIndex);
147 void(*OnDefragment)(uint32_t toIndex, uint32_t fromIndex);
151 while (!this->delayedRemoveQueue.
IsEmpty())
156 auto cid = this->entitySliceMap.
ValueAtIndex(eid.id, index);
177 template<
class ID_ALLOCATOR>
184template<
class ID_ALLOCATOR>
188 auto& freeIds = allocator.FreeIds();
194 SizeT size = freeIds.Size();
195 for (
SizeT i = size - 1; i >= 0; --i)
197 index = freeIds.Back();
199 dataSize = (uint32_t)allocator.Size();
200 if (index >= dataSize)
204 oldIndex = dataSize - 1;
205 lastId =
state.entities[oldIndex].id;
206 if (
state.OnInstanceMoved !=
nullptr)
207 state.OnInstanceMoved(index, oldIndex);
208 allocator.EraseIndexSwap(index);
209 state.entities.EraseIndexSwap(index);
210 mapIndex =
state.entitySliceMap.FindIndex(lastId);
213 state.entitySliceMap.ValueAtIndex(lastId, mapIndex) = index;
217 freeIds.Append(index);
Definition graphicscontext.h:165
static void InternalDefragment(ID_ALLOCATOR &allocator, Graphics::GraphicsContextState &&state)
Definition graphicscontext.h:186
static void InternalDeregisterEntity(const Graphics::GraphicsEntityId id, Graphics::GraphicsContextState &&state)
Definition graphicscontext.cc:52
static void InternalRegisterEntity(const Graphics::GraphicsEntityId id, Graphics::GraphicsContextState &&state)
Definition graphicscontext.cc:31
GraphicsContext()
constructor
Definition graphicscontext.cc:14
virtual ~GraphicsContext()
destructor
Definition graphicscontext.cc:22
The graphics server is the main singleton for the Graphics subsystem.
Definition graphicsserver.h:47
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:60
bool IsEmpty() const
return true if array empty
Definition array.h:1016
void EraseIndexSwap(IndexT index)
erase element at index, fill gap by swapping in last element, destroys sorting!
Definition array.h:1058
Organizes key/value pairs by a hash code.
Definition hashtable.h:42
IndexT FindIndex(const KEYTYPE &key) const
find index in bucket
Definition hashtable.h:580
VALUETYPE & ValueAtIndex(const KEYTYPE &key, IndexT i) const
get value from key and bucket
Definition hashtable.h:597
void EraseIndex(const KEYTYPE &key, IndexT i)
erase an entry with known index
Definition hashtable.h:533
#define n_assert(exp)
Definition debug.h:50
#define ID_32_TYPE(x)
Definition id.h:16
Implements the shader server used by Vulkan.
Definition cameramanager.h:21
uint32_t Id32
Definition id.h:138
id
Definition resourceid.h:37
Vulkan::GraphicsDeviceState state
Definition graphicscontext.h:133
Definition graphicscontext.h:114
void(* OnViewCreated)(const Ptr< Graphics::View > &view)
Definition graphicscontext.h:121
void(* OnAttachEntity)(Graphics::GraphicsEntityId entity)
Definition graphicscontext.h:123
void(* OnRemoveEntity)(Graphics::GraphicsEntityId entity)
Definition graphicscontext.h:124
void(* OnWindowResized)(const CoreGraphics::WindowId windowId, SizeT width, SizeT height)
Definition graphicscontext.h:125
void(* OnDiscardView)(const Ptr< Graphics::View > &view)
Definition graphicscontext.h:122
GraphicsContextFunctionBundle()
Definition graphicscontext.h:127
void(* OnRenderDebug)(uint32_t flags)
Definition graphicscontext.h:116
void(* OnStageCreated)(const Ptr< Graphics::Stage > &stage)
Definition graphicscontext.h:119
void(* OnDiscardStage)(const Ptr< Graphics::Stage > &stage)
Definition graphicscontext.h:120
A graphics context is a resource which holds a contextual representation for a graphics entity.
Definition graphicscontext.h:136
void CleanupDelayedRemoveQueue()
Definition graphicscontext.h:149
Util::StackArray< GraphicsEntityId, 8 > delayedRemoveQueue
Definition graphicscontext.h:137
Util::HashTable< GraphicsEntityId, ContextEntityId, 128, 64 > entitySliceMap
Definition graphicscontext.h:140
Util::Array< GraphicsEntityId > entities
Definition graphicscontext.h:139
The graphics entity is only an Id, to which we can attach GraphicsContexts.
Definition graphicsentity.h:16
Typedefs for the Timing subsystem.
static const int InvalidIndex
Definition types.h:54
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48