Skip to content

Commit d5a8505

Browse files
nreaganhoffstadt
authored andcommitted
feat: Add colorWriteMask enum to blend state
1 parent 3cc03d0 commit d5a8505

File tree

9 files changed

+45
-11
lines changed

9 files changed

+45
-11
lines changed

examples/example_gfx_0.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
269269
},
270270
.atBlendStates = {
271271
{
272-
.bBlendEnabled = false
272+
.bBlendEnabled = false,
273+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL
273274
}
274275
},
275276
.tRenderPassLayout = gptStarter->get_render_pass_layout(),

examples/example_gfx_1.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
296296
},
297297
.atBlendStates = {
298298
{
299-
.bBlendEnabled = false
299+
.bBlendEnabled = false,
300+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL
300301
}
301302
},
302303
.tRenderPassLayout = gptStarter->get_render_pass_layout(),

examples/example_gfx_2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
439439
},
440440
.atBlendStates = {
441441
{
442-
.bBlendEnabled = false
442+
.bBlendEnabled = false,
443+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL
443444
}
444445
},
445446
.tRenderPassLayout = gptStarter->get_render_pass_layout(),

extensions/pl_draw_backend_ext.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ pl__get_3d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, p
467467
.atBlendStates = {
468468
{
469469
.bBlendEnabled = true,
470+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
470471
.tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA,
471472
.tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
472473
.tColorOp = PL_BLEND_OP_ADD,
@@ -513,6 +514,7 @@ pl__get_3d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, p
513514
.atBlendStates = {
514515
{
515516
.bBlendEnabled = true,
517+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
516518
.tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA,
517519
.tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
518520
.tColorOp = PL_BLEND_OP_ADD,
@@ -581,6 +583,7 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u
581583
.atBlendStates = {
582584
{
583585
.bBlendEnabled = true,
586+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
584587
.tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA,
585588
.tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
586589
.tColorOp = PL_BLEND_OP_ADD,
@@ -598,7 +601,7 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u
598601
}
599602
},
600603
{
601-
.atTextureBindings = {
604+
.atTextureBindings = {
602605
{.uSlot = 0, .tStages = PL_SHADER_STAGE_FRAGMENT, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED}
603606
}
604607
}
@@ -636,6 +639,7 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u
636639
.atBlendStates = {
637640
{
638641
.bBlendEnabled = true,
642+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
639643
.tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA,
640644
.tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
641645
.tColorOp = PL_BLEND_OP_ADD,
@@ -653,13 +657,13 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u
653657
}
654658
},
655659
{
656-
.atTextureBindings = {
660+
.atTextureBindings = {
657661
{.uSlot = 0, .tStages = PL_SHADER_STAGE_FRAGMENT, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED}
658662
}
659663
}
660664
},
661665
.tMSAASampleCount = uMSAASampleCount
662-
};
666+
};
663667
ptEntry->tSecondaryPipeline = gptGfx->create_shader(ptDevice, &tSecondaryShaderDesc);
664668
pl_temp_allocator_reset(&gptDrawBackendCtx->tTempAllocator);
665669
return ptEntry;

extensions/pl_graphics_ext.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,13 +1098,15 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode)
10981098
static const plBlendState atStateMap[PL_BLEND_MODE_COUNT] =
10991099
{
11001100
// PL_BLEND_MODE_OPAQUE
1101-
{
1102-
.bBlendEnabled = false,
1101+
{
1102+
.bBlendEnabled = false,
1103+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
11031104
},
11041105

11051106
// PL_BLEND_MODE_ALPHA
11061107
{
11071108
.bBlendEnabled = true,
1109+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
11081110
.tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA,
11091111
.tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
11101112
.tColorOp = PL_BLEND_OP_ADD,
@@ -1116,6 +1118,7 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode)
11161118
// PL_BLEND_MODE_PREMULTIPLY
11171119
{
11181120
.bBlendEnabled = true,
1121+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
11191122
.tSrcColorFactor = PL_BLEND_FACTOR_ONE,
11201123
.tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
11211124
.tColorOp = PL_BLEND_OP_ADD,
@@ -1127,6 +1130,7 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode)
11271130
// PL_BLEND_MODE_ADDITIVE
11281131
{
11291132
.bBlendEnabled = true,
1133+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
11301134
.tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA,
11311135
.tDstColorFactor = PL_BLEND_FACTOR_ONE,
11321136
.tColorOp = PL_BLEND_OP_ADD,
@@ -1138,6 +1142,7 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode)
11381142
// PL_BLEND_MODE_MULTIPLY
11391143
{
11401144
.bBlendEnabled = true,
1145+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
11411146
.tSrcColorFactor = PL_BLEND_FACTOR_DST_COLOR,
11421147
.tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
11431148
.tColorOp = PL_BLEND_OP_ADD,
@@ -1149,6 +1154,7 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode)
11491154
// PL_BLEND_MODE_CLIP_MASK
11501155
{
11511156
.bBlendEnabled = true,
1157+
.uColorWriteMask = PL_COLOR_WRITE_MASK_ALL,
11521158
.tSrcColorFactor = PL_BLEND_FACTOR_ZERO,
11531159
.tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
11541160
.tColorOp = PL_BLEND_OP_ADD,

extensions/pl_graphics_ext.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ typedef struct _plComputeShader
884884
typedef struct _plBlendState
885885
{
886886
bool bBlendEnabled;
887+
uint8_t uColorWriteMask; // PL_COLOR_WRITE_MASK_* bits
887888
plBlendOp tColorOp;
888889
plBlendOp tAlphaOp;
889890
plBlendFactor tSrcColorFactor;
@@ -1779,6 +1780,16 @@ enum _plFormat
17791780
PL_FORMAT_COUNT
17801781
};
17811782

1783+
enum _plColorWriteMask
1784+
{
1785+
PL_COLOR_WRITE_MASK_R = 1 << 0,
1786+
PL_COLOR_WRITE_MASK_G = 1 << 1,
1787+
PL_COLOR_WRITE_MASK_B = 1 << 2,
1788+
PL_COLOR_WRITE_MASK_A = 1 << 3,
1789+
PL_COLOR_WRITE_MASK_ALL = 0xF,
1790+
PL_COLOR_WRITE_MASK_NONE = 0
1791+
};
1792+
17821793
enum _plBlendMode
17831794
{
17841795
PL_BLEND_MODE_OPAQUE,

extensions/pl_graphics_metal.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,12 @@
16151615
{
16161616
pipelineDescriptor.colorAttachments[uCurrentColorAttachment].pixelFormat = pl__metal_format(ptLayout->tDesc.atRenderTargets[uTargetIndex].tFormat);
16171617
pipelineDescriptor.colorAttachments[uCurrentColorAttachment].blendingEnabled = ptDescription->atBlendStates[uCurrentColorAttachment].bBlendEnabled ? YES : NO;
1618-
1618+
pipelineDescriptor.colorAttachments[uCurrentColorAttachment].writeMask =
1619+
(ptDescription->atBlendStates[uCurrentColorAttachment].uColorWriteMask & PL_COLOR_WRITE_MASK_R ? MTLColorWriteMaskRed : 0) |
1620+
(ptDescription->atBlendStates[uCurrentColorAttachment].uColorWriteMask & PL_COLOR_WRITE_MASK_G ? MTLColorWriteMaskGreen : 0) |
1621+
(ptDescription->atBlendStates[uCurrentColorAttachment].uColorWriteMask & PL_COLOR_WRITE_MASK_B ? MTLColorWriteMaskBlue : 0) |
1622+
(ptDescription->atBlendStates[uCurrentColorAttachment].uColorWriteMask & PL_COLOR_WRITE_MASK_A ? MTLColorWriteMaskAlpha : 0);
1623+
16191624
if(ptDescription->atBlendStates[uCurrentColorAttachment].bBlendEnabled)
16201625
{
16211626
pipelineDescriptor.colorAttachments[uCurrentColorAttachment].sourceRGBBlendFactor = pl__metal_blend_factor(ptDescription->atBlendStates[uCurrentColorAttachment].tSrcColorFactor);

extensions/pl_graphics_vulkan.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,11 @@ pl_create_shader(plDevice* ptDevice, const plShaderDesc* ptDescription)
18241824
VkPipelineColorBlendAttachmentState atColorBlendAttachment[PL_MAX_RENDER_TARGETS] = {0};
18251825
for (uint32_t i = 0; i < PL_MAX_RENDER_TARGETS; i++)
18261826
{
1827-
atColorBlendAttachment[i].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
1827+
atColorBlendAttachment[i].colorWriteMask =
1828+
(ptDescription->atBlendStates[i].uColorWriteMask & PL_COLOR_WRITE_MASK_R ? VK_COLOR_COMPONENT_R_BIT : 0) |
1829+
(ptDescription->atBlendStates[i].uColorWriteMask & PL_COLOR_WRITE_MASK_G ? VK_COLOR_COMPONENT_G_BIT : 0) |
1830+
(ptDescription->atBlendStates[i].uColorWriteMask & PL_COLOR_WRITE_MASK_B ? VK_COLOR_COMPONENT_B_BIT : 0) |
1831+
(ptDescription->atBlendStates[i].uColorWriteMask & PL_COLOR_WRITE_MASK_A ? VK_COLOR_COMPONENT_A_BIT : 0);
18281832
atColorBlendAttachment[i].blendEnable = ptDescription->atBlendStates[i].bBlendEnabled ? VK_TRUE : VK_FALSE;
18291833
if (ptDescription->atBlendStates[i].bBlendEnabled)
18301834
{

extensions/pl_shader_variant_ext.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,11 @@ pl_shader_tool_load_manifest(const char* pcPath)
712712
{
713713
plJsonObject* ptBlendState = pl_json_member_by_index(ptBlendStates, i);
714714
tShaderDesc.atBlendStates[i].bBlendEnabled = pl_json_bool_member(ptBlendState, "bBlendEnabled", false);
715+
tShaderDesc.atBlendStates[i].uColorWriteMask = (uint8_t)pl_json_uint_member(ptBlendState, "uColorWriteMask", PL_COLOR_WRITE_MASK_ALL);
715716

716717
char acBlendOp[64] = {0};
717718
char* pcBlendEnum = NULL;
718-
719+
719720
pcBlendEnum = pl_json_string_member(ptBlendState, "tSrcColorFactor", acBlendOp, 64);
720721
tShaderDesc.atBlendStates[i].tSrcColorFactor = pl__shader_tools_get_blend_factor(pcBlendEnum);
721722

0 commit comments

Comments
 (0)