mirror of
https://github.com/love2d/love.git
synced 2026-08-12 16:40:57 +02:00
vulkan: implement setBlendState
This commit is contained in:
@@ -265,6 +265,10 @@ namespace love {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void Graphics::setBlendState(const BlendState& blend) {
|
||||
states.back().blend = blend;
|
||||
}
|
||||
|
||||
void Graphics::setPointSize(float size) {
|
||||
std::cout << "setPointSize ";
|
||||
|
||||
@@ -1230,6 +1234,7 @@ namespace love {
|
||||
configuration.shader = (Shader*)Shader::current;
|
||||
configuration.primitiveType = primitiveType;
|
||||
configuration.polygonMode = currentPolygonMode;
|
||||
configuration.blendState = states.back().blend;
|
||||
std::vector<VkBuffer> bufferVector;
|
||||
|
||||
std::vector<VkDeviceSize> offsets;
|
||||
@@ -1321,13 +1326,13 @@ namespace love {
|
||||
|
||||
VkPipelineColorBlendAttachmentState colorBlendAttachment{};
|
||||
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
||||
colorBlendAttachment.blendEnable = VK_TRUE;
|
||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.blendEnable = Vulkan::getBool(configuration.blendState.enable);
|
||||
colorBlendAttachment.srcColorBlendFactor = Vulkan::getBlendFactor(configuration.blendState.srcFactorRGB);
|
||||
colorBlendAttachment.dstColorBlendFactor = Vulkan::getBlendFactor(configuration.blendState.dstFactorRGB);
|
||||
colorBlendAttachment.colorBlendOp = Vulkan::getBlendOp(configuration.blendState.operationRGB);
|
||||
colorBlendAttachment.srcAlphaBlendFactor = Vulkan::getBlendFactor(configuration.blendState.srcFactorA);
|
||||
colorBlendAttachment.dstAlphaBlendFactor = Vulkan::getBlendFactor(configuration.blendState.dstFactorA);
|
||||
colorBlendAttachment.alphaBlendOp = Vulkan::getBlendOp(configuration.blendState.operationA);
|
||||
|
||||
VkPipelineColorBlendStateCreateInfo colorBlending{};
|
||||
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||
@@ -1485,6 +1490,9 @@ namespace love {
|
||||
}
|
||||
|
||||
bool operator==(const GraphicsPipelineConfiguration& first, const GraphicsPipelineConfiguration& other) {
|
||||
if (!(first.blendState == other.blendState)) { // not sure why != doesn't work
|
||||
return false;
|
||||
}
|
||||
if (first.polygonMode != other.polygonMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace love {
|
||||
Shader* shader = nullptr;
|
||||
PrimitiveType primitiveType = PRIMITIVE_MAX_ENUM;
|
||||
VkPolygonMode polygonMode = VK_POLYGON_MODE_FILL;
|
||||
BlendState blendState;
|
||||
|
||||
friend static bool operator==(const GraphicsPipelineConfiguration& first, const GraphicsPipelineConfiguration& other);
|
||||
};
|
||||
@@ -99,7 +100,7 @@ namespace love {
|
||||
void setDepthMode(CompareMode compare, bool write) override { std::cout << "setDepthMode "; }
|
||||
void setFrontFaceWinding(Winding winding) override { std::cout << "setFrontFaceWinding "; }
|
||||
void setColorMask(ColorChannelMask mask) override { std::cout << "setColorMask "; }
|
||||
void setBlendState(const BlendState& blend) override { std::cout << "setBlendState "; }
|
||||
void setBlendState(const BlendState& blend) override;
|
||||
void setPointSize(float size) override;
|
||||
void setWireframe(bool enable) override;
|
||||
PixelFormat getSizedFormat(PixelFormat format, bool rendertarget, bool readable) const override;
|
||||
|
||||
@@ -301,6 +301,60 @@ namespace love {
|
||||
throw love::Exception("unknown primitive type");
|
||||
}
|
||||
}
|
||||
|
||||
VkBlendFactor Vulkan::getBlendFactor(BlendFactor blendFactor) {
|
||||
switch (blendFactor) {
|
||||
case BLENDFACTOR_ZERO:
|
||||
return VK_BLEND_FACTOR_ZERO;
|
||||
case BLENDFACTOR_ONE:
|
||||
return VK_BLEND_FACTOR_ONE;
|
||||
case BLENDFACTOR_SRC_COLOR:
|
||||
return VK_BLEND_FACTOR_SRC_COLOR;
|
||||
case BLENDFACTOR_ONE_MINUS_SRC_COLOR:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
|
||||
case BLENDFACTOR_SRC_ALPHA:
|
||||
return VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
case BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
case BLENDFACTOR_DST_COLOR:
|
||||
return VK_BLEND_FACTOR_DST_COLOR;
|
||||
case BLENDFACTOR_ONE_MINUS_DST_COLOR:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
|
||||
case BLENDFACTOR_DST_ALPHA:
|
||||
return VK_BLEND_FACTOR_DST_ALPHA;
|
||||
case BLENDFACTOR_ONE_MINUS_DST_ALPHA:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
|
||||
case BLENDFACTOR_SRC_ALPHA_SATURATED:
|
||||
return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE;
|
||||
case BLENDFACTOR_MAX_ENUM:
|
||||
throw love::Exception("unknown blend factor");
|
||||
}
|
||||
}
|
||||
|
||||
VkBlendOp Vulkan::getBlendOp(BlendOperation op) {
|
||||
switch (op) {
|
||||
case BLENDOP_ADD:
|
||||
return VK_BLEND_OP_ADD;
|
||||
case BLENDOP_MAX:
|
||||
return VK_BLEND_OP_MAX;
|
||||
case BLENDOP_MIN:
|
||||
return VK_BLEND_OP_MIN;
|
||||
case BLENDOP_SUBTRACT:
|
||||
return VK_BLEND_OP_SUBTRACT;
|
||||
case BLENDOP_REVERSE_SUBTRACT:
|
||||
return VK_BLEND_OP_REVERSE_SUBTRACT;
|
||||
case BLENDOP_MAX_ENUM:
|
||||
throw love::Exception("unknown blend operation");
|
||||
}
|
||||
}
|
||||
|
||||
VkBool32 Vulkan::getBool(bool b) {
|
||||
if (b) {
|
||||
return VK_TRUE;
|
||||
} else {
|
||||
return VK_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace love {
|
||||
static std::string getVendorName(uint32_t vendorId);
|
||||
static std::string getVulkanApiVersion(uint32_t apiVersion);
|
||||
static VkPrimitiveTopology getPrimitiveTypeTopology(graphics::PrimitiveType);
|
||||
static VkBlendFactor getBlendFactor(BlendFactor);
|
||||
static VkBlendOp getBlendOp(BlendOperation);
|
||||
static VkBool32 getBool(bool);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user