#pragma once
#include "Bindable.h"
#include <wrl.h>
#include <d3d11.h>
#include <vector>
#include "Structs.h"

class VertexBuffer : public Bindable
{
public:
	template<class V>
	VertexBuffer(Graphics& gfx, const std::vector<V>& vertices, Logger& logger)
		:
		stride(sizeof(V))
	{
		D3D11_BUFFER_DESC bd = {};
		bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
		bd.Usage = D3D11_USAGE_DEFAULT;
		bd.CPUAccessFlags = 0u;
		bd.MiscFlags = 0u;
		bd.ByteWidth = UINT(sizeof(V) * vertices.size());
		bd.StructureByteStride = sizeof(V);
		D3D11_SUBRESOURCE_DATA sd = {};
		sd.pSysMem = vertices.data();
		GetDevice(gfx)->CreateBuffer(&bd, &sd, &pVertexBuffer);

		logger.PutLog("VertexBuffer::VertexBuffer", "size of vertices: " + std::to_string(vertices.size()));
		logger.PutLog("VertexBuffer::VertexBuffer", "size of StructVertex: " + std::to_string(sizeof(V)));
		logger.PutLog("VertexBuffer::VertexBuffer", "ByteWidth: " + std::to_string(bd.ByteWidth));
		logger.PutLog("VertexBuffer::VertexBuffer", "StructureByteStride: " + std::to_string(bd.StructureByteStride));
	};

	void Bind(Graphics& gfx, Logger& logger) noexcept override;
protected:
	UINT stride;
	Microsoft::WRL::ComPtr<ID3D11Buffer> pVertexBuffer;
};
