NDEVR
API Documentation
GraphicsUpdater.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Graphics
28File: GraphicsUpdater
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include "NDEVRGraphics/Headers/GraphicsPipeline.h"
35#include "NDEVRGraphics/Headers/GraphicsUpdateArguments.h"
36#include "Design/Headers/DesignObjectUpdateTarget.h"
37#include "Base/Headers/ConcurrentOperation.h"
38#include "Base/Headers/Thread.h"
39namespace NDEVR
40{
41 class Exception;
42 class CheckoutLock;
43 class Renderer;
44 class GraphicsSession;
49 class NDEVR_GRAPHICS_API GraphicsUpdater : public DesignObjectUpdateTarget
50 {
51 friend class CheckoutLock;
52 public:
63 void update(DesignObjectLookup* lookup, Time time) override;
66 void setLog(LogPtr log)
67 {
68 m_args.log = log;
69 }
70
73 {
74 m_args.lookup = lookup;
75 }
76
79 {
80 return m_last_update_time;
81 }
82
85 bool hasManager(const UUID& id);
89 void addManager(const UUID& id, Renderer* renderer);
92 void removeManager(const UUID& id);
97 CheckoutLock tryCheckout(const UUID& id, bool wait_until_ready);
102 CheckoutLock checkout(const UUID& id, bool wait_until_ready);
109 {
110 WLock lock(this);
111 m_pipelines.add(pipline);
112 }
113
120 void recreate();
129 void setExceptionCallback(const std::function<void(const Exception&)>& callback) { m_exception_callback = callback; };
132 void setIsGrabSetup(bool grab_setup);
134 void update();
138 private:
139 RLock _checkout(const UUID& id, bool wait_until_ready);
140 void checkin(const UUID& id);
141 bool renderNeedsUpdate() const;
142 bool createPipeline(GraphicsUpdateArguments& args);
143 void updateUniformBuffer(GraphicsUpdateArguments& args);
144 protected:
146 std::function<void(const Exception&)> m_exception_callback;
155 };
156
161 {
162 public:
167 CheckoutLock(GraphicsUpdater* updater, bool wait_until_ready, UUID id = Constant<UUID>::Invalid)
168 : m_updater(updater)
169 , m_id(id)
170 , m_lock(IsValid(m_id) ? m_updater->_checkout(m_id, wait_until_ready) : RLock(&m_id))
171 {}
172 CheckoutLock(const CheckoutLock& checkout) = delete;
176 : m_updater(checkout.m_updater)
177 , m_id(checkout.m_id)
178 , m_lock(std::move(checkout.m_lock))
179 {
180 checkout.m_id = Constant<UUID>::Invalid;
181 }
182
184 {
185 if(IsValid(m_id))
186 m_updater->checkin(m_id);
187 }
188
191 {
192 return (IsValid(m_id));
193 }
194 protected:
198 };
199}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Used by Viewports to signal they are rendering and we should not be performing an Update.
RLock m_lock
The read lock held during checkout.
GraphicsUpdater * m_updater
The owning updater.
~CheckoutLock()
Destructor.
UUID m_id
The checked-out camera UUID.
bool isCheckedOut()
Checks whether this lock holds a valid checkout.
CheckoutLock(GraphicsUpdater *updater, bool wait_until_ready, UUID id=Constant< UUID >::Invalid)
Constructs a checkout lock for a renderer.
CheckoutLock(const CheckoutLock &checkout)=delete
Non-copyable.
CheckoutLock(CheckoutLock &&checkout)
Move constructor.
A core class where all Design Objects including models, materials, and geometries are stored.
An object that will be called to update each time the lookup is updated.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Provides consistent interface to handle errors through the throw expression.
Definition Exception.hpp:47
A GraphicsPipeline is a set of resources that are chained together to correctly render something.
A GraphicsPipeline that is responsible for setting up and rendering the resources of a DesignObjectLo...
Options that are used for performing an update on a Graphics Engine call.
Responsible for updating resources or layouts of data in-between calls to render.
Time lastUpdateTime() const
Returns the last time an update was performed.
void removeManager(const UUID &id)
Removes a registered renderer.
void removePipeline(GraphicsPipeline *pipline)
Removes a graphics pipeline from the update list.
GraphicsUpdateArguments m_args
Current graphics update arguments.
DynamicPointer< GraphicsDevice > m_device
The graphics device used for rendering.
static GraphicsUpdater * DefaultUpdater(DesignObjectLookup *lookup, LogPtr log, DynamicPointer< GraphicsDevice > device)
Returns or creates the default updater singleton.
void addPipeline(GraphicsPipeline *pipline)
Adds a graphics pipeline to the update list.
Time m_last_update_time
Last time a full update was performed.
void update(GraphicsUpdateArguments &args)
Performs an update using the provided arguments.
Buffer< GraphicsPipeline * > m_pipelines
Registered graphics pipelines.
void addManager(const UUID &id, Renderer *renderer)
Registers a renderer for a given camera ID.
GraphicsUpdateArguments & args()
Returns the current graphics update arguments.
void setLog(LogPtr log)
Sets the log for graphics update operations.
Dictionary< UUID, Renderer * > m_renderers
Registered renderers keyed by camera UUID.
GraphicsUpdater(DesignObjectLookup *lookup, const DynamicPointer< GraphicsDevice > &device, LogPtr log=LogPtr())
Constructs the updater for a design lookup and graphics device.
volatile uint04 m_total_checked_out_count
Number of currently checked-out renderers.
const DynamicPointer< GraphicsDevice > & device() const
Returns the graphics device.
void setExceptionCallback(const std::function< void(const Exception &)> &callback)
Sets a callback invoked when a graphics exception occurs.
void update(DesignObjectLookup *lookup, Time time) override
Performs a full update cycle for all graphics resources.
std::function< void(const Exception &)> m_exception_callback
Callback for graphics exceptions.
void update()
Performs an update using the internal arguments.
bool m_grab_setup
Whether the updater is in image-grab mode.
Dictionary< UUID, bool > needs_update
Per-renderer update flags.
void setIsGrabSetup(bool grab_setup)
Sets whether this updater is configured for image grab mode.
CheckoutLock checkout(const UUID &id, bool wait_until_ready)
Checks out a renderer, blocking until available.
void setLookup(DesignObjectLookup *lookup)
Sets the design object lookup.
~GraphicsUpdater()
Destructor.
bool hasManager(const UUID &id)
Checks whether a renderer is registered for the given ID.
void recreate()
Triggers a full pipeline recreation.
CheckoutLock tryCheckout(const UUID &id, bool wait_until_ready)
Attempts a non-blocking checkout of a renderer.
std::mutex m_critical_section
Mutex for thread-safe access.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Used to lock a particular variable for reading.
Definition RWLock.h:157
An object that renders a specific Camera object, typically run on a different thread than the main UI...
Definition Renderer.h:53
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
Used to lock a particular variable for writing.
Definition RWLock.h:272
The primary namespace for the NDEVR SDK.
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
Definition Angle.h:398
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
STL namespace.