diff --git a/gdk/gdkdisplayprivate.h b/gdk/gdkdisplayprivate.h index 0cd45f856f..6bd87d149c 100644 --- a/gdk/gdkdisplayprivate.h +++ b/gdk/gdkdisplayprivate.h @@ -116,6 +116,9 @@ struct _GdkDisplay guint double_click_time; /* Maximum time between clicks in msecs */ guint double_click_distance; /* Maximum distance between clicks in pixels */ + + guint has_gl_extension_texture_non_power_of_two : 1; + guint has_gl_extension_texture_rectangle : 1; }; struct _GdkDisplayClass diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c index 1bfb17f7e7..f1e87406e3 100644 --- a/gdk/gdkglcontext.c +++ b/gdk/gdkglcontext.c @@ -77,9 +77,15 @@ #include "gdkintl.h" +#include + typedef struct { GdkWindow *window; GdkVisual *visual; + + guint realized : 1; + guint use_texture_rectangle : 1; + } GdkGLContextPrivate; enum { @@ -265,6 +271,33 @@ gdk_gl_context_end_frame (GdkGLContext *context, GDK_GL_CONTEXT_GET_CLASS (context)->end_frame (context, painted, damage); } +gboolean +gdk_gl_context_use_texture_rectangle (GdkGLContext *context) +{ + GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); + + return priv->use_texture_rectangle; +} + +static void +gdk_gl_context_realize (GdkGLContext *context) +{ + GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); + gboolean has_npot, has_texture_rectangle; + + has_npot = epoxy_has_gl_extension ("GL_ARB_texture_non_power_of_two"); + has_texture_rectangle = epoxy_has_gl_extension ("GL_ARB_texture_rectangle"); + + if (has_npot) + priv->use_texture_rectangle = FALSE; + else if (has_texture_rectangle) + priv->use_texture_rectangle = TRUE; + else + g_warning ("Gl implementation doesn't support any form of non-power-of-two textures"); + + priv->realized = TRUE; +} + /** * gdk_gl_context_make_current: * @context: a #GdkGLContext @@ -281,6 +314,9 @@ gdk_gl_context_make_current (GdkGLContext *context) g_return_if_fail (GDK_IS_GL_CONTEXT (context)); gdk_display_make_gl_context_current (gdk_window_get_display (priv->window), context); + + if (!priv->realized) + gdk_gl_context_realize (context); } /** diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h index 96d4924613..c7b6937ba6 100644 --- a/gdk/gdkglcontextprivate.h +++ b/gdk/gdkglcontextprivate.h @@ -49,6 +49,7 @@ struct _GdkGLContextClass cairo_region_t *region); }; +gboolean gdk_gl_context_use_texture_rectangle (GdkGLContext *context); void gdk_gl_context_end_frame (GdkGLContext *context, cairo_region_t *painted, cairo_region_t *damage);