summaryrefslogtreecommitdiff
path: root/lib/nes/common/display.hh
blob: ca78a850bd96ce73bedb4e95e8efa2c7042fd13c (plain)
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
#pragma once

#include "nes/common/rgb.hh"

namespace nes
{
	class rgb;

	/// Abstraction of the display logic.
	class display
	{
	public:
		static constexpr auto width = unsigned{ 256 };
		static constexpr auto height = unsigned{ 240 };

		virtual ~display() = default;

		display(display const&) = delete;
		display(display&&) = delete;
		auto operator=(display const&) -> display& = delete;
		auto operator=(display&&) -> display& = delete;

		/// Switch between front and back buffers.
		virtual auto switch_buffers() -> void = 0;
		/// Update the pixel at the given position in the back buffer.
		virtual auto set(unsigned x, unsigned y, rgb value) -> void = 0;
		/// Load the pixel value at the given position in the back buffer.
		virtual auto get(unsigned x, unsigned y) const -> rgb = 0;
		/// Clear the entire back buffer with a color.
		virtual auto clear(rgb const color) -> void
		{
			for (auto y = unsigned{ 0 }; y < height; ++y)
			{
				for (auto x = unsigned{ 0 }; x < width; ++x)
				{
					set(x, y, color);
				}
			}
		}

	protected:
		explicit display() = default;
	};
} // namespace nes