15 auto header =
tmpStrCat(
"#define SUPERIMPOSE ",
char(
'0' + i),
'\n');
20 program[i].bindAttribLocation(0,
"a_position");
21 program[i].bindAttribLocation(1,
"a_texCoord");
24 glUniform1i(
program[i].getUniformLocation(
"tex"), 0);
26 glUniform1i(
program[i].getUniformLocation(
"videoTex"), 1);
29 glUniformMatrix4fv(
program[i].getUniformLocation(
"u_mvpMatrix"),
42 int i = superImpose ? 1 : 0;
48 unsigned srcStartY,
unsigned srcEndY,
unsigned srcWidth,
49 unsigned dstStartY,
unsigned dstEndY,
unsigned dstWidth,
50 unsigned logSrcHeight,
bool textureFromZero)
52 auto srcStartYF = narrow<float>(srcStartY);
53 auto srcEndYF = narrow<float>(srcEndY);
54 auto dstStartYF = narrow<float>(dstStartY);
55 auto dstEndYF = narrow<float>(dstEndY);
56 auto dstWidthF = narrow<float>(dstWidth);
57 auto srcWidthF = narrow<float>(srcWidth);
58 auto srcHeightF = narrow<float>(src.
getHeight());
59 auto logSrcHeightF = narrow<float>(logSrcHeight);
62 glActiveTexture(GL_TEXTURE1);
64 glActiveTexture(GL_TEXTURE0);
66 int i = superImpose ? 1 : 0;
67 glUniform3f(
unifTexSize[i], srcWidthF, srcHeightF, logSrcHeightF);
74 static constexpr float BIAS = 0.001f;
75 float samplePos = (textureFromZero ? 0.5f : 0.0f) + BIAS;
76 float hShift = samplePos / dstWidthF;
77 float yRatio = (srcEndYF - srcStartYF) / (dstEndYF - dstStartYF);
78 float vShift = samplePos * yRatio;
82 vec2( 0.0f, dstStartYF),
83 vec2(dstWidthF, dstStartYF),
84 vec2(dstWidthF, dstEndYF ),
85 vec2( 0.0f, dstEndYF ),
88 float tex0StartY = (srcStartYF + vShift) / srcHeightF;
89 float tex0EndY = (srcEndYF + vShift) / srcHeightF;
90 float tex1StartY = (srcStartYF + vShift) / logSrcHeightF;
91 float tex1EndY = (srcEndYF + vShift) / logSrcHeightF;
93 vec3(0.0f + hShift, tex0StartY, tex1StartY),
94 vec3(1.0f + hShift, tex0StartY, tex1StartY),
95 vec3(1.0f + hShift, tex0EndY , tex1EndY ),
96 vec3(0.0f + hShift, tex0EndY , tex1EndY ),
99 glBindBuffer(GL_ARRAY_BUFFER,
vbo[0].
get());
100 glBufferData(GL_ARRAY_BUFFER,
sizeof(pos), pos.data(), GL_STREAM_DRAW);
101 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0,
nullptr);
103 glBindBuffer(GL_ARRAY_BUFFER,
vbo[1].
get());
104 glBufferData(GL_ARRAY_BUFFER,
sizeof(tex), tex.data(), GL_STREAM_DRAW);
105 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,
nullptr);
107 glEnableVertexAttribArray(0);
108 glEnableVertexAttribArray(1);
110 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
112 glDisableVertexAttribArray(1);
113 glDisableVertexAttribArray(0);
114 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.
void setup(bool superImpose)
GLScaler(const std::string &progName)
std::array< gl::ShaderProgram, 2 > program
std::array< GLint, 2 > unifTexSize
std::array< gl::BufferObject, 2 > vbo
void execute(gl::ColorTexture &src, gl::ColorTexture *superImpose, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, unsigned dstStartY, unsigned dstEndY, unsigned dstWidth, unsigned logSrcHeight, bool textureFromZero=false)
Helper method to draw a rectangle with multiple texture coordinates.
virtual void uploadBlock(unsigned srcStartY, unsigned srcEndY, unsigned lineWidth, FrameSource &paintFrame)
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)