opengl: add flipping vertex shader
authorGerd Hoffmann <kraxel@redhat.com>
Tue, 10 Oct 2017 13:54:50 +0000 (15:54 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Tue, 17 Oct 2017 08:25:42 +0000 (10:25 +0200)
Add vertex shader which flips the texture upside down while blitting it.
Add argument to qemu_gl_run_texture_blit() to enable flipping.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 20171010135453.6704-4-kraxel@redhat.com

Makefile
include/ui/shader.h
ui/console-gl.c
ui/shader.c
ui/shader/texture-blit-flip.vert [new file with mode: 0644]

index e124f1c5a0854508667d613eca14fdeeb29b8f12..0d293ad29415b4a0d1a569dbcc89c6fa39d57549 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -673,7 +673,9 @@ ui/shader/%-frag.h: $(SRC_PATH)/ui/shader/%.frag $(SRC_PATH)/scripts/shaderinclu
                "FRAG","$@")
 
 ui/shader.o: $(SRC_PATH)/ui/shader.c \
-       ui/shader/texture-blit-vert.h ui/shader/texture-blit-frag.h
+       ui/shader/texture-blit-vert.h \
+       ui/shader/texture-blit-flip-vert.h \
+       ui/shader/texture-blit-frag.h
 
 # documentation
 MAKEINFO=makeinfo
index 369e49865f9985b0a7a533f93418181c9c384746..4c5acb2ce8b21ac4b0b270a395fa9b83f6a6f88a 100644 (file)
@@ -5,7 +5,7 @@
 
 typedef struct QemuGLShader QemuGLShader;
 
-void qemu_gl_run_texture_blit(QemuGLShader *gls);
+void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip);
 
 QemuGLShader *qemu_gl_init_shader(void);
 void qemu_gl_fini_shader(QemuGLShader *gls);
index 9b50daedbd2e926ebff9ab7099d9f0a085ea49fb..5b77e7aa88cf4bf3877eac4281f554b204096f17 100644 (file)
@@ -109,7 +109,7 @@ void surface_gl_render_texture(QemuGLShader *gls,
     glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
     glClear(GL_COLOR_BUFFER_BIT);
 
-    qemu_gl_run_texture_blit(gls);
+    qemu_gl_run_texture_blit(gls, false);
 }
 
 void surface_gl_destroy_texture(QemuGLShader *gls,
index d36e7af232518962597bb54db859a6a3640639f2..008458bf94edba4b8bad31b619622d82c50a0287 100644 (file)
 #include "ui/shader.h"
 
 #include "shader/texture-blit-vert.h"
+#include "shader/texture-blit-flip-vert.h"
 #include "shader/texture-blit-frag.h"
 
 struct QemuGLShader {
     GLint texture_blit_prog;
+    GLint texture_blit_flip_prog;
     GLint texture_blit_vao;
 };
 
@@ -68,9 +70,11 @@ static GLuint qemu_gl_init_texture_blit(GLint texture_blit_prog)
     return vao;
 }
 
-void qemu_gl_run_texture_blit(QemuGLShader *gls)
+void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip)
 {
-    glUseProgram(gls->texture_blit_prog);
+    glUseProgram(flip
+                 ? gls->texture_blit_flip_prog
+                 : gls->texture_blit_prog);
     glBindVertexArray(gls->texture_blit_vao);
     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 }
@@ -150,7 +154,9 @@ QemuGLShader *qemu_gl_init_shader(void)
 
     gls->texture_blit_prog = qemu_gl_create_compile_link_program
         (texture_blit_vert_src, texture_blit_frag_src);
-    if (!gls->texture_blit_prog) {
+    gls->texture_blit_flip_prog = qemu_gl_create_compile_link_program
+        (texture_blit_flip_vert_src, texture_blit_frag_src);
+    if (!gls->texture_blit_prog || !gls->texture_blit_flip_prog) {
         exit(1);
     }
 
diff --git a/ui/shader/texture-blit-flip.vert b/ui/shader/texture-blit-flip.vert
new file mode 100644 (file)
index 0000000..ba081fa
--- /dev/null
@@ -0,0 +1,10 @@
+
+#version 300 es
+
+in vec2  in_position;
+out vec2 ex_tex_coord;
+
+void main(void) {
+    gl_Position = vec4(in_position, 0.0, 1.0);
+    ex_tex_coord = vec2(1.0 + in_position.x, 1.0 + in_position.y) * 0.5;
+}