console-gl.c (98c710f2d5cdf37f29a267352eb1f3c28cbf369d) console-gl.c (46e19e149f3b129a22c440caba853188df67deab)
1/*
2 * QEMU graphical console -- opengl helper bits
3 *
4 * Copyright (c) 2014 Red Hat
5 *
6 * Authors:
7 * Gerd Hoffmann <kraxel@redhat.com>
8 *

--- 15 unchanged lines hidden (view full) ---

24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 */
27#include "qemu/osdep.h"
28#include "qemu-common.h"
29#include "ui/console.h"
30#include "ui/shader.h"
31
1/*
2 * QEMU graphical console -- opengl helper bits
3 *
4 * Copyright (c) 2014 Red Hat
5 *
6 * Authors:
7 * Gerd Hoffmann <kraxel@redhat.com>
8 *

--- 15 unchanged lines hidden (view full) ---

24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 */
27#include "qemu/osdep.h"
28#include "qemu-common.h"
29#include "ui/console.h"
30#include "ui/shader.h"
31
32#include "shader/texture-blit-vert.h"
33#include "shader/texture-blit-frag.h"
34
35struct ConsoleGLState {
36 GLint texture_blit_prog;
37 GLint texture_blit_vao;
38};
39
40/* ---------------------------------------------------------------------- */
41
32/* ---------------------------------------------------------------------- */
33
42ConsoleGLState *console_gl_init_context(void)
43{
44 ConsoleGLState *gls = g_new0(ConsoleGLState, 1);
45
46 gls->texture_blit_prog = qemu_gl_create_compile_link_program
47 (texture_blit_vert_src, texture_blit_frag_src);
48 if (!gls->texture_blit_prog) {
49 exit(1);
50 }
51
52 gls->texture_blit_vao =
53 qemu_gl_init_texture_blit(gls->texture_blit_prog);
54
55 return gls;
56}
57
58void console_gl_fini_context(ConsoleGLState *gls)
59{
60 if (!gls) {
61 return;
62 }
63 g_free(gls);
64}
65
66bool console_gl_check_format(DisplayChangeListener *dcl,
67 pixman_format_code_t format)
68{
69 switch (format) {
70 case PIXMAN_BE_b8g8r8x8:
71 case PIXMAN_BE_b8g8r8a8:
72 case PIXMAN_r5g6b5:
73 return true;
74 default:
75 return false;
76 }
77}
78
34bool console_gl_check_format(DisplayChangeListener *dcl,
35 pixman_format_code_t format)
36{
37 switch (format) {
38 case PIXMAN_BE_b8g8r8x8:
39 case PIXMAN_BE_b8g8r8a8:
40 case PIXMAN_r5g6b5:
41 return true;
42 default:
43 return false;
44 }
45}
46
79void surface_gl_create_texture(ConsoleGLState *gls,
47void surface_gl_create_texture(QemuGLShader *gls,
80 DisplaySurface *surface)
81{
82 assert(gls);
83 assert(surface_stride(surface) % surface_bytes_per_pixel(surface) == 0);
84
85 switch (surface->format) {
86 case PIXMAN_BE_b8g8r8x8:
87 case PIXMAN_BE_b8g8r8a8:

--- 23 unchanged lines hidden (view full) ---

111 surface_height(surface),
112 0, surface->glformat, surface->gltype,
113 surface_data(surface));
114
115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
116 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
117}
118
48 DisplaySurface *surface)
49{
50 assert(gls);
51 assert(surface_stride(surface) % surface_bytes_per_pixel(surface) == 0);
52
53 switch (surface->format) {
54 case PIXMAN_BE_b8g8r8x8:
55 case PIXMAN_BE_b8g8r8a8:

--- 23 unchanged lines hidden (view full) ---

79 surface_height(surface),
80 0, surface->glformat, surface->gltype,
81 surface_data(surface));
82
83 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
84 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
85}
86
119void surface_gl_update_texture(ConsoleGLState *gls,
87void surface_gl_update_texture(QemuGLShader *gls,
120 DisplaySurface *surface,
121 int x, int y, int w, int h)
122{
123 uint8_t *data = (void *)surface_data(surface);
124
125 assert(gls);
126
127 glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT,
128 surface_stride(surface) / surface_bytes_per_pixel(surface));
129 glTexSubImage2D(GL_TEXTURE_2D, 0,
130 x, y, w, h,
131 surface->glformat, surface->gltype,
132 data + surface_stride(surface) * y
133 + surface_bytes_per_pixel(surface) * x);
134}
135
88 DisplaySurface *surface,
89 int x, int y, int w, int h)
90{
91 uint8_t *data = (void *)surface_data(surface);
92
93 assert(gls);
94
95 glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT,
96 surface_stride(surface) / surface_bytes_per_pixel(surface));
97 glTexSubImage2D(GL_TEXTURE_2D, 0,
98 x, y, w, h,
99 surface->glformat, surface->gltype,
100 data + surface_stride(surface) * y
101 + surface_bytes_per_pixel(surface) * x);
102}
103
136void surface_gl_render_texture(ConsoleGLState *gls,
104void surface_gl_render_texture(QemuGLShader *gls,
137 DisplaySurface *surface)
138{
139 assert(gls);
140
141 glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
142 glClear(GL_COLOR_BUFFER_BIT);
143
105 DisplaySurface *surface)
106{
107 assert(gls);
108
109 glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
110 glClear(GL_COLOR_BUFFER_BIT);
111
144 qemu_gl_run_texture_blit(gls->texture_blit_prog,
145 gls->texture_blit_vao);
112 qemu_gl_run_texture_blit(gls);
146}
147
113}
114
148void surface_gl_destroy_texture(ConsoleGLState *gls,
115void surface_gl_destroy_texture(QemuGLShader *gls,
149 DisplaySurface *surface)
150{
151 if (!surface || !surface->texture) {
152 return;
153 }
154 glDeleteTextures(1, &surface->texture);
155 surface->texture = 0;
156}
157
116 DisplaySurface *surface)
117{
118 if (!surface || !surface->texture) {
119 return;
120 }
121 glDeleteTextures(1, &surface->texture);
122 surface->texture = 0;
123}
124
158void surface_gl_setup_viewport(ConsoleGLState *gls,
125void surface_gl_setup_viewport(QemuGLShader *gls,
159 DisplaySurface *surface,
160 int ww, int wh)
161{
162 int gw, gh, stripe;
163 float sw, sh;
164
165 assert(gls);
166

--- 13 unchanged lines hidden ---
126 DisplaySurface *surface,
127 int ww, int wh)
128{
129 int gw, gh, stripe;
130 float sw, sh;
131
132 assert(gls);
133

--- 13 unchanged lines hidden ---