| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/templates/paged_array.h" |
| 34 |
#include "core/templates/rid_owner.h" |
| 35 |
#include "servers/rendering/renderer_rd/shaders/canvas_sdf.glsl.gen.h" |
| 36 |
#include "servers/rendering/renderer_rd/storage_rd/forward_id_storage.h" |
| 37 |
#include "servers/rendering/rendering_server_default.h" |
| 38 |
#include "servers/rendering/storage/texture_storage.h" |
| 39 |
#include "servers/rendering/storage/utilities.h" |
| 40 |
|
| 41 |
namespace RendererRD { |
| 42 |
|
| 43 |
class LightStorage; |
| 44 |
class MaterialStorage; |
| 45 |
|
| 46 |
class TextureStorage : public RendererTextureStorage { |
| 47 |
public: |
| 48 |
enum DefaultRDTexture { |
| 49 |
DEFAULT_RD_TEXTURE_WHITE, |
| 50 |
DEFAULT_RD_TEXTURE_BLACK, |
| 51 |
DEFAULT_RD_TEXTURE_TRANSPARENT, |
| 52 |
DEFAULT_RD_TEXTURE_NORMAL, |
| 53 |
DEFAULT_RD_TEXTURE_ANISO, |
| 54 |
DEFAULT_RD_TEXTURE_DEPTH, |
| 55 |
DEFAULT_RD_TEXTURE_MULTIMESH_BUFFER, |
| 56 |
DEFAULT_RD_TEXTURE_CUBEMAP_BLACK, |
| 57 |
DEFAULT_RD_TEXTURE_CUBEMAP_ARRAY_BLACK, |
| 58 |
DEFAULT_RD_TEXTURE_CUBEMAP_WHITE, |
| 59 |
DEFAULT_RD_TEXTURE_CUBEMAP_ARRAY_WHITE, |
| 60 |
DEFAULT_RD_TEXTURE_CUBEMAP_TRANSPARENT, |
| 61 |
DEFAULT_RD_TEXTURE_CUBEMAP_ARRAY_TRANSPARENT, |
| 62 |
DEFAULT_RD_TEXTURE_3D_WHITE, |
| 63 |
DEFAULT_RD_TEXTURE_3D_BLACK, |
| 64 |
DEFAULT_RD_TEXTURE_3D_TRANSPARENT, |
| 65 |
DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE, |
| 66 |
DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK, |
| 67 |
DEFAULT_RD_TEXTURE_2D_ARRAY_TRANSPARENT, |
| 68 |
DEFAULT_RD_TEXTURE_2D_ARRAY_NORMAL, |
| 69 |
DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH, |
| 70 |
DEFAULT_RD_TEXTURE_2D_UINT, |
| 71 |
DEFAULT_RD_TEXTURE_VRS, |
| 72 |
DEFAULT_RD_TEXTURE_MAX |
| 73 |
}; |
| 74 |
|
| 75 |
enum TextureType { |
| 76 |
TYPE_2D, |
| 77 |
TYPE_LAYERED, |
| 78 |
TYPE_3D |
| 79 |
}; |
| 80 |
|
| 81 |
struct CanvasTextureInfo { |
| 82 |
RID diffuse; |
| 83 |
RID normal; |
| 84 |
RID specular; |
| 85 |
RID sampler; |
| 86 |
Size2i size; |
| 87 |
Color specular_color; |
| 88 |
|
| 89 |
bool use_normal = false; |
| 90 |
bool use_specular = false; |
| 91 |
|
| 92 |
_FORCE_INLINE_ bool is_valid() const { return diffuse.is_valid(); } |
| 93 |
_FORCE_INLINE_ bool is_null() const { return diffuse.is_null(); } |
| 94 |
}; |
| 95 |
|
| 96 |
typedef void (*InvalidationCallback)(bool p_deleted, void *p_userdata); |
| 97 |
|
| 98 |
private: |
| 99 |
friend class LightStorage; |
| 100 |
friend class MaterialStorage; |
| 101 |
|
| 102 |
static TextureStorage *singleton; |
| 103 |
|
| 104 |
RID default_rd_textures[DEFAULT_RD_TEXTURE_MAX]; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
struct CanvasTextureCache { |
| 109 |
RID diffuse; |
| 110 |
RID normal; |
| 111 |
RID specular; |
| 112 |
}; |
| 113 |
|
| 114 |
class CanvasTexture { |
| 115 |
public: |
| 116 |
RID diffuse; |
| 117 |
RID normal_map; |
| 118 |
RID specular; |
| 119 |
Color specular_color = Color(1, 1, 1, 1); |
| 120 |
float shininess = 1.0; |
| 121 |
|
| 122 |
RS::CanvasItemTextureFilter texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT; |
| 123 |
RS::CanvasItemTextureRepeat texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT; |
| 124 |
CanvasTextureCache info_cache[2]; |
| 125 |
|
| 126 |
InvalidationCallback invalidated_callback = nullptr; |
| 127 |
void *invalidated_callback_userdata = nullptr; |
| 128 |
|
| 129 |
Size2i size_cache = Size2i(1, 1); |
| 130 |
bool use_normal_cache = false; |
| 131 |
bool use_specular_cache = false; |
| 132 |
|
| 133 |
void clear_cache(); |
| 134 |
~CanvasTexture(); |
| 135 |
}; |
| 136 |
|
| 137 |
RID_Owner<CanvasTexture, true> canvas_texture_owner; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
struct RenderTarget; |
| 142 |
|
| 143 |
class Texture { |
| 144 |
public: |
| 145 |
TextureType type; |
| 146 |
RS::TextureLayeredType layered_type = RS::TEXTURE_LAYERED_2D_ARRAY; |
| 147 |
|
| 148 |
RenderingDevice::TextureType rd_type; |
| 149 |
RID rd_texture; |
| 150 |
RID rd_texture_srgb; |
| 151 |
RenderingDevice::DataFormat rd_format; |
| 152 |
RenderingDevice::DataFormat rd_format_srgb; |
| 153 |
|
| 154 |
RD::TextureView rd_view; |
| 155 |
|
| 156 |
Image::Format format; |
| 157 |
Image::Format validated_format; |
| 158 |
|
| 159 |
int width; |
| 160 |
int height; |
| 161 |
int depth; |
| 162 |
int layers; |
| 163 |
int mipmaps; |
| 164 |
|
| 165 |
int height_2d; |
| 166 |
int width_2d; |
| 167 |
|
| 168 |
struct BufferSlice3D { |
| 169 |
Size2i size; |
| 170 |
uint32_t offset = 0; |
| 171 |
uint32_t buffer_size = 0; |
| 172 |
}; |
| 173 |
Vector<BufferSlice3D> buffer_slices_3d; |
| 174 |
uint32_t buffer_size_3d = 0; |
| 175 |
|
| 176 |
RenderTarget *render_target = nullptr; |
| 177 |
bool is_render_target; |
| 178 |
bool is_proxy; |
| 179 |
|
| 180 |
Ref<Image> image_cache_2d; |
| 181 |
String path; |
| 182 |
|
| 183 |
RID proxy_to; |
| 184 |
Vector<RID> proxies; |
| 185 |
|
| 186 |
HashSet<RID> lightmap_users; |
| 187 |
|
| 188 |
RS::TextureDetectCallback detect_3d_callback = nullptr; |
| 189 |
void *detect_3d_callback_ud = nullptr; |
| 190 |
|
| 191 |
RS::TextureDetectCallback detect_normal_callback = nullptr; |
| 192 |
void *detect_normal_callback_ud = nullptr; |
| 193 |
|
| 194 |
RS::TextureDetectRoughnessCallback detect_roughness_callback = nullptr; |
| 195 |
void *detect_roughness_callback_ud = nullptr; |
| 196 |
|
| 197 |
CanvasTexture *canvas_texture = nullptr; |
| 198 |
|
| 199 |
void cleanup(); |
| 200 |
}; |
| 201 |
|
| 202 |
|
| 203 |
mutable RID_Owner<Texture, true> texture_owner; |
| 204 |
Texture *get_texture(RID p_rid) { return texture_owner.get_or_null(p_rid); } |
| 205 |
|
| 206 |
struct TextureToRDFormat { |
| 207 |
RD::DataFormat format; |
| 208 |
RD::DataFormat format_srgb; |
| 209 |
RD::TextureSwizzle swizzle_r; |
| 210 |
RD::TextureSwizzle swizzle_g; |
| 211 |
RD::TextureSwizzle swizzle_b; |
| 212 |
RD::TextureSwizzle swizzle_a; |
| 213 |
TextureToRDFormat() { |
| 214 |
format = RD::DATA_FORMAT_MAX; |
| 215 |
format_srgb = RD::DATA_FORMAT_MAX; |
| 216 |
swizzle_r = RD::TEXTURE_SWIZZLE_R; |
| 217 |
swizzle_g = RD::TEXTURE_SWIZZLE_G; |
| 218 |
swizzle_b = RD::TEXTURE_SWIZZLE_B; |
| 219 |
swizzle_a = RD::TEXTURE_SWIZZLE_A; |
| 220 |
} |
| 221 |
}; |
| 222 |
|
| 223 |
Ref<Image> _validate_texture_format(const Ref<Image> &p_image, TextureToRDFormat &r_format); |
| 224 |
void _texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0, bool p_immediate = false); |
| 225 |
|
| 226 |
struct TextureFromRDFormat { |
| 227 |
Image::Format image_format; |
| 228 |
RD::DataFormat rd_format; |
| 229 |
RD::DataFormat rd_format_srgb; |
| 230 |
RD::TextureSwizzle swizzle_r; |
| 231 |
RD::TextureSwizzle swizzle_g; |
| 232 |
RD::TextureSwizzle swizzle_b; |
| 233 |
RD::TextureSwizzle swizzle_a; |
| 234 |
TextureFromRDFormat() { |
| 235 |
image_format = Image::FORMAT_MAX; |
| 236 |
rd_format = RD::DATA_FORMAT_MAX; |
| 237 |
rd_format_srgb = RD::DATA_FORMAT_MAX; |
| 238 |
swizzle_r = RD::TEXTURE_SWIZZLE_R; |
| 239 |
swizzle_g = RD::TEXTURE_SWIZZLE_G; |
| 240 |
swizzle_b = RD::TEXTURE_SWIZZLE_B; |
| 241 |
swizzle_a = RD::TEXTURE_SWIZZLE_A; |
| 242 |
} |
| 243 |
}; |
| 244 |
|
| 245 |
void _texture_format_from_rd(RD::DataFormat p_rd_format, TextureFromRDFormat &r_format); |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
struct DecalAtlas { |
| 250 |
struct Texture { |
| 251 |
int panorama_to_dp_users; |
| 252 |
int users; |
| 253 |
Rect2 uv_rect; |
| 254 |
}; |
| 255 |
|
| 256 |
struct SortItem { |
| 257 |
RID texture; |
| 258 |
Size2i pixel_size; |
| 259 |
Size2i size; |
| 260 |
Point2i pos; |
| 261 |
|
| 262 |
bool operator<(const SortItem &p_item) const { |
| 263 |
|
| 264 |
if (size.height == p_item.size.height) { |
| 265 |
return size.width > p_item.size.width; |
| 266 |
} else { |
| 267 |
return size.height > p_item.size.height; |
| 268 |
} |
| 269 |
} |
| 270 |
}; |
| 271 |
|
| 272 |
HashMap<RID, Texture> textures; |
| 273 |
bool dirty = true; |
| 274 |
int mipmaps = 5; |
| 275 |
|
| 276 |
RID texture; |
| 277 |
RID texture_srgb; |
| 278 |
struct MipMap { |
| 279 |
RID fb; |
| 280 |
RID texture; |
| 281 |
Size2i size; |
| 282 |
}; |
| 283 |
Vector<MipMap> texture_mipmaps; |
| 284 |
|
| 285 |
Size2i size; |
| 286 |
} decal_atlas; |
| 287 |
|
| 288 |
struct Decal { |
| 289 |
Vector3 size = Vector3(2, 2, 2); |
| 290 |
RID textures[RS::DECAL_TEXTURE_MAX]; |
| 291 |
float emission_energy = 1.0; |
| 292 |
float albedo_mix = 1.0; |
| 293 |
Color modulate = Color(1, 1, 1, 1); |
| 294 |
uint32_t cull_mask = (1 << 20) - 1; |
| 295 |
float upper_fade = 0.3; |
| 296 |
float lower_fade = 0.3; |
| 297 |
bool distance_fade = false; |
| 298 |
float distance_fade_begin = 40.0; |
| 299 |
float distance_fade_length = 10.0; |
| 300 |
float normal_fade = 0.0; |
| 301 |
|
| 302 |
Dependency dependency; |
| 303 |
}; |
| 304 |
|
| 305 |
mutable RID_Owner<Decal, true> decal_owner; |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
struct DecalInstance { |
| 310 |
RID decal; |
| 311 |
Transform3D transform; |
| 312 |
float sorting_offset = 0.0; |
| 313 |
uint32_t cull_mask = 0; |
| 314 |
RendererRD::ForwardID forward_id = -1; |
| 315 |
}; |
| 316 |
|
| 317 |
mutable RID_Owner<DecalInstance> decal_instance_owner; |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
struct DecalData { |
| 322 |
float xform[16]; |
| 323 |
float inv_extents[3]; |
| 324 |
float albedo_mix; |
| 325 |
float albedo_rect[4]; |
| 326 |
float normal_rect[4]; |
| 327 |
float orm_rect[4]; |
| 328 |
float emission_rect[4]; |
| 329 |
float modulate[4]; |
| 330 |
float emission_energy; |
| 331 |
uint32_t mask; |
| 332 |
float upper_fade; |
| 333 |
float lower_fade; |
| 334 |
float normal_xform[12]; |
| 335 |
float normal[3]; |
| 336 |
float normal_fade; |
| 337 |
}; |
| 338 |
|
| 339 |
struct DecalInstanceSort { |
| 340 |
float depth; |
| 341 |
DecalInstance *decal_instance; |
| 342 |
Decal *decal; |
| 343 |
bool operator<(const DecalInstanceSort &p_sort) const { |
| 344 |
return depth < p_sort.depth; |
| 345 |
} |
| 346 |
}; |
| 347 |
|
| 348 |
uint32_t max_decals = 0; |
| 349 |
uint32_t decal_count = 0; |
| 350 |
DecalData *decals = nullptr; |
| 351 |
DecalInstanceSort *decal_sort = nullptr; |
| 352 |
RID decal_buffer; |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
struct RenderTarget { |
| 357 |
Size2i size; |
| 358 |
uint32_t view_count; |
| 359 |
RID color; |
| 360 |
Vector<RID> color_slices; |
| 361 |
RID color_multisample; |
| 362 |
|
| 363 |
RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED; |
| 364 |
bool msaa_needs_resolve = false; |
| 365 |
|
| 366 |
|
| 367 |
RD::DataFormat color_format = RD::DATA_FORMAT_R4G4_UNORM_PACK8; |
| 368 |
RD::DataFormat color_format_srgb = RD::DATA_FORMAT_R4G4_UNORM_PACK8; |
| 369 |
Image::Format image_format = Image::FORMAT_L8; |
| 370 |
|
| 371 |
bool is_transparent = false; |
| 372 |
bool use_hdr = false; |
| 373 |
bool use_debanding = false; |
| 374 |
|
| 375 |
bool sdf_enabled = false; |
| 376 |
|
| 377 |
RID backbuffer; |
| 378 |
RID backbuffer_fb; |
| 379 |
RID backbuffer_mipmap0; |
| 380 |
|
| 381 |
Vector<RID> backbuffer_mipmaps; |
| 382 |
|
| 383 |
RID framebuffer_uniform_set; |
| 384 |
RID backbuffer_uniform_set; |
| 385 |
|
| 386 |
RID sdf_buffer_write; |
| 387 |
RID sdf_buffer_write_fb; |
| 388 |
RID sdf_buffer_process[2]; |
| 389 |
RID sdf_buffer_read; |
| 390 |
RID sdf_buffer_process_uniform_sets[2]; |
| 391 |
RS::ViewportSDFOversize sdf_oversize = RS::VIEWPORT_SDF_OVERSIZE_120_PERCENT; |
| 392 |
RS::ViewportSDFScale sdf_scale = RS::VIEWPORT_SDF_SCALE_50_PERCENT; |
| 393 |
Size2i process_size; |
| 394 |
|
| 395 |
|
| 396 |
RS::ViewportVRSMode vrs_mode = RS::VIEWPORT_VRS_DISABLED; |
| 397 |
RS::ViewportVRSUpdateMode vrs_update_mode = RS::VIEWPORT_VRS_UPDATE_ONCE; |
| 398 |
RID vrs_texture; |
| 399 |
|
| 400 |
Rect2i render_region; |
| 401 |
|
| 402 |
|
| 403 |
struct RTOverridden { |
| 404 |
RID color; |
| 405 |
RID depth; |
| 406 |
RID velocity; |
| 407 |
RID velocity_depth; |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
struct SliceKey { |
| 417 |
RID rid; |
| 418 |
uint32_t layer = 0; |
| 419 |
|
| 420 |
bool operator==(const SliceKey &p_val) const { |
| 421 |
return (rid == p_val.rid) && (layer == p_val.layer); |
| 422 |
} |
| 423 |
|
| 424 |
static uint32_t hash(const SliceKey &p_val) { |
| 425 |
uint32_t h = hash_one_uint64(p_val.rid.get_id()); |
| 426 |
h = hash_murmur3_one_32(p_val.layer, h); |
| 427 |
return hash_fmix32(h); |
| 428 |
} |
| 429 |
|
| 430 |
SliceKey() {} |
| 431 |
SliceKey(RID p_rid, uint32_t p_layer) { |
| 432 |
rid = p_rid; |
| 433 |
layer = p_layer; |
| 434 |
} |
| 435 |
}; |
| 436 |
|
| 437 |
mutable HashMap<SliceKey, RID, SliceKey> cached_slices; |
| 438 |
} overridden; |
| 439 |
|
| 440 |
|
| 441 |
RID texture; |
| 442 |
bool was_used; |
| 443 |
|
| 444 |
|
| 445 |
bool clear_requested; |
| 446 |
Color clear_color; |
| 447 |
|
| 448 |
RID get_framebuffer(); |
| 449 |
}; |
| 450 |
|
| 451 |
mutable RID_Owner<RenderTarget> render_target_owner; |
| 452 |
RenderTarget *get_render_target(RID p_rid) const { return render_target_owner.get_or_null(p_rid); } |
| 453 |
|
| 454 |
void _clear_render_target(RenderTarget *rt); |
| 455 |
void _update_render_target(RenderTarget *rt); |
| 456 |
void _create_render_target_backbuffer(RenderTarget *rt); |
| 457 |
void _render_target_allocate_sdf(RenderTarget *rt); |
| 458 |
void _render_target_clear_sdf(RenderTarget *rt); |
| 459 |
Rect2i _render_target_get_sdf_rect(const RenderTarget *rt) const; |
| 460 |
|
| 461 |
struct RenderTargetSDF { |
| 462 |
enum { |
| 463 |
SHADER_LOAD, |
| 464 |
SHADER_LOAD_SHRINK, |
| 465 |
SHADER_PROCESS, |
| 466 |
SHADER_PROCESS_OPTIMIZED, |
| 467 |
SHADER_STORE, |
| 468 |
SHADER_STORE_SHRINK, |
| 469 |
SHADER_MAX |
| 470 |
}; |
| 471 |
|
| 472 |
struct PushConstant { |
| 473 |
int32_t size[2]; |
| 474 |
int32_t stride; |
| 475 |
int32_t shift; |
| 476 |
int32_t base_size[2]; |
| 477 |
int32_t pad[2]; |
| 478 |
}; |
| 479 |
|
| 480 |
CanvasSdfShaderRD shader; |
| 481 |
RID shader_version; |
| 482 |
RID pipelines[SHADER_MAX]; |
| 483 |
} rt_sdf; |
| 484 |
|
| 485 |
public: |
| 486 |
static TextureStorage *get_singleton(); |
| 487 |
|
| 488 |
_FORCE_INLINE_ RID texture_rd_get_default(DefaultRDTexture p_texture) { |
| 489 |
return default_rd_textures[p_texture]; |
| 490 |
} |
| 491 |
|
| 492 |
TextureStorage(); |
| 493 |
virtual ~TextureStorage(); |
| 494 |
|
| 495 |
bool free(RID p_rid); |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
bool owns_canvas_texture(RID p_rid) { return canvas_texture_owner.owns(p_rid); } |
| 500 |
|
| 501 |
virtual RID canvas_texture_allocate() override; |
| 502 |
virtual void canvas_texture_initialize(RID p_rid) override; |
| 503 |
virtual void canvas_texture_free(RID p_rid) override; |
| 504 |
|
| 505 |
virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override; |
| 506 |
virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override; |
| 507 |
|
| 508 |
virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override; |
| 509 |
virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override; |
| 510 |
|
| 511 |
CanvasTextureInfo canvas_texture_get_info(RID p_texture, RS::CanvasItemTextureFilter p_base_filter, RS::CanvasItemTextureRepeat p_base_repeat, bool p_use_srgb, bool p_texture_is_data); |
| 512 |
void canvas_texture_set_invalidation_callback(RID p_canvas_texture, InvalidationCallback p_callback, void *p_userdata); |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
bool owns_texture(RID p_rid) const { return texture_owner.owns(p_rid); } |
| 517 |
|
| 518 |
virtual RID texture_allocate() override; |
| 519 |
virtual void texture_free(RID p_rid) override; |
| 520 |
|
| 521 |
virtual void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override; |
| 522 |
virtual void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override; |
| 523 |
virtual void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override; |
| 524 |
virtual void texture_external_initialize(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) override; |
| 525 |
virtual void texture_proxy_initialize(RID p_texture, RID p_base) override; |
| 526 |
|
| 527 |
virtual RID texture_create_from_native_handle(RS::TextureType p_type, Image::Format p_format, uint64_t p_native_handle, int p_width, int p_height, int p_depth, int p_layers = 1, RS::TextureLayeredType p_layered_type = RS::TEXTURE_LAYERED_2D_ARRAY) override; |
| 528 |
|
| 529 |
virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override; |
| 530 |
virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override; |
| 531 |
virtual void texture_external_update(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) override; |
| 532 |
virtual void texture_proxy_update(RID p_proxy, RID p_base) override; |
| 533 |
|
| 534 |
Ref<Image> texture_2d_placeholder; |
| 535 |
Vector<Ref<Image>> texture_2d_array_placeholder; |
| 536 |
Vector<Ref<Image>> cubemap_placeholder; |
| 537 |
Vector<Ref<Image>> texture_3d_placeholder; |
| 538 |
|
| 539 |
|
| 540 |
virtual void texture_2d_placeholder_initialize(RID p_texture) override; |
| 541 |
virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override; |
| 542 |
virtual void texture_3d_placeholder_initialize(RID p_texture) override; |
| 543 |
|
| 544 |
virtual Ref<Image> texture_2d_get(RID p_texture) const override; |
| 545 |
virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override; |
| 546 |
virtual Vector<Ref<Image>> texture_3d_get(RID p_texture) const override; |
| 547 |
|
| 548 |
virtual void texture_replace(RID p_texture, RID p_by_texture) override; |
| 549 |
virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) override; |
| 550 |
|
| 551 |
virtual void texture_set_path(RID p_texture, const String &p_path) override; |
| 552 |
virtual String texture_get_path(RID p_texture) const override; |
| 553 |
|
| 554 |
virtual Image::Format texture_get_format(RID p_texture) const override; |
| 555 |
|
| 556 |
virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override; |
| 557 |
virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override; |
| 558 |
virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override; |
| 559 |
|
| 560 |
virtual void texture_debug_usage(List<RS::TextureInfo> *r_info) override; |
| 561 |
|
| 562 |
virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override; |
| 563 |
|
| 564 |
virtual Size2 texture_size_with_proxy(RID p_proxy) override; |
| 565 |
|
| 566 |
virtual void texture_rd_initialize(RID p_texture, const RID &p_rd_texture, const RS::TextureLayeredType p_layer_type = RS::TEXTURE_LAYERED_2D_ARRAY) override; |
| 567 |
virtual RID texture_get_rd_texture(RID p_texture, bool p_srgb = false) const override; |
| 568 |
virtual uint64_t texture_get_native_handle(RID p_texture, bool p_srgb = false) const override; |
| 569 |
|
| 570 |
|
| 571 |
_FORCE_INLINE_ TextureType texture_get_type(RID p_texture) { |
| 572 |
RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture); |
| 573 |
if (tex == nullptr) { |
| 574 |
return TYPE_2D; |
| 575 |
} |
| 576 |
|
| 577 |
return tex->type; |
| 578 |
} |
| 579 |
|
| 580 |
_FORCE_INLINE_ int texture_get_layers(RID p_texture) { |
| 581 |
RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture); |
| 582 |
if (tex == nullptr) { |
| 583 |
return 1; |
| 584 |
} |
| 585 |
|
| 586 |
return tex->layers; |
| 587 |
} |
| 588 |
|
| 589 |
_FORCE_INLINE_ Size2i texture_2d_get_size(RID p_texture) { |
| 590 |
if (p_texture.is_null()) { |
| 591 |
return Size2i(); |
| 592 |
} |
| 593 |
RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture); |
| 594 |
|
| 595 |
if (!tex) { |
| 596 |
return Size2i(); |
| 597 |
} |
| 598 |
return Size2i(tex->width_2d, tex->height_2d); |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
void update_decal_atlas(); |
| 604 |
|
| 605 |
bool owns_decal(RID p_rid) const { return decal_owner.owns(p_rid); } |
| 606 |
|
| 607 |
RID decal_atlas_get_texture() const; |
| 608 |
RID decal_atlas_get_texture_srgb() const; |
| 609 |
_FORCE_INLINE_ Rect2 decal_atlas_get_texture_rect(RID p_texture) { |
| 610 |
DecalAtlas::Texture *t = decal_atlas.textures.getptr(p_texture); |
| 611 |
if (!t) { |
| 612 |
return Rect2(); |
| 613 |
} |
| 614 |
|
| 615 |
return t->uv_rect; |
| 616 |
} |
| 617 |
|
| 618 |
virtual RID decal_allocate() override; |
| 619 |
virtual void decal_initialize(RID p_decal) override; |
| 620 |
virtual void decal_free(RID p_rid) override; |
| 621 |
|
| 622 |
virtual void decal_set_size(RID p_decal, const Vector3 &p_size) override; |
| 623 |
virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override; |
| 624 |
virtual void decal_set_emission_energy(RID p_decal, float p_energy) override; |
| 625 |
virtual void decal_set_albedo_mix(RID p_decal, float p_mix) override; |
| 626 |
virtual void decal_set_modulate(RID p_decal, const Color &p_modulate) override; |
| 627 |
virtual void decal_set_cull_mask(RID p_decal, uint32_t p_layers) override; |
| 628 |
virtual void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length) override; |
| 629 |
virtual void decal_set_fade(RID p_decal, float p_above, float p_below) override; |
| 630 |
virtual void decal_set_normal_fade(RID p_decal, float p_fade) override; |
| 631 |
|
| 632 |
void decal_atlas_mark_dirty_on_texture(RID p_texture); |
| 633 |
void decal_atlas_remove_texture(RID p_texture); |
| 634 |
|
| 635 |
virtual void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override; |
| 636 |
virtual void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override; |
| 637 |
|
| 638 |
_FORCE_INLINE_ Vector3 decal_get_size(RID p_decal) { |
| 639 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 640 |
return decal->size; |
| 641 |
} |
| 642 |
|
| 643 |
_FORCE_INLINE_ RID decal_get_texture(RID p_decal, RS::DecalTexture p_texture) { |
| 644 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 645 |
return decal->textures[p_texture]; |
| 646 |
} |
| 647 |
|
| 648 |
_FORCE_INLINE_ Color decal_get_modulate(RID p_decal) { |
| 649 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 650 |
return decal->modulate; |
| 651 |
} |
| 652 |
|
| 653 |
_FORCE_INLINE_ float decal_get_emission_energy(RID p_decal) { |
| 654 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 655 |
return decal->emission_energy; |
| 656 |
} |
| 657 |
|
| 658 |
_FORCE_INLINE_ float decal_get_albedo_mix(RID p_decal) { |
| 659 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 660 |
return decal->albedo_mix; |
| 661 |
} |
| 662 |
|
| 663 |
_FORCE_INLINE_ uint32_t decal_get_cull_mask(RID p_decal) { |
| 664 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 665 |
return decal->cull_mask; |
| 666 |
} |
| 667 |
|
| 668 |
_FORCE_INLINE_ float decal_get_upper_fade(RID p_decal) { |
| 669 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 670 |
return decal->upper_fade; |
| 671 |
} |
| 672 |
|
| 673 |
_FORCE_INLINE_ float decal_get_lower_fade(RID p_decal) { |
| 674 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 675 |
return decal->lower_fade; |
| 676 |
} |
| 677 |
|
| 678 |
_FORCE_INLINE_ float decal_get_normal_fade(RID p_decal) { |
| 679 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 680 |
return decal->normal_fade; |
| 681 |
} |
| 682 |
|
| 683 |
_FORCE_INLINE_ bool decal_is_distance_fade_enabled(RID p_decal) { |
| 684 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 685 |
return decal->distance_fade; |
| 686 |
} |
| 687 |
|
| 688 |
_FORCE_INLINE_ float decal_get_distance_fade_begin(RID p_decal) { |
| 689 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 690 |
return decal->distance_fade_begin; |
| 691 |
} |
| 692 |
|
| 693 |
_FORCE_INLINE_ float decal_get_distance_fade_length(RID p_decal) { |
| 694 |
const Decal *decal = decal_owner.get_or_null(p_decal); |
| 695 |
return decal->distance_fade_length; |
| 696 |
} |
| 697 |
|
| 698 |
virtual AABB decal_get_aabb(RID p_decal) const override; |
| 699 |
virtual uint32_t decal_get_cull_mask(RID p_decal) const override; |
| 700 |
Dependency *decal_get_dependency(RID p_decal); |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
bool owns_decal_instance(RID p_rid) const { return decal_instance_owner.owns(p_rid); } |
| 705 |
|
| 706 |
virtual RID decal_instance_create(RID p_decal) override; |
| 707 |
virtual void decal_instance_free(RID p_decal_instance) override; |
| 708 |
virtual void decal_instance_set_transform(RID p_decal_instance, const Transform3D &p_transform) override; |
| 709 |
virtual void decal_instance_set_sorting_offset(RID p_decal_instance, float p_sorting_offset) override; |
| 710 |
|
| 711 |
_FORCE_INLINE_ RID decal_instance_get_base(RID p_decal_instance) const { |
| 712 |
DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance); |
| 713 |
return di->decal; |
| 714 |
} |
| 715 |
|
| 716 |
_FORCE_INLINE_ RendererRD::ForwardID decal_instance_get_forward_id(RID p_decal_instance) const { |
| 717 |
DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance); |
| 718 |
return di->forward_id; |
| 719 |
} |
| 720 |
|
| 721 |
_FORCE_INLINE_ Transform3D decal_instance_get_transform(RID p_decal_instance) const { |
| 722 |
DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance); |
| 723 |
return di->transform; |
| 724 |
} |
| 725 |
|
| 726 |
_FORCE_INLINE_ ForwardID decal_instance_get_forward_id(RID p_decal_instance) { |
| 727 |
DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance); |
| 728 |
return di->forward_id; |
| 729 |
} |
| 730 |
|
| 731 |
_FORCE_INLINE_ void decal_instance_set_cullmask(RID p_decal_instance, uint32_t p_cull_mask) const { |
| 732 |
DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance); |
| 733 |
di->cull_mask = p_cull_mask; |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
void free_decal_data(); |
| 739 |
void set_max_decals(const uint32_t p_max_decals); |
| 740 |
RID get_decal_buffer() { return decal_buffer; } |
| 741 |
void update_decal_buffer(const PagedArray<RID> &p_decals, const Transform3D &p_camera_xform); |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
bool owns_render_target(RID p_rid) const { return render_target_owner.owns(p_rid); } |
| 746 |
|
| 747 |
virtual RID render_target_create() override; |
| 748 |
virtual void render_target_free(RID p_rid) override; |
| 749 |
|
| 750 |
virtual void render_target_set_position(RID p_render_target, int p_x, int p_y) override; |
| 751 |
virtual Point2i render_target_get_position(RID p_render_target) const override; |
| 752 |
virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override; |
| 753 |
virtual Size2i render_target_get_size(RID p_render_target) const override; |
| 754 |
virtual void render_target_set_transparent(RID p_render_target, bool p_is_transparent) override; |
| 755 |
virtual bool render_target_get_transparent(RID p_render_target) const override; |
| 756 |
virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override; |
| 757 |
virtual bool render_target_get_direct_to_screen(RID p_render_target) const override; |
| 758 |
virtual bool render_target_was_used(RID p_render_target) const override; |
| 759 |
virtual void render_target_set_as_unused(RID p_render_target) override; |
| 760 |
virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override; |
| 761 |
virtual RS::ViewportMSAA render_target_get_msaa(RID p_render_target) const override; |
| 762 |
virtual void render_target_set_msaa_needs_resolve(RID p_render_target, bool p_needs_resolve) override; |
| 763 |
virtual bool render_target_get_msaa_needs_resolve(RID p_render_target) const override; |
| 764 |
virtual void render_target_do_msaa_resolve(RID p_render_target) override; |
| 765 |
virtual void render_target_set_use_hdr(RID p_render_target, bool p_use_hdr) override; |
| 766 |
virtual bool render_target_is_using_hdr(RID p_render_target) const override; |
| 767 |
virtual void render_target_set_use_debanding(RID p_render_target, bool p_use_debanding) override; |
| 768 |
virtual bool render_target_is_using_debanding(RID p_render_target) const override; |
| 769 |
|
| 770 |
void render_target_copy_to_back_buffer(RID p_render_target, const Rect2i &p_region, bool p_gen_mipmaps); |
| 771 |
void render_target_clear_back_buffer(RID p_render_target, const Rect2i &p_region, const Color &p_color); |
| 772 |
void render_target_gen_back_buffer_mipmaps(RID p_render_target, const Rect2i &p_region); |
| 773 |
RID render_target_get_back_buffer_uniform_set(RID p_render_target, RID p_base_shader); |
| 774 |
|
| 775 |
virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override; |
| 776 |
virtual bool render_target_is_clear_requested(RID p_render_target) override; |
| 777 |
virtual Color render_target_get_clear_request_color(RID p_render_target) override; |
| 778 |
virtual void render_target_disable_clear_request(RID p_render_target) override; |
| 779 |
virtual void render_target_do_clear_request(RID p_render_target) override; |
| 780 |
|
| 781 |
virtual void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) override; |
| 782 |
RID render_target_get_sdf_texture(RID p_render_target); |
| 783 |
RID render_target_get_sdf_framebuffer(RID p_render_target); |
| 784 |
void render_target_sdf_process(RID p_render_target); |
| 785 |
virtual Rect2i render_target_get_sdf_rect(RID p_render_target) const override; |
| 786 |
virtual void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) override; |
| 787 |
bool render_target_is_sdf_enabled(RID p_render_target) const; |
| 788 |
|
| 789 |
virtual void render_target_set_vrs_mode(RID p_render_target, RS::ViewportVRSMode p_mode) override; |
| 790 |
virtual RS::ViewportVRSMode render_target_get_vrs_mode(RID p_render_target) const override; |
| 791 |
virtual void render_target_set_vrs_update_mode(RID p_render_target, RS::ViewportVRSUpdateMode p_mode) override; |
| 792 |
virtual RS::ViewportVRSUpdateMode render_target_get_vrs_update_mode(RID p_render_target) const override; |
| 793 |
virtual void render_target_set_vrs_texture(RID p_render_target, RID p_texture) override; |
| 794 |
virtual RID render_target_get_vrs_texture(RID p_render_target) const override; |
| 795 |
|
| 796 |
virtual void render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture, RID p_velocity_depth_texture) override; |
| 797 |
virtual RID render_target_get_override_color(RID p_render_target) const override; |
| 798 |
virtual RID render_target_get_override_depth(RID p_render_target) const override; |
| 799 |
RID render_target_get_override_depth_slice(RID p_render_target, const uint32_t p_layer) const; |
| 800 |
virtual RID render_target_get_override_velocity(RID p_render_target) const override; |
| 801 |
RID render_target_get_override_velocity_slice(RID p_render_target, const uint32_t p_layer) const; |
| 802 |
virtual RID render_target_get_override_velocity_depth(RID p_render_target) const override; |
| 803 |
|
| 804 |
virtual void render_target_set_render_region(RID p_render_target, const Rect2i &p_render_region) override; |
| 805 |
virtual Rect2i render_target_get_render_region(RID p_render_target) const override; |
| 806 |
|
| 807 |
virtual RID render_target_get_texture(RID p_render_target) override; |
| 808 |
|
| 809 |
virtual void render_target_set_velocity_target_size(RID p_render_target, const Size2i &p_target_size) override {} |
| 810 |
virtual Size2i render_target_get_velocity_target_size(RID p_render_target) const override { return Size2i(0, 0); } |
| 811 |
|
| 812 |
RID render_target_get_rd_framebuffer(RID p_render_target); |
| 813 |
RID render_target_get_rd_texture(RID p_render_target); |
| 814 |
RID render_target_get_rd_texture_slice(RID p_render_target, uint32_t p_layer); |
| 815 |
RID render_target_get_rd_texture_msaa(RID p_render_target); |
| 816 |
RID render_target_get_rd_backbuffer(RID p_render_target); |
| 817 |
RID render_target_get_rd_backbuffer_framebuffer(RID p_render_target); |
| 818 |
|
| 819 |
RID render_target_get_framebuffer_uniform_set(RID p_render_target); |
| 820 |
RID render_target_get_backbuffer_uniform_set(RID p_render_target); |
| 821 |
|
| 822 |
void render_target_set_framebuffer_uniform_set(RID p_render_target, RID p_uniform_set); |
| 823 |
void render_target_set_backbuffer_uniform_set(RID p_render_target, RID p_uniform_set); |
| 824 |
|
| 825 |
static RD::DataFormat render_target_get_color_format(bool p_use_hdr, bool p_srgb); |
| 826 |
static uint32_t render_target_get_color_usage_bits(bool p_msaa); |
| 827 |
}; |
| 828 |
|
| 829 |
} |