<commit_before>#include "Rendering/Skybox.h"
#include "Rendering/RenderContext.h"
#include "Rendering/Renderer.h"
#include "Rendering/GraphicsDriver.h"
#include "Rendering/DrawItem.h"
#include "Rendering/Texture.h"
#include "Rendering/RenderPassProgram.h"
#include "Rendering/Mesh.h"

#include "Misc/Assert.h"

namespace MAD
{
	USkybox::USkybox(const eastl::string& inShaderPath, const eastl::string& inCubemapPath, const Vector3& inBoxDimensions)
		: m_skyboxDimensions(inBoxDimensions)
		, m_skyboxTransform(Matrix::CreateScale(inBoxDimensions.x, inBoxDimensions.y, inBoxDimensions.z))
	{
		MAD_ASSERT_DESC(InitializeSkybox(inShaderPath, inCubemapPath), "Error loading skybox\n");
	}

	void USkybox::DrawSkybox()
	{
		auto& graphicsDriver = URenderContext::Get().GetGraphicsDriver();
		const auto& gBufferPassDesc = URenderContext::Get().GetRenderer().GetGBufferPassDescriptor();
		SPerDrawConstants skyboxDrawConstants;

		// Bind the program
		m_skyboxShader->SetProgramActive(graphicsDriver, 0);

		// Bind the input layout
		graphicsDriver.SetInputLayout(m_skyboxInputLayout);

		// Bind the vertex buffer
		m_skyboxMesh->m_gpuPositions.Bind(graphicsDriver, 0);
		
		graphicsDriver.SetIndexBuffer(m_skyboxMesh->m_gpuIndexBuffer, 0);

		// Set the light accumulation buffer as render target since we dont want that the skybox to be lit (remember to unbind the depth buffer as input incase previous steps needed it as a SRV)
		graphicsDriver.SetPixelShaderResource(nullptr, ETextureSlot::DepthBuffer);
		graphicsDriver.SetRenderTargets(&gBufferPassDesc.m_renderTargets[AsIntegral(ERenderTargetSlot::LightingBuffer)], 1, m_depthStencilView.Get());

		graphicsDriver.SetDepthStencilState(m_depthStencilState, 0);

		// Upload sky box's scale matrix
		skyboxDrawConstants.m_objectToWorldMatrix = m_skyboxTransform;
		graphicsDriver.UpdateBuffer(EConstantBufferSlot::PerDraw, &skyboxDrawConstants, sizeof(skyboxDrawConstants));

		// Bind the rasterizer state
		graphicsDriver.SetRasterizerState(m_boxRasterizerState);

		graphicsDriver.SetBlendState(m_skyboxBlendState);

		graphicsDriver.DrawIndexed(static_cast<UINT>(m_skyboxMesh->m_indexBuffer.size()), 0, 0);
	}

	bool USkybox::InitializeSkybox(const eastl::string& inShaderPath, const eastl::string& inCubemapPath)
	{
		eastl::shared_ptr<UTexture> boxCubeMapTex = UTexture::Load(inCubemapPath, true, false, D3D11_RESOURCE_MISC_TEXTURECUBE);

		m_boxCubeMapSRV = boxCubeMapTex->GetTexureResource();
		MAD_ASSERT_DESC(m_boxCubeMapSRV, "Error creating the shader resource view for the skybox cube map\n");
		if (!m_boxCubeMapSRV) return false;

		m_skyboxShader = URenderPassProgram::Load(inShaderPath);
		MAD_ASSERT_DESC(m_skyboxShader != nullptr, "Error loading the skybox shader program\n");
		if (!m_skyboxShader) return false;

		m_skyboxInputLayout = UInputLayoutCache::GetInputLayout(EInputLayoutSemantic::Position);
		MAD_ASSERT_DESC(m_skyboxInputLayout, "Error retrieving the skybox input layout\n");
		if (!m_skyboxInputLayout) return false;

		m_depthStencilView = URenderContext::Get().GetRenderer().GetGBufferPassDescriptor().m_depthStencilView;
		MAD_ASSERT_DESC(m_depthStencilView, "Error retrieving the g-buffer's depth buffer\n");
		if (!m_depthStencilView) return false;

		m_depthStencilState = URenderContext::Get().GetRenderer().GetGBufferPassDescriptor().m_depthStencilState;

		m_boxRasterizerState = URenderContext::Get().GetGraphicsDriver().CreateRasterizerState(EFillMode::Solid, ECullMode::Front);
		MAD_ASSERT_DESC(m_boxRasterizerState, "Error creating rasterizer state\n");
		if (!m_boxRasterizerState) return false;

		m_skyboxBlendState = URenderContext::Get().GetGraphicsDriver().CreateBlendState(false);
		MAD_ASSERT_DESC(m_skyboxBlendState, "Error creating blend state\n");
		if (!m_skyboxBlendState) return false;

		// Initialize the position vertex buffer with the vertices of the entire box
		m_skyboxMesh = UMesh::Load("engine\\meshes\\primitives\\icosphere.obj");
		MAD_ASSERT_DESC(m_skyboxMesh != nullptr, "Error loading the skybox cube mesh\n");
		if (!m_skyboxMesh) return false;

		return true;
	}
}<commit_msg>Minor changes because we can't use MAD_ASSERT_DESC when in release<commit_after>#include "Rendering/Skybox.h"
#include "Rendering/RenderContext.h"
#include "Rendering/Renderer.h"
#include "Rendering/GraphicsDriver.h"
#include "Rendering/DrawItem.h"
#include "Rendering/Texture.h"
#include "Rendering/RenderPassProgram.h"
#include "Rendering/Mesh.h"

