#include "detail/graphics.h"

namespace deerith {
	void graphics::init_vulkan() {
		deerith_graphics_trace("Initializing Vulkan");

		create_vulkan_validation_layer();
		create_vulkan_instance();
		create_vulkan_surface();
		create_vulkan_phisical_device();
		create_vulkan_logical_device();
		create_vulkan_swap_chain();
		create_vulkan_image_view();
		create_vulkan_render_pass();
		create_vulkan_graphics_pipeline();
		create_vulkan_frame_buffer();
		create_vulkan_command_buffer();
		create_vulkan_sync_objects();
		vulkan_test_loop();
	}

	void graphics::shutdown_vulkan() {
		deerith_graphics_trace("Shutting Vulkan");

		vkDeviceWaitIdle(device);
		vkDestroyCommandPool(device, command_pool, nullptr);
		for (auto framebuffer : swap_chain_frame_buffers) {
			vkDestroyFramebuffer(device, framebuffer, nullptr);
		}

		vkDestroyPipeline(device, graphics_pipeline, nullptr);
		vkDestroyRenderPass(device, render_pass, nullptr);
		vkDestroyPipelineLayout(device, pipeline_layout, nullptr);

		for (auto image_view : swap_chain_image_views) {
			vkDestroyImageView(device, image_view, nullptr);
		}

		vkDestroySwapchainKHR(device, swap_chain, nullptr);
		vkDestroySurfaceKHR(instance, surface, nullptr);
		vkDestroyDevice(device, nullptr);
		vkDestroyInstance(instance, nullptr);
	}
} // namespace deerith