Example #1
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	// 載入Vertex Shader
	g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/VertexCompression_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
	if ( NULL==g_pVertexShader )
		return false;
	// 載入Pixel Shader
	g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/VertexCompression_dx10.hlsl", "PS", "ps_4_0");
	if ( NULL==g_pPixelShader )
		return false;

	// 設定Vertex資料格式
	D3D10_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, D3D10_INPUT_PER_VERTEX_DATA, 0 }
	};
	if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
		return false;

	SAFE_RELEASE(pVSCode);

	// 拷備模型資料
	g_pVertexBuffer = GutCreateVertexBuffer_DX10(sizeof(CompressedVertex) * g_iNumSphereVertices, g_pCompressedVertices);
	g_pIndexBuffer = GutCreateIndexBuffer_DX10(sizeof(unsigned short) * g_iNumSphereIndices, g_pSphereIndices);
	g_pConstantBuffer = GutCreateShaderConstant_DX10(sizeof(Matrix4x4)*2);

	// 投影矩陣
	g_proj_matrix = GutMatrixPerspectiveRH_DirectX(90.0f, 1.0f, 0.1f, 100.0f);

	return true;
}
Example #2
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	// 載入Vertex Shader
	g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/vertex_color_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
	if ( NULL==g_pVertexShader )
		return false;
	// 載入Pixel Shader
	g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/vertex_color_dx10.hlsl", "PS", "ps_4_0");
	if ( NULL==g_pPixelShader )
		return false;

	// 設定Vertex資料格式
	D3D10_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
	};

	if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
		return false;

	SAFE_RELEASE(pVSCode);

	D3D10_BUFFER_DESC cbDesc;
	// sun vertex buffer
	cbDesc.ByteWidth = sizeof(Vertex_VC) * g_iNumSphereVertices;
	cbDesc.Usage = D3D10_USAGE_IMMUTABLE;
	cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	cbDesc.CPUAccessFlags = 0;
	cbDesc.MiscFlags = 0;
	// 開啟Vertex Buffer時同時把資料拷貝過去
	D3D10_SUBRESOURCE_DATA sbDesc;
	sbDesc.pSysMem = g_pSunVertices;
	// 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &sbDesc, &g_pSunVertexBuffer ) )
		return false;

	// 開啟Vertex Buffer時同時把資料拷貝過去
	sbDesc.pSysMem = g_pEarthVertices;
	// 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &sbDesc, &g_pEarthVertexBuffer ) )
		return false;

	// 開啟Vertex Buffer時同時把資料拷貝過去
	sbDesc.pSysMem = g_pMoonVertices;
	// 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &sbDesc, &g_pMoonVertexBuffer ) )
		return false;

	// 設定一塊可以用來放Index的記憶體.
	cbDesc.ByteWidth = sizeof(unsigned short) * g_iNumSphereIndices;
	cbDesc.Usage = D3D10_USAGE_IMMUTABLE;
	cbDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
	cbDesc.CPUAccessFlags = 0;
	cbDesc.MiscFlags = 0;
	// 開啟Index Buffer時同時把資料拷貝過去
	sbDesc.pSysMem = g_pSphereIndices;
	// 配置一塊可以存放Index的記憶體, 也就是Index Buffer.
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &sbDesc, &g_pSphereIndexBuffer ) )
		return false;

	// 配置Shader讀取參數的記憶體空間
	cbDesc.ByteWidth = sizeof(Matrix4x4);
	cbDesc.Usage = D3D10_USAGE_DYNAMIC;
	cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
	cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
	cbDesc.MiscFlags = 0;
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer ) )
		return false;

	// 計算出一個可以轉換到鏡頭座標系的矩陣
	g_proj_matrix = GutMatrixPerspectiveRH_DirectX(90.0f, 1.0f, 0.1f, 100.0f);

	// 開?rasterizer state物件
	D3D10_RASTERIZER_DESC rasterizer_state_desc;

	rasterizer_state_desc.FillMode = D3D10_FILL_SOLID;
	rasterizer_state_desc.CullMode = D3D10_CULL_BACK;
	rasterizer_state_desc.FrontCounterClockwise = true;
	rasterizer_state_desc.DepthBias = 0;
	rasterizer_state_desc.DepthBiasClamp = 0.0f;
	rasterizer_state_desc.SlopeScaledDepthBias = 0.0f;
	rasterizer_state_desc.DepthClipEnable = false;
	rasterizer_state_desc.ScissorEnable = false;
	rasterizer_state_desc.MultisampleEnable = false;
	rasterizer_state_desc.AntialiasedLineEnable = false;

	if ( D3D_OK != g_pDevice->CreateRasterizerState(&rasterizer_state_desc, &g_pRasterizerState) )
		return false;

	g_pDevice->RSSetState(g_pRasterizerState);

	return true;
}
Example #3
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	{
		// 載入Vertex Shader
		g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/color_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
		if ( NULL==g_pVertexShader )
			return false;
		// 載入Pixel Shader
		g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/color_dx10.hlsl", "PS", "ps_4_0");
		if ( NULL==g_pPixelShader )
			return false;
	}

	CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");
	CGutModel::SetTexturePath("../../textures/");
	g_Model_DX10.ConvertToDX10Model(&g_Model);

	// 設定Vertex資料格式
	{
		D3D10_INPUT_ELEMENT_DESC layout[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		};

		if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
			return false;

		SAFE_RELEASE(pVSCode);
	}

	// 配置Shader讀取參數的記憶體空間
	{
		D3D10_BUFFER_DESC cbDesc;
		ZeroMemory(&cbDesc, sizeof(cbDesc));

		cbDesc.ByteWidth = sizeof(ShaderConstant);
		cbDesc.Usage = D3D10_USAGE_DYNAMIC;
		cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
		cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		cbDesc.MiscFlags = 0;

		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer ) )
			return false;
	}

	// 配置Vertex Buffer
	{
		D3D10_BUFFER_DESC cbDesc;
		ZeroMemory(&cbDesc, sizeof(cbDesc));

		cbDesc.ByteWidth = sizeof(Vertex_V) * 4;
		cbDesc.Usage = D3D10_USAGE_DYNAMIC ;
		cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
		cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		cbDesc.MiscFlags = 0;

		D3D10_SUBRESOURCE_DATA subDesc;
		ZeroMemory(&subDesc, sizeof(subDesc));
		subDesc.pSysMem = g_Quad;

		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBuffer ) )
			return false;
	}

	// rasterizer state物件
	{
		D3D10_RASTERIZER_DESC desc;

		GutSetDX10DefaultRasterizerDesc(desc);

		desc.CullMode = D3D10_CULL_NONE;
		desc.FrontCounterClockwise = true;

		if ( D3D_OK != g_pDevice->CreateRasterizerState(&desc, &g_pRasterizerNoCull) )
			return false;

		desc.CullMode = D3D10_CULL_BACK;
		desc.FrontCounterClockwise = true;

		if ( D3D_OK != g_pDevice->CreateRasterizerState(&desc, &g_pRasterizerCull) )
			return false;

		CGutModel_DX10::SetRasterizeState(g_pRasterizerCull, g_pRasterizerNoCull);

		g_pDevice->RSSetState(g_pRasterizerNoCull);
	}

	// depth stencil object
	{
		D3D10_DEPTH_STENCIL_DESC desc;
		GutSetDX10DefaultDepthStencilDesc(desc);

		desc.StencilEnable = TRUE;
		desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
		desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_INCR;
		desc.BackFace = desc.FrontFace;

		g_pDevice->CreateDepthStencilState(&desc, &g_pZStencil_Incr);

		desc.DepthFunc = D3D10_COMPARISON_ALWAYS;
		desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
		desc.FrontFace.StencilFunc = D3D10_COMPARISON_EQUAL;
		desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
		desc.BackFace = desc.FrontFace;

		g_pDevice->CreateDepthStencilState(&desc, &g_pZStencil_Test);

		desc.FrontFace.StencilFunc = D3D10_COMPARISON_LESS;
		desc.BackFace = desc.FrontFace;

		g_pDevice->CreateDepthStencilState(&desc, &g_pZStencil_Less);
	}

	// sampler state / texture filter
	{
		D3D10_SAMPLER_DESC sampler_desc;
		ZeroMemory(&sampler_desc, sizeof(sampler_desc));

		sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
		sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
		sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
		sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;

		g_pDevice->CreateSamplerState(&sampler_desc, &g_pSamplerState);

		for ( int i=0; i<4; i++ )
		{
			g_pDevice->PSSetSamplers(i, 1, &g_pSamplerState);
		}
	}

	// 投影矩陣
	g_proj_matrix = GutMatrixPerspectiveRH_DirectX(g_fFOV, 1.0f, 0.1f, 100.0f);

	return true;
}
Example #4
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	// 載入Vertex Shader
	g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/texture_dx10.shader", "VS", "vs_4_0", &pVSCode);
	if ( NULL==g_pVertexShader )
		return false;
	// 載入Pixel Shader
	g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/texture_dx10.shader", "PS", "ps_4_0");
	if ( NULL==g_pPixelShader )
		return false;

	if ( D3D_OK!=D3DX10CreateShaderResourceViewFromFile(g_pDevice, "../../textures/lena.bmp", NULL, NULL, &g_pTexture, NULL) )
		return false;

	// 設定Vertex資料格式
	D3D10_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
	};

	if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
		return false;

	SAFE_RELEASE(pVSCode);

	D3D10_BUFFER_DESC cbDesc;
	// vertex buffer
	cbDesc.ByteWidth = sizeof(Vertex_VT) * 4;
	cbDesc.Usage = D3D10_USAGE_DYNAMIC ;
	cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
	cbDesc.MiscFlags = 0;

	D3D10_SUBRESOURCE_DATA subDesc;
	ZeroMemory(&subDesc, sizeof(subDesc));
	subDesc.pSysMem = g_Quad;
	// 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBuffer ) )
		return false;

	// 配置Shader參數的記憶體空間
	cbDesc.ByteWidth = sizeof(Matrix4x4);
	cbDesc.Usage = D3D10_USAGE_DYNAMIC;
	cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
	cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
	cbDesc.MiscFlags = 0;
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer ) )
		return false;

	// 計算投影矩陣
	g_proj_matrix = GutMatrixPerspectiveRH_DirectX(g_fFovW, 1.0f, 0.1f, 100.0f);

	// rasterizer state物件
	{
		D3D10_RASTERIZER_DESC desc;
		GutSetDX10DefaultRasterizerDesc(desc);

		desc.CullMode = D3D10_CULL_NONE;
		desc.FrontCounterClockwise = true;
		desc.ScissorEnable = true;

		if ( D3D_OK != g_pDevice->CreateRasterizerState(&desc, &g_pRasterizerState) )
			return false;

		g_pDevice->RSSetState(g_pRasterizerState);
	}

	g_view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);

	return true;
}
Example #5
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	// 載入Vertex Shader
	g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/texture_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
	if ( NULL==g_pVertexShader )
		return false;
	// 載入Pixel Shader
	g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/texture_dx10.hlsl", "PS", "ps_4_0");
	if ( NULL==g_pPixelShader )
		return false;

	CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");

	CGutModel::SetTexturePath("../../textures/");
	g_Model_DX10.ConvertToDX10Model(&g_Model);

	// 設定Vertex資料格式
	D3D10_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0 }
	};

	if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), 
		pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
		return false;

	SAFE_RELEASE(pVSCode);

	D3D10_BUFFER_DESC cbDesc;
	ZeroMemory(&cbDesc, sizeof(cbDesc));

	// 配置Vertex Buffer
	{
		cbDesc.ByteWidth = sizeof(Vertex_VT) * 4;
		cbDesc.Usage = D3D10_USAGE_DYNAMIC ;
		cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
		cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		cbDesc.MiscFlags = 0;

		D3D10_SUBRESOURCE_DATA subDesc;
		ZeroMemory(&subDesc, sizeof(subDesc));
		subDesc.pSysMem = g_Quad;

		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBuffer ) )
			return false;
	}

	// 配置Vertex Shader 常數記憶體
	{
		cbDesc.ByteWidth = sizeof(Matrix4x4);
		cbDesc.Usage = D3D10_USAGE_DYNAMIC;
		cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
		cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		cbDesc.MiscFlags = 0;

		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pVSConstBuffer ) )
			return false;
	}

	// 配置RGBA動態貼圖
	{
		D3D10_TEXTURE2D_DESC dstex;
		dstex.Width = 512;
		dstex.Height = 512;
		dstex.MipLevels = 1;
		dstex.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		dstex.SampleDesc.Count = 1;
		dstex.SampleDesc.Quality = 0;
		dstex.Usage = D3D10_USAGE_DEFAULT;
		dstex.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
		dstex.CPUAccessFlags = 0;
		dstex.MiscFlags = 0;
		dstex.ArraySize = 1;

		g_pDevice->CreateTexture2D( &dstex, NULL, &g_pTexture );

		D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc;
		ZeroMemory( &SRVDesc, sizeof(SRVDesc) );
		SRVDesc.Format = dstex.Format;
		SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
		SRVDesc.Texture2D.MipLevels = 1;
		// for shader
		g_pDevice->CreateShaderResourceView(g_pTexture, &SRVDesc, &g_pTextureView);

		D3D10_RENDER_TARGET_VIEW_DESC DescRT;
		DescRT.Format = dstex.Format;
		DescRT.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
		DescRT.Texture2D.MipSlice = 0;
		// for rendertarget
		g_pDevice->CreateRenderTargetView(g_pTexture, &DescRT, &g_pRGBAView);
	}

	// 配置DepthStencil動態貼圖
	{
		D3D10_TEXTURE2D_DESC desc;
		ZeroMemory( &desc, sizeof(desc) );

		desc.Width =  512;
		desc.Height =  512;
		desc.MipLevels = 1;
		desc.ArraySize = 1;
		desc.SampleDesc.Count = 1;
		desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
		desc.Usage = D3D10_USAGE_DEFAULT;
		desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;

		g_pDevice->CreateTexture2D( &desc, NULL, &g_pDepthStencilTexture );

		D3D10_DEPTH_STENCIL_VIEW_DESC target_desc;
		ZeroMemory( &target_desc, sizeof(target_desc) );

		target_desc.Format = desc.Format;
		target_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
		target_desc.Texture2D.MipSlice = 0;

		g_pDevice->CreateDepthStencilView(g_pDepthStencilTexture, &target_desc, &g_pDepthStencilView);
	}

	// Rasterizer State物件
	{
		D3D10_RASTERIZER_DESC rasterizer_state_desc;

		rasterizer_state_desc.FillMode = D3D10_FILL_SOLID;
		//rasterizer_state_desc.CullMode = D3D10_CULL_BACK;
		rasterizer_state_desc.CullMode = D3D10_CULL_NONE;
		rasterizer_state_desc.FrontCounterClockwise = true;
		rasterizer_state_desc.DepthBias = 0;
		rasterizer_state_desc.DepthBiasClamp = 0.0f;
		rasterizer_state_desc.SlopeScaledDepthBias = 0.0f;
		rasterizer_state_desc.DepthClipEnable = false;
		rasterizer_state_desc.ScissorEnable = false;
		rasterizer_state_desc.MultisampleEnable = false;
		rasterizer_state_desc.AntialiasedLineEnable = false;

		if ( D3D_OK != g_pDevice->CreateRasterizerState(&rasterizer_state_desc, &g_pRasterizerState) )
			return false;

		g_pDevice->RSSetState(g_pRasterizerState);
	}

	// sampler state / texture filter
	{
		D3D10_SAMPLER_DESC sampler_desc;
		ZeroMemory(&sampler_desc, sizeof(sampler_desc));

		sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
		sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
		sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
		sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;

		g_pDevice->CreateSamplerState(&sampler_desc, &g_pSamplerState);

		for ( int i=0; i<4; i++ )
		{
			g_pDevice->PSSetSamplers(i, 1, &g_pSamplerState);
		}
	}

	// 投影矩陣
	g_proj_matrix = GutMatrixPerspectiveRH_DirectX(g_fFOV, 1.0f, 0.1f, 100.0f);

	return true;
}
Example #6
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	// 載入Vertex Shader
	g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/texture_alphatest_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
	if ( NULL==g_pVertexShader )
		return false;
	// 載入Pixel Shader
	g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/texture_alphatest_dx10.hlsl", "PS", "ps_4_0");
	if ( NULL==g_pPixelShader )
		return false;

	g_pTexture0 = GutLoadTexture_DX10("../../textures/brickwall_broken.tga");
	g_pTexture1 = GutLoadTexture_DX10("../../textures/spotlight_effect.tga");
	if ( g_pTexture0==NULL || g_pTexture1==NULL )
		return false;

	// 設定Vertex資料格式
	D3D10_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
	};

	if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
		return false;

	SAFE_RELEASE(pVSCode);

	D3D10_BUFFER_DESC cbDesc;

	// vertex buffer
	{
		cbDesc.ByteWidth = sizeof(Vertex_VT) * 4;
		cbDesc.Usage = D3D10_USAGE_DYNAMIC ;
		cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
		cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		cbDesc.MiscFlags = 0;

		D3D10_SUBRESOURCE_DATA subDesc;
		ZeroMemory(&subDesc, sizeof(subDesc));
		subDesc.pSysMem = g_Quad;
		// 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBuffer ) )
			return false;
	}

	// 配置Shader參數的記憶體空間
	{
		cbDesc.ByteWidth = sizeof(Matrix4x4);
		cbDesc.Usage = D3D10_USAGE_DYNAMIC;
		cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
		cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		cbDesc.MiscFlags = 0;
		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer ) )
			return false;
	}

	// rasterizer state物件
	{
		D3D10_RASTERIZER_DESC desc;
		GutSetDX10DefaultRasterizerDesc(desc);

		desc.CullMode = D3D10_CULL_NONE;
		desc.FrontCounterClockwise = true;

		if ( D3D_OK != g_pDevice->CreateRasterizerState(&desc, &g_pRasterizerState) )
			return false;

		g_pDevice->RSSetState(g_pRasterizerState);
	}

	// depth stencil state
	{
		D3D10_DEPTH_STENCIL_DESC desc;
		GutSetDX10DefaultDepthStencilDesc(desc);

		desc.DepthEnable = FALSE;
		desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
		desc.DepthFunc = D3D10_COMPARISON_ALWAYS;

		desc.StencilEnable = TRUE;
		desc.StencilReadMask = 0xff;
		desc.StencilWriteMask = 0xff;

		desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
		desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
		desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_REPLACE;
		desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;

		desc.BackFace = desc.FrontFace;
		// 這個設定用來設定像素的stencil值
		g_pDevice->CreateDepthStencilState(&desc, &g_pStencilState_Replace);

		desc.FrontFace.StencilFunc = D3D10_COMPARISON_EQUAL;
		desc.BackFace = desc.FrontFace;
		// 這個設定用來做stencil test測試
		g_pDevice->CreateDepthStencilState(&desc, &g_pStencilState_Test);
	}

	// blend state
	{
		D3D10_BLEND_DESC desc;
		GutSetDX10DefaultBlendDesc(desc);

		desc.BlendEnable[0] = TRUE;

		desc.SrcBlend = D3D10_BLEND_ONE;
		desc.DestBlend = D3D10_BLEND_ONE;
		desc.BlendOp = D3D10_BLEND_OP_ADD;

		desc.SrcBlendAlpha = D3D10_BLEND_ONE;
		desc.DestBlendAlpha = D3D10_BLEND_ONE;
		desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;

		g_pDevice->CreateBlendState(&desc, &g_pBlendState);
	}

	// sampler state / texture filter
	{
		D3D10_SAMPLER_DESC desc;
		GutSetDX10DefaultSamplerDesc(desc);

		desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
		desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
		desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
		desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;

		g_pDevice->CreateSamplerState(&desc, &g_pSamplerState);

		for ( int i=0; i<4; i++ )
		{
			g_pDevice->PSSetSamplers(i, 1, &g_pSamplerState);
		}
	}

	// 計算投影矩陣
	g_view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
	g_proj_matrix = GutMatrixOrthoRH_DirectX(g_fOrthoWidth, g_fOrthoHeight, 0.1f, 100.0f);

	return true;
}
Example #7
0
bool CGutFontDX10::LoadShader(const char *filename)
{
	ID3D10Device *pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	// 載入Vertex Shader
	m_pVertexShader = GutLoadVertexShaderDX10_HLSL(filename, "VS", "vs_4_0", &pVSCode);
	if ( NULL==m_pVertexShader )
		return false;
	// 載入Pixel Shader
	m_pPixelShader = GutLoadPixelShaderDX10_HLSL(filename, "PS", "ps_4_0");
	if ( NULL==m_pPixelShader )
		return false;

	// Shader常數的記憶體空間
	{
		D3D10_BUFFER_DESC desc;
		//
		desc.ByteWidth = sizeof(Matrix4x4);
		desc.Usage = D3D10_USAGE_DYNAMIC;
		desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
		desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		desc.MiscFlags = 0;
		if ( D3D_OK != pDevice->CreateBuffer( &desc, NULL, &m_pShaderConstant ) )
			return false;
	}

	int max_characters = m_iNumRows * m_iNumColumns;

	// vertex buffer
	{
		D3D10_BUFFER_DESC desc;

		desc.ByteWidth = max_characters * sizeof(_FontVertex) * 4;
		desc.Usage = D3D10_USAGE_DYNAMIC ;
		desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
		desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		desc.MiscFlags = 0;

		if ( D3D_OK != pDevice->CreateBuffer( &desc, NULL, &m_pVertexBuffer ) )
			return false;
	}
	// index buffer
	{
		D3D10_BUFFER_DESC desc;

		desc.ByteWidth = max_characters * 6 * sizeof(short);
		desc.Usage = D3D10_USAGE_DYNAMIC;
		desc.BindFlags = D3D10_BIND_INDEX_BUFFER;
		desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		desc.MiscFlags = 0;

		D3D10_SUBRESOURCE_DATA subDesc;
		ZeroMemory(&subDesc, sizeof(subDesc));
		subDesc.pSysMem = m_pIndexArray;

		if ( D3D_OK != pDevice->CreateBuffer( &desc, &subDesc, &m_pIndexBuffer ) )
			return false;
	}
	// rasterizer state物件
	{
		D3D10_RASTERIZER_DESC desc;
		GutSetDX10DefaultRasterizerDesc(desc);

		desc.CullMode = D3D10_CULL_NONE;

		if ( D3D_OK != pDevice->CreateRasterizerState(&desc, &m_pRasterizerState) )
			return false;
	}
	// 設定Vertex資料格式
	{
		D3D10_INPUT_ELEMENT_DESC layout[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0,12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
		};
		//
		if ( D3D_OK != pDevice->CreateInputLayout(layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &m_pVertexLayout ) )
			return false;
	}

	return true;
}
Example #8
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	g_pTexture = GutLoadTexture_DX10("../../textures/space.tga", &g_ImageInfo);
	if ( NULL==g_pTexture )
		return false;

	// 載入Vertex Shader
	{
		g_pBlurVS = GutLoadVertexShaderDX10_HLSL("../../shaders/Posteffect_blur_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
		g_pBlurPS = GutLoadPixelShaderDX10_HLSL("../../shaders/Posteffect_blur_dx10.hlsl", "PS", "ps_4_0");
		g_pBrightnessPS = GutLoadPixelShaderDX10_HLSL("../../shaders/Posteffect_brightness_dx10.hlsl", "PS", "ps_4_0");
		g_pRGBAPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/texture_dx10.hlsl", "PS", "ps_4_0");

		if ( NULL==g_pBlurVS || NULL==g_pBlurPS ||
			NULL==g_pRGBAPixelShader || NULL==g_pBrightnessPS )
			return false;
	}

	// 設定Vertex資料格式
	{
		D3D10_INPUT_ELEMENT_DESC layout[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
		};

		if ( D3D_OK != g_pDevice->CreateInputLayout( layout, 2, pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
			return false;

		SAFE_RELEASE(pVSCode);
	}

	g_pVertexBuffer = GutCreateVertexBuffer_DX10(sizeof(Vertex_VT)*4, g_FullScreenQuad);

	Matrix4x4 ident_mat; ident_mat.Identity();

	g_pVSConstantBuffer = GutCreateShaderConstant_DX10(sizeof(Matrix4x4), &ident_mat);
	g_pBlurConstantBuffer = GutCreateShaderConstant_DX10(sizeof(Vector4)*9);
	g_pBrightnessConstantBuffer = GutCreateShaderConstant_DX10(sizeof(Vector4)*2);

	int w = g_ImageInfo.m_iWidth/4;
	int h = g_ImageInfo.m_iHeight/4;

	if ( !GutCreateRenderTarget_DX10(w, h, 
		DXGI_FORMAT_R8G8B8A8_UNORM, &g_pFrameTexture[0], &g_pFrameSRView[0], &g_pFrameRTView[0]) )
		return false;

	if ( !GutCreateRenderTarget_DX10(w, h,
		DXGI_FORMAT_R8G8B8A8_UNORM, &g_pFrameTexture[1], &g_pFrameSRView[1], &g_pFrameRTView[1]) )
		return false;

	{
		D3D10_RASTERIZER_DESC desc;
		GutSetDX10DefaultRasterizerDesc(desc);
		desc.CullMode = D3D10_CULL_NONE;

		g_pDevice->CreateRasterizerState(&desc, &g_pNoCull);
		g_pDevice->RSSetState(g_pNoCull);
	}

	{
		D3D10_BLEND_DESC desc;
		GutSetDX10DefaultBlendDesc(desc);

		g_pDevice->CreateBlendState(&desc, &g_pNoBlend);

		desc.BlendEnable[0] = TRUE;
		desc.SrcBlend = D3D10_BLEND_ONE;
		desc.DestBlend = D3D10_BLEND_ONE;

		g_pDevice->CreateBlendState(&desc, &g_pAddBlend);
	}

	{
		D3D10_DEPTH_STENCIL_DESC desc;
		GutSetDX10DefaultDepthStencilDesc(desc);

		desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
		desc.DepthEnable = FALSE;

		g_pDevice->CreateDepthStencilState(&desc, &g_pNoZWrite);
		g_pDevice->OMSetDepthStencilState(g_pNoZWrite, 0);
	}

	return true;
}
Example #9
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	// shader loading
	{
		const char *shaders = "../../shaders/cubemap_photovr_dx10.hlsl";
		// 載入Vertex Shader
		g_pVertexShader = GutLoadVertexShaderDX10_HLSL(shaders, "VS", "vs_4_0", &pVSCode);
		if ( NULL==g_pVertexShader )
			return false;
		// 載入Pixel Shader
		g_pPixelShader = GutLoadPixelShaderDX10_HLSL(shaders, "PS", "ps_4_0");
		if ( NULL==g_pPixelShader )
			return false;
	}

	// 載入貼圖
	{
		const char *texture_array[] = 
		{
			"../../textures/uffizi_right.tga",
			"../../textures/uffizi_left.tga",
			"../../textures/uffizi_top.tga",
			"../../textures/uffizi_bottom.tga",
			"../../textures/uffizi_back.tga", // `右手座標系上 Z+ 為鏡頭後方.`
			"../../textures/uffizi_front.tga" // `右手座標系上 Z- 為鏡頭前方.`
		};

		g_pTexture = GutLoadCubemapTexture_DX10(texture_array);
	}

	{
		// 設定Vertex資料格式
		D3D10_INPUT_ELEMENT_DESC layout[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
			{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		};

		if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
			return false;

		SAFE_RELEASE(pVSCode);
	}

	D3D10_BUFFER_DESC cbDesc;
	D3D10_SUBRESOURCE_DATA subDesc;

	{
		// vertex buffer
		ZeroMemory(&cbDesc, sizeof(cbDesc));
		cbDesc.ByteWidth = sizeof(Vertex_VN) * g_iNumSphereVertices;
		cbDesc.Usage = D3D10_USAGE_IMMUTABLE;
		cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
		// 開啟Vertex Buffer時同時把資料拷貝過去
		ZeroMemory(&subDesc, sizeof(subDesc));
		subDesc.pSysMem = g_pSphereVertices;
		// 配置Vertex Buffer.
		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBuffer ) )
			return false;
	}

	{
		// 設定一塊可以用來放Index的記憶體.
		ZeroMemory(&cbDesc, sizeof(cbDesc));
		cbDesc.ByteWidth = sizeof(unsigned short) * g_iNumSphereIndices;
		cbDesc.Usage = D3D10_USAGE_IMMUTABLE;
		cbDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
		// 開啟Index Buffer時同時把資料拷貝過去
		ZeroMemory(&subDesc, sizeof(subDesc));
		subDesc.pSysMem = g_pSphereIndices;
		// 配置Index Buffer.
		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pSphereIndexBuffer ) )
			return false;
	}

	{
		ZeroMemory(&cbDesc, sizeof(cbDesc));
		// 配置Shader參數的記憶體空間
		cbDesc.ByteWidth = sizeof(Matrix4x4);
		cbDesc.Usage = D3D10_USAGE_DYNAMIC;
		cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
		cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		// 配置Shader Constant
		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer ) )
			return false;
	}

	// rasterizer state物件
	{
		D3D10_RASTERIZER_DESC rs;
		ZeroMemory(&rs, sizeof(rs));

		rs.FillMode = D3D10_FILL_SOLID;
		rs.CullMode = D3D10_CULL_NONE;
		rs.FrontCounterClockwise = true;
		rs.DepthBias = 0;
		rs.DepthBiasClamp = 0.0f;
		rs.SlopeScaledDepthBias = 0.0f;
		rs.DepthClipEnable = false;
		rs.ScissorEnable = false;
		rs.MultisampleEnable = false;
		rs.AntialiasedLineEnable = false;

		if ( D3D_OK != g_pDevice->CreateRasterizerState(&rs, &g_pRasterizerState) )
			return false;

		g_pDevice->RSSetState(g_pRasterizerState);
	}

	// 計算投影矩陣
	g_proj_matrix = GutMatrixPerspectiveRH_DirectX(g_fFovW, 1.0f, 0.1f, 100.0f);

	return true;
}
Example #10
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	// 載入Vertex Shader.
	g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/vertex_transform_dx10.shader", "VS", "vs_4_0", &pVSCode);
	if ( NULL==g_pVertexShader )
		return false;
	// 載入Pixel Shader.
	g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/vertex_transform_dx10.shader", "PS", "ps_4_0");
	if ( NULL==g_pPixelShader )
		return false;

	// 設定Vertex資料格式.
	D3D10_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
	};

	if ( D3D_OK != g_pDevice->CreateInputLayout( layout, 1, pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
		return false;

	SAFE_RELEASE(pVSCode);

	// 設定一塊可以用來放Vertex的記憶體.
	D3D10_BUFFER_DESC cbDesc;
	cbDesc.ByteWidth = sizeof(g_vertices);
	cbDesc.Usage = D3D10_USAGE_DYNAMIC;
	cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
	cbDesc.MiscFlags = 0;

	// 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pVertexBuffer ) )
		return false;

	// 把資料拷貝到顯示卡記憶體的Vertex Buffer.
	Vector4 *pVertexBuffer;
	g_pVertexBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pVertexBuffer );
	memcpy(pVertexBuffer, g_vertices, sizeof(g_vertices));
	g_pVertexBuffer->Unmap();

	// 配置Shader讀取參數的記憶體空間.
	cbDesc.ByteWidth = sizeof(Matrix4x4);
	cbDesc.Usage = D3D10_USAGE_DYNAMIC;
	cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
	cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
	cbDesc.MiscFlags = 0;
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer ) )
		return false;

	// 計算出一個可以轉換到鏡頭座標系的矩陣.
	Matrix4x4 view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
	Matrix4x4 projection_matrix = GutMatrixPerspectiveRH_DirectX(90.0f, 1.0f, 1.0f, 100.0f);
	Matrix4x4 view_projection_matrix = view_matrix * projection_matrix;

	// 把矩陣拷貝到shader參數區的記憶體空間.
	Matrix4x4 *pConstData;
	g_pConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstData );
	*pConstData = view_projection_matrix;
	g_pConstantBuffer->Unmap();

	return true;
}
Example #11
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	// 載入Vertex Shader
	g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/vertex_color_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
	if ( NULL==g_pVertexShader )
		return false;
	// 載入Pixel Shader
	g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/vertex_color_dx10.hlsl", "PS", "ps_4_0");
	if ( NULL==g_pPixelShader )
		return false;

	CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");
	for ( int i=0; i<3; i++ )
	{
		g_Model_DX10[i].ConvertToDX10Model(&g_Models[i]);
	}

	// 設定Vertex資料格式
	D3D10_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
	};

	if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
		return false;

	SAFE_RELEASE(pVSCode);

	//
	g_pBorderVertexBuffer = GutCreateVertexBuffer_DX10(sizeof(g_Border), g_Border);
	// 配置Shader讀取參數的記憶體空間
	g_pConstantBuffer = GutCreateShaderConstant_DX10(sizeof(Matrix4x4));

	// 計算出一個可以轉換到鏡頭座標系的矩陣
	g_proj_matrix = GutMatrixPerspectiveRH_DirectX(70.0f, 1.0f, 0.1f, 100.0f);

	// 開?rasterizer state物件
	D3D10_RASTERIZER_DESC rasterizer_state_desc;

	rasterizer_state_desc.FillMode = D3D10_FILL_SOLID;
	rasterizer_state_desc.CullMode = D3D10_CULL_BACK;
	rasterizer_state_desc.FrontCounterClockwise = true;
	rasterizer_state_desc.DepthBias = 0;
	rasterizer_state_desc.DepthBiasClamp = 0.0f;
	rasterizer_state_desc.SlopeScaledDepthBias = 0.0f;
	rasterizer_state_desc.DepthClipEnable = false;
	rasterizer_state_desc.ScissorEnable = false;
	rasterizer_state_desc.MultisampleEnable = false;
	rasterizer_state_desc.AntialiasedLineEnable = false;

	if ( D3D_OK != g_pDevice->CreateRasterizerState(&rasterizer_state_desc, &g_pRasterizerState) )
		return false;

	g_pDevice->RSSetState(g_pRasterizerState);

	return true;
}
Example #12
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	const char *shader = "../../shaders/texture_dx10.hlsl";
	// 載入Vertex Shader
	g_pVertexShader = GutLoadVertexShaderDX10_HLSL(shader, "VS", "vs_4_0", &pVSCode);
	if ( NULL==g_pVertexShader )
		return false;
	// 載入Pixel Shader
	g_pPixelShader = GutLoadPixelShaderDX10_HLSL(shader, "PS", "ps_4_0");
	if ( NULL==g_pPixelShader )
		return false;

	g_pTexture0 = GutLoadTexture_DX10("../../textures/brickwall.tga");
	g_pTexture1 = GutLoadTexture_DX10("../../textures/spotlight_effect.tga");

	if ( g_pTexture0==NULL || g_pTexture1==NULL )
		return false;

	// 設定Vertex資料格式
	D3D10_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
	};

	if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
		return false;

	SAFE_RELEASE(pVSCode);

	D3D10_BUFFER_DESC cbDesc;
	// vertex buffer
	cbDesc.ByteWidth = sizeof(Vertex_VT) * 4;
	cbDesc.Usage = D3D10_USAGE_DYNAMIC ;
	cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
	cbDesc.MiscFlags = 0;

	D3D10_SUBRESOURCE_DATA subDesc;
	ZeroMemory(&subDesc, sizeof(subDesc));
	subDesc.pSysMem = g_Quad;
	// 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBuffer ) )
		return false;

	subDesc.pSysMem = g_FullScreenQuad;
	// 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBufferFullScreen ) )
		return false;

	// 配置Shader參數的記憶體空間
	cbDesc.ByteWidth = sizeof(Matrix4x4);
	cbDesc.Usage = D3D10_USAGE_DYNAMIC;
	cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
	cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
	cbDesc.MiscFlags = 0;
	if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer ) )
		return false;

	{
		// rasterizer state物件
		D3D10_RASTERIZER_DESC rasterizer_state_desc;

		rasterizer_state_desc.FillMode = D3D10_FILL_SOLID;
		rasterizer_state_desc.CullMode = D3D10_CULL_NONE;
		rasterizer_state_desc.FrontCounterClockwise = true;
		rasterizer_state_desc.DepthBias = 0;
		rasterizer_state_desc.DepthBiasClamp = 0.0f;
		rasterizer_state_desc.SlopeScaledDepthBias = 0.0f;
		rasterizer_state_desc.DepthClipEnable = false;
		rasterizer_state_desc.ScissorEnable = false;
		rasterizer_state_desc.MultisampleEnable = false;
		rasterizer_state_desc.AntialiasedLineEnable = false;

		if ( D3D_OK != g_pDevice->CreateRasterizerState(&rasterizer_state_desc, &g_pRasterizerState) )
			return false;

		g_pDevice->RSSetState(g_pRasterizerState);
	}

	{
		D3D10_BLEND_DESC blend_desc;
		ZeroMemory(&blend_desc, sizeof(blend_desc));

		blend_desc.BlendEnable[0] = TRUE;
		blend_desc.SrcBlend = D3D10_BLEND_ONE;
		blend_desc.DestBlend = D3D10_BLEND_ONE;
		blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
		blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
		blend_desc.DestBlendAlpha = D3D10_BLEND_ONE;
		blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;

		blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;

		if ( D3D_OK != g_pDevice->CreateBlendState(&blend_desc, &g_pBlendState) )
			return false;

		float dummy[4];
		g_pDevice->OMSetBlendState(g_pBlendState, dummy, 0xffffffff);
	}

	{
		D3D10_DEPTH_STENCIL_DESC depthstencil_desc;
		ZeroMemory(&depthstencil_desc, sizeof(depthstencil_desc));

		depthstencil_desc.DepthEnable = TRUE;
		depthstencil_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
		depthstencil_desc.DepthFunc = D3D10_COMPARISON_ALWAYS;
		depthstencil_desc.StencilEnable = FALSE;

		g_pDevice->CreateDepthStencilState(&depthstencil_desc, &g_pDepthStencilState_ZDisable);
	}

	g_view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
	g_proj_matrix = GutMatrixOrthoRH_DirectX(g_fOrthoWidth, g_fOrthoHeight, 0.1f, 100.0f);

	return true;
}
Example #13
0
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	{
		const char *shader = "../../shaders/texture3D_dx10.hlsl";
		// 載入Vertex Shader
		g_pVertexShader = GutLoadVertexShaderDX10_HLSL(shader, "VS", "vs_4_0", &pVSCode);
		if ( NULL==g_pVertexShader )
			return false;
		// 載入Pixel Shader
		g_pPixelShader = GutLoadPixelShaderDX10_HLSL(shader, "PS", "ps_4_0");
		if ( NULL==g_pPixelShader )
			return false;
	}

	// 載入貼圖
	g_pTexture = GutLoadVolumeTexture_DX10("../../textures/CT_256x256x256.dds");
	if ( NULL==g_pTexture )
		return false;

	// 設定Vertex資料格式
	D3D10_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
	};
	if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
		return false;

	SAFE_RELEASE(pVSCode);

	D3D10_BUFFER_DESC cbDesc;
	D3D10_SUBRESOURCE_DATA subDesc;

	{
		// vertex buffer
		cbDesc.ByteWidth = sizeof(Vertex_VT) * 4;
		cbDesc.Usage = D3D10_USAGE_DYNAMIC ;
		cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
		cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		cbDesc.MiscFlags = 0;

		ZeroMemory(&subDesc, sizeof(subDesc));
		subDesc.pSysMem = g_Quad;
		// 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBuffer ) )
			return false;
	}

	{
		// 配置Shader參數的記憶體空間
		cbDesc.ByteWidth = sizeof(Matrix4x4) * 2;
		cbDesc.Usage = D3D10_USAGE_DYNAMIC;
		cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
		cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
		cbDesc.MiscFlags = 0;
		if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer ) )
			return false;
	}

	// 計算投影矩陣
	g_proj_matrix = GutMatrixPerspectiveRH_DirectX(g_fFovW, 1.0f, 0.1f, 100.0f);

	{
		// rasterizer state物件
		D3D10_RASTERIZER_DESC rasterizer_state_desc;

		rasterizer_state_desc.FillMode = D3D10_FILL_SOLID;
		rasterizer_state_desc.CullMode = D3D10_CULL_NONE;
		rasterizer_state_desc.FrontCounterClockwise = true;
		rasterizer_state_desc.DepthBias = 0;
		rasterizer_state_desc.DepthBiasClamp = 0.0f;
		rasterizer_state_desc.SlopeScaledDepthBias = 0.0f;
		rasterizer_state_desc.DepthClipEnable = false;
		rasterizer_state_desc.ScissorEnable = false;
		rasterizer_state_desc.MultisampleEnable = false;
		rasterizer_state_desc.AntialiasedLineEnable = false;

		if ( D3D_OK != g_pDevice->CreateRasterizerState(&rasterizer_state_desc, &g_pRasterizerState) )
			return false;

		g_pDevice->RSSetState(g_pRasterizerState);
	}

	{
		D3D10_SAMPLER_DESC sampler_desc;
		ZeroMemory(&sampler_desc, sizeof(sampler_desc));

		sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
		sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
		sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
		sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;

		if ( D3D_OK != g_pDevice->CreateSamplerState(&sampler_desc, &g_pSamplerState) )
			return false;

		g_pDevice->PSSetSamplers(0, 1, &g_pSamplerState);
	}

	g_view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);

	return true;
}
Example #14
0
bool InitResourceDX10(void)
{
    g_pDevice = GutGetGraphicsDeviceDX10();
    ID3D10Blob *pVSCode = NULL;

    // 載入Vertex Shader
    g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/vertex_lighting_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
    if ( NULL==g_pVertexShader )
        return false;
    // 載入Pixel Shader
    g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/vertex_lighting_dx10.hlsl", "PS", "ps_4_0");
    if ( NULL==g_pPixelShader )
        return false;

    // 設定Vertex資料格式
    D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
    };

    if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
        return false;

    SAFE_RELEASE(pVSCode);

    D3D10_BUFFER_DESC cbDesc;
    // vertex buffer
    cbDesc.ByteWidth = sizeof(Vertex_V3N3) * g_iMaxNumGridVertices;
    cbDesc.Usage = D3D10_USAGE_DYNAMIC ;
    cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
    cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
    cbDesc.MiscFlags = 0;
    // 配置一塊可以存放Vertex的記憶體, 也就是Vertex Buffer.
    if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pVertexBuffer ) )
        return false;

    // 設定一塊可以用來放Index的記憶體.
    cbDesc.ByteWidth = sizeof(unsigned short) * g_iMaxNumGridIndices;
    cbDesc.Usage = D3D10_USAGE_DYNAMIC;
    cbDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
    cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
    cbDesc.MiscFlags = 0;
    // 配置一塊可以存放Index的記憶體, 也就是Index Buffer.
    if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pIndexBuffer ) )
        return false;

    // 配置Shader讀取參數的記憶體空間
    cbDesc.ByteWidth = sizeof(Matrix4x4) * 2;
    cbDesc.Usage = D3D10_USAGE_DYNAMIC;
    cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
    cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
    cbDesc.MiscFlags = 0;
    if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pMatrixConstantBuffer ) )
        return false;

    cbDesc.ByteWidth = sizeof(Light_Info) * g_iNumLights;
    cbDesc.Usage = D3D10_USAGE_DYNAMIC;
    cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
    cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
    cbDesc.MiscFlags = 0;
    if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pLightConstantBuffer ) )
        return false;

    // 計算投影矩陣
    g_proj_matrix = GutMatrixPerspectiveRH_DirectX(g_fFovW, 1.0f, 0.1f, 100.0f);

    // rasterizer state物件
    D3D10_RASTERIZER_DESC rasterizer_state_desc;

    rasterizer_state_desc.FillMode = D3D10_FILL_SOLID;
    rasterizer_state_desc.CullMode = D3D10_CULL_NONE;
    rasterizer_state_desc.FrontCounterClockwise = true;
    rasterizer_state_desc.DepthBias = 0;
    rasterizer_state_desc.DepthBiasClamp = 0.0f;
    rasterizer_state_desc.SlopeScaledDepthBias = 0.0f;
    rasterizer_state_desc.DepthClipEnable = false;
    rasterizer_state_desc.ScissorEnable = false;
    rasterizer_state_desc.MultisampleEnable = false;
    rasterizer_state_desc.AntialiasedLineEnable = false;

    if ( D3D_OK != g_pDevice->CreateRasterizerState(&rasterizer_state_desc, &g_pRasterizerState) )
        return false;

    g_pDevice->RSSetState(g_pRasterizerState);

    g_view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);

    return true;
}