sandbox updates

This commit is contained in:
2026-10-07 11:51:14 -07:00
parent 3784d0fdec
commit 09a6c0283a
8 changed files with 296 additions and 6 deletions
+45
View File
@@ -0,0 +1,45 @@
#include "material.hpp"
#include <sophia/util/logger.hpp>
namespace sophia {
Material::Material(Device& device, std::unique_ptr<Shader> vertexShader,
std::unique_ptr<Shader> 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