From e9408e9b2441ec6f836cd36b4c244328e85e93f7 Mon Sep 17 00:00:00 2001 From: HuYingzhuo Date: Sat, 20 Apr 2019 17:18:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=9C=89vertex=20input?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/VKPipeline.cpp | 2 +- example/Vulkan/main.cpp | 84 +++++++++++++++++------------------ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/example/Vulkan/VKPipeline.cpp b/example/Vulkan/VKPipeline.cpp index fa80d79f..06d2286a 100644 --- a/example/Vulkan/VKPipeline.cpp +++ b/example/Vulkan/VKPipeline.cpp @@ -81,7 +81,7 @@ PipelineCreater::PipelineCreater(Device *dev) rasterizer.rasterizerDiscardEnable = VK_FALSE; rasterizer.polygonMode = VK_POLYGON_MODE_FILL; rasterizer.cullMode = VK_CULL_MODE_FRONT_AND_BACK; - rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE; + rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; rasterizer.depthBiasEnable = VK_FALSE; rasterizer.depthBiasConstantFactor = 0; rasterizer.depthBiasClamp = 0; diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index df5d1cb0..ca3b18d2 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -70,43 +70,43 @@ vulkan::Shader *LoadShader(VkDevice device) return(nullptr); } -//constexpr float vertex_data[]={0.0f,0.5f, -0.5f,-0.5f, 0.5f,-0.5f }; -//constexpr float color_data[]={1,0,0, 0,1,0, 0,0,1 }; -// -//vulkan::VertexBuffer *vertex_buffer=nullptr; -//vulkan::VertexBuffer *color_buffer=nullptr; -// -//vulkan::VertexInput *CreateVertexBuffer(vulkan::Device *dev) -//{ -// vertex_buffer=dev->CreateVBO(FMT_RG32F,6*sizeof(float)); -// color_buffer=dev->CreateVBO(FMT_RGB32F,9*sizeof(float)); -// -// { -// float *p=(float *)vertex_buffer->Map(); -// -// memcpy(p,vertex_data,6*sizeof(float)); -// -// vertex_buffer->Unmap(); -// } -// -// { -// float *p=(float *)color_buffer->Map(); -// -// memcpy(p,color_data,9*sizeof(float)); -// -// color_buffer->Unmap(); -// } -// -// vulkan::VertexInput *vi=new vulkan::VertexInput(); -// -// constexpr uint32_t position_shader_location=0; //对应shader中的layout(locaiton=0,暂时这样写 -// constexpr uint32_t color_shader_location=1; -// -// vi->Add(position_shader_location, vertex_buffer); -// vi->Add(color_shader_location, color_buffer); -// -// return vi; -//} +constexpr float vertex_data[]={0.0f,0.5f, -0.5f,-0.5f, 0.5f,-0.5f }; +constexpr float color_data[]={1,0,0, 0,1,0, 0,0,1 }; + +vulkan::VertexBuffer *vertex_buffer=nullptr; +vulkan::VertexBuffer *color_buffer=nullptr; + +vulkan::VertexInput *CreateVertexBuffer(vulkan::Device *dev) +{ + vertex_buffer=dev->CreateVBO(FMT_RG32F,6*sizeof(float)); + color_buffer=dev->CreateVBO(FMT_RGB32F,9*sizeof(float)); + + { + float *p=(float *)vertex_buffer->Map(); + + memcpy(p,vertex_data,6*sizeof(float)); + + vertex_buffer->Unmap(); + } + + { + float *p=(float *)color_buffer->Map(); + + memcpy(p,color_data,9*sizeof(float)); + + color_buffer->Unmap(); + } + + vulkan::VertexInput *vi=new vulkan::VertexInput(); + + constexpr uint32_t position_shader_location=0; //对应shader中的layout(locaiton=0,暂时这样写 + constexpr uint32_t color_shader_location=1; + + vi->Add(position_shader_location, vertex_buffer); + vi->Add(color_shader_location, color_buffer); + + return vi; +} void wait_seconds(int seconds) { #ifdef WIN32 @@ -170,8 +170,8 @@ int main(int,char **) return -3; vulkan::Semaphore *sem=device->CreateSem(); - -// vulkan::VertexInput *vi=CreateVertexBuffer(device); + + vulkan::VertexInput *vi=CreateVertexBuffer(device); vulkan::PipelineCreater pc(device); vulkan::RenderPass *rp=device->CreateRenderPass(); @@ -181,7 +181,7 @@ int main(int,char **) vulkan::PipelineLayout *pl=CreatePipelineLayout(device->GetDevice(),dsl); pc.Set(shader); - //pc.Set(vi); + pc.Set(vi); pc.Set(PRIM_TRIANGLES); pc.Set(*pl); pc.Set(*rp); @@ -202,7 +202,7 @@ int main(int,char **) cmd_buf->Begin(rp,fb[0]); cmd_buf->Bind(pipeline); cmd_buf->Bind(pl); -// cmd_buf->Bind(vi); + cmd_buf->Bind(vi); cmd_buf->Draw(3); cmd_buf->End(); @@ -224,7 +224,7 @@ int main(int,char **) delete sem; delete rp; -// delete vi; + delete vi; // delete ubo; delete shader;