vsg: include/vsg/app/Viewer.h Source File

vsg 1.1.3 VulkanSceneGraph library

Loading...
Searching...
No Matches
Viewer.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <vsg/animation/AnimationManager.h>
16#include <vsg/app/CompileManager.h>
17#include <vsg/app/Presentation.h>
18#include <vsg/app/RecordAndSubmitTask.h>
19#include <vsg/app/UpdateOperations.h>
20#include <vsg/app/Window.h>
21#include <vsg/threading/Barrier.h>
22#include <vsg/threading/FrameBlock.h>
23#include <vsg/utils/Instrumentation.h>
24
25#include <map>
26
27namespace vsg
28{
29
32 class VSG_DECLSPEC Viewer : public Inherit<Object, Viewer>
33 {
34 public:
35 Viewer();
36
37 Viewer(const Viewer&) = delete;
38 Viewer& operator=(const Viewer& rhs) = delete;
39
41 virtual void addWindow(ref_ptr<Window> window);
42
44 virtual void removeWindow(ref_ptr<Window> window);
45
46 Windows& windows() { return _windows; }
47 const Windows& windows() const { return _windows; }
48
49 clock::time_point& start_point() { return _start_point; }
50 const clock::time_point& start_point() const { return _start_point; }
51
52 FrameStamp* getFrameStamp() { return _frameStamp; }
53 const FrameStamp* getFrameStamp() const { return _frameStamp; }
54
56 bool active() const;
57
59 virtual void close();
60
62 virtual bool pollEvents(bool discardPreviousEvents = true);
63
65 UIEvents& getEvents() { return _events; }
66
68 const UIEvents& getEvents() const { return _events; }
69
71 void addEventHandler(ref_ptr<Visitor> eventHandler) { _eventHandlers.emplace_back(eventHandler); }
72
73 void addEventHandlers(const EventHandlers& eventHandlers) { _eventHandlers.insert(_eventHandlers.end(), eventHandlers.begin(), eventHandlers.end()); }
74
76 EventHandlers& getEventHandlers() { return _eventHandlers; }
77
79 const EventHandlers& getEventHandlers() const { return _eventHandlers; }
80
82 ref_ptr<UpdateOperations> updateOperations;
83
85 void addUpdateOperation(ref_ptr<Operation> op, UpdateOperations::RunBehavior runBehavior = UpdateOperations::ONE_TIME)
86 {
87 updateOperations->add(op, runBehavior);
88 }
89
91 ref_ptr<AnimationManager> animationManager;
92
94 ref_ptr<CompileManager> compileManager;
95
97 static constexpr double UseTimeSinceStartPoint = std::numeric_limits<double>::max();
98
102 virtual bool advanceToNextFrame(double simulationTime = UseTimeSinceStartPoint);
103
105 virtual void handleEvents();
106
107 virtual void compile(ref_ptr<ResourceHints> hints = {});
108
109 virtual bool acquireNextFrame();
110
113 virtual VkResult waitForFences(size_t relativeFrameIndex, uint64_t timeout);
114
115 // Manage the work to do each frame using RecordAndSubmitTasks. Those that need to present results need to be wired up to respective Presentation objects.
116 RecordAndSubmitTasks recordAndSubmitTasks;
117
118 // Manage the presentation of rendering using Presentation objects
119 using Presentations = std::vector<ref_ptr<Presentation>>;
120 Presentations presentations;
121
124 virtual void assignRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs);
125
127 void addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs);
128
129 ref_ptr<ActivityStatus> status;
130 std::list<std::thread> threads;
131
132 void setupThreading();
133 void stopThreading();
134
135 virtual void update();
136
137 virtual void recordAndSubmit();
138
139 virtual void present();
140
142 virtual void deviceWaitIdle() const;
143
145 uint64_t frameReference = 0;
146 ref_ptr<Instrumentation> instrumentation;
147
149 void assignInstrumentation(ref_ptr<Instrumentation> in_instrumentation);
150
151 protected:
152 virtual ~Viewer();
153
154 bool _close = false;
155
156 ref_ptr<FrameStamp> _frameStamp;
157
158 Windows _windows;
159
160 clock::time_point _start_point;
161 UIEvents _events;
162 EventHandlers _eventHandlers;
163
164 bool _threading = false;
165 ref_ptr<FrameBlock> _frameBlock;
166 ref_ptr<Barrier> _submissionCompleted;
167 };
168 VSG_type_name(vsg::Viewer);
169
171 extern VSG_DECLSPEC void updateViewer(Viewer& viewer, const CompileResult& compileResult);
172
173} // namespace vsg
vsg::Inherit
Definition Inherit.h:28
vsg::UpdateOperations::RunBehavior
RunBehavior
specification of whether update operation should be invoked once or on all frames
Definition UpdateOperations.h:31
vsg::Viewer
Definition Viewer.h:33
vsg::Viewer::deviceWaitIdle
virtual void deviceWaitIdle() const
Call vkDeviceWaitIdle on all the devices associated with this Viewer.
vsg::Viewer::advanceToNextFrame
virtual bool advanceToNextFrame(double simulationTime=UseTimeSinceStartPoint)
vsg::Viewer::addRecordAndSubmitTaskAndPresentation
void addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs)
Add command graphs creating RecordAndSubmitTask/Presentation objects where appropriate.
vsg::Viewer::assignInstrumentation
void assignInstrumentation(ref_ptr< Instrumentation > in_instrumentation)
Convenience method for assigning Instrumentation to the viewer and any associated objects.
vsg::Viewer::handleEvents
virtual void handleEvents()
pass the Events into any registered EventHandlers
vsg::Viewer::waitForFences
virtual VkResult waitForFences(size_t relativeFrameIndex, uint64_t timeout)
vsg::Viewer::updateOperations
ref_ptr< UpdateOperations > updateOperations
thread safe container for update operations
Definition Viewer.h:82
vsg::Viewer::assignRecordAndSubmitTaskAndPresentation
virtual void assignRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs)
vsg::Viewer::animationManager
ref_ptr< AnimationManager > animationManager
manager for starting and running animations
Definition Viewer.h:91
vsg::Viewer::addUpdateOperation
void addUpdateOperation(ref_ptr< Operation > op, UpdateOperations::RunBehavior runBehavior=UpdateOperations::ONE_TIME)
add an update operation
Definition Viewer.h:85
vsg::Viewer::addEventHandler
void addEventHandler(ref_ptr< Visitor > eventHandler)
add event handler
Definition Viewer.h:71
vsg::Viewer::active
bool active() const
return true if viewer is valid and active
vsg::Viewer::pollEvents
virtual bool pollEvents(bool discardPreviousEvents=true)
poll the events for all attached windows, return true if new events are available
vsg::Viewer::getEvents
UIEvents & getEvents()
get the current set of Events that are filled in by prior calls to pollEvents
Definition Viewer.h:65
vsg::Viewer::close
virtual void close()
schedule closure of the viewer and associated windows, after a call to Viewer::close() the Viewer::ac...
vsg::Viewer::removeWindow
virtual void removeWindow(ref_ptr< Window > window)
remove Window from Viewer
vsg::Viewer::getEventHandlers
const EventHandlers & getEventHandlers() const
get the const list of EventHandlers
Definition Viewer.h:79
vsg::Viewer::getEventHandlers
EventHandlers & getEventHandlers()
get the list of EventHandlers
Definition Viewer.h:76
vsg::Viewer::getEvents
const UIEvents & getEvents() const
get the const current set of Events that are filled in by prior calls to pollEvents
Definition Viewer.h:68
vsg::Viewer::addWindow
virtual void addWindow(ref_ptr< Window > window)
add Window to Viewer
vsg::Viewer::compileManager
ref_ptr< CompileManager > compileManager
compile manager provides thread safe support for compiling subgraphs
Definition Viewer.h:94
vsg::CompileResult
Definition CompileManager.h:24
vsg::allocator_affinity_nodes
std container adapter for allocating with MEMORY_AFFINITY_NODES
Definition Allocator.h:138