COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
- /* Although this texture is being moved out of the atlas, we
- don't need to flush the journal here because the contents of
- the old image will still be left in the same position in the
- atlas. The only way this would get overwritten would be if a
- new texture was added, but in that case we flush the journal
- anyway */
+ /* We don't know if any materials may currently be referenced in
+ * the journal that depend on the current underlying GL texture
+ * storage so we flush the journal before migrating.
+ *
+ * We are assuming that texture atlas migration never happens
+ * during a flush so we don't have to consider recursion here.
+ */
+ _cogl_journal_flush ();
cogl_handle_unref (atlas_tex->sub_texture);
_cogl_atlas_texture_blit_begin (&blit_data, new_texture, old_texture);
+ /* We don't know if any materials may currently be referenced in the
+ * journal that depend on the current underlying GL texture storage
+ * so we flush the journal before migrating.
+ *
+ * We are assuming that texture atlas migration never happens during
+ * a flush so we don't have to consider recursion here.
+ */
+ _cogl_journal_flush ();
+
for (i = 0; i < n_textures; i++)
{
/* Skip the texture that is being added because it doesn't contain
return COGL_INVALID_HANDLE;
}
- /* We need to flush the journal when adding a new atlas texture for
- two reasons:
-
- 1) If the atlas gets reorganized then any existing textures may
- be moved so the coordinates in journal will be wrong.
-
- 2) We don't want to flush before migrating a texture out of the
- atlas because we will potentially already be in the middle of
- a flush to cause the migration. Therefore we rely on the old
- contents of the texture still remaining in the atlas so that
- any existing journal entries will still be valid. However once
- the texture is migrated out the space would be free to be
- reclaimed by this new texture. That won't matter if we flush
- now */
- _cogl_journal_flush ();
-
/* We need to allocate the texture now because we need the pointer
to set as the data for the rectangle in the atlas */
atlas_tex = g_new (CoglAtlasTexture, 1);