#include "material.hpp" #include namespace sophia { Material::Material(Device& device, std::unique_ptr vertexShader, std::unique_ptr fragmentShader, vk::Format colorFormat, vk::Format depthFormat) { createPipelineLayout(device); this->pipeline = GraphicsPipeline::Builder(device) .setVertexShader(*vertexShader) .setFragmentShader(*fragmentShader) .setPipelineLayout(this->pipelineLayout.get()) .setColorAttachmentFormats({colorFormat}) .setDepthAttachmentFormat(depthFormat) .setDepthTest(true, true) .setCullMode(vk::CullModeFlagBits::eBack) .build(); } Material::~Material() { log::trace("destroyed sophia::Material"); } void Material::createPipelineLayout(Device& device) { vk::PushConstantRange pushConstantRange{}; pushConstantRange.stageFlags = vk::ShaderStageFlagBits::eVertex; pushConstantRange.offset = 0; pushConstantRange.size = sizeof(PushConstants); vk::PipelineLayoutCreateInfo pipelineLayoutInfo = {}; pipelineLayoutInfo.setLayoutCount = 0; pipelineLayoutInfo.pushConstantRangeCount = 1; pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange; try { this->pipelineLayout = device.get()->createPipelineLayoutUnique(pipelineLayoutInfo); log::trace("created vk::PipelineLayout"); } catch (const vk::SystemError& err) { log::fatal("failed to create vk::PipelineLayout"); throw std::runtime_error("failed to create vk::PipelineLayout"); } } } // namespace sophia