Skip to content

Commit

Permalink
WIP: save work.
Browse files Browse the repository at this point in the history
  • Loading branch information
oddkiva committed Dec 10, 2023
1 parent 7c4da52 commit c6cece7
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ namespace fs = std::filesystem;
//! @brief The 4 vertices of the square.
// clang-format off
static auto vertices = std::vector<Vertex>{
{.pos = {-0.5f, -0.5f}, .uv = {0.f, 0.f}},
{.pos = { 0.5f, -0.5f}, .uv = {1.f, 0.f}},
{.pos = { 0.5f, 0.5f}, .uv = {1.f, 1.f}},
{.pos = {-0.5f, 0.5f}, .uv = {0.f, 1.f}}
{.pos = {-1.0f, -1.0f}, .uv = {0.f, 0.f}},
{.pos = { 1.0f, -1.0f}, .uv = {1.f, 0.f}},
{.pos = { 1.0f, 1.0f}, .uv = {1.f, 1.f}},
{.pos = {-1.0f, 1.0f}, .uv = {0.f, 1.f}}
};
// clang-format on

Expand Down Expand Up @@ -112,20 +112,23 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
_vstream.open(_vpath);
const auto image_host = sara::from_rgb8_to_rgba8(_vstream.frame());

// Rescale the x coordinates of the vertices so that it matches that video
// rectangle aspect ratio.
const auto aspect_ratio =
static_cast<float>(image_host.width()) / image_host.height();
for (auto& vertex : vertices)
vertex.pos.x() *= aspect_ratio;

// Initialize the projection matrix.
{
auto w = int{};
auto h = int{};
glfwGetWindowSize(window, &w, &h);
const auto fb_aspect_ratio = static_cast<float>(w) / h;
_mvp.projection = k::orthographic( //
-0.5f * fb_aspect_ratio, 0.5f * fb_aspect_ratio, //
-0.5f, 0.5f, //
-0.5f, 0.5f);
_mvp.projection = k::orthographic( //
-fb_aspect_ratio, fb_aspect_ratio, //
-1.f, 1.f, //
-1.f, 1.f);
}

// General vulkan context objects.
Expand Down Expand Up @@ -864,6 +867,7 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
{
auto w = int{};
auto h = int{};
glfwGetFramebufferSize(_window, &w, &h);
while (w == 0 || h == 0)
{
glfwGetFramebufferSize(_window, &w, &h);
Expand All @@ -884,11 +888,20 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
init_swapchain(_window);
init_swapchain_fbos();

// const auto fb_aspect_ratio = static_cast<float>(w) / h;
// _mvp.projection = k::orthographic( //
// -0.5f * fb_aspect_ratio, 0.5f * fb_aspect_ratio, //
// -0.5f, 0.5f, //
// -0.5f, 0.5f);
// // This time only modify the view matrix.
// {
// _mvp.view.setIdentity();
// _mvp.view.scale(static_cast<float>(w) / _vstream.width());
// }

// Recalculate the projection matrix.
{
const auto fb_aspect_ratio = static_cast<float>(w) / h;
_mvp.projection = k::orthographic( //
-fb_aspect_ratio, fb_aspect_ratio, //
-1.f, 1.f, //
-1.f, 1.f);
}

SARA_CHECK(_mvp.model.matrix());
SARA_CHECK(_mvp.view.matrix());
Expand Down

0 comments on commit c6cece7

Please sign in to comment.