openMSX
OutputSurface.hh
Go to the documentation of this file.
1 #ifndef OUTPUTSURFACE_HH
2 #define OUTPUTSURFACE_HH
3 
4 #include "PixelFormat.hh"
5 #include "gl_vec.hh"
6 #include <string>
7 #include <cassert>
8 #include <cstdint>
9 
10 namespace openmsx {
11 
20 {
21 public:
22  OutputSurface(const OutputSurface&) = delete;
24 
25  virtual ~OutputSurface() = default;
26 
27  [[nodiscard]] int getLogicalWidth() const { return m_logicalSize[0]; }
28  [[nodiscard]] int getLogicalHeight() const { return m_logicalSize[1]; }
29  [[nodiscard]] gl::ivec2 getLogicalSize() const { return m_logicalSize; }
30  [[nodiscard]] gl::ivec2 getPhysicalSize() const { return m_physSize; }
31 
32  [[nodiscard]] gl::ivec2 getViewOffset() const { return m_viewOffset; }
33  [[nodiscard]] gl::ivec2 getViewSize() const { return m_viewSize; }
34  [[nodiscard]] gl::vec2 getViewScale() const { return m_viewScale; }
35  [[nodiscard]] bool isViewScaled() const { return m_viewScale != gl::vec2(1.0f); }
36 
37  [[nodiscard]] const PixelFormat& getPixelFormat() const { return pixelFormat; }
38 
43  [[nodiscard]] uint32_t mapRGB(gl::vec3 rgb) const
44  {
45  return mapRGB255(gl::ivec3(rgb * 255.0f));
46  }
47 
50  [[nodiscard]] uint32_t mapRGB255(gl::ivec3 rgb) const
51  {
52  auto [r, g, b] = rgb;
53  return getPixelFormat().map(r, g, b);
54  }
55 
58  template<typename Pixel> [[nodiscard]] inline Pixel getKeyColor() const
59  {
60  return sizeof(Pixel) == 2
61  ? 0x0001 // lowest bit of 'some' color component is set
62  : 0x00000000; // alpha = 0
63  }
64 
69  template<typename Pixel> [[nodiscard]] inline Pixel getKeyColorClash() const
70  {
71  assert(sizeof(Pixel) != 4); // shouldn't get clashes in 32bpp
72  return 0; // is visually very close, practically
73  // indistinguishable, from the actual KeyColor
74  }
75 
80  template<typename Pixel> [[nodiscard]] Pixel mapKeyedRGB255(gl::ivec3 rgb)
81  {
82  Pixel p = mapRGB255(rgb);
83  if constexpr (sizeof(Pixel) == 2) {
84  return (p != getKeyColor<Pixel>())
85  ? p
86  : getKeyColorClash<Pixel>();
87  } else {
88  assert(p != getKeyColor<Pixel>());
89  return p;
90  }
91  }
92 
97  template<typename Pixel> [[nodiscard]] Pixel mapKeyedRGB(gl::vec3 rgb)
98  {
99  return mapKeyedRGB255<Pixel>(gl::ivec3(rgb * 255.0f));
100  }
101 
105  virtual void saveScreenshot(const std::string& filename) = 0;
106 
107 protected:
108  OutputSurface() = default;
109 
110  // These two _must_ be called from (each) subclass constructor.
111  void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize);
112  void setPixelFormat(const PixelFormat& format) { pixelFormat = format; }
113  void setOpenGlPixelFormat();
114 
115 private:
116  PixelFormat pixelFormat;
117  gl::ivec2 m_logicalSize;
118  gl::ivec2 m_physSize;
119  gl::ivec2 m_viewOffset;
120  gl::ivec2 m_viewSize;
121  gl::vec2 m_viewScale{1.0f};
122 };
123 
124 } // namespace openmsx
125 
126 #endif
int g
A frame buffer where pixels can be written to.
uint32_t mapRGB255(gl::ivec3 rgb) const
Same as mapRGB, but RGB components are in range [0..255].
const PixelFormat & getPixelFormat() const
gl::ivec2 getPhysicalSize() const
Pixel mapKeyedRGB255(gl::ivec3 rgb)
Returns the pixel value for the given RGB color.
int getLogicalWidth() const
void setPixelFormat(const PixelFormat &format)
OutputSurface & operator=(const OutputSurface &)=delete
gl::vec2 getViewScale() const
gl::ivec2 getLogicalSize() const
bool isViewScaled() const
gl::ivec2 getViewOffset() const
OutputSurface(const OutputSurface &)=delete
void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize)
Definition: OutputSurface.cc:6
virtual ~OutputSurface()=default
gl::ivec2 getViewSize() const
int getLogicalHeight() const
Pixel mapKeyedRGB(gl::vec3 rgb)
Returns the pixel value for the given RGB color.
virtual void saveScreenshot(const std::string &filename)=0
Save the content of this OutputSurface to a PNG file.
uint32_t mapRGB(gl::vec3 rgb) const
Returns the pixel value for the given RGB color.
Pixel getKeyColorClash() const
Returns a color that is visually very close to the key color.
Pixel getKeyColor() const
Returns the color key for this output surface.
unsigned map(unsigned r, unsigned g, unsigned b) const
Definition: PixelFormat.hh:40
vecN< 2, float > vec2
Definition: gl_vec.hh:139
void format(SectorAccessibleDisk &disk, bool dos1)
Format the given disk (= a single partition).
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint32_t Pixel
constexpr const char *const filename