Skip to content

Commit

Permalink
ENH: check implementation with video.
Browse files Browse the repository at this point in the history
  • Loading branch information
oddkiva committed Dec 6, 2023
1 parent 5a97ce5 commit de4fb31
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target_link_libraries(
PRIVATE SignalHandler #
DO::Sara::Core #
DO::Sara::ImageIO #
DO::Sara::VideoIO #
DO::Shakti::Vulkan)
set_target_properties(hello_vulkan_image PROPERTIES FOLDER
"Examples/Shakti/Vulkan")
Expand Down
25 changes: 21 additions & 4 deletions cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <DO/Sara/Core/Image.hpp>
#include <DO/Sara/ImageIO.hpp>
#include <DO/Sara/VideoIO.hpp>


namespace sara = DO::Sara;
Expand Down Expand Up @@ -120,8 +121,14 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
init_ebos(indices);

// Device memory for image data..
const auto image_fp = program_dir_path / "data" / "dog.jpg";
const auto image_host = sara::imread<sara::Rgba8>(image_fp.string());
// const auto image_fp = program_dir_path / "data" / "dog.jpg";
// const auto image_host = sara::imread<sara::Rgba8>(image_fp.string());

const auto video_fp = std::filesystem::path{
"/home/david/Desktop/Capoeira/thursday/00372.MTS.mp4" //
};
_vstream.open(video_fp.string());
const auto image_host = _vstream.frame().convert<sara::Rgba8>();
init_vulkan_image_objects(image_host);
init_image_copy_command_buffers();
// Initialize the image data on the device side.
Expand All @@ -147,6 +154,14 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();

if (_vstream.read())
{
const auto image_host = _vstream.frame().convert<sara::Rgba8>();
copy_image_data_from_host_to_staging_buffer(image_host);
copy_image_data_from_staging_to_device_buffer();
}

draw_frame();

if (SignalHandler::ctrl_c_hit)
Expand Down Expand Up @@ -439,7 +454,7 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
}

private: /* Methods to initialize image data */
auto init_vulkan_image_objects(const sara::Image<sara::Rgba8>& image_host)
auto init_vulkan_image_objects(const sara::ImageView<sara::Rgba8>& image_host)
-> void
{
// Temporary image object on the host side.
Expand Down Expand Up @@ -496,7 +511,7 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
}

auto copy_image_data_from_host_to_staging_buffer(
const sara::Image<sara::Rgba8>& image_host) -> void
const sara::ImageView<sara::Rgba8>& image_host) -> void
{
// Temporary image object on the host side.
_image_staging_dmem.copy_from(image_host.data(), image_host.size(), 0);
Expand Down Expand Up @@ -797,6 +812,8 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
private:
int _current_frame = 0;

sara::VideoStream _vstream;

// Geometry data (quad)
svk::Buffer _vbo;
svk::DeviceMemory _vdm;
Expand Down

0 comments on commit de4fb31

Please sign in to comment.