50 unsigned srcStartY,
unsigned srcEndY,
unsigned srcWidth,
51 unsigned dstStartY,
unsigned dstEndY,
unsigned dstWidth,
52 unsigned logSrcHeight,
bool textureFromZero)
54 auto srcStartYF = narrow<float>(srcStartY);
55 auto srcEndYF = narrow<float>(srcEndY);
56 auto dstStartYF = narrow<float>(dstStartY);
57 auto dstEndYF = narrow<float>(dstEndY);
58 auto dstWidthF = narrow<float>(dstWidth);
59 auto srcWidthF = narrow<float>(srcWidth);
60 auto srcHeightF = narrow<float>(src.
getHeight());
61 auto logSrcHeightF = narrow<float>(logSrcHeight);
64 glActiveTexture(GL_TEXTURE1);
66 glActiveTexture(GL_TEXTURE0);
68 int i = superImpose ? 1 : 0;
69 glUniform3f(
unifTexSize[i], srcWidthF, srcHeightF, logSrcHeightF);
76 static constexpr float BIAS = 0.001f;
77 float samplePos = (textureFromZero ? 0.5f : 0.0f) + BIAS;
78 float hShift = samplePos / dstWidthF;
79 float yRatio = (srcEndYF - srcStartYF) / (dstEndYF - dstStartYF);
80 float vShift = samplePos * yRatio;
84 vec2( 0.0f, dstStartYF),
85 vec2(dstWidthF, dstStartYF),
86 vec2(dstWidthF, dstEndYF ),
87 vec2( 0.0f, dstEndYF ),
90 float tex0StartY = (srcStartYF + vShift) / srcHeightF;
91 float tex0EndY = (srcEndYF + vShift) / srcHeightF;
92 float tex1StartY = (srcStartYF + vShift) / logSrcHeightF;
93 float tex1EndY = (srcEndYF + vShift) / logSrcHeightF;
95 vec3(0.0f + hShift, tex0StartY, tex1StartY),
96 vec3(1.0f + hShift, tex0StartY, tex1StartY),
97 vec3(1.0f + hShift, tex0EndY , tex1EndY ),
98 vec3(0.0f + hShift, tex0EndY , tex1EndY ),
101 glBindBuffer(GL_ARRAY_BUFFER,
vbo[0].get());
102 glBufferData(GL_ARRAY_BUFFER,
sizeof(pos), pos.data(), GL_STREAM_DRAW);
103 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0,
nullptr);
105 glBindBuffer(GL_ARRAY_BUFFER,
vbo[1].get());
106 glBufferData(GL_ARRAY_BUFFER,
sizeof(tex), tex.data(), GL_STREAM_DRAW);
107 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,
nullptr);
109 glEnableVertexAttribArray(0);
110 glEnableVertexAttribArray(1);
112 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
114 glDisableVertexAttribArray(1);
115 glDisableVertexAttribArray(0);
116 glBindBuffer(GL_ARRAY_BUFFER, 0);
GLsizei getHeight() const
void bind() const
Makes this texture the active GL texture.
void execute(const gl::ColorTexture &src, const 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.