Explicit threadpooling and framebuffers

This commit is contained in:
Ben
2019-08-28 23:44:46 +01:00
parent 75f54c1717
commit ac331d071b
20 changed files with 320 additions and 186 deletions

View File

@@ -0,0 +1,54 @@
#include "framebuffer.hpp"
#include "../pixel.hpp"
FrameBuffer::FrameBuffer(int xres, int yres) {
XRes = xres; YRes = yres;
Data = (uint32_t*)malloc((xres * yres) * sizeof(uint32_t));
memset((void*)Data, 0, (xres * yres) * sizeof(uint32_t));
}
void FrameBuffer::SetPixel(int x, int y, Pixel p) {
Data[y * this->XRes + x] = p.rgb();
}
void FrameBuffer::SetPixel(int x, int y, uint32_t p) {
Data[y * this->XRes + x] = p;
}
void FrameBuffer::SetPixel(int x, int y, glm::vec3 p) {
Pixel pixel{ (uint8_t)p.r, (uint8_t)p.g, (uint8_t)p.b };
Data[y * this->XRes + x] = pixel.rgb();
}
void FrameBuffer::SetPixelSafe(int x, int y, Pixel p) {
if (x >= 0 && x < this->XRes && y >= 0 && this->YRes) {
Data[y * this->XRes + x] = p.rgb();
}
}
void FrameBuffer::SetPixelSafe(int x, int y, uint32_t p) {
if (x >= 0 && x < this->XRes && y >= 0 && this->YRes) {
Data[y * this->XRes + x] = p;
}
}
void FrameBuffer::SetPixelSafe(int x, int y, glm::vec3 p) {
if (x >= 0 && x < this->XRes && y >= 0 && this->YRes) {
Pixel pixel{ (uint8_t)p.r, (uint8_t)p.g, (uint8_t)p.b };
Data[y * this->XRes + x] = pixel.rgb();
}
}
void FrameBuffer::SetFramebuffer(uint32_t* fb) {
free(Data);
Data = fb;
}
void FrameBuffer::ClearFramebuffer() {
memset((void*)Data, 0, (XRes * YRes) * sizeof(uint32_t));
}
FrameBuffer::~FrameBuffer() {
free(Data);
}