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
7#include <string>
8#include <cassert>
9#include <cstdint>
10
11namespace openmsx {
12
21{
22public:
23 using Pixel = uint32_t;
24
25 OutputSurface(const 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
44 [[nodiscard]] uint32_t mapRGB(gl::vec3 rgb) const
45 {
46 return mapRGB255(gl::ivec3(rgb * 255.0f));
47 }
48
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
60 [[nodiscard]] inline Pixel getKeyColor() const
61 {
62 return 0x00000000; // alpha = 0
63 }
64
68 virtual void saveScreenshot(const std::string& filename) = 0;
69
70protected:
71 OutputSurface() = default;
72
73 // These two _must_ be called from (each) subclass constructor.
74 void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize);
75
76private:
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
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
OutputSurface(OutputSurface &&)=delete
gl::vec2 getViewScale() const
gl::ivec2 getLogicalSize() const
gl::ivec2 getViewOffset() const
OutputSurface(const OutputSurface &)=delete
void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize)
OutputSurface & operator=(OutputSurface &&)=delete
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