openMSX
GLRGBScaler.cc
Go to the documentation of this file.
1 #include "GLRGBScaler.hh"
2 #include "RenderSettings.hh"
3 
4 namespace openmsx {
5 
7  RenderSettings& renderSettings_, GLScaler& fallback_)
8  : GLScaler("rgb")
9  , renderSettings(renderSettings_)
10  , fallback(fallback_)
11 {
12  for (int i = 0; i < 2; ++i) {
13  program[i].activate();
14  unifCnsts[i] = program[i].getUniformLocation("cnsts");
15  }
16 }
17 
19  gl::ColorTexture& src, gl::ColorTexture* superImpose,
20  unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
21  unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
22  unsigned logSrcHeight)
23 {
24  int i = superImpose ? 1 : 0;
25 
26  GLfloat blur = renderSettings.getBlurFactor() / 256.0f;
27  GLfloat scanline = renderSettings.getScanlineFactor() / 255.0f;
28  unsigned yScale = (dstEndY - dstStartY) / (srcEndY - srcStartY);
29  if (yScale == 0) {
30  // less lines in destination than in source
31  // (factor=1 / interlace) --> disable scanlines
32  scanline = 1.0f;
33  yScale = 1;
34  }
35  if ((blur != 0.0f) || (scanline != 1.0f) || superImpose) {
36  setup(superImpose != nullptr);
37  if (srcWidth != 1) {
38  // workaround for ATI cards
39  src.setInterpolation(true);
40  } else {
41  // treat border as 256-pixel wide display area
42  srcWidth = 320;
43  }
44  GLfloat a = (yScale & 1) ? 0.5f : ((yScale + 1) / (2.0f * yScale));
45  GLfloat c1 = blur;
46  GLfloat c2 = 3.0f - 2.0f * c1;
47  glUniform4f(unifCnsts[i],
48  a, // scan_a
49  (1.0f - scanline) * 2.0f * c2, // scan_b_c2
50  scanline * c2, // scan_c_c2
51  (c1 - c2) / c2); // scan_c1_2_2
52  execute(src, superImpose,
53  srcStartY, srcEndY, srcWidth,
54  dstStartY, dstEndY, dstWidth,
55  logSrcHeight);
56  src.setInterpolation(false);
57  } else {
58  fallback.scaleImage(src, superImpose,
59  srcStartY, srcEndY, srcWidth,
60  dstStartY, dstEndY, dstWidth,
61  logSrcHeight);
62  }
63 }
64 
65 } // namespace openmsx
openmsx::GLScaler::scaleImage
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.
openmsx::GLScaler::program
gl::ShaderProgram program[2]
Definition: GLScaler.hh:78
openmsx::RenderSettings
Class containing all settings for renderers.
Definition: RenderSettings.hh:22
openmsx::RenderSettings::getBlurFactor
int getBlurFactor() const
The amount of horizontal blur [0..256].
Definition: RenderSettings.hh:95
gl::ColorTexture
Definition: GLUtil.hh:100
openmsx::GLRGBScaler::GLRGBScaler
GLRGBScaler(RenderSettings &renderSettings, GLScaler &fallback)
Definition: GLRGBScaler.cc:6
gl::ShaderProgram::activate
void activate() const
Makes this program the active shader program.
Definition: GLUtil.cc:298
openmsx::GLScaler::execute
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
GLRGBScaler.hh
openmsx::GLRGBScaler::scaleImage
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.
Definition: GLRGBScaler.cc:18
gl::ShaderProgram::getUniformLocation
GLint getUniformLocation(const char *name) const
Gets a reference to a uniform variable declared in the shader source.
Definition: GLUtil.cc:290
openmsx::GLScaler::setup
void setup(bool superImpose)
Definition: GLScaler.cc:39
RenderSettings.hh
openmsx::RenderSettings::getScanlineFactor
int getScanlineFactor() const
The alpha value [0..255] of the gap between scanlines.
Definition: RenderSettings.hh:100
openmsx::GLScaler
Abstract base class for OpenGL scalers.
Definition: GLScaler.hh:14
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
gl::Texture::setInterpolation
void setInterpolation(bool interpolation)
Enable/disable bilinear interpolation for this texture.
Definition: GLUtil.cc:49