Skip to content
Snippets Groups Projects
Commit 34979078 authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#66] Fix first mesh project main

parent 369d3dcf
No related branches found
No related tags found
1 merge request!54Resolve "Cmd/Sync-Rework"
...@@ -63,18 +63,12 @@ int main(int argc, const char** argv) { ...@@ -63,18 +63,12 @@ int main(int argc, const char** argv) {
// an example attachment for passes that output to the window // an example attachment for passes that output to the window
const vkcv::AttachmentDescription present_color_attachment( const vkcv::AttachmentDescription present_color_attachment(
vkcv::AttachmentLayout::UNDEFINED,
vkcv::AttachmentLayout::COLOR_ATTACHMENT,
vkcv::AttachmentLayout::PRESENTATION,
vkcv::AttachmentOperation::STORE, vkcv::AttachmentOperation::STORE,
vkcv::AttachmentOperation::CLEAR, vkcv::AttachmentOperation::CLEAR,
core.getSwapchainImageFormat() core.getSwapchainImageFormat()
); );
const vkcv::AttachmentDescription depth_attachment( const vkcv::AttachmentDescription depth_attachment(
vkcv::AttachmentLayout::UNDEFINED,
vkcv::AttachmentLayout::DEPTH_STENCIL_ATTACHMENT,
vkcv::AttachmentLayout::DEPTH_STENCIL_ATTACHMENT,
vkcv::AttachmentOperation::STORE, vkcv::AttachmentOperation::STORE,
vkcv::AttachmentOperation::CLEAR, vkcv::AttachmentOperation::CLEAR,
vk::Format::eD32Sfloat vk::Format::eD32Sfloat
...@@ -100,17 +94,10 @@ int main(int argc, const char** argv) { ...@@ -100,17 +94,10 @@ int main(int argc, const char** argv) {
return static_cast<uint32_t>(x.type) < static_cast<uint32_t>(y.type); return static_cast<uint32_t>(x.type) < static_cast<uint32_t>(y.type);
}); });
vkcv::DescriptorSetConfig setConfig({ std::vector<vkcv::DescriptorBinding> descriptorBindings = {
vkcv::DescriptorBinding(vkcv::DescriptorType::IMAGE_SAMPLED, 1, vkcv::ShaderStage::FRAGMENT), vkcv::DescriptorBinding(vkcv::DescriptorType::IMAGE_SAMPLED, 1, vkcv::ShaderStage::FRAGMENT),
vkcv::DescriptorBinding(vkcv::DescriptorType::SAMPLER, 1, vkcv::ShaderStage::FRAGMENT) vkcv::DescriptorBinding(vkcv::DescriptorType::SAMPLER, 1, vkcv::ShaderStage::FRAGMENT) };
}); vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorBindings);
vkcv::DescriptorSetHandle set = core.createDescriptorSet({ setConfig });
//only exemplary code for testing
for (int i = 0; i < 1001; i++) {
vkcv::DescriptorSetHandle furtherSets = core.createDescriptorSet({ setConfig });
}
//end of exemplary code
const vkcv::PipelineConfig trianglePipelineDefinition( const vkcv::PipelineConfig trianglePipelineDefinition(
triangleShaderProgram, triangleShaderProgram,
...@@ -118,7 +105,7 @@ int main(int argc, const char** argv) { ...@@ -118,7 +105,7 @@ int main(int argc, const char** argv) {
UINT32_MAX, UINT32_MAX,
trianglePass, trianglePass,
mesh.vertexGroups[0].vertexBuffer.attributes, mesh.vertexGroups[0].vertexBuffer.attributes,
{ core.getDescriptorSet(set, 0) }, { core.getDescriptorSet(descriptorSet).layout },
true); true);
vkcv::PipelineHandle trianglePipeline = core.createGraphicsPipeline(trianglePipelineDefinition); vkcv::PipelineHandle trianglePipeline = core.createGraphicsPipeline(trianglePipelineDefinition);
...@@ -137,16 +124,16 @@ int main(int argc, const char** argv) { ...@@ -137,16 +124,16 @@ int main(int argc, const char** argv) {
vkcv::SamplerAddressMode::REPEAT vkcv::SamplerAddressMode::REPEAT
); );
std::vector<vkcv::VertexBufferBinding> vertexBufferBindings = { const std::vector<vkcv::VertexBufferBinding> vertexBufferBindings = {
{ mesh.vertexGroups[0].vertexBuffer.attributes[0].offset, vertexBuffer.getHandle() }, vkcv::VertexBufferBinding( mesh.vertexGroups[0].vertexBuffer.attributes[0].offset, vertexBuffer.getVulkanHandle() ),
{ mesh.vertexGroups[0].vertexBuffer.attributes[1].offset, vertexBuffer.getHandle() }, vkcv::VertexBufferBinding( mesh.vertexGroups[0].vertexBuffer.attributes[1].offset, vertexBuffer.getVulkanHandle() ),
{ mesh.vertexGroups[0].vertexBuffer.attributes[2].offset, vertexBuffer.getHandle() } vkcv::VertexBufferBinding( mesh.vertexGroups[0].vertexBuffer.attributes[2].offset, vertexBuffer.getVulkanHandle() )
}; };
vkcv::DescriptorWrites setWrites; vkcv::DescriptorWrites setWrites;
setWrites.sampledImageWrites = { vkcv::SampledImageDescriptorWrite(0, texture.getHandle()) }; setWrites.sampledImageWrites = { vkcv::SampledImageDescriptorWrite(0, texture.getHandle()) };
setWrites.samplerWrites = { vkcv::SamplerDescriptorWrite(1, sampler) }; setWrites.samplerWrites = { vkcv::SamplerDescriptorWrite(1, sampler) };
core.writeResourceDescription(set, 0, setWrites); core.writeResourceDescription(descriptorSet, 0, setWrites);
vkcv::ImageHandle depthBuffer = core.createImage(vk::Format::eD32Sfloat, windowWidth, windowHeight).getHandle(); vkcv::ImageHandle depthBuffer = core.createImage(vk::Format::eD32Sfloat, windowWidth, windowHeight).getHandle();
...@@ -156,6 +143,11 @@ int main(int argc, const char** argv) { ...@@ -156,6 +143,11 @@ int main(int argc, const char** argv) {
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle(); const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
const vkcv::Mesh renderMesh(vertexBufferBindings, indexBuffer.getVulkanHandle(), mesh.vertexGroups[0].numIndices);
vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(descriptorSet).vulkanHandle);
vkcv::DrawcallInfo drawcall(renderMesh, { descriptorUsage });
auto start = std::chrono::system_clock::now(); auto start = std::chrono::system_clock::now();
while (window.isWindowOpen()) { while (window.isWindowOpen()) {
vkcv::Window::pollEvents(); vkcv::Window::pollEvents();
...@@ -170,17 +162,20 @@ int main(int argc, const char** argv) { ...@@ -170,17 +162,20 @@ int main(int argc, const char** argv) {
cameraManager.getCamera().updateView(std::chrono::duration<double>(deltatime).count()); cameraManager.getCamera().updateView(std::chrono::duration<double>(deltatime).count());
const glm::mat4 mvp = cameraManager.getCamera().getProjection() * cameraManager.getCamera().getView(); const glm::mat4 mvp = cameraManager.getCamera().getProjection() * cameraManager.getCamera().getView();
vkcv::PushConstantData pushConstantData((void*)&mvp, sizeof(glm::mat4));
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
core.recordDrawcallsToCmdStream( core.recordDrawcallsToCmdStream(
cmdStream,
trianglePass, trianglePass,
trianglePipeline, trianglePipeline,
sizeof(mvp), pushConstantData,
&mvp, { drawcall },
vertexBufferBindings, renderTargets);
indexBuffer.getHandle(), core.prepareSwapchainImageForPresent(cmdStream);
mesh.vertexGroups[0].numIndices, core.submitCommandStream(cmdStream);
set,
0,
{ swapchainInput, depthBuffer });
core.endFrame(); core.endFrame();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment