-
Notifications
You must be signed in to change notification settings - Fork 2
/
rasterizer_cpu.hpp
52 lines (43 loc) · 985 Bytes
/
rasterizer_cpu.hpp
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
#pragma once
#include "primitive_setup.hpp"
// A crude implementation which used during bringup.
namespace RetroWarp
{
struct Texel
{
uint8_t r, g, b, a;
};
struct Sampler
{
virtual Texel sample(int u, int v) = 0;
};
struct ROP
{
virtual void emit_pixel(int x, int y, uint16_t z, const Texel &texel) = 0;
};
class RasterizerCPU
{
public:
void render_primitive(const PrimitiveSetup &prim);
void set_scissor(int x, int y, int width, int height);
void set_sampler(Sampler *sampler);
void set_rop(ROP *rop);
private:
Sampler *sampler = nullptr;
ROP *rop = nullptr;
struct
{
int x = 0;
int y = 0;
int width = 1;
int height = 1;
} scissor;
struct FilteredTexel
{
uint16_t r, g, b, a;
};
static FilteredTexel filter_linear_horiz(const Texel &left, const Texel &right, int weight);
static Texel filter_linear_vert(const FilteredTexel &top, const FilteredTexel &bottom, int weight);
static Texel multiply_unorm8(const Texel &left, const Texel &right);
};
}