Keep global state clean

Unbind the FBO+texture after initialization, bind it before
rendering, unbind it after, re-bind the texture to scrape the
data, unbind the texture.

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2022-07-19 21:04:43 +02:00
parent 6bfa914582
commit 22b2fd4864

View file

@ -232,10 +232,13 @@ int main(int argc, char **argv)
glBindTexture(GL_TEXTURE_2D, fbo_tex); glBindTexture(GL_TEXTURE_2D, fbo_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, NULL); GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
fbo_tex, 0); fbo_tex, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
} else { } else {
window_show(wnd); window_show(wnd);
} }
@ -244,6 +247,10 @@ int main(int argc, char **argv)
while (to_stdout || window_handle_events()) { while (to_stdout || window_handle_events()) {
/* render image to FBO */ /* render image to FBO */
clock_gettime(CLOCK_MONOTONIC_RAW, &frame_start); clock_gettime(CLOCK_MONOTONIC_RAW, &frame_start);
if (to_stdout)
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@ -255,9 +262,14 @@ int main(int argc, char **argv)
/* get image from FBO, dump to stdout */ /* get image from FBO, dump to stdout */
if (to_stdout) { if (to_stdout) {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, fbo_tex);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA,
GL_UNSIGNED_BYTE, fb32); GL_UNSIGNED_BYTE, fb32);
glBindTexture(GL_TEXTURE_2D, 0);
convert_for_ffmpeg(fb32, fb24, width, height); convert_for_ffmpeg(fb32, fb24, width, height);
if (write_retry(STDOUT_FILENO, fb24, if (write_retry(STDOUT_FILENO, fb24,