aboutsummaryrefslogtreecommitdiff
path: root/src/shaders/simple_shaders.cpp
blob: af7bb79d467debcf2171e5553806151384987a50 (plain) (blame)
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
#include "shaders/simple_shaders.hpp"
#include <vector>
#include <cstddef>
#include <utility>
#include "math/vector.hpp"
#include "math/mat4.hpp"

using namespace engine::shaders;
using
    engine::math::Vector4,
    engine::math::Matrix4;

SimpleShaders::SimpleShaders(int w, int h, unsigned char* pixels) : w { w }, h { h }, pixels {} {
    this->pixels.reserve(w * h);
    for (size_t i = 0; i < static_cast<std::size_t>(w * h); i++) {
        [&]<std::size_t... j>(std::index_sequence<j...>) {
            this->pixels.emplace_back(static_cast<float>(pixels[i * 4 + j]) / 255.f ...);
        }(std::make_index_sequence<4> {});
    }
}

void SimpleShaders::set_view(const Matrix4& view_mat, const Matrix4& proj_mat) {
    this->view_mat = view_mat;
    this->proj_mat = proj_mat;
}

void SimpleShaders::set_model(const Matrix4& model_mat) {
    this->model_mat = model_mat;
    final_mat = proj_mat * view_mat * model_mat;
}