openMSX
GLScaler.cc
Go to the documentation of this file.
1 #include "GLScaler.hh"
2 #include "GLUtil.hh"
3 #include "memory.hh"
4 
5 namespace openmsx {
6 
8 {
9  VertexShader vertexShader ("superImpose.vert");
10  FragmentShader fragmentShader("superImpose.frag");
11  scalerProgram.attach(vertexShader);
12  scalerProgram.attach(fragmentShader);
13  scalerProgram.link();
14 #ifdef GL_VERSION_2_0
15  if (GLEW_VERSION_2_0) {
16  scalerProgram.activate();
17  glUniform1i(scalerProgram.getUniformLocation("tex"), 0);
18  glUniform1i(scalerProgram.getUniformLocation("videoTex"), 1);
19  }
20 #endif
21 }
22 
24 {
25 }
26 
28  unsigned /*srcStartY*/, unsigned /*srcEndY*/,
29  unsigned /*lineWidth*/, FrameSource& /*paintFrame*/)
30 {
31 }
32 
34  ColorTexture& src, ColorTexture* superImpose,
35  unsigned srcStartY, unsigned srcEndY, unsigned /*srcWidth*/,
36  unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
37  unsigned logSrcHeight)
38 {
39  if (superImpose) {
40  glActiveTexture(GL_TEXTURE1);
41  superImpose->bind();
42  glActiveTexture(GL_TEXTURE0);
43  scalerProgram.activate();
44  } else {
45  scalerProgram.deactivate();
46  }
47 
48  drawMultiTex(src, srcStartY, srcEndY, src.getHeight(), logSrcHeight,
49  dstStartY, dstEndY, dstWidth);
50 }
51 
53  ColorTexture& src,
54  unsigned srcStartY, unsigned srcEndY,
55  float physSrcHeight, float logSrcHeight,
56  unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
57  bool textureFromZero)
58 {
59  src.bind();
60  // Note: hShift is pre-divided by srcWidth, while vShift will be divided
61  // by srcHeight later on.
62  // Note: The coordinate is put just past zero, to avoid fract() in the
63  // fragment shader to wrap around on rounding errors.
64  float hShift = textureFromZero ? 0.501f / dstWidth : 0.0f;
65  float vShift = textureFromZero ? 0.501f * (
66  float(srcEndY - srcStartY) / float(dstEndY - dstStartY)
67  ) : 0.0f;
68  glEnable(GL_TEXTURE_2D);
69  glBegin(GL_QUADS);
70  {
71  GLfloat tex0StartY = (srcStartY + vShift) / physSrcHeight;
72  GLfloat tex0EndY = (srcEndY + vShift) / physSrcHeight;
73  GLfloat tex1StartY = (srcStartY + vShift) / logSrcHeight;
74  GLfloat tex1EndY = (srcEndY + vShift) / logSrcHeight;
75 
76  glMultiTexCoord2f(GL_TEXTURE0, 0.0f + hShift, tex0StartY);
77  glMultiTexCoord2f(GL_TEXTURE1, 0.0f + hShift, tex1StartY);
78  glVertex2i( 0, dstStartY);
79 
80  glMultiTexCoord2f(GL_TEXTURE0, 1.0f + hShift, tex0StartY);
81  glMultiTexCoord2f(GL_TEXTURE1, 1.0f + hShift, tex1StartY);
82  glVertex2i(dstWidth, dstStartY);
83 
84  glMultiTexCoord2f(GL_TEXTURE0, 1.0f + hShift, tex0EndY );
85  glMultiTexCoord2f(GL_TEXTURE1, 1.0f + hShift, tex1EndY );
86  glVertex2i(dstWidth, dstEndY );
87 
88  glMultiTexCoord2f(GL_TEXTURE0, 0.0f + hShift, tex0EndY );
89  glMultiTexCoord2f(GL_TEXTURE1, 0.0f + hShift, tex1EndY );
90  glVertex2i( 0, dstEndY );
91  }
92  glEnd();
93  glDisable(GL_TEXTURE_2D);
94 }
95 
96 } // namespace openmsx