Example #1
0
//==============================================================================
VkPipelineColorBlendStateCreateInfo* PipelineImpl::initColorState(
	const ColorStateInfo& c, VkPipelineColorBlendStateCreateInfo& ci)
{
	ci.logicOpEnable = VK_FALSE;
	ci.attachmentCount = c.m_attachmentCount;

	for(U i = 0; i < ci.attachmentCount; ++i)
	{
		VkPipelineColorBlendAttachmentState& out =
			const_cast<VkPipelineColorBlendAttachmentState&>(
				ci.pAttachments[i]);
		const ColorAttachmentStateInfo& in = c.m_attachments[i];
		out.blendEnable = !(in.m_srcBlendMethod == BlendMethod::ONE
			&& in.m_dstBlendMethod == BlendMethod::ZERO);
		out.srcColorBlendFactor = convertBlendMethod(in.m_srcBlendMethod);
		out.dstColorBlendFactor = convertBlendMethod(in.m_dstBlendMethod);
		out.colorBlendOp = convertBlendFunc(in.m_blendFunction);
		out.srcAlphaBlendFactor = out.srcColorBlendFactor;
		out.dstAlphaBlendFactor = out.dstColorBlendFactor;
		out.alphaBlendOp = out.colorBlendOp;

		out.colorWriteMask = convertColorWriteMask(in.m_channelWriteMask);
	}

	return &ci;
}
Example #2
0
void PipelineImpl::initColorState()
{
	for(U i = 0; i < m_in.m_color.m_attachmentCount; ++i)
	{
		Attachment& out = m_cache.m_attachments[i];
		const ColorAttachmentStateInfo& in = m_in.m_color.m_attachments[i];

		out.m_srcBlendMethod = convertBlendMethod(in.m_srcBlendMethod);
		out.m_dstBlendMethod = convertBlendMethod(in.m_dstBlendMethod);

		switch(in.m_blendFunction)
		{
		case BlendFunction::ADD:
			out.m_blendFunction = GL_FUNC_ADD;
			break;
		case BlendFunction::SUBTRACT:
			out.m_blendFunction = GL_FUNC_SUBTRACT;
			break;
		case BlendFunction::REVERSE_SUBTRACT:
			out.m_blendFunction = GL_FUNC_REVERSE_SUBTRACT;
			break;
		case BlendFunction::MIN:
			out.m_blendFunction = GL_MIN;
			break;
		case BlendFunction::MAX:
			out.m_blendFunction = GL_MAX;
			break;
		default:
			ANKI_ASSERT(0);
		}

		out.m_channelWriteMask[0] = (in.m_channelWriteMask & ColorBit::RED) != 0;
		out.m_channelWriteMask[1] = (in.m_channelWriteMask & ColorBit::GREEN) != 0;
		out.m_channelWriteMask[2] = (in.m_channelWriteMask & ColorBit::BLUE) != 0;
		out.m_channelWriteMask[3] = (in.m_channelWriteMask & ColorBit::ALPHA) != 0;

		if(!(out.m_srcBlendMethod == GL_ONE && out.m_dstBlendMethod == GL_ZERO))
		{
			m_blendEnabled = true;
		}
	}

	m_hashes.m_color = computeHash(&m_in.m_color, sizeof(m_in.m_color));
}