gl renderer: add basic code to support texture tiling

This commit is contained in:
Timm Bäder 2018-03-19 11:34:01 +01:00
parent a9fec38680
commit 4240119d64
3 changed files with 42 additions and 21 deletions

View File

@ -654,3 +654,14 @@ gsk_gl_driver_init_texture_with_surface (GskGLDriver *self,
if (t->min_filter != GL_NEAREST) if (t->min_filter != GL_NEAREST)
glGenerateMipmap (GL_TEXTURE_2D); glGenerateMipmap (GL_TEXTURE_2D);
} }
gboolean
gsk_gl_driver_texture_needs_tiling (GskGLDriver *self,
GdkTexture *texture)
{
int max = gsk_gl_driver_get_max_texture_size (self);
g_assert (self->max_texture_size > -1);
return texture->width > max || texture->height > max;
}

View File

@ -33,6 +33,8 @@ int gsk_gl_driver_create_permanent_texture (GskGLDriver *driver
int gsk_gl_driver_create_texture (GskGLDriver *driver, int gsk_gl_driver_create_texture (GskGLDriver *driver,
float width, float width,
float height); float height);
gboolean gsk_gl_driver_texture_needs_tiling (GskGLDriver *driver,
GdkTexture *texture);
int gsk_gl_driver_create_render_target (GskGLDriver *driver, int gsk_gl_driver_create_render_target (GskGLDriver *driver,
int texture_id, int texture_id,
gboolean add_depth_buffer, gboolean add_depth_buffer,

View File

@ -555,33 +555,41 @@ render_texture_node (GskGLRenderer *self,
GskRenderNode *node, GskRenderNode *node,
RenderOpBuilder *builder) RenderOpBuilder *builder)
{ {
const float min_x = builder->dx + node->bounds.origin.x;
const float min_y = builder->dy + node->bounds.origin.y;
const float max_x = min_x + node->bounds.size.width;
const float max_y = min_y + node->bounds.size.height;
GdkTexture *texture = gsk_texture_node_get_texture (node); GdkTexture *texture = gsk_texture_node_get_texture (node);
int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
int texture_id;
get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter); if (gsk_gl_driver_texture_needs_tiling (self->gl_driver, texture))
{
texture_id = gsk_gl_driver_get_texture_for_texture (self->gl_driver, }
texture, else
gl_min_filter, {
gl_mag_filter); const float min_x = builder->dx + node->bounds.origin.x;
ops_set_program (builder, &self->blit_program); const float min_y = builder->dy + node->bounds.origin.y;
ops_set_texture (builder, texture_id); const float max_x = min_x + node->bounds.size.width;
const float max_y = min_y + node->bounds.size.height;
int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
int texture_id;
get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter);
texture_id = gsk_gl_driver_get_texture_for_texture (self->gl_driver,
texture,
gl_min_filter,
gl_mag_filter);
ops_set_program (builder, &self->blit_program);
ops_set_texture (builder, texture_id);
ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) { ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
{ { min_x, min_y }, { 0, 0 }, }, { { min_x, min_y }, { 0, 0 }, },
{ { min_x, max_y }, { 0, 1 }, }, { { min_x, max_y }, { 0, 1 }, },
{ { max_x, min_y }, { 1, 0 }, }, { { max_x, min_y }, { 1, 0 }, },
{ { max_x, max_y }, { 1, 1 }, }, { { max_x, max_y }, { 1, 1 }, },
{ { min_x, max_y }, { 0, 1 }, }, { { min_x, max_y }, { 0, 1 }, },
{ { max_x, min_y }, { 1, 0 }, }, { { max_x, min_y }, { 1, 0 }, },
}); });
}
} }
static inline void static inline void