Added a triangle

This commit is contained in:
Alexandre 2026-08-06 19:54:29 +02:00
parent c20c6928b1
commit fe7f7521d8

View File

@ -3,7 +3,7 @@
// Normal header // Normal header
// Current progress // Current progress
// 3 - Graphics Pipeline - Doing PipelineBuilder functions // 3 - Graphics Pipeline - Doing mesh buffers
#include "descriptors.h" // Required for public interface custom allocator #include "descriptors.h" // Required for public interface custom allocator
#include "Common/Types.h" #include "Common/Types.h"
@ -143,6 +143,9 @@ class Engine {
void drawBackground( void drawBackground(
VkCommandBuffer cmd VkCommandBuffer cmd
); );
void drawGeometry(
VkCommandBuffer cmd
);
void drawImgui( void drawImgui(
VkCommandBuffer cmd, VkCommandBuffer cmd,
VkImageView targetImageView VkImageView targetImageView
@ -352,11 +355,21 @@ void Engine::draw() {
drawBackground(cmd); drawBackground(cmd);
// Transfer the draw image and swapchain image to the correct layouts // Prepare for geometry draw
vkutil::transitionImage( vkutil::transitionImage(
cmd, cmd,
_drawImage.image, _drawImage.image,
VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
);
drawGeometry(cmd);
// Transfer the draw image and swapchain image to the correct layouts
vkutil::transitionImage(
cmd,
_drawImage.image,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
); );
@ -1330,6 +1343,51 @@ void Engine::drawBackground(
} }
void Engine::drawGeometry(
VkCommandBuffer cmd
) {
// Store some info
uint32_t width = _drawExtent.width;
uint32_t height = _drawExtent.height;
// Begin rendering
VkRenderingAttachmentInfo colorAttachment = vkinit::attachmentInfo(_drawImage.imageView, nullptr, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
VkRenderingInfo renderInfo = vkinit::renderingInfo(_drawExtent, &colorAttachment, nullptr);
vkCmdBeginRendering(cmd, &renderInfo);
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, _trianglePipeline);
// Dynamic viewport and scissor
VkViewport viewport = {
.x = 0,
.y = 0,
.width = (float)width,
.height = (float)height,
.minDepth = 0.f,
.maxDepth = 1.f
};
vkCmdSetViewport(cmd, 0, 1, &viewport);
VkRect2D scissor = {
.offset = {
.x = 0,
.y = 0
},
.extent = {
.width = (uint32_t)width,
.height = (uint32_t)height
}
};
vkCmdSetScissor(cmd, 0, 1, &scissor);
//launch a draw command to draw 3 vertices
vkCmdDraw(cmd, 3, 1, 0, 0);
vkCmdEndRendering(cmd);
}
void Engine::drawImgui( void Engine::drawImgui(
VkCommandBuffer cmd, VkCommandBuffer cmd,
VkImageView targetImageView VkImageView targetImageView