[gtk/wip/chergert/glproto: 675/920] more texture upload, vertices work
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/glproto: 675/920] more texture upload, vertices work
- Date: Mon, 8 Feb 2021 19:15:36 +0000 (UTC)
commit 3a4524b5e7d59b858628e67bbdf4cf7955c5bb94
Author: Christian Hergert <chergert redhat com>
Date: Mon Jan 11 12:32:20 2021 -0800
more texture upload, vertices work
gsk/next/gskgldriver.c | 43 +-----------
gsk/next/gskgldriverprivate.h | 3 +-
gsk/next/gskglrenderjob.c | 160 +++++++++++++++++++++++++++---------------
3 files changed, 105 insertions(+), 101 deletions(-)
---
diff --git a/gsk/next/gskgldriver.c b/gsk/next/gskgldriver.c
index 00bfa09e6f..498fd0f431 100644
--- a/gsk/next/gskgldriver.c
+++ b/gsk/next/gskgldriver.c
@@ -42,13 +42,6 @@
G_DEFINE_TYPE (GskNextDriver, gsk_next_driver, G_TYPE_OBJECT)
-static inline gboolean
-size_can_be_atlased (float width,
- float height)
-{
- return width < 128 && height < 128;
-}
-
static guint
texture_key_hash (gconstpointer v)
{
@@ -486,8 +479,6 @@ gsk_next_driver_cache_texture (GskNextDriver *self,
* @texture: a #GdkTexture
* @min_filter: GL_NEAREST or GL_LINEAR
* @mag_filter: GL_NEAREST or GL_LINEAR
- * @area: (out): a #graphene_rect_t containing the area within the texture
- * containing the contents that were uploaded.
*
* Loads a #GdkTexture by uploading the contents to the GPU when
* necessary. If @texture is a #GdkGLTexture, it can be used without
@@ -509,8 +500,7 @@ guint
gsk_next_driver_load_texture (GskNextDriver *self,
GdkTexture *texture,
int min_filter,
- int mag_filter,
- graphene_rect_t *area)
+ int mag_filter)
{
GdkGLContext *context;
GdkTexture *downloaded_texture = NULL;
@@ -522,7 +512,6 @@ gsk_next_driver_load_texture (GskNextDriver *self,
g_return_val_if_fail (GSK_IS_NEXT_DRIVER (self), 0);
g_return_val_if_fail (GDK_IS_TEXTURE (texture), 0);
g_return_val_if_fail (GSK_IS_GL_COMMAND_QUEUE (self->command_queue), 0);
- g_return_val_if_fail (area != NULL, 0);
context = self->command_queue->context;
@@ -537,8 +526,6 @@ gsk_next_driver_load_texture (GskNextDriver *self,
{
/* A GL texture from the same GL context is a simple task... */
- area->origin.x = area->origin.y = 0;
- area->size.width = area->size.height = 1;
return gdk_gl_texture_get_id ((GdkGLTexture *)texture);
}
else
@@ -565,11 +552,7 @@ gsk_next_driver_load_texture (GskNextDriver *self,
if ((t = gdk_texture_get_render_data (texture, self)))
{
if (t->min_filter == min_filter && t->mag_filter == mag_filter)
- {
- area->origin.x = area->origin.y = 0;
- area->size.width = area->size.height = 1;
- return t->texture_id;
- }
+ return t->texture_id;
}
source_texture = texture;
@@ -578,25 +561,6 @@ gsk_next_driver_load_texture (GskNextDriver *self,
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
- if (size_can_be_atlased (width, height))
- {
- GskGLTextureAtlas *atlas;
-
- if (gsk_gl_texture_library_lookup (GSK_GL_TEXTURE_LIBRARY (self->icons),
- texture, &atlas, area))
- return atlas->texture_id;
-
- if (gsk_gl_texture_library_pack (GSK_GL_TEXTURE_LIBRARY (self->icons),
- texture, sizeof (void *),
- width, height,
- &atlas, area))
- {
- gsk_gl_texture_library_upload (GSK_GL_TEXTURE_LIBRARY (self->icons),
- atlas, area, texture);
- return atlas->texture_id;
- }
- }
-
t = g_slice_new0 (GskGLTexture);
t->width = gdk_texture_get_width (texture);
t->height = gdk_texture_get_height (texture);
@@ -615,9 +579,6 @@ gsk_next_driver_load_texture (GskNextDriver *self,
if (gdk_texture_set_render_data (texture, self, t, gsk_gl_texture_destroyed))
t->user = texture;
- area->origin.x = area->origin.y = 0;
- area->size.width = area->size.height = 1;
-
gdk_gl_context_label_object_printf (context, GL_TEXTURE, t->texture_id,
"GdkTexture<%p> %d", texture, t->texture_id);
diff --git a/gsk/next/gskgldriverprivate.h b/gsk/next/gskgldriverprivate.h
index 7a75064de6..388df35784 100644
--- a/gsk/next/gskgldriverprivate.h
+++ b/gsk/next/gskgldriverprivate.h
@@ -113,8 +113,7 @@ void gsk_next_driver_cache_texture (GskNextDriver *se
guint gsk_next_driver_load_texture (GskNextDriver *self,
GdkTexture *texture,
int min_filter,
- int mag_filter,
- graphene_rect_t *area);
+ int mag_filter);
GskGLTexture *gsk_next_driver_create_texture (GskNextDriver *self,
float width,
float height,
diff --git a/gsk/next/gskglrenderjob.c b/gsk/next/gskglrenderjob.c
index 26db07e92f..dae2f28ccb 100644
--- a/gsk/next/gskglrenderjob.c
+++ b/gsk/next/gskglrenderjob.c
@@ -655,61 +655,97 @@ gsk_gl_render_job_node_overlaps_clip (GskGLRenderJob *job,
return TRUE;
}
-static void
-gsk_gl_render_job_draw_coords (GskGLRenderJob *job,
- float min_x,
- float min_y,
- float max_x,
- float max_y)
+/* load_vertex_data_with_region */
+static inline void
+gsk_gl_render_job_load_vertices_from_offscreen (GskGLRenderJob *job,
+ const graphene_rect_t *bounds,
+ const GskGLRenderOffscreen *offscreen)
{
GskGLDrawVertex *vertices = gsk_gl_command_queue_add_vertices (job->command_queue, NULL);
+ float min_x = job->offset_x + bounds->origin.x;
+ float min_y = job->offset_y + bounds->origin.y;
+ float max_x = min_x + bounds->size.width;
+ float max_y = min_y + bounds->size.height;
+ float y1 = offscreen->flip_y ? Y2 (&offscreen->area) : Y1 (&offscreen->area);
+ float y2 = offscreen->flip_y ? Y1 (&offscreen->area) : Y2 (&offscreen->area);
vertices[0].position[0] = min_x;
vertices[0].position[1] = min_y;
- vertices[0].uv[0] = 0;
- vertices[0].uv[1] = 1;
+ vertices[0].uv[0] = X1 (bounds);
+ vertices[0].uv[1] = y1;
vertices[1].position[0] = min_x;
vertices[1].position[1] = max_y;
- vertices[1].uv[0] = 0;
- vertices[1].uv[1] = 0;
+ vertices[1].uv[0] = X1 (bounds);
+ vertices[1].uv[1] = y2;
vertices[2].position[0] = max_x;
vertices[2].position[1] = min_y;
- vertices[2].uv[0] = 1;
- vertices[2].uv[1] = 1;
+ vertices[2].uv[0] = X2 (bounds);
+ vertices[2].uv[1] = y1;
vertices[3].position[0] = max_x;
vertices[3].position[1] = max_y;
- vertices[3].uv[0] = 1;
- vertices[3].uv[1] = 0;
+ vertices[3].uv[0] = X2 (bounds);
+ vertices[3].uv[1] = y2;
vertices[4].position[0] = min_x;
vertices[4].position[1] = max_y;
- vertices[4].uv[0] = 0;
- vertices[4].uv[1] = 0;
+ vertices[4].uv[0] = X1 (bounds);
+ vertices[4].uv[1] = y2;
vertices[5].position[0] = max_x;
vertices[5].position[1] = min_y;
- vertices[5].uv[0] = 1;
- vertices[5].uv[1] = 1;
+ vertices[5].uv[0] = X2 (bounds);
+ vertices[5].uv[1] = y1;
}
-static void
+/* load_float_vertex_data */
+static inline void
gsk_gl_render_job_draw (GskGLRenderJob *job,
float x,
float y,
float width,
float height)
{
+ GskGLDrawVertex *vertices = gsk_gl_command_queue_add_vertices (job->command_queue, NULL);
float min_x = job->offset_x + x;
float min_y = job->offset_y + y;
float max_x = min_x + width;
float max_y = min_y + height;
- gsk_gl_render_job_draw_coords (job, min_x, min_y, max_x, max_y);
+ vertices[0].position[0] = min_x;
+ vertices[0].position[1] = min_y;
+ vertices[0].uv[0] = 0;
+ vertices[0].uv[1] = 0;
+
+ vertices[1].position[0] = min_x;
+ vertices[1].position[1] = max_y;
+ vertices[1].uv[0] = 0;
+ vertices[1].uv[1] = 1;
+
+ vertices[2].position[0] = max_x;
+ vertices[2].position[1] = min_y;
+ vertices[2].uv[0] = 1;
+ vertices[2].uv[1] = 0;
+
+ vertices[3].position[0] = max_x;
+ vertices[3].position[1] = max_y;
+ vertices[3].uv[0] = 1;
+ vertices[3].uv[1] = 1;
+
+ vertices[4].position[0] = min_x;
+ vertices[4].position[1] = max_y;
+ vertices[4].uv[0] = 0;
+ vertices[4].uv[1] = 1;
+
+ vertices[5].position[0] = max_x;
+ vertices[5].position[1] = min_y;
+ vertices[5].uv[0] = 1;
+ vertices[5].uv[1] = 0;
}
+/* load_vertex_data */
static inline void
gsk_gl_render_job_draw_rect (GskGLRenderJob *job,
const graphene_rect_t *bounds)
@@ -721,50 +757,58 @@ gsk_gl_render_job_draw_rect (GskGLRenderJob *job,
bounds->size.height);
}
+/* fill_vertex_data */
static void
-gsk_gl_render_job_draw_from_offscreen (GskGLRenderJob *job,
- const graphene_rect_t *bounds,
- GskGLRenderOffscreen *offscreen)
+gsk_gl_render_job_draw_coords (GskGLRenderJob *job,
+ float min_x,
+ float min_y,
+ float max_x,
+ float max_y)
{
- GskGLDrawVertex *vertices;
- float min_x = job->offset_x + bounds->origin.x;
- float min_y = job->offset_y + bounds->origin.y;
- float max_x = min_x + bounds->size.width;
- float max_y = min_y + bounds->size.height;
- float y1 = offscreen->flip_y ? Y2 (&offscreen->area) : Y1 (&offscreen->area);
- float y2 = offscreen->flip_y ? Y1 (&offscreen->area) : Y2 (&offscreen->area);
-
- vertices = gsk_gl_command_queue_add_vertices (job->command_queue, NULL);
+ GskGLDrawVertex *vertices = gsk_gl_command_queue_add_vertices (job->command_queue, NULL);
vertices[0].position[0] = min_x;
vertices[0].position[1] = min_y;
- vertices[0].uv[0] = X1 (&offscreen->area);
- vertices[0].uv[1] = y1;
+ vertices[0].uv[0] = 0;
+ vertices[0].uv[1] = 1;
vertices[1].position[0] = min_x;
vertices[1].position[1] = max_y;
- vertices[1].uv[0] = X1 (&offscreen->area);
- vertices[1].uv[1] = y2;
+ vertices[1].uv[0] = 0;
+ vertices[1].uv[1] = 0;
vertices[2].position[0] = max_x;
vertices[2].position[1] = min_y;
- vertices[2].uv[0] = X2 (&offscreen->area);
- vertices[2].uv[1] = y1;
+ vertices[2].uv[0] = 1;
+ vertices[2].uv[1] = 1;
vertices[3].position[0] = max_x;
vertices[3].position[1] = max_y;
- vertices[3].uv[0] = X2 (&offscreen->area);
- vertices[3].uv[1] = y2;
+ vertices[3].uv[0] = 1;
+ vertices[3].uv[1] = 0;
vertices[4].position[0] = min_x;
vertices[4].position[1] = max_y;
- vertices[4].uv[0] = X1 (&offscreen->area);
- vertices[4].uv[1] = y2;
+ vertices[4].uv[0] = 0;
+ vertices[4].uv[1] = 0;
vertices[5].position[0] = max_x;
vertices[5].position[1] = min_y;
- vertices[5].uv[0] = X2 (&offscreen->area);
- vertices[5].uv[1] = y1;
+ vertices[5].uv[0] = 1;
+ vertices[5].uv[1] = 1;
+}
+
+/* load_offscreen_vertex_data */
+static inline void
+gsk_gl_render_job_draw_offscreen_rect (GskGLRenderJob *job,
+ const graphene_rect_t *bounds)
+{
+ float min_x = job->offset_x + bounds->origin.x;
+ float min_y = job->offset_y + bounds->origin.y;
+ float max_x = min_x + bounds->size.width;
+ float max_y = min_y + bounds->size.height;
+
+ gsk_gl_render_job_draw_coords (job, min_x, min_y, max_x, max_y);
}
static void
@@ -779,7 +823,6 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job,
cairo_surface_t *surface;
cairo_surface_t *rendered_surface;
cairo_t *cr;
- graphene_rect_t area;
int cached_id;
int texture_id;
GskTextureKey key;
@@ -806,7 +849,7 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job,
gsk_gl_program_set_uniform_texture (job->driver->blit,
UNIFORM_SHARED_SOURCE,
GL_TEXTURE_2D, GL_TEXTURE0, cached_id);
- gsk_gl_render_job_draw_rect (job, &node->bounds);
+ gsk_gl_render_job_draw_offscreen_rect (job, &node->bounds);
gsk_gl_program_end_draw (job->driver->blit);
return;
}
@@ -865,11 +908,8 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job,
/* Create texture to upload */
texture = gdk_texture_new_for_surface (surface);
- texture_id = gsk_next_driver_load_texture (job->driver,
- texture,
- GL_NEAREST,
- GL_NEAREST,
- &area);
+ texture_id = gsk_next_driver_load_texture (job->driver, texture,
+ GL_NEAREST, GL_NEAREST);
if (gdk_gl_context_has_debug (job->command_queue->context))
gdk_gl_context_label_object_printf (job->command_queue->context, GL_TEXTURE, texture_id,
@@ -889,7 +929,7 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job,
gsk_gl_render_job_get_modelview_matrix (job),
gsk_gl_render_job_get_clip (job),
job->alpha);
- gsk_gl_render_job_draw_rect (job, &area);
+ gsk_gl_render_job_draw_offscreen_rect (job, &node->bounds);
gsk_gl_program_end_draw (job->driver->blit);
}
@@ -1706,7 +1746,7 @@ gsk_gl_render_job_visit_opacity_node (GskGLRenderJob *job,
GL_TEXTURE_2D,
GL_TEXTURE0,
offscreen.texture_id);
- gsk_gl_render_job_draw_from_offscreen (job, &node->bounds, &offscreen);
+ gsk_gl_render_job_load_vertices_from_offscreen (job, &node->bounds, &offscreen);
gsk_gl_program_end_draw (job->driver->blit);
}
else
@@ -2004,13 +2044,17 @@ gsk_gl_render_job_visit_node_with_offscreen (GskGLRenderJob *job,
GdkTexture *texture = gsk_texture_node_get_texture (node);
offscreen->texture_id =
- gsk_next_driver_load_texture (job->driver,
- texture,
- GL_LINEAR,
- GL_LINEAR,
- &offscreen->area);
+ gsk_next_driver_load_texture (job->driver, texture,
+ GL_LINEAR, GL_LINEAR);
+
+ offscreen->area.origin.x = 0;
+ offscreen->area.origin.y = 0;
+ offscreen->area.size.width = 0;
+ offscreen->area.size.height = 0;
}
+ /* TODO: */
+
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]