Huge changes for 3d
This commit is contained in:
@@ -101,6 +101,21 @@ GraphicsPipeline::Builder& GraphicsPipeline::Builder::setAlphaBlending(
|
||||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipeline::Builder& GraphicsPipeline::Builder::setDepthTest(
|
||||
bool test, bool write, vk::CompareOp compareOp) {
|
||||
this->depthTest = test;
|
||||
this->depthWrite = write;
|
||||
this->depthCompareOp = compareOp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipeline::Builder& GraphicsPipeline::Builder::setCullMode(
|
||||
vk::CullModeFlags cullMode, vk::FrontFace frontFace) {
|
||||
this->cullMode = cullMode;
|
||||
this->frontFace = frontFace;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::unique_ptr<GraphicsPipeline> GraphicsPipeline::Builder::build() const {
|
||||
if (this->vertexShader == nullptr || this->fragmentShader == nullptr) {
|
||||
log::fatal(
|
||||
@@ -130,26 +145,14 @@ std::unique_ptr<GraphicsPipeline> GraphicsPipeline::Builder::build() const {
|
||||
"setDepthAttachmentFormat() was not called");
|
||||
}
|
||||
|
||||
return std::unique_ptr<GraphicsPipeline>(new GraphicsPipeline(
|
||||
this->device, *this->vertexShader, *this->fragmentShader,
|
||||
this->pipelineLayout, this->colorAttachmentFormats,
|
||||
this->depthAttachmentFormat, this->stencilAttachmentFormat,
|
||||
this->bindingDescriptions, this->attributeDescriptions,
|
||||
this->alphaBlending));
|
||||
return std::unique_ptr<GraphicsPipeline>(new GraphicsPipeline(*this));
|
||||
}
|
||||
|
||||
GraphicsPipeline::GraphicsPipeline(
|
||||
Device& device, Shader& vertexShader, Shader& fragmentShader,
|
||||
vk::PipelineLayout pipelineLayout,
|
||||
std::vector<vk::Format> colorAttachmentFormats,
|
||||
vk::Format depthAttachmentFormat, vk::Format stencilAttachmentFormat,
|
||||
std::vector<vk::VertexInputBindingDescription> bindingDescriptions,
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions,
|
||||
bool alphaBlending)
|
||||
: Pipeline(device, vk::PipelineBindPoint::eGraphics) {
|
||||
GraphicsPipeline::GraphicsPipeline(const Builder& builder)
|
||||
: Pipeline(builder.device, vk::PipelineBindPoint::eGraphics) {
|
||||
setDefaultGraphicsPipelineConfig();
|
||||
|
||||
if (alphaBlending) {
|
||||
if (builder.alphaBlending) {
|
||||
vk::PipelineColorBlendAttachmentState& blend =
|
||||
this->config.colorBlendAttachment;
|
||||
blend.blendEnable = vk::True;
|
||||
@@ -159,17 +162,24 @@ GraphicsPipeline::GraphicsPipeline(
|
||||
blend.dstAlphaBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha;
|
||||
}
|
||||
|
||||
this->config.bindingDescriptions = std::move(bindingDescriptions);
|
||||
this->config.attributeDescriptions = std::move(attributeDescriptions);
|
||||
this->config.pipelineLayout = pipelineLayout;
|
||||
this->config.colorAttachmentFormats = std::move(colorAttachmentFormats);
|
||||
this->config.depthAttachmentFormat = depthAttachmentFormat;
|
||||
this->config.stencilAttachmentFormat = stencilAttachmentFormat;
|
||||
this->config.depthStencilInfo.depthTestEnable = builder.depthTest;
|
||||
this->config.depthStencilInfo.depthWriteEnable = builder.depthWrite;
|
||||
this->config.depthStencilInfo.depthCompareOp = builder.depthCompareOp;
|
||||
|
||||
this->config.rasterizationInfo.cullMode = builder.cullMode;
|
||||
this->config.rasterizationInfo.frontFace = builder.frontFace;
|
||||
|
||||
this->config.bindingDescriptions = builder.bindingDescriptions;
|
||||
this->config.attributeDescriptions = builder.attributeDescriptions;
|
||||
this->config.pipelineLayout = builder.pipelineLayout;
|
||||
this->config.colorAttachmentFormats = builder.colorAttachmentFormats;
|
||||
this->config.depthAttachmentFormat = builder.depthAttachmentFormat;
|
||||
this->config.stencilAttachmentFormat = builder.stencilAttachmentFormat;
|
||||
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
createShaderModule(vertexShader.getSpirv());
|
||||
createShaderModule(builder.vertexShader->getSpirv());
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
createShaderModule(fragmentShader.getSpirv());
|
||||
createShaderModule(builder.fragmentShader->getSpirv());
|
||||
log::trace("created graphics shader modules");
|
||||
|
||||
vk::PipelineShaderStageCreateInfo shaderStages[] = {
|
||||
@@ -245,7 +255,7 @@ void GraphicsPipeline::setDefaultGraphicsPipelineConfig() {
|
||||
this->config.rasterizationInfo.polygonMode = vk::PolygonMode::eFill;
|
||||
this->config.rasterizationInfo.lineWidth = 1.0f;
|
||||
this->config.rasterizationInfo.cullMode = vk::CullModeFlagBits::eNone;
|
||||
this->config.rasterizationInfo.frontFace = vk::FrontFace::eClockwise;
|
||||
this->config.rasterizationInfo.frontFace = vk::FrontFace::eCounterClockwise;
|
||||
this->config.rasterizationInfo.depthBiasEnable = vk::False;
|
||||
this->config.rasterizationInfo.depthBiasConstantFactor = 0.0f;
|
||||
this->config.rasterizationInfo.depthBiasClamp = 0.0f;
|
||||
|
||||
Reference in New Issue
Block a user