Merge pull request #77985 from clayjohn/GLES3-array-texture-crash

Properly update array textures when using the OpenGL backend to avoid crash
This commit is contained in:
Rémi Verschelde 2023-06-08 09:11:54 +02:00
commit 2985a9ac34
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -789,14 +789,14 @@ void TextureStorage::texture_2d_layered_initialize(RID p_texture, const Vector<R
texture.format = image->get_format();
texture.type = Texture::TYPE_LAYERED;
texture.layered_type = p_layered_type;
texture.target = GL_TEXTURE_2D_ARRAY;
texture.target = p_layered_type == RS::TEXTURE_LAYERED_CUBEMAP ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D_ARRAY;
texture.layers = p_layers.size();
_get_gl_image_and_format(Ref<Image>(), texture.format, texture.real_format, texture.gl_format_cache, texture.gl_internal_format_cache, texture.gl_type_cache, texture.compressed, false);
texture.active = true;
glGenTextures(1, &texture.tex_id);
texture_owner.initialize_rid(p_texture, texture);
for (int i = 0; i < p_layers.size(); i++) {
_texture_set_data(p_texture, p_layers[i], 1, i == 0);
_texture_set_data(p_texture, p_layers[i], i, i == 0);
}
}
@ -1310,7 +1310,7 @@ void TextureStorage::_texture_set_data(RID p_texture, const Ref<Image> &p_image,
if (initialize) {
glTexImage3D(GL_TEXTURE_2D_ARRAY, i, internal_format, w, h, texture->layers, 0, format, type, nullptr);
}
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, i, 0, 0, p_layer, w, h, 0, format, type, &read[ofs]);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, i, 0, 0, p_layer, w, h, 1, format, type, &read[ofs]);
} else {
glTexImage2D(blit_target, i, internal_format, w, h, 0, format, type, &read[ofs]);
}