From 135721118a719ecacfd2bd83524a9c53c6ca6015 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 30 May 2018 14:18:07 +0100 Subject: render: remove wlr_renderer_check_import_dmabuf It's possible to implement it outside the renderer, by creating a texture and destroying it right away. This reduces the API surface of the renderer. --- render/gles2/renderer.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'render/gles2/renderer.c') diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index e68bb83f..ed12fc7c 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -242,12 +242,6 @@ static int gles2_get_dmabuf_modifiers(struct wlr_renderer *wlr_renderer, return wlr_egl_get_dmabuf_modifiers(renderer->egl, format, modifiers); } -static bool gles2_check_import_dmabuf(struct wlr_renderer *wlr_renderer, - struct wlr_dmabuf_attributes *attribs) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); - return wlr_egl_check_import_dmabuf(renderer->egl, attribs); -} - static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer, enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, @@ -348,7 +342,6 @@ static const struct wlr_renderer_impl renderer_impl = { .wl_drm_buffer_get_size = gles2_wl_drm_buffer_get_size, .get_dmabuf_formats = gles2_get_dmabuf_formats, .get_dmabuf_modifiers = gles2_get_dmabuf_modifiers, - .check_import_dmabuf = gles2_check_import_dmabuf, .read_pixels = gles2_read_pixels, .format_supported = gles2_format_supported, .texture_from_pixels = gles2_texture_from_pixels, -- cgit v1.2.3 From de91c55ea9da1b4c22bc377a7013efdcc71fff06 Mon Sep 17 00:00:00 2001 From: NeKit Date: Sun, 3 Jun 2018 01:20:09 +0300 Subject: Fix GLES2 renderer to use glGetUniformLocations locations This is needed as uniform locations are driver implementation-specific. --- include/render/gles2.h | 36 +++++++++++++--- render/gles2/renderer.c | 109 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 108 insertions(+), 37 deletions(-) (limited to 'render/gles2/renderer.c') diff --git a/include/render/gles2.h b/include/render/gles2.h index 99beff29..c47751d1 100644 --- a/include/render/gles2.h +++ b/include/render/gles2.h @@ -32,11 +32,37 @@ struct wlr_gles2_renderer { const char *exts_str; struct { - GLuint quad; - GLuint ellipse; - GLuint tex_rgba; - GLuint tex_rgbx; - GLuint tex_ext; + struct { + GLuint program; + GLint proj; + GLint color; + } quad; + struct { + GLuint program; + GLint proj; + GLint color; + } ellipse; + struct { + GLuint program; + GLint proj; + GLint invert_y; + GLint tex; + GLint alpha; + } tex_rgba; + struct { + GLuint program; + GLint proj; + GLint invert_y; + GLint tex; + GLint alpha; + } tex_rgbx; + struct { + GLuint program; + GLint proj; + GLint invert_y; + GLint tex; + GLint alpha; + } tex_ext; } shaders; uint32_t viewport_width, viewport_height; diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 1eeb915e..dce59d88 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -120,16 +120,36 @@ static bool gles2_render_texture_with_matrix(struct wlr_renderer *wlr_renderer, GLuint prog = 0; GLenum target = 0; + GLint proj_loc = 0; + GLint invert_y_loc = 0; + GLint tex_loc = 0; + GLint alpha_loc = 0; + switch (texture->type) { case WLR_GLES2_TEXTURE_GLTEX: case WLR_GLES2_TEXTURE_WL_DRM_GL: - prog = texture->has_alpha ? renderer->shaders.tex_rgba : - renderer->shaders.tex_rgbx; + if (texture->has_alpha) { + prog = renderer->shaders.tex_rgba.program; + proj_loc = renderer->shaders.tex_rgba.proj; + invert_y_loc = renderer->shaders.tex_rgba.invert_y; + tex_loc = renderer->shaders.tex_rgba.tex; + alpha_loc = renderer->shaders.tex_rgba.alpha; + } else { + prog = renderer->shaders.tex_rgbx.program; + proj_loc = renderer->shaders.tex_rgbx.proj; + invert_y_loc = renderer->shaders.tex_rgbx.invert_y; + tex_loc = renderer->shaders.tex_rgbx.tex; + alpha_loc = renderer->shaders.tex_rgbx.alpha; + } target = GL_TEXTURE_2D; break; case WLR_GLES2_TEXTURE_WL_DRM_EXT: case WLR_GLES2_TEXTURE_DMABUF: - prog = renderer->shaders.tex_ext; + prog = renderer->shaders.tex_ext.program; + proj_loc = renderer->shaders.tex_ext.proj; + invert_y_loc = renderer->shaders.tex_ext.invert_y; + tex_loc = renderer->shaders.tex_ext.tex; + alpha_loc = renderer->shaders.tex_ext.alpha; target = GL_TEXTURE_EXTERNAL_OES; break; } @@ -151,9 +171,10 @@ static bool gles2_render_texture_with_matrix(struct wlr_renderer *wlr_renderer, glUseProgram(prog); - glUniformMatrix3fv(0, 1, GL_FALSE, transposition); - glUniform1i(1, texture->inverted_y); - glUniform1f(3, alpha); + glUniformMatrix3fv(proj_loc, 1, GL_FALSE, transposition); + glUniform1i(invert_y_loc, texture->inverted_y); + glUniform1f(alpha_loc, alpha); + glUniform1i(tex_loc, 0); draw_quad(); @@ -173,9 +194,10 @@ static void gles2_render_quad_with_matrix(struct wlr_renderer *wlr_renderer, wlr_matrix_transpose(transposition, matrix); PUSH_GLES2_DEBUG; - glUseProgram(renderer->shaders.quad); - glUniformMatrix3fv(0, 1, GL_FALSE, transposition); - glUniform4f(1, color[0], color[1], color[2], color[3]); + glUseProgram(renderer->shaders.quad.program); + + glUniformMatrix3fv(renderer->shaders.quad.proj, 1, GL_FALSE, transposition); + glUniform4f(renderer->shaders.quad.color, color[0], color[1], color[2], color[3]); draw_quad(); POP_GLES2_DEBUG; } @@ -191,9 +213,10 @@ static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer, wlr_matrix_transpose(transposition, matrix); PUSH_GLES2_DEBUG; - glUseProgram(renderer->shaders.ellipse); - glUniformMatrix3fv(0, 1, GL_FALSE, transposition); - glUniform4f(1, color[0], color[1], color[2], color[3]); + glUseProgram(renderer->shaders.ellipse.program); + + glUniformMatrix3fv(renderer->shaders.ellipse.proj, 1, GL_FALSE, transposition); + glUniform4f(renderer->shaders.ellipse.color, color[0], color[1], color[2], color[3]); draw_quad(); POP_GLES2_DEBUG; } @@ -313,11 +336,11 @@ static void gles2_destroy(struct wlr_renderer *wlr_renderer) { wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL); PUSH_GLES2_DEBUG; - glDeleteProgram(renderer->shaders.quad); - glDeleteProgram(renderer->shaders.ellipse); - glDeleteProgram(renderer->shaders.tex_rgba); - glDeleteProgram(renderer->shaders.tex_rgbx); - glDeleteProgram(renderer->shaders.tex_ext); + glDeleteProgram(renderer->shaders.quad.program); + glDeleteProgram(renderer->shaders.ellipse.program); + glDeleteProgram(renderer->shaders.tex_rgba.program); + glDeleteProgram(renderer->shaders.tex_rgbx.program); + glDeleteProgram(renderer->shaders.tex_ext.program); POP_GLES2_DEBUG; if (glDebugMessageCallbackKHR) { @@ -486,31 +509,53 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) { PUSH_GLES2_DEBUG; - renderer->shaders.quad = link_program(quad_vertex_src, quad_fragment_src); - if (!renderer->shaders.quad) { + GLuint prog; + renderer->shaders.quad.program = prog = + link_program(quad_vertex_src, quad_fragment_src); + if (!renderer->shaders.quad.program) { goto error; } - renderer->shaders.ellipse = + renderer->shaders.quad.proj = glGetUniformLocation(prog, "proj"); + renderer->shaders.quad.color = glGetUniformLocation(prog, "color"); + + renderer->shaders.ellipse.program = prog = link_program(quad_vertex_src, ellipse_fragment_src); - if (!renderer->shaders.ellipse) { + if (!renderer->shaders.ellipse.program) { goto error; } - renderer->shaders.tex_rgba = + renderer->shaders.ellipse.proj = glGetUniformLocation(prog, "proj"); + renderer->shaders.ellipse.color = glGetUniformLocation(prog, "color"); + + renderer->shaders.tex_rgba.program = prog = link_program(tex_vertex_src, tex_fragment_src_rgba); - if (!renderer->shaders.tex_rgba) { + if (!renderer->shaders.tex_rgba.program) { goto error; } - renderer->shaders.tex_rgbx = + renderer->shaders.tex_rgba.proj = glGetUniformLocation(prog, "proj"); + renderer->shaders.tex_rgba.invert_y = glGetUniformLocation(prog, "invert_y"); + renderer->shaders.tex_rgba.tex = glGetUniformLocation(prog, "tex"); + renderer->shaders.tex_rgba.alpha = glGetUniformLocation(prog, "alpha"); + + renderer->shaders.tex_rgbx.program = prog = link_program(tex_vertex_src, tex_fragment_src_rgbx); - if (!renderer->shaders.tex_rgbx) { + if (!renderer->shaders.tex_rgbx.program) { goto error; } + renderer->shaders.tex_rgbx.proj = glGetUniformLocation(prog, "proj"); + renderer->shaders.tex_rgbx.invert_y = glGetUniformLocation(prog, "invert_y"); + renderer->shaders.tex_rgbx.tex = glGetUniformLocation(prog, "tex"); + renderer->shaders.tex_rgbx.alpha = glGetUniformLocation(prog, "alpha"); + if (glEGLImageTargetTexture2DOES) { - renderer->shaders.tex_ext = + renderer->shaders.tex_ext.program = prog = link_program(tex_vertex_src, tex_fragment_src_external); - if (!renderer->shaders.tex_ext) { + if (!renderer->shaders.tex_ext.program) { goto error; } + renderer->shaders.tex_ext.proj = glGetUniformLocation(prog, "proj"); + renderer->shaders.tex_ext.invert_y = glGetUniformLocation(prog, "invert_y"); + renderer->shaders.tex_ext.tex = glGetUniformLocation(prog, "tex"); + renderer->shaders.tex_ext.alpha = glGetUniformLocation(prog, "alpha"); } POP_GLES2_DEBUG; @@ -518,11 +563,11 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) { return &renderer->wlr_renderer; error: - glDeleteProgram(renderer->shaders.quad); - glDeleteProgram(renderer->shaders.ellipse); - glDeleteProgram(renderer->shaders.tex_rgba); - glDeleteProgram(renderer->shaders.tex_rgbx); - glDeleteProgram(renderer->shaders.tex_ext); + glDeleteProgram(renderer->shaders.quad.program); + glDeleteProgram(renderer->shaders.ellipse.program); + glDeleteProgram(renderer->shaders.tex_rgba.program); + glDeleteProgram(renderer->shaders.tex_rgbx.program); + glDeleteProgram(renderer->shaders.tex_ext.program); POP_GLES2_DEBUG; -- cgit v1.2.3 From 6f29db10446662ac6741e4a63bac74380f01199e Mon Sep 17 00:00:00 2001 From: NeKit Date: Wed, 13 Jun 2018 13:43:01 +0300 Subject: gles2 renderer: introduce struct wlr_gles2_tex_shader --- include/render/gles2.h | 32 +++++++++++--------------------- render/gles2/renderer.c | 34 +++++++++------------------------- 2 files changed, 20 insertions(+), 46 deletions(-) (limited to 'render/gles2/renderer.c') diff --git a/include/render/gles2.h b/include/render/gles2.h index c47751d1..67d4e9f5 100644 --- a/include/render/gles2.h +++ b/include/render/gles2.h @@ -25,6 +25,14 @@ struct wlr_gles2_pixel_format { bool has_alpha; }; +struct wlr_gles2_tex_shader { + GLuint program; + GLint proj; + GLint invert_y; + GLint tex; + GLint alpha; +}; + struct wlr_gles2_renderer { struct wlr_renderer wlr_renderer; @@ -42,27 +50,9 @@ struct wlr_gles2_renderer { GLint proj; GLint color; } ellipse; - struct { - GLuint program; - GLint proj; - GLint invert_y; - GLint tex; - GLint alpha; - } tex_rgba; - struct { - GLuint program; - GLint proj; - GLint invert_y; - GLint tex; - GLint alpha; - } tex_rgbx; - struct { - GLuint program; - GLint proj; - GLint invert_y; - GLint tex; - GLint alpha; - } tex_ext; + struct wlr_gles2_tex_shader tex_rgba; + struct wlr_gles2_tex_shader tex_rgbx; + struct wlr_gles2_tex_shader tex_ext; } shaders; uint32_t viewport_width, viewport_height; diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index dce59d88..05426fa9 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -118,38 +118,22 @@ static bool gles2_render_texture_with_matrix(struct wlr_renderer *wlr_renderer, struct wlr_gles2_texture *texture = get_gles2_texture_in_context(wlr_texture); - GLuint prog = 0; + struct wlr_gles2_tex_shader *shader = NULL; GLenum target = 0; - GLint proj_loc = 0; - GLint invert_y_loc = 0; - GLint tex_loc = 0; - GLint alpha_loc = 0; switch (texture->type) { case WLR_GLES2_TEXTURE_GLTEX: case WLR_GLES2_TEXTURE_WL_DRM_GL: if (texture->has_alpha) { - prog = renderer->shaders.tex_rgba.program; - proj_loc = renderer->shaders.tex_rgba.proj; - invert_y_loc = renderer->shaders.tex_rgba.invert_y; - tex_loc = renderer->shaders.tex_rgba.tex; - alpha_loc = renderer->shaders.tex_rgba.alpha; + shader = &renderer->shaders.tex_rgba; } else { - prog = renderer->shaders.tex_rgbx.program; - proj_loc = renderer->shaders.tex_rgbx.proj; - invert_y_loc = renderer->shaders.tex_rgbx.invert_y; - tex_loc = renderer->shaders.tex_rgbx.tex; - alpha_loc = renderer->shaders.tex_rgbx.alpha; + shader = &renderer->shaders.tex_rgbx; } target = GL_TEXTURE_2D; break; case WLR_GLES2_TEXTURE_WL_DRM_EXT: case WLR_GLES2_TEXTURE_DMABUF: - prog = renderer->shaders.tex_ext.program; - proj_loc = renderer->shaders.tex_ext.proj; - invert_y_loc = renderer->shaders.tex_ext.invert_y; - tex_loc = renderer->shaders.tex_ext.tex; - alpha_loc = renderer->shaders.tex_ext.alpha; + shader = &renderer->shaders.tex_ext; target = GL_TEXTURE_EXTERNAL_OES; break; } @@ -169,12 +153,12 @@ static bool gles2_render_texture_with_matrix(struct wlr_renderer *wlr_renderer, glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glUseProgram(prog); + glUseProgram(shader->program); - glUniformMatrix3fv(proj_loc, 1, GL_FALSE, transposition); - glUniform1i(invert_y_loc, texture->inverted_y); - glUniform1f(alpha_loc, alpha); - glUniform1i(tex_loc, 0); + glUniformMatrix3fv(shader->proj, 1, GL_FALSE, transposition); + glUniform1i(shader->invert_y, texture->inverted_y); + glUniform1i(shader->tex, 0); + glUniform1f(shader->alpha, alpha); draw_quad(); -- cgit v1.2.3