OXYGENHUB
◆ main openmsx / src / video / scalers / GLScaler.hh
3.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef GLSCALER_HH
2
#define GLSCALER_HH
3
4
#include "GLUtil.hh"
5
#include <array>
6
#include <string>
7
8
namespace openmsx {
9
10
class FrameSource;
11
12
/** Abstract base class for OpenGL scalers.
13
  * A scaler is an algorithm that converts low-res graphics to hi-res graphics.
14
  */
15
class GLScaler
16
{
17
public:
18
	virtual ~GLScaler() = default;
19
20
	/** Setup scaler.
21
	  * Must be called once per frame before calling scaleImage() (possibly
22
	  * multiple times).
23
	  */
24
	void setup(bool superImpose);
25
26
	/** Scales the image in the given area, which must consist of lines which
27
	  * are all equally wide.
28
	  * Scaling factor depends on the concrete scaler.
29
	  * @param src Source: texture containing the frame to be scaled.
30
	  * @param superImpose Texture containing the to-be-superimposed image (can be nullptr).
31
	  * @param srcStartY Y-coordinate of the top source line (inclusive).
32
	  * @param srcEndY Y-coordinate of the bottom source line (exclusive).
33
	  * @param srcWidth The number of pixels per line for the given area.
34
	  * @param dstStartY Y-coordinate of the top destination line (inclusive).
35
	  * @param dstEndY Y-coordinate of the bottom destination line (exclusive).
36
	  * @param dstWidth The number of pixels per line on the output screen.
37
	  * @param logSrcHeight The logical height of the complete src texture
38
	  *        (actual texture height can be double as high in case of
39
	  *        non-interlace). This is needed to translate src-Y-coordinates
40
	  *        to superImpose-Y-coordinates.
41
	  */
42
	virtual void scaleImage(
43
		gl::ColorTexture& src, gl::ColorTexture* superImpose,
44
		unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
45
		unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
46
		unsigned logSrcHeight) = 0;
47
48
	virtual void uploadBlock(
49
		unsigned srcStartY, unsigned srcEndY,
50
		unsigned lineWidth, FrameSource& paintFrame);
51
52
protected:
53
	explicit GLScaler(const std::string& progName);
54
55
	/** Helper method to draw a rectangle with multiple texture coordinates.
56
	  * This method is similar to Texture::drawRect() but it calculates a
57
	  * seconds set of texture coordinates. The first tex-coords are used
58
	  * for the MSX texture (texture unit 0), and are calculated from
59
	  * src{Start,End}Y and src.getHeight(). The second set of tex-coord are
60
	  * used for the superimpose texture (texture unit 1) and are calculated
61
	  * from src{Start,End}Y and logSrcHeight.
62
	  * @param src
63
	  * @param superImpose
64
	  * @param srcStartY
65
	  * @param srcEndY
66
	  * @param srcWidth
67
	  * @param dstStartY
68
	  * @param dstEndY
69
	  * @param dstWidth
70
	  * @param logSrcHeight
71
	  * @param textureFromZero If true, the texture coordinates of subpixels
72
	  *   will start from zero: for example in 4x zoom the source coordinates
73
	  *   will be 0.0, 0.25, 0.5, 0.75. If false, the texture coordinates of
74
	  *   subpixels will be centered: for example in 4x zoom the source
75
	  *   coordinates will be 0.125, 0.375, 0.625, 0.875.
76
	  */
77
	void execute(const gl::ColorTexture& src, const gl::ColorTexture* superImpose,
78
	             unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
79
	             unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
80
	             unsigned logSrcHeight,
81
	             bool textureFromZero = false);
82
83
protected:
84
	std::array<gl::BufferObject, 2> vbo;
85
	std::array<gl::ShaderProgram, 2> program;
86
	std::array<GLint, 2> unifTexSize;
87
	std::array<GLint, 2> unifMvpMatrix;
88
};
89
90
} // namespace openmsx
91
92
#endif // GLSCALER_HH