From a49c1c0c7d9994e8db9c717ea65ea548d89236f2 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Tue, 25 May 2021 15:03:45 +0200
Subject: [PATCH] [#39] Added documentation and typedefs for function types

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 include/vkcv/Core.hpp | 17 +++++++++++++----
 src/vkcv/Core.cpp     | 21 ++++++++++-----------
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/include/vkcv/Core.hpp b/include/vkcv/Core.hpp
index c23a64b6..0712be48 100644
--- a/include/vkcv/Core.hpp
+++ b/include/vkcv/Core.hpp
@@ -29,6 +29,9 @@ namespace vkcv
 		std::vector<vk::Semaphore> waitSemaphores;
 		std::vector<vk::Semaphore> signalSemaphores;
 	};
+	
+	typedef std::function<void(const vk::CommandBuffer& cmdBuffer)> RecordCommandFunction;
+	typedef std::function<void(void)> FinishCommandFunction;
 
     class Core final
     {
@@ -179,9 +182,15 @@ namespace vkcv
 
 		vk::Format getSwapchainImageFormat();
 
-		void submitCommands(
-			const SubmitInfo &submitInfo,
-			const std::function<void(vk::CommandBuffer cmdBuffer)> recording, 
-			const std::function<void()> finishCallback);
+		/**
+		 * Submit a command buffer to any queue of selected type. The recording can be customized by a
+		 * custom record-command-function. If the command submission has finished, an optional finish-function
+		 * will be called.
+		 *
+		 * @param submitInfo Submit information
+		 * @param record Record-command-function
+		 * @param finish Finish-command-function or nullptr
+		 */
+		void submitCommands(const SubmitInfo &submitInfo, const RecordCommandFunction& record, const FinishCommandFunction& finish);
     };
 }
diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp
index d6785892..e5e847ab 100644
--- a/src/vkcv/Core.cpp
+++ b/src/vkcv/Core.cpp
@@ -173,7 +173,7 @@ namespace vkcv
 		SubmitInfo submitInfo;
 		submitInfo.queueType = QueueType::Graphics;
 		submitInfo.signalSemaphores = { m_SyncResources.renderFinished };
-		submitCommands(submitInfo, [renderpass, renderArea, imageView, framebuffer, pipeline](const vk::CommandBuffer cmdBuffer) {
+		submitCommands(submitInfo, [renderpass, renderArea, imageView, framebuffer, pipeline](const vk::CommandBuffer& cmdBuffer) {
 
 			const std::array<float, 4> clearColor = { 0.f, 0.f, 0.f, 1.f };
 			const vk::ClearValue clearValues(clearColor);
@@ -222,12 +222,9 @@ namespace vkcv
         /* boilerplate for #34 */
         std::cout << "Resized to : " << width << " , " << height << std::endl;
     }
-
-	void Core::submitCommands(
-		const SubmitInfo& submitInfo,
-		const std::function<void(vk::CommandBuffer cmdBuffer)> recording,
-		const std::function<void()> finishCallback) {
-
+	
+	void Core::submitCommands(const SubmitInfo &submitInfo, const RecordCommandFunction& record, const FinishCommandFunction& finish)
+	{
 		const vk::Device& device = m_Context.getDevice();
 
 		const vkcv::Queue		queue		= getQueueForSubmit(submitInfo.queueType, m_Context.getQueueManager());
@@ -235,16 +232,18 @@ namespace vkcv
 		const vk::CommandBuffer	cmdBuffer	= allocateCommandBuffer(device, cmdPool);
 
 		beginCommandBuffer(cmdBuffer, vk::CommandBufferUsageFlagBits::eOneTimeSubmit);
-		recording(cmdBuffer);
+		record(cmdBuffer);
 		cmdBuffer.end();
 
 		const vk::Fence waitFence = createFence(device);
 		submitCommandBufferToQueue(queue.handle, cmdBuffer, waitFence, submitInfo.waitSemaphores, submitInfo.signalSemaphores);
 		waitForFence(device, waitFence);
 		device.destroyFence(waitFence);
-		if (finishCallback) {
-			finishCallback();
-		}
+		
 		device.freeCommandBuffers(cmdPool, cmdBuffer);
+		
+		if (finish) {
+			finish();
+		}
 	}
 }
-- 
GitLab