12 GLScaler::GLScaler(
const string& progName)
15 auto header =
tmpStrCat(
"#define SUPERIMPOSE ",
char(
'0' + i),
'\n');
18 program[i].attach(vShader);
19 program[i].attach(fShader);
20 program[i].bindAttribLocation(0,
"a_position");
21 program[i].bindAttribLocation(1,
"a_texCoord");
23 program[i].activate();
24 glUniform1i(program[i].getUniformLocation(
"tex"), 0);
26 glUniform1i(program[i].getUniformLocation(
"videoTex"), 1);
28 unifTexSize[i] = program[i].getUniformLocation(
"texSize");
29 glUniformMatrix4fv(program[i].getUniformLocation(
"u_mvpMatrix"),
34 void GLScaler::uploadBlock(
40 void GLScaler::setup(
bool superImpose)
42 int i = superImpose ? 1 : 0;
43 program[i].activate();
46 void GLScaler::execute(
48 unsigned srcStartY,
unsigned srcEndY,
unsigned srcWidth,
49 unsigned dstStartY,
unsigned dstEndY,
unsigned dstWidth,
50 unsigned logSrcHeight,
bool textureFromZero)
53 glActiveTexture(GL_TEXTURE1);
55 glActiveTexture(GL_TEXTURE0);
57 int i = superImpose ? 1 : 0;
58 glUniform3f(unifTexSize[i], srcWidth, src.
getHeight(), logSrcHeight);
65 constexpr
float BIAS = 0.001f;
66 float samplePos = (textureFromZero ? 0.5f : 0.0f) + BIAS;
67 float hShift = samplePos / dstWidth;
68 float yRatio = float(srcEndY - srcStartY) / float(dstEndY - dstStartY);
69 float vShift = samplePos * yRatio;
74 vec2(dstWidth, dstStartY),
75 vec2(dstWidth, dstEndY ),
79 float tex0StartY = float(srcStartY + vShift) / src.
getHeight();
80 float tex0EndY = float(srcEndY + vShift) / src.
getHeight();
81 float tex1StartY = float(srcStartY + vShift) / logSrcHeight;
82 float tex1EndY = float(srcEndY + vShift) / logSrcHeight;
84 vec3(0.0f + hShift, tex0StartY, tex1StartY),
85 vec3(1.0f + hShift, tex0StartY, tex1StartY),
86 vec3(1.0f + hShift, tex0EndY , tex1EndY ),
87 vec3(0.0f + hShift, tex0EndY , tex1EndY ),
90 glBindBuffer(GL_ARRAY_BUFFER, vbo[0].get());
91 glBufferData(GL_ARRAY_BUFFER,
sizeof(pos), pos, GL_STREAM_DRAW);
92 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0,
nullptr);
94 glBindBuffer(GL_ARRAY_BUFFER, vbo[1].get());
95 glBufferData(GL_ARRAY_BUFFER,
sizeof(tex), tex, GL_STREAM_DRAW);
96 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,
nullptr);
98 glEnableVertexAttribArray(0);
99 glEnableVertexAttribArray(1);
101 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
103 glDisableVertexAttribArray(1);
104 glDisableVertexAttribArray(0);
105 glBindBuffer(GL_ARRAY_BUFFER, 0);
GLsizei getHeight() const
Wrapper around an OpenGL fragment shader: a program executed on the GPU that computes the colors of p...
void bind()
Makes this texture the active GL texture.
Wrapper around an OpenGL vertex shader: a program executed on the GPU that computes per-vertex stuff.
Interface for getting lines from a video frame.
std::unique_ptr< Context > context
This file implemented 3 utility functions:
TemporaryString tmpStrCat(Ts &&... ts)
constexpr auto xrange(T e)