aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gltf.cpp2
-rw-r--r--src/scene.cpp41
-rw-r--r--src/vk-api.cpp2
-rw-r--r--src/vk-renderer.cpp13
4 files changed, 32 insertions, 26 deletions
diff --git a/src/gltf.cpp b/src/gltf.cpp
index 64e5644..537e4e1 100644
--- a/src/gltf.cpp
+++ b/src/gltf.cpp
@@ -118,7 +118,7 @@ void gltf::load_textures(const std::filesystem::path &path) {
const auto &gltf_image = gltf_images[image_index];
auto filepath = (path / gltf_image["uri"].get<std::string>()).string();
auto& image = images[image_index];
- image.data = stbi_load(filepath.c_str(), &image.x, &image.y, &image.n, 4);
+ image.data = stbi_load(filepath.c_str(), &image.x, &image.y, &image.channels, 4);
}
// const auto &gltf_samplers = gltf_json["samplers"];
diff --git a/src/scene.cpp b/src/scene.cpp
index dcbafe3..f560d03 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -118,6 +118,7 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height)
// Add offset to indices in order to have absolute indices
for (const auto& submesh: mesh->get_submeshes()) {
auto vertex_offset = vertices_offset + submesh.vertex_offset;
+ const auto& material = submesh.material;
for (size_t element_index { 0U }; element_index < submesh.element_count; element_index++, index_offset += 3) {
size_t submesh_level_index_1 = mesh_indices[index_offset];
@@ -136,31 +137,31 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height)
auto triangle_offset = triangles_offset * 3 + index_offset;
- indices[triangle_offset] = (submesh_level_index_1 + vertex_offset); // | (0xff000000 & (materials.size() << 8));
- indices[triangle_offset + 1] = (submesh_level_index_2 + vertex_offset); // | (0xff000000 & (materials.size() << 16));
- indices[triangle_offset + 2] = (submesh_level_index_3 + vertex_offset); // | (0xff000000 & (materials.size() << 24));
+ indices[triangle_offset] = (submesh_level_index_1 + vertex_offset) | (0xff000000 & (materials.size() << 8));
+ indices[triangle_offset + 1] = (submesh_level_index_2 + vertex_offset) | (0xff000000 & (materials.size() << 16));
+ indices[triangle_offset + 2] = (submesh_level_index_3 + vertex_offset) | (0xff000000 & (materials.size() << 24));
+ }
- const auto& material = submesh.material;
- const auto& albedo_image = vkrenderer::api.get_image(material.base_color_texture->device_image);
- const auto& albedo_sampler = vkrenderer::api.get_sampler(material.base_color_texture->sampler->device_sampler);
+ const auto& albedo_image = vkrenderer::api.get_image(material.base_color_texture->device_image);
+ const auto& albedo_sampler = vkrenderer::api.get_sampler(material.base_color_texture->sampler->device_sampler);
- materials.emplace_back(gpu_material {
- .base_color = material.base_color,
- .albedo_texture_id = albedo_image.bindless_sampled_index,
- .albedo_texture_sampler_id = albedo_sampler.bindless_index,
- .metalness = material.metalness,
- .roughness = material.roughness
- });
+ materials.emplace_back(gpu_material {
+ .base_color = material.base_color,
+ .albedo_texture_id = albedo_image.bindless_sampled_index,
+ .albedo_texture_sampler_id = albedo_sampler.bindless_index,
+ .metalness = material.metalness,
+ .roughness = material.roughness
+ });
- if (material.metallic_roughness_texture != nullptr) {
- auto& gpu_material = materials.back();
- const auto& metallic_roughness_image = vkrenderer::api.get_image(material.metallic_roughness_texture->device_image);
- const auto& metallic_roughness_sampler = vkrenderer::api.get_sampler(material.metallic_roughness_texture->sampler->device_sampler);
+ if (material.metallic_roughness_texture != nullptr) {
+ auto& gpu_material = materials.back();
+ const auto& metallic_roughness_image = vkrenderer::api.get_image(material.metallic_roughness_texture->device_image);
+ const auto& metallic_roughness_sampler = vkrenderer::api.get_sampler(material.metallic_roughness_texture->sampler->device_sampler);
- gpu_material.metallic_roughness_texture_id = metallic_roughness_image.bindless_sampled_index;
- gpu_material.metallic_roughness_texture_sampler_id = metallic_roughness_sampler.bindless_index;
- }
+ gpu_material.metallic_roughness_texture_id = metallic_roughness_image.bindless_sampled_index;
+ gpu_material.metallic_roughness_texture_sampler_id = metallic_roughness_sampler.bindless_index;
}
+
}
triangles_offset += mesh->triangle_count();
diff --git a/src/vk-api.cpp b/src/vk-api.cpp
index cb9ec0a..60ab6d4 100644
--- a/src/vk-api.cpp
+++ b/src/vk-api.cpp
@@ -201,7 +201,7 @@ void vkapi::copy_buffer(VkCommandBuffer cmd_buf, handle src, handle dst, size_t
}
// TODO: Change handle type, here we don't know what type of ressources we are working with
-void vkapi::copy_buffer(VkCommandBuffer cmd_buf, handle src, handle dst, off_t buffer_offset) {
+void vkapi::copy_buffer(VkCommandBuffer cmd_buf, handle src, handle dst, size_t size, size_t buffer_offset) {
auto& dst_image = images[dst];
VkImageSubresourceLayers image_subresource_layers = {};
diff --git a/src/vk-renderer.cpp b/src/vk-renderer.cpp
index 1cbf0be..54c667f 100644
--- a/src/vk-renderer.cpp
+++ b/src/vk-renderer.cpp
@@ -106,26 +106,31 @@ void vkrenderer::queue_image_update(Texture* texture) {
}
void vkrenderer::update_images() {
+ if(upload_queue.empty())
+ return;
+
auto* staging_buffer = staging_buffers[virtual_frame_index];
+ staging_buffer->reset();
VkCommandBuffer command_buffer = copy_command_buffers[virtual_frame_index];
vkrenderer::api.start_record(command_buffer);
while(!upload_queue.empty()) {
auto* texture = upload_queue.back();
- upload_queue.pop_back();
auto texture_size = texture->size();
auto offset = staging_buffer->alloc(texture_size);
- if (offset == RingBuffer::invalid_alloc) {
+ if (offset == RingBuffer::invalid_alloc)
break;
- }
+
+ upload_queue.pop_back();
staging_buffer->write(texture->data, offset, texture_size);
vkrenderer::api.image_barrier(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, texture->device_image);
- vkrenderer::api.copy_buffer(command_buffer, staging_buffer->device_buffer, texture->device_image, offset);
+ vkrenderer::api.copy_buffer(command_buffer, staging_buffer->device_buffer, texture->device_image, 0, offset);
vkrenderer::api.image_barrier(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, texture->device_image);
+ break;
}
vkrenderer::api.end_record(command_buffer);