Nebula
Loading...
Searching...
No Matches
graphicsserver.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
13//------------------------------------------------------------------------------
14#include "core/refcounted.h"
16#include "util/stringatom.h"
18#include "stage.h"
19#include "graphicsentity.h"
25#include "debug/debughandler.h"
26
27namespace Graphics
28{
29
38
39using ViewIndependentCall = void(*)(const Graphics::FrameContext& ctx);
40using ViewDependentCall = void(*)(const Ptr<Graphics::View>& view, const Graphics::FrameContext& ctx);
41
42class GraphicsContext;
45class View;
47{
50public:
54 virtual ~GraphicsServer();
55
57 void Open();
59 void Close();
60
67
69 Ptr<View> CreateView(const Util::StringAtom& name, void(*)(const Math::rectangle<int>&, IndexT, IndexT), const Math::rectangle<int>& viewport);
73 const Ptr<View>& GetView(const Util::StringAtom& name);
75 void DiscardView(const Ptr<View>& view);
77 const Ptr<View>& GetCurrentView() const;
79 void SetCurrentView(const Ptr<View>& view);
80
81 using PreViewCallback = void(*)(IndexT, IndexT);
82 using PostViewCallback = void(*)(IndexT, IndexT);
84 void AddPreViewCall(PreViewCallback callback);
86 void AddPostViewCall(PostViewCallback callback);
88 void SetResizeCall(void(*)(const SizeT, const SizeT));
89
97 void SetSwapInfo(const SwapInfo& info);
98
100 Ptr<Stage> CreateStage(const Util::StringAtom& name, bool main);
102 void DiscardStage(const Ptr<Stage>& stage);
103
112
114 void RunPreLogic();
116 void RunPostLogic();
118 void Render();
119
121 void EndFrame();
123 void NewFrame();
124
126 const Timing::Time GetTime() const;
128 const Timing::Time GetFrameTime() const;
130 const IndexT GetFrameIndex() const;
131
133 void RenderDebug(uint32_t flags);
134
139
142
143private:
144
146
150
153
158
159
162
163 void (*resizeCall) (const SizeT, const SizeT);
164
170
173
175
176 bool isOpen;
177};
178
179//------------------------------------------------------------------------------
182static GraphicsEntityId
184{
185 return GraphicsServer::Instance()->CreateGraphicsEntity();
186}
187
188//------------------------------------------------------------------------------
191static void
193{
194 GraphicsServer::Instance()->DiscardGraphicsEntity(id);
195}
196
197//------------------------------------------------------------------------------
200template<typename ... CONTEXTS>
201static void
203{
204 (CONTEXTS::RegisterEntity(id), ...);
205}
206
207//------------------------------------------------------------------------------
210template<typename ... CONTEXTS>
211static void
213{
214 (CONTEXTS::DeregisterEntity(id), ...);
215}
216
217//------------------------------------------------------------------------------
220inline const Ptr<View>&
222{
223 return this->viewsByName[name];
224}
225
226//------------------------------------------------------------------------------
229inline const Ptr<View>&
231{
232 return this->currentView;
233}
234
235//------------------------------------------------------------------------------
238inline void
243
244//------------------------------------------------------------------------------
247inline void
252
253//------------------------------------------------------------------------------
256inline void
257GraphicsServer::SetResizeCall(void(*func)(const SizeT windowWidth, const SizeT windowHeight))
258{
259 this->resizeCall = func;
260}
261
262//------------------------------------------------------------------------------
265inline void
267{
268 this->swapInfo = info;
269}
270
271//------------------------------------------------------------------------------
274inline void
279
280//------------------------------------------------------------------------------
283inline void
288
289//------------------------------------------------------------------------------
292inline void
297
298//------------------------------------------------------------------------------
301inline void
306
307//------------------------------------------------------------------------------
310inline const Timing::Time
312{
313 return this->frameContext.time;
314}
315
316//------------------------------------------------------------------------------
319inline const Timing::Time
321{
322 return this->frameContext.frameTime;
323}
324
325//------------------------------------------------------------------------------
328inline const IndexT
330{
331 return this->frameContext.frameIndex;
332}
333
334
335
336} // namespace Graphics
The common base class of Nebula.
Definition refcounted.h:38
Definition graphicscontext.h:165
The graphics server is the main singleton for the Graphics subsystem.
Definition graphicsserver.h:47
void Render()
Render views.
Definition graphicsserver.cc:544
void SetupPreLogicViewCalls(const Util::Array< ViewDependentCall > &calls)
Setup per-view calls.
Definition graphicsserver.h:293
Util::Array< PostViewCallback > postViewCallbacks
Definition graphicsserver.h:161
void RunPostLogic()
Run post-logic calls.
Definition graphicsserver.cc:507
void DiscardStage(const Ptr< Stage > &stage)
discard stage
Definition graphicsserver.cc:350
void SetResizeCall(void(*)(const SizeT, const SizeT))
Set a function to be run when resize.
Definition graphicsserver.h:257
void SetCurrentView(const Ptr< View > &view)
set current view (do not use unless you know what you are doing since this is normally handled by the...
Definition graphicsserver.cc:421
void DiscardGraphicsEntity(const GraphicsEntityId id)
discard graphics entity
Definition graphicsserver.cc:321
void(*)(IndexT, IndexT) PreViewCallback
Definition graphicsserver.h:81
void Close()
closes the graphics server
Definition graphicsserver.cc:233
void AddPostViewCall(PostViewCallback callback)
Add callback for rendering after the views are processed.
Definition graphicsserver.h:248
Util::Array< ViewIndependentCall > postLogicCalls
Definition graphicsserver.h:171
Util::Dictionary< Util::StringAtom, Ptr< View > > viewsByName
Definition graphicsserver.h:155
const Timing::Time GetFrameTime() const
get frame time in seconds
Definition graphicsserver.h:320
Util::Array< GraphicsContextState * > states
Definition graphicsserver.h:152
Ptr< View > CreateView(const Util::StringAtom &name, void(*)(const Math::rectangle< int > &, IndexT, IndexT), const Math::rectangle< int > &viewport)
create a new view with a new framescript
Definition graphicsserver.cc:361
void NewFrame()
Progress to next frame.
Definition graphicsserver.cc:622
void SetupPreLogicCalls(const Util::Array< ViewIndependentCall > &calls)
Setup pre game logic graphics calls.
Definition graphicsserver.h:275
GraphicsEntityId CreateGraphicsEntity()
create graphics entity
Definition graphicsserver.cc:310
FrameContext frameContext
Definition graphicsserver.h:149
Util::Array< GraphicsContextFunctionBundle * > contexts
Definition graphicsserver.h:151
Util::Array< ViewDependentCall > preLogicViewCalls
Definition graphicsserver.h:172
const Ptr< View > & GetCurrentView() const
get current view
Definition graphicsserver.h:230
GraphicsServer()
constructor
Definition graphicsserver.cc:42
const Timing::Time GetTime() const
get total time in seconds
Definition graphicsserver.h:311
void(*)(IndexT, IndexT) PostViewCallback
Definition graphicsserver.h:82
void OnWindowResized(CoreGraphics::WindowId wndId)
call when the window has been resized
Definition graphicsserver.cc:287
const IndexT GetFrameIndex() const
get frame index
Definition graphicsserver.h:329
Ptr< CoreGraphics::ShapeRenderer > shapeRenderer
Definition graphicsserver.h:168
void SetupPostLogicCalls(const Util::Array< ViewIndependentCall > &calls)
Setup post game logic graphics calls.
Definition graphicsserver.h:284
Ptr< CoreGraphics::ShaderServer > shaderServer
Definition graphicsserver.h:167
Util::Array< Ptr< Stage > > stages
Definition graphicsserver.h:154
bool isOpen
Definition graphicsserver.h:176
Ids::IdGenerationPool entityPool
Definition graphicsserver.h:145
Util::Array< PreViewCallback > preViewCallbacks
Definition graphicsserver.h:160
Ptr< FrameSync::FrameSyncTimer > timer
Definition graphicsserver.h:147
void DiscardView(const Ptr< View > &view)
discard view
Definition graphicsserver.cc:404
void Open()
opens the graphics server
Definition graphicsserver.cc:61
__DeclareSingleton(GraphicsServer)
const Ptr< View > & GetView(const Util::StringAtom &name)
Get view by name.
Definition graphicsserver.h:221
SwapInfo swapInfo
Definition graphicsserver.h:174
void RenderDebug(uint32_t flags)
debug rendering
Definition graphicsserver.cc:430
Ptr< CoreGraphics::TextRenderer > textRenderer
Definition graphicsserver.h:169
void RegisterGraphicsContext(GraphicsContextFunctionBundle *context, GraphicsContextState *state)
register function bundle from graphics context, see GraphicsContextType::Create
Definition graphicsserver.cc:265
bool graphicsDevice
Definition graphicsserver.h:166
void SetupPostLogicViewCalls(const Util::Array< ViewDependentCall > &calls)
Setup per-view calls.
Definition graphicsserver.h:302
void SetSwapInfo(const SwapInfo &info)
Setup the swap info.
Definition graphicsserver.h:266
Util::Array< ViewIndependentCall > preLogicCalls
Definition graphicsserver.h:171
void UnregisterGraphicsContext(GraphicsContextFunctionBundle *context)
unregister function bundle
Definition graphicsserver.cc:275
void RunPreLogic()
Run pre-logic calls.
Definition graphicsserver.cc:444
void AddPreViewCall(PreViewCallback callback)
Add callback for rendering before the views are processed.
Definition graphicsserver.h:239
Util::Array< Ptr< View > > views
Definition graphicsserver.h:156
void EndFrame()
End the frame and submit.
Definition graphicsserver.cc:577
Util::Array< ViewDependentCall > postLogicViewCalls
Definition graphicsserver.h:172
Ptr< CoreGraphics::DisplayDevice > displayDevice
Definition graphicsserver.h:165
Ptr< Stage > CreateStage(const Util::StringAtom &name, bool main)
create a new stage
Definition graphicsserver.cc:339
bool IsValidGraphicsEntity(const GraphicsEntityId id)
check if graphics entity is valid
Definition graphicsserver.cc:330
virtual ~GraphicsServer()
destructor
Definition graphicsserver.cc:52
bool ownsTimer
Definition graphicsserver.h:148
Ptr< View > currentView
Definition graphicsserver.h:157
void(* resizeCall)(const SizeT, const SizeT)
Definition graphicsserver.h:163
__DeclareClass(GraphicsServer)
A view describes a camera which can observe a Stage.
Definition view.h:23
Provides a system for creating array friendly id numbers with reuse and generations.
Definition idgenerationpool.h:43
A 2d rectangle class.
Definition rectangle.h:20
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
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition array.h:1334
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
A StringAtom.
Definition stringatom.h:22
Implements the shader server used by Vulkan.
Definition cameramanager.h:21
static GraphicsEntityId CreateEntity()
Definition graphicsserver.h:183
void(*)(const Graphics::FrameContext &ctx) ViewIndependentCall
Definition graphicsserver.h:39
void(*)(const Ptr< Graphics::View > &view, const Graphics::FrameContext &ctx) ViewDependentCall
Definition graphicsserver.h:40
static void RegisterEntity(const GraphicsEntityId id)
Definition graphicsserver.h:202
static void DeregisterEntity(const GraphicsEntityId id)
Definition graphicsserver.h:212
static void DestroyEntity(const GraphicsEntityId id)
Definition graphicsserver.h:192
int Tick
the tick datatype (one tick == 1 millisecond)
Definition time.h:20
double Time
the time datatype
Definition time.h:18
Vulkan::GraphicsDeviceState state
Definition commandbuffer.h:155
Definition graphicsdevice.h:101
texture type
Definition texture.h:25
Definition window.h:25
Definition graphicsserver.h:31
Timing::Time frameTime
Definition graphicsserver.h:34
Timing::Time time
Definition graphicsserver.h:32
IndexT bufferIndex
Definition graphicsserver.h:36
Timing::Tick ticks
Definition graphicsserver.h:33
IndexT frameIndex
Definition graphicsserver.h:35
Definition graphicscontext.h:114
A graphics context is a resource which holds a contextual representation for a graphics entity.
Definition graphicscontext.h:136
The graphics entity is only an Id, to which we can attach GraphicsContexts.
Definition graphicsentity.h:16
Definition graphicsserver.h:91
CoreGraphics::TextureId swapSource
Definition graphicsserver.h:93
CoreGraphics::SubmissionWaitEvent submission
Definition graphicsserver.h:94
void(* syncFunc)(CoreGraphics::CmdBufferId)
Definition graphicsserver.h:92
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48