[gtk/wip/matthiasc/gsk-hdr: 3/5] ngl: Allow specifying texture formats
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/gsk-hdr: 3/5] ngl: Allow specifying texture formats
- Date: Wed, 6 Oct 2021 21:13:24 +0000 (UTC)
commit 80dbf8a83e0ab3d8c8d08a34ef67be9fce02840f
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Oct 5 23:36:49 2021 -0400
ngl: Allow specifying texture formats
Allow passing a format when creating textures or render targets.
Update all callers to pass GL_RGBA8, which is the format we
have always used so far.
gsk/ngl/gsknglcommandqueue.c | 9 ++++++---
gsk/ngl/gsknglcommandqueueprivate.h | 2 ++
gsk/ngl/gskngldriver.c | 20 +++++++++++++++++++-
gsk/ngl/gskngldriverprivate.h | 3 +++
gsk/ngl/gsknglrenderer.c | 1 +
gsk/ngl/gsknglrenderjob.c | 6 ++++++
gsk/ngl/gskngltexture.c | 2 ++
gsk/ngl/gskngltexturelibrary.c | 2 +-
gsk/ngl/gskngltextureprivate.h | 2 ++
9 files changed, 42 insertions(+), 5 deletions(-)
---
diff --git a/gsk/ngl/gsknglcommandqueue.c b/gsk/ngl/gsknglcommandqueue.c
index b2a474cf59..31dad9365b 100644
--- a/gsk/ngl/gsknglcommandqueue.c
+++ b/gsk/ngl/gsknglcommandqueue.c
@@ -1232,6 +1232,7 @@ gboolean
gsk_ngl_command_queue_create_render_target (GskNglCommandQueue *self,
int width,
int height,
+ int format,
int min_filter,
int mag_filter,
guint *out_fbo_id,
@@ -1248,6 +1249,7 @@ gsk_ngl_command_queue_create_render_target (GskNglCommandQueue *self,
texture_id = gsk_ngl_command_queue_create_texture (self,
width, height,
+ format,
min_filter, mag_filter);
if (texture_id == -1)
@@ -1273,6 +1275,7 @@ int
gsk_ngl_command_queue_create_texture (GskNglCommandQueue *self,
int width,
int height,
+ int format,
int min_filter,
int mag_filter)
{
@@ -1297,9 +1300,9 @@ gsk_ngl_command_queue_create_texture (GskNglCommandQueue *self,
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (gdk_gl_context_get_use_es (self->context))
- glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D (GL_TEXTURE_2D, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
else
- glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D (GL_TEXTURE_2D, 0, format, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
/* Restore the previous texture if it was set */
if (self->attachments->textures[0].id != 0)
@@ -1354,7 +1357,7 @@ gsk_ngl_command_queue_upload_texture (GskNglCommandQueue *self,
height = MAX (height, self->max_texture_size);
}
- texture_id = gsk_ngl_command_queue_create_texture (self, width, height, min_filter, mag_filter);
+ texture_id = gsk_ngl_command_queue_create_texture (self, width, height, GL_RGBA8, min_filter, mag_filter);
if (texture_id == -1)
return texture_id;
diff --git a/gsk/ngl/gsknglcommandqueueprivate.h b/gsk/ngl/gsknglcommandqueueprivate.h
index b13838d48e..40cca01162 100644
--- a/gsk/ngl/gsknglcommandqueueprivate.h
+++ b/gsk/ngl/gsknglcommandqueueprivate.h
@@ -290,12 +290,14 @@ int gsk_ngl_command_queue_upload_texture (GskNglCommandQue
int gsk_ngl_command_queue_create_texture (GskNglCommandQueue *self,
int width,
int height,
+ int format,
int min_filter,
int mag_filter);
guint gsk_ngl_command_queue_create_framebuffer (GskNglCommandQueue *self);
gboolean gsk_ngl_command_queue_create_render_target (GskNglCommandQueue *self,
int width,
int height,
+ int format,
int min_filter,
int mag_filter,
guint *out_fbo_id,
diff --git a/gsk/ngl/gskngldriver.c b/gsk/ngl/gskngldriver.c
index 3bf4ace071..87f2864241 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -183,6 +183,7 @@ gsk_ngl_driver_create_atlas (GskNglDriver *self)
atlas->texture_id = gsk_ngl_command_queue_create_texture (self->command_queue,
atlas->width,
atlas->height,
+ GL_RGBA8,
GL_LINEAR,
GL_LINEAR);
@@ -750,6 +751,7 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
guint texture_id;
int height;
int width;
+ int format;
g_return_val_if_fail (GSK_IS_NGL_DRIVER (self), 0);
g_return_val_if_fail (GDK_IS_TEXTURE (texture), 0);
@@ -757,6 +759,8 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
context = self->command_queue->context;
+ format = GL_RGBA8;
+
if (GDK_IS_GL_TEXTURE (texture))
{
GdkGLTexture *gl_texture = (GdkGLTexture *) texture;
@@ -799,7 +803,7 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
mag_filter);
t = gsk_ngl_texture_new (texture_id,
- width, height, min_filter, mag_filter,
+ width, height, format, min_filter, mag_filter,
self->current_frame_id);
g_hash_table_insert (self->textures, GUINT_TO_POINTER (texture_id), t);
@@ -820,6 +824,7 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
* @self: a `GskNglDriver`
* @width: the width of the texture
* @height: the height of the texture
+ * @format: format for the texture
* @min_filter: GL_NEAREST or GL_LINEAR
* @mag_filter: GL_NEAREST or GL_FILTER
*
@@ -827,6 +832,8 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
* to upload data, map to a framebuffer, or other uses which may
* modify the texture immediately.
*
+ * Typical examples for @format are GK_RGBA8, GL_RGBA16F or GL_RGBA32F.
+ *
* Use gsk_ngl_driver_release_texture() to release this texture back into
* the pool so it may be reused later in the pipeline.
*
@@ -837,6 +844,7 @@ GskNglTexture *
gsk_ngl_driver_create_texture (GskNglDriver *self,
float width,
float height,
+ int format,
int min_filter,
int mag_filter)
{
@@ -847,9 +855,11 @@ gsk_ngl_driver_create_texture (GskNglDriver *self,
texture_id = gsk_ngl_command_queue_create_texture (self->command_queue,
width, height,
+ format,
min_filter, mag_filter);
texture = gsk_ngl_texture_new (texture_id,
width, height,
+ format,
min_filter, mag_filter,
self->current_frame_id);
g_hash_table_insert (self->textures,
@@ -896,6 +906,7 @@ gsk_ngl_driver_release_texture (GskNglDriver *self,
* @self: a `GskNglDriver`
* @width: the width for the render target
* @height: the height for the render target
+ * @format: the format to use
* @min_filter: the min filter to use for the texture
* @mag_filter: the mag filter to use for the texture
* @out_render_target: (out): a location for the render target
@@ -904,6 +915,8 @@ gsk_ngl_driver_release_texture (GskNglDriver *self,
* bound to that framebuffer of the size @width x @height and using the
* appropriate filters.
*
+ * Typical examples for @format are GK_RGBA8, GL_RGBA16F or GL_RGBA32F.
+ *
* Use gsk_ngl_driver_release_render_target() when you are finished with
* the render target to release it. You may steal the texture from the
* render target when releasing it.
@@ -915,6 +928,7 @@ gboolean
gsk_ngl_driver_create_render_target (GskNglDriver *self,
int width,
int height,
+ int format,
int min_filter,
int mag_filter,
GskNglRenderTarget **out_render_target)
@@ -947,6 +961,7 @@ gsk_ngl_driver_create_render_target (GskNglDriver *self,
if (gsk_ngl_command_queue_create_render_target (self->command_queue,
width, height,
+ format,
min_filter, mag_filter,
&framebuffer_id, &texture_id))
{
@@ -955,6 +970,7 @@ gsk_ngl_driver_create_render_target (GskNglDriver *self,
render_target = g_slice_new0 (GskNglRenderTarget);
render_target->min_filter = min_filter;
render_target->mag_filter = mag_filter;
+ render_target->format = format;
render_target->width = width;
render_target->height = height;
render_target->framebuffer_id = framebuffer_id;
@@ -1014,6 +1030,7 @@ gsk_ngl_driver_release_render_target (GskNglDriver *self,
texture = gsk_ngl_texture_new (render_target->texture_id,
render_target->width,
render_target->height,
+ render_target->format,
render_target->min_filter,
render_target->mag_filter,
self->current_frame_id);
@@ -1266,6 +1283,7 @@ gsk_ngl_driver_add_texture_slices (GskNglDriver *self,
/* Allocate one Texture for the entire thing. */
t = gsk_ngl_texture_new (0,
tex_width, tex_height,
+ GL_RGBA8,
GL_NEAREST, GL_NEAREST,
self->current_frame_id);
diff --git a/gsk/ngl/gskngldriverprivate.h b/gsk/ngl/gskngldriverprivate.h
index 9d40c81b2b..42b6263ec1 100644
--- a/gsk/ngl/gskngldriverprivate.h
+++ b/gsk/ngl/gskngldriverprivate.h
@@ -88,6 +88,7 @@ struct _GskNglRenderTarget
guint texture_id;
int min_filter;
int mag_filter;
+ int format;
int width;
int height;
};
@@ -144,6 +145,7 @@ GdkGLContext *gsk_ngl_driver_get_context (GskNglDriver
gboolean gsk_ngl_driver_create_render_target (GskNglDriver *self,
int width,
int height,
+ int format,
int min_filter,
int mag_filter,
GskNglRenderTarget **render_target);
@@ -166,6 +168,7 @@ guint gsk_ngl_driver_load_texture (GskNglDriver
GskNglTexture *gsk_ngl_driver_create_texture (GskNglDriver *self,
float width,
float height,
+ int format,
int min_filter,
int mag_filter);
void gsk_ngl_driver_release_texture (GskNglDriver *self,
diff --git a/gsk/ngl/gsknglrenderer.c b/gsk/ngl/gsknglrenderer.c
index cdb6717043..7263d0b1e4 100644
--- a/gsk/ngl/gsknglrenderer.c
+++ b/gsk/ngl/gsknglrenderer.c
@@ -245,6 +245,7 @@ gsk_ngl_renderer_render_texture (GskRenderer *renderer,
if (gsk_ngl_driver_create_render_target (self->driver,
width, height,
+ GL_RGBA8,
GL_NEAREST, GL_NEAREST,
&render_target))
{
diff --git a/gsk/ngl/gsknglrenderjob.c b/gsk/ngl/gsknglrenderjob.c
index baf87f6461..d285eb24b0 100644
--- a/gsk/ngl/gsknglrenderjob.c
+++ b/gsk/ngl/gsknglrenderjob.c
@@ -1258,6 +1258,7 @@ blur_offscreen (GskNglRenderJob *job,
if (!gsk_ngl_driver_create_render_target (job->driver,
MAX (texture_to_blur_width, 1),
MAX (texture_to_blur_height, 1),
+ GL_RGBA8,
GL_NEAREST, GL_NEAREST,
&pass1))
return 0;
@@ -1268,6 +1269,7 @@ blur_offscreen (GskNglRenderJob *job,
if (!gsk_ngl_driver_create_render_target (job->driver,
texture_to_blur_width,
texture_to_blur_height,
+ GL_RGBA8,
GL_NEAREST, GL_NEAREST,
&pass2))
return gsk_ngl_driver_release_render_target (job->driver, pass1, FALSE);
@@ -2179,6 +2181,7 @@ gsk_ngl_render_job_visit_blurred_inset_shadow_node (GskNglRenderJob *job,
if (!gsk_ngl_driver_create_render_target (job->driver,
texture_width, texture_height,
+ GL_RGBA8,
GL_NEAREST, GL_NEAREST,
&render_target))
g_assert_not_reached ();
@@ -2449,6 +2452,7 @@ gsk_ngl_render_job_visit_blurred_outset_shadow_node (GskNglRenderJob *job,
gsk_ngl_driver_create_render_target (job->driver,
texture_width, texture_height,
+ GL_RGBA8,
GL_NEAREST, GL_NEAREST,
&render_target);
@@ -3856,6 +3860,7 @@ gsk_ngl_render_job_visit_node_with_offscreen (GskNglRenderJob *job,
if (!gsk_ngl_driver_create_render_target (job->driver,
scaled_width, scaled_height,
+ GL_RGBA8,
filter, filter,
&render_target))
g_assert_not_reached ();
@@ -3954,6 +3959,7 @@ gsk_ngl_render_job_render_flipped (GskNglRenderJob *job,
if (!gsk_ngl_command_queue_create_render_target (job->command_queue,
MAX (1, job->viewport.size.width),
MAX (1, job->viewport.size.height),
+ GL_RGBA8,
GL_NEAREST, GL_NEAREST,
&framebuffer_id, &texture_id))
return;
diff --git a/gsk/ngl/gskngltexture.c b/gsk/ngl/gskngltexture.c
index 5ee38f69b6..c70d4d91b2 100644
--- a/gsk/ngl/gskngltexture.c
+++ b/gsk/ngl/gskngltexture.c
@@ -59,6 +59,7 @@ GskNglTexture *
gsk_ngl_texture_new (guint texture_id,
int width,
int height,
+ int format,
int min_filter,
int mag_filter,
gint64 frame_id)
@@ -70,6 +71,7 @@ gsk_ngl_texture_new (guint texture_id,
texture->link.data = texture;
texture->min_filter = min_filter;
texture->mag_filter = mag_filter;
+ texture->format = format;
texture->width = width;
texture->height = height;
texture->last_used_in_frame = frame_id;
diff --git a/gsk/ngl/gskngltexturelibrary.c b/gsk/ngl/gskngltexturelibrary.c
index 7998ae9850..03b8e252f7 100644
--- a/gsk/ngl/gskngltexturelibrary.c
+++ b/gsk/ngl/gskngltexturelibrary.c
@@ -228,7 +228,7 @@ gsk_ngl_texture_library_pack_one (GskNglTextureLibrary *self,
height = MIN (height, self->driver->command_queue->max_texture_size);
}
- texture = gsk_ngl_driver_create_texture (self->driver, width, height, GL_LINEAR, GL_LINEAR);
+ texture = gsk_ngl_driver_create_texture (self->driver, width, height, GL_RGBA8, GL_LINEAR, GL_LINEAR);
texture->permanent = TRUE;
return texture;
diff --git a/gsk/ngl/gskngltextureprivate.h b/gsk/ngl/gskngltextureprivate.h
index 1d9052f625..55ef48c4d3 100644
--- a/gsk/ngl/gskngltextureprivate.h
+++ b/gsk/ngl/gskngltextureprivate.h
@@ -67,6 +67,7 @@ struct _GskNglTexture
int height;
int min_filter;
int mag_filter;
+ int format;
/* Set when used by an atlas so we don't drop the texture */
guint permanent : 1;
@@ -75,6 +76,7 @@ struct _GskNglTexture
GskNglTexture *gsk_ngl_texture_new (guint texture_id,
int width,
int height,
+ int format,
int min_filter,
int mag_filter,
gint64 frame_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]