NDEVR
API Documentation
VulkanRenderObject.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: VulkanRenderObject
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "VulkanDefines.h"
34#include "VulkanImage.h"
35#include "VulkanBuffer.h"
36#include "VulkanBitflagObject.h"
37#include "NDEVRGraphics/Headers/GraphicsUpdateArguments.h"
38#include "Design/Headers/Material.h"
39#include "Design/Headers/Geometry.h"
40#include "Design/Headers/Model.h"
41#include "Base/Headers/Pointer.hpp"
42#include "Base/Headers/RGBColor.h"
43#include "Base/Headers/Bounds.hpp"
44
45
46struct VkCommandBuffer_T;
47struct VkDescriptorSetLayout_T;
48struct VkDescriptorPool_T;
49struct VkDescriptorSet_T;
50struct VkSampler_T;
51struct VkVertexInputAttributeDescription;
52struct VkVertexInputBindingDescription;
53struct VkPipelineShaderStageCreateInfo;
54
55DEFINE_NON_DISPATCHABLE_HANDLE(VkPipeline);
56DEFINE_NON_DISPATCHABLE_HANDLE(VkPipelineLayout);
57
58namespace NDEVR
59{
60 class Camera;
63
69 class VulkanRenderObject
70 {
72 struct ModelMatrixUniformObject
73 {
74 Matrix<fltp04> model_transform = Constant<Matrix<fltp04>>::Invalid;
75 Vector<3, sint04> model_offset = Vector<3, sint04>(0);
77 RGBColor custom_color = Constant<RGBColor>::Invalid;
78 bool operator==(const ModelMatrixUniformObject& object) const
79 {
80 return model_transform == object.model_transform
81 && flags == object.flags
82 && model_offset == object.model_offset
83 && custom_color == object.custom_color;
84 }
85 bool operator!=(const ModelMatrixUniformObject& object) const
86 {
87 return model_transform != object.model_transform
88 || flags != object.flags
89 || model_offset != object.model_offset
90 || custom_color != object.custom_color;
91 }
92 };
93 protected:
96 {
99 ModelProperties(const Model& model)
100 : model_id(model.get<NDPO::guid>())
101 {
102 is_visible = model.isVisible();
103 }
104 Time updated_time = Constant<Time>::Invalid;
105 UUID model_id = Constant<UUID>::Invalid;
107 bool is_visible = false;
108 };
109
126 public:
127 VulkanRenderObject(const ConstPointer<VulkanDevice>& pipeline);
128 VulkanRenderObject(const VulkanRenderObject&) = delete;
129 ~VulkanRenderObject();
130 void cleanup();
131 VkPipeline getPipeline() { return m_graphics_pipeline; }
132 void setDevice(const DynamicPointer<VulkanDevice>& instance);
133 void updateUniformBuffer(GraphicsUpdateArguments& args);
134 bool hasOpacity() const;
135 bool hasImage() const;
136 bool hasParity() const;
137 fltp04 fadeDistance() const;
138 bool hasTangent() const { return m_has_tangent; }
139 bool createPipeline(GraphicsUpdateArguments& args);
140 //void resetPool() { m_descriptor_pool = nullptr; }
141 bool runCommand(GraphicsUpdateArguments& args, VkDescriptorSet camera_descriptor);
142 bool runCommandPass(GraphicsUpdateArguments& args, uint01 parity) const;
143 bool isFilledShape() const;
144 void setGraphicsPipeline(VkPipeline pipeline);
145 bool hasActiveGeo() const;
146 void setParityGraphicsPipeline(VkPipeline pipeline);
147 Vector<2, VkPipelineShaderStageCreateInfo> getShaderCreateInfo() const;
148 const PrimitiveBuffer<VkVertexInputAttributeDescription>& getAttributeDescriptions() const;
149 const PrimitiveBuffer<VkVertexInputBindingDescription>& getBindingDescriptions() const;
150 const ConstPointer<VulkanMaterialManager>& materialManager() const { return m_material_manager; }
151 const ConstPointer<VulkanVertexManager>& vertexManager() const { return m_vertex_manager; }
152 PrimitiveMode primitiveMode() const { return m_index_mode; };
153 PrimitiveProperty primitiveProperty() const { return m_index_property; };
154 void setPrimitiveMode(const PrimitiveMode& type) { m_index_mode = type; }
155 void setPrimitiveProperty(const PrimitiveProperty& property) { m_index_property = property; }
156 void setVertexManager(const DynamicPointer<VulkanVertexManager>& vertex_manager);
157 void setMaterialManager(const DynamicPointer<VulkanMaterialManager>& material_manager);
158 void setHasTangent(bool has_tangent);
159 void addInstance(const Geometry& geo);
160 bool removeInstance(const Geometry& geo);
161 void setMaterial(const Material& material);
162 void clearInstances();
163 void updateVertexBuffers(GraphicsUpdateArguments& args, bool can_reallocate = true);
164 bool needsPipelineUpdate() const { return m_needs_pipeline_update; }
165 void finishUpdatingPipeline() { m_needs_pipeline_update = false; }
166 public:
167 static VkPipelineLayout PipelineLayout(ConstPointer<VulkanDevice> instance);
168 private:
169 bool computeHasActiveGeo();
170 void drawInstances(uint04 start, uint04 size, const GeoProperties& geo, const GraphicsUpdateArguments& args, bool& is_index_bound) const;
171 VulkanBitflagObject getBitflagObject(const Geometry& mesh, const Model& model) const;
172 //returns false if nothing to render
173 bool getExclusionList(GraphicsUpdateArguments& args, uint01 parity) const;
174 void updateBufferCache(GraphicsUpdateArguments& args);
175 void updateModelParents(uint04 geo_index, uint04& matrix_idx);
176 ModelMatrixUniformObject getMatrixUniformObject(const Geometry& geo, const Model& model) const;
177 PrimitiveBuffer<VkVertexInputAttributeDescription>& calculateAttributeDescriptions(PrimitiveBuffer<VkVertexInputAttributeDescription>& buffer, GraphicsUpdateArguments& args) const;
178 PrimitiveBuffer<VkVertexInputBindingDescription>& calculateBindingDescriptions(PrimitiveBuffer<VkVertexInputBindingDescription>& buffer, GraphicsUpdateArguments& args) const;
179 private:
180 Time m_last_buffer_time = Time(0);
181 UUID m_material_id;
182 PrimitiveProperty m_index_property;
183 PrimitiveMode m_index_mode;
184 Set<Geometry> m_added_geos;
185 Buffer<GeoProperties> m_geometries;
186 //ExtraPropertySettings m_extra_settings;
187 String m_extra_property;
188 //DynamicPointer<VulkanBuffer> m_bitf_uniform_buffer;
189 DynamicPointer<VulkanVertexManager> m_vertex_manager;
190 ConstPointer<VulkanMaterialManager> m_material_manager;
191 PrimitiveBuffer<VkVertexInputAttributeDescription> m_attribute_descriptions;
192 mutable PrimitiveBuffer<VkVertexInputAttributeDescription> m_attribute_descriptions_buffer;
193 PrimitiveBuffer<VkVertexInputBindingDescription> m_binding_descriptions;
194 mutable PrimitiveBuffer<VkVertexInputBindingDescription> m_binding_descriptions_buffer;
195 VkBuffer m_vertex_buffers[9];
196 Buffer<ModelMatrixUniformObject> m_model_matrix_uniforms;
197 DynamicPointer<VulkanBuffer> m_matrix_instance_buffer;
198 ConstPointer<VulkanDevice> m_instance;
199 VkPipeline m_graphics_pipeline;
200 VkPipeline m_parity_pipeline;
201 uint04 m_matrix_index_offset = 0;
202 uint04 m_wait_count = 0;
203 uint08 m_buffer_update_idx = Constant<uint08>::Invalid;
204 bool m_has_tangent = false;
205 bool m_has_parity = false;
206 volatile mutable bool m_needs_matrix_commit;
207 volatile mutable bool m_needs_pipeline_update = true;
208 bool m_has_instance_difference = false;
209 bool m_needs_command_refresh = false;
210 bool m_has_active_geo = false;
211 };
212}
213bool operator!=(const VkVertexInputAttributeDescription& a, const VkVertexInputAttributeDescription& b);
214bool operator!=(const VkVertexInputBindingDescription& a, const VkVertexInputBindingDescription& b);
215bool operator==(const VkVertexInputAttributeDescription& a, const VkVertexInputAttributeDescription& b);
216bool operator==(const VkVertexInputBindingDescription& a, const VkVertexInputBindingDescription& b);
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core object representing a user view as well as convenience functions for moving this view through ...
Definition Camera.h:95
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
A core class within the model hierarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:143
Options that are used for performing an update on a Graphics Engine call.
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
A core class that represents a node on model hierarchy.
Definition Model.h:292
bool isVisible() const
Checks whether this model is visible (accounting for inherited visibility).
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
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
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
Logic for creating the data in Vulkan for a specific Material.
Manages all vertices in a specific Scene object for interfacing with Vulkan.
The primary namespace for the NDEVR SDK.
@ type
The type identifier string for this model node.
Definition Model.h:58
constexpr bool operator!=(const Vector< t_dims, t_type > &vec_a, const Vector< t_dims, t_type > &vec_b)
Inequality operator.
Definition Vector.hpp:673
PrimitiveMode
Used with Geometry to describe how vertices and indices are used to form shapes.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
NDPO
NDPO - NDEVR Design Property Object: Values stored in the property database.
@ guid
A 128-bit globally unique identifier for the object.
PrimitiveProperty
Describes which rendering property a primitive index buffer corresponds to.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Stores bools to be sent to both the Vertex and Fragment shaders in the Vulkan space.
Cached properties of a Geometry instance within this render object.
Time modified_time
Last modification time of this geometry.
Buffer< ModelProperties > model_parents
Properties of all parent models.
uint04 index_size
Number of indices.
Geometry geometry
The geometry object reference.
uint04 vertex_start
Start index in the vertex buffer.
bool is_deleted
Whether this geometry has been deleted.
uint04 vertex_size
Number of vertices.
uint04 index_start
Start index in the index buffer.
bool is_visible
Whether this geometry is visible.
fltp04 pixel_thickness
Line/point thickness in pixels.
GeoProperties(const Geometry &geo)
Constructs geometry properties from a Geometry object.
uint01 parity
Parity flag for culling direction.
Time updated_time
Last time these properties were updated.
ModelProperties(const Model &model)
Constructs model properties from a Model object.
UUID model_id
UUID of the parent model.
bool is_visible
Whether the parent model is visible.