aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2017-10-10 15:54:50 +0200
committerGerd Hoffmann <kraxel@redhat.com>2017-10-17 10:25:42 +0200
commit2e1d70b9e03ca3f1c6185b54010bc9e47e0a0d0c (patch)
tree98f4a8f35a8a696ddcae2a20ea87db4425c8d396 /ui
parent46e19e149f3b129a22c440caba853188df67deab (diff)
downloadqemu-2e1d70b9e03ca3f1c6185b54010bc9e47e0a0d0c.zip
qemu-2e1d70b9e03ca3f1c6185b54010bc9e47e0a0d0c.tar.gz
qemu-2e1d70b9e03ca3f1c6185b54010bc9e47e0a0d0c.tar.bz2
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
Diffstat (limited to 'ui')
-rw-r--r--ui/console-gl.c2
-rw-r--r--ui/shader.c12
-rw-r--r--ui/shader/texture-blit-flip.vert10
3 files changed, 20 insertions, 4 deletions
diff --git a/ui/console-gl.c b/ui/console-gl.c
index 9b50dae..5b77e7a 100644
--- a/ui/console-gl.c
+++ b/ui/console-gl.c
@@ -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,
diff --git a/ui/shader.c b/ui/shader.c
index d36e7af..008458b 100644
--- a/ui/shader.c
+++ b/ui/shader.c
@@ -29,10 +29,12 @@
#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
index 0000000..ba081fa
--- /dev/null
+++ b/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;
+}