-
Notifications
You must be signed in to change notification settings - Fork 2
/
gpu_3d_renderer.h
88 lines (66 loc) · 2.84 KB
/
gpu_3d_renderer.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Copyright 2019-2020 Hydr8gon
This file is part of NooDS.
NooDS is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NooDS is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with NooDS. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef GPU_3D_RENDERER_H
#define GPU_3D_RENDERER_H
#include <atomic>
#include <cstdint>
#include <thread>
class Core;
struct Vertex;
struct _Polygon;
class Gpu3DRenderer
{
public:
Gpu3DRenderer(Core *core);
~Gpu3DRenderer();
void drawScanline(int line);
uint16_t *getFramebuffer(int line);
uint16_t readDisp3DCnt() { return disp3DCnt; }
void writeDisp3DCnt(uint16_t mask, uint16_t value);
void writeClearColor(uint32_t mask, uint32_t value);
void writeClearDepth(uint16_t mask, uint16_t value);
void writeFogColor(uint32_t mask, uint32_t value);
void writeFogOffset(uint16_t mask, uint16_t value);
void writeFogTable(int index, uint8_t value);
void writeToonTable(int index, uint16_t mask, uint16_t value);
private:
Core *core;
uint16_t framebuffer[256 * 192 * 2] = {};
uint32_t depthBuffer[3][256] = {};
uint8_t attribBuffer[3][256] = {};
uint8_t stencilBuffer[3][256] = {};
bool stencilClear[3] = {};
int activeThreads = 0;
bool ready[192];
uint16_t disp3DCnt = 0;
uint32_t clearColor = 0;
uint16_t clearDepth = 0;
uint32_t fogColor = 0;
uint16_t fogOffset = 0;
uint8_t fogTable[32] = {};
uint16_t toonTable[32] = {};
uint32_t rgba5ToRgba6(uint32_t color);
void drawThreaded(int thread);
void drawScanline1(int line, int thread);
uint8_t *getTexture(uint32_t address);
uint8_t *getPalette(uint32_t address);
uint32_t interpolateLinear(uint32_t v1, uint32_t v2, uint32_t x1, uint32_t x, uint32_t x2);
uint32_t interpolateFill(uint32_t v1, uint32_t v2, uint32_t x1, uint32_t x, uint32_t x2, uint32_t w1, uint32_t w2);
uint32_t interpolateEdge(uint32_t v1, uint32_t v2, uint32_t x1, uint32_t x, uint32_t x2, uint32_t w1, uint32_t w2);
uint32_t interpolateColor(uint32_t c1, uint32_t c2, uint32_t x1, uint32_t x, uint32_t x2);
uint32_t readTexture(_Polygon *polygon, int s, int t);
void drawPolygon(int line, int thread, _Polygon *polygon);
};
#endif // GPU_3D_RENDERER_H