bool CDX11SourceTextureData2D::CreateD3DData(ID3D11Device* pkDevice)
{
	D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
	D3D11_TEXTURE2D_DESC desc;

	CFileSystem* pFileSystem = CCoreEngine::Get()->GetFileSystem();
	CFile* pFile = pFileSystem->OpenFile(m_kCreateParams.m_sFileName, CFile::OM_Read);
	if (pFile == 0)
		return false;

	size_t stSize = pFile->GetSize();
	char* acData = IntAlloc(char, stSize);
	if (pFile->ReadData(acData, stSize) != stSize)
	{
		IntFree(acData);
		pFileSystem->CloseFile(pFile);
		return false;
	}

	// Load the texture and initialize an ID3D11Texture2D object.
	D3DX11CreateTextureFromMemory( pkDevice, acData, stSize, 
			NULL, NULL, (ID3D11Resource**) &m_d3dTexture2D, NULL );

	// free the temporary read data and close the file again
	IntFree(acData);
	pFileSystem->CloseFile(pFile);

	// Get a texture description to determine the texture
	// format of the loaded texture.
	m_d3dTexture2D->GetDesc( &desc );

	// Fill in the D3D11_SHADER_RESOURCE_VIEW_DESC structure.
	srvDesc.Format = desc.Format;
	srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	srvDesc.Texture2D.MostDetailedMip = 0;
	srvDesc.Texture2D.MipLevels = desc.MipLevels;

	// Create the shader resource view.
	pkDevice->CreateShaderResourceView(m_d3dTexture2D, 
		&srvDesc, &m_d3dShaderResourceView );

	return true;
}
Exemplo n.º 2
0
Type * ParseConstList(Type * type)
{
	Bool id_required;
	Var * var;
	BigInt last_n, * c;

	IntInit(&last_n, 0);

	EnterBlockWithStop(TOKEN_VOID);
		
	id_required = false;

	while (TOK != TOKEN_ERROR && !NextIs(TOKEN_BLOCK_END)) {

		while(NextIs(TOKEN_EOL));

		if (TOK == TOKEN_ID || (TOK >= TOKEN_KEYWORD && TOK <= TOKEN_LAST_KEYWORD)) {
			var = VarAllocScope(NO_SCOPE, INSTR_CONST, NAME, 0);
			NextToken();
			if (NextIs(TOKEN_EQUAL)) {
				SyntaxError("Unexpected equal");
			}

			if (NextIs(TOKEN_COLON)) {
				c = ParseIntConstExpression(type->owner);
				if (TOK) {
					IntModify(&last_n, c);
				}
/*
				// Parse const expression
				if (TOK == TOKEN_INT) {
					last_n = LEX.n;
					NextToken();
				} else {
					SyntaxError("expected integer value");
				}
*/
			} else {
				IntAddN(&last_n, 1);
			}

			var->var = VarN(&last_n);

			if (type->owner != SCOPE) {
				type = TypeDerive(type);
			}

			TypeAddConst(type, var);

		} else {
			if (id_required) {
				SyntaxError("expected constant identifier");
			} else {
				ExitBlock();
				break;
			}
		}
		id_required = false;
		// One code may be ended either by comma or by new line
		if (NextIs(TOKEN_COMMA)) id_required = true;
		NextIs(TOKEN_EOL);
	}
	IntFree(&last_n);
	return type;
}