From 1ad367d650e5c558950f854befd97bc514b3f668 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 13 Sep 2026 19:53:24 +0200 Subject: [PATCH] Removed the triangle and rectangle --- src/Engine/engine/engine.h | 160 ++++--------------------------------- 1 file changed, 16 insertions(+), 144 deletions(-) diff --git a/src/Engine/engine/engine.h b/src/Engine/engine/engine.h index b2de7f8..7836eb0 100644 --- a/src/Engine/engine/engine.h +++ b/src/Engine/engine/engine.h @@ -109,10 +109,6 @@ class Engine { std::vector backgroundEffects; int currentBackgroundEffect{0}; // Already initialized - // Triangle Pipeline - VkPipelineLayout _trianglePipelineLayout; - VkPipeline _trianglePipeline; - // ImGUI texture sampler VkSampler _viewportSampler; VkDescriptorSet _viewportTextureID; @@ -172,7 +168,6 @@ class Engine { void initDescriptors(); void initPipelines(); void initBackgroundPipelines(); - void initTrianglePipeline(); void initMeshPipeline(); void initImgui(); @@ -365,6 +360,12 @@ void Engine::cleanup() { _frames[i]._deletionQueue.flush(); } + // Destroy meshes + for(auto& mesh: testMeshes) { + destroyBuffer(mesh->meshBuffers.indexBuffer); + destroyBuffer(mesh->meshBuffers.vertexBuffer); + } + // Flush the global deletion queue _mainDeletionQueue.flush(); @@ -1248,7 +1249,6 @@ void Engine::initPipelines() { initBackgroundPipelines(); // GRAPHICS PIPELINES - initTrianglePipeline(); initMeshPipeline(); #ifdef DEBUG @@ -1410,88 +1410,6 @@ void Engine::initBackgroundPipelines() { #endif } -void Engine::initTrianglePipeline() { - #ifdef DEBUG - _logger.logRAM(ENGINE, EINIT, "Initializing triangle pipeline..."); - #endif - // Create the shader - VkShaderModule triangleFragShader; - if(!vkutil::loadShaderModule("shaders/colored_triangle_fragment.spv", _device, &triangleFragShader)) { - fmt::println("[Engine:Error] Failed to load the triangle fragment shader !"); - } else { - fmt::println("[Engine:Info] Successfully loaded the triangle fragment shader !"); - } - - VkShaderModule triangleVertShader; - if(!vkutil::loadShaderModule("shaders/colored_triangle_vertices.spv", _device, &triangleVertShader)) { - fmt::println("[Engine:Error] Failed to load the triangle vertex shader !"); - } else { - fmt::println("[Engine:Info] Successfully loaded the triangle vertex shader !"); - } - - // Build the pipeline with the helper functions - // Build the pipeline layout that controls the inputs/outputs of the shader - // We are not using descriptor sets or other systems yet, so no need to use anything other than empty default - // This is because we don't have push constants or descriptor bindings - VkPipelineLayoutCreateInfo pipelineLayoutInfo = vkinit::pipelineLayoutCreateInfo(); - VK_CHECK( - vkCreatePipelineLayout( - _device, - &pipelineLayoutInfo, - nullptr, - &_trianglePipelineLayout - ) - ); - - PipelineBuilder pipelineBuilder; - pipelineBuilder._pipelineLayout = _trianglePipelineLayout; - // Connect both the vertex and fragment shader together - // Todo : Handle the case where they are both in the same VkShaderModule, - // with slang shaders for example - pipelineBuilder.setShaders(triangleVertShader, triangleFragShader); - // Draw triangles - // Can also draw "wireframe" - pipelineBuilder.setInputTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST); - // Fill those triangles. - // For wireframe, don't - pipelineBuilder.setPolygonMode(VK_POLYGON_MODE_FILL); - // No backface culling atm - // Enable it for optimization, but beware of clockwise/anticlockwise coordinates - // Also, Vulkan uses -Y, so take note - pipelineBuilder.setCullMode(VK_CULL_MODE_NONE, VK_FRONT_FACE_CLOCKWISE); - // No multisampling, - // used for a more "retro" look, - // and more performance - // also useless because it's a single triangle - pipelineBuilder.setMultisamplingNone(); - // No blending - pipelineBuilder.disableBlending(); - // No depth testing, - // 'cause no depth buffer nor 3D triangle - pipelineBuilder.disableDepthtest(); - - // Connect the image format we will draw into, from draw image - pipelineBuilder.setColorAttachmentFormat(_drawImage.imageFormat); - pipelineBuilder.setDepthFormat(_depthImage.imageFormat); // Why ? - // Because validation errors, now it's the same format - - // Finally build the pipeline - _trianglePipeline = pipelineBuilder.buildPipeline(_device); - - // clean structures - vkDestroyShaderModule(_device, triangleFragShader, nullptr); - vkDestroyShaderModule(_device, triangleVertShader, nullptr); - - _mainDeletionQueue.pushFunction([this]() { - vkDestroyPipelineLayout(_device, _trianglePipelineLayout, nullptr); - vkDestroyPipeline(_device, _trianglePipeline, nullptr); - }); - - #ifdef DEBUG - _logger.logRAM(ENGINE, EINIT, "Triangle pipeline initalized !"); - #endif -} - void Engine::initMeshPipeline() { #ifdef DEBUG _logger.logRAM(ENGINE, EINIT, "Initializing mesh pipeline..."); @@ -1724,42 +1642,10 @@ void Engine::initDefaultData() { #ifdef DEBUG _logger.logRAM(ENGINE, EINIT, "Creating default data..."); #endif - - std::array rectVertices; - - rectVertices[0].position = {0.5, -0.5, 0}; - rectVertices[1].position = {0.5, 0.5, 0}; - rectVertices[2].position = {-0.5, -0.5, 0}; - rectVertices[3].position = {-0.5, 0.5, 0}; - - rectVertices[0].color = {0, 0, 0, 1}; - rectVertices[1].color = {0.5, 0.5, 0.5, 1}; - rectVertices[2].color = {1, 0, 0, 1}; - rectVertices[3].color = {0, 1, 0, 1}; - - std::array rectIndices; - - rectIndices[0] = 0; - rectIndices[1] = 1; - rectIndices[2] = 2; - - rectIndices[3] = 2; - rectIndices[4] = 1; - rectIndices[5] = 3; - - rectangle = uploadMesh( - rectIndices, - rectVertices - ); - // Load the mesh testMeshes = loadGltfMeshes(this, _modelPath).value(); - - // Delete the default data on engine shutdown - _mainDeletionQueue.pushFunction([this](){ - destroyBuffer(rectangle.indexBuffer); - destroyBuffer(rectangle.vertexBuffer); - }); + // Todo + // Destroy here (queue) #ifdef DEBUG _logger.logRAM(ENGINE, EINIT, "Default data created !"); #endif @@ -2007,7 +1893,12 @@ void Engine::drawGeometry( vkCmdBeginRendering(cmd, &renderInfo); - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, _trianglePipeline); + // Bind the mesh pipeline + vkCmdBindPipeline( + cmd, + VK_PIPELINE_BIND_POINT_GRAPHICS, + _meshPipeline + ); // Dynamic viewport and scissor VkViewport viewport = { @@ -2034,15 +1925,6 @@ void Engine::drawGeometry( vkCmdSetScissor(cmd, 0, 1, &scissor); - //launch a draw command to draw 3 vertices - vkCmdDraw(cmd, 3, 1, 0, 0); - - vkCmdBindPipeline( - cmd, - VK_PIPELINE_BIND_POINT_GRAPHICS, - _meshPipeline - ); - GPUDrawPushConstants pushConstants; pushConstants.worldMatrix = glm::mat4{ 1.0f }; pushConstants.vertexBuffer = rectangle.vertexBufferAddress; @@ -2056,18 +1938,8 @@ void Engine::drawGeometry( &pushConstants ); - vkCmdBindIndexBuffer( - cmd, - rectangle.indexBuffer.buffer, - 0, - VK_INDEX_TYPE_UINT32 - ); - - // Draw the rectangle - vkCmdDrawIndexed(cmd, 6, 1, 0, 0, 0); - - // Now the model - // Correct the matrix + // Model + // Correct the matrix glm::mat4 view = glm::translate(glm::vec3{ 0, 0, -5}); // Camera projection /*