gsk: Rework surface -> texture API

Drop the texture parameters handling from the texture creation, and
associate them with the contents upload. Also, rename the function to
something more in line with what it does.
This commit is contained in:
Emmanuele Bassi 2016-07-19 14:32:17 +01:00
parent e2a43a8701
commit b169ce374e
3 changed files with 28 additions and 19 deletions

View File

@ -243,9 +243,7 @@ gsk_gl_driver_get_vao (GskGLDriver *driver,
int
gsk_gl_driver_create_texture (GskGLDriver *driver,
int width,
int height,
int min_filter,
int mag_filter)
int height)
{
guint texture_id;
Texture *t;
@ -257,15 +255,15 @@ gsk_gl_driver_create_texture (GskGLDriver *driver,
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
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_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
t = texture_new ();
t->texture_id = texture_id;
t->width = width;
t->height = height;
t->min_filter = min_filter;
t->mag_filter = mag_filter;
t->min_filter = GL_NEAREST;
t->mag_filter = GL_NEAREST;
g_hash_table_insert (driver->textures, GUINT_TO_POINTER (texture_id), t);
return texture_id;
@ -441,9 +439,11 @@ gsk_gl_driver_bind_render_target (GskGLDriver *driver,
}
void
gsk_gl_driver_render_surface_to_texture (GskGLDriver *driver,
gsk_gl_driver_init_texture_with_surface (GskGLDriver *driver,
int texture_id,
cairo_surface_t *surface,
int texture_id)
int min_filter,
int mag_filter)
{
Texture *t;
@ -455,8 +455,17 @@ gsk_gl_driver_render_surface_to_texture (GskGLDriver *driver,
glBindTexture (GL_TEXTURE_2D, t->texture_id);
if (min_filter != t->min_filter)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
if (mag_filter != t->mag_filter)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
gdk_cairo_surface_upload_to_gl (surface, GL_TEXTURE_2D, t->width, t->height, NULL);
t->min_filter = min_filter;
t->mag_filter = mag_filter;
if (t->min_filter != GL_NEAREST)
glGenerateMipmap (GL_TEXTURE_2D);
}

View File

@ -23,9 +23,7 @@ void gsk_gl_driver_end_frame (GskGLDriver *driver
int gsk_gl_driver_create_texture (GskGLDriver *driver,
int width,
int height,
int min_filter,
int mag_filter);
int height);
int gsk_gl_driver_create_vao_for_quad (GskGLDriver *driver,
int position_id,
int uv_id,
@ -41,9 +39,11 @@ void gsk_gl_driver_bind_mask_texture (GskGLDriver *driver
void gsk_gl_driver_bind_vao (GskGLDriver *driver,
int vao_id);
void gsk_gl_driver_render_surface_to_texture (GskGLDriver *driver,
void gsk_gl_driver_init_texture_with_surface (GskGLDriver *driver,
int texture_id,
cairo_surface_t *surface,
int texture_id);
int min_filter,
int mag_filter);
G_END_DECLS

View File

@ -720,12 +720,12 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
/* Upload the Cairo surface to a GL texture */
item.render_data.texture_id = gsk_gl_driver_create_texture (self->gl_driver,
bounds.size.width,
bounds.size.height,
self->gl_min_filter,
self->gl_mag_filter);
gsk_gl_driver_render_surface_to_texture (self->gl_driver,
bounds.size.height);
gsk_gl_driver_init_texture_with_surface (self->gl_driver,
item.render_data.texture_id,
surface,
item.render_data.texture_id);
self->gl_min_filter,
self->gl_mag_filter);
GSK_NOTE (OPENGL, g_print ("Adding node <%s>[%p] to render items\n",
node->name != NULL ? node->name : "unnamed",