<commit_before>#include "D3D.h"
#include <shared/shared.h>
#include "RenderTarget.h"
#include "DepthStencil.h"
#include "Configuration.h"

#include "D3DCompiler.h"

namespace Pimp
{

D3D* gD3D = NULL;


D3D::D3D(ID3D10Device1 *device, IDXGISwapChain* swapchain) : 
	device(device), swapchain(swapchain)
,	rasterizerState(nullptr)
,	renderTargetBackBuffer(nullptr)
,	depthStencil(nullptr)
,	depthStencilState(nullptr)
,	pWhiteTex(nullptr)
{
	memset(blendStates, 0, MAX_BlendMode*sizeof(BlendMode));

	HRESULT hr;

	const Configuration::DisplayMode& mode = Configuration::Instance()->GetDisplayMode();
	viewWidth = mode.width;
	viewHeight = mode.height;

#ifdef D3D_DISABLE_SPECIFIC_WARNINGS
	ID3D10InfoQueue* infoQueue;
	device->QueryInterface(__uuidof(ID3D10InfoQueue),  (void **)&infoQueue); 
	
	D3D10_MESSAGE_ID messageIDs [] = { 
		D3D10_MESSAGE_ID_DEVICE_OMSETRENDERTARGETS_HAZARD,
		D3D10_MESSAGE_ID_DEVICE_PSSETSHADERRESOURCES_HAZARD,
	};

	// Set the DenyList to use the list of messages
	D3D10_INFO_QUEUE_FILTER filter = { 0 };
	filter.DenyList.NumIDs = 2;
	filter.DenyList.pIDList = messageIDs;

	// Apply the filter to the info queue
	infoQueue->AddStorageFilterEntries(&filter);  
#endif

	// Retrieve backbuffer.
	ID3D10Texture2D* backbuffer;
	hr = swapchain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&backbuffer);
	D3D_ASSERT(hr);
	ASSERT(backbuffer != NULL);

	// Create render target view for backbuffer.
	ID3D10RenderTargetView* renderTargetViewBackbuffer;
	hr = device->CreateRenderTargetView(backbuffer, NULL, &renderTargetViewBackbuffer);
	D3D_ASSERT(hr);
	ASSERT(renderTargetViewBackbuffer != NULL);

	renderTargetBackBuffer = new RenderTarget(PIMP_BACKBUFFER_FORMAT_GAMMA, backbuffer, renderTargetViewBackbuffer, NULL);

	// Resort to triangle lists.
	device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Rasterizer state.
	D3D10_RASTERIZER_DESC rasterDesc;
	memset(&rasterDesc, 0, sizeof(rasterDesc));
	rasterDesc.FillMode = D3D10_FILL_SOLID;
	rasterDesc.CullMode = D3D10_CULL_BACK;
	//rasterDesc.FrontCounterClockwise = FALSE;
	//rasterDesc.DepthBias = 0;
	//rasterDesc.DepthBiasClamp = 0;
	//rasterDesc.SlopeScaledDepthBias = 0;
	rasterDesc.DepthClipEnable = TRUE;
	//rasterDesc.ScissorEnable = FALSE;
	rasterDesc.MultisampleEnable = TRUE;
	//rasterDesc.AntialiasedLineEnable = FALSE;
	
	rasterizerState = NULL;
	hr = device->CreateRasterizerState(&rasterDesc, &rasterizerState);
	D3D_ASSERT(hr);

	device->RSSetState(rasterizerState);

	// Create depth-stencil
	depthStencil = CreateDepthStencil(true);

	// Depth-stencil state
	D3D10_DEPTH_STENCIL_DESC descDepthS;
	memset(&descDepthS, 0, sizeof(descDepthS));
	descDepthS.DepthEnable = true;
	descDepthS.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
	descDepthS.DepthFunc = D3D10_COMPARISON_LESS;

	depthStencilState = NULL;
	hr = device->CreateDepthStencilState(&descDepthS, &depthStencilState);
	D3D_ASSERT(hr);
	ASSERT(depthStencilState != NULL);

