Browse Source

GR/GL: Add separate blend factors and operation

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
1f37c0c760

+ 14 - 2
src/anki/gr/CommandBuffer.h

@@ -208,11 +208,23 @@ public:
 	/// Set color channel write mask.
 	void setColorChannelWriteMask(U32 attachment, ColorBit mask);
 
+	/// Set blend factors seperate.
+	void setBlendFactors(U32 attachment, BlendFactor srcRgb, BlendFactor dstRgb, BlendFactor srcA, BlendFactor dstA);
+
 	/// Set blend factors.
-	void setBlendFactors(U32 attachment, BlendFactor src, BlendFactor dst);
+	void setBlendFactors(U32 attachment, BlendFactor src, BlendFactor dst)
+	{
+		setBlendFactors(attachment, src, dst, src, dst);
+	}
+
+	/// Set the blend operation seperate.
+	void setBlendOperation(U32 attachment, BlendOperation funcRgb, BlendOperation funcA);
 
 	/// Set the blend operation.
-	void setBlendOperation(U32 attachment, BlendOperation func);
+	void setBlendOperation(U32 attachment, BlendOperation func)
+	{
+		setBlendOperation(attachment, func, func);
+	}
 
 	/// Bind texture.
 	void bindTexture(U32 set, U32 binding, TexturePtr tex, DepthStencilAspectBit aspect = DepthStencilAspectBit::DEPTH);

+ 27 - 16
src/anki/gr/gl/CommandBuffer.cpp

@@ -558,59 +558,70 @@ void CommandBuffer::setColorChannelWriteMask(U32 attachment, ColorBit mask)
 	}
 }
 
-void CommandBuffer::setBlendFactors(U32 attachment, BlendFactor src, BlendFactor dst)
+void CommandBuffer::setBlendFactors(
+	U32 attachment, BlendFactor srcRgb, BlendFactor dstRgb, BlendFactor srcA, BlendFactor dstA)
 {
 	class Cmd final : public GlCommand
 	{
 	public:
 		U8 m_attachment;
-		GLenum m_src;
-		GLenum m_dst;
+		GLenum m_srcRgb;
+		GLenum m_dstRgb;
+		GLenum m_srcA;
+		GLenum m_dstA;
 
-		Cmd(U8 att, GLenum src, GLenum dst)
+		Cmd(U8 att, GLenum srcRgb, GLenum dstRgb, GLenum srcA, GLenum dstA)
 			: m_attachment(att)
-			, m_src(src)
-			, m_dst(dst)
+			, m_srcRgb(srcRgb)
+			, m_dstRgb(dstRgb)
+			, m_srcA(srcA)
+			, m_dstA(dstA)
 		{
 		}
 
 		Error operator()(GlState&)
 		{
-			glBlendFunci(m_attachment, m_src, m_dst);
+			glBlendFuncSeparatei(m_attachment, m_srcRgb, m_dstRgb, m_srcA, m_dstA);
 			return ErrorCode::NONE;
 		}
 	};
 
-	if(m_impl->m_state.setBlendFactors(attachment, src, dst))
+	if(m_impl->m_state.setBlendFactors(attachment, srcRgb, dstRgb, srcA, dstA))
 	{
-		m_impl->pushBackNewCommand<Cmd>(attachment, convertBlendFactor(src), convertBlendFactor(dst));
+		m_impl->pushBackNewCommand<Cmd>(attachment,
+			convertBlendFactor(srcRgb),
+			convertBlendFactor(dstRgb),
+			convertBlendFactor(srcA),
+			convertBlendFactor(dstA));
 	}
 }
 
-void CommandBuffer::setBlendOperation(U32 attachment, BlendOperation func)
+void CommandBuffer::setBlendOperation(U32 attachment, BlendOperation funcRgb, BlendOperation funcA)
 {
 	class Cmd final : public GlCommand
 	{
 	public:
 		U8 m_attachment;
-		GLenum m_func;
+		GLenum m_funcRgb;
+		GLenum m_funcA;
 
-		Cmd(U8 att, GLenum func)
+		Cmd(U8 att, GLenum funcRgb, GLenum funcA)
 			: m_attachment(att)
-			, m_func(func)
+			, m_funcRgb(funcRgb)
+			, m_funcA(funcA)
 		{
 		}
 
 		Error operator()(GlState&)
 		{
-			glBlendEquationi(m_attachment, m_func);
+			glBlendEquationSeparatei(m_attachment, m_funcRgb, m_funcA);
 			return ErrorCode::NONE;
 		}
 	};
 
-	if(m_impl->m_state.setBlendOperation(attachment, func))
+	if(m_impl->m_state.setBlendOperation(attachment, funcRgb, funcA))
 	{
-		m_impl->pushBackNewCommand<Cmd>(attachment, convertBlendOperation(func));
+		m_impl->pushBackNewCommand<Cmd>(attachment, convertBlendOperation(funcRgb), convertBlendOperation(funcA));
 	}
 }
 

