diff options
author | Bastiaan Olij <mux213@gmail.com> | 2023-02-22 16:28:58 +1100 |
---|---|---|
committer | Bastiaan Olij <mux213@gmail.com> | 2023-02-22 16:50:58 +1100 |
commit | 467d735eb1c9de94b94623caa8afa6d2a921a275 (patch) | |
tree | 66e2a82fe7f865f645647989318620af2766af02 /servers/rendering/renderer_rd/storage_rd | |
parent | e13fae1414b0369fdd3f51b4e3529fd3f272b0e1 (diff) |
Fix issue with default textures requiring arrays when using multiview
Diffstat (limited to 'servers/rendering/renderer_rd/storage_rd')
3 files changed, 90 insertions, 1 deletions
diff --git a/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp b/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp index f5d6404f01..e1dc9f8624 100644 --- a/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp +++ b/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp @@ -486,6 +486,11 @@ Ref<RenderBufferCustomDataRD> RenderSceneBuffersRD::get_custom_data(const String // Depth texture bool RenderSceneBuffersRD::has_depth_texture() { + if (render_target.is_null()) { + // not applicable when there is no render target (likely this is for a reflection probe) + return false; + } + RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); RID depth = texture_storage->render_target_get_override_depth(render_target); if (depth.is_valid()) { @@ -496,6 +501,11 @@ bool RenderSceneBuffersRD::has_depth_texture() { } RID RenderSceneBuffersRD::get_depth_texture() { + if (render_target.is_null()) { + // not applicable when there is no render target (likely this is for a reflection probe) + return RID(); + } + RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); RID depth = texture_storage->render_target_get_override_depth(render_target); if (depth.is_valid()) { diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index 0ee9b28826..50b324a9fd 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -362,7 +362,7 @@ TextureStorage::TextureStorage() { } } - { //create default array + { //create default array white RD::TextureFormat tformat; tformat.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; @@ -388,6 +388,82 @@ TextureStorage::TextureStorage() { } } + { //create default array black + + RD::TextureFormat tformat; + tformat.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; + tformat.width = 4; + tformat.height = 4; + tformat.array_layers = 1; + tformat.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT; + tformat.texture_type = RD::TEXTURE_TYPE_2D_ARRAY; + + Vector<uint8_t> pv; + pv.resize(16 * 4); + for (int i = 0; i < 16; i++) { + pv.set(i * 4 + 0, 0); + pv.set(i * 4 + 1, 0); + pv.set(i * 4 + 2, 0); + pv.set(i * 4 + 3, 0); + } + + { + Vector<Vector<uint8_t>> vpv; + vpv.push_back(pv); + default_rd_textures[DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK] = RD::get_singleton()->texture_create(tformat, RD::TextureView(), vpv); + } + } + + { //create default array normal + + RD::TextureFormat tformat; + tformat.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; + tformat.width = 4; + tformat.height = 4; + tformat.array_layers = 1; + tformat.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT; + tformat.texture_type = RD::TEXTURE_TYPE_2D_ARRAY; + + Vector<uint8_t> pv; + pv.resize(16 * 4); + for (int i = 0; i < 16; i++) { + pv.set(i * 4 + 0, 128); + pv.set(i * 4 + 1, 128); + pv.set(i * 4 + 2, 255); + pv.set(i * 4 + 3, 255); + } + + { + Vector<Vector<uint8_t>> vpv; + vpv.push_back(pv); + default_rd_textures[DEFAULT_RD_TEXTURE_2D_ARRAY_NORMAL] = RD::get_singleton()->texture_create(tformat, RD::TextureView(), vpv); + } + } + + { //create default array depth + + RD::TextureFormat tformat; + tformat.format = RD::DATA_FORMAT_D16_UNORM; + tformat.width = 4; + tformat.height = 4; + tformat.array_layers = 1; + tformat.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT | RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + tformat.texture_type = RD::TEXTURE_TYPE_2D_ARRAY; + + Vector<uint8_t> sv; + sv.resize(16 * 2); + uint16_t *ptr = (uint16_t *)sv.ptrw(); + for (int i = 0; i < 16; i++) { + ptr[i] = Math::make_half_float(1.0f); + } + + { + Vector<Vector<uint8_t>> vsv; + vsv.push_back(sv); + default_rd_textures[DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH] = RD::get_singleton()->texture_create(tformat, RD::TextureView(), vsv); + } + } + { // default atlas texture RD::TextureFormat tformat; tformat.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.h b/servers/rendering/renderer_rd/storage_rd/texture_storage.h index c16f5274ad..b6bb9fa52f 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.h @@ -62,6 +62,9 @@ public: DEFAULT_RD_TEXTURE_3D_WHITE, DEFAULT_RD_TEXTURE_3D_BLACK, DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE, + DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK, + DEFAULT_RD_TEXTURE_2D_ARRAY_NORMAL, + DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH, DEFAULT_RD_TEXTURE_2D_UINT, DEFAULT_RD_TEXTURE_VRS, DEFAULT_RD_TEXTURE_MAX |