[gtk+/wip/ebassi/gles: 102/113] gl: Add 'use-es' flag



commit daeefc11127ba007e80a7802c8e67299c59b0cbd
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Apr 18 10:10:30 2016 +0100

    gl: Add 'use-es' flag
    
    On some platforms we can ask the GL context machinery to create a GLES
    context, instead of a GL one.
    
    In order to ask for a GLES context at GdkGLContext realization time, we
    use a bit field like we do for forward compatible, or debug contexts.
    
    The 'use-es' bit also changes the way we select a default version,
    because OpenGL and OpenGLES versions differ.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=743746

 gdk/gdkglcontext.c        |   46 ++++++++++++++++++++++++++++++++++++++++----
 gdk/gdkglcontext.h        |    5 ++++
 gdk/gdkglcontextprivate.h |    1 +
 3 files changed, 47 insertions(+), 5 deletions(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 00a33eb..00a2c78 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -104,6 +104,7 @@ typedef struct {
   guint debug_enabled : 1;
   guint forward_compatible : 1;
   guint is_legacy : 1;
+  guint use_es : 1;
 
   GdkGLContextPaintData *paint_data;
 } GdkGLContextPrivate;
@@ -496,8 +497,8 @@ gdk_gl_context_set_required_version (GdkGLContext *context,
                                      int           major,
                                      int           minor)
 {
-  int version;
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+  int version, min_ver;
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
   g_return_if_fail (!priv->realized);
@@ -512,10 +513,16 @@ gdk_gl_context_set_required_version (GdkGLContext *context,
 
   /* Enforce a minimum context version number of 3.2 */
   version = (major * 100) + minor;
-  if (version < 302)
+
+  if (!priv->use_es)
+    min_ver = 302;
+  else
+    min_ver = 200;
+
+  if (version < min_ver)
     {
       g_warning ("gdk_gl_context_set_required_version - GL context versions less than 3.2 are not 
supported.");
-      version = 302;
+      version = min_ver;
     }
   priv->major = version / 100;
   priv->minor = version % 100;
@@ -538,19 +545,31 @@ gdk_gl_context_get_required_version (GdkGLContext *context,
                                      int          *minor)
 {
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+  int default_major, default_minor;
   int maj, min;
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
 
+  if (!priv->use_es)
+    {
+      default_major = 3;
+      default_minor = 2;
+    }
+  else
+    {
+      default_major = 2;
+      default_minor = 0;
+    }
+
   if (priv->major > 0)
     maj = priv->major;
   else
-    maj = 3;
+    maj = default_major;
 
   if (priv->minor > 0)
     min = priv->minor;
   else
-    min = 2;
+    min = default_minor;
 
   if (major != NULL)
     *major = maj;
@@ -603,6 +622,23 @@ gdk_gl_context_set_is_legacy (GdkGLContext *context,
   priv->is_legacy = !!is_legacy;
 }
 
+void
+gdk_gl_context_set_use_es (GdkGLContext *context,
+                           gboolean      use_es)
+{
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+
+  priv->use_es = !!use_es;
+}
+
+gboolean
+gdk_gl_context_get_use_es (GdkGLContext *context)
+{
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+
+  return priv->use_es;
+}
+
 /**
  * gdk_gl_context_realize:
  * @context: a #GdkGLContext
diff --git a/gdk/gdkglcontext.h b/gdk/gdkglcontext.h
index daacd1e..44633a7 100644
--- a/gdk/gdkglcontext.h
+++ b/gdk/gdkglcontext.h
@@ -73,6 +73,11 @@ void                    gdk_gl_context_set_forward_compatible   (GdkGLContext  *
                                                                  gboolean       compatible);
 GDK_AVAILABLE_IN_3_16
 gboolean                gdk_gl_context_get_forward_compatible   (GdkGLContext  *context);
+GDK_AVAILABLE_IN_3_22
+void                    gdk_gl_context_set_use_es               (GdkGLContext  *context,
+                                                                 gboolean       use_es);
+GDK_AVAILABLE_IN_3_22
+gboolean                gdk_gl_context_get_use_es               (GdkGLContext  *context);
 
 GDK_AVAILABLE_IN_3_16
 gboolean                gdk_gl_context_realize                  (GdkGLContext  *context,
diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h
index 348c168..4660494 100644
--- a/gdk/gdkglcontextprivate.h
+++ b/gdk/gdkglcontextprivate.h
@@ -69,6 +69,7 @@ typedef struct {
   GdkGLContextProgram *current_program;
 
   guint is_legacy : 1;
+  guint use_es : 1;
 } GdkGLContextPaintData;
 
 void                    gdk_gl_context_set_is_legacy            (GdkGLContext    *context,


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