OXYGENHUB
◆ main openmsx / src / video / Renderer.hh
7.7 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef RENDERER_HH
2
#define RENDERER_HH
3
4
#include "VRAMObserver.hh"
5
6
#include <array>
7
#include <cstdint>
8
9
namespace openmsx {
10
11
class PostProcessor;
12
class DisplayMode;
13
class RawFrame;
14
15
/** Abstract base class for Renderers.
16
  * A Renderer is a class that converts VDP state to visual
17
  * information (for example, pixels on a screen).
18
  *
19
  * The update methods are called exactly before the change occurs in
20
  * the VDP, so that the renderer can update itself to the specified
21
  * time using the old settings.
22
  */
23
class Renderer : public VRAMObserver
24
{
25
public:
26
	virtual ~Renderer() = default;
27
28
	/** See VDP::getPostProcessor. */
29
	[[nodiscard]] virtual PostProcessor* getPostProcessor() const = 0;
30
31
	/** See VDP::getWorkingFrame() and VDP::getLastFrame() */
32
	[[nodiscard]] virtual const RawFrame* getWorkingFrame(EmuTime time) = 0;
33
	[[nodiscard]] virtual const RawFrame* getLastFrame() const = 0;
34
35
	/** Reinitialize Renderer state.
36
	  */
37
	virtual void reInit() = 0;
38
39
	/** Signals the start of a new frame.
40
	  * The Renderer can use this to get fixed-per-frame settings from
41
	  * the VDP, such as PAL/NTSC timing.
42
	  * @param time The moment in emulated time the frame starts.
43
	  */
44
	virtual void frameStart(EmuTime time) = 0;
45
46
	/** Signals the end of a frame.
47
	  * @param time The moment in emulated time the frame ends.
48
	  *   Note: this is the same time stamp as the start of the next frame.
49
	  */
50
	virtual void frameEnd(EmuTime time) = 0;
51
52
	/** Informs the renderer of a VDP transparency enable/disable change.
53
	  * @param enabled The new transparency state.
54
	  * @param time The moment in emulated time this change occurs.
55
	  */
56
	virtual void updateTransparency(bool enabled, EmuTime time) = 0;
57
58
	/** Informs the renderer of a VDP superimposing change.
59
	  * @param videoSource Video that should be superimposed, nullptr if none.
60
	  * @param time The moment in emulated time this change occurs.
61
	  */
62
	virtual void updateSuperimposing(const RawFrame* videoSource,
63
	                                 EmuTime time) = 0;
64
65
	/** Informs the renderer of a VDP foreground color change.
66
	  * @param color The new foreground color.
67
	  * @param time The moment in emulated time this change occurs.
68
	  */
69
	virtual void updateForegroundColor(uint8_t color, EmuTime time) = 0;
70
71
	/** Informs the renderer of a VDP background color change.
72
	  * @param color The new background color.
73
	  * @param time The moment in emulated time this change occurs.
74
	  */
75
	virtual void updateBackgroundColor(uint8_t color, EmuTime time) = 0;
76
77
	/** Informs the renderer of a VDP blink foreground color change.
78
	  * @param color The new blink foreground color.
79
	  * @param time The moment in emulated time this change occurs.
80
	  */
81
	virtual void updateBlinkForegroundColor(uint8_t color, EmuTime time) = 0;
82
83
	/** Informs the renderer of a VDP blink background color change.
84
	  * @param color The new blink background color.
85
	  * @param time The moment in emulated time this change occurs.
86
	  */
87
	virtual void updateBlinkBackgroundColor(uint8_t color, EmuTime time) = 0;
88
89
	/** Informs the renderer of a VDP blinking state change.
90
	  * @param enabled The new blink state.
91
	  * @param time The moment in emulated time this change occurs.
92
	  */
93
	virtual void updateBlinkState(bool enabled, EmuTime time) = 0;
94
95
	/** Informs the renderer of a VDP palette change.
96
	  * @param index The index [0..15] in the palette that changes.
97
	  * @param grb The new definition for the changed palette index:
98
	  *   bit 10..8 is green, bit 6..4 is red and bit 2..0 is blue;
99
	  *   all other bits are zero.
100
	  * @param time The moment in emulated time this change occurs.
101
	  */
102
	virtual void updatePalette(unsigned index, int grb, EmuTime time) = 0;
103
104
	/** Informs the renderer of a vertical scroll change.
105
	  * @param scroll The new scroll value.
106
	  * @param time The moment in emulated time this change occurs.
107
	  */
108
	virtual void updateVerticalScroll(int scroll, EmuTime time) = 0;
109
110
	/** Informs the renderer of a horizontal scroll change:
111
	  * the lower scroll value has changed.
112
	  * @param scroll The new scroll value.
113
	  * @param time The moment in emulated time this change occurs.
114
	  */
115
	virtual void updateHorizontalScrollLow(uint8_t scroll, EmuTime time) = 0;
116
117
	/** Informs the renderer of a horizontal scroll change:
118
	  * the higher scroll value has changed.
119
	  * @param scroll The new scroll value.
120
	  * @param time The moment in emulated time this change occurs.
121
	  */
122
	virtual void updateHorizontalScrollHigh(uint8_t scroll, EmuTime time) = 0;
123
124
	/** Informs the renderer of a horizontal scroll change:
125
	  * the border mask has been enabled/disabled.
126
	  * @param masked true iff enabled.
127
	  * @param time The moment in emulated time this change occurs.
128
	  */
129
	virtual void updateBorderMask(bool masked, EmuTime time) = 0;
130
131
	/** Informs the renderer of a horizontal scroll change:
132
	  * the multi page setting has changed.
133
	  * @param multiPage The new multi page flag.
134
	  * @param time The moment in emulated time this change occurs.
135
	  */
136
	virtual void updateMultiPage(bool multiPage, EmuTime time) = 0;
137
138
	/** Informs the renderer of a horizontal adjust change.
139
	  * Note that there is no similar method for vertical adjust updates:
140
	  * vertical adjust only takes effect when the display line counter is
141
	  * reset, see updateLineZero().
142
	  * @param adjust The new adjust value.
143
	  * @param time The moment in emulated time this change occurs.
144
	  */
145
	virtual void updateHorizontalAdjust(int adjust, EmuTime time) = 0;
146
147
	/** Informs the renderer that the display line counter is reset, which
148
	  * moves display line zero (see VDP::getLineZero()). Lines before this
149
	  * moment must be rendered against the old line zero.
150
	  * @param time The moment in emulated time this change occurs.
151
	  */
152
	virtual void updateLineZero(EmuTime time) = 0;
153
154
	/** Informs the renderer of a VDP display enabled change.
155
	  * Both the regular border start/end and forced blanking by clearing
156
	  * the display enable bit are considered display enabled changes.
157
	  * @param enabled The new display enabled state.
158
	  * @param time The moment in emulated time this change occurs.
159
	  */
160
	virtual void updateDisplayEnabled(bool enabled, EmuTime time) = 0;
161
162
	/** Informs the renderer of a VDP display mode change.
163
	  * @param mode The new display mode.
164
	  * @param time The moment in emulated time this change occurs.
165
	  */
166
	virtual void updateDisplayMode(DisplayMode mode, EmuTime time) = 0;
167
168
	/** Informs the renderer of a name table base address change.
169
	  * @param addr The new base address.
170
	  * @param time The moment in emulated time this change occurs.
171
	  */
172
	virtual void updateNameBase(unsigned addr, EmuTime time) = 0;
173
174
	/** Informs the renderer of a pattern table base address change.
175
	  * @param addr The new base address.
176
	  * @param time The moment in emulated time this change occurs.
177
	  */
178
	virtual void updatePatternBase(unsigned addr, EmuTime time) = 0;
179
180
	/** Informs the renderer of a color table base address change.
181
	  * @param addr The new base address.
182
	  * @param time The moment in emulated time this change occurs.
183
	  */
184
	virtual void updateColorBase(unsigned addr, EmuTime time) = 0;
185
186
	/** Informs the renderer of a VDP sprites enabled change.
187
	  * @param enabled The new sprites enabled state.
188
	  * @param time The moment in emulated time this change occurs.
189
	  */
190
	virtual void updateSpritesEnabled(bool enabled, EmuTime time) = 0;
191
192
	/** Sprite palette in Graphic 7 mode.
193
          * See page 98 of the V9938 data book.
194
	  * Each palette entry is a word in GRB format:
195
	  * bit 10..8 is green, bit 6..4 is red and bit 2..0 is blue.
196
	  */
197
	static constexpr std::array<uint16_t, 16> GRAPHIC7_SPRITE_PALETTE = {
198
		0x000, 0x002, 0x030, 0x032, 0x300, 0x302, 0x330, 0x332,
199
		0x472, 0x007, 0x070, 0x077, 0x700, 0x707, 0x770, 0x777,
200
	};
201
202
protected:
203
	Renderer() = default;
204
};
205
206
} // namespace openmsx
207
208
#endif