diff --git a/examples/example_gfx_0.c b/examples/example_gfx_0.c index 3e808a98..88aa335e 100644 --- a/examples/example_gfx_0.c +++ b/examples/example_gfx_0.c @@ -269,7 +269,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) }, .atBlendStates = { { - .bBlendEnabled = false + .bBlendEnabled = false, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL } }, .tRenderPassLayout = gptStarter->get_render_pass_layout(), diff --git a/examples/example_gfx_1.c b/examples/example_gfx_1.c index 155856b9..28b3acd3 100644 --- a/examples/example_gfx_1.c +++ b/examples/example_gfx_1.c @@ -296,7 +296,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) }, .atBlendStates = { { - .bBlendEnabled = false + .bBlendEnabled = false, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL } }, .tRenderPassLayout = gptStarter->get_render_pass_layout(), diff --git a/examples/example_gfx_2.c b/examples/example_gfx_2.c index 3666b542..93be541e 100644 --- a/examples/example_gfx_2.c +++ b/examples/example_gfx_2.c @@ -439,7 +439,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) }, .atBlendStates = { { - .bBlendEnabled = false + .bBlendEnabled = false, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL } }, .tRenderPassLayout = gptStarter->get_render_pass_layout(), diff --git a/extensions/pl_draw_backend_ext.c b/extensions/pl_draw_backend_ext.c index b8269ce0..9f8394ca 100644 --- a/extensions/pl_draw_backend_ext.c +++ b/extensions/pl_draw_backend_ext.c @@ -467,6 +467,7 @@ pl__get_3d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, p .atBlendStates = { { .bBlendEnabled = true, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, .tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA, .tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, .tColorOp = PL_BLEND_OP_ADD, @@ -513,6 +514,7 @@ pl__get_3d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, p .atBlendStates = { { .bBlendEnabled = true, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, .tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA, .tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, .tColorOp = PL_BLEND_OP_ADD, @@ -581,6 +583,7 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u .atBlendStates = { { .bBlendEnabled = true, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, .tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA, .tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, .tColorOp = PL_BLEND_OP_ADD, @@ -598,7 +601,7 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u } }, { - .atTextureBindings = { + .atTextureBindings = { {.uSlot = 0, .tStages = PL_SHADER_STAGE_FRAGMENT, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED} } } @@ -636,6 +639,7 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u .atBlendStates = { { .bBlendEnabled = true, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, .tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA, .tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, .tColorOp = PL_BLEND_OP_ADD, @@ -653,13 +657,13 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u } }, { - .atTextureBindings = { + .atTextureBindings = { {.uSlot = 0, .tStages = PL_SHADER_STAGE_FRAGMENT, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED} } } }, .tMSAASampleCount = uMSAASampleCount - }; + }; ptEntry->tSecondaryPipeline = gptGfx->create_shader(ptDevice, &tSecondaryShaderDesc); pl_temp_allocator_reset(&gptDrawBackendCtx->tTempAllocator); return ptEntry; diff --git a/extensions/pl_graphics_ext.c b/extensions/pl_graphics_ext.c index b546179d..82615e98 100644 --- a/extensions/pl_graphics_ext.c +++ b/extensions/pl_graphics_ext.c @@ -1098,13 +1098,15 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode) static const plBlendState atStateMap[PL_BLEND_MODE_COUNT] = { // PL_BLEND_MODE_OPAQUE - { - .bBlendEnabled = false, + { + .bBlendEnabled = false, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, }, // PL_BLEND_MODE_ALPHA { .bBlendEnabled = true, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, .tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA, .tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, .tColorOp = PL_BLEND_OP_ADD, @@ -1116,6 +1118,7 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode) // PL_BLEND_MODE_PREMULTIPLY { .bBlendEnabled = true, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, .tSrcColorFactor = PL_BLEND_FACTOR_ONE, .tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, .tColorOp = PL_BLEND_OP_ADD, @@ -1127,6 +1130,7 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode) // PL_BLEND_MODE_ADDITIVE { .bBlendEnabled = true, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, .tSrcColorFactor = PL_BLEND_FACTOR_SRC_ALPHA, .tDstColorFactor = PL_BLEND_FACTOR_ONE, .tColorOp = PL_BLEND_OP_ADD, @@ -1138,6 +1142,7 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode) // PL_BLEND_MODE_MULTIPLY { .bBlendEnabled = true, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, .tSrcColorFactor = PL_BLEND_FACTOR_DST_COLOR, .tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, .tColorOp = PL_BLEND_OP_ADD, @@ -1149,6 +1154,7 @@ pl_graphics_get_blend_state(plBlendMode tBlendMode) // PL_BLEND_MODE_CLIP_MASK { .bBlendEnabled = true, + .uColorWriteMask = PL_COLOR_WRITE_MASK_ALL, .tSrcColorFactor = PL_BLEND_FACTOR_ZERO, .tDstColorFactor = PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, .tColorOp = PL_BLEND_OP_ADD, diff --git a/extensions/pl_graphics_ext.h b/extensions/pl_graphics_ext.h index 06b8fa4d..0c20c55e 100644 --- a/extensions/pl_graphics_ext.h +++ b/extensions/pl_graphics_ext.h @@ -884,6 +884,7 @@ typedef struct _plComputeShader typedef struct _plBlendState { bool bBlendEnabled; + uint8_t uColorWriteMask; // PL_COLOR_WRITE_MASK_* bits plBlendOp tColorOp; plBlendOp tAlphaOp; plBlendFactor tSrcColorFactor; @@ -1779,6 +1780,16 @@ enum _plFormat PL_FORMAT_COUNT }; +enum _plColorWriteMask +{ + PL_COLOR_WRITE_MASK_R = 1 << 0, + PL_COLOR_WRITE_MASK_G = 1 << 1, + PL_COLOR_WRITE_MASK_B = 1 << 2, + PL_COLOR_WRITE_MASK_A = 1 << 3, + PL_COLOR_WRITE_MASK_ALL = 0xF, + PL_COLOR_WRITE_MASK_NONE = 0 +}; + enum _plBlendMode { PL_BLEND_MODE_OPAQUE, diff --git a/extensions/pl_graphics_metal.m b/extensions/pl_graphics_metal.m index c0573f33..ecc52454 100644 --- a/extensions/pl_graphics_metal.m +++ b/extensions/pl_graphics_metal.m @@ -1615,7 +1615,12 @@ { pipelineDescriptor.colorAttachments[uCurrentColorAttachment].pixelFormat = pl__metal_format(ptLayout->tDesc.atRenderTargets[uTargetIndex].tFormat); pipelineDescriptor.colorAttachments[uCurrentColorAttachment].blendingEnabled = ptDescription->atBlendStates[uCurrentColorAttachment].bBlendEnabled ? YES : NO; - + pipelineDescriptor.colorAttachments[uCurrentColorAttachment].writeMask = + (ptDescription->atBlendStates[uCurrentColorAttachment].uColorWriteMask & PL_COLOR_WRITE_MASK_R ? MTLColorWriteMaskRed : 0) | + (ptDescription->atBlendStates[uCurrentColorAttachment].uColorWriteMask & PL_COLOR_WRITE_MASK_G ? MTLColorWriteMaskGreen : 0) | + (ptDescription->atBlendStates[uCurrentColorAttachment].uColorWriteMask & PL_COLOR_WRITE_MASK_B ? MTLColorWriteMaskBlue : 0) | + (ptDescription->atBlendStates[uCurrentColorAttachment].uColorWriteMask & PL_COLOR_WRITE_MASK_A ? MTLColorWriteMaskAlpha : 0); + if(ptDescription->atBlendStates[uCurrentColorAttachment].bBlendEnabled) { pipelineDescriptor.colorAttachments[uCurrentColorAttachment].sourceRGBBlendFactor = pl__metal_blend_factor(ptDescription->atBlendStates[uCurrentColorAttachment].tSrcColorFactor); diff --git a/extensions/pl_graphics_vulkan.c b/extensions/pl_graphics_vulkan.c index ce49f5fc..69dc2245 100644 --- a/extensions/pl_graphics_vulkan.c +++ b/extensions/pl_graphics_vulkan.c @@ -1824,7 +1824,11 @@ pl_create_shader(plDevice* ptDevice, const plShaderDesc* ptDescription) VkPipelineColorBlendAttachmentState atColorBlendAttachment[PL_MAX_RENDER_TARGETS] = {0}; for (uint32_t i = 0; i < PL_MAX_RENDER_TARGETS; i++) { - atColorBlendAttachment[i].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + atColorBlendAttachment[i].colorWriteMask = + (ptDescription->atBlendStates[i].uColorWriteMask & PL_COLOR_WRITE_MASK_R ? VK_COLOR_COMPONENT_R_BIT : 0) | + (ptDescription->atBlendStates[i].uColorWriteMask & PL_COLOR_WRITE_MASK_G ? VK_COLOR_COMPONENT_G_BIT : 0) | + (ptDescription->atBlendStates[i].uColorWriteMask & PL_COLOR_WRITE_MASK_B ? VK_COLOR_COMPONENT_B_BIT : 0) | + (ptDescription->atBlendStates[i].uColorWriteMask & PL_COLOR_WRITE_MASK_A ? VK_COLOR_COMPONENT_A_BIT : 0); atColorBlendAttachment[i].blendEnable = ptDescription->atBlendStates[i].bBlendEnabled ? VK_TRUE : VK_FALSE; if (ptDescription->atBlendStates[i].bBlendEnabled) { diff --git a/extensions/pl_shader_variant_ext.c b/extensions/pl_shader_variant_ext.c index b565f698..aaa3cd1c 100644 --- a/extensions/pl_shader_variant_ext.c +++ b/extensions/pl_shader_variant_ext.c @@ -712,10 +712,11 @@ pl_shader_tool_load_manifest(const char* pcPath) { plJsonObject* ptBlendState = pl_json_member_by_index(ptBlendStates, i); tShaderDesc.atBlendStates[i].bBlendEnabled = pl_json_bool_member(ptBlendState, "bBlendEnabled", false); + tShaderDesc.atBlendStates[i].uColorWriteMask = (uint8_t)pl_json_uint_member(ptBlendState, "uColorWriteMask", PL_COLOR_WRITE_MASK_ALL); char acBlendOp[64] = {0}; char* pcBlendEnum = NULL; - + pcBlendEnum = pl_json_string_member(ptBlendState, "tSrcColorFactor", acBlendOp, 64); tShaderDesc.atBlendStates[i].tSrcColorFactor = pl__shader_tools_get_blend_factor(pcBlendEnum);