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 "graphicsentity.h"
24#include "graphics/view.h"
25#include "debug/debughandler.h"
26
27namespace Graphics
28{
29
38
39using ViewIndependentCall = void(*)(const Graphics::FrameContext& ctx);
40using ViewDependentCall = void(*)(const ViewId view, const Graphics::FrameContext& ctx);
41
42
43class GraphicsContext;
46struct ViewId;
48{
51public:
55 virtual ~GraphicsServer();
56
58 void Open();
60 void Close();
61
68
71 const Util::StringAtom& name
72 , bool(*renderFunction)(const Math::rectangle<int>&, IndexT, IndexT)
73 , const Math::rectangle<int>& viewport
75 , std::function<void(IndexT, IndexT)> preViewCallback = nullptr
76 , std::function<void(IndexT, IndexT)> postViewCallback = nullptr
77 );
81 const Graphics::ViewId GetView(const Util::StringAtom& name);
83 void DiscardView(const Graphics::ViewId view);
85 const Graphics::ViewId GetCurrentView() const;
87 void SetCurrentView(const Graphics::ViewId view);
88
90 void AddEndFrameCall(void(*func)(IndexT frameIndex, IndexT bufferIndex));
92 void SetResizeCall(void(*)(const SizeT, const SizeT));
93
95 void AddWindow(const CoreGraphics::WindowId window);
97 void RemoveWindow(const CoreGraphics::WindowId window);
100
109
111 void RunPreLogic();
113 void RunPostLogic();
115 void Render();
116
118 void EndFrame();
120 void NewFrame();
121
123 const Timing::Time GetTime() const;
125 const Timing::Time GetFrameTime() const;
127 const IndexT GetFrameIndex() const;
128
130 void RenderDebug(uint32_t flags);
131
136
139
140private:
141
143
147
150
154
158
159 void (*resizeCall) (const SizeT, const SizeT);
160
166
169
172
173 bool isOpen;
174};
175
176//------------------------------------------------------------------------------
179static GraphicsEntityId
181{
182 return GraphicsServer::Instance()->CreateGraphicsEntity();
183}
184
185//------------------------------------------------------------------------------
188static void
190{
191 GraphicsServer::Instance()->DiscardGraphicsEntity(id);
192}
193
194//------------------------------------------------------------------------------
197template<typename ... CONTEXTS>
198static void
200{
201 (CONTEXTS::RegisterEntity(id), ...);
202}
203
204//------------------------------------------------------------------------------
207template<typename ... CONTEXTS>
208static void
210{
211 (CONTEXTS::DeregisterEntity(id), ...);
212}
213
214//------------------------------------------------------------------------------
217template<typename ... CONTEXTS>
218static void
220{
221 (CONTEXTS::DeregisterEntityImmediate(id), ...);
222}
223
224//------------------------------------------------------------------------------
227inline void
228GraphicsServer::SetResizeCall(void(*func)(const SizeT windowWidth, const SizeT windowHeight))
229{
230 this->resizeCall = func;
231}
232
233//------------------------------------------------------------------------------
236inline void
241
242//------------------------------------------------------------------------------
245inline void
250
251//------------------------------------------------------------------------------
254inline void
259
260//------------------------------------------------------------------------------
263inline void
268
269//------------------------------------------------------------------------------
272inline const Timing::Time
274{
275 return this->frameContext.time;
276}
277
278//------------------------------------------------------------------------------
281inline const Timing::Time
283{
284 return this->frameContext.frameTime;
285}
286
287//------------------------------------------------------------------------------
290inline const IndexT
292{
293 return this->frameContext.frameIndex;
294}
295
296
297
298} // namespace Graphics
The common base class of Nebula.
Definition refcounted.h:38
Definition graphicscontext.h:175
Graphics::ViewId currentView
Definition graphicsserver.h:153
const Util::Array< CoreGraphics::WindowId > & GetWindows() const
Get windows.
Definition graphicsserver.cc:392
void DiscardView(const Graphics::ViewId view)
discard view
Definition graphicsserver.cc:459
void Render()
Render views.
Definition graphicsserver.cc:604
void SetupPreLogicViewCalls(const Util::Array< ViewDependentCall > &calls)
Setup per-view calls.
Definition graphicsserver.h:255
void RunPostLogic()
Run post-logic calls.
Definition graphicsserver.cc:588
Util::Dictionary< Util::StringAtom, Graphics::ViewId > viewsByName
Definition graphicsserver.h:151
void SetResizeCall(void(*)(const SizeT, const SizeT))
Set a function to be run when resize.
Definition graphicsserver.h:228
void DiscardGraphicsEntity(const GraphicsEntityId id)
discard graphics entity
Definition graphicsserver.cc:343
SizeT maxWindowWidth
Definition graphicsserver.h:171
void Close()
closes the graphics server
Definition graphicsserver.cc:238
Util::Array< ViewIndependentCall > postLogicCalls
Definition graphicsserver.h:167
Graphics::ViewId CreateView(const Util::StringAtom &name, bool(*renderFunction)(const Math::rectangle< int > &, IndexT, IndexT), const Math::rectangle< int > &viewport, Graphics::StageMask stageMask=PRIMARY_STAGE_MASK, std::function< void(IndexT, IndexT)> preViewCallback=nullptr, std::function< void(IndexT, IndexT)> postViewCallback=nullptr)
create a new view with a new framescript
Definition graphicsserver.cc:401
const Timing::Time GetFrameTime() const
get frame time in seconds
Definition graphicsserver.h:282
Util::Array< GraphicsContextState * > states
Definition graphicsserver.h:149
const Graphics::ViewId GetView(const Util::StringAtom &name)
Get view by name.
Definition graphicsserver.cc:485
void NewFrame()
Progress to next frame.
Definition graphicsserver.cc:695
void SetupPreLogicCalls(const Util::Array< ViewIndependentCall > &calls)
Setup pre game logic graphics calls.
Definition graphicsserver.h:237
GraphicsEntityId CreateGraphicsEntity()
create graphics entity
Definition graphicsserver.cc:332
FrameContext frameContext
Definition graphicsserver.h:146
Util::Array< GraphicsContextFunctionBundle * > contexts
Definition graphicsserver.h:148
Util::Array< ViewDependentCall > preLogicViewCalls
Definition graphicsserver.h:168
GraphicsServer()
constructor
Definition graphicsserver.cc:42
void AddEndFrameCall(void(*func)(IndexT frameIndex, IndexT bufferIndex))
Add callback to run just before frame is finished.
Definition graphicsserver.cc:503
const Timing::Time GetTime() const
get total time in seconds
Definition graphicsserver.h:273
const IndexT GetFrameIndex() const
get frame index
Definition graphicsserver.h:291
Ptr< CoreGraphics::ShapeRenderer > shapeRenderer
Definition graphicsserver.h:164
void SetupPostLogicCalls(const Util::Array< ViewIndependentCall > &calls)
Setup post game logic graphics calls.
Definition graphicsserver.h:246
bool OnWindowResized(CoreGraphics::WindowId wndId)
call when the window has been resized
Definition graphicsserver.cc:307
Ptr< CoreGraphics::ShaderServer > shaderServer
Definition graphicsserver.h:163
void AddWindow(const CoreGraphics::WindowId window)
Add window to update.
Definition graphicsserver.cc:361
bool isOpen
Definition graphicsserver.h:173
Ids::IdGenerationPool entityPool
Definition graphicsserver.h:142
void RemoveWindow(const CoreGraphics::WindowId window)
Remove window.
Definition graphicsserver.cc:381
Util::Array< std::function< void(IndexT, IndexT)> > postViewCallbacks
Definition graphicsserver.h:156
Ptr< FrameSync::FrameSyncTimer > timer
Definition graphicsserver.h:144
Util::Array< CoreGraphics::WindowId > windows
Definition graphicsserver.h:170
void Open()
opens the graphics server
Definition graphicsserver.cc:64
__DeclareSingleton(GraphicsServer)
Util::Array< Graphics::ViewId > views
Definition graphicsserver.h:152
void RenderDebug(uint32_t flags)
debug rendering
Definition graphicsserver.cc:512
Util::Array< std::function< void(IndexT, IndexT)> > endFrameCallbacks
Definition graphicsserver.h:157
Ptr< CoreGraphics::TextRenderer > textRenderer
Definition graphicsserver.h:165
void RegisterGraphicsContext(GraphicsContextFunctionBundle *context, GraphicsContextState *state)
register function bundle from graphics context, see GraphicsContextType::Create
Definition graphicsserver.cc:277
SizeT maxWindowHeight
Definition graphicsserver.h:171
bool graphicsDevice
Definition graphicsserver.h:162
void SetupPostLogicViewCalls(const Util::Array< ViewDependentCall > &calls)
Setup per-view calls.
Definition graphicsserver.h:264
Util::Array< ViewIndependentCall > preLogicCalls
Definition graphicsserver.h:167
void UnregisterGraphicsContext(GraphicsContextFunctionBundle *context)
unregister function bundle
Definition graphicsserver.cc:295
void RunPreLogic()
Run pre-logic calls.
Definition graphicsserver.cc:526
void EndFrame()
End the frame and submit.
Definition graphicsserver.cc:666
Util::Array< ViewDependentCall > postLogicViewCalls
Definition graphicsserver.h:168
Ptr< CoreGraphics::DisplayDevice > displayDevice
Definition graphicsserver.h:161
void SetCurrentView(const Graphics::ViewId view)
set current view (do not use unless you know what you are doing since this is normally handled by the...
Definition graphicsserver.cc:476
bool IsValidGraphicsEntity(const GraphicsEntityId id)
check if graphics entity is valid
Definition graphicsserver.cc:352
virtual ~GraphicsServer()
destructor
Definition graphicsserver.cc:55
bool ownsTimer
Definition graphicsserver.h:145
void(* resizeCall)(const SizeT, const SizeT)
Definition graphicsserver.h:159
Util::Array< std::function< void(IndexT, IndexT)> > preViewCallbacks
Definition graphicsserver.h:155
const Graphics::ViewId GetCurrentView() const
get current view
Definition graphicsserver.cc:494
__DeclareClass(GraphicsServer)
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
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:22
static GraphicsEntityId CreateEntity()
Definition graphicsserver.h:180
void(*)(const Graphics::FrameContext &ctx) ViewIndependentCall
Definition graphicsserver.h:39
static constexpr StageMask PRIMARY_STAGE_MASK
Definition view.h:24
static void RegisterEntity(const GraphicsEntityId id)
Definition graphicsserver.h:199
uint16_t StageMask
Definition view.h:23
static void DeregisterEntityImmediate(const GraphicsEntityId id)
Definition graphicsserver.h:219
void(*)(const ViewId view, const Graphics::FrameContext &ctx) ViewDependentCall
Definition graphicsserver.h:40
static void DeregisterEntity(const GraphicsEntityId id)
Definition graphicsserver.h:209
static void DestroyEntity(const GraphicsEntityId id)
Definition graphicsserver.h:189
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 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:126
A graphics context is a resource which holds a contextual representation for a graphics entity.
Definition graphicscontext.h:146
The graphics entity is only an Id, to which we can attach GraphicsContexts.
Definition graphicsentity.h:16
Definition view.h:34
int SizeT
Definition types.h:42
int IndexT
Definition types.h:41