#pragma once
#include "VertexBuffer.h"

VertexBuffer::VertexBuffer(Graphics& gfx, const std::vector<StructVertex>& vertices, Logger& logger)
	:
	stride(sizeof(StructVertex))
{
	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(StructVertex) * vertices.size());
	bd.StructureByteStride = sizeof(StructVertex);
	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(StructVertex)));
	logger.PutLog("VertexBuffer::VertexBuffer", "ByteWidth: " + std::to_string(bd.ByteWidth));
	logger.PutLog("VertexBuffer::VertexBuffer", "StructureByteStride: " + std::to_string(bd.StructureByteStride));
}

void VertexBuffer::Bind(Graphics& gfx, Logger& logger) noexcept
{
	const UINT offset = 0u;
	GetContext(gfx)->IASetVertexBuffers(0u, 1u, pVertexBuffer.GetAddressOf(), &stride, &offset);

	logger.PutLog("VertexBuffer::Bind", "stride: " + std::to_string(stride));
	logger.PutLog("VertexBuffer::Bind", "offset: " + std::to_string(offset));
}
