Example #1
0
bool EAE_Engine::Tools::cMeshBuilder::Build( const std::vector<std::string>& )
{
	/*
	open may failed on Linux has about 30 conditions, some of them are:
	If the file exists and you don't have permission to write it.
	If the file doesn't exist, and you don't have permission (on the diretory) to create it.
	If you don't have search permission on some parent directory.
	If you pass in a bogus char* for the filename.
	If, while opening a device file, you press CTRL-C.
	If the kernel encountered too many symbolic links while resolving the name.
	If you try to open a directory for writing.
	If the pathname is too long.
	If your process has too many files open already.
	If the system has too many files open already.
	If the pathname refers to a device file, and there is no such device in the system.
	If the kernel has run out of memory.
	If the filesystem is full.
	If a component of the pathname is not a directory.
	If the file is on a read-only filesystem. 
	If the file is an executable file which is currently being executed.
	*/
	bool wereThereErrors = false;
	// Copy the source to the target
	{
		const bool dontFailIfTargetAlreadyExists = false;
		const bool updateTheTargetFileTime = true;
		std::ofstream outfile(_path_target, std::ofstream::binary);
		if (!outfile)
		{
			std::stringstream decoratedErrorMessage;
			decoratedErrorMessage << "Failed to output mesh to: " << _path_target;
			OutputErrorMessage(decoratedErrorMessage.str().c_str(), __FILE__);
			wereThereErrors = true;
			return !wereThereErrors;
		}
		char* o_pBuffer = nullptr;
		uint32_t o_sizeOfBuffer = 0;
		wereThereErrors = !GenerateBinaryMeshData(_path_source, o_pBuffer, o_sizeOfBuffer);
		if (!wereThereErrors)
		{
			// write to outfile
			outfile.write(o_pBuffer, o_sizeOfBuffer);
			// release dynamically-allocated memory
			delete[] o_pBuffer;
		}
		outfile.close();
		if (wereThereErrors)
		{
			wereThereErrors = true;
			std::stringstream decoratedErrorMessage;
			decoratedErrorMessage << "Failed to build mesh from\"" << _path_source << "\" to \"" << _path_target;
			OutputErrorMessage(decoratedErrorMessage.str().c_str(), __FILE__);
		}
	}
	
	return !wereThereErrors;
}
bool AssetBuilder::GetAssetBuilderEnvironmentVariable(const char* i_key, std::string& o_value)
{
	// Windows requires a character buffer
	// to copy the environment variable into.
	// An arbitrary value is chosen that "should" be "big enough":
	const DWORD maxCharacterCount = 512;
	char buffer[maxCharacterCount];
	// Ask Windows for the environment variable
	const DWORD characterCount = GetEnvironmentVariable( i_key, buffer, maxCharacterCount );
	if ( characterCount > 0 )
	{
		if ( characterCount <= maxCharacterCount )
		{
			o_value = buffer;
			return true;
		}
		else
		{
			// If you're seeing this error you will need to increase maxCharacterCount
			std::stringstream errorMessage;
			errorMessage << "The environment variable \"" << i_key << "\" requires " << characterCount <<
				" characters and the provided buffer only has room for " << maxCharacterCount;
			OutputErrorMessage( errorMessage.str().c_str() );
			return false;
		}
	}
	else
	{
		DWORD errorCode;
		std::string errorString = GetLastWindowsError( &errorCode );
		if ( errorCode == ERROR_ENVVAR_NOT_FOUND )
		{
			// If you're seeing this error and the environment variable is spelled correctly
			// it _probably_ means that you are debugging and haven't set up the environment.
			//	* Right click the project name and choose "Properties"
			//	* In the tree view to the left select "Configuration Properties->Debugging"
			//	* In the "Environment" field make sure that you have this environment variable set like:
			//		* someKey=$(someKey)
			std::string errorMessage = std::string( "The environment variable \"" ) +
				i_key + "\" doesn't exist";
			OutputErrorMessage( errorMessage.c_str() );
		}
		else
		{
			std::string errorMessage = std::string( "Windows failed to get the environment variable \"" ) +
				i_key + "\": " + errorString;
			OutputErrorMessage( errorMessage.c_str() );
		}
		return false;
	}
}
int AssetBuilder::OutputErrorMessage(lua_State* io_luaState)
{
	// Argument #1: The error message
	const char* i_errorMessage;
	if (lua_isstring(io_luaState, 1))
	{
		i_errorMessage = lua_tostring(io_luaState, 1);
	}
	else
	{
		return luaL_error(io_luaState,
			"Argument #1 must be a string (instead of a %s)",
			luaL_typename(io_luaState, 1));
	}
	// Argument #2: An optional file name
	const char* i_optionalFileName = NULL;
	if (lua_isstring(io_luaState, 2))
	{
		i_optionalFileName = lua_tostring(io_luaState, 2);
	}

	// Output the error message
	OutputErrorMessage(i_errorMessage, i_optionalFileName);

	return 0;
}
bool TextureShaderClass::SetShaderParameters(HWND hwnd, ID3D11DeviceContext* deviceContext, XMMATRIX& worldMatrix, XMMATRIX& viewMatrix, XMMATRIX& projectionMatrix, ID3D11ShaderResourceView* texture, float blend, XMFLOAT4 hueColor, bool xFlip, bool yFlip){
	HRESULT hr;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	MatrixBufferType* dataPtr;
	PixelShaderBufferType* dataPtr2;
	unsigned int bufferNumber;

	hr = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if (FAILED(hr)){
		OutputErrorMessage(hwnd, hr, L"Could not map matrix buffer with error: ");
		return false;
	}

	dataPtr = (MatrixBufferType*)mappedResource.pData;
	dataPtr->world = worldMatrix;
	dataPtr->view = viewMatrix;
	dataPtr->projection = projectionMatrix;

	deviceContext->Unmap(m_matrixBuffer, 0);

	bufferNumber = 0;

	deviceContext->VSSetConstantBuffers(bufferNumber, 1, &m_matrixBuffer);

	deviceContext->PSSetShaderResources(0, 1, &texture);

	hr = deviceContext->Map(m_pixelShaderCBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if (FAILED(hr)){
		OutputErrorMessage(hwnd, hr, L"Could not map pixel shader C buffer with error: ");
		return false;
	}
	
	dataPtr2 = (PixelShaderBufferType*)mappedResource.pData;
	dataPtr2->hueColor = hueColor;
	dataPtr2->alphaBlendAmount = blend;
	dataPtr2->xFlip = xFlip;
	dataPtr2->yFlip = yFlip;
	deviceContext->Unmap(m_pixelShaderCBuffer, 0);
	bufferNumber = 0;
	deviceContext->PSSetConstantBuffers(bufferNumber, 1, &m_pixelShaderCBuffer);

	return true;
}
Example #5
0
bool EAE_Engine::Tools::cGenericBuilder::Build( const std::vector<std::string>& )
{
	bool wereThereErrors = false;

	// Copy the source to the target
	{
		const bool dontFailIfTargetAlreadyExists = false;
		const bool updateTheTargetFileTime = true;
		std::string errorMessage;
		if ( !EAE_Engine::CopyFile( _path_source, _path_target, dontFailIfTargetAlreadyExists, updateTheTargetFileTime, &errorMessage ) )
		{
			wereThereErrors = true;
			std::stringstream decoratedErrorMessage;
			decoratedErrorMessage << "Windows failed to copy \"" << _path_source << "\" to \"" << _path_target << "\": " << errorMessage;
			OutputErrorMessage( decoratedErrorMessage.str().c_str(), __FILE__ );
		}
	}
	
	return !wereThereErrors;
}
bool eae6320::cTextureBuilder::Build( const std::vector<std::string>& )
{
	bool wereThereErrors = false;

	if ( !Initialize( m_path_source ) )
	{
		wereThereErrors = true;
		goto OnExit;
	}

	// Get information about the source image
	D3DXIMAGE_INFO imageInfo_source;
	{
		if ( FAILED( D3DXGetImageInfoFromFile( m_path_source, &imageInfo_source ) ) )
		{
			wereThereErrors = true;
			OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source );
			goto OnExit;
		}
	}
	// Load the source image and do any necessary processing (compress, generate MIP maps, change resolution, etc.)
	{
		// Try to match the original image's format as closely as possible
		D3DFORMAT format = D3DFMT_UNKNOWN;
		{
			if ( imageInfo_source.ImageFileFormat == D3DXIFF_DDS )
			{
				// DDS files will remain unchanged
				// (this could cause problems in the simplistic OpenGL texture loading code that I provide)
				format = imageInfo_source.Format;
			}
			else
			{
				// The decision of which DXT format to use is simplistic:
				//	* If it can easily be determined that the source image doesn't have an alpha channel then DXT1 is used
				//	* DXT5 is used for everything else
				const D3DFORMAT format_original = imageInfo_source.Format;
				const bool isAlphaChannelUnnecessary = ( format_original == D3DFMT_R8G8B8 ) || ( format_original == D3DFMT_X8R8G8B8 )
					|| ( format_original == D3DFMT_R5G6B5 ) || ( format_original == D3DFMT_X1R5G5B5 )
					|| ( format_original == D3DFMT_X4R4G4B4  ) || ( format_original == D3DFMT_X8B8G8R8 );
				if ( isAlphaChannelUnnecessary )
				{
					format = D3DFMT_DXT1;
				}
				else
				{
					format = D3DFMT_DXT5;
				}
			}
		}
		// The source width and height could be used, but ensuring that the dimensions are always a power-of-2 is more compatible
		// (and the image will probably end up taking the same amount of space anyway because of alignment issues)
		const unsigned int roundUpToAPowerOf2 = D3DX_DEFAULT;
		unsigned int requestedMipMapCount;
		{
			const bool doMipMapsExist = imageInfo_source.MipLevels > 1;
			if ( doMipMapsExist )
			{
				requestedMipMapCount = D3DX_FROM_FILE;
			}
			else
			{
				// This will generate all of the potential MIP map levels (down to the smallest 1x1)
				requestedMipMapCount = D3DX_DEFAULT;
			}
		}
		const DWORD staticTexture = 0;
		const D3DPOOL letD3dManageMemory = D3DPOOL_MANAGED;
		const DWORD useDefaultFiltering = D3DX_DEFAULT;
		const D3DCOLOR noColorKey = 0;
		PALETTEENTRY* noColorPalette = NULL;
		switch( imageInfo_source.ResourceType )
		{
		case D3DRTYPE_TEXTURE:
			{
				const HRESULT result = D3DXCreateTextureFromFileEx( s_direct3dDevice, m_path_source, 
					roundUpToAPowerOf2, roundUpToAPowerOf2, requestedMipMapCount,
					staticTexture, format, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, 
					&imageInfo_source, noColorPalette, reinterpret_cast<IDirect3DTexture9**>( &s_texture ) );
				if ( FAILED( result ) )
				{
					wereThereErrors = true;
					OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source );
					goto OnExit;
				}
			}
			break;
		case D3DRTYPE_CUBETEXTURE:
			{
				const HRESULT result = D3DXCreateCubeTextureFromFileEx( s_direct3dDevice, m_path_source, 
					roundUpToAPowerOf2, requestedMipMapCount,
					staticTexture, format, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, 
					&imageInfo_source, noColorPalette, reinterpret_cast<IDirect3DCubeTexture9**>( &s_texture ) );
				if ( FAILED( result ) )
				{
					wereThereErrors = true;
					OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source );
					goto OnExit;
				}
			}
			break;
		case D3DRTYPE_VOLUMETEXTURE:
			{
				const HRESULT result = D3DXCreateVolumeTextureFromFileEx( s_direct3dDevice, m_path_source, 
					roundUpToAPowerOf2, roundUpToAPowerOf2, imageInfo_source.Depth, requestedMipMapCount,
					staticTexture, format, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, 
					&imageInfo_source, noColorPalette, reinterpret_cast<IDirect3DVolumeTexture9**>( &s_texture ) );
				if ( FAILED( result ) )
				{
					wereThereErrors = true;
					OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source );
					goto OnExit;
				}
			}
			break;
		default:
			{
				wereThereErrors = true;
				std::stringstream errorMessage;
				errorMessage << "Unsupported texture resource type " << imageInfo_source.ResourceType;
				OutputErrorMessage( errorMessage.str().c_str(), m_path_source );
				goto OnExit;
			}
		}
	}
	// Save the texture
	{
		const D3DXIMAGE_FILEFORMAT ddsFormat = D3DXIFF_DDS;
		PALETTEENTRY* noColorPalette = NULL;
		HRESULT result = D3DXSaveTextureToFile( m_path_target, ddsFormat, s_texture, noColorPalette );
		if ( FAILED( result ) )
		{
			wereThereErrors = true;
			OutputErrorMessage( "DirectX failed to save the texture", m_path_target );
			goto OnExit;
		}
	}

