Exemplo n.º 1
0
bool GLoadToken::LoadBuffer(const TCHAR* strFileName)
{
	CStopwatch stopwatch;
	TCHAR Drive[MAX_PATH];
	TCHAR Dir[MAX_PATH];
	TCHAR FName[MAX_PATH];
	TCHAR Ext[MAX_PATH];
	_tsplitpath(strFileName, Drive, Dir, FName, Ext);
	m_szDirName = Drive;
	m_szDirName += Dir;
	m_szName = FName;
	m_szName += Ext;

	LARGE_INTEGER FileSize;
	m_hHandle = CreateFile(strFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL, NULL);
	if (m_hHandle != INVALID_HANDLE_VALUE)
	{
		GetFileSizeEx(m_hHandle, &FileSize);
		UINT cBytes = FileSize.LowPart;

		SAFE_NEW_ARRAY(m_pmbStaticMeshData, char, cBytes);
		if (!m_pmbStaticMeshData)
		{
			DeleteBuffer();
			return false;//E_OUTOFMEMORY;
		}

		DWORD dwBytesRead;
		if (!ReadFile(m_hHandle, m_pmbStaticMeshData, cBytes, &dwBytesRead, NULL))
		{
			DeleteBuffer();
			return false;
		}
		//SetFilePointer( m_hHandle, 0, 0, FILE_BEGIN );				
	}
	else
	{
		return false;
	}

	TCHAR* szMeshData = NULL;
	TCHAR* SearchString = NULL;
	size_t convertedChars = 0;
	SAFE_NEW_ARRAY(m_pwcStaticMeshData, TCHAR, FileSize.LowPart);
	if (mbstowcs_s(&convertedChars, m_pwcStaticMeshData, FileSize.LowPart, m_pmbStaticMeshData, _TRUNCATE) == 0)
	{
		DeleteBuffer();
		return false;
	}
	if (m_pwcStaticMeshData)
	{
		SAFE_DELETE_ARRAY(m_pmbStaticMeshData);
		m_pwcTokenData = m_pwcStaticMeshData;
		m_pwcSearchData = m_pwcStaticMeshData;
	}

	CloseHandle(m_hHandle);
	m_hHandle = 0;

	BeginToken();
	stopwatch.Output(L"GLoadToken::LoadBuffer");
	return true;
}
Exemplo n.º 2
0
bool		GGbsModel::Init(TCHAR* strFileName, TCHAR* strShaderName) {

	HRESULT hr = S_OK;

	//파싱, 필요한 처리 시작.
	CStopwatch stopwatch;


	//I_AseParser
	I_GbsParser.InitGbsModel(strFileName, this);

	//필요한 처리 끝.
	stopwatch.Output(L"Init()");


	// Create the sample state
	D3D11_SAMPLER_DESC sampDesc;
	ZeroMemory(&sampDesc, sizeof(sampDesc));
	sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	sampDesc.MinLOD = 0;
	sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
	hr = g_pd3dDevice->CreateSamplerState(&sampDesc, m_pSamplerLinear.GetAddressOf());
	if (FAILED(hr))
		return hr;




	// Compile the vertex shader
	ID3DBlob* pVSBlob = NULL;
	hr = CompileShaderFromFile(strShaderName, "VS", "vs_4_0", &pVSBlob);
	if (FAILED(hr))
	{
		MessageBox(NULL,
			L"The FX file cannot be compiled.  Please run this executable from the directory that contains the FX file.", L"Error", MB_OK);
		return hr;
	}

	// Create the vertex shader
	hr = g_pd3dDevice->CreateVertexShader(pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), NULL, m_pVertexShader.GetAddressOf());
	if (FAILED(hr))
	{
		pVSBlob->Release();
		return hr;
	}

	// Define the input layout
	D3D11_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,  0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL",   0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, 40, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};
	UINT numElements = ARRAYSIZE(layout);

	// Create the input layout
	hr = g_pd3dDevice->CreateInputLayout(layout, numElements, pVSBlob->GetBufferPointer(),
		pVSBlob->GetBufferSize(), m_pVertexLayout.GetAddressOf());
	pVSBlob->Release();
	if (FAILED(hr))
		return hr;

	// Set the input layout
	g_pImmediateContext->IASetInputLayout(m_pVertexLayout.Get());

	// Compile the pixel shader
	ID3DBlob* pPSBlob = NULL;
	hr = CompileShaderFromFile(strShaderName, "PS", "ps_4_0", &pPSBlob);
	if (FAILED(hr))
	{
		MessageBox(NULL,
			L"The FX file cannot be compiled.  Please run this executable from the directory that contains the FX file.", L"Error", MB_OK);
		return hr;
	}

	// Create the pixel shader
	hr = g_pd3dDevice->CreatePixelShader(pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), NULL, m_pPixelShader.GetAddressOf());
	pPSBlob->Release();
	if (FAILED(hr))
		return hr;


	

	if (m_vGeomObj.size() == 1)
		SingleModelInit();
	else
		MultiModelInit();

	


	return true;
};