From 582f62c2b2cfa35794fe2886eab6579ffb7938f6 Mon Sep 17 00:00:00 2001 From: Daniel Rakos Date: Sun, 3 Mar 2019 16:38:29 +0100 Subject: [PATCH] Fixed TextureArray and Texture3D issues - Texture arrays and 3D textures weren't working previously due to an incorrect number of calls to glTexImage3D with incorrect level parameters. This change fixes that. - Fixed the incorrect calculation of the byte size of layered textures. - Added the layer count to the debugger info when viewing video memory usage. --- drivers/gles3/rasterizer_storage_gles3.cpp | 19 +++++++++++++------ servers/register_server_types.cpp | 6 +++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index e38f9f922cf..959bfaffc92 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -702,14 +702,18 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_ int mipmaps = 0; - while (width != 1 && height != 1) { - glTexImage3D(texture->target, 0, internal_format, width, height, depth, 0, format, type, NULL); + while (width > 0 || height > 0 || (p_type == VS::TEXTURE_TYPE_3D && depth > 0)) { + width = MAX(1, width); + height = MAX(1, height); + depth = MAX(1, depth); - width = MAX(1, width / 2); - height = MAX(1, height / 2); + glTexImage3D(texture->target, mipmaps, internal_format, width, height, depth, 0, format, type, NULL); + + width /= 2; + height /= 2; if (p_type == VS::TEXTURE_TYPE_3D) { - depth = MAX(1, depth / 2); + depth /= 2; } mipmaps++; @@ -926,6 +930,9 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref &p h = MAX(1, h >> 1); } + // Handle array and 3D textures, as those set their data per layer. + tsize *= MAX(texture->alloc_depth, 1); + info.texture_mem -= texture->total_data_size; texture->total_data_size = tsize; info.texture_mem += texture->total_data_size; @@ -1496,7 +1503,7 @@ void RasterizerStorageGLES3::texture_debug_usage(List *r_info) tinfo.format = t->format; tinfo.width = t->alloc_width; tinfo.height = t->alloc_height; - tinfo.depth = 0; + tinfo.depth = t->alloc_depth; tinfo.bytes = t->total_data_size; r_info->push_back(tinfo); } diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index 922f017d0ba..0cc1cc119c2 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -73,7 +73,11 @@ static void _debugger_get_resource_usage(Listget().bytes; usage.id = E->get().texture; usage.type = "Texture"; - usage.format = itos(E->get().width) + "x" + itos(E->get().height) + " " + Image::get_format_name(E->get().format); + if (E->get().depth == 0) { + usage.format = itos(E->get().width) + "x" + itos(E->get().height) + " " + Image::get_format_name(E->get().format); + } else { + usage.format = itos(E->get().width) + "x" + itos(E->get().height) + "x" + itos(E->get().depth) + " " + Image::get_format_name(E->get().format); + } r_usage->push_back(usage); } }