aboutsummaryrefslogtreecommitdiff
path: root/src/fb/pixfb.cpp
blob: 10f2d02a6a0e51e618d3c851520cdd8c7862a457 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "fb/pixfb.h"
#include <cstdint>
#include <algorithm>
#include "math/vector.h"
#include "o3d/vertex_data.h"

using namespace engine::fb;

PixelFrameBuffer::PixelFrameBuffer(unsigned int w, unsigned int h) {
    resize(w, h);
}

void PixelFrameBuffer::resize(unsigned int w, unsigned int h) {
    this->w = w;
    this->h = h;
    pixels_vector.resize(w * h);
    clear();
}

unsigned int PixelFrameBuffer::width() const {
    return w;
}

unsigned int PixelFrameBuffer::height() const {
    return h;
}

const uint32_t* PixelFrameBuffer::pixels() const {
    return pixels_vector.data();
}

void PixelFrameBuffer::clear() {
    std::fill(pixels_vector.begin(), pixels_vector.end(), 0x000000FF);
}

void PixelFrameBuffer::draw_point(int x, int y, engine::math::Vector3 loc, const engine::o3d::VertexData& vd) {
    (void) loc;
    int ir = ((int) (((float) ((int) (vd.tx * 10.f))) * 25.5f));
    int ig = ((int) (((float) ((int) (vd.ty * 10.f))) * 25.5f));
    pixels_vector[x + y * w] = (ir << 24) | (ig << 16) | 0xFFFF;
}

uint32_t PixelFrameBuffer::face_color(int face_ind) const {
    int n = face_ind / 2;
    return ((n % 2 ? 0xFF000000 : 0x55000000) >> ((n % 6) / 2 * 8)) | 0xFF;
}