OXYGENHUB
◆ main openmsx / src / video / OutputSurface.hh
2.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef OUTPUTSURFACE_HH
2
#define OUTPUTSURFACE_HH
3
4
#include "PixelOperations.hh"
5
#include "gl_vec.hh"
6
7
#include <cassert>
8
#include <cstdint>
9
#include <string>
10
11
namespace openmsx {
12
13
/** A frame buffer where pixels can be written to.
14
  * It could be an in-memory buffer or a video buffer visible to the user
15
  * (see *OffScreenSurface and *VisibleSurface classes).
16
  *
17
  * The OutputSurface class itself knows about its dimensions and pixel format.
18
  * But the actual pixel storage is left for the subclasses.
19
  */
20
class OutputSurface
21
{
22
public:
23
	using Pixel = uint32_t;
24
25
	OutputSurface(const OutputSurface&) = delete;
26
	OutputSurface(OutputSurface&&) = delete;
27
	OutputSurface& operator=(const OutputSurface&) = delete;
28
	OutputSurface& operator=(OutputSurface&&) = delete;
29
	virtual ~OutputSurface() = default;
30
31
	[[nodiscard]] int getLogicalWidth()  const { return m_logicalSize.x; }
32
	[[nodiscard]] int getLogicalHeight() const { return m_logicalSize.y; }
33
	[[nodiscard]] gl::ivec2 getLogicalSize()  const { return m_logicalSize; }
34
	[[nodiscard]] gl::ivec2 getPhysicalSize() const { return m_physSize; }
35
36
	[[nodiscard]] gl::ivec2 getViewOffset() const { return m_viewOffset; }
37
	[[nodiscard]] gl::ivec2 getViewSize()   const { return m_viewSize; }
38
	[[nodiscard]] gl::vec2  getViewScale()  const { return m_viewScale; }
39
40
	/** Returns the pixel value for the given RGB color.
41
	  * No effort is made to ensure that the returned pixel value is not the
42
	  * color key for this output surface.
43
	  */
44
	[[nodiscard]] uint32_t mapRGB(gl::vec3 rgb) const
45
	{
46
		return mapRGB255(gl::ivec3(rgb * 255.0f));
47
	}
48
49
	/** Same as mapRGB, but RGB components are in range [0..255].
50
	 */
51
	[[nodiscard]] uint32_t mapRGB255(gl::ivec3 rgb) const
52
	{
53
		auto [r, g, b] = rgb;
54
		PixelOperations pixelOps;
55
		return pixelOps.combine(r, g, b);
56
	}
57
58
	/** Returns the color key for this output surface.
59
	  */
60
	[[nodiscard]] Pixel getKeyColor() const
61
	{
62
		return 0x00000000; // alpha = 0
63
	}
64
65
	/** Save the content of this OutputSurface to a PNG file.
66
	  * @throws MSXException If creating the PNG file fails.
67
	  */
68
	virtual void saveScreenshot(const std::string& filename) = 0;
69
70
protected:
71
	OutputSurface() = default;
72
73
	// These two _must_ be called from (each) subclass constructor.
74
	void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize);
75
76
private:
77
	gl::ivec2 m_logicalSize;
78
	gl::ivec2 m_physSize;
79
	gl::ivec2 m_viewOffset;
80
	gl::ivec2 m_viewSize;
81
	gl::vec2 m_viewScale{1.0f};
82
};
83
84
} // namespace openmsx
85
86
#endif