From 10c79f30a04724f751b00b3b24f8309a10269cff Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 24 Oct 2020 19:14:31 +0800 Subject: [PATCH] upgrade examples --- example/Vulkan/InlineGeometryScene.cpp | 27 +++++++++++++++++++++++++- example/Vulkan/first_triangle.cpp | 15 +++++++------- example/Vulkan/indices_rect.cpp | 2 +- example/Vulkan/texture_rect.cpp | 4 +--- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/example/Vulkan/InlineGeometryScene.cpp b/example/Vulkan/InlineGeometryScene.cpp index d2b1ebc8..4cabb931 100644 --- a/example/Vulkan/InlineGeometryScene.cpp +++ b/example/Vulkan/InlineGeometryScene.cpp @@ -91,7 +91,29 @@ private: { - texture.sampler =db->CreateSampler(); + VkSamplerCreateInfo sampler_create_info= + { + VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, + nullptr, + 0, + VK_FILTER_LINEAR, + VK_FILTER_LINEAR, + VK_SAMPLER_MIPMAP_MODE_LINEAR, + VK_SAMPLER_ADDRESS_MODE_REPEAT, + VK_SAMPLER_ADDRESS_MODE_REPEAT, + VK_SAMPLER_ADDRESS_MODE_REPEAT, + 0.0f, + false, + 0, + false, + VK_COMPARE_OP_NEVER, + 0.0f, + 1.0f, + VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, + false + }; + + texture.sampler =db->CreateSampler(&sampler_create_info); texture.color =db->LoadTexture2D(OS_TEXT("res/image/Brickwall/Albedo.Tex2D")); texture.normal =db->LoadTexture2D(OS_TEXT("res/image/Brickwall/Normal.Tex2D")); @@ -147,6 +169,9 @@ private: tci.numberSlices=128; tci.numberStacks=64; + tci.uv_scale.x=4; + tci.uv_scale.y=1; + ro_torus=CreateRenderableTorus(db,material,&tci); } diff --git a/example/Vulkan/first_triangle.cpp b/example/Vulkan/first_triangle.cpp index 712ab251..7f4effd3 100644 --- a/example/Vulkan/first_triangle.cpp +++ b/example/Vulkan/first_triangle.cpp @@ -20,10 +20,10 @@ constexpr float vertex_data[VERTEX_COUNT][2]= {SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75} }; -constexpr float color_data[VERTEX_COUNT][3]= -{ {1,0,0}, - {0,1,0}, - {0,0,1} +constexpr float color_data[VERTEX_COUNT][4]= +{ {1,0,0,1}, + {0,1,0,1}, + {0,0,1,1} }; class TestApp:public VulkanApplicationFramework @@ -34,7 +34,7 @@ private: MaterialInstance * material_instance =nullptr; RenderableInstance *render_instance =nullptr; - GPUBuffer * ubo_world_matrix =nullptr; + GPUBuffer * ubo_world_matrix =nullptr; Pipeline * pipeline =nullptr; @@ -78,7 +78,7 @@ private: if(!render_obj)return(false); if(!render_obj->Set(VAN::Position, db->CreateVAB(VAF_VEC2,VERTEX_COUNT,vertex_data)))return(false); - if(!render_obj->Set(VAN::Color, db->CreateVAB(VAF_VEC3,VERTEX_COUNT,color_data)))return(false); + if(!render_obj->Set(VAN::Color, db->CreateVAB(VAF_VEC4,VERTEX_COUNT,color_data)))return(false); render_instance=db->CreateRenderableInstance(render_obj,material_instance,pipeline); return(true); @@ -100,7 +100,8 @@ public: if(!InitVBO()) return(false); - BuildCommandBuffer(render_instance); + if(!BuildCommandBuffer(render_instance)) + return(false); return(true); } diff --git a/example/Vulkan/indices_rect.cpp b/example/Vulkan/indices_rect.cpp index 0fe8e93d..3f42b596 100644 --- a/example/Vulkan/indices_rect.cpp +++ b/example/Vulkan/indices_rect.cpp @@ -38,7 +38,7 @@ private: MaterialInstance * material_instance =nullptr; RenderableInstance *renderable_instance =nullptr; - GPUBuffer * ubo_world_matrix =nullptr; + GPUBuffer * ubo_world_matrix =nullptr; Pipeline * pipeline =nullptr; diff --git a/example/Vulkan/texture_rect.cpp b/example/Vulkan/texture_rect.cpp index d0f0bc40..fdce93ac 100644 --- a/example/Vulkan/texture_rect.cpp +++ b/example/Vulkan/texture_rect.cpp @@ -66,11 +66,9 @@ private: pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D); if(!pipeline)return(false); - texture=CreateTextureFromFile(device,OS_TEXT("res/image/lena.Tex2D")); + texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D")); if(!texture)return(false); - db->Add(texture); - sampler=db->CreateSampler(); material_instance->BindSampler("tex",texture,sampler);