[gtk+/wip/ebassi/render-solid-colors: 2/3] gsk: Allocate a white 1px texture target



commit cd2c20251ecce7e04511abb4ec64c9aa555f958e
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Nov 16 17:30:59 2016 +0000

    gsk: Allocate a white 1px texture target
    
    This allows us to efficiently render things like solid colors.

 gsk/gskgldriver.c        |   26 ++++++++++++++++++++++++++
 gsk/gskgldriverprivate.h |    2 ++
 2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/gsk/gskgldriver.c b/gsk/gskgldriver.c
index edb6653..8b0bd2a 100644
--- a/gsk/gskgldriver.c
+++ b/gsk/gskgldriver.c
@@ -42,6 +42,8 @@ struct _GskGLDriver
 
   Fbo default_fbo;
 
+  Texture white_texture;
+
   GHashTable *textures;
   GHashTable *vaos;
 
@@ -219,6 +221,22 @@ gsk_gl_driver_begin_frame (GskGLDriver *driver)
       GSK_NOTE (OPENGL, g_print ("GL max texture size: %d\n", driver->max_texture_size));
     }
 
+  if (driver->white_texture.texture_id == 0)
+    {
+      const float white_pixel[4] = { 1, 1, 1, 1, };
+
+      glGenTextures (1, &(driver->white_texture.texture_id));
+
+      driver->white_texture.width = 1;
+      driver->white_texture.height = 1;
+      driver->white_texture.min_filter = GL_NEAREST;
+      driver->white_texture.mag_filter = GL_NEAREST;
+      driver->white_texture.in_use = TRUE;
+
+      glBindTexture (GL_TEXTURE_2D, driver->white_texture.texture_id);
+      glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_FLOAT, white_pixel);
+    }
+
   glGetIntegerv (GL_FRAMEBUFFER_BINDING, (GLint *) &(driver->default_fbo.fbo_id));
   driver->bound_fbo = &driver->default_fbo;
 
@@ -848,3 +866,11 @@ gsk_gl_driver_init_texture_with_surface (GskGLDriver     *driver,
 
   glBindTexture (GL_TEXTURE_2D, 0);
 }
+
+int
+gsk_gl_driver_get_white_texture (GskGLDriver *driver)
+{
+  g_return_val_if_fail (GSK_IS_GL_DRIVER (driver), -1);
+
+  return driver->white_texture.texture_id;
+}
diff --git a/gsk/gskgldriverprivate.h b/gsk/gskgldriverprivate.h
index 64f9be1..b9e4d0e 100644
--- a/gsk/gskgldriverprivate.h
+++ b/gsk/gskgldriverprivate.h
@@ -67,6 +67,8 @@ void            gsk_gl_driver_destroy_vao               (GskGLDriver     *driver
 int             gsk_gl_driver_collect_textures          (GskGLDriver     *driver);
 int             gsk_gl_driver_collect_vaos              (GskGLDriver     *driver);
 
+int             gsk_gl_driver_get_white_texture         (GskGLDriver     *driver);
+
 G_END_DECLS
 
 #endif /* __GSK_GL_DRIVER_PRIVATE_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]