Browse Source

opengl: add flipping vertex shader

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
Gerd Hoffmann 7 years ago
parent
commit
2e1d70b9e0
5 changed files with 24 additions and 6 deletions
  1. 3 1
      Makefile
  2. 1 1
      include/ui/shader.h
  3. 1 1
      ui/console-gl.c
  4. 9 3
      ui/shader.c
  5. 10 0
      ui/shader/texture-blit-flip.vert

+ 3 - 1
Makefile

@@ -673,7 +673,9 @@ ui/shader/%-frag.h: $(SRC_PATH)/ui/shader/%.frag $(SRC_PATH)/scripts/shaderinclu
 		"FRAG","$@")
 		"FRAG","$@")
 
 
 ui/shader.o: $(SRC_PATH)/ui/shader.c \
 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
 # documentation
 MAKEINFO=makeinfo
 MAKEINFO=makeinfo

+ 1 - 1
include/ui/shader.h

@@ -5,7 +5,7 @@
 
 
 typedef struct QemuGLShader QemuGLShader;
 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);
 QemuGLShader *qemu_gl_init_shader(void);
 void qemu_gl_fini_shader(QemuGLShader *gls);
 void qemu_gl_fini_shader(QemuGLShader *gls);

+ 1 - 1
ui/console-gl.c

@@ -109,7 +109,7 @@ void surface_gl_render_texture(QemuGLShader *gls,
     glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
     glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
     glClear(GL_COLOR_BUFFER_BIT);
     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,
 void surface_gl_destroy_texture(QemuGLShader *gls,

+ 9 - 3
ui/shader.c

@@ -29,10 +29,12 @@
 #include "ui/shader.h"
 #include "ui/shader.h"
 
 
 #include "shader/texture-blit-vert.h"
 #include "shader/texture-blit-vert.h"
+#include "shader/texture-blit-flip-vert.h"
 #include "shader/texture-blit-frag.h"
 #include "shader/texture-blit-frag.h"
 
 
 struct QemuGLShader {
 struct QemuGLShader {
     GLint texture_blit_prog;
     GLint texture_blit_prog;
+    GLint texture_blit_flip_prog;
     GLint texture_blit_vao;
     GLint texture_blit_vao;
 };
 };
 
 
@@ -68,9 +70,11 @@ static GLuint qemu_gl_init_texture_blit(GLint texture_blit_prog)
     return vao;
     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);
     glBindVertexArray(gls->texture_blit_vao);
     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
     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
     gls->texture_blit_prog = qemu_gl_create_compile_link_program
         (texture_blit_vert_src, texture_blit_frag_src);
         (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);
         exit(1);
     }
     }
 
 

+ 10 - 0
ui/shader/texture-blit-flip.vert

@@ -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;
+}