API Documentation
Loading...
Searching...
No Matches
VulkanMaterialManager.h
Go to the documentation of this file.
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 "VulkanDefines.h"
35#include "VulkanBuffer.h"
36#include "VulkanImage.h"
37#include "Shader.h"
38#include "VulkanBitflagObject.h"
41struct VkWriteDescriptorSet;
42struct VkDescriptorImageInfo;
43struct VkPipelineShaderStageCreateInfo;
46DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSetLayout);
48namespace NDEVR
49{
50 class GraphicsUpdateArguments;
51
53 {
55 fltp04 reserved0 = 0.0;
56 fltp04 reserved1 = 0.0;
57 fltp04 reserved2 = 0.0;
58 };
59 static_assert(sizeof(VertexUniformObject) == 16, "Bad VertexUniformSize");
60#pragma pack(push, 1)
102 //static_assert(sizeof(FragUniformObject) == 176, "Bad UniformSize");
103 static_assert(sizeof(FragUniformObject) == 176, "Bad FragUniformSize");
104#pragma pack(pop)
106 {
107 public:
109 VulkanMaterialManager(const VulkanMaterialManager& m_pipeline) = delete;
111
112 void cleanup();
115 bool hasGrid() const { return m_has_grid; }
116 void checkImages();
122 void addMaterial(const Material& material);
123 void clearMaterials();
124 bool hasOpacity() const { return m_has_opacity; }
125 bool ignoreDepth() const { return m_ignore_depth; }
126 bool writeToDepth() const { return m_write_to_depth; }
127 bool isDynamic() const { return m_is_dynamic; }
128 bool usesModelColor() const { return m_use_model_color; }
129 bool usesLayerColor() const { return m_use_layer_color; }
130 fltp04 fadeDistance() const;
131 fltp04 depthBias() const { return m_depth_bias; }
132 bool hasImage() const;
133 void commit();
134 void createPipeline(GraphicsUpdateArguments& args, DynamicPointer<VulkanShaderManager>& shader_manager, DynamicPointer<VulkanImageManager>& image_manager, VkDescriptorPool pool);
135
137
139
141
142 //void setFragmentShader(const Pointer<Shader>& shader) { m_fragment_shader = shader; }
144 void getShaderCreateInfo(PrimitiveMode property, Buffer<VkPipelineShaderStageCreateInfo, uint04, ObjectAllocator<true>>& buffer) const;
145 void createSampler(const GraphicsUpdateArguments& args);
146
147 VkDescriptorSet descriptorSet() const
148 {
149 return m_descriptor_set;
150 }
151
152
154 UUID material() const;
155 bool isTwoSided() const { return m_is_two_sided; }
156 bool isWireframe() const { return m_is_wireframe; }
157 bool overrideCamera() const { return m_override_camera; }
159 bool useLighting() const;
160 bool smoothNormals() const;
162 static VkDescriptorSetLayout descriptorSetLayout(ConstPointer<VulkanDevice> device);
163 UUID id() const;
164 static UUID MaterialID(const Material& material);
165 protected:
166
167 void createDescriptorSet(VkDescriptorPool pool, const GraphicsUpdateArguments& args);
168 void getDescriptorWrites(Buffer<VkWriteDescriptorSet, uint04, ObjectAllocator<true>>& descriptor_writes, Buffer<VkDescriptorImageInfo, uint04, ObjectAllocator<true>>& image_info) const;
169
170 void updateShader(const Material& mat, const GraphicsUpdateArguments& args, DynamicPointer<VulkanShaderManager>& shader_manager);
171 void updateImages(const Material& mat, const GraphicsUpdateArguments& args, DynamicPointer<VulkanImageManager>& image_manager);
174
176
177
178 protected:
179
180
182 VkSampler m_sampler;
184 VkDescriptorPool m_descriptor_pool;
186
189
192
193 //ConstPointer<Shader> m_fragment_shader;
194
199
201
203
204
205 VkDescriptorSet m_descriptor_set;
208
213
214 mutable bool m_needs_to_commit_frag_buffer = true;
215 mutable bool m_needs_to_commit_vert_buffer = true;
217 bool m_has_opacity = false;
218 bool m_has_image = false;
220 bool m_is_two_sided = false;
221 bool m_override_camera = false;
222 bool m_smooth_normals = false;
223 bool m_is_wireframe = false;
224 bool m_is_dynamic = false;
225 bool m_has_grid = false;
227 bool m_use_model_color = false;
228 bool m_use_layer_color = false;
229 bool m_ignore_depth = false;
230 bool m_write_to_depth = true;
233 };
234}
#define vk_null
Definition VulkanDefines.h:11
#define DEFINE_NON_DISPATCHABLE_HANDLE(object)
Definition VulkanInstance.h:49
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition GraphicsPipeline.h:42
Definition Pointer.hpp:303
Definition GraphicsUpdateArguments.h:40
Definition Material.h:45
ShadingModel
Definition Material.h:48
TextureCoordMode
Definition Material.h:98
Definition MemoryManager.h:283
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:53
Definition String.h:40
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition UUID.h:66
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
Definition VulkanMaterialManager.h:106
DynamicPointer< VulkanBuffer > m_frag_uniform_buffer
Definition VulkanMaterialManager.h:191
bool m_is_wireframe
Definition VulkanMaterialManager.h:223
bool m_has_image_opacity
Definition VulkanMaterialManager.h:219
VertexUniformObject getVertexUniformObject(const Material &material, const GraphicsUpdateArguments &args) const
Definition VulkanMaterialManager.cpp:180
void addMaterial(const Material &material)
Definition VulkanMaterialManager.cpp:378
bool hasOpacity() const
Definition VulkanMaterialManager.h:124
bool hasImage() const
Definition VulkanMaterialManager.cpp:424
DynamicPointer< VulkanShaderManager > m_shader_manager
Definition VulkanMaterialManager.h:209
void updateShader(const Material &mat, const GraphicsUpdateArguments &args, DynamicPointer< VulkanShaderManager > &shader_manager)
Definition VulkanMaterialManager.cpp:401
bool m_use_model_color
Definition VulkanMaterialManager.h:227
VkDescriptorSet m_descriptor_set
Definition VulkanMaterialManager.h:205
VulkanMaterialManager(const ConstPointer< VulkanDevice > &device)
Definition VulkanMaterialManager.cpp:126
void resetPool()
Definition VulkanMaterialManager.h:161
VkSampler m_sampler
Definition VulkanMaterialManager.h:182
bool m_needs_to_commit_vert_buffer
Definition VulkanMaterialManager.h:215
Time lastDependencyUpdate() const
Definition VulkanMaterialManager.h:153
VulkanBitflagObject uvImageFlags() const
Definition VulkanMaterialManager.h:114
void getShaderCreateInfo(PrimitiveMode property, Buffer< VkPipelineShaderStageCreateInfo, uint04, ObjectAllocator< true > > &buffer) const
Definition VulkanMaterialManager.cpp:765
String getColorByChannel(GraphicsUpdateArguments &args) const
Definition VulkanMaterialManager.cpp:481
bool useNormalForTexture() const
Definition VulkanMaterialManager.h:158
ConstPointer< VulkanShader > getFragmentShader(PrimitiveMode property) const
Definition VulkanMaterialManager.cpp:497
String getExtraPropertyChannel() const
Definition VulkanMaterialManager.h:140
bool m_write_to_depth
Definition VulkanMaterialManager.h:230
void createDescriptorSet(VkDescriptorPool pool, const GraphicsUpdateArguments &args)
Definition VulkanMaterialManager.cpp:667
bool usesLayerColor() const
Definition VulkanMaterialManager.h:129
bool usesModelColor() const
Definition VulkanMaterialManager.h:128
VertexUniformObject m_vert_uniform
Definition VulkanMaterialManager.h:187
void cleanup()
Definition VulkanMaterialManager.cpp:154
UUID id() const
Definition VulkanMaterialManager.cpp:611
ConstPointer< VulkanImageView > m_uv_view[cast< uint04 >(UVType::e_uv_size)]
Definition VulkanMaterialManager.h:196
bool useLighting() const
Definition VulkanMaterialManager.cpp:881
void createSampler(const GraphicsUpdateArguments &args)
Definition VulkanMaterialManager.cpp:532
VulkanBitflagObject m_last_image_flag_object
Definition VulkanMaterialManager.h:183
VulkanMaterialManager(const VulkanMaterialManager &m_pipeline)=delete
fltp04 fadeDistance() const
Definition VulkanMaterialManager.cpp:420
Time m_last_push_update_time
Definition VulkanMaterialManager.h:200
String m_shader_name
Definition VulkanMaterialManager.h:211
bool m_smooth_normals
Definition VulkanMaterialManager.h:222
UUID m_id
Definition VulkanMaterialManager.h:232
bool m_has_grid
Definition VulkanMaterialManager.h:225
String m_image_address[cast< uint04 >(UVType::e_uv_size)]
Definition VulkanMaterialManager.h:202
bool m_needs_to_commit_frag_buffer
Definition VulkanMaterialManager.h:214
bool m_ignore_depth
Definition VulkanMaterialManager.h:229
VkDescriptorPool m_descriptor_pool
Definition VulkanMaterialManager.h:184
VulkanBitflagObject getUVImageFlags(const Material &material) const
Definition VulkanMaterialManager.cpp:159
uint04 m_layer_number
Definition VulkanMaterialManager.h:231
Vector< 3, Material::TileTextureMode > m_texture_tile_mode
Definition VulkanMaterialManager.h:207
~VulkanMaterialManager()
Definition VulkanMaterialManager.cpp:150
Buffer< Material > m_materials
Definition VulkanMaterialManager.h:181
bool m_needs_pipeline_update
Definition VulkanMaterialManager.h:216
bool isDynamic() const
Definition VulkanMaterialManager.h:127
UUID material() const
Definition VulkanMaterialManager.cpp:777
ConstPointer< VulkanDevice > m_device
Definition VulkanMaterialManager.h:185
void clearMaterials()
Definition VulkanMaterialManager.cpp:397
Time m_last_updated_time
Definition VulkanMaterialManager.h:198
bool needsToUpdateShader(const Material &material)
Definition VulkanMaterialManager.cpp:876
void updateUniformBuffer(GraphicsUpdateArguments &args)
Definition VulkanMaterialManager.cpp:212
uint04 getNumberOfImages(const GraphicsUpdateArguments &args) const
Definition VulkanMaterialManager.cpp:464
bool hasGrid() const
Definition VulkanMaterialManager.h:115
bool m_has_opacity
Definition VulkanMaterialManager.h:217
String m_extra_channel
Definition VulkanMaterialManager.h:206
static VkDescriptorSetLayout descriptorSetLayout(ConstPointer< VulkanDevice > device)
Definition VulkanMaterialManager.cpp:566
DynamicPointer< VulkanBuffer > m_vertex_uniform_buffer
Definition VulkanMaterialManager.h:190
fltp04 m_depth_bias
Definition VulkanMaterialManager.h:212
bool m_use_layer_color
Definition VulkanMaterialManager.h:228
bool ignoreDepth() const
Definition VulkanMaterialManager.h:125
bool m_is_dynamic
Definition VulkanMaterialManager.h:224
bool isWireframe() const
Definition VulkanMaterialManager.h:156
fltp04 depthBias() const
Definition VulkanMaterialManager.h:131
bool needsToUpdateImage(const Material &material)
Definition VulkanMaterialManager.cpp:856
bool overrideCamera() const
Definition VulkanMaterialManager.h:157
bool writeToDepth() const
Definition VulkanMaterialManager.h:126
void getDescriptorWrites(Buffer< VkWriteDescriptorSet, uint04, ObjectAllocator< true > > &descriptor_writes, Buffer< VkDescriptorImageInfo, uint04, ObjectAllocator< true > > &image_info) const
Definition VulkanMaterialManager.cpp:718
bool m_use_normal_for_texture
Definition VulkanMaterialManager.h:226
void commit()
Definition VulkanMaterialManager.cpp:433
FragUniformObject getFragUniformObject(const Material &material) const
Definition VulkanMaterialManager.cpp:187
bool m_is_two_sided
Definition VulkanMaterialManager.h:220
void checkImages()
Definition VulkanMaterialManager.cpp:175
const VertexUniformObject & vertexUniform() const
Definition VulkanMaterialManager.h:118
uint04 m_number_of_uniforms
Definition VulkanMaterialManager.h:197
bool smoothNormals() const
Definition VulkanMaterialManager.cpp:891
Material::ShadingModel m_shade_model
Definition VulkanMaterialManager.h:210
bool m_override_camera
Definition VulkanMaterialManager.h:221
void createPipeline(GraphicsUpdateArguments &args, DynamicPointer< VulkanShaderManager > &shader_manager, DynamicPointer< VulkanImageManager > &image_manager, VkDescriptorPool pool)
Definition VulkanMaterialManager.cpp:450
bool m_has_image
Definition VulkanMaterialManager.h:218
VkDescriptorSet descriptorSet() const
Definition VulkanMaterialManager.h:147
FragUniformObject m_frag_uniform
Definition VulkanMaterialManager.h:188
bool isTwoSided() const
Definition VulkanMaterialManager.h:155
static UUID MaterialID(const Material &material)
Definition VulkanMaterialManager.cpp:615
uint04 getLayerNumber(const Material &material) const
Definition VulkanMaterialManager.cpp:896
void updateImages(const Material &mat, const GraphicsUpdateArguments &args, DynamicPointer< VulkanImageManager > &image_manager)
Definition VulkanMaterialManager.cpp:785
VulkanBitflagObject getBitflagObject() const
Definition VulkanMaterialManager.cpp:196
ConstPointer< VulkanImageData > m_uv_data[cast< uint04 >(UVType::e_uv_size)]
Definition VulkanMaterialManager.h:195
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
PrimitiveMode
Definition DesignObjectBase.h:113
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
Definition BaseValues.hpp:272
Definition VulkanMaterialManager.h:62
Vector< 16, fltp04 > float_values
Definition VulkanMaterialManager.h:76
FloatPosition
Definition VulkanMaterialManager.h:71
@ e_max_value_frag_pos
Definition GLESMaterialManager.h:65
@ e_min_value_frag_pos
Definition GLESMaterialManager.h:63
@ e_mid_value_frag_pos
Definition GLESMaterialManager.h:64
fltp04 shininess
Definition GLESMaterialManager.h:74
fltp04 opacity
Definition GLESMaterialManager.h:75
fltp04 fade_distance
Definition GLESMaterialManager.h:71
FragUniformObject()
Definition VulkanMaterialManager.h:92
fltp04 max_distance
Definition GLESMaterialManager.h:72
Vector< 4, sint04 > m_grid_lines_desc
Definition GLESMaterialManager.h:70
Vector< 12, RGBColor > palette_colors
Definition GLESMaterialManager.h:68
uint04 palette_size
Definition VulkanMaterialManager.h:88
VulkanBitflagObject tex_flags
Definition VulkanMaterialManager.h:89
void setMode(Material::TextureCoordMode mat_mode)
Definition VulkanMaterialManager.h:97
FragUniformObject(const Material &m_material)
uint04 texture_coord_mode
Definition GLESMaterialManager.h:78
Vector< 4, sint04 > m_grid_lines
Definition GLESMaterialManager.h:69
uint04 layer_number
Definition VulkanMaterialManager.h:85
ColorPosition
Definition VulkanMaterialManager.h:64
@ e_ks_frag_pos
Definition GLESMaterialManager.h:58
@ e_ka_frag_pos
Definition GLESMaterialManager.h:57
@ e_kd_frag_pos
Definition GLESMaterialManager.h:56
@ e_kr_frag_pos
Definition GLESMaterialManager.h:59
Definition VulkanMaterialManager.h:53
fltp04 pixel_thickness
Definition GLESMaterialManager.h:45
fltp04 reserved2
Definition GLESMaterialManager.h:48
fltp04 reserved0
Definition GLESMaterialManager.h:46
fltp04 reserved1
Definition GLESMaterialManager.h:47
Definition VulkanBitflagObject.h:38