refactor and renamed MaterialInstance to MaterialParameters.
This commit is contained in:
parent
bc8848afa6
commit
3658171954
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit c22207b6401476bf8859e581a28346326e6d482b
|
Subproject commit 109e52db4da1c88a30ecb33e121f9ac06fcab397
|
@ -15,7 +15,7 @@
|
|||||||
#include<hgl/graph/VKFormat.h>
|
#include<hgl/graph/VKFormat.h>
|
||||||
#include<hgl/graph/VKFramebuffer.h>
|
#include<hgl/graph/VKFramebuffer.h>
|
||||||
#include<hgl/graph/VKMaterial.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VKRenderTarget.h>
|
#include<hgl/graph/VKRenderTarget.h>
|
||||||
#include<hgl/graph/VKRenderResource.h>
|
#include<hgl/graph/VKRenderResource.h>
|
||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/RenderList.h>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/RenderList.h>
|
||||||
#include<hgl/graph/VKPipeline.h>
|
#include<hgl/graph/VKPipeline.h>
|
||||||
#include<hgl/graph/VKMaterial.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
|
|
||||||
using RenderNodePointer=hgl::graph::RenderNode *;
|
using RenderNodePointer=hgl::graph::RenderNode *;
|
||||||
|
|
||||||
|
@ -54,7 +54,21 @@ class RenderPass;
|
|||||||
class GPUFence;
|
class GPUFence;
|
||||||
class GPUSemaphore;
|
class GPUSemaphore;
|
||||||
|
|
||||||
|
enum class DescriptorSetsType
|
||||||
|
{
|
||||||
|
//设计使其对应shader中的sets
|
||||||
|
|
||||||
|
Material=0, ///<材质中永远不变的参数
|
||||||
|
// Texture, ///<材质中的纹理参数
|
||||||
|
Values, ///<材质中的变量参数
|
||||||
|
Renderable, ///<渲染实例参数(如Local2World matrix)
|
||||||
|
Global, ///<全局参数(如太阳光等)
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(Material,Global)
|
||||||
|
};//
|
||||||
|
|
||||||
class DescriptorSetLayoutCreater;
|
class DescriptorSetLayoutCreater;
|
||||||
|
class DescriptorSets;
|
||||||
|
|
||||||
struct ShaderStage;
|
struct ShaderStage;
|
||||||
|
|
||||||
@ -67,7 +81,6 @@ class PipelineLayout;
|
|||||||
struct PipelineData;
|
struct PipelineData;
|
||||||
enum class InlinePipeline;
|
enum class InlinePipeline;
|
||||||
class Pipeline;
|
class Pipeline;
|
||||||
class DescriptorSets;
|
|
||||||
class VertexAttributeBinding;
|
class VertexAttributeBinding;
|
||||||
|
|
||||||
class Renderable;
|
class Renderable;
|
||||||
|
@ -23,8 +23,7 @@ class Material
|
|||||||
|
|
||||||
DescriptorSetLayoutCreater *dsl_creater;
|
DescriptorSetLayoutCreater *dsl_creater;
|
||||||
|
|
||||||
DescriptorSets *g_desc_sets;
|
MaterialParameters *mp_m,*mp_g,*mp_r;
|
||||||
DescriptorSets *ri_desc_sets;
|
|
||||||
|
|
||||||
VertexAttributeBinding *vab;
|
VertexAttributeBinding *vab;
|
||||||
|
|
||||||
@ -63,11 +62,7 @@ public:
|
|||||||
const VkPipelineShaderStageCreateInfo * GetStages ()const{return shader_stage_list->GetData();}
|
const VkPipelineShaderStageCreateInfo * GetStages ()const{return shader_stage_list->GetData();}
|
||||||
|
|
||||||
const VkPipelineLayout GetPipelineLayout ()const;
|
const VkPipelineLayout GetPipelineLayout ()const;
|
||||||
DescriptorSets * CreateMIDescriptorSets ()const;
|
|
||||||
|
|
||||||
DescriptorSets * GetGlobalDescriptorSets (){return g_desc_sets;}
|
|
||||||
DescriptorSets * GetRIDescriptorSets (){return ri_desc_sets;}
|
|
||||||
|
|
||||||
const VertexAttributeBinding * GetVAB ()const{return vab;}
|
const VertexAttributeBinding * GetVAB ()const{return vab;}
|
||||||
const uint32_t GetVertexAttrCount ()const{return vab->GetVertexAttrCount();}
|
const uint32_t GetVertexAttrCount ()const{return vab->GetVertexAttrCount();}
|
||||||
const VkVertexInputBindingDescription * GetVertexBindingList ()const{return vab->GetVertexBindingList();}
|
const VkVertexInputBindingDescription * GetVertexBindingList ()const{return vab->GetVertexBindingList();}
|
||||||
@ -75,7 +70,14 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MaterialParameters * CreateInstance ();
|
MaterialParameters * CreateMP (const DescriptorSetsType &type=DescriptorSetsType::Values);
|
||||||
|
MaterialParameters * GetMP (const DescriptorSetsType &type)
|
||||||
|
{
|
||||||
|
if(type==DescriptorSetsType::Material )return mp_m;else
|
||||||
|
if(type==DescriptorSetsType::Renderable )return mp_r;else
|
||||||
|
if(type==DescriptorSetsType::Global )return mp_g;else
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
};//class Material
|
};//class Material
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
|
|
||||||
#define MP_TYPE_IS(name) const bool is##name()const{return ds_type==DescriptorSetsType::name;}
|
#define MP_TYPE_IS(name) const bool is##name()const{return ds_type==DescriptorSetsType::name;}
|
||||||
MP_TYPE_IS(Material)
|
MP_TYPE_IS(Material)
|
||||||
MP_TYPE_IS(Texture)
|
// MP_TYPE_IS(Texture)
|
||||||
MP_TYPE_IS(Values)
|
MP_TYPE_IS(Values)
|
||||||
MP_TYPE_IS(Renderable)
|
MP_TYPE_IS(Renderable)
|
||||||
MP_TYPE_IS(Global)
|
MP_TYPE_IS(Global)
|
@ -8,7 +8,7 @@
|
|||||||
#include<hgl/graph/VKBuffer.h>
|
#include<hgl/graph/VKBuffer.h>
|
||||||
#include<hgl/graph/VKSampler.h>
|
#include<hgl/graph/VKSampler.h>
|
||||||
#include<hgl/graph/VKTexture.h>
|
#include<hgl/graph/VKTexture.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VertexAttribData.h>
|
#include<hgl/graph/VertexAttribData.h>
|
||||||
#include<hgl/graph/VKRenderableInstance.h>
|
#include<hgl/graph/VKRenderableInstance.h>
|
||||||
#include<hgl/graph/font/TextRenderable.h>
|
#include<hgl/graph/font/TextRenderable.h>
|
||||||
|
@ -55,11 +55,11 @@ public:
|
|||||||
public: //pipeline
|
public: //pipeline
|
||||||
|
|
||||||
Pipeline *CreatePipeline(Material *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
Pipeline *CreatePipeline(Material *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
Pipeline *CreatePipeline(MaterialParameters *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||||
Pipeline *CreatePipeline(Material *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
Pipeline *CreatePipeline(Material *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||||
Pipeline *CreatePipeline(MaterialInstance *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
Pipeline *CreatePipeline(MaterialParameters *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||||
Pipeline *CreatePipeline(Material *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
Pipeline *CreatePipeline(Material *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
Pipeline *CreatePipeline(MaterialParameters *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||||
|
|
||||||
public: // command buffer
|
public: // command buffer
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include<hgl/graph/VKRenderable.h>
|
#include<hgl/graph/VKRenderable.h>
|
||||||
#include<hgl/graph/VKPipeline.h>
|
#include<hgl/graph/VKPipeline.h>
|
||||||
#include<hgl/graph/VKDescriptorSets.h>
|
#include<hgl/graph/VKDescriptorSets.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
/**
|
/**
|
||||||
* 可渲染对象实例<br>
|
* 可渲染对象实例<br>
|
||||||
|
@ -7,25 +7,6 @@
|
|||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
/**
|
|
||||||
* Shader数据来源
|
|
||||||
*/
|
|
||||||
enum class ShaderDataSource
|
|
||||||
{
|
|
||||||
Global=0, ///<由全局系统提供的数据(如CameraMatrix)
|
|
||||||
Private=1, ///<每种材质的私有数据
|
|
||||||
};//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shader数据来源类型
|
|
||||||
*/
|
|
||||||
enum class ShaderDataSourceType
|
|
||||||
{
|
|
||||||
Static=0,
|
|
||||||
Dynamic,
|
|
||||||
Instance
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ShaderStage
|
struct ShaderStage
|
||||||
{
|
{
|
||||||
AnsiString name;
|
AnsiString name;
|
||||||
@ -51,17 +32,6 @@ struct ShaderDescriptor
|
|||||||
|
|
||||||
using ShaderDescriptorList=List<ShaderDescriptor>;
|
using ShaderDescriptorList=List<ShaderDescriptor>;
|
||||||
|
|
||||||
enum class DescriptorSetsType
|
|
||||||
{
|
|
||||||
//设计使其对应shader中的sets
|
|
||||||
|
|
||||||
Material=0, ///<材质中永远不变的参数
|
|
||||||
Texture, ///<材质中的纹理参数
|
|
||||||
Values, ///<材质中的变量参数
|
|
||||||
Renderable, ///<渲染实例参数(如Local2World matrix)
|
|
||||||
Global, ///<全局参数(如太阳光等)
|
|
||||||
};//
|
|
||||||
|
|
||||||
#ifndef VK_DESCRIPTOR_TYPE_BEGIN_RANGE
|
#ifndef VK_DESCRIPTOR_TYPE_BEGIN_RANGE
|
||||||
constexpr size_t VK_DESCRIPTOR_TYPE_BEGIN_RANGE=VK_DESCRIPTOR_TYPE_SAMPLER;
|
constexpr size_t VK_DESCRIPTOR_TYPE_BEGIN_RANGE=VK_DESCRIPTOR_TYPE_SAMPLER;
|
||||||
#endif//VK_DESCRIPTOR_TYPE_BEGIN_RANGE
|
#endif//VK_DESCRIPTOR_TYPE_BEGIN_RANGE
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/gui/ThemeEngine.h>
|
#include<hgl/gui/ThemeEngine.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
|
||||||
#include<hgl/graph/VKPipeline.h>
|
#include<hgl/graph/VKPipeline.h>
|
||||||
#include<hgl/type/Map.h>
|
#include<hgl/type/Map.h>
|
||||||
#include"DefaultThemeForm.h"
|
#include"DefaultThemeForm.h"
|
||||||
|
@ -122,6 +122,7 @@ SET(VK_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h
|
|||||||
Vulkan/VKDeviceBuffer.cpp
|
Vulkan/VKDeviceBuffer.cpp
|
||||||
Vulkan/VKDeviceImage.cpp
|
Vulkan/VKDeviceImage.cpp
|
||||||
Vulkan/VKDeviceTexture.cpp
|
Vulkan/VKDeviceTexture.cpp
|
||||||
|
Vulkan/VKDeviceMaterial.cpp
|
||||||
Vulkan/VKDeviceFramebuffer.cpp
|
Vulkan/VKDeviceFramebuffer.cpp
|
||||||
Vulkan/VKDeviceSwapchain.cpp
|
Vulkan/VKDeviceSwapchain.cpp
|
||||||
Vulkan/VKDeviceRenderPass.cpp
|
Vulkan/VKDeviceRenderPass.cpp
|
||||||
@ -159,9 +160,9 @@ SET(VK_TEXTURE_SOURCE ${SG_INCLUDE_PATH}/VKImageView.h
|
|||||||
Vulkan/VKTextureLoader.cpp)
|
Vulkan/VKTextureLoader.cpp)
|
||||||
|
|
||||||
SET(VK_MATERIAL_SOURCE ${SG_INCLUDE_PATH}/VKMaterial.h
|
SET(VK_MATERIAL_SOURCE ${SG_INCLUDE_PATH}/VKMaterial.h
|
||||||
${SG_INCLUDE_PATH}/VKMaterialInstance.h
|
${SG_INCLUDE_PATH}/VKMaterialParameters.h
|
||||||
Vulkan/VKMaterial.cpp
|
Vulkan/VKMaterial.cpp
|
||||||
Vulkan/VKMaterialInstance.cpp)
|
Vulkan/VKMaterialParameters.cpp)
|
||||||
|
|
||||||
SOURCE_GROUP("Vulkan\\Material" FILES ${VK_MATERIAL_SOURCE})
|
SOURCE_GROUP("Vulkan\\Material" FILES ${VK_MATERIAL_SOURCE})
|
||||||
SOURCE_GROUP("Vulkan\\Material\\Texture" FILES ${VK_TEXTURE_SOURCE})
|
SOURCE_GROUP("Vulkan\\Material\\Texture" FILES ${VK_TEXTURE_SOURCE})
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include<hgl/graph/VKRenderable.h>
|
#include<hgl/graph/VKRenderable.h>
|
||||||
#include<hgl/graph/VKCommandBuffer.h>
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VKRenderableInstance.h>
|
#include<hgl/graph/VKRenderableInstance.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
|
@ -35,8 +35,7 @@ void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDesc
|
|||||||
{
|
{
|
||||||
//重复的绑定点是有可能存在的,比如CameraInfo在vs/fs中同时存在
|
//重复的绑定点是有可能存在的,比如CameraInfo在vs/fs中同时存在
|
||||||
|
|
||||||
if((!index_by_binding.KeyExist(sd.binding))
|
if(!all_index_by_binding.KeyExist(sd.binding))
|
||||||
&&(!index_by_binding_ri.KeyExist(sd.binding)))
|
|
||||||
{
|
{
|
||||||
p->binding = sd.binding;
|
p->binding = sd.binding;
|
||||||
p->descriptorType = desc_type;
|
p->descriptorType = desc_type;
|
||||||
@ -45,15 +44,16 @@ void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDesc
|
|||||||
p->pImmutableSamplers = nullptr;
|
p->pImmutableSamplers = nullptr;
|
||||||
|
|
||||||
if(sd.name[0]=='r'
|
if(sd.name[0]=='r'
|
||||||
&&sd.name[1]=='i'
|
&&sd.name[1]=='_')
|
||||||
&&sd.name[2]=='_')
|
index_by_binding[(size_t)DescriptorSetsType::Renderable].Add(sd.binding,fin_count+old_count);
|
||||||
index_by_binding_ri.Add(sd.binding,fin_count+old_count);
|
|
||||||
else
|
else
|
||||||
if(sd.name[0]=='g'
|
if(sd.name[0]=='g'
|
||||||
&&sd.name[1]=='_')
|
&&sd.name[1]=='_')
|
||||||
index_by_binding_global.Add(sd.binding,fin_count+old_count);
|
index_by_binding[(size_t)DescriptorSetsType::Global].Add(sd.binding,fin_count+old_count);
|
||||||
else
|
else
|
||||||
index_by_binding.Add(sd.binding,fin_count+old_count);
|
index_by_binding[(size_t)DescriptorSetsType::Values].Add(sd.binding,fin_count+old_count);
|
||||||
|
|
||||||
|
all_index_by_binding.Add(sd.binding,fin_count+old_count);
|
||||||
|
|
||||||
++p;
|
++p;
|
||||||
++fin_count;
|
++fin_count;
|
||||||
@ -113,14 +113,15 @@ DescriptorSets *DescriptorSetLayoutCreater::Create(const DescriptorSetsType &typ
|
|||||||
BindingMapping *bm=nullptr;
|
BindingMapping *bm=nullptr;
|
||||||
|
|
||||||
if(type==DescriptorSetsType::Material
|
if(type==DescriptorSetsType::Material
|
||||||
||type==DescriptorSetsType::MaterialInstance) //未开会区分开
|
// ||type==DescriptorSetsType::Texture
|
||||||
bm=&index_by_binding;
|
||type==DescriptorSetsType::Values) //未来会区分开
|
||||||
|
bm=&index_by_binding[(size_t)DescriptorSetsType::Values];
|
||||||
else
|
else
|
||||||
if(type==DescriptorSetsType::RenderableInstance)
|
if(type==DescriptorSetsType::Renderable)
|
||||||
bm=&index_by_binding_ri;
|
bm=&index_by_binding[(size_t)DescriptorSetsType::Renderable];
|
||||||
else
|
else
|
||||||
if(type==DescriptorSetsType::Global)
|
if(type==DescriptorSetsType::Global)
|
||||||
bm=&index_by_binding_global;
|
bm=&index_by_binding[(size_t)DescriptorSetsType::Global];
|
||||||
else
|
else
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
|
@ -17,9 +17,8 @@ class DescriptorSetLayoutCreater
|
|||||||
List<VkDescriptorSetLayoutBinding> layout_binding_list;
|
List<VkDescriptorSetLayoutBinding> layout_binding_list;
|
||||||
VkDescriptorSetLayout dsl=VK_NULL_HANDLE;
|
VkDescriptorSetLayout dsl=VK_NULL_HANDLE;
|
||||||
|
|
||||||
BindingMapping index_by_binding;
|
BindingMapping all_index_by_binding;
|
||||||
BindingMapping index_by_binding_ri;
|
BindingMapping index_by_binding[size_t(DescriptorSetsType::RANGE_SIZE)];
|
||||||
BindingMapping index_by_binding_global;
|
|
||||||
|
|
||||||
VkPipelineLayout pipeline_layout=VK_NULL_HANDLE;
|
VkPipelineLayout pipeline_layout=VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
83
src/SceneGraph/Vulkan/VKDeviceMaterial.cpp
Normal file
83
src/SceneGraph/Vulkan/VKDeviceMaterial.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#include<hgl/graph/VKDevice.h>
|
||||||
|
#include<hgl/graph/VKMaterial.h>
|
||||||
|
#include"VKDescriptorSetLayoutCreater.h"
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *shader_maps)
|
||||||
|
{
|
||||||
|
const int shader_count=shader_maps->GetCount();
|
||||||
|
|
||||||
|
if(shader_count<2)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
const ShaderModule *sm;
|
||||||
|
|
||||||
|
if(!shader_maps->Get(VK_SHADER_STAGE_VERTEX_BIT,sm))
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
DescriptorSetLayoutCreater *dsl_creater=CreateDescriptorSetLayoutCreater();
|
||||||
|
List<VkPipelineShaderStageCreateInfo> *shader_stage_list=new List<VkPipelineShaderStageCreateInfo>;
|
||||||
|
|
||||||
|
shader_stage_list->SetCount(shader_count);
|
||||||
|
|
||||||
|
VkPipelineShaderStageCreateInfo *p=shader_stage_list->GetData();
|
||||||
|
|
||||||
|
auto **itp=shader_maps->GetDataList();
|
||||||
|
for(int i=0;i<shader_count;i++)
|
||||||
|
{
|
||||||
|
sm=(*itp)->right;
|
||||||
|
hgl_cpy(p,sm->GetCreateInfo());
|
||||||
|
|
||||||
|
dsl_creater->Bind(sm->GetDescriptorList(),sm->GetStage());
|
||||||
|
|
||||||
|
++p;
|
||||||
|
++itp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!dsl_creater->CreatePipelineLayout())
|
||||||
|
{
|
||||||
|
delete shader_stage_list;
|
||||||
|
delete dsl_creater;
|
||||||
|
delete shader_maps;
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(new Material(mtl_name,shader_maps,shader_stage_list,dsl_creater));
|
||||||
|
}
|
||||||
|
|
||||||
|
Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module)
|
||||||
|
{
|
||||||
|
if(!vertex_shader_module||!fragment_shader_module)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
if(!vertex_shader_module->IsVertex())return(nullptr);
|
||||||
|
if(!fragment_shader_module->IsFragment())return(nullptr);
|
||||||
|
|
||||||
|
ShaderModuleMap *smm=new ShaderModuleMap;
|
||||||
|
|
||||||
|
smm->Add(vertex_shader_module);
|
||||||
|
smm->Add(fragment_shader_module);
|
||||||
|
|
||||||
|
return CreateMaterial(mtl_name,smm);
|
||||||
|
}
|
||||||
|
|
||||||
|
Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module)
|
||||||
|
{
|
||||||
|
if(!vertex_shader_module
|
||||||
|
||!geometry_shader_module
|
||||||
|
||!fragment_shader_module)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
if(!vertex_shader_module->IsVertex())return(nullptr);
|
||||||
|
if(!geometry_shader_module->IsGeometry())return(nullptr);
|
||||||
|
if(!fragment_shader_module->IsFragment())return(nullptr);
|
||||||
|
|
||||||
|
ShaderModuleMap *smm=new ShaderModuleMap;
|
||||||
|
|
||||||
|
smm->Add(vertex_shader_module);
|
||||||
|
smm->Add(geometry_shader_module);
|
||||||
|
smm->Add(fragment_shader_module);
|
||||||
|
|
||||||
|
return CreateMaterial(mtl_name,smm);
|
||||||
|
}
|
||||||
|
VK_NAMESPACE_END
|
@ -1,90 +1,7 @@
|
|||||||
#include<hgl/graph/VKMaterial.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
#include<hgl/graph/VKDevice.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VKDescriptorSets.h>
|
|
||||||
#include<hgl/graph/VKShaderModule.h>
|
|
||||||
#include<hgl/graph/VKShaderModuleMap.h>
|
|
||||||
#include<hgl/graph/VKVertexAttributeBinding.h>
|
|
||||||
#include<hgl/graph/VKBuffer.h>
|
|
||||||
#include"VKDescriptorSetLayoutCreater.h"
|
#include"VKDescriptorSetLayoutCreater.h"
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *shader_maps)
|
|
||||||
{
|
|
||||||
const int shader_count=shader_maps->GetCount();
|
|
||||||
|
|
||||||
if(shader_count<2)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
const ShaderModule *sm;
|
|
||||||
|
|
||||||
if(!shader_maps->Get(VK_SHADER_STAGE_VERTEX_BIT,sm))
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
DescriptorSetLayoutCreater *dsl_creater=CreateDescriptorSetLayoutCreater();
|
|
||||||
List<VkPipelineShaderStageCreateInfo> *shader_stage_list=new List<VkPipelineShaderStageCreateInfo>;
|
|
||||||
|
|
||||||
shader_stage_list->SetCount(shader_count);
|
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo *p=shader_stage_list->GetData();
|
|
||||||
|
|
||||||
auto **itp=shader_maps->GetDataList();
|
|
||||||
for(int i=0;i<shader_count;i++)
|
|
||||||
{
|
|
||||||
sm=(*itp)->right;
|
|
||||||
hgl_cpy(p,sm->GetCreateInfo());
|
|
||||||
|
|
||||||
dsl_creater->Bind(sm->GetDescriptorList(),sm->GetStage());
|
|
||||||
|
|
||||||
++p;
|
|
||||||
++itp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!dsl_creater->CreatePipelineLayout())
|
|
||||||
{
|
|
||||||
delete shader_stage_list;
|
|
||||||
delete dsl_creater;
|
|
||||||
delete shader_maps;
|
|
||||||
return(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(new Material(mtl_name,shader_maps,shader_stage_list,dsl_creater));
|
|
||||||
}
|
|
||||||
|
|
||||||
Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module)
|
|
||||||
{
|
|
||||||
if(!vertex_shader_module||!fragment_shader_module)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
if(!vertex_shader_module->IsVertex())return(nullptr);
|
|
||||||
if(!fragment_shader_module->IsFragment())return(nullptr);
|
|
||||||
|
|
||||||
ShaderModuleMap *smm=new ShaderModuleMap;
|
|
||||||
|
|
||||||
smm->Add(vertex_shader_module);
|
|
||||||
smm->Add(fragment_shader_module);
|
|
||||||
|
|
||||||
return CreateMaterial(mtl_name,smm);
|
|
||||||
}
|
|
||||||
|
|
||||||
Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module)
|
|
||||||
{
|
|
||||||
if(!vertex_shader_module
|
|
||||||
||!geometry_shader_module
|
|
||||||
||!fragment_shader_module)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
if(!vertex_shader_module->IsVertex())return(nullptr);
|
|
||||||
if(!geometry_shader_module->IsGeometry())return(nullptr);
|
|
||||||
if(!fragment_shader_module->IsFragment())return(nullptr);
|
|
||||||
|
|
||||||
ShaderModuleMap *smm=new ShaderModuleMap;
|
|
||||||
|
|
||||||
smm->Add(vertex_shader_module);
|
|
||||||
smm->Add(geometry_shader_module);
|
|
||||||
smm->Add(fragment_shader_module);
|
|
||||||
|
|
||||||
return CreateMaterial(mtl_name,smm);
|
|
||||||
}
|
|
||||||
|
|
||||||
Material::Material(const UTF8String &name,ShaderModuleMap *smm,List<VkPipelineShaderStageCreateInfo> *psci_list,DescriptorSetLayoutCreater *dslc)
|
Material::Material(const UTF8String &name,ShaderModuleMap *smm,List<VkPipelineShaderStageCreateInfo> *psci_list,DescriptorSetLayoutCreater *dslc)
|
||||||
{
|
{
|
||||||
mtl_name=name;
|
mtl_name=name;
|
||||||
@ -105,12 +22,17 @@ Material::Material(const UTF8String &name,ShaderModuleMap *smm,List<VkPipelineSh
|
|||||||
vab=nullptr;
|
vab=nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ri_desc_sets=dsl_creater->Create(DescriptorSetsType::RenderableInstance);
|
mp_m=CreateMP(DescriptorSetsType::Material);
|
||||||
|
mp_r=CreateMP(DescriptorSetsType::Renderable);
|
||||||
|
mp_g=CreateMP(DescriptorSetsType::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
Material::~Material()
|
Material::~Material()
|
||||||
{
|
{
|
||||||
SAFE_CLEAR(ri_desc_sets);
|
SAFE_CLEAR(mp_m);
|
||||||
|
SAFE_CLEAR(mp_r);
|
||||||
|
SAFE_CLEAR(mp_g);
|
||||||
|
|
||||||
delete dsl_creater;
|
delete dsl_creater;
|
||||||
|
|
||||||
if(vab)
|
if(vab)
|
||||||
@ -153,8 +75,12 @@ const VkPipelineLayout Material::GetPipelineLayout()const
|
|||||||
return dsl_creater->GetPipelineLayout();
|
return dsl_creater->GetPipelineLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
DescriptorSets *Material::CreateMIDescriptorSets()const
|
MaterialParameters *Material::CreateMP(const DescriptorSetsType &type)
|
||||||
{
|
{
|
||||||
return dsl_creater->Create(DescriptorSetsType::MaterialInstance);
|
DescriptorSets *ds=dsl_creater->Create(type);
|
||||||
|
|
||||||
|
if(!ds)return(nullptr);
|
||||||
|
|
||||||
|
return(new MaterialParameters(this,type,ds));
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
|
|
||||||
#include<hgl/graph/VKMaterial.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
#include<hgl/graph/VKDescriptorSets.h>
|
#include<hgl/graph/VKDescriptorSets.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
MaterialParameters::MaterialParameters(Material *m,DescriptorSets *ds)
|
MaterialParameters::MaterialParameters(Material *m,const DescriptorSetsType &type,DescriptorSets *ds)
|
||||||
{
|
{
|
||||||
material=m;
|
material=m;
|
||||||
|
ds_type=type;
|
||||||
descriptor_sets=ds;
|
descriptor_sets=ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,13 +68,4 @@ void MaterialParameters::Update()
|
|||||||
{
|
{
|
||||||
descriptor_sets->Update();
|
descriptor_sets->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialParameters *Material::CreateInstance()
|
|
||||||
{
|
|
||||||
DescriptorSets *ds=CreateMIDescriptorSets();
|
|
||||||
|
|
||||||
if(!ds)return(nullptr);
|
|
||||||
|
|
||||||
return(new MaterialParameters(this,ds));
|
|
||||||
}
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
@ -54,7 +54,7 @@ MaterialParameters *RenderResource::CreateMaterialInstance(Material *mtl)
|
|||||||
{
|
{
|
||||||
if(!mtl)return(nullptr);
|
if(!mtl)return(nullptr);
|
||||||
|
|
||||||
MaterialParameters *mi=mtl->CreateInstance();
|
MaterialParameters *mi=mtl->CreateMP();
|
||||||
|
|
||||||
if(mi)
|
if(mi)
|
||||||
Add(mi);
|
Add(mi);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include<hgl/graph/VKRenderTarget.h>
|
#include<hgl/graph/VKRenderTarget.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VKDevice.h>
|
#include<hgl/graph/VKDevice.h>
|
||||||
#include<hgl/graph/VKInlinePipeline.h>
|
#include<hgl/graph/VKInlinePipeline.h>
|
||||||
#include<hgl/graph/VKPipelineData.h>
|
#include<hgl/graph/VKPipelineData.h>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include<hgl/graph/VKRenderableInstance.h>
|
#include<hgl/graph/VKRenderableInstance.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VKMaterial.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||||
#include<hgl/util/hash/Hash.h>
|
#include<hgl/util/hash/Hash.h>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user