2017-11-18 13:30:57 +00:00
|
|
|
|
|
|
|
#include "gskglimageprivate.h"
|
|
|
|
#include <epoxy/gl.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_gl_image_create (GskGLImage *self,
|
|
|
|
GskGLDriver *gl_driver,
|
|
|
|
int width,
|
2019-06-02 16:47:57 +00:00
|
|
|
int height,
|
|
|
|
int min_filter,
|
|
|
|
int mag_filter)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
2019-05-22 05:10:57 +00:00
|
|
|
self->texture_id = gsk_gl_driver_create_texture (gl_driver, width, height);
|
2017-11-18 13:30:57 +00:00
|
|
|
self->width = width;
|
|
|
|
self->height = height;
|
|
|
|
|
|
|
|
gsk_gl_driver_bind_source_texture (gl_driver, self->texture_id);
|
2019-06-02 16:47:57 +00:00
|
|
|
gsk_gl_driver_init_texture_empty (gl_driver, self->texture_id, min_filter, mag_filter);
|
2019-05-22 05:10:57 +00:00
|
|
|
gsk_gl_driver_mark_texture_permanent (gl_driver, self->texture_id);
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_gl_image_destroy (GskGLImage *self,
|
|
|
|
GskGLDriver *gl_driver)
|
|
|
|
{
|
|
|
|
gsk_gl_driver_destroy_texture (gl_driver, self->texture_id);
|
2019-05-22 05:33:45 +00:00
|
|
|
self->texture_id = 0;
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_gl_image_write_to_png (const GskGLImage *self,
|
|
|
|
GskGLDriver *gl_driver,
|
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
int stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, self->width);
|
|
|
|
guchar *data = g_malloc (self->height * stride);
|
|
|
|
cairo_surface_t *s;
|
|
|
|
|
|
|
|
gsk_gl_driver_bind_source_texture (gl_driver, self->texture_id);
|
|
|
|
glGetTexImage (GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
|
|
|
|
s = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32, self->width, self->height, stride);
|
|
|
|
cairo_surface_write_to_png (s, filename);
|
|
|
|
|
|
|
|
cairo_surface_destroy (s);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-14 14:22:40 +00:00
|
|
|
gsk_gl_image_upload_region (GskGLImage *self,
|
|
|
|
GskGLDriver *gl_driver,
|
|
|
|
const GskImageRegion *region)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
2019-02-14 14:22:40 +00:00
|
|
|
gsk_gl_driver_bind_source_texture (gl_driver, self->texture_id);
|
|
|
|
glBindTexture (GL_TEXTURE_2D, self->texture_id);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-02-14 14:22:40 +00:00
|
|
|
glTexSubImage2D (GL_TEXTURE_2D, 0, region->x, region->y, region->width, region->height,
|
|
|
|
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, region->data);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
/*gsk_gl_driver_bind_source_texture (gl_driver, self->texture_id);*/
|
|
|
|
/*gsk_gl_image_dump (self, gl_driver, "/home/baedert/atlases/test_dump.png");*/
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|