NDEVR
API Documentation
VulkanMaterialManager.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: VulkanMaterialManager
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "VulkanDefines.h"
34#include "VulkanBuffer.h"
35#include "VulkanImage.h"
36#include "VulkanShader.h"
37#include "VulkanBitflagObject.h"
38#include <NDEVR/Model.h>
39#include <NDEVR/Material.h>
40struct VkWriteDescriptorSet;
41struct VkDescriptorImageInfo;
42struct VkPipelineShaderStageCreateInfo;
43DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorPool);
44DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSet);
45DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSetLayout);
46DEFINE_NON_DISPATCHABLE_HANDLE(VkSampler);
47namespace NDEVR
48{
60 static_assert(sizeof(VulkanVertexUniformObject) == 16, "Bad VertexUniformSize");
61#pragma pack(push, 1)
66 {
75
86 fltp04 fade_distance = 99.9f;
87 fltp04 max_distance = 500.0f;
88
89 fltp04 shininess = 1.0f;
90 fltp04 opacity = 1.0f;
91 uint04 layer_number = Constant<uint04>::Invalid;
92
94 uint04 palette_size = 0;
95 VulkanBitflagObject tex_flags;
96
97 public:
100 {
101 }
102 FragUniformObject(const Material& m_material);
104 {
105 texture_coord_mode = mat_mode;
106 }
107 };
108 //static_assert(sizeof(FragUniformObject) == 176, "Bad UniformSize");
109 static_assert(sizeof(FragUniformObject) == 176, "Bad FragUniformSize");
110#pragma pack(pop)
115 class VulkanMaterialManager
116 {
117 public:
118 VulkanMaterialManager(const ConstPointer<VulkanDevice>& device);
119 VulkanMaterialManager(const VulkanMaterialManager& m_pipeline) = delete;
120 ~VulkanMaterialManager();
121
122 void cleanup();
123 VulkanBitflagObject getUVImageFlags(const Material& material) const;
124 VulkanBitflagObject uvImageFlags() const { return m_last_image_flag_object; }
125 bool hasGrid() const { return m_has_grid; }
126 void checkImages();
127 VulkanVertexUniformObject getVulkanVertexUniformObject(const Material& material, const GraphicsUpdateArguments& args) const;
128 const VulkanVertexUniformObject& vertexUniform() const { return m_vert_uniform; }
129 FragUniformObject getFragUniformObject(const Material& material) const;
130 VulkanBitflagObject getBitflagObject() const;
131 void updateUniformBuffer(GraphicsUpdateArguments& args);
132 void addMaterial(const Material& material);
133 void clearMaterials();
134 bool hasOpacity() const { return m_has_opacity; }
135 bool ignoreDepth() const { return m_ignore_depth; }
136 bool writeToDepth() const { return m_write_to_depth; }
137 bool usesModelColor() const { return m_use_model_color; }
138 bool usesLayerColor() const { return m_use_layer_color; }
139 bool needsPipelineUpdate() const { return m_needs_pipeline_update; }
140 fltp04 fadeDistance() const;
141 fltp04 depthBias() const { return m_depth_bias; }
142 bool hasImage() const;
143 void commit();
144 void createPipeline(GraphicsUpdateArguments& args, DynamicPointer<VulkanShaderManager>& shader_manager, DynamicPointer<VulkanImageManager>& image_manager, VkDescriptorPool pool);
145 void updateBuffers(GraphicsUpdateArguments& args, DynamicPointer<VulkanImageManager>& image_manager);
146
147 uint04 getNumberOfImages(const GraphicsUpdateArguments& args) const;
148
149 StringView getColorByChannel(GraphicsUpdateArguments& args) const;
150
151 StringView getExtraPropertyChannel() const { return m_extra_channel; }
152
153 //void setFragmentShader(const Pointer<Shader>& shader) { m_fragment_shader = shader; }
154 ConstPointer<VulkanShader> getFragmentShader(VulkanShaderManager::ShaderType shader_type) const;
155 VkPipelineShaderStageCreateInfo getShaderCreateInfo(VulkanShaderManager::ShaderType shader_type) const;
156 void createSampler(const GraphicsUpdateArguments& args);
157
158 VkDescriptorSet descriptorSet() const
159 {
160 return m_descriptor_set;
161 }
162
163
164 Time lastDependencyUpdate() const { return m_last_push_update_time; }
165 UUID material() const;
166 bool isTwoSided() const { return m_is_two_sided; }
167 bool isWireframe() const { return m_is_wireframe; }
168 bool overrideCamera() const { return m_override_camera; }
169 bool useNormalForTexture() const { return m_use_normal_for_texture; }
170 bool useLighting() const;
171 bool smoothNormals() const;
172
173 bool simpleAllowed() const;
174 void resetPool() { m_descriptor_pool = vk_null; }
175 static VkDescriptorSetLayout descriptorSetLayout(ConstPointer<VulkanDevice> device);
176 UUID id() const;
177 static UUID MaterialID(const Material& material);
178 protected:
179
180 void createDescriptorSet(VkDescriptorPool pool, const GraphicsUpdateArguments& args);
181 void getDescriptorWrites(Buffer<VkWriteDescriptorSet>& descriptor_writes, Buffer<VkDescriptorImageInfo>& image_info) const;
182
183 void updateShader(const Material& mat, const GraphicsUpdateArguments& args, DynamicPointer<VulkanShaderManager>& shader_manager);
184 void updateImages(const Material& mat, const GraphicsUpdateArguments& args, DynamicPointer<VulkanImageManager>& image_manager);
185 bool needsToUpdateImage(const Material& material);
186 bool needsToUpdateShader(const Material& material);
187
188 uint04 getLayerNumber(const Material& material) const;
189
190
191 protected:
192
193
194 Buffer<Material> m_materials;
195 VkSampler m_sampler;
196 VulkanBitflagObject m_last_image_flag_object;
197 VkDescriptorPool m_descriptor_pool;
199
200 VulkanVertexUniformObject m_vert_uniform;
201 FragUniformObject m_frag_uniform;
202
203 DynamicPointer<VulkanBuffer> m_vertex_uniform_buffer;
204 DynamicPointer<VulkanBuffer> m_frag_uniform_buffer;
205
206 //ConstPointer<Shader> m_fragment_shader;
207
210 uint04 m_number_of_uniforms;
211 Time m_last_updated_time;
212
213 Time m_last_push_update_time;
214
215 String m_image_address[cast<uint04>(UVType::e_uv_size)];
216
217
218 VkDescriptorSet m_descriptor_set;
219 String m_extra_channel;
220 Vector<3, Material::TileTextureMode> m_texture_tile_mode;
221
223 Material::ShadingModel m_shade_model;
224 String m_shader_name;
225 fltp04 m_depth_bias;
226
227 mutable bool m_needs_to_commit_frag_buffer = true;
228 mutable bool m_needs_to_commit_vert_buffer = true;
229 bool m_needs_pipeline_update = true;
230 bool m_has_opacity = false;
231 bool m_has_image = false;
232 bool m_has_image_opacity = false;
233 bool m_is_two_sided = false;
234 bool m_override_camera = false;
235 bool m_smooth_normals = false;
236 bool m_is_wireframe = false;
237 bool m_has_grid = false;
238 bool m_use_normal_for_texture = false;
239 bool m_use_model_color = false;
240 bool m_use_layer_color = false;
241 bool m_ignore_depth = false;
242 bool m_write_to_depth = true;
243 bool m_needs_buffer_update = false;
244 uint04 m_layer_number;
245 UUID m_id;
246 };
247}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
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
Options that are used for performing an update on a Graphics Engine call.
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:153
ShadingModel
Enumerates the available shading models for material rendering.
Definition Material.h:162
TextureCoordMode
Defines how texture coordinates are generated or interpreted for a material.
Definition Material.h:226
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
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
ShaderType
The types of shaders available for rendering different primitives.
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
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...
@ e_uv_size
The number of UV types. Used for sizing arrays.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Items to send to the OpenGL Fragmentation shader.
Matrix< fltp04 > float_values
Matrix of float value ranges for the fragment shader.
Vector< 4, sint04 > m_grid_lines
Grid line positions.
fltp04 max_distance
Maximum visible distance.
void setMode(Material::TextureCoordMode mat_mode)
Sets the texture coordinate mode.
Vector< 4, sint04 > m_grid_lines_desc
Grid line descriptors.
FragUniformObject()
Default constructor.
fltp04 fade_distance
Distance at which objects begin to fade.
FloatPosition
Indices into the float_values matrix for fragment shader value ranges.
@ e_min_value_frag_pos
Index of the minimum value row.
@ e_mid_value_frag_pos
Index of the midpoint value row.
@ e_max_value_frag_pos
Index of the maximum value row.
uint04 texture_coord_mode
Texture coordinate generation mode.
ColorPosition
Indices for color values within the fragment uniform palette.
@ e_ka_frag_pos
Ambient color position index.
@ e_kd_frag_pos
Diffuse color position index.
@ e_ks_frag_pos
Specular color position index.
@ e_kr_frag_pos
Reflective color position index.
Buffer< Vector< 4, fltp04 > > palette_colors
Color palette for indexed color rendering.
fltp04 shininess
Specular shininess exponent.
fltp04 opacity
Overall material opacity.
Stores bools to be sent to both the Vertex and Fragment shaders in the Vulkan space.
Information sent to the Vertex shader as a Uniform object.
fltp04 reserved0
Reserved for future use.
fltp04 reserved1
Reserved for future use.
fltp04 reserved2
Reserved for future use.
fltp04 pixel_thickness
The thickness of rendered points/lines in pixels.