summary refs log tree commit diff
path: root/src/Util/ImageViewer.cpp
blob: abb22d4e4b88a58718f8a699a6b4952a477ce80f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "ImageViewer.hpp"

namespace MC::Util {

void ImageViewer::render(GFX::Actions& actions) {
    // TODO: Re-add texture support
    // TODO: Add orthographic camera support
    actions.add({
        .mesh = &m_mesh,
        .program = GFX::Resources::Program::ImageViewer,
        .transform = Transform(),
    });
}

GFX::Mesh ImageViewer::create_mesh(Real window_aspect, U32 image_width, U32 image_height) {
    auto aspect = (Real)image_width / image_height;
    Real max_size = view_size * 0.8;
    Real width = max_size * std::min(1.0, aspect);
    Real height = max_size * std::min(1.0, 1/aspect);

    Real x = (view_size * window_aspect - width) / 2.0f;
    Real y = (view_size - height) / 2.0f;

    return {{
        std::vector<Vector<3, F32>>{
            {x, y, 0.0f}, // top left
            {x, y + height, 0.0f}, // bottom left
            {x + width, y + height, 0.0f}, // bottom right
            {x + width, y, 0.0f}  // top right
        },
        std::vector<Vector<2, F32>>{
            {0.0f, 0.0f},
            {0.0f, 1.0f},
            {1.0f, 1.0f},
            {1.0f, 0.0f},
        },
    }, {0, 1, 2, 0, 2, 3}};
}

}