11 GLScaler::GLScaler(
const std::string& progName)
14 auto header =
tmpStrCat(
"#define SUPERIMPOSE ",
char(
'0' + i),
'\n');
17 program[i].attach(vShader);
18 program[i].attach(fShader);
19 program[i].bindAttribLocation(0,
"a_position");
20 program[i].bindAttribLocation(1,
"a_texCoord");
22 program[i].activate();
23 glUniform1i(program[i].getUniformLocation(
"tex"), 0);
25 glUniform1i(program[i].getUniformLocation(
"videoTex"), 1);
27 unifTexSize[i] = program[i].getUniformLocation(
"texSize");
28 glUniformMatrix4fv(program[i].getUniformLocation(
"u_mvpMatrix"),
33 void GLScaler::uploadBlock(
39 void GLScaler::setup(
bool superImpose)
41 int i = superImpose ? 1 : 0;
42 program[i].activate();
45 void GLScaler::execute(
47 unsigned srcStartY,
unsigned srcEndY,
unsigned srcWidth,
48 unsigned dstStartY,
unsigned dstEndY,
unsigned dstWidth,
49 unsigned logSrcHeight,
bool textureFromZero)
52 glActiveTexture(GL_TEXTURE1);
54 glActiveTexture(GL_TEXTURE0);
56 int i = superImpose ? 1 : 0;
57 glUniform3f(unifTexSize[i], srcWidth, src.
getHeight(), logSrcHeight);
64 constexpr
float BIAS = 0.001f;
65 float samplePos = (textureFromZero ? 0.5f : 0.0f) + BIAS;
66 float hShift = samplePos / dstWidth;
67 float yRatio = float(srcEndY - srcStartY) / float(dstEndY - dstStartY);
68 float vShift = samplePos * yRatio;
73 vec2(dstWidth, dstStartY),
74 vec2(dstWidth, dstEndY ),
78 float tex0StartY = float(srcStartY + vShift) / src.
getHeight();
79 float tex0EndY = float(srcEndY + vShift) / src.
getHeight();
80 float tex1StartY = float(srcStartY + vShift) / logSrcHeight;
81 float tex1EndY = float(srcEndY + vShift) / logSrcHeight;
83 vec3(0.0f + hShift, tex0StartY, tex1StartY),
84 vec3(1.0f + hShift, tex0StartY, tex1StartY),
85 vec3(1.0f + hShift, tex0EndY , tex1EndY ),
86 vec3(0.0f + hShift, tex0EndY , tex1EndY ),
89 glBindBuffer(GL_ARRAY_BUFFER, vbo[0].
get());
90 glBufferData(GL_ARRAY_BUFFER,
sizeof(pos), pos, GL_STREAM_DRAW);
91 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0,
nullptr);
93 glBindBuffer(GL_ARRAY_BUFFER, vbo[1].
get());
94 glBufferData(GL_ARRAY_BUFFER,
sizeof(tex), tex, GL_STREAM_DRAW);
95 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,
nullptr);
97 glEnableVertexAttribArray(0);
98 glEnableVertexAttribArray(1);
100 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
102 glDisableVertexAttribArray(1);
103 glDisableVertexAttribArray(0);
104 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::optional< Context > context
This file implemented 3 utility functions:
const T & get(const Event &event)
TemporaryString tmpStrCat(Ts &&... ts)
constexpr auto xrange(T e)