	device->OMSetDepthStencilState(depthStencilState, 0);

	// Bind our backbuffer and depth stencil by default
	BindBackbuffer(depthStencil);

	// For letterboxing..
	float renderAspectRatio = Configuration::Instance()->GetRenderAspectRatio();

	// define full & adjusted (16:9) viewport
	m_fullVP.TopLeftX = 0;
	m_fullVP.TopLeftY = 0;
	m_fullVP.Width = viewWidth;
	m_fullVP.Height = viewHeight;
	m_fullVP.MinDepth = 0.f;
	m_fullVP.MaxDepth = 1.f;

	const float fullAspectRatio = (float) m_fullVP.Width / m_fullVP.Height;
	unsigned int xResAdj, yResAdj;
	if (fullAspectRatio < renderAspectRatio)
	{
		xResAdj = m_fullVP.Width;
		yResAdj = (unsigned int) (m_fullVP.Width/renderAspectRatio);
	}
	else if (fullAspectRatio > renderAspectRatio)
	{
		xResAdj = (unsigned int) (m_fullVP.Height*renderAspectRatio);
		yResAdj = m_fullVP.Height;
	}
	else // ==
	{
		xResAdj = m_fullVP.Width;
		yResAdj = m_fullVP.Height;
	}
	
	m_adjVP.Width = xResAdj;
	m_adjVP.Height = yResAdj;
	m_adjVP.TopLeftX = (m_fullVP.Width-xResAdj)/2;
	m_adjVP.TopLeftY = (m_fullVP.Height-yResAdj)/2;
	m_adjVP.MinDepth = 0.f;
	m_adjVP.MaxDepth = 1.f;

	// Set adj. viewport
	device->RSSetViewports(1, &m_adjVP);

	// Blend states
	blendStates[BM_None] = NULL;

	D3D10_BLEND_DESC alphaDesc;<commit_msg>Still fucks up and I don't know why.<commit_after>#include "D3D.h"
#include <shared/shared.h>
#include "RenderTarget.h"
#include "DepthStencil.h"
#include "Configuration.h"

#include "D3DCompiler.h"

namespace Pimp
{

D3D* gD3D = NULL;


D3D::D3D(ID3D10Device1 *device, IDXGISwapChain* swapchain) : 
	device(device), swapchain(swapchain)
,	rasterizerState(nullptr)
,	renderTargetBackBuffer(nullptr)
,	depthStencil(nullptr)
,	depthStencilState(nullptr)
,	pWhiteTex(nullptr)
{
	memset(blendStates, 0, MAX_BlendMode*sizeof(BlendMode));

	HRESULT hr;

	const Configuration::DisplayMode& mode = Configuration::Instance()->GetDisplayMode();
	viewWidth = mode.width;
	viewHeight = mode.height;

#ifdef D3D_DISABLE_SPECIFIC_WARNINGS
	ID3D10InfoQueue* infoQueue;
	device->QueryInterface(__uuidof(ID3D10InfoQueue),  (void **)&infoQueue); 
	
	D3D10_MESSAGE_ID messageIDs [] = { 
		D3D10_MESSAGE_ID_DEVICE_OMSETRENDERTARGETS_HAZARD,
		D3D10_MESSAGE_ID_DEVICE_PSSETSHADERRESOURCES_HAZARD,
	};

	// Set the DenyList to use the list of messages
	D3D10_INFO_QUEUE_FILTER filter = { 0 };
	filter.DenyList.NumIDs = 2;
	filter.DenyList.pIDList = messageIDs;

	// Apply the filter to the info queue
	infoQueue->AddStorageFilterEntries(&filter);  
#endif

	// Retrieve backbuffer.
	ID3D10Texture2D* backbuffer;
	hr = swapchain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&backbuffer);
	D3D_ASSERT(hr);
	ASSERT(backbuffer != NULL);

