30#define __DeclarePluginContext() \
32 static Graphics::GraphicsContextState __state;\
33 static Graphics::GraphicsContextFunctionBundle __bundle;\
35 static void RegisterEntity(const Graphics::GraphicsEntityId id);\
36 static void DeregisterEntity(const Graphics::GraphicsEntityId id);\
37 static void DeregisterEntityImmediate(const Graphics::GraphicsEntityId id);\
38 static bool IsEntityRegistered(const Graphics::GraphicsEntityId id);\
39 static void Destroy(); \
40 static Graphics::ContextEntityId GetContextId(const Graphics::GraphicsEntityId id); \
41 static const Graphics::ContextEntityId& GetContextIdRef(const Graphics::GraphicsEntityId id); \
42 static void BeginBulkRegister(); \
43 static void EndBulkRegister(); \
46#define __DeclareContext() \
47 __DeclarePluginContext(); \
48 static void Defragment();
51#define __ImplementPluginContext(ctx) \
52Graphics::GraphicsContextState ctx::__state; \
53Graphics::GraphicsContextFunctionBundle ctx::__bundle; \
54void ctx::RegisterEntity(const Graphics::GraphicsEntityId id) \
56 Graphics::GraphicsContext::InternalRegisterEntity(id, std::forward<Graphics::GraphicsContextState>(__state));\
59void ctx::DeregisterEntity(const Graphics::GraphicsEntityId id)\
61 Graphics::GraphicsContext::InternalDeregisterEntity(id, std::forward<Graphics::GraphicsContextState>(__state));\
64void ctx::DeregisterEntityImmediate(const Graphics::GraphicsEntityId id)\
66 IndexT index = __state.entitySliceMap.FindIndex(id);\
67 n_assert(index != InvalidIndex);\
68 auto cid = __state.entitySliceMap.ValueAtIndex(id.id, index);\
69 __state.Dealloc(cid);\
70 __state.entitySliceMap.EraseIndex(id, index);\
71 if (__state.Defragment != nullptr)\
72 __state.Defragment();\
75bool ctx::IsEntityRegistered(const Graphics::GraphicsEntityId id)\
77 return __state.entitySliceMap.Contains(id);\
81 Graphics::GraphicsServer::Instance()->UnregisterGraphicsContext(&__bundle);\
83Graphics::ContextEntityId ctx::GetContextId(const Graphics::GraphicsEntityId id)\
85 IndexT idx = __state.entitySliceMap.FindIndex(id); \
86 if (idx == InvalidIndex) return Graphics::InvalidContextEntityId; \
87 else return __state.entitySliceMap.ValueAtIndex(id, idx); \
89const Graphics::ContextEntityId& ctx::GetContextIdRef(const Graphics::GraphicsEntityId id)\
91 IndexT idx = __state.entitySliceMap.FindIndex(id); \
92 n_assert(idx != InvalidIndex); \
93 return __state.entitySliceMap.ValueAtIndex(id, idx); \
95void ctx::BeginBulkRegister()\
97 __state.entitySliceMap.BeginBulkAdd();\
99void ctx::EndBulkRegister()\
101 __state.entitySliceMap.EndBulkAdd();\
104#define __ImplementContext(ctx, idAllocator) \
105__ImplementPluginContext(ctx);\
106void ctx::Defragment()\
108 Graphics::GraphicsContext::InternalDefragment(idAllocator, std::forward<Graphics::GraphicsContextState>(__state));\
111#define __CreatePluginContext() \
112 __state.Alloc = Alloc; \
113 __state.Dealloc = Dealloc;
115#define __CreateContext() \
116 __CreatePluginContext() \
117 __state.Defragment = Defragment;
161 while (!this->delayedRemoveQueue.
IsEmpty())
166 auto cid = this->entitySliceMap.
ValueAtIndex(eid.id, index);
187 template<
class ID_ALLOCATOR>
194template<
class ID_ALLOCATOR>
198 auto& freeIds = allocator.FreeIds();
204 SizeT size = freeIds.Size();
205 for (
SizeT i = size - 1; i >= 0; --i)
207 index = freeIds.Back();
209 dataSize = (uint32_t)allocator.Size();
210 if (index >= dataSize)
214 oldIndex = dataSize - 1;
215 lastId =
state.entities[oldIndex].id;
216 if (
state.OnInstanceMoved !=
nullptr)
217 state.OnInstanceMoved(index, oldIndex);
218 allocator.EraseIndexSwap(index);
219 state.entities.EraseIndexSwap(index);
220 mapIndex =
state.entitySliceMap.FindIndex(lastId);
223 state.entitySliceMap.ValueAtIndex(lastId, mapIndex) = index;
227 freeIds.Append(index);
static void InternalDefragment(ID_ALLOCATOR &allocator, Graphics::GraphicsContextState &&state)
Definition graphicscontext.h:196
friend class GraphicsServer
Definition graphicscontext.h:184
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
A view describes a camera which can observe a Stage.
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:22
uint32_t Id32
Definition id.h:138
id
Definition resourceid.h:37
Array< TYPE, STACK_SIZE > StackArray
Definition array.h:1890
Vulkan::GraphicsDeviceState state
Definition graphicscontext.h:143
void(* OnAttachEntity)(Graphics::GraphicsEntityId entity)
Definition graphicscontext.h:133
void(* OnRemoveEntity)(Graphics::GraphicsEntityId entity)
Definition graphicscontext.h:134
void(* OnDiscardView)(const Graphics::ViewId view)
Definition graphicscontext.h:132
GraphicsContextFunctionBundle()
Definition graphicscontext.h:137
void(* OnRenderDebug)(uint32_t flags)
Definition graphicscontext.h:128
void(* OnViewCreated)(const Graphics::ViewId view)
Definition graphicscontext.h:131
void(* OnViewportResized)(const uint framescriptHash, SizeT width, SizeT height)
Definition graphicscontext.h:135
A graphics context is a resource which holds a contextual representation for a graphics entity.
Definition graphicscontext.h:146
void(* OnDefragment)(uint32_t toIndex, uint32_t fromIndex)
called to manually handle fragmentation
Definition graphicscontext.h:157
void CleanupDelayedRemoveQueue()
Definition graphicscontext.h:159
void(* Dealloc)(ContextEntityId id)
Definition graphicscontext.h:152
void(* Defragment)()
Definition graphicscontext.h:153
void(* OnInstanceMoved)(uint32_t toIndex, uint32_t fromIndex)
called after a context entity has moved index
Definition graphicscontext.h:155
Util::StackArray< GraphicsEntityId, 8 > delayedRemoveQueue
Definition graphicscontext.h:147
Util::HashTable< GraphicsEntityId, ContextEntityId, 128, 64 > entitySliceMap
Definition graphicscontext.h:150
Util::Array< GraphicsEntityId > entities
Definition graphicscontext.h:149
ContextEntityId(* Alloc)()
Definition graphicscontext.h:151
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:47
int SizeT
Definition types.h:42
unsigned int uint
Definition types.h:33
int IndexT
Definition types.h:41