2016-07-08 15:21:13 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskgldriverprivate.h"
|
|
|
|
|
|
|
|
#include "gskdebugprivate.h"
|
2017-11-16 08:33:20 +00:00
|
|
|
#include "gskprofilerprivate.h"
|
2019-04-24 11:27:43 +00:00
|
|
|
#include "gdk/gdkglcontextprivate.h"
|
2017-11-02 20:39:00 +00:00
|
|
|
#include "gdk/gdktextureprivate.h"
|
2018-03-05 13:38:38 +00:00
|
|
|
#include "gdk/gdkgltextureprivate.h"
|
2016-07-08 15:21:13 +00:00
|
|
|
|
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <epoxy/gl.h>
|
|
|
|
|
2017-12-28 20:21:09 +00:00
|
|
|
typedef struct {
|
|
|
|
GLuint fbo_id;
|
|
|
|
GLuint depth_stencil_id;
|
|
|
|
} Fbo;
|
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
typedef struct {
|
|
|
|
GLuint texture_id;
|
|
|
|
int width;
|
|
|
|
int height;
|
2016-07-12 10:15:45 +00:00
|
|
|
GLuint min_filter;
|
|
|
|
GLuint mag_filter;
|
2017-12-28 20:21:09 +00:00
|
|
|
Fbo fbo;
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *user;
|
2017-11-18 13:30:57 +00:00
|
|
|
guint in_use : 1;
|
|
|
|
guint permanent : 1;
|
2018-03-20 08:17:26 +00:00
|
|
|
|
|
|
|
/* TODO: Make this optional and not for every texture... */
|
|
|
|
TextureSlice *slices;
|
|
|
|
guint n_slices;
|
2016-07-08 15:21:13 +00:00
|
|
|
} Texture;
|
|
|
|
|
|
|
|
struct _GskGLDriver
|
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
|
|
|
GdkGLContext *gl_context;
|
2017-11-16 08:33:20 +00:00
|
|
|
GskProfiler *profiler;
|
|
|
|
struct {
|
|
|
|
GQuark created_textures;
|
|
|
|
GQuark reused_textures;
|
|
|
|
GQuark surface_uploads;
|
|
|
|
} counters;
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2016-07-20 16:55:35 +00:00
|
|
|
Fbo default_fbo;
|
2016-07-12 14:41:31 +00:00
|
|
|
|
2019-10-22 06:27:28 +00:00
|
|
|
GHashTable *textures; /* texture_id -> Texture */
|
|
|
|
GHashTable *pointer_textures; /* pointer -> texture_id */
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2017-11-09 09:55:14 +00:00
|
|
|
const Texture *bound_source_texture;
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2016-10-26 14:47:29 +00:00
|
|
|
int max_texture_size;
|
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
gboolean in_frame : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GskGLDriver, gsk_gl_driver, G_TYPE_OBJECT)
|
|
|
|
|
2016-07-12 13:59:37 +00:00
|
|
|
static Texture *
|
|
|
|
texture_new (void)
|
|
|
|
{
|
|
|
|
return g_slice_new0 (Texture);
|
|
|
|
}
|
|
|
|
|
2017-12-28 20:21:09 +00:00
|
|
|
static inline void
|
|
|
|
fbo_clear (const Fbo *f)
|
|
|
|
{
|
|
|
|
if (f->depth_stencil_id != 0)
|
|
|
|
glDeleteRenderbuffers (1, &f->depth_stencil_id);
|
|
|
|
|
|
|
|
glDeleteFramebuffers (1, &f->fbo_id);
|
|
|
|
}
|
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
static void
|
2016-07-12 13:59:37 +00:00
|
|
|
texture_free (gpointer data)
|
2016-07-08 15:21:13 +00:00
|
|
|
{
|
|
|
|
Texture *t = data;
|
2018-03-20 08:17:26 +00:00
|
|
|
guint i;
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2016-11-16 04:37:20 +00:00
|
|
|
if (t->user)
|
2017-11-02 20:39:00 +00:00
|
|
|
gdk_texture_clear_render_data (t->user);
|
2016-11-07 16:59:38 +00:00
|
|
|
|
2017-12-28 20:21:09 +00:00
|
|
|
if (t->fbo.fbo_id != 0)
|
|
|
|
fbo_clear (&t->fbo);
|
|
|
|
|
2018-03-20 08:17:26 +00:00
|
|
|
if (t->texture_id != 0)
|
|
|
|
{
|
|
|
|
glDeleteTextures (1, &t->texture_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_assert_cmpint (t->n_slices, >, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < t->n_slices; i ++)
|
|
|
|
glDeleteTextures (1, &t->slices[i].texture_id);
|
|
|
|
}
|
|
|
|
|
2016-07-12 13:59:37 +00:00
|
|
|
g_slice_free (Texture, t);
|
2016-07-08 15:21:13 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 08:17:26 +00:00
|
|
|
static void
|
|
|
|
gsk_gl_driver_set_texture_parameters (GskGLDriver *self,
|
|
|
|
int min_filter,
|
|
|
|
int mag_filter)
|
|
|
|
{
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
|
|
|
|
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2016-07-12 14:41:31 +00:00
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
static void
|
|
|
|
gsk_gl_driver_finalize (GObject *gobject)
|
|
|
|
{
|
|
|
|
GskGLDriver *self = GSK_GL_DRIVER (gobject);
|
|
|
|
|
2016-08-04 11:37:54 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
|
|
|
|
2016-07-12 13:59:37 +00:00
|
|
|
g_clear_pointer (&self->textures, g_hash_table_unref);
|
2018-11-28 17:40:48 +00:00
|
|
|
g_clear_pointer (&self->pointer_textures, g_hash_table_unref);
|
2017-11-16 08:33:20 +00:00
|
|
|
g_clear_object (&self->profiler);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2016-08-04 11:37:54 +00:00
|
|
|
if (self->gl_context == gdk_gl_context_get_current ())
|
|
|
|
gdk_gl_context_clear_current ();
|
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
G_OBJECT_CLASS (gsk_gl_driver_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_driver_class_init (GskGLDriverClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = gsk_gl_driver_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_driver_init (GskGLDriver *self)
|
|
|
|
{
|
2016-07-12 13:59:37 +00:00
|
|
|
self->textures = g_hash_table_new_full (NULL, NULL, NULL, texture_free);
|
2016-10-26 14:47:29 +00:00
|
|
|
|
|
|
|
self->max_texture_size = -1;
|
2017-11-16 08:33:20 +00:00
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
self->profiler = gsk_profiler_new ();
|
|
|
|
self->counters.created_textures = gsk_profiler_add_counter (self->profiler,
|
|
|
|
"created_textures",
|
|
|
|
"Textures created this frame",
|
|
|
|
TRUE);
|
|
|
|
self->counters.reused_textures = gsk_profiler_add_counter (self->profiler,
|
|
|
|
"reused_textures",
|
|
|
|
"Textures reused this frame",
|
|
|
|
TRUE);
|
|
|
|
self->counters.surface_uploads = gsk_profiler_add_counter (self->profiler,
|
|
|
|
"surface_uploads",
|
|
|
|
"Texture uploads from surfaces this frame",
|
|
|
|
TRUE);
|
|
|
|
#endif
|
2016-07-08 15:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GskGLDriver *
|
|
|
|
gsk_gl_driver_new (GdkGLContext *context)
|
|
|
|
{
|
2017-12-28 20:32:46 +00:00
|
|
|
GskGLDriver *self;
|
2016-07-08 15:21:13 +00:00
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
|
|
|
|
|
2017-12-28 20:32:46 +00:00
|
|
|
self = (GskGLDriver *) g_object_new (GSK_TYPE_GL_DRIVER, NULL);
|
|
|
|
self->gl_context = context;
|
|
|
|
|
|
|
|
return self;
|
2016-07-08 15:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-11-16 08:33:20 +00:00
|
|
|
gsk_gl_driver_begin_frame (GskGLDriver *self)
|
2016-07-08 15:21:13 +00:00
|
|
|
{
|
2017-11-16 08:33:20 +00:00
|
|
|
g_return_if_fail (GSK_IS_GL_DRIVER (self));
|
|
|
|
g_return_if_fail (!self->in_frame);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2017-11-16 08:33:20 +00:00
|
|
|
self->in_frame = TRUE;
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2017-11-16 08:33:20 +00:00
|
|
|
if (self->max_texture_size < 0)
|
2016-10-26 14:47:29 +00:00
|
|
|
{
|
2017-11-16 08:33:20 +00:00
|
|
|
glGetIntegerv (GL_MAX_TEXTURE_SIZE, (GLint *) &self->max_texture_size);
|
2018-01-14 14:52:52 +00:00
|
|
|
GSK_NOTE (OPENGL, g_message ("GL max texture size: %d", self->max_texture_size));
|
2016-10-26 14:47:29 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 00:03:59 +00:00
|
|
|
glBindFramebuffer (GL_FRAMEBUFFER, 0);
|
2016-07-12 14:41:31 +00:00
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
glActiveTexture (GL_TEXTURE0);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
glActiveTexture (GL_TEXTURE0 + 1);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
glBindVertexArray (0);
|
|
|
|
glUseProgram (0);
|
|
|
|
|
|
|
|
glActiveTexture (GL_TEXTURE0);
|
2017-11-16 08:33:20 +00:00
|
|
|
|
2017-12-29 07:51:57 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2017-11-16 08:33:20 +00:00
|
|
|
gsk_profiler_reset (self->profiler);
|
2017-12-29 07:51:57 +00:00
|
|
|
#endif
|
2016-07-08 15:21:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-22 12:20:02 +00:00
|
|
|
gboolean
|
|
|
|
gsk_gl_driver_in_frame (GskGLDriver *self)
|
|
|
|
{
|
|
|
|
return self->in_frame;
|
|
|
|
}
|
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
void
|
2017-11-16 08:33:20 +00:00
|
|
|
gsk_gl_driver_end_frame (GskGLDriver *self)
|
2016-07-08 15:21:13 +00:00
|
|
|
{
|
2017-11-16 08:33:20 +00:00
|
|
|
g_return_if_fail (GSK_IS_GL_DRIVER (self));
|
|
|
|
g_return_if_fail (self->in_frame);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2017-11-16 08:33:20 +00:00
|
|
|
self->bound_source_texture = NULL;
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2017-11-16 08:33:20 +00:00
|
|
|
self->default_fbo.fbo_id = 0;
|
2016-11-23 00:03:59 +00:00
|
|
|
|
2017-12-29 07:51:57 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2017-11-16 08:33:20 +00:00
|
|
|
GSK_NOTE (OPENGL,
|
2018-06-10 20:49:47 +00:00
|
|
|
g_message ("Textures created: %" G_GINT64_FORMAT "\n"
|
|
|
|
" Textures reused: %" G_GINT64_FORMAT "\n"
|
|
|
|
" Surface uploads: %" G_GINT64_FORMAT,
|
2017-11-16 08:33:20 +00:00
|
|
|
gsk_profiler_counter_get (self->profiler, self->counters.created_textures),
|
|
|
|
gsk_profiler_counter_get (self->profiler, self->counters.reused_textures),
|
|
|
|
gsk_profiler_counter_get (self->profiler, self->counters.surface_uploads)));
|
2017-12-29 07:51:57 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-20 16:55:35 +00:00
|
|
|
GSK_NOTE (OPENGL,
|
2018-01-14 14:52:52 +00:00
|
|
|
g_message ("*** Frame end: textures=%d",
|
2017-12-28 20:12:03 +00:00
|
|
|
g_hash_table_size (self->textures)));
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2017-11-16 08:33:20 +00:00
|
|
|
self->in_frame = FALSE;
|
2016-07-08 15:21:13 +00:00
|
|
|
}
|
|
|
|
|
2016-08-09 10:24:05 +00:00
|
|
|
int
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_collect_textures (GskGLDriver *self)
|
2016-08-04 11:37:54 +00:00
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer value_p = NULL;
|
2016-08-09 10:24:05 +00:00
|
|
|
int old_size;
|
2016-08-04 11:37:54 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
g_return_val_if_fail (GSK_IS_GL_DRIVER (self), 0);
|
|
|
|
g_return_val_if_fail (!self->in_frame, 0);
|
2016-08-09 10:24:05 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
old_size = g_hash_table_size (self->textures);
|
2016-08-04 11:37:54 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
g_hash_table_iter_init (&iter, self->textures);
|
2016-08-04 11:37:54 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, &value_p))
|
|
|
|
{
|
|
|
|
Texture *t = value_p;
|
|
|
|
|
2017-11-18 13:30:57 +00:00
|
|
|
if (t->user || t->permanent)
|
2016-11-07 16:59:38 +00:00
|
|
|
continue;
|
|
|
|
|
2016-08-04 11:37:54 +00:00
|
|
|
if (t->in_use)
|
2016-08-09 10:24:05 +00:00
|
|
|
{
|
|
|
|
t->in_use = FALSE;
|
2017-12-28 20:21:09 +00:00
|
|
|
|
|
|
|
if (t->fbo.fbo_id != 0)
|
|
|
|
{
|
|
|
|
fbo_clear (&t->fbo);
|
|
|
|
t->fbo.fbo_id = 0;
|
|
|
|
}
|
2016-08-09 10:24:05 +00:00
|
|
|
}
|
2016-08-04 11:37:54 +00:00
|
|
|
else
|
2018-11-28 17:40:48 +00:00
|
|
|
{
|
|
|
|
/* Remove from self->pointer_textures. */
|
|
|
|
/* TODO: Is there a better way for this? */
|
|
|
|
if (self->pointer_textures)
|
|
|
|
{
|
|
|
|
GHashTableIter pointer_iter;
|
|
|
|
gpointer value;
|
|
|
|
gpointer p;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&pointer_iter, self->pointer_textures);
|
|
|
|
while (g_hash_table_iter_next (&pointer_iter, &p, &value))
|
|
|
|
{
|
|
|
|
if (GPOINTER_TO_INT (value) == t->texture_id)
|
|
|
|
{
|
|
|
|
g_hash_table_iter_remove (&pointer_iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_iter_remove (&iter);
|
|
|
|
}
|
2016-08-04 11:37:54 +00:00
|
|
|
}
|
2016-08-09 10:24:05 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
return old_size - g_hash_table_size (self->textures);
|
2016-08-09 10:24:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 11:27:43 +00:00
|
|
|
|
|
|
|
GdkGLContext *
|
|
|
|
gsk_gl_driver_get_gl_context (GskGLDriver *self)
|
|
|
|
{
|
|
|
|
return self->gl_context;
|
|
|
|
}
|
|
|
|
|
2016-10-26 14:47:29 +00:00
|
|
|
int
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_get_max_texture_size (GskGLDriver *self)
|
2016-10-26 14:47:29 +00:00
|
|
|
{
|
2018-03-18 21:00:01 +00:00
|
|
|
if (self->max_texture_size < 0)
|
2016-10-26 14:47:29 +00:00
|
|
|
{
|
2018-03-18 21:00:01 +00:00
|
|
|
if (gdk_gl_context_get_use_es (self->gl_context))
|
2016-10-26 14:47:29 +00:00
|
|
|
return 2048;
|
|
|
|
|
|
|
|
return 1024;
|
|
|
|
}
|
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
return self->max_texture_size;
|
2016-10-26 14:47:29 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 14:41:31 +00:00
|
|
|
static Texture *
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_get_texture (GskGLDriver *self,
|
2016-07-12 14:41:31 +00:00
|
|
|
int texture_id)
|
|
|
|
{
|
2016-07-20 16:55:35 +00:00
|
|
|
Texture *t;
|
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
if (g_hash_table_lookup_extended (self->textures, GINT_TO_POINTER (texture_id), NULL, (gpointer *) &t))
|
2016-07-20 16:55:35 +00:00
|
|
|
return t;
|
|
|
|
|
|
|
|
return NULL;
|
2016-07-12 14:41:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 04:37:20 +00:00
|
|
|
static Texture *
|
2017-11-16 08:33:20 +00:00
|
|
|
create_texture (GskGLDriver *self,
|
2017-11-15 17:40:57 +00:00
|
|
|
float fwidth,
|
|
|
|
float fheight)
|
2016-07-08 15:21:13 +00:00
|
|
|
{
|
|
|
|
guint texture_id;
|
2016-07-12 13:59:37 +00:00
|
|
|
Texture *t;
|
2017-11-15 17:40:57 +00:00
|
|
|
int width = ceilf (fwidth);
|
|
|
|
int height = ceilf (fheight);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2017-12-09 13:31:10 +00:00
|
|
|
g_assert (width > 0);
|
|
|
|
g_assert (height > 0);
|
|
|
|
|
2018-03-20 08:17:26 +00:00
|
|
|
if (width > self->max_texture_size ||
|
|
|
|
height > self->max_texture_size)
|
2016-10-26 14:47:29 +00:00
|
|
|
{
|
|
|
|
g_critical ("Texture %d x %d is bigger than supported texture limit of %d; clipping...",
|
|
|
|
width, height,
|
2017-11-16 08:33:20 +00:00
|
|
|
self->max_texture_size);
|
2016-10-26 14:47:29 +00:00
|
|
|
|
2017-11-16 08:33:20 +00:00
|
|
|
width = MIN (width, self->max_texture_size);
|
|
|
|
height = MIN (height, self->max_texture_size);
|
2016-10-26 14:47:29 +00:00
|
|
|
}
|
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
glGenTextures (1, &texture_id);
|
2016-07-12 13:59:37 +00:00
|
|
|
t = texture_new ();
|
|
|
|
t->texture_id = texture_id;
|
|
|
|
t->width = width;
|
|
|
|
t->height = height;
|
2016-07-19 13:32:17 +00:00
|
|
|
t->min_filter = GL_NEAREST;
|
|
|
|
t->mag_filter = GL_NEAREST;
|
2016-08-04 11:37:54 +00:00
|
|
|
t->in_use = TRUE;
|
2017-11-16 08:33:20 +00:00
|
|
|
g_hash_table_insert (self->textures, GINT_TO_POINTER (texture_id), t);
|
2017-12-29 07:51:57 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2017-11-16 08:33:20 +00:00
|
|
|
gsk_profiler_counter_inc (self->profiler, self->counters.created_textures);
|
2017-12-29 07:51:57 +00:00
|
|
|
#endif
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2016-11-16 04:37:20 +00:00
|
|
|
return t;
|
2016-07-08 15:21:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 04:37:20 +00:00
|
|
|
static void
|
|
|
|
gsk_gl_driver_release_texture (gpointer data)
|
|
|
|
{
|
|
|
|
Texture *t = data;
|
|
|
|
|
|
|
|
t->user = NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-20 08:17:26 +00:00
|
|
|
void
|
|
|
|
gsk_gl_driver_slice_texture (GskGLDriver *self,
|
|
|
|
GdkTexture *texture,
|
|
|
|
TextureSlice **out_slices,
|
|
|
|
guint *out_n_slices)
|
|
|
|
{
|
|
|
|
const int max_texture_size = gsk_gl_driver_get_max_texture_size (self) / 4; // XXX Too much?
|
|
|
|
const int tex_width = texture->width;
|
|
|
|
const int tex_height = texture->height;
|
|
|
|
const int cols = (texture->width / max_texture_size) + 1;
|
|
|
|
const int rows = (texture->height / max_texture_size) + 1;
|
|
|
|
int col, row;
|
|
|
|
int x = 0, y = 0; /* Position in the texture */
|
|
|
|
TextureSlice *slices;
|
|
|
|
Texture *tex;
|
|
|
|
|
|
|
|
g_assert (tex_width > max_texture_size || tex_height > max_texture_size);
|
|
|
|
|
|
|
|
|
|
|
|
tex = gdk_texture_get_render_data (texture, self);
|
|
|
|
|
|
|
|
if (tex != NULL)
|
|
|
|
{
|
|
|
|
g_assert (tex->n_slices > 0);
|
|
|
|
*out_slices = tex->slices;
|
|
|
|
*out_n_slices = tex->n_slices;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
slices = g_new0 (TextureSlice, cols * rows);
|
|
|
|
|
|
|
|
/* TODO: (Perf):
|
|
|
|
* We still create a surface here, which should obviously be unnecessary
|
|
|
|
* and we should eventually remove it and upload the data directly.
|
|
|
|
*/
|
|
|
|
for (col = 0; col < cols; col ++)
|
|
|
|
{
|
|
|
|
const int slice_width = MIN (max_texture_size, texture->width - x);
|
|
|
|
const int stride = slice_width * 4;
|
|
|
|
|
|
|
|
for (row = 0; row < rows; row ++)
|
|
|
|
{
|
|
|
|
const int slice_height = MIN (max_texture_size, texture->height - y);
|
|
|
|
const int slice_index = (col * rows) + row;
|
|
|
|
guchar *data;
|
|
|
|
guint texture_id;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
data = g_malloc (sizeof (guchar) * stride * slice_height);
|
|
|
|
|
|
|
|
gdk_texture_download_area (texture,
|
|
|
|
&(GdkRectangle){x, y, slice_width, slice_height},
|
|
|
|
data, stride);
|
|
|
|
surface = cairo_image_surface_create_for_data (data,
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
|
|
|
slice_width, slice_height,
|
|
|
|
stride);
|
|
|
|
|
|
|
|
glGenTextures (1, &texture_id);
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
gsk_profiler_counter_inc (self->profiler, self->counters.created_textures);
|
|
|
|
#endif
|
|
|
|
glBindTexture (GL_TEXTURE_2D, texture_id);
|
|
|
|
gsk_gl_driver_set_texture_parameters (self, GL_NEAREST, GL_NEAREST);
|
|
|
|
gdk_cairo_surface_upload_to_gl (surface, GL_TEXTURE_2D, slice_width, slice_height, NULL);
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
gsk_profiler_counter_inc (self->profiler, self->counters.surface_uploads);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
slices[slice_index].rect = (GdkRectangle){x, y, slice_width, slice_height};
|
|
|
|
slices[slice_index].texture_id = texture_id;
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
y += slice_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
y = 0;
|
|
|
|
x += slice_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate one Texture for the entire thing. */
|
|
|
|
tex = texture_new ();
|
|
|
|
tex->width = texture->width;
|
|
|
|
tex->height = texture->height;
|
|
|
|
tex->min_filter = GL_NEAREST;
|
|
|
|
tex->mag_filter = GL_NEAREST;
|
|
|
|
tex->in_use = TRUE;
|
|
|
|
tex->slices = slices;
|
|
|
|
tex->n_slices = cols * rows;
|
|
|
|
|
|
|
|
/* Use texture_free as destroy notify here since we are not inserting this Texture
|
|
|
|
* into self->textures! */
|
|
|
|
gdk_texture_set_render_data (texture, self, tex, texture_free);
|
|
|
|
|
|
|
|
*out_slices = slices;
|
|
|
|
*out_n_slices = cols * rows;
|
|
|
|
}
|
|
|
|
|
2016-11-16 04:37:20 +00:00
|
|
|
int
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_get_texture_for_texture (GskGLDriver *self,
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *texture,
|
2016-11-16 04:37:20 +00:00
|
|
|
int min_filter,
|
|
|
|
int mag_filter)
|
2016-11-07 16:59:38 +00:00
|
|
|
{
|
|
|
|
Texture *t;
|
2018-11-28 16:09:29 +00:00
|
|
|
cairo_surface_t *surface;
|
2016-11-16 04:37:20 +00:00
|
|
|
|
2018-01-17 05:52:15 +00:00
|
|
|
if (GDK_IS_GL_TEXTURE (texture))
|
2018-03-14 11:23:38 +00:00
|
|
|
{
|
|
|
|
GdkGLContext *texture_context = gdk_gl_texture_get_context ((GdkGLTexture *)texture);
|
2016-11-16 04:37:20 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
if (texture_context != self->gl_context)
|
2018-03-14 11:23:38 +00:00
|
|
|
{
|
|
|
|
/* In this case, we have to temporarily make the texture's context the current one,
|
|
|
|
* download its data into our context and then create a texture from it. */
|
2019-05-20 07:33:55 +00:00
|
|
|
if (texture_context)
|
|
|
|
gdk_gl_context_make_current (texture_context);
|
|
|
|
|
2018-11-28 16:09:29 +00:00
|
|
|
surface = gdk_texture_download_surface (texture);
|
2019-05-20 07:33:55 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
gdk_gl_context_make_current (self->gl_context);
|
2018-03-14 11:23:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* A GL texture from the same GL context is a simple task... */
|
2018-03-20 08:17:26 +00:00
|
|
|
return gdk_gl_texture_get_id ((GdkGLTexture *)texture);
|
2018-03-14 11:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-11-16 04:37:20 +00:00
|
|
|
{
|
2018-03-18 21:00:01 +00:00
|
|
|
t = gdk_texture_get_render_data (texture, self);
|
2018-03-14 11:23:38 +00:00
|
|
|
|
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
if (t->min_filter == min_filter && t->mag_filter == mag_filter)
|
|
|
|
return t->texture_id;
|
|
|
|
}
|
|
|
|
|
2018-11-28 16:09:29 +00:00
|
|
|
surface = gdk_texture_download_surface (texture);
|
2016-11-16 04:37:20 +00:00
|
|
|
}
|
2017-11-15 17:40:57 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
t = create_texture (self, gdk_texture_get_width (texture), gdk_texture_get_height (texture));
|
2016-11-16 04:37:20 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
if (gdk_texture_set_render_data (texture, self, t, gsk_gl_driver_release_texture))
|
2016-11-16 04:37:20 +00:00
|
|
|
t->user = texture;
|
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_bind_source_texture (self, t->texture_id);
|
2018-11-28 16:09:29 +00:00
|
|
|
gsk_gl_driver_init_texture_with_surface (self,
|
|
|
|
t->texture_id,
|
|
|
|
surface,
|
|
|
|
min_filter,
|
|
|
|
mag_filter);
|
2019-04-27 07:50:21 +00:00
|
|
|
gdk_gl_context_label_object_printf (self->gl_context, GL_TEXTURE, t->texture_id,
|
|
|
|
"GdkTexture<%p> %d", texture, t->texture_id);
|
|
|
|
|
2018-11-28 16:09:29 +00:00
|
|
|
cairo_surface_destroy (surface);
|
2016-11-16 04:37:20 +00:00
|
|
|
|
|
|
|
return t->texture_id;
|
|
|
|
}
|
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
static guint
|
|
|
|
texture_key_hash (gconstpointer v)
|
|
|
|
{
|
|
|
|
const GskTextureKey *k = (GskTextureKey *)v;
|
|
|
|
|
|
|
|
return GPOINTER_TO_UINT (k->pointer)
|
|
|
|
+ (guint)(k->scale*100)
|
|
|
|
+ (guint)k->filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
texture_key_equal (gconstpointer v1, gconstpointer v2)
|
|
|
|
{
|
|
|
|
const GskTextureKey *k1 = (GskTextureKey *)v1;
|
|
|
|
const GskTextureKey *k2 = (GskTextureKey *)v2;
|
|
|
|
|
|
|
|
return k1->pointer == k2->pointer &&
|
|
|
|
k1->scale == k2->scale &&
|
|
|
|
k1->filter == k2->filter;
|
|
|
|
}
|
|
|
|
|
2018-11-28 17:40:48 +00:00
|
|
|
int
|
2020-09-09 17:55:09 +00:00
|
|
|
gsk_gl_driver_get_texture_for_key (GskGLDriver *self,
|
|
|
|
GskTextureKey *key)
|
2018-11-28 17:40:48 +00:00
|
|
|
{
|
|
|
|
int id = 0;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (self->pointer_textures == NULL))
|
2020-09-09 17:55:09 +00:00
|
|
|
self->pointer_textures = g_hash_table_new_full (texture_key_hash, texture_key_equal, g_free, NULL);
|
2018-11-28 17:40:48 +00:00
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
id = GPOINTER_TO_INT (g_hash_table_lookup (self->pointer_textures, key));
|
2018-11-28 17:40:48 +00:00
|
|
|
|
2019-03-05 08:00:55 +00:00
|
|
|
if (id != 0)
|
|
|
|
{
|
2019-10-22 06:28:33 +00:00
|
|
|
Texture *t;
|
2019-03-05 08:00:55 +00:00
|
|
|
|
2019-10-22 06:28:33 +00:00
|
|
|
t = g_hash_table_lookup (self->textures, GINT_TO_POINTER (id));
|
2019-03-05 08:00:55 +00:00
|
|
|
|
2019-10-22 06:28:33 +00:00
|
|
|
if (t != NULL)
|
|
|
|
t->in_use = TRUE;
|
2019-03-05 08:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 17:40:48 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-09-09 17:55:09 +00:00
|
|
|
gsk_gl_driver_set_texture_for_key (GskGLDriver *self,
|
|
|
|
GskTextureKey *key,
|
|
|
|
int texture_id)
|
2018-11-28 17:40:48 +00:00
|
|
|
{
|
2020-09-09 17:55:09 +00:00
|
|
|
GskTextureKey *k;
|
|
|
|
|
2018-11-28 17:40:48 +00:00
|
|
|
if (G_UNLIKELY (self->pointer_textures == NULL))
|
2020-09-09 17:55:09 +00:00
|
|
|
self->pointer_textures = g_hash_table_new_full (texture_key_hash, texture_key_equal, g_free, NULL);
|
|
|
|
|
|
|
|
k = g_new (GskTextureKey, 1);
|
|
|
|
*k = *key;
|
2018-11-28 17:40:48 +00:00
|
|
|
|
2020-09-09 17:55:09 +00:00
|
|
|
g_hash_table_insert (self->pointer_textures, k, GINT_TO_POINTER (texture_id));
|
2018-11-28 17:40:48 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 04:37:20 +00:00
|
|
|
int
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_create_texture (GskGLDriver *self,
|
2017-11-15 17:40:57 +00:00
|
|
|
float width,
|
|
|
|
float height)
|
2016-11-16 04:37:20 +00:00
|
|
|
{
|
|
|
|
Texture *t;
|
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
g_return_val_if_fail (GSK_IS_GL_DRIVER (self), -1);
|
2016-11-07 16:59:38 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
t = create_texture (self, width, height);
|
2016-11-16 04:37:20 +00:00
|
|
|
|
|
|
|
return t->texture_id;
|
2016-11-07 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 04:32:25 +00:00
|
|
|
void
|
|
|
|
gsk_gl_driver_create_render_target (GskGLDriver *self,
|
|
|
|
int width,
|
|
|
|
int height,
|
2020-09-02 22:01:06 +00:00
|
|
|
int min_filter,
|
|
|
|
int mag_filter,
|
2019-12-19 04:32:25 +00:00
|
|
|
int *out_texture_id,
|
|
|
|
int *out_render_target_id)
|
2016-07-08 15:21:13 +00:00
|
|
|
{
|
2019-12-19 04:32:25 +00:00
|
|
|
GLuint fbo_id;
|
|
|
|
Texture *texture;
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2019-12-19 04:32:25 +00:00
|
|
|
g_return_if_fail (self->in_frame);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2019-12-19 04:32:25 +00:00
|
|
|
texture = create_texture (self, width, height);
|
|
|
|
gsk_gl_driver_bind_source_texture (self, texture->texture_id);
|
2020-09-02 22:01:06 +00:00
|
|
|
gsk_gl_driver_init_texture_empty (self, texture->texture_id, min_filter, mag_filter);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2016-07-12 14:41:31 +00:00
|
|
|
glGenFramebuffers (1, &fbo_id);
|
|
|
|
glBindFramebuffer (GL_FRAMEBUFFER, fbo_id);
|
2019-12-19 04:32:25 +00:00
|
|
|
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->texture_id, 0);
|
2016-07-12 14:41:31 +00:00
|
|
|
|
2019-12-19 04:32:25 +00:00
|
|
|
#if 0
|
2016-07-20 16:55:35 +00:00
|
|
|
if (add_depth_buffer || add_stencil_buffer)
|
2019-04-24 11:27:43 +00:00
|
|
|
{
|
|
|
|
glGenRenderbuffersEXT (1, &depth_stencil_buffer_id);
|
|
|
|
gdk_gl_context_label_object_printf (self->gl_context, GL_RENDERBUFFER, depth_stencil_buffer_id,
|
|
|
|
"%s buffer for %d", add_depth_buffer ? "Depth" : "Stencil", texture_id);
|
|
|
|
}
|
2016-07-20 16:55:35 +00:00
|
|
|
else
|
|
|
|
depth_stencil_buffer_id = 0;
|
|
|
|
|
|
|
|
glBindRenderbuffer (GL_RENDERBUFFER, depth_stencil_buffer_id);
|
|
|
|
|
|
|
|
if (add_depth_buffer || add_stencil_buffer)
|
|
|
|
{
|
|
|
|
if (add_stencil_buffer)
|
|
|
|
glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, t->width, t->height);
|
|
|
|
else
|
|
|
|
glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, t->width, t->height);
|
|
|
|
|
|
|
|
if (add_depth_buffer)
|
|
|
|
glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
|
|
|
GL_RENDERBUFFER, depth_stencil_buffer_id);
|
|
|
|
|
|
|
|
if (add_stencil_buffer)
|
|
|
|
glFramebufferRenderbufferEXT (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
|
|
|
GL_RENDERBUFFER, depth_stencil_buffer_id);
|
2019-12-19 04:32:25 +00:00
|
|
|
texture->fbo.depth_stencil_id = depth_stencil_buffer_id;
|
2016-07-20 16:55:35 +00:00
|
|
|
}
|
2019-12-19 04:32:25 +00:00
|
|
|
#endif
|
2016-07-20 16:55:35 +00:00
|
|
|
|
2019-12-19 04:32:25 +00:00
|
|
|
texture->fbo.fbo_id = fbo_id;
|
2016-07-20 16:55:35 +00:00
|
|
|
|
2018-03-14 18:21:09 +00:00
|
|
|
g_assert_cmphex (glCheckFramebufferStatus (GL_FRAMEBUFFER), ==, GL_FRAMEBUFFER_COMPLETE);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2019-12-19 04:32:25 +00:00
|
|
|
glBindFramebuffer (GL_FRAMEBUFFER, self->default_fbo.fbo_id);
|
2019-05-22 05:10:57 +00:00
|
|
|
|
2019-12-19 04:32:25 +00:00
|
|
|
*out_texture_id = texture->texture_id;
|
|
|
|
*out_render_target_id = fbo_id;
|
2019-05-22 05:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the texture permanent, meaning it won'e be reused by the GLDriver.
|
|
|
|
* E.g. to store it in some other cache. */
|
|
|
|
void
|
|
|
|
gsk_gl_driver_mark_texture_permanent (GskGLDriver *self,
|
|
|
|
int texture_id)
|
|
|
|
{
|
|
|
|
Texture *t = gsk_gl_driver_get_texture (self, texture_id);
|
|
|
|
|
2020-03-05 06:02:24 +00:00
|
|
|
g_assert (t != NULL);
|
2019-05-22 05:10:57 +00:00
|
|
|
|
|
|
|
t->permanent = TRUE;
|
|
|
|
}
|
|
|
|
|
2016-07-08 15:21:13 +00:00
|
|
|
void
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_bind_source_texture (GskGLDriver *self,
|
2016-07-08 15:21:13 +00:00
|
|
|
int texture_id)
|
|
|
|
{
|
|
|
|
Texture *t;
|
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
g_return_if_fail (GSK_IS_GL_DRIVER (self));
|
|
|
|
g_return_if_fail (self->in_frame);
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
t = gsk_gl_driver_get_texture (self, texture_id);
|
2016-07-08 15:21:13 +00:00
|
|
|
if (t == NULL)
|
2016-07-20 16:55:35 +00:00
|
|
|
{
|
|
|
|
g_critical ("No texture %d found.", texture_id);
|
|
|
|
return;
|
|
|
|
}
|
2016-07-08 15:21:13 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
if (self->bound_source_texture != t)
|
2016-07-08 15:21:13 +00:00
|
|
|
{
|
|
|
|
glActiveTexture (GL_TEXTURE0);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, t->texture_id);
|
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
self->bound_source_texture = t;
|
2016-07-08 15:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:55:35 +00:00
|
|
|
void
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_destroy_texture (GskGLDriver *self,
|
2016-07-20 16:55:35 +00:00
|
|
|
int texture_id)
|
|
|
|
{
|
2018-03-18 21:00:01 +00:00
|
|
|
g_return_if_fail (GSK_IS_GL_DRIVER (self));
|
2016-07-20 16:55:35 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
g_hash_table_remove (self->textures, GINT_TO_POINTER (texture_id));
|
2016-07-20 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_init_texture_empty (GskGLDriver *self,
|
2019-06-02 16:47:57 +00:00
|
|
|
int texture_id,
|
|
|
|
int min_filter,
|
|
|
|
int mag_filter)
|
2016-07-20 16:55:35 +00:00
|
|
|
{
|
2016-07-12 14:41:31 +00:00
|
|
|
Texture *t;
|
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
g_return_if_fail (GSK_IS_GL_DRIVER (self));
|
2016-07-12 14:41:31 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
t = gsk_gl_driver_get_texture (self, texture_id);
|
2016-07-12 14:41:31 +00:00
|
|
|
if (t == NULL)
|
|
|
|
{
|
2016-07-20 16:55:35 +00:00
|
|
|
g_critical ("No texture %d found.", texture_id);
|
|
|
|
return;
|
|
|
|
}
|
2016-07-12 14:41:31 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
if (self->bound_source_texture != t)
|
2016-07-20 16:55:35 +00:00
|
|
|
{
|
|
|
|
g_critical ("You must bind the texture before initializing it.");
|
|
|
|
return;
|
2016-07-12 14:41:31 +00:00
|
|
|
}
|
2016-07-20 16:55:35 +00:00
|
|
|
|
2019-06-02 16:47:57 +00:00
|
|
|
t->min_filter = min_filter;
|
|
|
|
t->mag_filter = mag_filter;
|
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
gsk_gl_driver_set_texture_parameters (self, t->min_filter, t->mag_filter);
|
2016-07-20 16:55:35 +00:00
|
|
|
|
2018-03-18 21:00:01 +00:00
|
|
|
if (gdk_gl_context_get_use_es (self->gl_context))
|
2016-07-20 16:55:35 +00:00
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, t->width, t->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
else
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, t->width, t->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
|
|
|
|
glBindTexture (GL_TEXTURE_2D, 0);
|
2016-07-12 14:41:31 +00:00
|
|
|
}
|
|
|
|
|
2019-06-02 15:54:50 +00:00
|
|
|
static gboolean
|
|
|
|
filter_uses_mipmaps (int filter)
|
|
|
|
{
|
|
|
|
return filter != GL_NEAREST && filter != GL_LINEAR;
|
|
|
|
}
|
|
|
|
|
2016-07-12 10:15:45 +00:00
|
|
|
void
|
2017-11-16 08:33:20 +00:00
|
|
|
gsk_gl_driver_init_texture_with_surface (GskGLDriver *self,
|
2016-07-19 13:32:17 +00:00
|
|
|
int texture_id,
|
2016-07-12 10:15:45 +00:00
|
|
|
cairo_surface_t *surface,
|
2016-07-19 13:32:17 +00:00
|
|
|
int min_filter,
|
|
|
|
int mag_filter)
|
2016-07-12 10:15:45 +00:00
|
|
|
{
|
|
|
|
Texture *t;
|
|
|
|
|
2017-11-16 08:33:20 +00:00
|
|
|
g_return_if_fail (GSK_IS_GL_DRIVER (self));
|
2016-07-12 10:15:45 +00:00
|
|
|
|
2017-11-16 08:33:20 +00:00
|
|
|
t = gsk_gl_driver_get_texture (self, texture_id);
|
2016-07-12 10:15:45 +00:00
|
|
|
if (t == NULL)
|
2016-07-20 16:55:35 +00:00
|
|
|
{
|
|
|
|
g_critical ("No texture %d found.", texture_id);
|
|
|
|
return;
|
|
|
|
}
|
2016-07-12 10:15:45 +00:00
|
|
|
|
2017-12-29 04:42:23 +00:00
|
|
|
if (self->bound_source_texture != t)
|
2016-07-20 16:55:35 +00:00
|
|
|
{
|
|
|
|
g_critical ("You must bind the texture before initializing it.");
|
|
|
|
return;
|
|
|
|
}
|
2016-07-19 13:32:17 +00:00
|
|
|
|
2017-11-16 08:33:20 +00:00
|
|
|
gsk_gl_driver_set_texture_parameters (self, min_filter, mag_filter);
|
2016-07-19 13:32:17 +00:00
|
|
|
|
2016-07-12 10:15:45 +00:00
|
|
|
gdk_cairo_surface_upload_to_gl (surface, GL_TEXTURE_2D, t->width, t->height, NULL);
|
2017-12-29 07:51:57 +00:00
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
2017-11-16 08:33:20 +00:00
|
|
|
gsk_profiler_counter_inc (self->profiler, self->counters.surface_uploads);
|
2017-12-29 07:51:57 +00:00
|
|
|
#endif
|
2016-07-12 10:15:45 +00:00
|
|
|
|
2016-07-19 13:32:17 +00:00
|
|
|
t->min_filter = min_filter;
|
|
|
|
t->mag_filter = mag_filter;
|
|
|
|
|
2019-06-02 15:54:50 +00:00
|
|
|
if (filter_uses_mipmaps (t->min_filter))
|
2016-07-12 10:15:45 +00:00
|
|
|
glGenerateMipmap (GL_TEXTURE_2D);
|
|
|
|
}
|