openMSX
GLSimpleScaler.cc
Go to the documentation of this file.
1 #include "GLSimpleScaler.hh"
2 #include "GLUtil.hh"
3 #include "RenderSettings.hh"
4 
5 using std::string;
6 
7 namespace openmsx {
8 
10  : renderSettings(renderSettings_)
11 {
12  for (int i = 0; i < 2; ++i) {
13  Data& d = data[i];
14 
15  string header = string("#define SUPERIMPOSE ")
16  + char('0' + i) + '\n';
17  VertexShader vertexShader (header, "simple.vert");
18  FragmentShader fragmentShader(header, "simple.frag");
19  d.scalerProgram.attach(vertexShader);
20  d.scalerProgram.attach(fragmentShader);
21  d.scalerProgram.link();
22 
23  data[i].scalerProgram.activate();
24  GLint texLoc = d.scalerProgram.getUniformLocation("tex");
25  glUniform1i(texLoc, 0);
26  if (i == 1) {
27  GLint texLoc2 = d.scalerProgram.getUniformLocation("videoTex");
28  glUniform1i(texLoc2, 1);
29  }
30  data[i].texSizeLoc = d.scalerProgram.getUniformLocation("texSize");
31  data[i].texStepXLoc = d.scalerProgram.getUniformLocation("texStepX");
32  data[i].cnstLoc = d.scalerProgram.getUniformLocation("cnst");
33  }
34 }
35 
37  ColorTexture& src, ColorTexture* superImpose,
38  unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
39  unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
40  unsigned logSrcHeight)
41 {
42  Data& d = data[superImpose ? 1 : 0];
43 
44  GLfloat blur = renderSettings.getBlurFactor() / 256.0f;
45  GLfloat scanline = renderSettings.getScanlineFactor() / 255.0f;
46  unsigned yScale = (dstEndY - dstStartY) / (srcEndY - srcStartY);
47  if (yScale == 0) {
48  // less lines in destination than in source
49  // (factor=1 / interlace) --> disable scanlines
50  scanline = 1.0f;
51  yScale = 1;
52  }
53 
54  if ((blur != 0.0f) && (srcWidth != 1)) { // srcWidth check: workaround for ATI cards
55  src.enableInterpolation();
56  }
57  if (((blur != 0.0f) || (scanline != 1.0f) || superImpose)) {
58  if (superImpose) {
59  glActiveTexture(GL_TEXTURE1);
60  superImpose->bind();
61  glActiveTexture(GL_TEXTURE0);
62  }
63  d.scalerProgram.activate();
64  GLfloat scan_a = (yScale & 1) ? 0.5f : ((yScale + 1) / (2.0f * yScale));
65  GLfloat scan_b = 2.0f - 2.0f * scanline;
66  GLfloat scan_c = scanline;
67  if (!superImpose) {
68  // small optimization in simple.frag:
69  // divide by 2 here instead of on every pixel
70  scan_b *= 0.5f;
71  scan_c *= 0.5f;
72  }
73  glUniform2f(d.texSizeLoc, srcWidth, src.getHeight());
74  glUniform3f(d.texStepXLoc, 1.0f / srcWidth, 1.0f / srcWidth, 0.0f);
75  glUniform4f(d.cnstLoc, scan_a, scan_b, scan_c, blur);
76  }
77 
78  // actually draw texture
79  drawMultiTex(src, srcStartY, srcEndY, src.getHeight(), logSrcHeight,
80  dstStartY, dstEndY, dstWidth);
82 }
83 
84 } // namespace openmsx
Wrapper around an OpenGL fragment shader: a program executed on the GPU that computes the colors of p...
Definition: GLUtil.hh:426
GLSimpleScaler(RenderSettings &renderSettings)
virtual void scaleImage(ColorTexture &src, ColorTexture *superImpose, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, unsigned dstStartY, unsigned dstEndY, unsigned dstWidth, unsigned logSrcHeight)
Scales the image in the given area, which must consist of lines which are all equally wide...
Wrapper around an OpenGL vertex shader: a program executed on the GPU that computes per-vertex stuff...
Definition: GLUtil.hh:413
void drawMultiTex(ColorTexture &src, unsigned srcStartY, unsigned srcEndY, float physSrcHeight, float logSrcHeight, unsigned dstStartY, unsigned dstEndY, unsigned dstWidth, bool textureFromZero=false)
Helper method to draw a rectangle with multiple texture coordinates.
Definition: GLScaler.cc:48
void disableInterpolation()
Disables bilinear interpolation for this texture and uses nearest neighbour instead.
Definition: GLUtil.cc:56
void bind()
Makes this texture the active GL texture.
Definition: GLUtil.hh:61
int getBlurFactor() const
The amount of horizontal blur [0..256].
GLsizei getHeight() const
Definition: GLUtil.hh:119
Class containing all settings for renderers.
void enableInterpolation()
Enables bilinear interpolation for this texture.
Definition: GLUtil.cc:49
int getScanlineFactor() const
The alpha value [0..255] of the gap between scanlines.