增加FragCoord属性测试

This commit is contained in:
2020-01-20 15:02:40 +08:00
parent d532e0d04c
commit e2811f2b2b
12 changed files with 282 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
// 1.indices_rect
// 该示例是0.triangle的进化演示使用索引数据画一个矩形
// indices_rect
// 该示例演示使用索引数据画一个矩形,并使用了颜色材质
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
@@ -12,6 +12,8 @@ constexpr uint32_t SCREEN_HEIGHT=128;
constexpr uint32_t VERTEX_COUNT=4;
static Vector4f color(1,1,0,1);
constexpr float SSP=0.25;
constexpr float SSN=1-SSP;
@@ -41,6 +43,7 @@ private:
vulkan::DescriptorSets * descriptor_sets =nullptr;
vulkan::Renderable * render_obj =nullptr;
vulkan::Buffer * ubo_mvp =nullptr;
vulkan::Buffer * ubo_color_material =nullptr;
vulkan::Pipeline * pipeline =nullptr;
@@ -54,6 +57,7 @@ public:
SAFE_CLEAR(index_buffer);
SAFE_CLEAR(vertex_buffer);
SAFE_CLEAR(pipeline);
SAFE_CLEAR(ubo_color_material);
SAFE_CLEAR(ubo_mvp);
SAFE_CLEAR(render_obj);
SAFE_CLEAR(descriptor_sets);
@@ -74,19 +78,38 @@ private:
return(true);
}
vulkan::Buffer *CreateUBO(const UTF8String &name,const VkDeviceSize size,void *data)
{
vulkan::Buffer *ubo=device->CreateUBO(size,data);
if(!ubo)
return(nullptr);
const int index=material->GetUBO(name);
if(index<0)
{
SAFE_CLEAR(ubo);
return(nullptr);
}
if(!descriptor_sets->BindUBO(index,ubo))
{
SAFE_CLEAR(ubo);
return(nullptr);
}
return ubo;
}
bool InitUBO()
{
const VkExtent2D extent=sc_render_target->GetExtent();
wm.ortho=ortho(extent.width,extent.height);
ubo_mvp=device->CreateUBO(sizeof(WorldMatrix),&wm);
if(!ubo_mvp)
return(false);
if(!descriptor_sets->BindUBO(material->GetUBO("world"),ubo_mvp))
return(false);
ubo_mvp =CreateUBO("world", sizeof(WorldMatrix),&wm);
ubo_color_material =CreateUBO("color_material",sizeof(Vector4f),&color);
descriptor_sets->Update();
return(true);