openMSX
SDLRasterizer.hh
Go to the documentation of this file.
1 #ifndef SDLRASTERIZER_HH
2 #define SDLRASTERIZER_HH
3 
4 #include "Rasterizer.hh"
5 #include "BitmapConverter.hh"
6 #include "CharacterConverter.hh"
7 #include "SpriteConverter.hh"
8 #include "Observer.hh"
9 #include "openmsx.hh"
10 #include <memory>
11 
12 namespace openmsx {
13 
14 class Display;
15 class VDP;
16 class VDPVRAM;
17 class OutputSurface;
18 class RawFrame;
19 class RenderSettings;
20 class Setting;
21 class PostProcessor;
22 
26 template <class Pixel>
27 class SDLRasterizer final : public Rasterizer
28  , private Observer<Setting>
29 {
30 public:
31  SDLRasterizer(const SDLRasterizer&) = delete;
32  SDLRasterizer& operator=(const SDLRasterizer&) = delete;
33 
35  VDP& vdp, Display& display, OutputSurface& screen,
36  std::unique_ptr<PostProcessor> postProcessor);
37  ~SDLRasterizer() override;
38 
39  // Rasterizer interface:
40  PostProcessor* getPostProcessor() const override;
41  bool isActive() override;
42  void reset() override;
43  void frameStart(EmuTime::param time) override;
44  void frameEnd() override;
45  void setDisplayMode(DisplayMode mode) override;
46  void setPalette(int index, int grb) override;
47  void setBackgroundColor(int index) override;
48  void setHorizontalAdjust(int adjust) override;
49  void setHorizontalScrollLow(byte scroll) override;
50  void setBorderMask(bool masked) override;
51  void setTransparency(bool enabled) override;
52  void setSuperimposeVideoFrame(const RawFrame* videoSource) override;
53  void drawBorder(int fromX, int fromY, int limitX, int limitY) override;
54  void drawDisplay(
55  int fromX, int fromY,
56  int displayX, int displayY,
57  int displayWidth, int displayHeight) override;
58  void drawSprites(
59  int fromX, int fromY,
60  int displayX, int displayY,
61  int displayWidth, int displayHeight) override;
62  bool isRecording() const override;
63 
64 private:
65  inline void renderBitmapLine(Pixel* buf, unsigned vramLine);
66 
69  void resetPalette();
70 
75  void precalcPalette();
76 
81  void precalcColorIndex0(DisplayMode mode, bool transparency,
82  const RawFrame* superimposing, byte bgcolorIndex);
83 
84  // Some of the border-related settings changed.
85  void borderSettingChanged();
86 
87  // Get the border color(s). These are 16bpp or 32bpp host pixels.
88  void getBorderColors(Pixel& border0, Pixel& border1);
89 
90  // Observer<Setting>
91  void update(const Setting& setting) override;
92 
95  VDP& vdp;
96 
99  VDPVRAM& vram;
100 
103  OutputSurface& screen;
104 
108  const std::unique_ptr<PostProcessor> postProcessor;
109 
112  std::unique_ptr<RawFrame> workFrame;
113 
116  RenderSettings& renderSettings;
117 
120  CharacterConverter<Pixel> characterConverter;
121 
124  BitmapConverter<Pixel> bitmapConverter;
125 
128  SpriteConverter<Pixel> spriteConverter;
129 
133  int lineRenderTop;
134 
142  Pixel palFg[16 * 2], palBg[16];
143 
146  Pixel palGraphic7Sprites[16];
147 
151  Pixel V9938_COLORS[8][8][8];
152 
156  Pixel PALETTE256[256];
157 
160  Pixel V9958_COLORS[32768];
161 
162  // True iff left/right border optimization can (still) be applied
163  // this frame.
164  bool canSkipLeftRightBorders;
165 
166  // True iff some of the left/right border related settings changed
167  // during this frame (meaning the border pixels of this frame cannot
168  // be reused for future frames).
169  bool mixedLeftRightBorders;
170 };
171 
172 } // namespace openmsx
173 
174 #endif
openmsx::VDPVRAM
Manages VRAM contents and synchronises the various users of the VRAM.
Definition: VDPVRAM.hh:384
openmsx::adjust
constexpr AdjustTables adjust
Definition: Y8950.cc:204
openmsx.hh
openmsx::SpriteConverter
Utility class for converting VRAM contents to host pixels.
Definition: SpriteConverter.hh:19
openmsx::SDLRasterizer::setSuperimposeVideoFrame
void setSuperimposeVideoFrame(const RawFrame *videoSource) override
Definition: SDLRasterizer.cc:145
openmsx::Rasterizer
Definition: Rasterizer.hh:12
openmsx::VDPVRAM
VDPVRAM
Definition: VDPVRAM.cc:343
openmsx::SDLRasterizer::setDisplayMode
void setDisplayMode(DisplayMode mode) override
Precalc several values that depend on the display mode.
Definition: SDLRasterizer.cc:221
openmsx::SDLRasterizer::frameStart
void frameStart(EmuTime::param time) override
Indicates the start of a new frame.
Definition: SDLRasterizer.cc:153
openmsx::VDP
Unified implementation of MSX Video Display Processors (VDPs).
Definition: VDP.hh:61
openmsx::RenderSettings
Class containing all settings for renderers.
Definition: RenderSettings.hh:21
openmsx::SDLRasterizer::isActive
bool isActive() override
Will the output of this Rasterizer be displayed? There is no point in producing a frame that will not...
Definition: SDLRasterizer.cc:116
openmsx::SDLRasterizer::setHorizontalAdjust
void setHorizontalAdjust(int adjust) override
Definition: SDLRasterizer.cc:263
openmsx::SDLRasterizer::drawBorder
void drawBorder(int fromX, int fromY, int limitX, int limitY) override
Render a rectangle of border pixels on the host screen.
Definition: SDLRasterizer.cc:444
BitmapConverter.hh
openmsx::Setting
Definition: Setting.hh:119
openmsx::DisplayMode
Represents a VDP display mode.
Definition: DisplayMode.hh:14
openmsx::SDLRasterizer::isRecording
bool isRecording() const override
Is video recording active?
Definition: SDLRasterizer.cc:677
SpriteConverter.hh
openmsx::SDLRasterizer
Rasterizer using a frame buffer approach: it writes pixels to a single rectangular pixel buffer.
Definition: SDLRasterizer.hh:27
openmsx::Pixel
uint32_t Pixel
Definition: GLHQLiteScaler.cc:93
Observer.hh
openmsx::CharacterConverter
Utility class for converting VRAM contents to host pixels.
Definition: CharacterConverter.hh:16
openmsx::SDLRasterizer::drawDisplay
void drawDisplay(int fromX, int fromY, int displayX, int displayY, int displayWidth, int displayHeight) override
Render a rectangle of display pixels on the host screen.
Definition: SDLRasterizer.cc:487
openmsx::SDLRasterizer::~SDLRasterizer
~SDLRasterizer() override
Definition: SDLRasterizer.cc:101
openmsx::SDLRasterizer::getPostProcessor
PostProcessor * getPostProcessor() const override
See VDP::getPostProcessor().
Definition: SDLRasterizer.cc:110
openmsx::SDLRasterizer::setBorderMask
void setBorderMask(bool masked) override
Definition: SDLRasterizer.cc:275
openmsx::PostProcessor
Abstract base class for post processors.
Definition: PostProcessor.hh:29
openmsx::SDLRasterizer::reset
void reset() override
Resynchronize with VDP: all cached states are flushed.
Definition: SDLRasterizer.cc:124
openmsx::RawFrame
A video frame as output by the VDP scanline conversion unit, before any postprocessing filters are ap...
Definition: RawFrame.hh:25
Rasterizer.hh
openmsx::SDLRasterizer::setTransparency
void setTransparency(bool enabled) override
Definition: SDLRasterizer.cc:281
openmsx::SDLRasterizer::operator=
SDLRasterizer & operator=(const SDLRasterizer &)=delete
openmsx::VDP
VDP
Definition: VDP.cc:1918
openmsx::SDLRasterizer::frameEnd
void frameEnd() override
Indicates the end of the current frame.
Definition: SDLRasterizer.cc:186
openmsx::Display
Represents the output window/screen of openMSX.
Definition: Display.hh:31
openmsx::OutputSurface
A frame buffer where pixels can be written to.
Definition: OutputSurface.hh:19
openmsx::SDLRasterizer::setHorizontalScrollLow
void setHorizontalScrollLow(byte scroll) override
Definition: SDLRasterizer.cc:269
CharacterConverter.hh
openmsx::SDLRasterizer::setBackgroundColor
void setBackgroundColor(int index) override
Changes the background color.
Definition: SDLRasterizer.cc:253
openmsx::BitmapConverter
Utility class for converting VRAM contents to host pixels.
Definition: BitmapConverter.hh:17
openmsx::SDLRasterizer::setPalette
void setPalette(int index, int grb) override
Change an entry in the palette.
Definition: SDLRasterizer.cc:238
openmsx::SDLRasterizer::SDLRasterizer
SDLRasterizer(const SDLRasterizer &)=delete
openmsx::SDLRasterizer::drawSprites
void drawSprites(int fromX, int fromY, int displayX, int displayY, int displayWidth, int displayHeight) override
Render a rectangle of sprite pixels on the host screen.
Definition: SDLRasterizer.cc:619
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::Observer
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:9