openMSX
GLScaler.cc
Go to the documentation of this file.
1 #include "GLScaler.hh"
2 #include "GLUtil.hh"
3 
4 namespace openmsx {
5 
7 {
8  VertexShader vertexShader ("superImpose.vert");
9  FragmentShader fragmentShader("superImpose.frag");
10  scalerProgram.attach(vertexShader);
11  scalerProgram.attach(fragmentShader);
12  scalerProgram.link();
13 
14  scalerProgram.activate();
15  glUniform1i(scalerProgram.getUniformLocation("tex"), 0);
16  glUniform1i(scalerProgram.getUniformLocation("videoTex"), 1);
17 }
18 
20 {
21 }
22 
24  unsigned /*srcStartY*/, unsigned /*srcEndY*/,
25  unsigned /*lineWidth*/, FrameSource& /*paintFrame*/)
26 {
27 }
28 
30  ColorTexture& src, ColorTexture* superImpose,
31  unsigned srcStartY, unsigned srcEndY, unsigned /*srcWidth*/,
32  unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
33  unsigned logSrcHeight)
34 {
35  if (superImpose) {
36  glActiveTexture(GL_TEXTURE1);
37  superImpose->bind();
38  glActiveTexture(GL_TEXTURE0);
39  scalerProgram.activate();
40  } else {
41  scalerProgram.deactivate();
42  }
43 
44  drawMultiTex(src, srcStartY, srcEndY, src.getHeight(), logSrcHeight,
45  dstStartY, dstEndY, dstWidth);
46 }
47 
49  ColorTexture& src,
50  unsigned srcStartY, unsigned srcEndY,
51  float physSrcHeight, float logSrcHeight,
52  unsigned dstStartY, unsigned dstEndY, unsigned dstWidth,
53  bool textureFromZero)
54 {
55  src.bind();
56  // Note: hShift is pre-divided by srcWidth, while vShift will be divided
57  // by srcHeight later on.
58  // Note: The coordinate is put just past zero, to avoid fract() in the
59  // fragment shader to wrap around on rounding errors.
60  float hShift = textureFromZero ? 0.501f / dstWidth : 0.0f;
61  float vShift = textureFromZero ? 0.501f * (
62  float(srcEndY - srcStartY) / float(dstEndY - dstStartY)
63  ) : 0.0f;
64  glEnable(GL_TEXTURE_2D);
65  glBegin(GL_QUADS);
66  {
67  GLfloat tex0StartY = (srcStartY + vShift) / physSrcHeight;
68  GLfloat tex0EndY = (srcEndY + vShift) / physSrcHeight;
69  GLfloat tex1StartY = (srcStartY + vShift) / logSrcHeight;
70  GLfloat tex1EndY = (srcEndY + vShift) / logSrcHeight;
71 
72  glMultiTexCoord2f(GL_TEXTURE0, 0.0f + hShift, tex0StartY);
73  glMultiTexCoord2f(GL_TEXTURE1, 0.0f + hShift, tex1StartY);
74  glVertex2i( 0, dstStartY);
75 
76  glMultiTexCoord2f(GL_TEXTURE0, 1.0f + hShift, tex0StartY);
77  glMultiTexCoord2f(GL_TEXTURE1, 1.0f + hShift, tex1StartY);
78  glVertex2i(dstWidth, dstStartY);
79 
80  glMultiTexCoord2f(GL_TEXTURE0, 1.0f + hShift, tex0EndY );
81  glMultiTexCoord2f(GL_TEXTURE1, 1.0f + hShift, tex1EndY );
82  glVertex2i(dstWidth, dstEndY );
83 
84  glMultiTexCoord2f(GL_TEXTURE0, 0.0f + hShift, tex0EndY );
85  glMultiTexCoord2f(GL_TEXTURE1, 0.0f + hShift, tex1EndY );
86  glVertex2i( 0, dstEndY );
87  }
88  glEnd();
89  glDisable(GL_TEXTURE_2D);
90 }
91 
92 } // namespace openmsx
virtual void uploadBlock(unsigned srcStartY, unsigned srcEndY, unsigned lineWidth, FrameSource &paintFrame)
Definition: GLScaler.cc:23
Wrapper around an OpenGL fragment shader: a program executed on the GPU that computes the colors of p...
Definition: GLUtil.hh:426
Wrapper around an OpenGL vertex shader: a program executed on the GPU that computes per-vertex stuff...
Definition: GLUtil.hh:413
virtual void scaleImage(ColorTexture &src, 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...
Definition: GLScaler.cc:29
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 activate() const
Makes this program the active shader program.
Definition: GLUtil.cc:383
virtual ~GLScaler()
Definition: GLScaler.cc:19
void link()
Links all attached shaders together into one program.
Definition: GLUtil.cc:346
Interface for getting lines from a video frame.
Definition: FrameSource.hh:15
GLint getUniformLocation(const char *name) const
Gets a reference to a uniform variable declared in the shader source.
Definition: GLUtil.cc:366
void bind()
Makes this texture the active GL texture.
Definition: GLUtil.hh:61
static void deactivate()
Deactivates all shader programs.
Definition: GLUtil.cc:388
GLsizei getHeight() const
Definition: GLUtil.hh:119
void attach(const Shader &shader)
Adds a given shader to this program.
Definition: GLUtil.cc:334