增加VKMaterialInstance类
This commit is contained in:
parent
854728ad57
commit
f947a0746a
@ -30,7 +30,7 @@ private:
|
||||
Camera cam;
|
||||
|
||||
vulkan::Material * material =nullptr;
|
||||
vulkan::DescriptorSets * descriptor_sets =nullptr;
|
||||
vulkan::MaterialInstance * material_instance =nullptr;
|
||||
vulkan::Renderable * render_obj =nullptr;
|
||||
vulkan::Buffer * ubo_mvp =nullptr;
|
||||
|
||||
@ -46,7 +46,7 @@ public:
|
||||
SAFE_CLEAR(pipeline);
|
||||
SAFE_CLEAR(ubo_mvp);
|
||||
SAFE_CLEAR(render_obj);
|
||||
SAFE_CLEAR(descriptor_sets);
|
||||
SAFE_CLEAR(material_instance);
|
||||
SAFE_CLEAR(material);
|
||||
}
|
||||
|
||||
@ -60,20 +60,7 @@ private:
|
||||
return(false);
|
||||
|
||||
render_obj=material->CreateRenderable(VERTEX_COUNT);
|
||||
descriptor_sets=material->CreateDescriptorSets();
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool BindUBO(const UTF8String &name,vulkan::Buffer *ubo)
|
||||
{
|
||||
const int index=material->GetUBO(name);
|
||||
|
||||
if(index<0)
|
||||
return(false);
|
||||
|
||||
if(!descriptor_sets->BindUBO(index,ubo))
|
||||
return(false);
|
||||
|
||||
material_instance=material->CreateInstance();
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -91,10 +78,10 @@ private:
|
||||
if(!ubo_mvp)
|
||||
return(nullptr);
|
||||
|
||||
BindUBO("world",ubo_mvp);
|
||||
BindUBO("fragment_world",ubo_mvp);
|
||||
material_instance->BindUBO("world",ubo_mvp);
|
||||
material_instance->BindUBO("fragment_world",ubo_mvp);
|
||||
|
||||
descriptor_sets->Update();
|
||||
material_instance->Update();
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -135,7 +122,7 @@ public:
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(pipeline,descriptor_sets,render_obj);
|
||||
BuildCommandBuffer(pipeline,material_instance->GetDescriptorSets(),render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -149,7 +136,7 @@ public:
|
||||
|
||||
ubo_mvp->Write(&cam.matrix);
|
||||
|
||||
BuildCommandBuffer(pipeline,descriptor_sets,render_obj);
|
||||
BuildCommandBuffer(pipeline,material_instance->GetDescriptorSets(),render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include<hgl/graph/vulkan/VKFormat.h>
|
||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||
#include<hgl/graph/vulkan/VKMaterial.h>
|
||||
#include<hgl/graph/vulkan/VKMaterialInstance.h>
|
||||
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
||||
#include<hgl/graph/shader/glsl2spv.h>
|
||||
#include<hgl/graph/SceneDB.h>
|
||||
|
@ -48,6 +48,7 @@ class ShaderModule;
|
||||
class ShaderModuleManage;
|
||||
class VertexShaderModule;
|
||||
class Material;
|
||||
class MaterialInstance;
|
||||
class PipelineLayout;
|
||||
class Pipeline;
|
||||
class DescriptorSets;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class DescriptorSetLayoutCreater;;
|
||||
class DescriptorSetLayoutCreater;
|
||||
using ShaderModuleMap=hgl::Map<VkShaderStageFlagBits,const ShaderModule *>;
|
||||
|
||||
/**
|
||||
@ -58,6 +58,7 @@ public:
|
||||
void Write(VkPipelineVertexInputStateCreateInfo &vis)const;
|
||||
|
||||
Renderable *CreateRenderable(const uint32_t draw_count=0);
|
||||
MaterialInstance *CreateInstance();
|
||||
};//class Material
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||
|
33
inc/hgl/graph/vulkan/VKMaterialInstance.h
Normal file
33
inc/hgl/graph/vulkan/VKMaterialInstance.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
||||
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class MaterialInstance
|
||||
{
|
||||
Material *material;
|
||||
|
||||
DescriptorSets *descriptor_sets;
|
||||
|
||||
private:
|
||||
|
||||
friend class Material;
|
||||
|
||||
MaterialInstance(Material *,DescriptorSets *);
|
||||
|
||||
public:
|
||||
|
||||
Material * GetMaterial (){return material;}
|
||||
DescriptorSets *GetDescriptorSets (){return descriptor_sets;}
|
||||
|
||||
public:
|
||||
|
||||
~MaterialInstance();
|
||||
|
||||
bool BindUBO(const UTF8String &name,vulkan::Buffer *ubo);
|
||||
|
||||
void Update();
|
||||
};//class MaterialInstance
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
@ -19,7 +19,8 @@ SET(VK_SHADER_SOURCE VKShaderParse.h
|
||||
|
||||
SET(VK_MATERIAL_SOURCE VKImageView.cpp
|
||||
VKTexture.cpp
|
||||
VKMaterial.cpp)
|
||||
VKMaterial.cpp
|
||||
VKMaterialInstance.cpp)
|
||||
|
||||
SET(VK_RENDER_PASS_SOURCE VKFramebuffer.cpp
|
||||
VKPipeline.cpp
|
||||
|
44
src/RenderDevice/Vulkan/VKMaterialInstance.cpp
Normal file
44
src/RenderDevice/Vulkan/VKMaterialInstance.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include<hgl/graph/vulkan/VKMaterialInstance.h>
|
||||
|
||||
#include<hgl/graph/vulkan/VKMaterial.h>
|
||||
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
MaterialInstance::MaterialInstance(Material *m,DescriptorSets *ds)
|
||||
{
|
||||
material=m;
|
||||
descriptor_sets=ds;
|
||||
}
|
||||
|
||||
MaterialInstance::~MaterialInstance()
|
||||
{
|
||||
delete descriptor_sets;
|
||||
}
|
||||
|
||||
bool MaterialInstance::BindUBO(const UTF8String &name,vulkan::Buffer *ubo)
|
||||
{
|
||||
const int index=material->GetUBO(name);
|
||||
|
||||
if(index<0)
|
||||
return(false);
|
||||
|
||||
if(!descriptor_sets->BindUBO(index,ubo))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void MaterialInstance::Update()
|
||||
{
|
||||
descriptor_sets->Update();
|
||||
}
|
||||
|
||||
MaterialInstance *Material::CreateInstance()
|
||||
{
|
||||
DescriptorSets *ds=CreateDescriptorSets();
|
||||
|
||||
if(!ds)return(nullptr);
|
||||
|
||||
return(new MaterialInstance(this,ds));
|
||||
}
|
||||
VK_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user