openMSX
ScalerFactory.cc
Go to the documentation of this file.
1 #include "ScalerFactory.hh"
2 #include "RenderSettings.hh"
3 #include "EnumSetting.hh"
4 #include "IntegerSetting.hh"
5 #include "Simple2xScaler.hh"
6 #include "Simple3xScaler.hh"
7 #include "SaI2xScaler.hh" // note: included even if MAX_SCALE_FACTOR == 1
8 #include "SaI3xScaler.hh"
9 #include "Scale2xScaler.hh"
10 #include "Scale3xScaler.hh"
11 #include "HQ2xScaler.hh"
12 #include "HQ3xScaler.hh"
13 #include "HQ2xLiteScaler.hh"
14 #include "HQ3xLiteScaler.hh"
15 #include "RGBTriplet3xScaler.hh"
16 #include "MLAAScaler.hh"
17 #include "Scaler1.hh"
18 #include "unreachable.hh"
19 #include "build-info.hh"
20 #include <cstdint>
21 #include <memory>
22 
23 using std::unique_ptr;
24 
25 namespace openmsx {
26 
27 template <class Pixel>
28 unique_ptr<Scaler<Pixel>> ScalerFactory<Pixel>::createScaler(
29  const PixelOperations<Pixel>& pixelOps, RenderSettings& renderSettings)
30 {
31  switch (renderSettings.getScaleFactor()) {
32 #if (MIN_SCALE_FACTOR <= 1) && (MAX_SCALE_FACTOR >= 1)
33  case 1:
34  return std::make_unique<Scaler1<Pixel>>(pixelOps);
35 #endif
36 #if (MIN_SCALE_FACTOR <= 2) && (MAX_SCALE_FACTOR >= 2)
37  case 2:
38  switch (renderSettings.getScaleAlgorithm()) {
40  return std::make_unique<Simple2xScaler<Pixel>>(
41  pixelOps, renderSettings);
43  return std::make_unique<SaI2xScaler<Pixel>>(pixelOps);
45  return std::make_unique<Scale2xScaler<Pixel>>(pixelOps);
47  return std::make_unique<HQ2xScaler<Pixel>>(pixelOps);
49  return std::make_unique<HQ2xLiteScaler<Pixel>>(pixelOps);
51  case RenderSettings::SCALER_TV: // fallback
52  return std::make_unique<Simple2xScaler<Pixel>>(
53  pixelOps, renderSettings);
55  return std::make_unique<MLAAScaler<Pixel>>(640, pixelOps);
56  default:
58  }
59 #endif
60 #if (MIN_SCALE_FACTOR <= 4) && (MAX_SCALE_FACTOR >= 3)
61  case 3:
62  case 4: // fallback
63  switch (renderSettings.getScaleAlgorithm()) {
65  return std::make_unique<Simple3xScaler<Pixel>>(
66  pixelOps, renderSettings);
68  return std::make_unique<SaI3xScaler<Pixel>>(pixelOps);
70  return std::make_unique<Scale3xScaler<Pixel>>(pixelOps);
72  return std::make_unique<HQ3xScaler<Pixel>>(pixelOps);
74  return std::make_unique<HQ3xLiteScaler<Pixel>>(pixelOps);
76  case RenderSettings::SCALER_TV: // fallback
77  return std::make_unique<RGBTriplet3xScaler<Pixel>>(
78  pixelOps, renderSettings);
80  return std::make_unique<MLAAScaler<Pixel>>(960, pixelOps);
81  default:
83  }
84 #endif
85  default:
87  }
88  return nullptr; // avoid warning
89 }
90 
91 // Force template instantiation.
92 #if HAVE_16BPP
93 template class ScalerFactory<uint16_t>;
94 #endif
95 #if HAVE_32BPP
96 template class ScalerFactory<uint32_t>;
97 #endif
98 
99 } // namespace openmsx
Abstract base class for scalers.
ScaleAlgorithm getScaleAlgorithm() const
The current scaling algorithm.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
Class containing all settings for renderers.
static std::unique_ptr< Scaler< Pixel > > createScaler(const PixelOperations< Pixel > &pixelOps, RenderSettings &renderSettings)
Instantiates a Scaler.
#define UNREACHABLE
Definition: unreachable.hh:38