-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenderThread.cpp
60 lines (52 loc) · 1.49 KB
/
RenderThread.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// RenderThread.cpp
// Curvature
//
// Created by Simon Demeule on 2019-03-26.
// Copyright © 2019 Simon Demeule. All rights reserved.
//
#include "RenderThread.hpp"
#include "RenderScheduler.hpp"
RenderThread::RenderThread(RenderScheduler* renderScheduler, RenderCore* renderCore, int identifier) :
renderScheduler(renderScheduler),
renderCore(renderCore),
identifier(identifier)
{}
RenderThread::~RenderThread() {
if(!done) {
thread.join();
}
}
void RenderThread::start() {
thread = std::thread(&RenderThread::renderLoop, this);
renderScheduler->debugOut(identifier, "Start");
}
void RenderThread::join() {
thread.join();
renderScheduler->debugOut(identifier, "Join");
}
void RenderThread::renderLoop() {
done = false;
while(!done) {
Tile* tile = renderScheduler->getNextTile();
if(tile == nullptr) {
renderScheduler->debugOut(identifier, "Done");
done = true;
} else {
renderScheduler->debugOut(identifier, "Tile " + std::to_string(tile->index));
renderTile(tile);
}
}
}
void RenderThread::renderTile(Tile* tile) {
// loop top to bottom
for(int y = tile->y; y < tile->y + tile->ySize; y++) {
// loop left to right
for(int x = tile->x; x < tile->x + tile->xSize; x++) {
// render pixel
glm::vec3 color = renderCore->colorPixel(x, y);
// write color to tile
tile->write(color, x, y);
}
}
}