OXYGENHUB
◆ main openmsx / src / video / SDLRasterizer.hh
4.9 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef SDLRASTERIZER_HH
2
#define SDLRASTERIZER_HH
3
4
#include "BitmapConverter.hh"
5
#include "CharacterConverter.hh"
6
#include "Rasterizer.hh"
7
#include "SpriteConverter.hh"
8
9
#include "Observer.hh"
10
11
#include <array>
12
#include <cstdint>
13
#include <memory>
14
15
namespace openmsx {
16
17
class Display;
18
class VDP;
19
class VDPVRAM;
20
class OutputSurface;
21
class RawFrame;
22
class RenderSettings;
23
class Setting;
24
class PostProcessor;
25
26
/** Rasterizer using a frame buffer approach: it writes pixels to a single
27
  * rectangular pixel buffer.
28
  */
29
class SDLRasterizer final : public Rasterizer
30
                          , private Observer<Setting>
31
{
32
public:
33
	using Pixel = uint32_t;
34
35
	SDLRasterizer(
36
		VDP& vdp, Display& display, OutputSurface& screen,
37
		std::unique_ptr<PostProcessor> postProcessor);
38
	SDLRasterizer(const SDLRasterizer&) = delete;
39
	SDLRasterizer(SDLRasterizer&&) = delete;
40
	SDLRasterizer& operator=(const SDLRasterizer&) = delete;
41
	SDLRasterizer& operator=(SDLRasterizer&&) = delete;
42
	~SDLRasterizer() override;
43
44
	// Rasterizer interface:
45
	[[nodiscard]] PostProcessor* getPostProcessor() const override;
46
	[[nodiscard]] const RawFrame* getWorkingFrame() const override;
47
	[[nodiscard]] const RawFrame* getLastFrame() const override;
48
	[[nodiscard]] bool isActive() override;
49
	void reset() override;
50
	void frameStart(EmuTime time) override;
51
	void frameEnd() override;
52
	void setDisplayMode(DisplayMode mode) override;
53
	void setPalette(unsigned index, int grb) override;
54
	void setBackgroundColor(uint8_t index) override;
55
	void setHorizontalAdjust(int adjust) override;
56
	void setHorizontalScrollLow(uint8_t scroll) override;
57
	void setBorderMask(bool masked) override;
58
	void setTransparency(bool enabled) override;
59
	void setSuperimposeVideoFrame(const RawFrame* videoSource) override;
60
	void drawBorder(int fromX, int fromY, int limitX, int limitY) override;
61
	void drawDisplay(
62
		int fromX, int fromY,
63
		int displayX, int displayY,
64
		int displayWidth, int displayHeight) override;
65
	void drawSprites(
66
		int fromX, int fromY,
67
		int displayX, int displayY,
68
		int displayWidth, int displayHeight) override;
69
	[[nodiscard]] bool isRecording() const override;
70
71
private:
72
	inline void renderBitmapLine(std::span<Pixel> buf, unsigned vramLine);
73
74
	/** Reload entire palette from VDP.
75
	  */
76
	void resetPalette();
77
78
	/** Precalc palette values.
79
	  * For MSX1 VDPs, results go directly into palFg/palBg.
80
	  * For higher VDPs, results go into V9938_COLORS and V9958_COLORS.
81
	  */
82
	void precalcPalette();
83
84
	/** Precalc foreground color index 0 (palFg[0]).
85
	  * @param mode Current display mode.
86
	  * @param transparency True iff transparency is enabled.
87
	  */
88
	void precalcColorIndex0(DisplayMode mode, bool transparency,
89
	                        const RawFrame* superimposing, uint8_t bgcolorIndex);
90
91
	// Get the border color(s). These are 16bpp or 32bpp host pixels.
92
	std::pair<Pixel, Pixel> getBorderColors();
93
94
	// Observer<Setting>
95
	void update(const Setting& setting) noexcept override;
96
97
private:
98
	/** The VDP of which the video output is being rendered.
99
	  */
100
	VDP& vdp;
101
102
	/** The VRAM whose contents are rendered.
103
	  */
104
	VDPVRAM& vram;
105
106
	/** The surface which is visible to the user.
107
	  */
108
	OutputSurface& screen;
109
110
	/** The video post processor which displays the frames produced by this
111
	  *  rasterizer.
112
	  */
113
	const std::unique_ptr<PostProcessor> postProcessor;
114
115
	/** The next frame as it is delivered by the VDP, work in progress.
116
	  */
117
	std::unique_ptr<RawFrame> workFrame;
118
119
	/** The current renderer settings (gamma, brightness, contrast)
120
	  */
121
	RenderSettings& renderSettings;
122
123
	/** VRAM to pixels converter for character display modes.
124
	  */
125
	CharacterConverter characterConverter;
126
127
	/** VRAM to pixels converter for bitmap display modes.
128
	  */
129
	BitmapConverter bitmapConverter;
130
131
	/** VRAM to pixels converter for sprites.
132
	  */
133
	SpriteConverter spriteConverter;
134
135
	/** Line to render at top of display.
136
	  * After all, our screen is 240 lines while display is 262 or 313.
137
	  */
138
	int lineRenderTop;
139
140
	/** Host colors corresponding to each VDP palette entry.
141
	  * palFg has entry 0 set to the current background color.
142
	  *       The 16 first entries are for even pixels, the next 16 are for
143
	  *       odd pixels. Second part is only needed (and guaranteed to be
144
	  *       up-to-date) in Graphics5 mode.
145
	  * palBg has entry 0 set to black.
146
	  */
147
	std::array<Pixel, 16 * 2> palFg;
148
	std::array<Pixel, 16> palBg;
149
150
	/** Host colors corresponding to each Graphic 7 sprite color.
151
	  */
152
	std::array<Pixel, 16> palGraphic7Sprites;
153
154
	/** Precalculated host colors corresponding to each possible V9938 color.
155
	  * Used by updatePalette to adjust palFg and palBg.
156
	  */
157
	std::array<std::array<std::array<Pixel, 8>, 8>, 8> V9938_COLORS;
158
159
	/** Host colors corresponding to the 256 color palette of Graphic7.
160
	  * Used by BitmapConverter.
161
	  */
162
	std::array<Pixel, 256> PALETTE256;
163
164
	/** Host colors corresponding to each possible V9958 color.
165
	  */
166
	std::array<Pixel, 32768> V9958_COLORS;
167
};
168
169
} // namespace openmsx
170
171
#endif