2019-04-25 10:09:56 +08:00
|
|
|
|
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
|
|
|
|
#define HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
|
|
|
|
|
|
|
|
|
#include"VK.h"
|
2019-04-28 16:06:53 +08:00
|
|
|
|
#include<hgl/type/Map.h>
|
|
|
|
|
#include<hgl/type/BaseString.h>
|
2019-04-25 10:09:56 +08:00
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-27 01:36:58 +08:00
|
|
|
|
class Device;
|
2019-04-28 16:06:53 +08:00
|
|
|
|
class ShaderModule;
|
|
|
|
|
class VertexShaderModule;
|
2019-04-25 10:09:56 +08:00
|
|
|
|
class DescriptorSetLayoutCreater;
|
2019-04-27 02:07:06 +08:00
|
|
|
|
class DescriptorSetLayout;
|
2019-04-25 10:09:56 +08:00
|
|
|
|
class MaterialInstance;
|
2019-04-26 22:34:51 +08:00
|
|
|
|
class VertexAttributeBinding;
|
2019-04-28 17:02:38 +08:00
|
|
|
|
class VertexBuffer;
|
|
|
|
|
class Renderable;
|
2019-04-28 17:47:58 +08:00
|
|
|
|
class PipelineLayout;
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
|
|
|
|
using ShaderModuleMap=hgl::Map<VkShaderStageFlagBits,const ShaderModule *>;
|
2019-04-25 10:09:56 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 材质类<br>
|
|
|
|
|
* 用于管理shader,提供DescriptorSetLayoutCreater
|
|
|
|
|
*/
|
|
|
|
|
class Material
|
|
|
|
|
{
|
2019-04-28 16:06:53 +08:00
|
|
|
|
VkDevice device;
|
|
|
|
|
ShaderModuleMap *shader_maps;
|
|
|
|
|
VertexShaderModule *vertex_sm;
|
|
|
|
|
List<VkPipelineShaderStageCreateInfo> shader_stage_list;
|
|
|
|
|
|
2019-04-27 02:07:06 +08:00
|
|
|
|
DescriptorSetLayoutCreater *dsl_creater;
|
2019-04-25 10:09:56 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2019-04-28 16:06:53 +08:00
|
|
|
|
Material(Device *dev,ShaderModuleMap *smm);
|
2019-04-25 10:09:56 +08:00
|
|
|
|
~Material();
|
|
|
|
|
|
2019-04-28 16:06:53 +08:00
|
|
|
|
const int GetUBOBinding(const UTF8String &)const;
|
2019-04-28 17:02:38 +08:00
|
|
|
|
const int GetVBOBinding(const UTF8String &)const;
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
|
|
|
|
MaterialInstance *CreateInstance()const;
|
|
|
|
|
|
2019-04-28 17:02:38 +08:00
|
|
|
|
const uint32_t GetStageCount ()const{return shader_stage_list.GetCount();}
|
|
|
|
|
const VkPipelineShaderStageCreateInfo * GetStages ()const{return shader_stage_list.GetData();}
|
2019-04-25 10:09:56 +08:00
|
|
|
|
};//class Material
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 材质实例<br>
|
|
|
|
|
* 用于在指定Material的情况下,具体绑定UBO/TEXTURE等,提供pipeline
|
|
|
|
|
*/
|
|
|
|
|
class MaterialInstance
|
|
|
|
|
{
|
2019-04-28 17:47:58 +08:00
|
|
|
|
VkDevice device;
|
2019-04-26 21:43:22 +08:00
|
|
|
|
const Material *mat; ///<这里的是对material的完全引用,不做任何修改
|
2019-04-28 17:02:38 +08:00
|
|
|
|
const VertexShaderModule *vertex_sm;
|
2019-04-27 01:36:58 +08:00
|
|
|
|
VertexAttributeBinding *vab;
|
2019-04-27 02:07:06 +08:00
|
|
|
|
DescriptorSetLayout *desc_set_layout;
|
2019-04-25 10:09:56 +08:00
|
|
|
|
|
2019-04-28 17:47:58 +08:00
|
|
|
|
VkPipelineLayout pipeline_layout;
|
|
|
|
|
|
2019-04-25 10:09:56 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2019-04-28 17:47:58 +08:00
|
|
|
|
MaterialInstance(VkDevice dev,const Material *m,const VertexShaderModule *,VertexAttributeBinding *v,DescriptorSetLayout *d,VkPipelineLayout pl);
|
2019-04-25 10:09:56 +08:00
|
|
|
|
~MaterialInstance();
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
|
|
|
|
bool UpdateUBO(const uint32_t binding,const VkDescriptorBufferInfo *buf_info);
|
|
|
|
|
bool UpdateUBO(const UTF8String &name,const VkDescriptorBufferInfo *buf_info)
|
|
|
|
|
{
|
|
|
|
|
if(name.IsEmpty()||!buf_info)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return UpdateUBO(mat->GetUBOBinding(name),buf_info);
|
|
|
|
|
}
|
2019-04-28 17:47:58 +08:00
|
|
|
|
|
2019-04-28 16:06:53 +08:00
|
|
|
|
const uint32_t GetStageCount ()const{return mat->GetStageCount();}
|
|
|
|
|
const VkPipelineShaderStageCreateInfo * GetStages ()const{return mat->GetStages();}
|
2019-04-28 17:02:38 +08:00
|
|
|
|
|
2019-04-28 16:06:53 +08:00
|
|
|
|
void Write(VkPipelineVertexInputStateCreateInfo &vis)const;
|
|
|
|
|
|
2019-04-28 17:47:58 +08:00
|
|
|
|
const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;}
|
|
|
|
|
const List<VkDescriptorSet> * GetDescriptorSets ()const;
|
2019-04-28 17:02:38 +08:00
|
|
|
|
|
|
|
|
|
Renderable *CreateRenderable();
|
2019-04-25 10:09:56 +08:00
|
|
|
|
};//class MaterialInstance
|
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|