wip: hacks around external

This commit is contained in:
Matthias Clasen
2023-10-15 11:54:03 -04:00
parent 5d0aa63489
commit 04cf18176f
4 changed files with 41 additions and 12 deletions

View File

@@ -1892,8 +1892,8 @@ init_dmabuf_formats (GdkDisplay *display)
uint64_t *modifiers; uint64_t *modifiers;
unsigned int *external_only; unsigned int *external_only;
if (!gdk_dmabuf_texture_may_support ((unsigned int)formats[i])) // if (!gdk_dmabuf_texture_may_support ((unsigned int)formats[i]))
continue; // continue;
eglQueryDmaBufModifiersEXT (priv->egl_display, formats[i], 0, NULL, NULL, &num_modifiers); eglQueryDmaBufModifiersEXT (priv->egl_display, formats[i], 0, NULL, NULL, &num_modifiers);
modifiers = g_new (uint64_t, num_modifiers); modifiers = g_new (uint64_t, num_modifiers);

View File

@@ -282,7 +282,10 @@ snapshot_attachments (const GskGLAttachmentState *state,
{ {
bind[count].id = state->textures[i].id; bind[count].id = state->textures[i].id;
bind[count].texture = state->textures[i].texture; bind[count].texture = state->textures[i].texture;
bind[count].sampler = state->textures[i].sampler; if (state->textures[i].target == GL_TEXTURE_EXTERNAL_OES)
bind[count].sampler = 15;
else
bind[count].sampler = state->textures[i].sampler;
count++; count++;
} }
} }
@@ -1190,12 +1193,23 @@ gsk_gl_command_queue_execute (GskGLCommandQueue *self,
s->sync = NULL; s->sync = NULL;
} }
glBindTexture (GL_TEXTURE_2D, bind->id); if (bind->sampler == 15)
glBindTexture (GL_TEXTURE_EXTERNAL_OES, bind->id);
else
glBindTexture (GL_TEXTURE_2D, bind->id);
textures[bind->texture] = bind->id; textures[bind->texture] = bind->id;
if (!self->has_samplers) if (!self->has_samplers)
{ {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_from_index (bind->sampler / GSK_GL_N_FILTERS)); if (bind->sampler == 15)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_from_index (bind->sampler % GSK_GL_N_FILTERS)); {
glTexParameteri (GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else
{
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_from_index (bind->sampler / GSK_GL_N_FILTERS));
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_from_index (bind->sampler % GSK_GL_N_FILTERS));
}
} }
} }
@@ -1205,8 +1219,16 @@ gsk_gl_command_queue_execute (GskGLCommandQueue *self,
glBindSampler (bind->texture, self->samplers[bind->sampler]); glBindSampler (bind->texture, self->samplers[bind->sampler]);
else else
{ {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_from_index (bind->sampler / GSK_GL_N_FILTERS)); if (bind->sampler == 15)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_from_index (bind->sampler % GSK_GL_N_FILTERS)); {
glTexParameteri (GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else
{
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_from_index (bind->sampler / GSK_GL_N_FILTERS));
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_from_index (bind->sampler % GSK_GL_N_FILTERS));
}
} }
samplers[bind->texture] = bind->sampler; samplers[bind->texture] = bind->sampler;
} }
@@ -1324,7 +1346,7 @@ gsk_gl_command_queue_end_frame (GskGLCommandQueue *self)
if (self->attachments->textures[i].id != 0) if (self->attachments->textures[i].id != 0)
{ {
glActiveTexture (GL_TEXTURE0 + i); glActiveTexture (GL_TEXTURE0 + i);
glBindTexture (GL_TEXTURE_2D, 0); glBindTexture (self->attachments->textures[i].target, 0);
self->attachments->textures[i].id = 0; self->attachments->textures[i].id = 0;
self->attachments->textures[i].changed = FALSE; self->attachments->textures[i].changed = FALSE;
@@ -1401,7 +1423,7 @@ gsk_gl_command_queue_create_texture (GskGLCommandQueue *self,
glActiveTexture (GL_TEXTURE0); glActiveTexture (GL_TEXTURE0);
glBindTexture (GL_TEXTURE_2D, texture_id); glBindTexture (GL_TEXTURE_2D, texture_id);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -1429,8 +1451,10 @@ gsk_gl_command_queue_create_texture (GskGLCommandQueue *self,
} }
/* Restore the previous texture if it was set */ /* Restore the previous texture if it was set */
if (self->attachments->textures[0].id != 0) if (self->attachments->textures[0].id != 0 &&
glBindTexture (GL_TEXTURE_2D, self->attachments->textures[0].id); self->attachments->textures[0].target == GL_TEXTURE_2D)
glBindTexture (self->attachments->textures[0].target,
self->attachments->textures[0].id);
return (int)texture_id; return (int)texture_id;
} }

View File

@@ -54,6 +54,7 @@ typedef struct _GskGLCommandBind
*/ */
guint texture : 4; guint texture : 4;
/* the sampler to use. We set sampler to 15 to indicate external textures */
guint sampler : 4; guint sampler : 4;
/* The identifier for the texture created with glGenTextures(). */ /* The identifier for the texture created with glGenTextures(). */

View File

@@ -789,9 +789,13 @@ egl_import_image (EGLImage image,
glGenTextures (1, &texture_id); glGenTextures (1, &texture_id);
glBindTexture (target, texture_id); glBindTexture (target, texture_id);
g_assert (glGetError() == GL_NO_ERROR);
glEGLImageTargetTexture2DOES (target, image); glEGLImageTargetTexture2DOES (target, image);
g_assert (glGetError() == GL_NO_ERROR);
glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
g_assert (glGetError() == GL_NO_ERROR);
glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
g_assert (glGetError() == GL_NO_ERROR);
return texture_id; return texture_id;
} }