openMSX
GLSimpleScaler.cc
Go to the documentation of this file.
1 #include "GLSimpleScaler.hh"
2 #include "RenderSettings.hh"
3 #include "xrange.hh"
4 
5 namespace openmsx {
6 
8  RenderSettings& renderSettings_, GLScaler& fallback_)
9  : GLScaler("simple")
10  , renderSettings(renderSettings_)
11  , fallback(fallback_)
12 {
13  for (auto i : xrange(2)) {
14  program[i].activate();
15  unifTexStepX[i] = program[i].getUniformLocation("texStepX");
16  unifCnst[i] = program[i].getUniformLocation("cnst");
17  }
18 }
19 
21  gl::ColorTexture& src, gl::ColorTexture* superImpose,
22  unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
23  unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
24  unsigned logSrcHeight)
25 {
26  int i = superImpose ? 1 : 0;
27 
28  GLfloat blur = renderSettings.getBlurFactor() / 256.0f;
29  GLfloat scanline = renderSettings.getScanlineFactor() / 255.0f;
30  unsigned yScale = (dstEndY - dstStartY) / (srcEndY - srcStartY);
31  if (yScale == 0) {
32  // less lines in destination than in source
33  // (factor=1 / interlace) --> disable scanlines
34  scanline = 1.0f;
35  yScale = 1;
36  }
37 
38  if ((blur != 0.0f) || (scanline != 1.0f) || superImpose) {
39  setup(superImpose != nullptr);
40  if ((blur != 0.0f) && (srcWidth != 1)) { // srcWidth check: workaround for ATI cards
41  src.setInterpolation(true);
42  }
43  GLfloat scan_a = (yScale & 1) ? 0.5f : ((yScale + 1) / (2.0f * yScale));
44  GLfloat scan_b = 2.0f - 2.0f * scanline;
45  GLfloat scan_c = scanline;
46  if (!superImpose) {
47  // small optimization in simple.frag:
48  // divide by 2 here instead of on every pixel
49  scan_b *= 0.5f;
50  scan_c *= 0.5f;
51  }
52  glUniform3f(unifTexStepX[i], 1.0f / srcWidth, 1.0f / srcWidth, 0.0f);
53  glUniform4f(unifCnst[i], scan_a, scan_b, scan_c, blur);
54 
55  execute(src, superImpose,
56  srcStartY, srcEndY, srcWidth,
57  dstStartY, dstEndY, dstWidth,
58  logSrcHeight);
59 
60  src.setInterpolation(false);
61  } else {
62  fallback.scaleImage(src, superImpose, srcStartY, srcEndY, srcWidth,
63  dstStartY, dstEndY, dstWidth, logSrcHeight);
64  }
65 }
66 
67 } // namespace openmsx
void activate() const
Makes this program the active shader program.
Definition: GLUtil.cc:267
GLint getUniformLocation(const char *name) const
Gets a reference to a uniform variable declared in the shader source.
Definition: GLUtil.cc:259
void setInterpolation(bool interpolation)
Enable/disable bilinear interpolation for this texture.
Definition: GLUtil.cc:49
Abstract base class for OpenGL scalers.
Definition: GLScaler.hh:14
void setup(bool superImpose)
Definition: GLScaler.cc:40
void execute(gl::ColorTexture &src, gl::ColorTexture *superImpose, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, unsigned dstStartY, unsigned dstEndY, unsigned dstWidth, unsigned logSrcHeight, bool textureFromZero=false)
Helper method to draw a rectangle with multiple texture coordinates.
Definition: GLScaler.cc:46
virtual void scaleImage(gl::ColorTexture &src, gl::ColorTexture *superImpose, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, unsigned dstStartY, unsigned dstEndY, unsigned dstWidth, unsigned logSrcHeight)=0
Scales the image in the given area, which must consist of lines which are all equally wide.
gl::ShaderProgram program[2]
Definition: GLScaler.hh:78
GLSimpleScaler(RenderSettings &renderSettings, GLScaler &fallback)
void scaleImage(gl::ColorTexture &src, gl::ColorTexture *superImpose, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, unsigned dstStartY, unsigned dstEndY, unsigned dstWidth, unsigned logSrcHeight) override
Scales the image in the given area, which must consist of lines which are all equally wide.
Class containing all settings for renderers.
int getScanlineFactor() const
The alpha value [0..255] of the gap between scanlines.
int getBlurFactor() const
The amount of horizontal blur [0..256].
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr auto xrange(T e)
Definition: xrange.hh:155