#include "Misc/Assert.h"

namespace MAD
{
	USkybox::USkybox(const eastl::string& inShaderPath, const eastl::string& inCubemapPath, const Vector3& inBoxDimensions)
		: m_skyboxDimensions(inBoxDimensions)
		, m_skyboxTransform(Matrix::CreateScale(inBoxDimensions.x, inBoxDimensions.y, inBoxDimensions.z))
	{
		MAD_CHECK_DESC(InitializeSkybox(inShaderPath, inCubemapPath), "Error loading skybox\n");
	}

	void USkybox::DrawSkybox()
	{
		auto& graphicsDriver = URenderContext::Get().GetGraphicsDriver();
		const auto& gBufferPassDesc = URenderContext::Get().GetRenderer().GetGBufferPassDescriptor();
		SPerDrawConstants skyboxDrawConstants;

		// Bind the program
		m_skyboxShader->SetProgramActive(graphicsDriver, 0);

		// Bind the input layout
		graphicsDriver.SetInputLayout(m_skyboxInputLayout);

		// Bind the vertex buffer
		m_skyboxMesh->m_gpuPositions.Bind(graphicsDriver, 0);
		
		graphicsDriver.SetIndexBuffer(m_skyboxMesh->m_gpuIndexBuffer, 0);

		// Set the light accumulation buffer as render target since we dont want that the skybox to be lit (remember to unbind the depth buffer as input incase previous steps needed it as a SRV)
		graphicsDriver.SetPixelShaderResource(nullptr, ETextureSlot::DepthBuffer);
		graphicsDriver.SetRenderTargets(&gBufferPassDesc.m_renderTargets[AsIntegral(ERenderTargetSlot::LightingBuffer)], 1, m_depthStencilView.Get());

		graphicsDriver.SetDepthStencilState(m_depthStencilState, 0);

		// Upload sky box's scale matrix
		skyboxDrawConstants.m_objectToWorldMatrix = m_skyboxTransform;
		graphicsDriver.UpdateBuffer(EConstantBufferSlot::PerDraw, &skyboxDrawConstants, sizeof(skyboxDrawConstants));

		// Bind the rasterizer state
		graphicsDriver.SetRasterizerState(m_boxRasterizerState);

		graphicsDriver.SetBlendState(m_skyboxBlendState);

		graphicsDriver.DrawIndexed(static_cast<UINT>(m_skyboxMesh->m_indexBuffer.size()), 0, 0);
	}

	bool USkybox::InitializeSkybox(const eastl::string& inShaderPath, const eastl::string& inCubemapPath)
	{
		eastl::shared_ptr<UTexture> boxCubeMapTex = UTexture::Load(inCubemapPath, true, false, D3D11_RESOURCE_MISC_TEXTURECUBE);

		m_boxCubeMapSRV = boxCubeMapTex->GetTexureResource();
		MAD_CHECK_DESC(m_boxCubeMapSRV, "Error creating the shader resource view for the skybox cube map\n");
		if (!m_boxCubeMapSRV) return false;

		m_skyboxShader = URenderPassProgram::Load(inShaderPath);
		MAD_CHECK_DESC(m_skyboxShader != nullptr, "Error loading the skybox shader program\n");
		if (!m_skyboxShader) return false;

		m_skyboxInputLayout = UInputLayoutCache::GetInputLayout(EInputLayoutSemantic::Position);
		MAD_CHECK_DESC(m_skyboxInputLayout, "Error retrieving the skybox input layout\n");
		if (!m_skyboxInputLayout) return false;

		m_depthStencilView = URenderContext::Get().GetRenderer().GetGBufferPassDescriptor().m_depthStencilView;
		MAD_CHECK_DESC(m_depthStencilView, "Error retrieving the g-buffer's depth buffer\n");
		if (!m_depthStencilView) return false;

		m_depthStencilState = URenderContext::Get().GetRenderer().GetGBufferPassDescriptor().m_depthStencilState;

		m_boxRasterizerState = URenderContext::Get().GetGraphicsDriver().CreateRasterizerState(EFillMode::Solid, ECullMode::Front);
		MAD_CHECK_DESC(m_boxRasterizerState, "Error creating rasterizer state\n");
		if (!m_boxRasterizerState) return false;

		m_skyboxBlendState = URenderContext::Get().GetGraphicsDriver().CreateBlendState(false);
		MAD_CHECK_DESC(m_skyboxBlendState, "Error creating blend state\n");
		if (!m_skyboxBlendState) return false;

		// Initialize the position vertex buffer with the vertices of the entire box
		m_skyboxMesh = UMesh::Load("engine\\meshes\\primitives\\icosphere.obj");
		MAD_CHECK_DESC(m_skyboxMesh != nullptr, "Error loading the skybox cube mesh\n");
		if (!m_skyboxMesh) return false;

		return true;
	}
}
{'fraction_non_alphanumeric': 0.1034983658152766, 'fraction_numerical': 0.002663115845539281, 'mean_word_length': 7.245508982035928, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5519478', 'n_tokens_mistral': 2832, 'n_tokens_neox': 2651, 'n_words': 511}