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