gsk: Split surface upload from texture creation

We're going to need a method to create textures without a surface.
This commit is contained in:
Emmanuele Bassi 2016-07-12 11:15:45 +01:00
parent b98fb07419
commit 8807f23f76
3 changed files with 37 additions and 11 deletions

View File

@ -11,6 +11,8 @@ typedef struct {
GLuint texture_id;
int width;
int height;
GLuint min_filter;
GLuint mag_filter;
} Texture;
typedef struct {
@ -197,12 +199,13 @@ gsk_gl_driver_create_texture (GskGLDriver *driver,
int width,
int height,
int min_filter,
int mag_filter,
cairo_surface_t *surface)
int mag_filter)
{
guint texture_id;
Texture t;
g_return_val_if_fail (GSK_IS_GL_DRIVER (driver), -1);
glGenTextures (1, &texture_id);
glBindTexture (GL_TEXTURE_2D, texture_id);
@ -211,14 +214,11 @@ gsk_gl_driver_create_texture (GskGLDriver *driver,
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
gdk_cairo_surface_upload_to_gl (surface, GL_TEXTURE_2D, width, height, NULL);
if (min_filter != GL_NEAREST)
glGenerateMipmap (GL_TEXTURE_2D);
t.texture_id = texture_id;
t.width = width;
t.height = height;
t.min_filter = min_filter;
t.mag_filter = mag_filter;
g_array_append_val (driver->textures, t);
return texture_id;
@ -367,3 +367,24 @@ gsk_gl_driver_bind_vao (GskGLDriver *driver,
driver->bound_vao = v;
}
}
void
gsk_gl_driver_render_surface_to_texture (GskGLDriver *driver,
cairo_surface_t *surface,
int texture_id)
{
Texture *t;
g_return_if_fail (GSK_IS_GL_DRIVER (driver));
t = gsk_gl_driver_get_texture (driver, texture_id);
if (t == NULL)
return;
glBindTexture (GL_TEXTURE_2D, t->texture_id);
gdk_cairo_surface_upload_to_gl (surface, GL_TEXTURE_2D, t->width, t->height, NULL);
if (t->min_filter != GL_NEAREST)
glGenerateMipmap (GL_TEXTURE_2D);
}

View File

@ -25,8 +25,7 @@ int gsk_gl_driver_create_texture (GskGLDriver *driver
int width,
int height,
int min_filter,
int mag_filter,
cairo_surface_t *surface);
int mag_filter);
int gsk_gl_driver_create_vao_for_quad (GskGLDriver *driver,
int position_id,
int uv_id,
@ -40,6 +39,10 @@ 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,
cairo_surface_t *surface,
int texture_id);
G_END_DECLS
#endif /* __GSK_GL_DRIVER_PRIVATE_H__ */

View File

@ -719,8 +719,10 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
bounds.size.width,
bounds.size.height,
self->gl_min_filter,
self->gl_mag_filter,
surface);
self->gl_mag_filter);
gsk_gl_driver_render_surface_to_texture (self->gl_driver,
surface,
item.render_data.texture_id);
GSK_NOTE (OPENGL, g_print ("Adding node <%s>[%p] to render items\n",
node->name != NULL ? node->name : "unnamed",