From f8258320e3c932b3191cff612ea80ce4fd969d27 Mon Sep 17 00:00:00 2001 From: Alexander Gauggel <agauggel@uni-koblenz.de> Date: Sun, 16 May 2021 21:01:05 +0200 Subject: [PATCH] [#18] I HAVE BECOME RENDERER, DRAWER OF TRIANGLE --- projects/first_triangle/shaders/shader.vert | 17 ++++++++++++++--- projects/first_triangle/shaders/vert.spv | Bin 1056 -> 1508 bytes src/vkcv/Core.cpp | 6 +++++- src/vkcv/PipelineManager.cpp | 10 +++++----- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/projects/first_triangle/shaders/shader.vert b/projects/first_triangle/shaders/shader.vert index 246a3661..1d278d5f 100644 --- a/projects/first_triangle/shaders/shader.vert +++ b/projects/first_triangle/shaders/shader.vert @@ -1,10 +1,21 @@ #version 450 #extension GL_ARB_separate_shader_objects : enable -layout(location = 0) in vec2 inPosition; layout(location = 0) out vec3 fragColor; void main() { - gl_Position = vec4(inPosition, 0.0, 1.0); - fragColor = vec3(1); + vec3 positions[3] = { + vec3(-0.5, 0.5, 0), + vec3( 0.5, 0.5, 0), + vec3(0, -0.5, 0) + }; + + vec3 colors[3] = { + vec3(1, 0, 0), + vec3(0, 1, 0), + vec3(0, 0, 1) + }; + + gl_Position = vec4(positions[gl_VertexIndex], 1.0); + fragColor = colors[gl_VertexIndex]; } \ No newline at end of file diff --git a/projects/first_triangle/shaders/vert.spv b/projects/first_triangle/shaders/vert.spv index 7692f2cf09e53183c613f81db748d798a2e18fab..bd1e0e682c52e6e38a5f5aba4eeaf8e73a70d741 100644 GIT binary patch literal 1508 zcmZ9M>rd1`6van&m&YO?BH#nD>-q#-e8<EnK`_;16HpSrHg&gRP3>;lV$@ImXD0qt zelhX<+L?9ZkjuU2+;eB{+$q#1+Ed1yGEFmQ9++w^nh7z+%$mv4``x2%ColS)hmY=} zm^Zajh-Se|mvLRcKZkJ&xFT!Iwq-T_OvwL|xNc^Q-wk%(z6kPY7-nG+1^LIYA7#Pd z{imo`<Y<~`{DT9(`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5!J~iV;e)Y{R2h7D zsSsw^mm<XUkMWjR@b2pjHSl-jEy@n1yW;EP2{E;|74tO=rO1OWUXjm?dx{6LoCn*N z$1Jf1IdmxARoOWA^Dbt0VDwoJytXcVh&QANb6u0A4>MD5Q<fRPsYlG+!8i~1h7^hM zc8Gqx;`}Z7^k!D--;w1E82P=<2d6%9`~4g9P)u<4O3kQG^|s8%?htDI5t7Kh5X!7u zQs#UwlzuxMCNsl!JB+)WYC>kbDTPapd(rbqHMqxZDZ6A}FV&S8K7M@vzuL?*=|B2n BUS0qI diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp index 3c113a7a..07e7b82a 100644 --- a/src/vkcv/Core.cpp +++ b/src/vkcv/Core.cpp @@ -338,7 +338,7 @@ namespace vkcv void Core::renderTriangle(const PassHandle renderpassHandle, const PipelineHandle pipelineHandle, const int width, const int height) { const vk::RenderPass renderpass = m_PassManager->getVkPass(renderpassHandle); - const std::array<float, 4> clearColor = { 1.f, 1.f, 0.f, 1.f }; + const std::array<float, 4> clearColor = { 0.f, 0.f, 0.f, 1.f }; const vk::ClearValue clearValues(clearColor); const vk::Rect2D renderArea(vk::Offset2D(0, 0), vk::Extent2D(width, height)); const vk::ImageView imageView = m_swapchainImageViews[m_currentSwapchainImageIndex]; @@ -347,6 +347,10 @@ namespace vkcv const vk::RenderPassBeginInfo beginInfo(renderpass, framebuffer, renderArea, 1, &clearValues); const vk::SubpassContents subpassContents = {}; m_CommandResources.commandBuffer.beginRenderPass(beginInfo, subpassContents, {}); + + const vk::Pipeline pipeline = m_PipelineManager->getVkPipeline(pipelineHandle); + m_CommandResources.commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline, {}); + m_CommandResources.commandBuffer.draw(3, 1, 0, 0, {}); m_CommandResources.commandBuffer.endRenderPass(); } diff --git a/src/vkcv/PipelineManager.cpp b/src/vkcv/PipelineManager.cpp index 416356f4..e6d6beea 100644 --- a/src/vkcv/PipelineManager.cpp +++ b/src/vkcv/PipelineManager.cpp @@ -71,11 +71,11 @@ namespace vkcv vk::VertexInputAttributeDescription vertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, 0); vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( - {}, - 1, - &vertexInputBindingDescription, - 1, - &vertexInputAttributeDescription + {}, // no vertex input until vertex buffer is implemented + 0, // 1, + nullptr, // &vertexInputBindingDescription, + 0, // 1, + nullptr // &vertexInputAttributeDescription ); // input assembly state -- GitLab