include/mgba/internal/ds/gx/software.h (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef DS_GX_SOFTWARE_H
7#define DS_GX_SOFTWARE_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/internal/ds/gx.h>
14#include <mgba/internal/ds/video.h>
15#include <mgba-util/table.h>
16#include <mgba-util/vector.h>
17
18struct DSGXSoftwarePolygon {
19 struct DSGXPolygon* poly;
20 uint16_t* texBase;
21 uint16_t* palBase;
22 int texFormat;
23 int blendFormat;
24 int texW;
25 int texH;
26};
27
28struct DSGXSoftwareEdge {
29 unsigned polyId;
30 int32_t y0; // 20.12
31 int32_t x0; // 20.12
32 int32_t z0; // 20.12
33 int32_t w0; // 20.12
34 uint8_t cr0;
35 uint8_t cg0;
36 uint8_t cb0;
37 int16_t s0;
38 int16_t t0;
39
40 int32_t y1; // 20.12
41 int32_t x1; // 20.12
42 int32_t z1; // 20.12
43 int32_t w1; // 20.12
44 uint8_t cr1;
45 uint8_t cg1;
46 uint8_t cb1;
47 int16_t s1;
48 int16_t t1;
49};
50
51struct DSGXSoftwareEndpoint {
52 int32_t coord[4]; // 20.12
53 int64_t wRecip;
54 uint8_t cr;
55 uint8_t cg;
56 uint8_t cb;
57 int16_t s;
58 int16_t t;
59
60 int64_t stepZ;
61 int64_t stepW;
62 int64_t stepR;
63 int64_t stepG;
64 int64_t stepB;
65 int64_t stepS;
66 int64_t stepT;
67};
68
69struct DSGXSoftwareSpan {
70 struct DSGXSoftwarePolygon* poly;
71 int polyId;
72 struct DSGXSoftwareEndpoint ep[2];
73 struct DSGXSoftwareEndpoint step;
74};
75
76DECLARE_VECTOR(DSGXSoftwarePolygonList, struct DSGXSoftwarePolygon);
77DECLARE_VECTOR(DSGXSoftwareEdgeList, struct DSGXSoftwareEdge);
78DECLARE_VECTOR(DSGXSoftwareSpanList, struct DSGXSoftwareSpan);
79
80struct DSGXSoftwareRenderer {
81 struct DSGXRenderer d;
82
83 struct DSGXSoftwarePolygonList activePolys;
84 struct DSGXSoftwareEdgeList activeEdges;
85 struct DSGXSoftwareSpanList activeSpans;
86 struct DSGXSoftwareSpan** bucket;
87
88 int32_t depthBuffer[DS_VIDEO_HORIZONTAL_PIXELS];
89 uint8_t stencilBuffer[DS_VIDEO_HORIZONTAL_PIXELS];
90 color_t* scanlineCache;
91 bool flushPending;
92 int sort;
93
94 struct DSGXVertex* verts;
95};
96
97void DSGXSoftwareRendererCreate(struct DSGXSoftwareRenderer* renderer);
98
99CXX_GUARD_END
100
101#endif