All pastes #1736640 Raw Edit

Something

public cpp v1 · immutable
#1736640 ·published 2010-01-03 21:12 UTC
rendered paste body
#include "Device.h"/* FRIEND CLASSES */#include "Shader.h"/* CLASS Device */Device::Device( void ){	Invalidate();}Device::~Device( void ){	Destroy();}void Device::Invalidate( void ){	pDevice				= 0;	pRenderTargetView	= 0;	pDepthStencilView	= 0;	pSwapChain			= 0;	bDeviceActive		= FALSE;	memset(&sStates, 0, sizeof(_states));}bool Device::Create( HWND hOutput, HINSTANCE hInstance, unsigned uiWidth, unsigned uiHeight ){	unsigned flags = 0;#	ifdef DEBUG	flags = D3D10_CREATE_DEVICE_DEBUG;#	endif	hInstance = hInstance;	/* SWAP CHAIN DESCRIPTION (WINDOW MODE) */	DXGI_SWAP_CHAIN_DESC sw_desc	= {0};	sw_desc.BufferCount				= 1;								/* BackBuffer count */	sw_desc.BufferUsage				= DXGI_USAGE_RENDER_TARGET_OUTPUT;	/* Use for */	sw_desc.BufferDesc.Format		= DXGI_FORMAT_R8G8B8A8_UNORM;		/* Format for */	sw_desc.BufferDesc.Width		= uiWidth;							/* width and .. */	sw_desc.BufferDesc.Height		= uiHeight;							/* height of the backbuffer */	sw_desc.BufferDesc.RefreshRate.Numerator = 60;						/* refreshrate */	sw_desc.BufferDesc.RefreshRate.Denominator = 1;	sw_desc.Windowed				= TRUE;		sw_desc.OutputWindow			= hOutput;	sw_desc.SampleDesc.Count		= 1;								/* Anti-Aliasing */	sw_desc.SampleDesc.Quality		= 0;	/* CREATING SWAP CHAIN AND DEVICE */	HRESULT hr = D3D10CreateDeviceAndSwapChain(0, D3D10_DRIVER_TYPE_HARDWARE, 0, flags, D3D10_SDK_VERSION, &sw_desc, &pSwapChain, &pDevice);	if(FAILED(hr))	{		return false;	}	else	{		bDeviceActive = TRUE;	}	if(CreateDS() == false)	{		return false;	}	if(CreateRT() == false)	{		return false;	}	SetViewport(0.0f, 1.0f, uiWidth, uiHeight);	/* SET STATE READY */	sStates.bReady = TRUE;	return true;}bool Device::CreateRT( void ){	if(bDeviceActive == FALSE)	{		return false;	}	ID3D10Texture2D	*pBackBuffer = 0;	HRESULT hr = pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)&pBackBuffer);	if(FAILED(hr))	{		return false;	}	D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;	rtv_desc.Format							= DXGI_FORMAT_R8G8B8A8_UNORM;	rtv_desc.ViewDimension					= D3D10_RTV_DIMENSION_TEXTURE2D;	rtv_desc.Texture2D.MipSlice				= 0;	hr =	pDevice->CreateRenderTargetView(pBackBuffer, 0, &pRenderTargetView);			pBackBuffer->Release();	if(FAILED(hr))	{		return false;	}	pDevice->OMSetRenderTargets(1, &pRenderTargetView, (pDepthStencilView?pDepthStencilView:0));	return true;}bool Device::CreateDS( void ){	/* NOT NEEDED NJEEEEEEEEEEET :-D */	return true;}void Device::SetViewport( float min_depth, float max_depth, unsigned uiWidth, unsigned uiHeight ){	if(bDeviceActive == FALSE)	{		false;	}	D3D10_VIEWPORT viewport;	viewport.Width		= uiWidth;	viewport.Height		= uiHeight;	viewport.MaxDepth	= max_depth;	viewport.MinDepth	= min_depth;	viewport.TopLeftX	= 0;	viewport.TopLeftY	= 0;	pDevice->RSSetViewports(1, &viewport);}void Device::Destroy( void ){	RELEASE(pRenderTargetView);	RELEASE(pDepthStencilView);	RELEASE(pSwapChain);	RELEASE(pDevice);	bDeviceActive	= false;	sStates.bReady	= FALSE;}void Device::Render( void ){	if(bDeviceActive == FALSE)	{		return;		}	if(sStates.bCleared == FALSE)	{		RTClear();	}		RTPresent();}void Device::RTClear( float r, float g, float b, float a ){	if(bDeviceActive == FALSE)	{		return;	}	float colorRGBA[] = {r, g, b, a};	pDevice->ClearRenderTargetView(pRenderTargetView, colorRGBA);	/* SET STATE CLEARED */	sStates.bCleared = TRUE;}void Device::RTPresent( void ){	if(bDeviceActive == FALSE)	{		return;	}	pSwapChain->Present(0, 0);	/* CLEAR STATES */	memset(&sStates, 0, sizeof(_states));}Shader* Device::LoadShader( LPCSTR Filename ){	Shader *pShader = new Shader;	pShader->pDevice = pDevice;	if( false == pShader->Load(Filename) )	{		delete pShader;		pShader = 0;	}	return pShader;}RenderUnit* Device::CreateRenderUnit( void ){	RenderUnit *pRU = new RenderUnit;	pRU->pDevice = pDevice;	return pRU;}