2D scene rendering + image loading #15
@@ -95,6 +95,12 @@ GraphicsPipeline::Builder& GraphicsPipeline::Builder::setVertexInput(
|
||||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipeline::Builder& GraphicsPipeline::Builder::setAlphaBlending(
|
||||
bool enabled) {
|
||||
this->alphaBlending = enabled;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::unique_ptr<GraphicsPipeline> GraphicsPipeline::Builder::build() const {
|
||||
if (this->vertexShader == nullptr || this->fragmentShader == nullptr) {
|
||||
log::fatal(
|
||||
@@ -128,7 +134,8 @@ std::unique_ptr<GraphicsPipeline> GraphicsPipeline::Builder::build() const {
|
||||
this->device, *this->vertexShader, *this->fragmentShader,
|
||||
this->pipelineLayout, this->colorAttachmentFormats,
|
||||
this->depthAttachmentFormat, this->stencilAttachmentFormat,
|
||||
this->bindingDescriptions, this->attributeDescriptions));
|
||||
this->bindingDescriptions, this->attributeDescriptions,
|
||||
this->alphaBlending));
|
||||
}
|
||||
|
||||
GraphicsPipeline::GraphicsPipeline(
|
||||
@@ -137,10 +144,21 @@ GraphicsPipeline::GraphicsPipeline(
|
||||
std::vector<vk::Format> colorAttachmentFormats,
|
||||
vk::Format depthAttachmentFormat, vk::Format stencilAttachmentFormat,
|
||||
std::vector<vk::VertexInputBindingDescription> bindingDescriptions,
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions)
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions,
|
||||
bool alphaBlending)
|
||||
: Pipeline(device, vk::PipelineBindPoint::eGraphics) {
|
||||
setDefaultGraphicsPipelineConfig();
|
||||
|
||||
if (alphaBlending) {
|
||||
vk::PipelineColorBlendAttachmentState& blend =
|
||||
this->config.colorBlendAttachment;
|
||||
blend.blendEnable = vk::True;
|
||||
blend.srcColorBlendFactor = vk::BlendFactor::eSrcAlpha;
|
||||
blend.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha;
|
||||
blend.srcAlphaBlendFactor = vk::BlendFactor::eOne;
|
||||
blend.dstAlphaBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha;
|
||||
}
|
||||
|
||||
this->config.bindingDescriptions = std::move(bindingDescriptions);
|
||||
this->config.attributeDescriptions = std::move(attributeDescriptions);
|
||||
this->config.pipelineLayout = pipelineLayout;
|
||||
|
||||
@@ -47,7 +47,8 @@ class GraphicsPipeline : public Pipeline {
|
||||
std::vector<vk::Format> colorAttachmentFormats,
|
||||
vk::Format depthAttachmentFormat, vk::Format stencilAttachmentFormat,
|
||||
std::vector<vk::VertexInputBindingDescription> bindingDescriptions,
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions);
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions,
|
||||
bool alphaBlending);
|
||||
|
||||
void setDefaultGraphicsPipelineConfig();
|
||||
|
||||
@@ -69,6 +70,8 @@ class GraphicsPipeline::Builder {
|
||||
Builder& setVertexInput(
|
||||
std::vector<vk::VertexInputBindingDescription> bindingDescriptions,
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions);
|
||||
// Straight (non-premultiplied) "over" blending on every color attachment.
|
||||
Builder& setAlphaBlending(bool enabled = true);
|
||||
|
||||
std::unique_ptr<GraphicsPipeline> build() const;
|
||||
|
||||
@@ -83,6 +86,7 @@ class GraphicsPipeline::Builder {
|
||||
vk::Format stencilAttachmentFormat = vk::Format::eUndefined;
|
||||
std::vector<vk::VertexInputBindingDescription> bindingDescriptions{};
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions{};
|
||||
bool alphaBlending = false;
|
||||
};
|
||||
|
||||
} // namespace sophia
|
||||
|
||||
Reference in New Issue
Block a user