#include "gbuffer.h"
#include "../wrapper/image.h"
namespace vulkanapi {
	GeometryBuffer::GeometryBuffer(Device& device,int frames, int width, int height)
		:width(width),
		height(height)
	{
		VkFormat positionFmt = VK_FORMAT_R32G32B32A32_SFLOAT;
		VkFormat normalFmt = VK_FORMAT_R8G8B8A8_UNORM;
		VkFormat diffuseFmt = VK_FORMAT_R8G8B8A8_UNORM;

		int usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
		auto positionArgs = Image::Make2DArgs(width, height, positionFmt, VK_SAMPLE_COUNT_1_BIT, usage | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE);
		auto normalArgs = Image::Make2DArgs(width, height, positionFmt, VK_SAMPLE_COUNT_1_BIT, usage | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE);
		auto diffuseArgs = Image::Make2DArgs(width, height, positionFmt, VK_SAMPLE_COUNT_1_BIT, usage | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE);
		for (int i = 0; i < frames; i++) {
			string si = to_string(i);
			positions.push_back(new Image(device, "position" + si, positionArgs));
			normals.push_back(new Image(device, "normal" + si, normalArgs));
			diffuses.push_back(new Image(device, "diffuse" + si, diffuseArgs));
		}
	}
	GeometryBuffer::~GeometryBuffer()
	{
		int frames = positions.size();
		for (int i = 0; i < frames; i++) {
			delete positions[i];
			delete normals[i];
			delete diffuses[i];
		}
		positions.clear();
		normals.clear();
		diffuses.clear();
	}
}