| 1090 | } |
| 1091 | |
| 1092 | RID RenderingDevice::texture_create_shared(const TextureView &p_view, RID p_with_texture) { |
| 1093 | Texture *src_texture = texture_owner.get_or_null(p_with_texture); |
| 1094 | ERR_FAIL_NULL_V(src_texture, RID()); |
| 1095 | |
| 1096 | if (src_texture->owner.is_valid()) { // Ahh this is a share. The RenderingDeviceDriver needs the actual owner. |
| 1097 | p_with_texture = src_texture->owner; |
| 1098 | src_texture = texture_owner.get_or_null(src_texture->owner); |
| 1099 | ERR_FAIL_NULL_V(src_texture, RID()); // This is a bug. |
| 1100 | } |
| 1101 | |
| 1102 | // Create view. |
| 1103 | |
| 1104 | Texture texture = *src_texture; |
| 1105 | texture.slice_trackers = nullptr; |
| 1106 | texture.shared_fallback = nullptr; |
| 1107 | |
| 1108 | RDD::TextureView tv; |
| 1109 | bool create_shared = true; |
| 1110 | bool raw_reintepretation = false; |
| 1111 | if (p_view.format_override == DATA_FORMAT_MAX || p_view.format_override == texture.format) { |
| 1112 | tv.format = texture.format; |
| 1113 | } else { |
| 1114 | ERR_FAIL_INDEX_V(p_view.format_override, DATA_FORMAT_MAX, RID()); |
| 1115 | |
| 1116 | ERR_FAIL_COND_V_MSG(!texture.allowed_shared_formats.has(p_view.format_override), RID(), |
| 1117 | "Format override is not in the list of allowed shareable formats for original texture."); |
| 1118 | tv.format = p_view.format_override; |
| 1119 | create_shared = driver->texture_can_make_shared_with_format(texture.driver_id, p_view.format_override, raw_reintepretation); |
| 1120 | } |
| 1121 | tv.swizzle_r = p_view.swizzle_r; |
| 1122 | tv.swizzle_g = p_view.swizzle_g; |
| 1123 | tv.swizzle_b = p_view.swizzle_b; |
| 1124 | tv.swizzle_a = p_view.swizzle_a; |
| 1125 | |
| 1126 | if (create_shared) { |
| 1127 | texture.driver_id = driver->texture_create_shared(texture.driver_id, tv); |
| 1128 | } else { |
| 1129 | // The regular view will use the same format as the main texture. |
| 1130 | RDD::TextureView regular_view = tv; |
| 1131 | regular_view.format = src_texture->format; |
| 1132 | texture.driver_id = driver->texture_create_shared(texture.driver_id, regular_view); |
| 1133 | |
| 1134 | // Create the independent texture for the alias. |
| 1135 | RDD::TextureFormat alias_format = texture.texture_format(); |
| 1136 | alias_format.format = tv.format; |
| 1137 | alias_format.usage_bits = TEXTURE_USAGE_SAMPLING_BIT | TEXTURE_USAGE_CAN_COPY_TO_BIT; |
| 1138 | |
| 1139 | _texture_check_shared_fallback(src_texture); |
| 1140 | _texture_check_shared_fallback(&texture); |
| 1141 | |
| 1142 | texture.shared_fallback->texture = driver->texture_create(alias_format, tv); |
| 1143 | texture.shared_fallback->raw_reinterpretation = raw_reintepretation; |
| 1144 | texture_memory += driver->texture_get_allocation_size(texture.shared_fallback->texture); |
| 1145 | |
| 1146 | RDG::ResourceTracker *tracker = RDG::resource_tracker_create(); |
| 1147 | tracker->texture_driver_id = texture.shared_fallback->texture; |
| 1148 | tracker->texture_size = Size2i(texture.width, texture.height); |
| 1149 | tracker->texture_subresources = texture.barrier_range(); |
no test coverage detected