From 37697f18179273c96204ebd9b53eee84cbf5204e Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 22 Nov 2014 09:39:18 -0800 Subject: [PATCH] gdkgl: Use a GdkTexturedQuad struct to paint quads We'll soon have a new function that paints multiple quads. --- gdk/gdkgl.c | 50 ++++++++++++++++++++------------------ gdk/gdkinternals.h | 12 ++++++--- gdk/x11/gdkglcontext-x11.c | 14 +++++++---- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c index 956d416941..d61c87ddf4 100644 --- a/gdk/gdkgl.c +++ b/gdk/gdkgl.c @@ -207,10 +207,7 @@ use_texture_rect_program (GdkGLContextPaintData *paint_data) void gdk_gl_texture_quad (GdkGLContext *paint_context, guint texture_target, - float x1, float y1, - float x2, float y2, - float u1, float v1, - float u2, float v2) + GdkTexturedQuad *quad) { GdkGLContextPaintData *paint_data = gdk_gl_context_get_paint_data (paint_context); GdkGLContextProgram *program; @@ -219,16 +216,16 @@ gdk_gl_texture_quad (GdkGLContext *paint_context, float w = gdk_window_get_width (window) * window_scale; float h = gdk_window_get_height (window) * window_scale; float vertex_buffer_data[] = { - (x2 * 2) / w - 1, (y1 * 2) / h - 1, - (x2 * 2) / w - 1, (y2 * 2) / h - 1, - (x1 * 2) / w - 1, (y2 * 2) / h - 1, - (x1 * 2) / w - 1, (y1 * 2) / h - 1, + (quad->x2 * 2) / w - 1, (quad->y1 * 2) / h - 1, + (quad->x2 * 2) / w - 1, (quad->y2 * 2) / h - 1, + (quad->x1 * 2) / w - 1, (quad->y2 * 2) / h - 1, + (quad->x1 * 2) / w - 1, (quad->y1 * 2) / h - 1, }; float uv_buffer_data[] = { - u2, v1, - u2, v2, - u1, v2, - u1, v1, + quad->u2, quad->v1, + quad->u2, quad->v2, + quad->u1, quad->v2, + quad->u1, quad->v1, }; bind_vao (paint_data); @@ -262,7 +259,6 @@ gdk_gl_texture_quad (GdkGLContext *paint_context, glDisableVertexAttribArray (1); } - /* x,y,width,height describes a rectangle in the gl render buffer coordinate space, and its top left corner is drawn at the current position according to the cairo translation. */ @@ -533,13 +529,14 @@ gdk_cairo_draw_from_gl (cairo_t *cr, { int clipped_src_x = x + (dest.x - dx * window_scale); int clipped_src_y = y + (height - dest.height - (dest.y - dy * window_scale)); + GdkTexturedQuad quad = { + dest.x, FLIP_Y(dest.y), + dest.x + dest.width, FLIP_Y(dest.y + dest.height), + clipped_src_x / (float)texture_width, (clipped_src_y + dest.height) / (float)texture_height, + (clipped_src_x + dest.width) / (float)texture_width, clipped_src_y / (float)texture_height, + }; - gdk_gl_texture_quad (paint_context, - GL_TEXTURE_2D, - dest.x, FLIP_Y(dest.y), - dest.x + dest.width, FLIP_Y(dest.y + dest.height), - clipped_src_x / (float)texture_width, (clipped_src_y + dest.height) / (float)texture_height, - (clipped_src_x + dest.width) / (float)texture_width, clipped_src_y / (float)texture_height); + gdk_gl_texture_quad (paint_context, GL_TEXTURE_2D, &quad); if (impl_window->current_paint.flushed_region) { @@ -713,11 +710,16 @@ gdk_gl_texture_from_surface (cairo_surface_t *surface, vmax = 1.0; } - gdk_gl_texture_quad (paint_context, target, - rect.x * window_scale, FLIP_Y(rect.y), - (rect.x + rect.width) * window_scale, FLIP_Y((rect.y + rect.height) * window_scale), - 0, 0, - umax, vmax); + { + GdkTexturedQuad quad = { + rect.x * window_scale, FLIP_Y(rect.y), + (rect.x + rect.width) * window_scale, FLIP_Y((rect.y + rect.height) * window_scale), + 0, 0, + umax, vmax, + }; + + gdk_gl_texture_quad (paint_context, target, &quad); + } } glDisable (GL_SCISSOR_TEST); diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h index ca89811e4d..d945a19a6e 100644 --- a/gdk/gdkinternals.h +++ b/gdk/gdkinternals.h @@ -350,12 +350,16 @@ gboolean _gdk_cairo_surface_extents (cairo_surface_t *surface, GdkRectangle *extents); void gdk_gl_texture_from_surface (cairo_surface_t *surface, cairo_region_t *region); + +typedef struct { + float x1, y1, x2, y2; + float u1, v1, u2, v2; +} GdkTexturedQuad; + void gdk_gl_texture_quad (GdkGLContext *paint_context, guint texture_target, - float x1, float y1, - float x2, float y2, - float u1, float v1, - float u2, float v2); + GdkTexturedQuad *quad); + void gdk_cairo_surface_mark_as_direct (cairo_surface_t *surface, GdkWindow *window); cairo_region_t *gdk_cairo_region_from_clip (cairo_t *cr); diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c index 3383d3d520..92d0b9e709 100644 --- a/gdk/x11/gdkglcontext-x11.c +++ b/gdk/x11/gdkglcontext-x11.c @@ -498,11 +498,15 @@ gdk_x11_gl_context_texture_from_surface (GdkGLContext *paint_context, vscale = 1.0 / cairo_xlib_surface_get_height (surface); } - gdk_gl_texture_quad (paint_context, target, - rect.x * window_scale, FLIP_Y(rect.y) * window_scale, - (rect.x + rect.width) * window_scale, FLIP_Y(rect.y + rect.height) * window_scale, - uscale * src_x, vscale * src_y, - uscale * (src_x + src_width), vscale * (src_y + src_height)); + { + GdkTexturedQuad quad = { + rect.x * window_scale, FLIP_Y(rect.y) * window_scale, + (rect.x + rect.width) * window_scale, FLIP_Y(rect.y + rect.height) * window_scale, + uscale * src_x, vscale * src_y, + uscale * (src_x + src_width), vscale * (src_y + src_height), + }; + gdk_gl_texture_quad (paint_context, target, &quad); + } } glXReleaseTexImageEXT (glx_pixmap->display, glx_pixmap->drawable,