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"
19#include "stage.h"
20#include "graphicsentity.h"
26#include "frame/frameserver.h"
27#include "debug/debughandler.h"
28
29namespace Graphics
30{
31
40
41using ViewIndependentCall = void(*)(const Graphics::FrameContext& ctx);
42using ViewDependentCall = void(*)(const Ptr<Graphics::View>& view, const Graphics::FrameContext& ctx);
43
44class GraphicsContext;
47class View;
49{
52public:
56 virtual ~GraphicsServer();
57
59 void Open();
61 void Close();
62
69
71 Ptr<View> CreateView(const Util::StringAtom& name, const IO::URI& framescript, const CoreGraphics::WindowId window = CoreGraphics::InvalidWindowId);
75 void DiscardView(const Ptr<View>& view);
77 const Ptr<View>& GetCurrentView() const;
79 void SetCurrentView(const Ptr<View>& view);
80
82 Ptr<Stage> CreateStage(const Util::StringAtom& name, bool main);
84 void DiscardStage(const Ptr<Stage>& stage);
85
94
96 void RunPreLogic();
98 void RunPostLogic();
100 void Render();
101
103 void EndFrame();
105 void NewFrame();
106
108 const Timing::Time GetTime() const;
110 const Timing::Time GetFrameTime() const;
112 const IndexT GetFrameIndex() const;
113
115 void RenderDebug(uint32_t flags);
116
121
124
125private:
127
129
133
136
141
148
151
152 bool isOpen;
153};
154
155//------------------------------------------------------------------------------
158static GraphicsEntityId
160{
161 return GraphicsServer::Instance()->CreateGraphicsEntity();
162}
163
164//------------------------------------------------------------------------------
167static void
169{
170 GraphicsServer::Instance()->DiscardGraphicsEntity(id);
171}
172
173//------------------------------------------------------------------------------
176template<typename ... CONTEXTS>
177static void
179{
180 (CONTEXTS::RegisterEntity(id), ...);
181}
182
183//------------------------------------------------------------------------------
186template<typename ... CONTEXTS>
187static void
189{
190 (CONTEXTS::DeregisterEntity(id), ...);
191}
192
193//------------------------------------------------------------------------------
196inline const Ptr<View>&
198{
199 return this->currentView;
200}
201
202//------------------------------------------------------------------------------
205inline void
210
211//------------------------------------------------------------------------------
214inline void
219
220//------------------------------------------------------------------------------
223inline void
228
229//------------------------------------------------------------------------------
232inline void
237
238//------------------------------------------------------------------------------
241inline const Timing::Time
243{
244 return this->frameContext.time;
245}
246
247//------------------------------------------------------------------------------
250inline const Timing::Time
252{
253 return this->frameContext.frameTime;
254}
255
256//------------------------------------------------------------------------------
259inline const IndexT
261{
262 return this->frameContext.frameIndex;
263}
264
265
266
267} // namespace Graphics
The common base class of Nebula.
Definition refcounted.h:38
BatchGroup denotes a zero indexed name registry which corresponds to the type of materials being batc...
Definition batchgroup.h:31
Definition graphicscontext.h:165
The graphics server is the main singleton for the Graphics subsystem.
Definition graphicsserver.h:49
void Render()
Render views.
Definition graphicsserver.cc:541
void SetupPreLogicViewCalls(const Util::Array< ViewDependentCall > &calls)
Setup per-view calls.
Definition graphicsserver.h:224
void RunPostLogic()
Run post-logic calls.
Definition graphicsserver.cc:504
void DiscardStage(const Ptr< Stage > &stage)
discard stage
Definition graphicsserver.cc:339
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:417
void DiscardGraphicsEntity(const GraphicsEntityId id)
discard graphics entity
Definition graphicsserver.cc:310
void Close()
closes the graphics server
Definition graphicsserver.cc:226
Ptr< View > CreateView(const Util::StringAtom &name, const IO::URI &framescript, const CoreGraphics::WindowId window=CoreGraphics::InvalidWindowId)
create a new view with a new framescript
Definition graphicsserver.cc:350
Util::Array< ViewIndependentCall > postLogicCalls
Definition graphicsserver.h:149
const Timing::Time GetFrameTime() const
get frame time in seconds
Definition graphicsserver.h:251
Util::Array< GraphicsContextState * > states
Definition graphicsserver.h:135
void NewFrame()
Progress to next frame.
Definition graphicsserver.cc:574
void SetupPreLogicCalls(const Util::Array< ViewIndependentCall > &calls)
Setup pre game logic graphics calls.
Definition graphicsserver.h:206
GraphicsEntityId CreateGraphicsEntity()
create graphics entity
Definition graphicsserver.cc:299
FrameContext frameContext
Definition graphicsserver.h:132
Util::Array< GraphicsContextFunctionBundle * > contexts
Definition graphicsserver.h:134
Util::Array< ViewDependentCall > preLogicViewCalls
Definition graphicsserver.h:150
const Ptr< View > & GetCurrentView() const
get current view
Definition graphicsserver.h:197
GraphicsServer()
constructor
Definition graphicsserver.cc:34
const Timing::Time GetTime() const
get total time in seconds
Definition graphicsserver.h:242
void OnWindowResized(CoreGraphics::WindowId wndId)
call when the window has been resized
Definition graphicsserver.cc:283
const IndexT GetFrameIndex() const
get frame index
Definition graphicsserver.h:260
Ptr< CoreGraphics::ShapeRenderer > shapeRenderer
Definition graphicsserver.h:145
void SetupPostLogicCalls(const Util::Array< ViewIndependentCall > &calls)
Setup post game logic graphics calls.
Definition graphicsserver.h:215
Ptr< CoreGraphics::ShaderServer > shaderServer
Definition graphicsserver.h:144
Util::Array< Ptr< Stage > > stages
Definition graphicsserver.h:137
bool isOpen
Definition graphicsserver.h:152
Ids::IdGenerationPool entityPool
Definition graphicsserver.h:128
Ptr< FrameSync::FrameSyncTimer > timer
Definition graphicsserver.h:130
Ptr< Frame::FrameServer > frameServer
Definition graphicsserver.h:147
void DiscardView(const Ptr< View > &view)
discard view
Definition graphicsserver.cc:398
void Open()
opens the graphics server
Definition graphicsserver.cc:52
__DeclareSingleton(GraphicsServer)
void RenderDebug(uint32_t flags)
debug rendering
Definition graphicsserver.cc:427
Ptr< CoreGraphics::TextRenderer > textRenderer
Definition graphicsserver.h:146
void RegisterGraphicsContext(GraphicsContextFunctionBundle *context, GraphicsContextState *state)
register function bundle from graphics context, see GraphicsContextType::Create
Definition graphicsserver.cc:261
bool graphicsDevice
Definition graphicsserver.h:143
void SetupPostLogicViewCalls(const Util::Array< ViewDependentCall > &calls)
Setup per-view calls.
Definition graphicsserver.h:233
Util::Array< ViewIndependentCall > preLogicCalls
Definition graphicsserver.h:149
void UnregisterGraphicsContext(GraphicsContextFunctionBundle *context)
unregister function bundle
Definition graphicsserver.cc:271
void RunPreLogic()
Run pre-logic calls.
Definition graphicsserver.cc:441
Util::Array< Ptr< View > > views
Definition graphicsserver.h:138
void EndFrame()
End the frame and submit.
Definition graphicsserver.cc:564
Util::Array< ViewDependentCall > postLogicViewCalls
Definition graphicsserver.h:150
Ptr< CoreGraphics::DisplayDevice > displayDevice
Definition graphicsserver.h:142
Ptr< Stage > CreateStage(const Util::StringAtom &name, bool main)
create a new stage
Definition graphicsserver.cc:328
bool IsValidGraphicsEntity(const GraphicsEntityId id)
check if graphics entity is valid
Definition graphicsserver.cc:319
virtual ~GraphicsServer()
destructor
Definition graphicsserver.cc:43
bool ownsTimer
Definition graphicsserver.h:131
CoreGraphics::BatchGroup batchGroupRegistry
Definition graphicsserver.h:139
Ptr< View > currentView
Definition graphicsserver.h:140
__DeclareClass(GraphicsServer)
A view describes a camera which can observe a Stage.
Definition view.h:23
An URI object can split a Uniform Resource Identifier string into its components or build a string fr...
Definition uri.h:67
Provides a system for creating array friendly id numbers with reuse and generations.
Definition idgenerationpool.h:43
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 StringAtom.
Definition stringatom.h:22
Implements the shader server used by Vulkan.
Definition cameramanager.h:21
static GraphicsEntityId CreateEntity()
Definition graphicsserver.h:159
void(*)(const Graphics::FrameContext &ctx) ViewIndependentCall
Definition graphicsserver.h:41
void(*)(const Ptr< Graphics::View > &view, const Graphics::FrameContext &ctx) ViewDependentCall
Definition graphicsserver.h:42
static void RegisterEntity(const GraphicsEntityId id)
Definition graphicsserver.h:178
static void DeregisterEntity(const GraphicsEntityId id)
Definition graphicsserver.h:188
static void DestroyEntity(const GraphicsEntityId id)
Definition graphicsserver.h:168
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:33
Timing::Time frameTime
Definition graphicsserver.h:36
Timing::Time time
Definition graphicsserver.h:34
IndexT bufferIndex
Definition graphicsserver.h:38
Timing::Tick ticks
Definition graphicsserver.h:35
IndexT frameIndex
Definition graphicsserver.h:37
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
int IndexT
Definition types.h:48