Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/example_gfx_0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion examples/example_gfx_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion examples/example_gfx_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
10 changes: 7 additions & 3 deletions extensions/pl_draw_backend_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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}
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions extensions/pl_graphics_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions extensions/pl_graphics_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion extensions/pl_graphics_metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion extensions/pl_graphics_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion extensions/pl_shader_variant_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading