Пример #1
0
D3DBlendStateProvider::D3DBlendStateProvider(const ComPtr<ID3D11Device> &device, const BlendStateDescription &desc)
{
	BlendEquation blend_op_color, blend_op_alpha;
	desc.get_blend_equation(blend_op_color, blend_op_alpha);

	BlendFunc src_blend, dest_blend, src_blend_alpha, dest_blend_alpha;
	desc.get_blend_function(src_blend, dest_blend, src_blend_alpha, dest_blend_alpha);

	bool red, green, blue, alpha;
	desc.get_color_write(red, green, blue, alpha);

	D3D11_BLEND_DESC d3d_desc;
	d3d_desc.AlphaToCoverageEnable = FALSE;
	d3d_desc.IndependentBlendEnable = FALSE;
	for (int i = 0; i < 8; i++)
	{
		d3d_desc.RenderTarget[i].BlendEnable = FALSE;
		d3d_desc.RenderTarget[i].SrcBlend = D3D11_BLEND_ONE;
		d3d_desc.RenderTarget[i].DestBlend = D3D11_BLEND_ZERO;
		d3d_desc.RenderTarget[i].BlendOp = D3D11_BLEND_OP_ADD;
		d3d_desc.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_ONE;
		d3d_desc.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ZERO;
		d3d_desc.RenderTarget[i].BlendOpAlpha = D3D11_BLEND_OP_ADD;
		d3d_desc.RenderTarget[i].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
	}

	d3d_desc.RenderTarget[0].BlendEnable = desc.is_blending_enabled() ? TRUE : FALSE;
	d3d_desc.RenderTarget[0].BlendOp = to_d3d_blend_op(blend_op_color);
	d3d_desc.RenderTarget[0].BlendOpAlpha = to_d3d_blend_op(blend_op_alpha);
	d3d_desc.RenderTarget[0].SrcBlend = to_d3d_blend_func(src_blend);
	d3d_desc.RenderTarget[0].DestBlend = to_d3d_blend_func(dest_blend);
	d3d_desc.RenderTarget[0].SrcBlendAlpha = to_d3d_blend_func(src_blend_alpha);
	d3d_desc.RenderTarget[0].DestBlendAlpha = to_d3d_blend_func(dest_blend_alpha);
	d3d_desc.RenderTarget[0].RenderTargetWriteMask = 0;
	if (red)
		d3d_desc.RenderTarget[0].RenderTargetWriteMask |= D3D11_COLOR_WRITE_ENABLE_RED;
	if (green)
		d3d_desc.RenderTarget[0].RenderTargetWriteMask |= D3D11_COLOR_WRITE_ENABLE_GREEN;
	if (blue)
		d3d_desc.RenderTarget[0].RenderTargetWriteMask |= D3D11_COLOR_WRITE_ENABLE_BLUE;
	if (alpha)
		d3d_desc.RenderTarget[0].RenderTargetWriteMask |= D3D11_COLOR_WRITE_ENABLE_ALPHA;

	HRESULT result = device->CreateBlendState(&d3d_desc, state.output_variable());
	D3DTarget::throw_if_failed("D3D11Device.CreateBlendState failed", result);
}
std::shared_ptr<BlendStateProvider> D3DGraphicContextProvider::create_blend_state(const BlendStateDescription &desc)
{
	std::map<BlendStateDescription, std::shared_ptr<BlendStateProvider> >::iterator it = blend_states.find(desc);
	if (it != blend_states.end())
	{
		return it->second;
	}
	else
	{
		std::shared_ptr<BlendStateProvider> state(new D3DBlendStateProvider(window->get_device(), desc));
		blend_states[desc.clone()] = state;
		return state;
	}
}
Пример #3
0
	void OpenGLBlendState::set(const BlendStateDescription &new_state, const Vec4f &new_blend_color)
	{
		if (!(new_state == desc))
		{
			desc = new_state.clone();
			changed_desc = true;
		}

		if (new_blend_color != blend_color)
		{
			blend_color = new_blend_color;
			changed_blend_color = true;
		}
	}
	std::shared_ptr<BlendStateProvider> GL3GraphicContextProvider::create_blend_state(const BlendStateDescription &desc)
	{
		auto it = blend_states.find(desc);
		if (it != blend_states.end())
		{
			return it->second;
		}
		else
		{
			std::shared_ptr<BlendStateProvider> state(new OpenGLBlendStateProvider(desc));
			blend_states[desc.clone()] = state;
			return state;
		}
	}
	BlendStateDescription BlendStateDescription::opaque()
	{
		BlendStateDescription desc;
		desc.enable_blending(false);
		return desc;
	}