+ 4 - 4
src/anki/gr/gl/CommandBufferImpl.cpp

@@ -175,14 +175,14 @@ void CommandBufferImpl::flushDrawcall(CommandBuffer& cmdb)
 				cmdb.setColorChannelWriteMask(i, ColorBit::ALL);
 			}
 
-			if(att.m_blendSrcFactor == BlendFactor::COUNT)
+			if(att.m_blendSrcFactorRgb == BlendFactor::COUNT)
 			{
-				cmdb.setBlendFactors(i, BlendFactor::ONE, BlendFactor::ZERO);
+				cmdb.setBlendFactors(i, BlendFactor::ONE, BlendFactor::ZERO, BlendFactor::ONE, BlendFactor::ZERO);
 			}
 
-			if(att.m_blendOp == BlendOperation::COUNT)
+			if(att.m_blendOpRgb == BlendOperation::COUNT)
 			{
-				cmdb.setBlendOperation(i, BlendOperation::ADD);
+				cmdb.setBlendOperation(i, BlendOperation::ADD, BlendOperation::ADD);
 			}
 		}
 	}

+ 21 - 12
src/anki/gr/gl/StateTracker.h

@@ -362,9 +362,12 @@ public:
 	public:
 		ColorBit m_writeMask = INVALID_COLOR_MASK;
 		Bool8 m_enableBlend = 2;
-		BlendFactor m_blendSrcFactor = BlendFactor::COUNT;
-		BlendFactor m_blendDstFactor = BlendFactor::COUNT;
-		BlendOperation m_blendOp = BlendOperation::COUNT;
+		BlendFactor m_blendSrcFactorRgb = BlendFactor::COUNT;
+		BlendFactor m_blendDstFactorRgb = BlendFactor::COUNT;
+		BlendFactor m_blendSrcFactorA = BlendFactor::COUNT;
+		BlendFactor m_blendDstFactorA = BlendFactor::COUNT;
+		BlendOperation m_blendOpRgb = BlendOperation::COUNT;
+		BlendOperation m_blendOpA = BlendOperation::COUNT;
 	};
 
 	Array<ColorAttachment, MAX_COLOR_ATTACHMENTS> m_colorAtt;
@@ -383,8 +386,10 @@ public:
 	{
 		auto& att = m_colorAtt[attidx];
 
-		Bool wantBlend = !(att.m_blendSrcFactor == BlendFactor::ONE && att.m_blendDstFactor == BlendFactor::ZERO)
-			&& (att.m_blendOp == BlendOperation::ADD || att.m_blendOp == BlendOperation::SUBTRACT);
+		Bool wantBlend = !(att.m_blendSrcFactorRgb == BlendFactor::ONE && att.m_blendDstFactorRgb == BlendFactor::ZERO)
+			&& !(att.m_blendSrcFactorA == BlendFactor::ONE && att.m_blendDstFactorA == BlendFactor::ZERO)
+			&& (att.m_blendOpRgb == BlendOperation::ADD || att.m_blendOpRgb == BlendOperation::SUBTRACT)
+			&& (att.m_blendOpA == BlendOperation::ADD || att.m_blendOpA == BlendOperation::SUBTRACT);
 
 		if(wantBlend != att.m_enableBlend)
 		{
@@ -394,25 +399,29 @@ public:
 		return false;
 	}
 
-	Bool setBlendFactors(U32 attachment, BlendFactor src, BlendFactor dst)
+	Bool setBlendFactors(U32 attachment, BlendFactor srcRgb, BlendFactor dstRgb, BlendFactor srcA, BlendFactor dstA)
 	{
 		auto& att = m_colorAtt[attachment];
-		if(att.m_blendSrcFactor != src || att.m_blendDstFactor != dst)
+		if(att.m_blendSrcFactorRgb != srcRgb || att.m_blendDstFactorRgb != dstRgb || att.m_blendSrcFactorA != srcA
+			|| att.m_blendDstFactorA != dstA)
 		{
-			att.m_blendSrcFactor = src;
-			att.m_blendDstFactor = dst;
+			att.m_blendSrcFactorRgb = srcRgb;
+			att.m_blendDstFactorRgb = dstRgb;
+			att.m_blendSrcFactorA = srcA;
+			att.m_blendDstFactorA = dstA;
 			return true;
 		}
 		return false;
 	}
 
-	Bool setBlendOperation(U32 attachment, BlendOperation func)
+	Bool setBlendOperation(U32 attachment, BlendOperation funcRgb, BlendOperation funcA)
 	{
 		auto& att = m_colorAtt[attachment];
 
-		if(att.m_blendOp != func)
+		if(att.m_blendOpRgb != funcRgb || att.m_blendOpA != funcA)
 		{
-			att.m_blendOp = func;
+			att.m_blendOpRgb = funcRgb;
+			att.m_blendOpA = funcA;
 			return true;
 		}
 		return false;