OnExit:

	if ( !ShutDown() )
	{
		wereThereErrors = true;
	}

	return !wereThereErrors;
}
bool TextureShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename){
	HRESULT hr;
	ID3D10Blob* errorMessage;
	ID3D10Blob* vertexShaderBuffer;
	ID3D10Blob* pixelShaderBuffer;
	D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
	unsigned int numElements;
	D3D11_BUFFER_DESC matrixBufferDesc;
	D3D11_SAMPLER_DESC samplerDesc;
	D3D11_BUFFER_DESC transparentBufferDesc;

	errorMessage = 0;
	vertexShaderBuffer = 0;
	pixelShaderBuffer = 0;

	hr = D3DCompileFromFile(vsFilename, NULL, NULL, "TextureVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &vertexShaderBuffer, &errorMessage);
	if (FAILED(hr)){
		if (errorMessage){
			OutputShaderErrorMessage(errorMessage, hwnd, vsFilename);
		}
		else{
			MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
		}
		return false;
	}

	hr = D3DCompileFromFile(psFilename, NULL, NULL, "TexturePixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &pixelShaderBuffer, &errorMessage);
	if (FAILED(hr)){
		if (errorMessage){
			OutputShaderErrorMessage(errorMessage, hwnd, psFilename);
		}
		else{
			MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
		}
		return false;
	}

	hr = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
	if (FAILED(hr)){
		OutputErrorMessage(hwnd, hr, L"Could not create vertex shader with error: ");
		return false;
	}

	hr = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
	if (FAILED(hr)){
		OutputErrorMessage(hwnd, hr, L"Could not create pixel shader with error: ");
		return false;
	}

	polygonLayout[0].SemanticName = "POSITION";
	polygonLayout[0].SemanticIndex = 0;
	polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
	polygonLayout[0].InputSlot = 0;
	polygonLayout[0].AlignedByteOffset = 0;
	polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[0].InstanceDataStepRate = 0;
	polygonLayout[1].SemanticName = "TEXCOORD";
	polygonLayout[1].SemanticIndex = 0;
	polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
	polygonLayout[1].InputSlot = 0;
	polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[1].InstanceDataStepRate = 0;

	numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);
	
	hr = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &m_layout);
	if (FAILED(hr)){
		OutputErrorMessage(hwnd, hr, L"Could not create input layout with error: ");
		return false;
	}

	vertexShaderBuffer->Release();
	vertexShaderBuffer = 0;
	pixelShaderBuffer->Release();
	pixelShaderBuffer = 0;

	ZeroMemory(&matrixBufferDesc, sizeof(matrixBufferDesc));
	matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
	matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType);
	matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	matrixBufferDesc.MiscFlags = 0;
	matrixBufferDesc.StructureByteStride = 0;
	hr = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
	if (FAILED(hr)){
		OutputErrorMessage(hwnd, hr, L"Could not create matrix buffer with error: ");
		return false;
	}

	ZeroMemory(&transparentBufferDesc, sizeof(transparentBufferDesc));
	transparentBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
	transparentBufferDesc.ByteWidth = sizeof(PixelShaderBufferType);
	transparentBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	transparentBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	transparentBufferDesc.MiscFlags = 0;
	transparentBufferDesc.StructureByteStride = 0;
	hr = device->CreateBuffer(&transparentBufferDesc, NULL, &m_pixelShaderCBuffer);
	if (FAILED(hr)){
		OutputErrorMessage(hwnd, hr, L"Could not create transparent buffer with error: ");
		return false;
	}

	ZeroMemory(&samplerDesc, sizeof(samplerDesc));
	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
	samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.MipLODBias = 0.0f;
	samplerDesc.MaxAnisotropy = 1;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
	samplerDesc.BorderColor[0] = 0;
	samplerDesc.BorderColor[1] = 1;
	samplerDesc.BorderColor[2] = 2;
	samplerDesc.BorderColor[3] = 3;
	samplerDesc.MinLOD = 0;
	samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
	hr = device->CreateSamplerState(&samplerDesc, &m_sampleState);
	if (FAILED(hr)){
		OutputErrorMessage(hwnd, hr, L"Could not create sampler state with error: ");
		return false;
	}

	return true;
}
bool AssetBuilder::BuildAsset(const char* i_path_assetsToBuild)
{
	//-------------------------------
	bool wereThereErrors = false;

	// Load and execute the build script
	{
		std::string path;
		{
			std::string scriptDir;
			std::string errorMessage;
			if (GetAssetBuilderEnvironmentVariable("ScriptDir", scriptDir))
			{
				path = scriptDir + "BuildAssets.lua";
			}
			else
			{
				wereThereErrors = true;
				OutputErrorMessage(errorMessage.c_str());
				goto OnExit;
			}
		}
		// Load the script
		const int result = luaL_loadfile(mluaState, path.c_str());
		if (result == LUA_OK)
		{
			// Execute it with the asset list path as an argument
			const int argumentCount = 1;
			{
				lua_pushstring(mluaState, i_path_assetsToBuild);
			}
			// The return value should be true (on success) or false (on failure)
			const int returnValueCount = 1;
			const int noMessageHandler = 0;
			if (lua_pcall(mluaState, argumentCount, returnValueCount, noMessageHandler) == LUA_OK)
			{
				// Note that lua_toboolean() follows the same rules as if something then statements in Lua:
				// false or nil will evaluate to false, and anything else will evaluate to true
				// (this means that if the script doesn't return anything it will result in a build failure)
				wereThereErrors = !lua_toboolean(mluaState, -1);
				lua_pop(mluaState, returnValueCount);
			}
			else
			{
				wereThereErrors = true;

				const char* errorMessage = lua_tostring(mluaState, -1);
				std::cerr << errorMessage << "\n";
				lua_pop(mluaState, 1);

				goto OnExit;
			}
		}
		else
		{
			wereThereErrors = true;

			const char* errorMessage = lua_tostring(mluaState, -1);
			std::cerr << errorMessage << "\n";
			lua_pop(mluaState, 1);

			goto OnExit;
		}
	}

OnExit:

	return !wereThereErrors;
}
bool eae6320::AssetBuilder::BuildAssets()
{
	bool wereThereErrors = false;
	std::string scriptDir;

	if ( !Initialize() )
	{
		wereThereErrors = true;
		goto OnExit;
	}

	// Get $(ScriptDir)
	{
		std::string errorMessage;
		if ( !GetEnvironmentVariable( "ScriptDir", scriptDir, &errorMessage ) )
		{
			wereThereErrors = true;
			OutputErrorMessage( errorMessage.c_str(), __FILE__ );
			goto OnExit;
		}
	}
	// Load and execute the build script
	{
		// Load the script
		const std::string path_buildScript = scriptDir + "BuildAssets.lua";
		const int result = luaL_loadfile( s_luaState, path_buildScript.c_str() );
		if ( result == LUA_OK )
		{
			// Execute it with the asset list path as an argument
			const int argumentCount = 1;
			{
				const std::string path_assetsToBuild = scriptDir + "AssetsToBuild.lua";
				lua_pushstring( s_luaState, path_assetsToBuild.c_str() );
			}
			// The return value should be true (on success) or false (on failure)
			const int returnValueCount = 1;
			const int noMessageHandler = 0;
			if ( lua_pcall( s_luaState, argumentCount, returnValueCount, noMessageHandler ) == LUA_OK )
			{
				// Note that lua_toboolean() follows the same rules as if something then statements in Lua:
				// false or nil will evaluate to false, and anything else will evaluate to true
				// (this means that if the script doesn't return anything it will result in a build failure)
				wereThereErrors = !lua_toboolean( s_luaState, -1 );
				lua_pop( s_luaState, returnValueCount );
			}
			else
			{
				wereThereErrors = true;

				const char* errorMessage = lua_tostring( s_luaState, -1 );
				std::cerr << errorMessage << "\n";
				lua_pop( s_luaState, 1 );

				goto OnExit;
			}
		}
		else
		{
			wereThereErrors = true;

			const char* errorMessage = lua_tostring( s_luaState, -1 );
			std::cerr << errorMessage << "\n";
			lua_pop( s_luaState, 1 );

			goto OnExit;
		}
	}

OnExit:

	if ( !ShutDown() )
	{
		wereThereErrors = true;
	}

	return !wereThereErrors;
}
Example #10
0
    //--------------------------------------------------------------------------------
    /// @brief      作成
    /// @param[in]  hInst           アプリケーションインスタンス
    /// @param[in]  clientWidth     クライアント領域の幅
    /// @param[in]  clientHeight    クライアント領域の高さ
    /// @param[in]  pTitle          ウィンドウタイトル
    /// @param[in]  isWindow        ウィンドウモードかどうか
    /// @retval     S_OK    成功
    /// @retval     E_FAIL  失敗
    //--------------------------------------------------------------------------------
    HRESULT Window::Create( HINSTANCE hInst, const wchar_t* pClassName, int clientWidth, int clientHeight, const wchar_t* pTitle, bool isWindow )
    {
        WNDCLASSEX wc;

        //ウィンドウクラスの定義
        wc.cbSize        = sizeof( WNDCLASSEX );                //構造体のサイズ
        wc.style         = NULL;                                //スタイル
        wc.lpfnWndProc   = _WndProc;                            //ウインドウ関数
        wc.cbClsExtra    = 0;                                   //エキストラクラス情報 
        wc.cbWndExtra    = 0;                                   //エキストラウィンドウ情報
        wc.hInstance     = hInst;                               //インスタンスハンドル
        wc.hIcon         = LoadIcon( NULL, IDI_APPLICATION );   //ラージアイコン
        wc.hIconSm       = LoadIcon( NULL, IDI_WINLOGO );       //スモールアイコン 
        //wc.hIcon         = (HICON)LoadImage( NULL, "Resource/Texture/icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE );    //ラージアイコン
        //wc.hIconSm       = (HICON)LoadImage( NULL, "Resource/Texture/icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE );    //スモールアイコン 
        wc.hCursor       = LoadCursor( NULL, IDC_ARROW );       //マウスカーソル
        wc.hbrBackground = NULL;                                //背景色 
        wc.lpszMenuName  = NULL;                                //メインメニュー名
        wc.lpszClassName = pClassName;                          //ウィンドウクラス名

        //ウィンドウクラスの登録
        if( RegisterClassEx( &wc ) == 0 )
        {
            OutputErrorMessage( L"ウィンドウクラスの登録に失敗しました。" );
            return E_FAIL;
        }

        // ウィンドウモードなら
        if( isWindow )
        {
            // ウィンドウスタイルの設定
            DWORD style = WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX;

            // ウィンドウサイズを計算
            RECT rect;
            rect.top    = 0;
            rect.left   = 0;
            rect.right  = clientWidth;
            rect.bottom = clientHeight;
            AdjustWindowRect( &rect, style, FALSE );

            int width  = rect.right - rect.left;
            int height = rect.bottom - rect.top;

            // ウィンドウ位置の計算
            int x;
            int y;

            x = (GetSystemMetrics( SM_CXFULLSCREEN ) - width ) / 2;
            y = (GetSystemMetrics( SM_CYFULLSCREEN ) - height) / 2;

            //ウィンドウの作成
            m_hWnd = CreateWindow(
                pClassName,         // 作成するウィンドウ名
                pTitle,             // ウィンドウのタイトル
                style,              // ウィンドウタイプ              
                x,                  // ウィンドウの位置(X座標)
                y,                  // ウィンドウの位置(Y座標)                      
                width,              // ウィンドウの幅
                height,             // ウィンドウの高さ          
                NULL,               // 親ウィンドウのハンドル
                NULL,               // メニューのハンドル
                hInst,              // インスタンスハンドル 
                NULL );             // 追加情報 
        }
        // フルスクリーンなら
        else
        {
            m_hWnd = CreateWindow( 
                pClassName,         // 登録されているクラス名
                pTitle,             // ウインドウ名
                WS_POPUP,           // ウインドウスタイル(ポップアップウインドウを作成)
                0,                  // ウインドウの横方向の位置
                0,                  // ウインドウの縦方向の位置
                clientWidth,        // ウインドウの幅
                clientHeight,       // ウインドウの高さ
                NULL,               // 親ウインドウのハンドル(省略)
                NULL,               // メニューや子ウインドウのハンドル
                hInst,              // アプリケーションインスタンスのハンドル
                NULL                // ウインドウの作成データ
                );
        }

        if ( m_hWnd == NULL )
        {
            OutputErrorMessage( L"ウィンドウの作成に失敗しました。" );
            return E_FAIL;
        }

        SetWindowLong( m_hWnd, GWL_USERDATA, reinterpret_cast<long>(this) );

        return S_OK;
    }
