[gtk/matthiasc/color-profiles: 96/111] ngl: Allow specifying texture formats
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profiles: 96/111] ngl: Allow specifying texture formats
- Date: Wed, 6 Oct 2021 06:20:00 +0000 (UTC)
commit c79fd43cec0dea55618409e30916e584920282e6
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Oct 1 08:28:51 2021 -0400
ngl: Allow specifying texture formats
Allow passing a format when creating textures or render targets.
Update all callers to pass GL_RGBA8.
gsk/ngl/gsknglcommandqueue.c | 9 ++++++---
gsk/ngl/gsknglcommandqueueprivate.h | 2 ++
gsk/ngl/gskngldriver.c | 18 +++++++++++++++++-
gsk/ngl/gskngldriverprivate.h | 3 +++
gsk/ngl/gsknglrenderer.c | 1 +
gsk/ngl/gsknglrenderjob.c | 7 +++++++
gsk/ngl/gskngltexture.c | 2 ++
gsk/ngl/gskngltexturelibrary.c | 2 +-
gsk/ngl/gskngltextureprivate.h | 2 ++
9 files changed, 41 insertions(+), 5 deletions(-)
---
diff --git a/gsk/ngl/gsknglcommandqueue.c b/gsk/ngl/gsknglcommandqueue.c
index e06a5f76f5..dbcbbf9ca2 100644
--- a/gsk/ngl/gsknglcommandqueue.c
+++ b/gsk/ngl/gsknglcommandqueue.c
@@ -1233,6 +1233,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,
@@ -1249,6 +1250,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)
@@ -1274,6 +1276,7 @@ int
gsk_ngl_command_queue_create_texture (GskNglCommandQueue *self,
int width,
int height,
+ int format,
int min_filter,
int mag_filter)
{
@@ -1298,9 +1301,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)
@@ -1430,7 +1433,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 550320f15f..224b5bd672 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);
@@ -818,6 +819,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);
@@ -825,6 +827,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;
@@ -858,6 +862,7 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
gsk_ngl_driver_create_render_target (self,
width, height,
+ format,
min_filter, mag_filter,
&target);
@@ -916,7 +921,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);
@@ -937,6 +942,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. Should be GL_RGBA8, GL_RGBA16F or GL_RGBA32F
* @min_filter: GL_NEAREST or GL_LINEAR
* @mag_filter: GL_NEAREST or GL_FILTER
*
@@ -954,6 +960,7 @@ GskNglTexture *
gsk_ngl_driver_create_texture (GskNglDriver *self,
float width,
float height,
+ int format,
int min_filter,
int mag_filter)
{
@@ -964,9 +971,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,
@@ -1013,6 +1022,8 @@ 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. This should be GL_RGBA8,
+ * GL_RGBA16F or GL_RGBA32F
* @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
@@ -1032,6 +1043,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)
@@ -1064,6 +1076,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))
{
@@ -1072,6 +1085,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;
@@ -1131,6 +1145,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);
@@ -1383,6 +1398,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 4582ad06c3..ff13fce842 100644
--- a/gsk/ngl/gsknglrenderjob.c
+++ b/gsk/ngl/gsknglrenderjob.c
@@ -1276,6 +1276,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;
@@ -1286,6 +1287,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);
@@ -2197,6 +2199,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 ();
@@ -2467,6 +2470,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);
@@ -3875,6 +3879,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 ();
@@ -3973,6 +3978,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;
@@ -4044,6 +4050,7 @@ gsk_ngl_render_job_render (GskNglRenderJob *job,
gsk_ngl_driver_create_render_target (job->driver,
job->viewport.size.width,
job->viewport.size.height,
+ GL_RGBA8,
GL_NEAREST,
GL_NEAREST,
&render_target);
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]