[gtk+] gsk: Add check on GL_MAX_TEXTURE_SIZE
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gsk: Add check on GL_MAX_TEXTURE_SIZE
- Date: Wed, 26 Oct 2016 14:59:06 +0000 (UTC)
commit e161f9eba332a85027f165e4a7cd7c641db8aaa4
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Oct 26 15:47:29 2016 +0100
gsk: Add check on GL_MAX_TEXTURE_SIZE
We should check (once) what's the maximum GL texture size and then use
that size to check when we create any GL texture, to avoid errors.
gsk/gskgldriver.c | 35 +++++++++++++++++++++++++++++++++++
gsk/gskgldriverprivate.h | 2 ++
2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/gsk/gskgldriver.c b/gsk/gskgldriver.c
index 2f045cf..a0bd8e3 100644
--- a/gsk/gskgldriver.c
+++ b/gsk/gskgldriver.c
@@ -48,6 +48,8 @@ struct _GskGLDriver
Vao *bound_vao;
Fbo *bound_fbo;
+ int max_texture_size;
+
gboolean in_frame : 1;
};
@@ -184,6 +186,8 @@ gsk_gl_driver_init (GskGLDriver *self)
{
self->textures = g_hash_table_new_full (NULL, NULL, NULL, texture_free);
self->vaos = g_hash_table_new_full (NULL, NULL, NULL, vao_free);
+
+ self->max_texture_size = -1;
}
GskGLDriver *
@@ -204,6 +208,12 @@ gsk_gl_driver_begin_frame (GskGLDriver *driver)
driver->in_frame = TRUE;
+ if (driver->max_texture_size < 0)
+ {
+ glGetIntegerv (GL_MAX_TEXTURE_SIZE, (GLint *) &driver->max_texture_size);
+ GSK_NOTE (OPENGL, g_print ("GL max texture size: %d\n", driver->max_texture_size));
+ }
+
glGetIntegerv (GL_FRAMEBUFFER_BINDING, (GLint *) &(driver->default_fbo.fbo_id));
driver->bound_fbo = &driver->default_fbo;
@@ -297,6 +307,20 @@ gsk_gl_driver_collect_vaos (GskGLDriver *driver)
return old_size - g_hash_table_size (driver->vaos);
}
+int
+gsk_gl_driver_get_max_texture_size (GskGLDriver *driver)
+{
+ if (driver->max_texture_size < 0)
+ {
+ if (gdk_gl_context_get_use_es (driver->gl_context))
+ return 2048;
+
+ return 1024;
+ }
+
+ return driver->max_texture_size;
+}
+
static Texture *
gsk_gl_driver_get_texture (GskGLDriver *driver,
int texture_id)
@@ -363,6 +387,17 @@ gsk_gl_driver_create_texture (GskGLDriver *driver,
g_return_val_if_fail (GSK_IS_GL_DRIVER (driver), -1);
+ if (width >= driver->max_texture_size ||
+ height >= driver->max_texture_size)
+ {
+ g_critical ("Texture %d x %d is bigger than supported texture limit of %d; clipping...",
+ width, height,
+ driver->max_texture_size);
+
+ width = MIN (width, driver->max_texture_size);
+ height = MIN (height, driver->max_texture_size);
+ }
+
t = find_texture_by_size (driver->textures, width, height);
if (t != NULL && !t->in_use)
{
diff --git a/gsk/gskgldriverprivate.h b/gsk/gskgldriverprivate.h
index f4836f5..6a41174 100644
--- a/gsk/gskgldriverprivate.h
+++ b/gsk/gskgldriverprivate.h
@@ -18,6 +18,8 @@ typedef struct {
GskGLDriver * gsk_gl_driver_new (GdkGLContext *context);
+int gsk_gl_driver_get_max_texture_size (GskGLDriver *driver);
+
void gsk_gl_driver_begin_frame (GskGLDriver *driver);
void gsk_gl_driver_end_frame (GskGLDriver *driver);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]