[gtk/matthiasc/color-profiles: 4/9] ngl: Allow specifying texture formats
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profiles: 4/9] ngl: Allow specifying texture formats
- Date: Fri, 1 Oct 2021 18:24:22 +0000 (UTC)
commit 130e77c07ffe8c137644ecdcdc2286a6a38dc849
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 | 17 ++++++++++++++++-
gsk/ngl/gskngldriverprivate.h | 3 +++
gsk/ngl/gsknglrenderer.c | 1 +
gsk/ngl/gsknglrenderjob.c | 7 +++++++
gsk/ngl/gskngltexturelibrary.c | 2 +-
gsk/ngl/gskngltexturepool.c | 8 ++++++--
gsk/ngl/gskngltexturepoolprivate.h | 3 +++
9 files changed, 45 insertions(+), 7 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 1ac952cf12..11c4fc0b76 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -179,6 +179,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);
@@ -809,6 +810,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);
@@ -816,6 +818,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;
@@ -849,6 +853,7 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
gsk_ngl_driver_create_render_target (self,
width, height,
+ format,
min_filter, mag_filter,
&target);
@@ -907,7 +912,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);
@@ -928,6 +933,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
*
@@ -945,6 +951,7 @@ GskNglTexture *
gsk_ngl_driver_create_texture (GskNglDriver *self,
float width,
float height,
+ int format,
int min_filter,
int mag_filter)
{
@@ -954,6 +961,7 @@ gsk_ngl_driver_create_texture (GskNglDriver *self,
texture = gsk_ngl_texture_pool_get (&self->texture_pool,
width, height,
+ format,
min_filter, mag_filter);
g_hash_table_insert (self->textures,
GUINT_TO_POINTER (texture->texture_id),
@@ -997,6 +1005,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
@@ -1016,6 +1026,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)
@@ -1048,6 +1059,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))
{
@@ -1056,6 +1068,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;
@@ -1115,6 +1128,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);
@@ -1367,6 +1381,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 b5b5e60600..457f7e26ee 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;
};
@@ -145,6 +146,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);
@@ -167,6 +169,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/gskngltexturelibrary.c b/gsk/ngl/gskngltexturelibrary.c
index 6e4eb62d4e..00e2cb73b8 100644
--- a/gsk/ngl/gskngltexturelibrary.c
+++ b/gsk/ngl/gskngltexturelibrary.c
@@ -211,7 +211,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/gskngltexturepool.c b/gsk/ngl/gskngltexturepool.c
index c5a1d04c4e..3293443f31 100644
--- a/gsk/ngl/gskngltexturepool.c
+++ b/gsk/ngl/gskngltexturepool.c
@@ -114,6 +114,7 @@ GskNglTexture *
gsk_ngl_texture_pool_get (GskNglTexturePool *self,
int width,
int height,
+ int format,
int min_filter,
int mag_filter)
{
@@ -125,6 +126,7 @@ gsk_ngl_texture_pool_get (GskNglTexturePool *self,
texture->link.data = texture;
texture->min_filter = min_filter;
texture->mag_filter = mag_filter;
+ texture->format = format;
glGenTextures (1, &texture->texture_id);
@@ -136,9 +138,9 @@ gsk_ngl_texture_pool_get (GskNglTexturePool *self,
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (gdk_gl_context_get_use_es (gdk_gl_context_get_current ()))
- 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);
glBindTexture (GL_TEXTURE_2D, 0);
@@ -149,6 +151,7 @@ GskNglTexture *
gsk_ngl_texture_new (guint texture_id,
int width,
int height,
+ int format,
int min_filter,
int mag_filter,
gint64 frame_id)
@@ -160,6 +163,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/gskngltexturepoolprivate.h b/gsk/ngl/gskngltexturepoolprivate.h
index 548fe83f4f..ff2db9d9f4 100644
--- a/gsk/ngl/gskngltexturepoolprivate.h
+++ b/gsk/ngl/gskngltexturepoolprivate.h
@@ -72,6 +72,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;
@@ -82,6 +83,7 @@ void gsk_ngl_texture_pool_clear (GskNglTexturePool
GskNglTexture *gsk_ngl_texture_pool_get (GskNglTexturePool *self,
int width,
int height,
+ int format,
int min_filter,
int mag_filter);
void gsk_ngl_texture_pool_put (GskNglTexturePool *self,
@@ -89,6 +91,7 @@ void gsk_ngl_texture_pool_put (GskNglTexturePool
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]