	// Create render target view for backbuffer.
	ID3D10RenderTargetView* renderTargetViewBackbuffer;
	hr = device->CreateRenderTargetView(backbuffer, NULL, &renderTargetViewBackbuffer);
	D3D_ASSERT(hr);
	ASSERT(renderTargetViewBackbuffer != NULL);

	renderTargetBackBuffer = new RenderTarget(PIMP_BACKBUFFER_FORMAT_GAMMA, backbuffer, renderTargetViewBackbuffer, NULL);

	// Resort to triangle lists.
	device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Rasterizer state.
	D3D10_RASTERIZER_DESC rasterDesc;
	memset(&rasterDesc, 0, sizeof(rasterDesc));
	rasterDesc.FillMode = D3D10_FILL_SOLID;
	rasterDesc.CullMode = D3D10_CULL_BACK;
	//rasterDesc.FrontCounterClockwise = FALSE;
	//rasterDesc.DepthBias = 0;
	//rasterDesc.DepthBiasClamp = 0;
	//rasterDesc.SlopeScaledDepthBias = 0;
	rasterDesc.DepthClipEnable = TRUE;
	//rasterDesc.ScissorEnable = FALSE;
	rasterDesc.MultisampleEnable = TRUE;
	//rasterDesc.AntialiasedLineEnable = FALSE;
	
	rasterizerState = NULL;
	hr = device->CreateRasterizerState(&rasterDesc, &rasterizerState);
	D3D_ASSERT(hr);

	device->RSSetState(rasterizerState);

	// Create depth-stencil
	depthStencil = CreateDepthStencil(true);

	// Depth-stencil state
	D3D10_DEPTH_STENCIL_DESC descDepthS;
	memset(&descDepthS, 0, sizeof(descDepthS));
	descDepthS.DepthEnable = true;
	descDepthS.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
	descDepthS.DepthFunc = D3D10_COMPARISON_LESS;

	depthStencilState = NULL;
	hr = device->CreateDepthStencilState(&descDepthS, &depthStencilState);
	D3D_ASSERT(hr);
	ASSERT(depthStencilState != NULL);

	device->OMSetDepthStencilState(depthStencilState, 0);

	// Bind our backbuffer and depth stencil by default
	BindBackbuffer(depthStencil);

	// For letterboxing..
	float renderAspectRatio = Configuration::Instance()->GetRenderAspectRatio();

	// define full & adjusted (16:9) viewport
	m_fullVP.TopLeftX = 0;
	m_fullVP.TopLeftY = 0;
	m_fullVP.Width = viewWidth;
	m_fullVP.Height = viewHeight;
	m_fullVP.MinDepth = 0.f;
	m_fullVP.MaxDepth = 1.f;

	const float fullAspectRatio = (float) m_fullVP.Width / m_fullVP.Height;
	unsigned int xResAdj, yResAdj;
	if (fullAspectRatio < renderAspectRatio)
	{
		xResAdj = m_fullVP.Width;
		yResAdj = (unsigned int) (m_fullVP.Width/renderAspectRatio);
	}
	else if (fullAspectRatio > renderAspectRatio)
	{
		xResAdj = (unsigned int) (m_fullVP.Height*renderAspectRatio);
		yResAdj = m_fullVP.Height;
	}
	else // ==
	{
		xResAdj = m_fullVP.Width;
		yResAdj = m_fullVP.Height;
	}
	
	m_adjVP.Width = xResAdj;
	m_adjVP.Height = yResAdj;
	m_adjVP.TopLeftX = (m_fullVP.Width-xResAdj)/2;
	m_adjVP.TopLeftY = (m_fullVP.Height-yResAdj)/2;
	m_adjVP.MinDepth = 0.f;
	m_adjVP.MaxDepth = 1.f;

	// Blend states
	blendStates[BM_None] = NULL;

	D3D10_BLEND_DESC alphaDesc;
{'fraction_non_alphanumeric': 0.11113755354593051, 'fraction_numerical': 0.021299381247025226, 'mean_word_length': 5.811183144246353, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, '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': '1949881', 'n_tokens_mistral': 3373, 'n_tokens_neox': 3230, 'n_words': 527}