-
Notifications
You must be signed in to change notification settings - Fork 0
/
rasterizer_tile.h
executable file
·65 lines (53 loc) · 1.6 KB
/
rasterizer_tile.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
#pragma once
#include <assert.h>
#include "rasterizer_math.h"
#include <tinystl/allocator.h>
#include <tinystl/vector.h>
namespace stl = tinystl;
// avoiding conditionals https://guru.multimedia.cx/avoiding-branchesifconditionals/
// 96bytes, 24 bytes per priangle
struct ALIGN16 Triangle
{
// x1, x2
// dx1, dx2, dx3
// y123
vec4_t x0, x1, x2;
vec4_t y0, y1, y2;
};
static_assert(sizeof(Triangle) == 96, "this is important");
// 48 bytes per 4 triangles, 12 bytes per triangle
struct TrianglePacked
{
// 24 bytes
uint16_t x0[4];
uint16_t x1[4];
uint16_t x2[4];
// 24 bytes
uint16_t y0[4];
uint16_t y1[4];
uint16_t y2[4];
};
static_assert(sizeof(TrianglePacked) == 48, "this is important");
struct ALIGN16 Tile
{
static constexpr int g_tile_height = 32;
static constexpr int g_tile_width = 128;
vec4i_t m_frame_buffer[g_tile_height];
uint32_t m_mask = 0;
uint32_t m_triangles_drawn_total = 0;
uint32_t m_triangles_drawn_occluder_total = 0;
uint32_t m_triangles_drawn_occludee_total = 0;
uint32_t m_triangles_skipped = 0;
int m_x = 0;
vec4_t m_y;
Tile(int x, int y);
void clear()
{
memset(m_frame_buffer, 0, sizeof(m_frame_buffer));
m_mask = 0;
m_triangles_drawn_total = 0;
m_triangles_drawn_occluder_total = 0;
m_triangles_drawn_occludee_total = 0;
m_triangles_skipped = 0;
}
};