example the first_triangle support ShaderResource

This commit is contained in:
hyzboy 2020-06-10 17:11:24 +08:00
parent d94e6dee6c
commit 26a434e9fb
5 changed files with 14 additions and 18 deletions

View File

@ -18,7 +18,6 @@
#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>
#include<hgl/graph/RenderList.h>

View File

@ -62,8 +62,8 @@ private:
bool InitMaterial()
{
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/FlatColor.vert.spv"),
OS_TEXT("res/shader/VertexColor.frag.spv"));
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/FlatColor.vert"),
OS_TEXT("res/shader/VertexColor.frag"));
if(!material)
return(false);
@ -91,13 +91,15 @@ private:
return(true);
}
void InitVBO()
bool InitVBO()
{
vertex_buffer =device->CreateVBO(FMT_RG32F, VERTEX_COUNT,vertex_data);
color_buffer =device->CreateVBO(FMT_RGB32F, VERTEX_COUNT,color_data);
render_obj->Set("Vertex", vertex_buffer);
render_obj->Set("Color", color_buffer);
if(!render_obj->Set("Vertex", vertex_buffer))return(false);
if(!render_obj->Set("Color", color_buffer))return(false);
return(true);
}
bool InitPipeline()
@ -138,7 +140,8 @@ public:
if(!InitUBO())
return(false);
InitVBO();
if(!InitVBO())
return(false);
if(!InitPipeline())
return(false);

2
res

@ -1 +1 @@
Subproject commit ee094e2efb1616014d18388eae4440fd740d07d1
Subproject commit c8c306e5a7cd3e975af4eb718f20ea16653ca4d3

View File

@ -30,12 +30,11 @@ VertexShaderModule::VertexShaderModule(VkDevice dev,int id,VkPipelineShaderStage
VkVertexInputBindingDescription *bind=binding_list;
VkVertexInputAttributeDescription *attr=attribute_list;
uint32_t binding_index=0;
ShaderStage **si=stage_inputs.GetData();
for(uint i=0;i<attr_count;i++)
{
bind->binding =binding_index; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号所以这个数字必须从0开始而且紧密排列。
bind->binding =i; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号所以这个数字必须从0开始而且紧密排列。
//在VertexInput类中buf_list需要严格按照本此binding为序列号排列
bind->stride =GetStrideByFormat((*si)->format);
bind->inputRate =VK_VERTEX_INPUT_RATE_VERTEX;
@ -45,14 +44,13 @@ VertexShaderModule::VertexShaderModule(VkDevice dev,int id,VkPipelineShaderStage
//比如在一个流中传递{pos,color}这样两个数据就需要两个attrib
//但在我们的设计中仅支持一个流传递一个attrib
attr->binding =binding_index;
attr->binding =i;
attr->location =(*si)->location; //此值对应shader中的layout(location=
attr->format =(*si)->format;
attr->offset =0;
++attr;
++bind;
++binding_index;
++si;
}

View File

@ -94,7 +94,7 @@ VK_NAMESPACE_BEGIN
for(int i=0;i<count;i++)
{
if(name==(*ss)->name)
return (*ss)->location;
return i;
++ss;
}
@ -122,7 +122,7 @@ VK_NAMESPACE_BEGIN
ShaderResource *LoadShaderResoruce(const OSString &filename)
{
int64 filesize;
uint8 *origin_filedata=(uint8 *)filesystem::LoadFileToMemory(filename,filesize);
uint8 *origin_filedata=(uint8 *)filesystem::LoadFileToMemory(filename+OS_TEXT(".shader"),filesize);
if(!origin_filedata)return(nullptr);
@ -159,10 +159,6 @@ VK_NAMESPACE_BEGIN
desc_type=AccessByPointer(filedata,uint32);
filedata=LoadShaderDescriptor(sr->GetDescriptorList((VkDescriptorType)desc_type),filedata);
{
delete sr;
return(nullptr);
}
}
return sr;