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 CoreGraphics
28{
29class MeshLoader;
31class TextureLoader;
32}
33
34namespace Models
35{
36class ModelLoader;
37}
38
39namespace Materials
40{
41class MaterialLoader;
42}
43
44namespace CoreAnimation
45{
46class AnimationLoader;
47}
48
49namespace Characters
50{
51class SkeletonLoader;
52}
53
54namespace Particles
55{
56class ParticleLoader;
57}
58
59namespace Graphics
60{
61
70
71using ViewIndependentCall = void(*)(const Graphics::FrameContext& ctx);
72using ViewDependentCall = void(*)(const ViewId view, const Graphics::FrameContext& ctx);
73
74
75class GraphicsContext;
78struct ViewId;
80{
83public:
87 virtual ~GraphicsServer();
88
90 void Open();
92 void Close();
93
100
103 const Util::StringAtom& name
104 , bool(*renderFunction)(const Math::rectangle<int>&, IndexT, IndexT)
105 , const Math::rectangle<int>& viewport
107 , std::function<void(IndexT, IndexT)> preViewCallback = nullptr
108 , std::function<void(IndexT, IndexT)> postViewCallback = nullptr
109 );
113 const Graphics::ViewId GetView(const Util::StringAtom& name);
115 void DiscardView(const Graphics::ViewId view);
117 const Graphics::ViewId GetCurrentView() const;
119 void SetCurrentView(const Graphics::ViewId view);
120
122 void AddEndFrameCall(void(*func)(IndexT frameIndex, IndexT bufferIndex));
124 void SetResizeCall(void(*)(const SizeT, const SizeT));
125
127 void AddWindow(const CoreGraphics::WindowId window);
129 void RemoveWindow(const CoreGraphics::WindowId window);
132
141
143 void RunPreLogic();
145 void RunPostLogic();
147 void Render();
148
150 void EndFrame();
152 void NewFrame();
153
155 const Timing::Time GetTime() const;
157 const Timing::Time GetFrameTime() const;
159 const IndexT GetFrameIndex() const;
160
162 void RenderDebug(uint32_t flags);
163
168
171
172private:
173
175
179
182
186
190
191 void (*resizeCall) (const SizeT, const SizeT);
192
198
207
210
213
214 bool isOpen;
215};
216
217//------------------------------------------------------------------------------
220static GraphicsEntityId
222{
223 return GraphicsServer::Instance()->CreateGraphicsEntity();
224}
225
226//------------------------------------------------------------------------------
229static void
231{
232 GraphicsServer::Instance()->DiscardGraphicsEntity(id);
233}
234
235//------------------------------------------------------------------------------
238template<typename ... CONTEXTS>
239static void
241{
242 (CONTEXTS::RegisterEntity(id), ...);
243}
244
245//------------------------------------------------------------------------------
248template<typename ... CONTEXTS>
249static void
251{
252 (CONTEXTS::DeregisterEntity(id), ...);
253}
254
255//------------------------------------------------------------------------------
258template<typename ... CONTEXTS>
259static void
261{
262 (CONTEXTS::DeregisterEntityImmediate(id), ...);
263}
264
265//------------------------------------------------------------------------------
268inline void
269GraphicsServer::SetResizeCall(void(*func)(const SizeT windowWidth, const SizeT windowHeight))
270{
271 this->resizeCall = func;
272}
273
274//------------------------------------------------------------------------------
277inline void
282
283//------------------------------------------------------------------------------
286inline void
291
292//------------------------------------------------------------------------------
295inline void
300
301//------------------------------------------------------------------------------
304inline void
309
310//------------------------------------------------------------------------------
313inline const Timing::Time
315{
316 return this->frameContext.time;
317}
318
319//------------------------------------------------------------------------------
322inline const Timing::Time
324{
325 return this->frameContext.frameTime;
326}
327
328//------------------------------------------------------------------------------
331inline const IndexT
333{
334 return this->frameContext.frameIndex;
335}
336
337
338
339} // namespace Graphics
Definition skeletonloader.h:18
The common base class of Nebula.
Definition refcounted.h:38
Resource loader to load a GPULang shader object from a stream.
Definition gpulangshaderloader.h:18
Definition meshloader.h:18
Definition textureloader.h:23
Definition graphicscontext.h:175
Ptr< CoreGraphics::GPULangShaderLoader > shaderLoader
Definition graphicsserver.h:199
Graphics::ViewId currentView
Definition graphicsserver.h:185
const Util::Array< CoreGraphics::WindowId > & GetWindows() const
Get windows.
Definition graphicsserver.cc:429
void DiscardView(const Graphics::ViewId view)
discard view
Definition graphicsserver.cc:496
void Render()
Render views.
Definition graphicsserver.cc:641
void SetupPreLogicViewCalls(const Util::Array< ViewDependentCall > &calls)
Setup per-view calls.
Definition graphicsserver.h:296
void RunPostLogic()
Run post-logic calls.
Definition graphicsserver.cc:625
Util::Dictionary< Util::StringAtom, Graphics::ViewId > viewsByName
Definition graphicsserver.h:183
void SetResizeCall(void(*)(const SizeT, const SizeT))
Set a function to be run when resize.
Definition graphicsserver.h:269
Ptr< Models::ModelLoader > modelLoader
Definition graphicsserver.h:200
void DiscardGraphicsEntity(const GraphicsEntityId id)
discard graphics entity
Definition graphicsserver.cc:380
Ptr< CoreGraphics::TextureLoader > textureLoader
Definition graphicsserver.h:202
Ptr< Characters::SkeletonLoader > skeletonLoader
Definition graphicsserver.h:205
SizeT maxWindowWidth
Definition graphicsserver.h:212
void Close()
closes the graphics server
Definition graphicsserver.cc:275
Util::Array< ViewIndependentCall > postLogicCalls
Definition graphicsserver.h:208
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:438
const Timing::Time GetFrameTime() const
get frame time in seconds
Definition graphicsserver.h:323
Util::Array< GraphicsContextState * > states
Definition graphicsserver.h:181
const Graphics::ViewId GetView(const Util::StringAtom &name)
Get view by name.
Definition graphicsserver.cc:522
void NewFrame()
Progress to next frame.
Definition graphicsserver.cc:732
void SetupPreLogicCalls(const Util::Array< ViewIndependentCall > &calls)
Setup pre game logic graphics calls.
Definition graphicsserver.h:278
GraphicsEntityId CreateGraphicsEntity()
create graphics entity
Definition graphicsserver.cc:369
FrameContext frameContext
Definition graphicsserver.h:178
Util::Array< GraphicsContextFunctionBundle * > contexts
Definition graphicsserver.h:180
Util::Array< ViewDependentCall > preLogicViewCalls
Definition graphicsserver.h:209
GraphicsServer()
constructor
Definition graphicsserver.cc:45
void AddEndFrameCall(void(*func)(IndexT frameIndex, IndexT bufferIndex))
Add callback to run just before frame is finished.
Definition graphicsserver.cc:540
const Timing::Time GetTime() const
get total time in seconds
Definition graphicsserver.h:314
const IndexT GetFrameIndex() const
get frame index
Definition graphicsserver.h:332
Ptr< CoreGraphics::ShapeRenderer > shapeRenderer
Definition graphicsserver.h:196
void SetupPostLogicCalls(const Util::Array< ViewIndependentCall > &calls)
Setup post game logic graphics calls.
Definition graphicsserver.h:287
bool OnWindowResized(CoreGraphics::WindowId wndId)
call when the window has been resized
Definition graphicsserver.cc:344
Ptr< CoreGraphics::ShaderServer > shaderServer
Definition graphicsserver.h:195
Ptr< CoreGraphics::MeshLoader > meshLoader
Definition graphicsserver.h:201
void AddWindow(const CoreGraphics::WindowId window)
Add window to update.
Definition graphicsserver.cc:398
bool isOpen
Definition graphicsserver.h:214
Ids::IdGenerationPool entityPool
Definition graphicsserver.h:174
void RemoveWindow(const CoreGraphics::WindowId window)
Remove window.
Definition graphicsserver.cc:418
Util::Array< std::function< void(IndexT, IndexT)> > postViewCallbacks
Definition graphicsserver.h:188
Ptr< FrameSync::FrameSyncTimer > timer
Definition graphicsserver.h:176
Util::Array< CoreGraphics::WindowId > windows
Definition graphicsserver.h:211
void Open()
opens the graphics server
Definition graphicsserver.cc:67
__DeclareSingleton(GraphicsServer)
Util::Array< Graphics::ViewId > views
Definition graphicsserver.h:184
void RenderDebug(uint32_t flags)
debug rendering
Definition graphicsserver.cc:549
Util::Array< std::function< void(IndexT, IndexT)> > endFrameCallbacks
Definition graphicsserver.h:189
Ptr< CoreGraphics::TextRenderer > textRenderer
Definition graphicsserver.h:197
void RegisterGraphicsContext(GraphicsContextFunctionBundle *context, GraphicsContextState *state)
register function bundle from graphics context, see GraphicsContextType::Create
Definition graphicsserver.cc:314
SizeT maxWindowHeight
Definition graphicsserver.h:212
bool graphicsDevice
Definition graphicsserver.h:194
void SetupPostLogicViewCalls(const Util::Array< ViewDependentCall > &calls)
Setup per-view calls.
Definition graphicsserver.h:305
Util::Array< ViewIndependentCall > preLogicCalls
Definition graphicsserver.h:208
void UnregisterGraphicsContext(GraphicsContextFunctionBundle *context)
unregister function bundle
Definition graphicsserver.cc:332
void RunPreLogic()
Run pre-logic calls.
Definition graphicsserver.cc:563
Ptr< Particles::ParticleLoader > particleLoader
Definition graphicsserver.h:206
void EndFrame()
End the frame and submit.
Definition graphicsserver.cc:703
Util::Array< ViewDependentCall > postLogicViewCalls
Definition graphicsserver.h:209
Ptr< Materials::MaterialLoader > materialLoader
Definition graphicsserver.h:203
Ptr< CoreGraphics::DisplayDevice > displayDevice
Definition graphicsserver.h:193
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:513
bool IsValidGraphicsEntity(const GraphicsEntityId id)
check if graphics entity is valid
Definition graphicsserver.cc:389
Ptr< CoreAnimation::AnimationLoader > animationLoader
Definition graphicsserver.h:204
virtual ~GraphicsServer()
destructor
Definition graphicsserver.cc:58
bool ownsTimer
Definition graphicsserver.h:177
void(* resizeCall)(const SizeT, const SizeT)
Definition graphicsserver.h:191
Util::Array< std::function< void(IndexT, IndexT)> > preViewCallbacks
Definition graphicsserver.h:187
const Graphics::ViewId GetCurrentView() const
get current view
Definition graphicsserver.cc:531
__DeclareClass(GraphicsServer)
Provides a system for creating array friendly id numbers with reuse and generations.
Definition idgenerationpool.h:43
Definition materialloader.h:24
A 2d rectangle class.
Definition rectangle.h:20
Definition modelloader.h:27
Definition particleloader.h:19
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:61
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:35
A StringAtom.
Definition stringatom.h:22
A character encapsulates a skeleton resource, an animation resource, and the ability to instantiate s...
Definition charactercontext.cc:21
An animation resource holds a set of animations from a loaded NAX file.
Definition charactercontext.h:40
Acceleration structures are used to enable ray tracing on the GPU by dividing the scene into a BVH.
Definition accelerationstructure.h:24
Implements the shader server used by Vulkan.
Definition cameramanager.h:22
static GraphicsEntityId CreateEntity()
Definition graphicsserver.h:221
void(*)(const Graphics::FrameContext &ctx) ViewIndependentCall
Definition graphicsserver.h:71
static constexpr StageMask PRIMARY_STAGE_MASK
Definition view.h:24
static void RegisterEntity(const GraphicsEntityId id)
Definition graphicsserver.h:240
uint16_t StageMask
Definition view.h:23
static void DeregisterEntityImmediate(const GraphicsEntityId id)
Definition graphicsserver.h:260
void(*)(const ViewId view, const Graphics::FrameContext &ctx) ViewDependentCall
Definition graphicsserver.h:72
static void DeregisterEntity(const GraphicsEntityId id)
Definition graphicsserver.h:250
static void DestroyEntity(const GraphicsEntityId id)
Definition graphicsserver.h:230
Material special version of variant.
Definition graphicsserver.h:40
A model resource consists of nodes, each of which inhibit some information read from an ....
Definition graphicsserver.h:35
Particle context controls playing and enabling/disabling of particle attrs inside a model.
Definition graphicsserver.h:55
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:63
Timing::Time frameTime
Definition graphicsserver.h:66
Timing::Time time
Definition graphicsserver.h:64
IndexT bufferIndex
Definition graphicsserver.h:68
Timing::Tick ticks
Definition graphicsserver.h:65
IndexT frameIndex
Definition graphicsserver.h:67
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