Skip to content

Commit

Permalink
WIP: save work.
Browse files Browse the repository at this point in the history
  • Loading branch information
oddkiva committed Nov 30, 2023
1 parent bfb6844 commit 4e3b9b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
2 changes: 0 additions & 2 deletions cpp/examples/Shakti/Vulkan/Common/SignalHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma once

#include "SignalHandler.hpp"


Expand Down
53 changes: 38 additions & 15 deletions cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
#include <DO/Shakti/Vulkan/GraphicsBackend.hpp>
#include <DO/Shakti/Vulkan/Image.hpp>

#include <DO/Sara/Core/DebugUtilities.hpp>

#include <Eigen/Geometry>
#include <DO/Sara/Core/Image.hpp>

#include <filesystem>
#include <limits>
#include <stdexcept>


namespace glfw = DO::Kalpana::GLFW;
Expand Down Expand Up @@ -377,6 +374,38 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
}
}

auto initialize_image() -> void
{
static constexpr auto w = 640;
static constexpr auto h = 480;

namespace sara = DO::Sara;

// Image data on the host.
auto image_host = sara::Image<sara::Rgba8>{w, h};

// Image data as a staging device buffer.
_image_staging_buffer = svk::BufferFactory{_device} //
.make_staging_buffer<std::uint32_t>(w * h);
_image_staging_dmem =
svk::DeviceMemoryFactory{_physical_device, _device} //
.allocate_for_staging_buffer(_image_staging_buffer);
_image_staging_buffer.bind(_image_staging_dmem, 0);
_image_staging_dmem.copy_from(image_host.data(), image_host.size());

// Image data as device image associated with a device memory.
_image =
svk::Image::Builder{_device}
.sizes(VkExtent2D{w, h})
.format(VK_FORMAT_B8G8R8A8_SRGB)
.tiling(VK_IMAGE_TILING_OPTIMAL)
.usage(VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT)
.create();
_image_dmem = svk::DeviceMemoryFactory{_physical_device, _device} //
.allocate_for_device_image(_image);
_image.bind(_image_dmem, 0);
}

auto update_mvp_uniform(const std::uint32_t swapchain_image_index) -> void
{
static auto start_time = std::chrono::high_resolution_clock::now();
Expand All @@ -390,17 +419,6 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
auto mvp = ModelViewProjectionStack{};

mvp.model.rotate(Eigen::AngleAxisf{time, Eigen::Vector3f::UnitZ()});
/*
mvp.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f),
glm::vec3(0.0f, 0.0f, 1.0f));
mvp.view =
glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 1.0f));
mvp.projection = glm::perspective(
glm::radians(45.0f),
swapChainExtent.width / (float) swapChainExtent.height, 0.1f, 10.0f);
ubo.proj[1][1] *= -1;
*/

memcpy(_mvp_ubo_ptrs[swapchain_image_index], &mvp, sizeof(mvp));
}
Expand Down Expand Up @@ -692,7 +710,12 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
std::vector<svk::DeviceMemory> _mvp_dmems;
std::vector<void*> _mvp_ubo_ptrs;

// Image
svk::Buffer _image_staging_buffer;
svk::DeviceMemory _image_staging_dmem;

svk::Image _image;
svk::DeviceMemory _image_dmem;

// 2. Layout binding referenced for the shader.
svk::DescriptorPool _desc_pool;
Expand Down
12 changes: 0 additions & 12 deletions cpp/examples/Shakti/Vulkan/hello_vulkan_triangle/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,7 @@ class VulkanTriangleRenderer : public kvk::GraphicsBackend
.count();

auto mvp = ModelViewProjectionStack{};

mvp.model.rotate(Eigen::AngleAxisf{time, Eigen::Vector3f::UnitZ()});
/*
mvp.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f),
glm::vec3(0.0f, 0.0f, 1.0f));
mvp.view =
glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 1.0f));
mvp.projection = glm::perspective(
glm::radians(45.0f),
swapChainExtent.width / (float) swapChainExtent.height, 0.1f, 10.0f);
ubo.proj[1][1] *= -1;
*/

memcpy(_mvp_ubo_ptrs[swapchain_image_index], &mvp, sizeof(mvp));
}
Expand Down

0 comments on commit 4e3b9b9

Please sign in to comment.