Files

47 lines
1.5 KiB
C++
Raw Permalink Normal View History

2026-07-07 03:25:10 -07:00
#pragma once
#include <stdint.h>
#include "datatypes.cpp"
#include "helpers.cpp"
// #include "shader.cpp"
2026-07-07 03:25:10 -07:00
namespace UwU {
// Buffer object - can be a wayland surface or a virtual buffer
class Buffer {
public:
Buffer(uint16_t width, uint16_t height) {
this->pixels = new uint8_t[width * height * 4];
2026-07-07 03:25:10 -07:00
this->width = width;
this->height = height;
this->stride = width * 4;
}
// Buffer(uint8_t* pixels, uint16_t width, uint16_t height, uint16_t stride) {
// this->pixels = pixels;
// this->width = width;
// this->height = height;
// this->stride = stride;
// }
Buffer() {}
uint8_t* pixels;
uint16_t width;
uint16_t height;
uint16_t stride;
2026-07-08 14:34:55 -07:00
void drawPixel(uint16_t x, uint16_t y, Color color) {
// if (color.a == 0) {return;}
2026-07-08 14:34:55 -07:00
size_t i = (size_t)y * stride + (size_t)x * 4;
// uint8_t b0 = pixels[i + 0];
// uint8_t g0 = pixels[i + 1];
// uint8_t r0 = pixels[i + 2];
// uint8_t b = Helpers::lerp8(b0, color.b, color.a);
// uint8_t g = Helpers::lerp8(g0, color.g, color.a);
// uint8_t r = Helpers::lerp8(r0, color.r, color.a);
pixels[i + 0] = color.b; // B
pixels[i + 1] = color.g; // G
pixels[i + 2] = color.r; // R
2026-07-08 14:34:55 -07:00
pixels[i + 3] = 0xff; // A
2026-07-07 03:25:10 -07:00
return;
}
};
}