Commit fb86fd90 authored by Timm Bäder's avatar Timm Bäder 🤔
Browse files

gl renderer: Make creating render targets easier

parent f32756e7
Pipeline #83722 passed with stages
in 27 minutes and 2 seconds
......@@ -585,21 +585,6 @@ gsk_gl_driver_set_texture_for_pointer (GskGLDriver *self,
g_hash_table_insert (self->pointer_textures, pointer, GINT_TO_POINTER (texture_id));
}
int
gsk_gl_driver_create_permanent_texture (GskGLDriver *self,
float width,
float height)
{
Texture *t;
g_return_val_if_fail (GSK_IS_GL_DRIVER (self), -1);
t = create_texture (self, width, height);
t->permanent = TRUE;
return t->texture_id;
}
int
gsk_gl_driver_create_texture (GskGLDriver *self,
float width,
......@@ -614,11 +599,11 @@ gsk_gl_driver_create_texture (GskGLDriver *self,
return t->texture_id;
}
int
gsk_gl_driver_create_render_target (GskGLDriver *self,
int texture_id,
gboolean add_depth_buffer,
gboolean add_stencil_buffer)
static int
create_render_target (GskGLDriver *self,
int texture_id,
gboolean add_depth_buffer,
gboolean add_stencil_buffer)
{
GLuint fbo_id, depth_stencil_buffer_id;
Texture *t;
......@@ -673,6 +658,38 @@ gsk_gl_driver_create_render_target (GskGLDriver *self,
return fbo_id;
}
void
gsk_gl_driver_create_render_target (GskGLDriver *self,
int width,
int height,
int *out_texture_id,
int *out_render_target_id)
{
int texture_id, render_target;
texture_id = gsk_gl_driver_create_texture (self, width, height);
gsk_gl_driver_bind_source_texture (self, texture_id);
gsk_gl_driver_init_texture_empty (self, texture_id);
render_target = create_render_target (self, texture_id, FALSE, FALSE);
*out_texture_id = texture_id;
*out_render_target_id = render_target;
}
/* 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);
g_assert_nonnull (t);
t->permanent = TRUE;
}
void
gsk_gl_driver_bind_source_texture (GskGLDriver *self,
int texture_id)
......
......@@ -39,17 +39,16 @@ int gsk_gl_driver_get_texture_for_pointer (GskGLDriver *driver
void gsk_gl_driver_set_texture_for_pointer (GskGLDriver *driver,
gpointer pointer,
int texture_id);
int gsk_gl_driver_create_permanent_texture (GskGLDriver *driver,
float width,
float height);
int gsk_gl_driver_create_texture (GskGLDriver *driver,
float width,
float height);
int gsk_gl_driver_create_render_target (GskGLDriver *driver,
int texture_id,
gboolean add_depth_buffer,
gboolean add_stencil_buffer);
void gsk_gl_driver_create_render_target (GskGLDriver *driver,
int width,
int height,
int *out_texture_id,
int *out_render_target_id);
void gsk_gl_driver_mark_texture_permanent (GskGLDriver *self,
int texture_id);
void gsk_gl_driver_bind_source_texture (GskGLDriver *driver,
int texture_id);
......
......@@ -8,12 +8,13 @@ gsk_gl_image_create (GskGLImage *self,
int width,
int height)
{
self->texture_id = gsk_gl_driver_create_permanent_texture (gl_driver, width, height);
self->texture_id = gsk_gl_driver_create_texture (gl_driver, width, height);
self->width = width;
self->height = height;
gsk_gl_driver_bind_source_texture (gl_driver, self->texture_id);
gsk_gl_driver_init_texture_empty (gl_driver, self->texture_id);
gsk_gl_driver_mark_texture_permanent (gl_driver, self->texture_id);
}
void
......
......@@ -1476,16 +1476,13 @@ render_outset_shadow_node (GskGLRenderer *self,
int prev_render_target;
GskRoundedRect blit_clip;
texture_id = gsk_gl_driver_create_texture (self->gl_driver, texture_width, texture_height);
gsk_gl_driver_bind_source_texture (self->gl_driver, texture_id);
gsk_gl_driver_init_texture_empty (self->gl_driver, texture_id);
gsk_gl_driver_create_render_target (self->gl_driver, texture_width, texture_height,
&texture_id, &render_target);
gdk_gl_context_label_object_printf (self->gl_context, GL_TEXTURE, texture_id,
"Outset Shadow Temp %d", texture_id);
render_target = gsk_gl_driver_create_render_target (self->gl_driver, texture_id, FALSE, FALSE);
gdk_gl_context_label_object_printf (self->gl_context, GL_FRAMEBUFFER, render_target,
"Outset Shadow FB Temp %d", render_target);
graphene_matrix_init_ortho (&item_proj,
0, texture_width, 0, texture_height,
ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE);
......@@ -1513,12 +1510,10 @@ render_outset_shadow_node (GskGLRenderer *self,
{ { texture_width, }, { 1, 1 }, },
});
blurred_texture_id = gsk_gl_driver_create_permanent_texture (self->gl_driver, texture_width, texture_height);
gsk_gl_driver_bind_source_texture (self->gl_driver, blurred_texture_id);
gsk_gl_driver_init_texture_empty (self->gl_driver, blurred_texture_id);
gsk_gl_driver_create_render_target (self->gl_driver, texture_width, texture_height,
&blurred_texture_id, &blurred_render_target);
gdk_gl_context_label_object_printf (self->gl_context, GL_TEXTURE, blurred_texture_id,
"Outset Shadow Cache %d", blurred_texture_id);
blurred_render_target = gsk_gl_driver_create_render_target (self->gl_driver, blurred_texture_id, TRUE, TRUE);
gdk_gl_context_label_object_printf (self->gl_context, GL_FRAMEBUFFER, render_target,
"Outset Shadow Cache FB %d", render_target);
......@@ -1556,6 +1551,7 @@ render_outset_shadow_node (GskGLRenderer *self,
ops_set_projection (builder, &prev_projection);
ops_set_render_target (builder, prev_render_target);
gsk_gl_driver_mark_texture_permanent (self->gl_driver, blurred_texture_id);
gsk_gl_shadow_cache_commit (&self->shadow_cache,
&offset_outline,
blur_radius,
......@@ -2773,13 +2769,9 @@ add_offscreen_ops (GskGLRenderer *self,
}
}
texture_id = gsk_gl_driver_create_texture (self->gl_driver, width, height);
gsk_gl_driver_bind_source_texture (self->gl_driver, texture_id);
gsk_gl_driver_init_texture_empty (self->gl_driver, texture_id);
gsk_gl_driver_create_render_target (self->gl_driver, width, height, &texture_id, &render_target);
gdk_gl_context_label_object_printf (self->gl_context, GL_TEXTURE, texture_id,
"Offscreen<%s> %d", child_node->node_class->type_name, texture_id);
render_target = gsk_gl_driver_create_render_target (self->gl_driver, texture_id, TRUE, TRUE);
gdk_gl_context_label_object_printf (self->gl_context, GL_FRAMEBUFFER, render_target,
"Offscreen<%s> FB %d", child_node->node_class->type_name, render_target);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment