openMSX
OutputSurface.hh
Go to the documentation of this file.
1#ifndef OUTPUTSURFACE_HH
2#define OUTPUTSURFACE_HH
3
4#include "PixelOperations.hh"
5#include "gl_vec.hh"
6#include <string>
7#include <cassert>
8#include <cstdint>
9
10namespace openmsx {
11
20{
21public:
22 using Pixel = uint32_t;
23
24 OutputSurface(const OutputSurface&) = delete;
26
27 virtual ~OutputSurface() = default;
28
29 [[nodiscard]] int getLogicalWidth() const { return m_logicalSize.x; }
30 [[nodiscard]] int getLogicalHeight() const { return m_logicalSize.y; }
31 [[nodiscard]] gl::ivec2 getLogicalSize() const { return m_logicalSize; }
32 [[nodiscard]] gl::ivec2 getPhysicalSize() const { return m_physSize; }
33
34 [[nodiscard]] gl::ivec2 getViewOffset() const { return m_viewOffset; }
35 [[nodiscard]] gl::ivec2 getViewSize() const { return m_viewSize; }
36 [[nodiscard]] gl::vec2 getViewScale() const { return m_viewScale; }
37
42 [[nodiscard]] uint32_t mapRGB(gl::vec3 rgb) const
43 {
44 return mapRGB255(gl::ivec3(rgb * 255.0f));
45 }
46
49 [[nodiscard]] uint32_t mapRGB255(gl::ivec3 rgb) const
50 {
51 auto [r, g, b] = rgb;
52 PixelOperations pixelOps;
53 return pixelOps.combine(r, g, b);
54 }
55
58 [[nodiscard]] inline Pixel getKeyColor() const
59 {
60 return 0x00000000; // alpha = 0
61 }
62
66 virtual void saveScreenshot(const std::string& filename) = 0;
67
68protected:
69 OutputSurface() = default;
70
71 // These two _must_ be called from (each) subclass constructor.
72 void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize);
73
74private:
75 gl::ivec2 m_logicalSize;
76 gl::ivec2 m_physSize;
77 gl::ivec2 m_viewOffset;
78 gl::ivec2 m_viewSize;
79 gl::vec2 m_viewScale{1.0f};
80};
81
82} // namespace openmsx
83
84#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].
gl::ivec2 getPhysicalSize() const
gl::vec2 getViewScale() const
gl::ivec2 getLogicalSize() const
gl::ivec2 getViewOffset() const
OutputSurface(const OutputSurface &)=delete
void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize)
virtual ~OutputSurface()=default
gl::ivec2 getViewSize() const
Pixel getKeyColor() const
Returns the color key for this output surface.
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.
OutputSurface & operator=(const OutputSurface &)=delete
Pixel combine(unsigned r, unsigned g, unsigned b) const
Combine RGB components to a pixel.
This file implemented 3 utility functions:
Definition Autofire.cc:11