-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframebuffer.h
More file actions
30 lines (28 loc) · 781 Bytes
/
Copy pathframebuffer.h
File metadata and controls
30 lines (28 loc) · 781 Bytes
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
// SPDX-License-Identifier: MIT
#pragma once
#include <cstdint>
#include <limits>
#include <string>
#include <vector>
namespace renderer {
struct Color {
std::uint8_t r{}, g{}, b{};
bool operator==(const Color&) const = default;
};
class Framebuffer {
public:
Framebuffer(int width, int height);
int width() const { return width_; }
int height() const { return height_; }
bool contains(int x, int y) const;
bool write(int x, int y, float depth, Color color);
Color color(int x, int y) const;
float depth(int x, int y) const;
void save(const std::string& path) const;
private:
int width_, height_;
std::vector<Color> colors_;
std::vector<float> depths_;
std::size_t index(int x, int y) const;
};
} // namespace renderer