Example #11
0
bool cShaderBuilder::Build(const std::vector<const std::string>& i_arguments)
{
	// Get which shader program type to compile
	eShaderProgramType shaderProgramType = UNKNOWN;
	{
		if (i_arguments.size() >= 1)
		{
			const std::string& argument = i_arguments[0];
			if (argument == "vertex")
			{
				shaderProgramType = VERTEX;
				//printf("argument %s\n", argument.c_str());
			}
			else if (argument == "fragment")
			{
				shaderProgramType = FRAGMENT;
				//printf("argument %s\n", argument.c_str());
			}
			else
			{
				std::stringstream errorMessage;
				errorMessage << "\"" << argument << "\" is not a valid shader program type";
				OutputErrorMessage(errorMessage.str().c_str(), m_path_source);
				return false;
			}
		}
		else
		{
			OutputErrorMessage(
				"A Shader must be built with an argument defining which type of shader program (e.g. \"vertex\" or \"fragment\") to compile",
				m_path_source);
			return false;
		}
	}

	/*bool wereThereErrors = false;

	// Copy the source to the target
	{
		const bool dontFailIfTargetAlreadyExists = false;
		std::string errorMessage;
		if (!eae6320::CopyFile(m_path_source, m_path_target, dontFailIfTargetAlreadyExists))
		{
			wereThereErrors = true;
			std::stringstream decoratedErrorMessage;
			decoratedErrorMessage << "Windows failed to copy \"" << m_path_source << "\" to \"" << m_path_target << "\": " << errorMessage;
			eae6320::OutputErrorMessage(decoratedErrorMessage.str().c_str(), __FILE__);
		}
	}

	return !wereThereErrors;*/
	// Get the path to the shader compiler
	std::string path_fxc;
	{
		// Get the path to the DirectX SDK
		std::string path_sdk;
		{
			std::string errorMessage;
			if (!GetEnvironmentVariable("DXSDK_DIR", path_sdk, &errorMessage))
			{
				std::stringstream decoratedErrorMessage;
				decoratedErrorMessage << "Windows failed to get the path to the DirectX SDK: " << errorMessage;
				OutputErrorMessage(decoratedErrorMessage.str().c_str(), __FILE__);
				return false;
			}
		}
		path_fxc = path_sdk + "Utilities/bin/" +
#ifndef _WIN64
			"x86"
#else
			"x64"
#endif
			+ "/fxc.exe";
	}
	// Create the command to run
	std::string command;
	{
		std::stringstream commandToBuild;
		commandToBuild << "\"" << path_fxc << "\"";
		// Target profile
		switch (shaderProgramType)
		{
		case VERTEX:
			commandToBuild << " /Tvs_3_0";
			break;
		case FRAGMENT:
			commandToBuild << " /Tps_3_0";
			break;
		}
		// Entry point
		commandToBuild << " /Emain"
#ifdef _DEBUG
			// Disable optimizations so that debugging is easier
			<< " /Od"
			// Enable debugging
			<< " /Zi"
#endif
			// Target file
			<< " /Fo\"" << m_path_target << "\""
			// Don't output the logo
			<< " /nologo"
			// Source file
			<< " \"" << m_path_source << "\""
			;
		command = commandToBuild.str();
	}
	// Execute the command
	{
		DWORD exitCode;
		std::string errorMessage;
		if (ExecuteCommand(command.c_str(), &exitCode, &errorMessage))
		{
			return exitCode == EXIT_SUCCESS;
		}
		else
		{
			OutputErrorMessage(errorMessage.c_str(), m_path_source);
			return false;
		}
	}
}