Browse Source

add internal function to pack blend state into 32 bits.

Sasha Szpakowski 11 months ago
parent
commit
26a7389a4d
1 changed files with 19 additions and 0 deletions
  1. 19 0
      src/modules/graphics/renderstate.h

+ 19 - 0
src/modules/graphics/renderstate.h

@@ -147,6 +147,25 @@ struct BlendState
 			&& srcFactorRGB == b.srcFactorRGB && srcFactorA == b.srcFactorA
 			&& dstFactorRGB == b.dstFactorRGB && dstFactorA == b.dstFactorA;
 	}
+
+	uint32 toKey() const
+	{
+		return (dstFactorA << 0) | (dstFactorRGB << 4) | (srcFactorA << 8) | (srcFactorRGB << 12)
+			| (operationA << 16) | (operationRGB << 20) | ((enable ? 1 : 0) << 24);
+	}
+
+	static BlendState fromKey(uint32 key)
+	{
+		BlendState b;
+		b.enable = (bool)((key >> 24) & 1);
+		b.operationRGB = (BlendOperation)((key >> 20) & 0x7);
+		b.operationA = (BlendOperation)((key >> 16) & 0x7);
+		b.srcFactorRGB = (BlendFactor)((key >> 12) & 0xF);
+		b.srcFactorA = (BlendFactor)((key >> 8) & 0xF);
+		b.dstFactorRGB = (BlendFactor)((key >> 4) & 0xF);
+		b.dstFactorA = (BlendFactor)((key >> 0) & 0xF);
+		return b;
+	}
 };
 
 struct DepthState