#include "CameraRenderingResources.hpp"

bool CameraRenderingResources::createOrRecreateFromCameraBackbuffer(ComPtr<ID3D11Device> device, ComPtr<ID3D11Texture2D> cameraBackBuffer)
{
	if (cameraBackBuffer.Get() != colorBuffer.Get())
	{
		colorBuffer = cameraBackBuffer;

		D3D11_TEXTURE2D_DESC tdesc;
		cameraBackBuffer->GetDesc(&tdesc);
		/*
		isStereo = tdesc.ArraySize != 1;
		auto hr = device->CreateRenderTargetView(colorBuffer.Get(), nullptr, &renderTargetView);
		if (!SUCCEEDED(hr))
			return false;

		if (currentWidth != tdesc.Width || currentHeight != tdesc.Height)
		{
			currentWidth = tdesc.Width;
			currentHeight = tdesc.Height;

			depthStencilView.Reset();
			depthBuffer.Reset();
		}

		if (depthStencilView == nullptr)
		{
			D3D11_TEXTURE2D_DESC ddesc;
			ZeroMemory(&ddesc, sizeof(ddesc));
			ddesc.ArraySize = tdesc.ArraySize;
			ddesc.Width = currentWidth;
			ddesc.Height = currentHeight;
			ddesc.CPUAccessFlags = 0;
			ddesc.Format = DXGI_FORMAT_R24G8_TYPELESS;
			ddesc.MipLevels = 1;
			ddesc.Usage = D3D11_USAGE_DEFAULT;
			ddesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
			ddesc.SampleDesc.Count = 1;
			hr = device->CreateTexture2D(&ddesc, nullptr, &depthBuffer);
			if (!SUCCEEDED(hr))
				return false;

			CD3D11_DEPTH_STENCIL_VIEW_DESC dsvd(isStereo ? D3D11_DSV_DIMENSION_TEXTURE2DARRAY : D3D11_DSV_DIMENSION_TEXTURE2D,
				DXGI_FORMAT_D24_UNORM_S8_UINT);

			hr = device->CreateDepthStencilView(depthBuffer.Get(), &dsvd, &depthStencilView);
			if (!SUCCEEDED(hr))
				return false;
		}
		*/
	}

	return true;
}