diff options
author | Juan Linietsky <reduzio@gmail.com> | 2019-06-11 15:43:37 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-02-11 11:53:26 +0100 |
commit | 3f335ce3d446372eeb9ed87f7e117099c4d2dd6a (patch) | |
tree | 669db7ddb21f328215a9c26e9bdaf2565db8c853 /servers | |
parent | 9ffe57a10eecf79ab8df2f0497d0387383755df3 (diff) |
Texture refactor
-Texture renamed to Texture2D
-TextureLayered as base now inherits 2Darray, cubemap and cubemap array
-Removed all references to flags in textures (they will go in the shader)
-Texture3D gone for now (will come back later done properly)
-Create base rasterizer for RenderDevice, RasterizerRD
Diffstat (limited to 'servers')
23 files changed, 1022 insertions, 201 deletions
diff --git a/servers/camera/camera_feed.cpp b/servers/camera/camera_feed.cpp index f58a8bfaaa..e8537950ec 100644 --- a/servers/camera/camera_feed.cpp +++ b/servers/camera/camera_feed.cpp @@ -29,9 +29,12 @@ /*************************************************************************/ #include "camera_feed.h" + #include "servers/visual_server.h" void CameraFeed::_bind_methods() { +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 // The setters prefixed with _ are only exposed so we can have feeds through GDNative! // They should not be called by the end user. @@ -51,7 +54,6 @@ void CameraFeed::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_RGB_img", "rgb_img"), &CameraFeed::set_RGB_img); ClassDB::bind_method(D_METHOD("_set_YCbCr_img", "ycbcr_img"), &CameraFeed::set_YCbCr_img); - ClassDB::bind_method(D_METHOD("_set_YCbCr_imgs", "y_img", "cbcr_img"), &CameraFeed::set_YCbCr_imgs); ClassDB::bind_method(D_METHOD("_allocate_texture", "width", "height", "format", "texture_type", "data_type"), &CameraFeed::allocate_texture); ADD_GROUP("Feed", "feed_"); @@ -66,6 +68,7 @@ void CameraFeed::_bind_methods() { BIND_ENUM_CONSTANT(FEED_UNSPECIFIED); BIND_ENUM_CONSTANT(FEED_FRONT); BIND_ENUM_CONSTANT(FEED_BACK); +#endif } int CameraFeed::get_id() const { @@ -142,10 +145,13 @@ CameraFeed::CameraFeed() { position = CameraFeed::FEED_UNSPECIFIED; transform = Transform2D(1.0, 0.0, 0.0, -1.0, 0.0, 1.0); +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 // create a texture object VisualServer *vs = VisualServer::get_singleton(); texture[CameraServer::FEED_Y_IMAGE] = vs->texture_create(); // also used for RGBA texture[CameraServer::FEED_CBCR_IMAGE] = vs->texture_create(); +#endif } CameraFeed::CameraFeed(String p_name, FeedPosition p_position) { @@ -159,20 +165,28 @@ CameraFeed::CameraFeed(String p_name, FeedPosition p_position) { position = p_position; transform = Transform2D(1.0, 0.0, 0.0, -1.0, 0.0, 1.0); +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 // create a texture object VisualServer *vs = VisualServer::get_singleton(); texture[CameraServer::FEED_Y_IMAGE] = vs->texture_create(); // also used for RGBA texture[CameraServer::FEED_CBCR_IMAGE] = vs->texture_create(); +#endif } CameraFeed::~CameraFeed() { +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 // Free our textures VisualServer *vs = VisualServer::get_singleton(); vs->free(texture[CameraServer::FEED_Y_IMAGE]); vs->free(texture[CameraServer::FEED_CBCR_IMAGE]); +#endif } void CameraFeed::set_RGB_img(Ref<Image> p_rgb_img) { +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 if (active) { VisualServer *vs = VisualServer::get_singleton(); @@ -190,9 +204,12 @@ void CameraFeed::set_RGB_img(Ref<Image> p_rgb_img) { vs->texture_set_data(texture[CameraServer::FEED_RGBA_IMAGE], p_rgb_img); datatype = CameraFeed::FEED_RGB; } +#endif } void CameraFeed::set_YCbCr_img(Ref<Image> p_ycbcr_img) { +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 if (active) { VisualServer *vs = VisualServer::get_singleton(); @@ -210,9 +227,12 @@ void CameraFeed::set_YCbCr_img(Ref<Image> p_ycbcr_img) { vs->texture_set_data(texture[CameraServer::FEED_RGBA_IMAGE], p_ycbcr_img); datatype = CameraFeed::FEED_YCBCR; } +#endif } void CameraFeed::set_YCbCr_imgs(Ref<Image> p_y_img, Ref<Image> p_cbcr_img) { +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 if (active) { VisualServer *vs = VisualServer::get_singleton(); @@ -240,8 +260,11 @@ void CameraFeed::set_YCbCr_imgs(Ref<Image> p_y_img, Ref<Image> p_cbcr_img) { vs->texture_set_data(texture[CameraServer::FEED_CBCR_IMAGE], p_cbcr_img); datatype = CameraFeed::FEED_YCBCR_SEP; } +#endif } +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 void CameraFeed::allocate_texture(int p_width, int p_height, Image::Format p_format, VisualServer::TextureType p_texture_type, FeedDataType p_data_type) { VisualServer *vs = VisualServer::get_singleton(); @@ -255,6 +278,7 @@ void CameraFeed::allocate_texture(int p_width, int p_height, Image::Format p_for datatype = p_data_type; } +#endif bool CameraFeed::activate_feed() { // nothing to do here diff --git a/servers/camera/camera_feed.h b/servers/camera/camera_feed.h index d5029812c1..b99ded68e4 100644 --- a/servers/camera/camera_feed.h +++ b/servers/camera/camera_feed.h @@ -103,7 +103,10 @@ public: void set_RGB_img(Ref<Image> p_rgb_img); void set_YCbCr_img(Ref<Image> p_ycbcr_img); void set_YCbCr_imgs(Ref<Image> p_y_img, Ref<Image> p_cbcr_img); +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 void allocate_texture(int p_width, int p_height, Image::Format p_format, VisualServer::TextureType p_texture_type, FeedDataType p_data_type); +#endif virtual bool activate_feed(); virtual void deactivate_feed(); diff --git a/servers/visual/SCsub b/servers/visual/SCsub index d730144861..9aa395db70 100644 --- a/servers/visual/SCsub +++ b/servers/visual/SCsub @@ -3,3 +3,5 @@ Import('env') env.add_source_files(env.servers_sources, "*.cpp") + +SConscript("rasterizer/SCsub") diff --git a/servers/visual/rasterizer/SCsub b/servers/visual/rasterizer/SCsub new file mode 100644 index 0000000000..70cd4087bf --- /dev/null +++ b/servers/visual/rasterizer/SCsub @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +Import('env') + +env.add_source_files(env.servers_sources, "*.cpp") + diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer/rasterizer.cpp index 77c716379a..77c716379a 100644 --- a/servers/visual/rasterizer.cpp +++ b/servers/visual/rasterizer/rasterizer.cpp diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer/rasterizer.h index 4d281f27a0..70b9ab18c6 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer/rasterizer.h @@ -60,7 +60,10 @@ public: virtual void environment_set_bg_energy(RID p_env, float p_energy) = 0; virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0; virtual void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0) = 0; +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) = 0; +#endif virtual void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) = 0; virtual void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) = 0; @@ -176,56 +179,44 @@ class RasterizerStorage { public: /* TEXTURE API */ - virtual RID texture_create() = 0; - virtual void texture_allocate(RID p_texture, - int p_width, - int p_height, - int p_depth_3d, - Image::Format p_format, - VS::TextureType p_type, - uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT) = 0; - - virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_level = 0) = 0; - - virtual void texture_set_data_partial(RID p_texture, - const Ref<Image> &p_image, - int src_x, int src_y, - int src_w, int src_h, - int dst_x, int dst_y, - int p_dst_mip, - int p_level = 0) = 0; - - virtual Ref<Image> texture_get_data(RID p_texture, int p_level = 0) const = 0; - virtual void texture_set_flags(RID p_texture, uint32_t p_flags) = 0; - virtual uint32_t texture_get_flags(RID p_texture) const = 0; - virtual Image::Format texture_get_format(RID p_texture) const = 0; - virtual VS::TextureType texture_get_type(RID p_texture) const = 0; - virtual uint32_t texture_get_texid(RID p_texture) const = 0; - virtual uint32_t texture_get_width(RID p_texture) const = 0; - virtual uint32_t texture_get_height(RID p_texture) const = 0; - virtual uint32_t texture_get_depth(RID p_texture) const = 0; - virtual void texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth_3d) = 0; + virtual RID texture_2d_create(const Ref<Image> &p_image) = 0; + virtual RID texture_2d_layered_create(const Vector<Ref<Image> > &p_layers, VS::TextureLayeredType p_layered_type) = 0; + virtual RID texture_3d_create(const Vector<Ref<Image> > &p_slices) = 0; //all slices, then all the mipmaps, must be coherent + + virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) = 0; //mostly used for video and streaming + virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) = 0; + virtual void texture_3d_update(RID p_texture, const Ref<Image> &p_image, int p_depth, int p_mipmap) = 0; + + //these two APIs can be used together or in combination with the others. + virtual RID texture_2d_placeholder_create() = 0; + virtual RID texture_2d_layered_placeholder_create() = 0; + virtual RID texture_3d_placeholder_create() = 0; + + virtual Ref<Image> texture_2d_get(RID p_texture) const = 0; + virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const = 0; + virtual Ref<Image> texture_3d_slice_get(RID p_texture, int p_depth, int p_mipmap) const = 0; + + virtual void texture_replace(RID p_texture, RID p_by_texture) = 0; + virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) = 0; +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 virtual void texture_bind(RID p_texture, uint32_t p_texture_no) = 0; +#endif virtual void texture_set_path(RID p_texture, const String &p_path) = 0; virtual String texture_get_path(RID p_texture) const = 0; - virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable) = 0; + virtual void texture_set_detect_3d_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) = 0; + virtual void texture_set_detect_normal_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) = 0; + virtual void texture_set_detect_roughness_callback(RID p_texture, VS::TextureDetectRoughnessCallback p_callback, void *p_userdata) = 0; virtual void texture_debug_usage(List<VS::TextureInfo> *r_info) = 0; - virtual RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const = 0; - - virtual void texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) = 0; - virtual void texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) = 0; - virtual void texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) = 0; - - virtual void textures_keep_original(bool p_enable) = 0; - virtual void texture_set_proxy(RID p_proxy, RID p_base) = 0; - virtual Size2 texture_size_with_proxy(RID p_texture) const = 0; virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) = 0; + virtual Size2 texture_size_with_proxy(RID p_proxy) const = 0; + /* SKY API */ virtual RID sky_create() = 0; diff --git a/servers/visual/rasterizer/rasterizer_canvas_rd.cpp b/servers/visual/rasterizer/rasterizer_canvas_rd.cpp new file mode 100644 index 0000000000..585647ba1d --- /dev/null +++ b/servers/visual/rasterizer/rasterizer_canvas_rd.cpp @@ -0,0 +1 @@ +#include "rasterizer_canvas_rd.h" diff --git a/servers/visual/rasterizer/rasterizer_canvas_rd.h b/servers/visual/rasterizer/rasterizer_canvas_rd.h new file mode 100644 index 0000000000..898fdb238a --- /dev/null +++ b/servers/visual/rasterizer/rasterizer_canvas_rd.h @@ -0,0 +1,28 @@ +#ifndef RASTERIZER_CANVAS_RD_H +#define RASTERIZER_CANVAS_RD_H + +#include "servers/visual/rasterizer/rasterizer.h" + +class RasterizerCanvasRD : public RasterizerCanvas { +public: + RID light_internal_create() { return RID(); } + void light_internal_update(RID p_rid, Light *p_light) {} + void light_internal_free(RID p_rid) {} + + void canvas_begin(){}; + void canvas_end(){}; + + void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_transform){}; + void canvas_debug_viewport_shadows(Light *p_lights_with_shadow){}; + + void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {} + + void reset_canvas() {} + + void draw_window_margins(int *p_margins, RID *p_margin_textures) {} + + RasterizerCanvasRD() {} + ~RasterizerCanvasRD() {} +}; + +#endif // RASTERIZER_CANVAS_RD_H diff --git a/servers/visual/rasterizer/rasterizer_rd.cpp b/servers/visual/rasterizer/rasterizer_rd.cpp new file mode 100644 index 0000000000..ecbcc2b251 --- /dev/null +++ b/servers/visual/rasterizer/rasterizer_rd.cpp @@ -0,0 +1,7 @@ +#include "rasterizer_rd.h" + +RasterizerRD::RasterizerRD() { + canvas = memnew(RasterizerCanvasRD); + storage = memnew(RasterizerStorageRD); + scene = memnew(RasterizerSceneForwardRD); +} diff --git a/servers/visual/rasterizer/rasterizer_rd.h b/servers/visual/rasterizer/rasterizer_rd.h new file mode 100644 index 0000000000..17ff29c19b --- /dev/null +++ b/servers/visual/rasterizer/rasterizer_rd.h @@ -0,0 +1,49 @@ +#ifndef RASTERIZER_RD_H +#define RASTERIZER_RD_H + +#include "core/os/os.h" +#include "servers/visual/rasterizer/rasterizer.h" +#include "servers/visual/rasterizer/rasterizer_canvas_rd.h" +#include "servers/visual/rasterizer/rasterizer_scene_forward_rd.h" +#include "servers/visual/rasterizer/rasterizer_storage_rd.h" +class RasterizerRD : public Rasterizer { +protected: + RasterizerCanvasRD *canvas; + RasterizerStorageRD *storage; + RasterizerSceneForwardRD *scene; + +public: + RasterizerStorage *get_storage() { return storage; } + RasterizerCanvas *get_canvas() { return canvas; } + RasterizerScene *get_scene() { return scene; } + + void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {} + + void initialize() {} + void begin_frame(double frame_step) {} + void set_current_render_target(RID p_render_target) {} + void restore_render_target(bool p_3d_was_drawn) {} + void clear_render_target(const Color &p_color) {} + void blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen = 0) {} + void output_lens_distorted_to_screen(RID p_render_target, const Rect2 &p_screen_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) {} + void end_frame(bool p_swap_buffers) { OS::get_singleton()->swap_buffers(); } + void finalize() {} + + static Error is_viable() { + return OK; + } + + static Rasterizer *_create_current() { + return memnew(RasterizerRD); + } + + static void make_current() { + _create_func = _create_current; + } + + virtual bool is_low_end() const { return true; } + + RasterizerRD(); + ~RasterizerRD() {} +}; +#endif // RASTERIZER_RD_H diff --git a/servers/visual/rasterizer/rasterizer_scene_forward_rd.cpp b/servers/visual/rasterizer/rasterizer_scene_forward_rd.cpp new file mode 100644 index 0000000000..56d100ba08 --- /dev/null +++ b/servers/visual/rasterizer/rasterizer_scene_forward_rd.cpp @@ -0,0 +1 @@ +#include "rasterizer_scene_forward_rd.h" diff --git a/servers/visual/rasterizer/rasterizer_scene_forward_rd.h b/servers/visual/rasterizer/rasterizer_scene_forward_rd.h new file mode 100644 index 0000000000..03cadb5ba4 --- /dev/null +++ b/servers/visual/rasterizer/rasterizer_scene_forward_rd.h @@ -0,0 +1,85 @@ +#ifndef RASTERIZER_SCENE_FORWARD_RD_H +#define RASTERIZER_SCENE_FORWARD_RD_H + +#include "servers/visual/rasterizer/rasterizer.h" + +class RasterizerSceneForwardRD : public RasterizerScene { +public: + /* SHADOW ATLAS API */ + + RID shadow_atlas_create() { return RID(); } + void shadow_atlas_set_size(RID p_atlas, int p_size) {} + void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) {} + bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) { return false; } + + int get_directional_light_shadow_size(RID p_light_intance) { return 0; } + void set_directional_shadow_count(int p_count) {} + + /* ENVIRONMENT API */ + + RID environment_create() { return RID(); } + + void environment_set_background(RID p_env, VS::EnvironmentBG p_bg) {} + void environment_set_sky(RID p_env, RID p_sky) {} + void environment_set_sky_custom_fov(RID p_env, float p_scale) {} + void environment_set_sky_orientation(RID p_env, const Basis &p_orientation) {} + void environment_set_bg_color(RID p_env, const Color &p_color) {} + void environment_set_bg_energy(RID p_env, float p_energy) {} + void environment_set_canvas_max_layer(RID p_env, int p_max_layer) {} + void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0) {} + + void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) {} + void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) {} + void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) {} + + void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) {} + + void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance, bool p_roughness) {} + void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {} + + void environment_set_tonemap(RID p_env, VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) {} + + void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) {} + + void environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount) {} + void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve) {} + void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve) {} + + bool is_environment(RID p_env) { return false; } + VS::EnvironmentBG environment_get_background(RID p_env) { return VS::ENV_BG_KEEP; } + int environment_get_canvas_max_layer(RID p_env) { return 0; } + + RID light_instance_create(RID p_light) { return RID(); } + void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) {} + void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0) {} + void light_instance_mark_visible(RID p_light_instance) {} + + RID reflection_atlas_create() { return RID(); } + void reflection_atlas_set_size(RID p_ref_atlas, int p_size) {} + void reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv) {} + + RID reflection_probe_instance_create(RID p_probe) { return RID(); } + void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform) {} + void reflection_probe_release_atlas_index(RID p_instance) {} + bool reflection_probe_instance_needs_redraw(RID p_instance) { return false; } + bool reflection_probe_instance_has_reflection(RID p_instance) { return false; } + bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) { return false; } + bool reflection_probe_instance_postprocess_step(RID p_instance) { return true; } + + RID gi_probe_instance_create() { return RID(); } + void gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data) {} + void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform) {} + void gi_probe_instance_set_bounds(RID p_probe, const Vector3 &p_bounds) {} + + void render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {} + void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) {} + + void set_scene_pass(uint64_t p_pass) {} + void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw) {} + + bool free(RID p_rid) { return true; } + + RasterizerSceneForwardRD() {} + ~RasterizerSceneForwardRD() {} +}; +#endif // RASTERIZER_SCENE_FORWARD_RD_H diff --git a/servers/visual/rasterizer/rasterizer_storage_rd.cpp b/servers/visual/rasterizer/rasterizer_storage_rd.cpp new file mode 100644 index 0000000000..bdaaba8d10 --- /dev/null +++ b/servers/visual/rasterizer/rasterizer_storage_rd.cpp @@ -0,0 +1,78 @@ +#include "rasterizer_storage_rd.h" + +RID RasterizerStorageRD::texture_2d_create(const Ref<Image> &p_image) { + + return RID(); +} + +RID RasterizerStorageRD::texture_2d_layered_create(const Vector<Ref<Image> > &p_layers, VS::TextureLayeredType p_layered_type) { + + return RID(); +} +RID RasterizerStorageRD::texture_3d_create(const Vector<Ref<Image> > &p_slices) { + + return RID(); +} + +void RasterizerStorageRD::texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer) { +} +void RasterizerStorageRD::texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer) { +} +void RasterizerStorageRD::texture_3d_update(RID p_texture, const Ref<Image> &p_image, int p_depth, int p_mipmap) { +} + +//these two APIs can be used together or in combination with the others. +RID RasterizerStorageRD::texture_2d_placeholder_create() { + + return RID(); +} +RID RasterizerStorageRD::texture_2d_layered_placeholder_create() { + + return RID(); +} +RID RasterizerStorageRD::texture_3d_placeholder_create() { + + return RID(); +} + +Ref<Image> RasterizerStorageRD::texture_2d_get(RID p_texture) const { + + return Ref<Image>(); +} +Ref<Image> RasterizerStorageRD::texture_2d_layer_get(RID p_texture, int p_layer) const { + + return Ref<Image>(); +} +Ref<Image> RasterizerStorageRD::texture_3d_slice_get(RID p_texture, int p_depth, int p_mipmap) const { + + return Ref<Image>(); +} + +void RasterizerStorageRD::texture_replace(RID p_texture, RID p_by_texture) { +} +void RasterizerStorageRD::texture_set_size_override(RID p_texture, int p_width, int p_height) { +} + +void RasterizerStorageRD::texture_set_path(RID p_texture, const String &p_path) { +} +String RasterizerStorageRD::texture_get_path(RID p_texture) const { + return String(); +} + +void RasterizerStorageRD::texture_set_detect_3d_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) { +} +void RasterizerStorageRD::texture_set_detect_normal_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) { +} +void RasterizerStorageRD::texture_set_detect_roughness_callback(RID p_texture, VS::TextureDetectRoughnessCallback p_callback, void *p_userdata) { +} +void RasterizerStorageRD::texture_debug_usage(List<VS::TextureInfo> *r_info) { +} + +void RasterizerStorageRD::texture_set_proxy(RID p_proxy, RID p_base) { +} +void RasterizerStorageRD::texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) { +} + +Size2 RasterizerStorageRD::texture_size_with_proxy(RID p_proxy) const { + return Size2(); +} diff --git a/servers/visual/rasterizer/rasterizer_storage_rd.h b/servers/visual/rasterizer/rasterizer_storage_rd.h new file mode 100644 index 0000000000..9c41f81fd7 --- /dev/null +++ b/servers/visual/rasterizer/rasterizer_storage_rd.h @@ -0,0 +1,579 @@ +#ifndef RASTERIZER_STORAGE_RD_H +#define RASTERIZER_STORAGE_RD_H + +#include "core/rid_owner.h" +#include "servers/visual/rasterizer/rasterizer.h" + +class RasterizerStorageRD : public RasterizerStorage { +public: + /* TEXTURE API */ + struct RDTexture { + int width; + int height; + uint32_t flags; + Image::Format format; + Ref<Image> image; + String path; + }; + + struct RDSurface { + uint32_t format; + VS::PrimitiveType primitive; + PoolVector<uint8_t> array; + int vertex_count; + PoolVector<uint8_t> index_array; + int index_count; + AABB aabb; + Vector<PoolVector<uint8_t> > blend_shapes; + Vector<AABB> bone_aabbs; + }; + + struct RDMesh { + Vector<RDSurface> surfaces; + int blend_shape_count; + VS::BlendShapeMode blend_shape_mode; + }; + + mutable RID_PtrOwner<RDTexture> texture_owner; + mutable RID_PtrOwner<RDMesh> mesh_owner; + + virtual RID texture_2d_create(const Ref<Image> &p_image); + virtual RID texture_2d_layered_create(const Vector<Ref<Image> > &p_layers, VS::TextureLayeredType p_layered_type); + virtual RID texture_3d_create(const Vector<Ref<Image> > &p_slices); //all slices, then all the mipmaps, must be coherent + + virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); //mostly used for video and streaming + virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); + virtual void texture_3d_update(RID p_texture, const Ref<Image> &p_image, int p_depth, int p_mipmap); + + //these two APIs can be used together or in combination with the others. + virtual RID texture_2d_placeholder_create(); + virtual RID texture_2d_layered_placeholder_create(); + virtual RID texture_3d_placeholder_create(); + + virtual Ref<Image> texture_2d_get(RID p_texture) const; + virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const; + virtual Ref<Image> texture_3d_slice_get(RID p_texture, int p_depth, int p_mipmap) const; + + virtual void texture_replace(RID p_texture, RID p_by_texture); + virtual void texture_set_size_override(RID p_texture, int p_width, int p_height); + + virtual void texture_set_path(RID p_texture, const String &p_path); + virtual String texture_get_path(RID p_texture) const; + + virtual void texture_set_detect_3d_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata); + virtual void texture_set_detect_normal_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata); + virtual void texture_set_detect_roughness_callback(RID p_texture, VS::TextureDetectRoughnessCallback p_callback, void *p_userdata); + + virtual void texture_debug_usage(List<VS::TextureInfo> *r_info); + + virtual void texture_set_proxy(RID p_proxy, RID p_base); + virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable); + + virtual Size2 texture_size_with_proxy(RID p_proxy) const; + + /* SKY API */ + + RID sky_create() { return RID(); } + void sky_set_texture(RID p_sky, RID p_cube_map, int p_radiance_size) {} + + /* SHADER API */ + + RID shader_create() { return RID(); } + + void shader_set_code(RID p_shader, const String &p_code) {} + String shader_get_code(RID p_shader) const { return ""; } + void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {} + + void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {} + RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const { return RID(); } + + /* COMMON MATERIAL API */ + + RID material_create() { return RID(); } + + void material_set_render_priority(RID p_material, int priority) {} + void material_set_shader(RID p_shader_material, RID p_shader) {} + RID material_get_shader(RID p_shader_material) const { return RID(); } + + void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) {} + Variant material_get_param(RID p_material, const StringName &p_param) const { return Variant(); } + Variant material_get_param_default(RID p_material, const StringName &p_param) const { return Variant(); } + + void material_set_line_width(RID p_material, float p_width) {} + + void material_set_next_pass(RID p_material, RID p_next_material) {} + + bool material_is_animated(RID p_material) { return false; } + bool material_casts_shadows(RID p_material) { return false; } + + void material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {} + void material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {} + + /* MESH API */ + + RID mesh_create() { + RDMesh *mesh = memnew(RDMesh); + ERR_FAIL_COND_V(!mesh, RID()); + mesh->blend_shape_count = 0; + mesh->blend_shape_mode = VS::BLEND_SHAPE_MODE_NORMALIZED; + return mesh_owner.make_rid(mesh); + } + + void mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const PoolVector<uint8_t> &p_array, int p_vertex_count, const PoolVector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes = Vector<PoolVector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()) { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND(!m); + + m->surfaces.push_back(RDSurface()); + RDSurface *s = &m->surfaces.write[m->surfaces.size() - 1]; + s->format = p_format; + s->primitive = p_primitive; + s->array = p_array; + s->vertex_count = p_vertex_count; + s->index_array = p_index_array; + s->index_count = p_index_count; + s->aabb = p_aabb; + s->blend_shapes = p_blend_shapes; + s->bone_aabbs = p_bone_aabbs; + } + + void mesh_set_blend_shape_count(RID p_mesh, int p_amount) { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND(!m); + m->blend_shape_count = p_amount; + } + int mesh_get_blend_shape_count(RID p_mesh) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, 0); + return m->blend_shape_count; + } + + void mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode) { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND(!m); + m->blend_shape_mode = p_mode; + } + VS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, VS::BLEND_SHAPE_MODE_NORMALIZED); + return m->blend_shape_mode; + } + + void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const PoolVector<uint8_t> &p_data) {} + + void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) {} + RID mesh_surface_get_material(RID p_mesh, int p_surface) const { return RID(); } + + int mesh_surface_get_array_len(RID p_mesh, int p_surface) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, 0); + + return m->surfaces[p_surface].vertex_count; + } + int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, 0); + + return m->surfaces[p_surface].index_count; + } + + PoolVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, PoolVector<uint8_t>()); + + return m->surfaces[p_surface].array; + } + PoolVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, PoolVector<uint8_t>()); + + return m->surfaces[p_surface].index_array; + } + + uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, 0); + + return m->surfaces[p_surface].format; + } + VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, VS::PRIMITIVE_POINTS); + + return m->surfaces[p_surface].primitive; + } + + AABB mesh_surface_get_aabb(RID p_mesh, int p_surface) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, AABB()); + + return m->surfaces[p_surface].aabb; + } + Vector<PoolVector<uint8_t> > mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, Vector<PoolVector<uint8_t> >()); + + return m->surfaces[p_surface].blend_shapes; + } + Vector<AABB> mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, Vector<AABB>()); + + return m->surfaces[p_surface].bone_aabbs; + } + + void mesh_remove_surface(RID p_mesh, int p_index) { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND(!m); + ERR_FAIL_COND(p_index >= m->surfaces.size()); + + m->surfaces.remove(p_index); + } + int mesh_get_surface_count(RID p_mesh) const { + RDMesh *m = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND_V(!m, 0); + return m->surfaces.size(); + } + + void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) {} + AABB mesh_get_custom_aabb(RID p_mesh) const { return AABB(); } + + AABB mesh_get_aabb(RID p_mesh, RID p_skeleton) const { return AABB(); } + void mesh_clear(RID p_mesh) {} + + /* MULTIMESH API */ + + virtual RID multimesh_create() { return RID(); } + + void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data = VS::MULTIMESH_CUSTOM_DATA_NONE) {} + int multimesh_get_instance_count(RID p_multimesh) const { return 0; } + + void multimesh_set_mesh(RID p_multimesh, RID p_mesh) {} + void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform) {} + void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) {} + void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) {} + void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) {} + + RID multimesh_get_mesh(RID p_multimesh) const { return RID(); } + + Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const { return Transform(); } + Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const { return Transform2D(); } + Color multimesh_instance_get_color(RID p_multimesh, int p_index) const { return Color(); } + Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const { return Color(); } + + void multimesh_set_as_bulk_array(RID p_multimesh, const PoolVector<float> &p_array) {} + + void multimesh_set_visible_instances(RID p_multimesh, int p_visible) {} + int multimesh_get_visible_instances(RID p_multimesh) const { return 0; } + + AABB multimesh_get_aabb(RID p_multimesh) const { return AABB(); } + + /* IMMEDIATE API */ + + RID immediate_create() { return RID(); } + void immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture = RID()) {} + void immediate_vertex(RID p_immediate, const Vector3 &p_vertex) {} + void immediate_normal(RID p_immediate, const Vector3 &p_normal) {} + void immediate_tangent(RID p_immediate, const Plane &p_tangent) {} + void immediate_color(RID p_immediate, const Color &p_color) {} + void immediate_uv(RID p_immediate, const Vector2 &tex_uv) {} + void immediate_uv2(RID p_immediate, const Vector2 &tex_uv) {} + void immediate_end(RID p_immediate) {} + void immediate_clear(RID p_immediate) {} + void immediate_set_material(RID p_immediate, RID p_material) {} + RID immediate_get_material(RID p_immediate) const { return RID(); } + AABB immediate_get_aabb(RID p_immediate) const { return AABB(); } + + /* SKELETON API */ + + RID skeleton_create() { return RID(); } + void skeleton_allocate(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) {} + void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) {} + void skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform &p_world_transform) {} + int skeleton_get_bone_count(RID p_skeleton) const { return 0; } + void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform) {} + Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone) const { return Transform(); } + void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) {} + Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const { return Transform2D(); } + + /* Light API */ + + RID light_create(VS::LightType p_type) { return RID(); } + + RID directional_light_create() { return light_create(VS::LIGHT_DIRECTIONAL); } + RID omni_light_create() { return light_create(VS::LIGHT_OMNI); } + RID spot_light_create() { return light_create(VS::LIGHT_SPOT); } + + void light_set_color(RID p_light, const Color &p_color) {} + void light_set_param(RID p_light, VS::LightParam p_param, float p_value) {} + void light_set_shadow(RID p_light, bool p_enabled) {} + void light_set_shadow_color(RID p_light, const Color &p_color) {} + void light_set_projector(RID p_light, RID p_texture) {} + void light_set_negative(RID p_light, bool p_enable) {} + void light_set_cull_mask(RID p_light, uint32_t p_mask) {} + void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) {} + void light_set_use_gi(RID p_light, bool p_enabled) {} + + void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) {} + void light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail) {} + + void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) {} + void light_directional_set_blend_splits(RID p_light, bool p_enable) {} + bool light_directional_get_blend_splits(RID p_light) const { return false; } + void light_directional_set_shadow_depth_range_mode(RID p_light, VS::LightDirectionalShadowDepthRangeMode p_range_mode) {} + VS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const { return VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE; } + + VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) { return VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL; } + VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) { return VS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID; } + + bool light_has_shadow(RID p_light) const { return false; } + + VS::LightType light_get_type(RID p_light) const { return VS::LIGHT_OMNI; } + AABB light_get_aabb(RID p_light) const { return AABB(); } + float light_get_param(RID p_light, VS::LightParam p_param) { return 0.0; } + Color light_get_color(RID p_light) { return Color(); } + bool light_get_use_gi(RID p_light) { return false; } + uint64_t light_get_version(RID p_light) const { return 0; } + + /* PROBE API */ + + RID reflection_probe_create() { return RID(); } + + void reflection_probe_set_update_mode(RID p_probe, VS::ReflectionProbeUpdateMode p_mode) {} + void reflection_probe_set_intensity(RID p_probe, float p_intensity) {} + void reflection_probe_set_interior_ambient(RID p_probe, const Color &p_ambient) {} + void reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy) {} + void reflection_probe_set_interior_ambient_probe_contribution(RID p_probe, float p_contrib) {} + void reflection_probe_set_max_distance(RID p_probe, float p_distance) {} + void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents) {} + void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) {} + void reflection_probe_set_as_interior(RID p_probe, bool p_enable) {} + void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) {} + void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) {} + void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) {} + void reflection_probe_set_resolution(RID p_probe, int p_resolution) {} + + AABB reflection_probe_get_aabb(RID p_probe) const { return AABB(); } + VS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const { return VisualServer::REFLECTION_PROBE_UPDATE_ONCE; } + uint32_t reflection_probe_get_cull_mask(RID p_probe) const { return 0; } + Vector3 reflection_probe_get_extents(RID p_probe) const { return Vector3(); } + Vector3 reflection_probe_get_origin_offset(RID p_probe) const { return Vector3(); } + float reflection_probe_get_origin_max_distance(RID p_probe) const { return 0.0; } + bool reflection_probe_renders_shadows(RID p_probe) const { return false; } + + void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) {} + void instance_remove_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) {} + + void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {} + void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {} + + /* GI PROBE API */ + + RID gi_probe_create() { return RID(); } + + void gi_probe_set_bounds(RID p_probe, const AABB &p_bounds) {} + AABB gi_probe_get_bounds(RID p_probe) const { return AABB(); } + + void gi_probe_set_cell_size(RID p_probe, float p_range) {} + float gi_probe_get_cell_size(RID p_probe) const { return 0.0; } + + void gi_probe_set_to_cell_xform(RID p_probe, const Transform &p_xform) {} + Transform gi_probe_get_to_cell_xform(RID p_probe) const { return Transform(); } + + void gi_probe_set_dynamic_data(RID p_probe, const PoolVector<int> &p_data) {} + PoolVector<int> gi_probe_get_dynamic_data(RID p_probe) const { + PoolVector<int> p; + return p; + } + + void gi_probe_set_dynamic_range(RID p_probe, int p_range) {} + int gi_probe_get_dynamic_range(RID p_probe) const { return 0; } + + void gi_probe_set_energy(RID p_probe, float p_range) {} + float gi_probe_get_energy(RID p_probe) const { return 0.0; } + + void gi_probe_set_bias(RID p_probe, float p_range) {} + float gi_probe_get_bias(RID p_probe) const { return 0.0; } + + void gi_probe_set_normal_bias(RID p_probe, float p_range) {} + float gi_probe_get_normal_bias(RID p_probe) const { return 0.0; } + + void gi_probe_set_propagation(RID p_probe, float p_range) {} + float gi_probe_get_propagation(RID p_probe) const { return 0.0; } + + void gi_probe_set_interior(RID p_probe, bool p_enable) {} + bool gi_probe_is_interior(RID p_probe) const { return false; } + + void gi_probe_set_compress(RID p_probe, bool p_enable) {} + bool gi_probe_is_compressed(RID p_probe) const { return false; } + + uint32_t gi_probe_get_version(RID p_probe) { return 0; } + + GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const { return GI_PROBE_UNCOMPRESSED; } + RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression) { return RID(); } + void gi_probe_dynamic_data_update(RID p_gi_probe_data, int p_depth_slice, int p_slice_count, int p_mipmap, const void *p_data) {} + + /* LIGHTMAP CAPTURE */ + struct Instantiable { + + SelfList<RasterizerScene::InstanceBase>::List instance_list; + + _FORCE_INLINE_ void instance_change_notify(bool p_aabb = true, bool p_materials = true) { + + SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first(); + while (instances) { + + instances->self()->base_changed(p_aabb, p_materials); + instances = instances->next(); + } + } + + _FORCE_INLINE_ void instance_remove_deps() { + SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first(); + while (instances) { + + SelfList<RasterizerScene::InstanceBase> *next = instances->next(); + instances->self()->base_removed(); + instances = next; + } + } + + Instantiable() {} + virtual ~Instantiable() { + } + }; + + struct LightmapCapture : public Instantiable { + + PoolVector<LightmapCaptureOctree> octree; + AABB bounds; + Transform cell_xform; + int cell_subdiv; + float energy; + LightmapCapture() { + energy = 1.0; + cell_subdiv = 1; + } + }; + + mutable RID_PtrOwner<LightmapCapture> lightmap_capture_data_owner; + void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds) {} + AABB lightmap_capture_get_bounds(RID p_capture) const { return AABB(); } + void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree) {} + RID lightmap_capture_create() { + LightmapCapture *capture = memnew(LightmapCapture); + return lightmap_capture_data_owner.make_rid(capture); + } + PoolVector<uint8_t> lightmap_capture_get_octree(RID p_capture) const { + const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture); + ERR_FAIL_COND_V(!capture, PoolVector<uint8_t>()); + return PoolVector<uint8_t>(); + } + void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform) {} + Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const { return Transform(); } + void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv) {} + int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const { return 0; } + void lightmap_capture_set_energy(RID p_capture, float p_energy) {} + float lightmap_capture_get_energy(RID p_capture) const { return 0.0; } + const PoolVector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const { + const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture); + ERR_FAIL_COND_V(!capture, NULL); + return &capture->octree; + } + + /* PARTICLES */ + + RID particles_create() { return RID(); } + + void particles_set_emitting(RID p_particles, bool p_emitting) {} + void particles_set_amount(RID p_particles, int p_amount) {} + void particles_set_lifetime(RID p_particles, float p_lifetime) {} + void particles_set_one_shot(RID p_particles, bool p_one_shot) {} + void particles_set_pre_process_time(RID p_particles, float p_time) {} + void particles_set_explosiveness_ratio(RID p_particles, float p_ratio) {} + void particles_set_randomness_ratio(RID p_particles, float p_ratio) {} + void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb) {} + void particles_set_speed_scale(RID p_particles, float p_scale) {} + void particles_set_use_local_coordinates(RID p_particles, bool p_enable) {} + void particles_set_process_material(RID p_particles, RID p_material) {} + void particles_set_fixed_fps(RID p_particles, int p_fps) {} + void particles_set_fractional_delta(RID p_particles, bool p_enable) {} + void particles_restart(RID p_particles) {} + + void particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order) {} + + void particles_set_draw_passes(RID p_particles, int p_count) {} + void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh) {} + + void particles_request_process(RID p_particles) {} + AABB particles_get_current_aabb(RID p_particles) { return AABB(); } + AABB particles_get_aabb(RID p_particles) const { return AABB(); } + + void particles_set_emission_transform(RID p_particles, const Transform &p_transform) {} + + bool particles_get_emitting(RID p_particles) { return false; } + int particles_get_draw_passes(RID p_particles) const { return 0; } + RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const { return RID(); } + + virtual bool particles_is_inactive(RID p_particles) const { return false; } + + /* RENDER TARGET */ + + RID render_target_create() { return RID(); } + void render_target_set_position(RID p_render_target, int p_x, int p_y) {} + void render_target_set_size(RID p_render_target, int p_width, int p_height) {} + RID render_target_get_texture(RID p_render_target) const { return RID(); } + void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) {} + void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) {} + bool render_target_was_used(RID p_render_target) { return false; } + void render_target_clear_used(RID p_render_target) {} + void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa) {} + + /* CANVAS SHADOW */ + + RID canvas_light_shadow_buffer_create(int p_width) { return RID(); } + + /* LIGHT SHADOW MAPPING */ + + RID canvas_light_occluder_create() { return RID(); } + void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines) {} + + VS::InstanceType get_base_type(RID p_rid) const { + if (mesh_owner.owns(p_rid)) { + return VS::INSTANCE_MESH; + } + + return VS::INSTANCE_NONE; + } + + bool free(RID p_rid) { + + if (texture_owner.owns(p_rid)) { + // delete the texture + RDTexture *texture = texture_owner.getornull(p_rid); + texture_owner.free(p_rid); + memdelete(texture); + } + return true; + } + + bool has_os_feature(const String &p_feature) const { return false; } + + void update_dirty_resources() {} + + void set_debug_generate_wireframes(bool p_generate) {} + + void render_info_begin_capture() {} + void render_info_end_capture() {} + int get_captured_render_info(VS::RenderInfo p_info) { return 0; } + + int get_render_info(VS::RenderInfo p_info) { return 0; } + String get_video_adapter_name() const { return String(); } + String get_video_adapter_vendor() const { return String(); } + + static RasterizerStorage *base_singleton; + + RasterizerStorageRD(){}; + ~RasterizerStorageRD() {} +}; + +#endif // RASTERIZER_STORAGE_RD_H diff --git a/servers/visual/visual_server_canvas.h b/servers/visual/visual_server_canvas.h index 8044afe164..7b5d2f6cb4 100644 --- a/servers/visual/visual_server_canvas.h +++ b/servers/visual/visual_server_canvas.h @@ -31,7 +31,7 @@ #ifndef VISUALSERVERCANVAS_H #define VISUALSERVERCANVAS_H -#include "rasterizer.h" +#include "rasterizer/rasterizer.h" #include "visual_server_viewport.h" class VisualServerCanvas { @@ -90,7 +90,7 @@ public: } }; - struct LightOccluderPolygon { + struct LightOccluderPolygon { bool active; Rect2 aabb; diff --git a/servers/visual/visual_server_globals.h b/servers/visual/visual_server_globals.h index 5a9d365eca..5bc76afe4c 100644 --- a/servers/visual/visual_server_globals.h +++ b/servers/visual/visual_server_globals.h @@ -31,7 +31,7 @@ #ifndef VISUAL_SERVER_GLOBALS_H #define VISUAL_SERVER_GLOBALS_H -#include "rasterizer.h" +#include "rasterizer/rasterizer.h" class VisualServerCanvas; class VisualServerViewport; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 9afcfc4648..ff2a4b01c4 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -32,7 +32,7 @@ #define VISUAL_SERVER_RASTER_H #include "core/math/octree.h" -#include "servers/visual/rasterizer.h" +#include "servers/visual/rasterizer/rasterizer.h" #include "servers/visual_server.h" #include "visual_server_canvas.h" #include "visual_server_globals.h" @@ -142,33 +142,42 @@ public: /* TEXTURE API */ - BIND0R(RID, texture_create) - BIND7(texture_allocate, RID, int, int, int, Image::Format, TextureType, uint32_t) - BIND3(texture_set_data, RID, const Ref<Image> &, int) - BIND10(texture_set_data_partial, RID, const Ref<Image> &, int, int, int, int, int, int, int, int) - BIND2RC(Ref<Image>, texture_get_data, RID, int) - BIND2(texture_set_flags, RID, uint32_t) - BIND1RC(uint32_t, texture_get_flags, RID) - BIND1RC(Image::Format, texture_get_format, RID) - BIND1RC(TextureType, texture_get_type, RID) - BIND1RC(uint32_t, texture_get_texid, RID) - BIND1RC(uint32_t, texture_get_width, RID) - BIND1RC(uint32_t, texture_get_height, RID) - BIND1RC(uint32_t, texture_get_depth, RID) - BIND4(texture_set_size_override, RID, int, int, int) + //these go pass-through, as they can be called from any thread + BIND1R(RID, texture_2d_create, const Ref<Image> &) + BIND2R(RID, texture_2d_layered_create, const Vector<Ref<Image> > &, TextureLayeredType) + BIND1R(RID, texture_3d_create, const Vector<Ref<Image> > &) + + //goes pass-through + BIND3(texture_2d_update_immediate, RID, const Ref<Image> &, int) + //these go through command queue if they are in another thread + BIND3(texture_2d_update, RID, const Ref<Image> &, int) + BIND4(texture_3d_update, RID, const Ref<Image> &, int, int) + + //these also go pass-through + BIND0R(RID, texture_2d_placeholder_create) + BIND0R(RID, texture_2d_layered_placeholder_create) + BIND0R(RID, texture_3d_placeholder_create) + + BIND1RC(Ref<Image>, texture_2d_get, RID) + BIND2RC(Ref<Image>, texture_2d_layer_get, RID, int) + BIND3RC(Ref<Image>, texture_3d_slice_get, RID, int, int) + + BIND2(texture_replace, RID, RID) + + BIND3(texture_set_size_override, RID, int, int) +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 BIND2(texture_bind, RID, uint32_t) +#endif BIND3(texture_set_detect_3d_callback, RID, TextureDetectCallback, void *) - BIND3(texture_set_detect_srgb_callback, RID, TextureDetectCallback, void *) BIND3(texture_set_detect_normal_callback, RID, TextureDetectCallback, void *) + BIND3(texture_set_detect_roughness_callback, RID, TextureDetectRoughnessCallback, void *) BIND2(texture_set_path, RID, const String &) BIND1RC(String, texture_get_path, RID) - BIND1(texture_set_shrink_all_x2_on_set_data, bool) BIND1(texture_debug_usage, List<TextureInfo> *) - BIND1(textures_keep_original, bool) - BIND2(texture_set_proxy, RID, RID) BIND2(texture_set_force_redraw_if_visible, RID, bool) @@ -502,7 +511,10 @@ public: BIND2(environment_set_bg_energy, RID, float) BIND2(environment_set_canvas_max_layer, RID, int) BIND4(environment_set_ambient_light, RID, const Color &, float, float) +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 BIND2(environment_set_camera_feed_id, RID, int) +#endif BIND7(environment_set_ssr, RID, bool, int, float, float, float, bool) BIND13(environment_set_ssao, RID, bool, float, float, float, float, float, float, float, const Color &, EnvironmentSSAOQuality, EnvironmentSSAOBlur, float) diff --git a/servers/visual/visual_server_scene.h b/servers/visual/visual_server_scene.h index a2d65791a0..61fdfd0861 100644 --- a/servers/visual/visual_server_scene.h +++ b/servers/visual/visual_server_scene.h @@ -31,7 +31,7 @@ #ifndef VISUALSERVERSCENE_H #define VISUALSERVERSCENE_H -#include "servers/visual/rasterizer.h" +#include "servers/visual/rasterizer/rasterizer.h" #include "core/math/geometry.h" #include "core/math/octree.h" diff --git a/servers/visual/visual_server_viewport.h b/servers/visual/visual_server_viewport.h index f701e3612a..4af22a4ad8 100644 --- a/servers/visual/visual_server_viewport.h +++ b/servers/visual/visual_server_viewport.h @@ -33,7 +33,7 @@ #include "core/rid_owner.h" #include "core/self_list.h" -#include "rasterizer.h" +#include "rasterizer/rasterizer.h" #include "servers/arvr/arvr_interface.h" #include "servers/visual_server.h" diff --git a/servers/visual/visual_server_wrap_mt.cpp b/servers/visual/visual_server_wrap_mt.cpp index 29ea8d80e7..4bce8eb942 100644 --- a/servers/visual/visual_server_wrap_mt.cpp +++ b/servers/visual/visual_server_wrap_mt.cpp @@ -136,7 +136,6 @@ void VisualServerWrapMT::finish() { visual_server->finish(); } - texture_free_cached_ids(); sky_free_cached_ids(); shader_free_cached_ids(); material_free_cached_ids(); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index b1bbed24fd..9b999a33f6 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -77,34 +77,42 @@ public: #define server_name visual_server #include "servers/server_wrap_mt_common.h" - /* EVENT QUEUING */ - FUNCRID(texture) - FUNC7(texture_allocate, RID, int, int, int, Image::Format, TextureType, uint32_t) - FUNC3(texture_set_data, RID, const Ref<Image> &, int) - FUNC10(texture_set_data_partial, RID, const Ref<Image> &, int, int, int, int, int, int, int, int) - FUNC2RC(Ref<Image>, texture_get_data, RID, int) - FUNC2(texture_set_flags, RID, uint32_t) - FUNC1RC(uint32_t, texture_get_flags, RID) - FUNC1RC(Image::Format, texture_get_format, RID) - FUNC1RC(TextureType, texture_get_type, RID) - FUNC1RC(uint32_t, texture_get_texid, RID) - FUNC1RC(uint32_t, texture_get_width, RID) - FUNC1RC(uint32_t, texture_get_height, RID) - FUNC1RC(uint32_t, texture_get_depth, RID) - FUNC4(texture_set_size_override, RID, int, int, int) + //these go pass-through, as they can be called from any thread + virtual RID texture_2d_create(const Ref<Image> &p_image) { return visual_server->texture_2d_create(p_image); } + virtual RID texture_2d_layered_create(const Vector<Ref<Image> > &p_layers, TextureLayeredType p_layered_type) { return visual_server->texture_2d_layered_create(p_layers, p_layered_type); } + virtual RID texture_3d_create(const Vector<Ref<Image> > &p_slices) { return visual_server->texture_3d_create(p_slices); } + + //goes pass-through + virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) { visual_server->texture_2d_update_immediate(p_texture, p_image, p_layer); } + //these go through command queue if they are in another thread + FUNC3(texture_2d_update, RID, const Ref<Image> &, int) + FUNC4(texture_3d_update, RID, const Ref<Image> &, int, int) + + //these also go pass-through + virtual RID texture_2d_placeholder_create() { return visual_server->texture_2d_placeholder_create(); } + virtual RID texture_2d_layered_placeholder_create() { return visual_server->texture_2d_layered_placeholder_create(); } + virtual RID texture_3d_placeholder_create() { return visual_server->texture_3d_placeholder_create(); } + + FUNC1RC(Ref<Image>, texture_2d_get, RID) + FUNC2RC(Ref<Image>, texture_2d_layer_get, RID, int) + FUNC3RC(Ref<Image>, texture_3d_slice_get, RID, int, int) + + FUNC2(texture_replace, RID, RID) + + FUNC3(texture_set_size_override, RID, int, int) +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 FUNC2(texture_bind, RID, uint32_t) +#endif FUNC3(texture_set_detect_3d_callback, RID, TextureDetectCallback, void *) - FUNC3(texture_set_detect_srgb_callback, RID, TextureDetectCallback, void *) FUNC3(texture_set_detect_normal_callback, RID, TextureDetectCallback, void *) + FUNC3(texture_set_detect_roughness_callback, RID, TextureDetectRoughnessCallback, void *) FUNC2(texture_set_path, RID, const String &) FUNC1RC(String, texture_get_path, RID) - FUNC1(texture_set_shrink_all_x2_on_set_data, bool) FUNC1S(texture_debug_usage, List<TextureInfo> *) - FUNC1(textures_keep_original, bool) - FUNC2(texture_set_proxy, RID, RID) FUNC2(texture_set_force_redraw_if_visible, RID, bool) @@ -429,7 +437,10 @@ public: FUNC2(environment_set_bg_energy, RID, float) FUNC2(environment_set_canvas_max_layer, RID, int) FUNC4(environment_set_ambient_light, RID, const Color &, float, float) +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 FUNC2(environment_set_camera_feed_id, RID, int) +#endif FUNC7(environment_set_ssr, RID, bool, int, float, float, float, bool) FUNC13(environment_set_ssao, RID, bool, float, float, float, float, float, float, float, const Color &, EnvironmentSSAOQuality, EnvironmentSSAOBlur, float) diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 19b9e2c783..ba200fe94a 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -51,18 +51,6 @@ VisualServer *VisualServer::create() { return NULL; } -RID VisualServer::texture_create_from_image(const Ref<Image> &p_image, uint32_t p_flags) { - - ERR_FAIL_COND_V(!p_image.is_valid(), RID()); - RID texture = texture_create(); - texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_flags); //if it has mipmaps, use, else generate - ERR_FAIL_COND_V(!texture.is_valid(), texture); - - texture_set_data(texture, p_image); - - return texture; -} - Array VisualServer::_texture_debug_usage_bind() { List<TextureInfo> list; @@ -167,7 +155,7 @@ RID VisualServer::get_test_texture() { Ref<Image> data = memnew(Image(TEST_TEXTURE_SIZE, TEST_TEXTURE_SIZE, false, Image::FORMAT_RGB8, test_data)); - test_texture = texture_create_from_image(data); + test_texture = texture_2d_create(data); return test_texture; } @@ -334,9 +322,7 @@ RID VisualServer::get_white_texture() { w[i] = 255; } Ref<Image> white = memnew(Image(4, 4, 0, Image::FORMAT_RGB8, wt)); - white_texture = texture_create(); - texture_allocate(white_texture, 4, 4, 0, Image::FORMAT_RGB8, TEXTURE_TYPE_2D); - texture_set_data(white_texture, white); + white_texture = texture_2d_create(white); return white_texture; } @@ -1647,28 +1633,8 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("sync"), &VisualServer::sync); ClassDB::bind_method(D_METHOD("draw", "swap_buffers", "frame_step"), &VisualServer::draw, DEFVAL(true), DEFVAL(0.0)); - ClassDB::bind_method(D_METHOD("texture_create"), &VisualServer::texture_create); - ClassDB::bind_method(D_METHOD("texture_create_from_image", "image", "flags"), &VisualServer::texture_create_from_image, DEFVAL(TEXTURE_FLAGS_DEFAULT)); - ClassDB::bind_method(D_METHOD("texture_allocate", "texture", "width", "height", "depth_3d", "format", "type", "flags"), &VisualServer::texture_allocate, DEFVAL(TEXTURE_FLAGS_DEFAULT)); - ClassDB::bind_method(D_METHOD("texture_set_data", "texture", "image", "layer"), &VisualServer::texture_set_data, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("texture_set_data_partial", "texture", "image", "src_x", "src_y", "src_w", "src_h", "dst_x", "dst_y", "dst_mip", "layer"), &VisualServer::texture_set_data_partial, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("texture_get_data", "texture", "cube_side"), &VisualServer::texture_get_data, DEFVAL(CUBEMAP_LEFT)); - ClassDB::bind_method(D_METHOD("texture_set_flags", "texture", "flags"), &VisualServer::texture_set_flags); - ClassDB::bind_method(D_METHOD("texture_get_flags", "texture"), &VisualServer::texture_get_flags); - ClassDB::bind_method(D_METHOD("texture_get_format", "texture"), &VisualServer::texture_get_format); - ClassDB::bind_method(D_METHOD("texture_get_type", "texture"), &VisualServer::texture_get_type); - ClassDB::bind_method(D_METHOD("texture_get_texid", "texture"), &VisualServer::texture_get_texid); - ClassDB::bind_method(D_METHOD("texture_get_width", "texture"), &VisualServer::texture_get_width); - ClassDB::bind_method(D_METHOD("texture_get_height", "texture"), &VisualServer::texture_get_height); - ClassDB::bind_method(D_METHOD("texture_get_depth", "texture"), &VisualServer::texture_get_depth); - ClassDB::bind_method(D_METHOD("texture_set_size_override", "texture", "width", "height", "depth"), &VisualServer::texture_set_size_override); - ClassDB::bind_method(D_METHOD("texture_set_path", "texture", "path"), &VisualServer::texture_set_path); - ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &VisualServer::texture_get_path); - ClassDB::bind_method(D_METHOD("texture_set_shrink_all_x2_on_set_data", "shrink"), &VisualServer::texture_set_shrink_all_x2_on_set_data); - ClassDB::bind_method(D_METHOD("texture_bind", "texture", "number"), &VisualServer::texture_bind); - - ClassDB::bind_method(D_METHOD("texture_debug_usage"), &VisualServer::_texture_debug_usage_bind); - ClassDB::bind_method(D_METHOD("textures_keep_original", "enable"), &VisualServer::textures_keep_original); +#warning TODO all texture methods need re-binding + #ifndef _3D_DISABLED ClassDB::bind_method(D_METHOD("sky_create"), &VisualServer::sky_create); ClassDB::bind_method(D_METHOD("sky_set_texture", "sky", "cube_map", "radiance_size"), &VisualServer::sky_set_texture); @@ -2058,26 +2024,16 @@ void VisualServer::_bind_methods() { BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MIN); BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MAX); - BIND_ENUM_CONSTANT(CUBEMAP_LEFT); - BIND_ENUM_CONSTANT(CUBEMAP_RIGHT); - BIND_ENUM_CONSTANT(CUBEMAP_BOTTOM); - BIND_ENUM_CONSTANT(CUBEMAP_TOP); - BIND_ENUM_CONSTANT(CUBEMAP_FRONT); - BIND_ENUM_CONSTANT(CUBEMAP_BACK); - - BIND_ENUM_CONSTANT(TEXTURE_TYPE_2D); - BIND_ENUM_CONSTANT(TEXTURE_TYPE_CUBEMAP); - BIND_ENUM_CONSTANT(TEXTURE_TYPE_2D_ARRAY); - BIND_ENUM_CONSTANT(TEXTURE_TYPE_3D); - - BIND_ENUM_CONSTANT(TEXTURE_FLAG_MIPMAPS); - BIND_ENUM_CONSTANT(TEXTURE_FLAG_REPEAT); - BIND_ENUM_CONSTANT(TEXTURE_FLAG_FILTER); - BIND_ENUM_CONSTANT(TEXTURE_FLAG_ANISOTROPIC_FILTER); - BIND_ENUM_CONSTANT(TEXTURE_FLAG_CONVERT_TO_LINEAR); - BIND_ENUM_CONSTANT(TEXTURE_FLAG_MIRRORED_REPEAT); - BIND_ENUM_CONSTANT(TEXTURE_FLAG_USED_FOR_STREAMING); - BIND_ENUM_CONSTANT(TEXTURE_FLAGS_DEFAULT); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_LEFT); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_RIGHT); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BOTTOM); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_TOP); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_FRONT); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BACK); + + BIND_ENUM_CONSTANT(TEXTURE_LAYERED_2D_ARRAY); + BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP); + BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP_ARRAY); BIND_ENUM_CONSTANT(SHADER_SPATIAL); BIND_ENUM_CONSTANT(SHADER_CANVAS_ITEM); diff --git a/servers/visual_server.h b/servers/visual_server.h index e7662695a6..4299870de0 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -80,76 +80,65 @@ public: /* TEXTURE API */ - enum TextureFlags { - TEXTURE_FLAG_MIPMAPS = 1, /// Enable automatic mipmap generation - when available - TEXTURE_FLAG_REPEAT = 2, /// Repeat texture (Tiling), otherwise Clamping - TEXTURE_FLAG_FILTER = 4, /// Create texture with linear (or available) filter - TEXTURE_FLAG_ANISOTROPIC_FILTER = 8, - TEXTURE_FLAG_CONVERT_TO_LINEAR = 16, - TEXTURE_FLAG_MIRRORED_REPEAT = 32, /// Repeat texture, with alternate sections mirrored - TEXTURE_FLAG_USED_FOR_STREAMING = 2048, - TEXTURE_FLAGS_DEFAULT = TEXTURE_FLAG_REPEAT | TEXTURE_FLAG_MIPMAPS | TEXTURE_FLAG_FILTER + enum TextureLayeredType { + TEXTURE_LAYERED_2D_ARRAY, + TEXTURE_LAYERED_CUBEMAP, + TEXTURE_LAYERED_CUBEMAP_ARRAY, }; - enum TextureType { - TEXTURE_TYPE_2D, - TEXTURE_TYPE_CUBEMAP, - TEXTURE_TYPE_2D_ARRAY, - TEXTURE_TYPE_3D, + enum CubeMapLayer { + + CUBEMAP_LAYER_LEFT, + CUBEMAP_LAYER_RIGHT, + CUBEMAP_LAYER_BOTTOM, + CUBEMAP_LAYER_TOP, + CUBEMAP_LAYER_FRONT, + CUBEMAP_LAYER_BACK }; - enum CubeMapSide { + virtual RID texture_2d_create(const Ref<Image> &p_image) = 0; + virtual RID texture_2d_layered_create(const Vector<Ref<Image> > &p_layers, TextureLayeredType p_layered_type) = 0; + virtual RID texture_3d_create(const Vector<Ref<Image> > &p_slices) = 0; //all slices, then all the mipmaps, must be coherent - CUBEMAP_LEFT, - CUBEMAP_RIGHT, - CUBEMAP_BOTTOM, - CUBEMAP_TOP, - CUBEMAP_FRONT, - CUBEMAP_BACK - }; + virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) = 0; //mostly used for video and streaming + virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) = 0; + virtual void texture_3d_update(RID p_texture, const Ref<Image> &p_image, int p_depth, int p_mipmap) = 0; + + //these two APIs can be used together or in combination with the others. + virtual RID texture_2d_placeholder_create() = 0; + virtual RID texture_2d_layered_placeholder_create() = 0; + virtual RID texture_3d_placeholder_create() = 0; - virtual RID texture_create() = 0; - RID texture_create_from_image(const Ref<Image> &p_image, uint32_t p_flags = TEXTURE_FLAGS_DEFAULT); // helper - virtual void texture_allocate(RID p_texture, - int p_width, - int p_height, - int p_depth_3d, - Image::Format p_format, - TextureType p_type, - uint32_t p_flags = TEXTURE_FLAGS_DEFAULT) = 0; - - virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) = 0; - virtual void texture_set_data_partial(RID p_texture, - const Ref<Image> &p_image, - int src_x, int src_y, - int src_w, int src_h, - int dst_x, int dst_y, - int p_dst_mip, - int p_layer = 0) = 0; - - virtual Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const = 0; - virtual void texture_set_flags(RID p_texture, uint32_t p_flags) = 0; - virtual uint32_t texture_get_flags(RID p_texture) const = 0; - virtual Image::Format texture_get_format(RID p_texture) const = 0; - virtual TextureType texture_get_type(RID p_texture) const = 0; - virtual uint32_t texture_get_texid(RID p_texture) const = 0; - virtual uint32_t texture_get_width(RID p_texture) const = 0; - virtual uint32_t texture_get_height(RID p_texture) const = 0; - virtual uint32_t texture_get_depth(RID p_texture) const = 0; - virtual void texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth_3d) = 0; + virtual Ref<Image> texture_2d_get(RID p_texture) const = 0; + virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const = 0; + virtual Ref<Image> texture_3d_slice_get(RID p_texture, int p_depth, int p_mipmap) const = 0; + + virtual void texture_replace(RID p_texture, RID p_by_texture) = 0; + virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) = 0; +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 virtual void texture_bind(RID p_texture, uint32_t p_texture_no) = 0; +#endif virtual void texture_set_path(RID p_texture, const String &p_path) = 0; virtual String texture_get_path(RID p_texture) const = 0; - virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable) = 0; - typedef void (*TextureDetectCallback)(void *); virtual void texture_set_detect_3d_callback(RID p_texture, TextureDetectCallback p_callback, void *p_userdata) = 0; - virtual void texture_set_detect_srgb_callback(RID p_texture, TextureDetectCallback p_callback, void *p_userdata) = 0; virtual void texture_set_detect_normal_callback(RID p_texture, TextureDetectCallback p_callback, void *p_userdata) = 0; + enum TextureDetectRoughnessChannel { + TEXTURE_DETECT_ROUGNHESS_R, + TEXTURE_DETECT_ROUGNHESS_G, + TEXTURE_DETECT_ROUGNHESS_B, + TEXTURE_DETECT_ROUGNHESS_A, + TEXTURE_DETECT_ROUGNHESS_GRAY, + }; + + typedef void (*TextureDetectRoughnessCallback)(void *, const String &, TextureDetectRoughnessChannel); + virtual void texture_set_detect_roughness_callback(RID p_texture, TextureDetectRoughnessCallback p_callback, void *p_userdata) = 0; + struct TextureInfo { RID texture; uint32_t width; @@ -163,8 +152,6 @@ public: virtual void texture_debug_usage(List<TextureInfo> *r_info) = 0; Array _texture_debug_usage_bind(); - virtual void textures_keep_original(bool p_enable) = 0; - virtual void texture_set_proxy(RID p_proxy, RID p_base) = 0; virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) = 0; @@ -722,7 +709,10 @@ public: virtual void environment_set_bg_energy(RID p_env, float p_energy) = 0; virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0; virtual void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0) = 0; +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) = 0; +#endif //set default SSAO options //set default SSR options @@ -1058,8 +1048,8 @@ public: }; // make variant understand the enums -VARIANT_ENUM_CAST(VisualServer::CubeMapSide); -VARIANT_ENUM_CAST(VisualServer::TextureFlags); +VARIANT_ENUM_CAST(VisualServer::TextureLayeredType); +VARIANT_ENUM_CAST(VisualServer::CubeMapLayer); VARIANT_ENUM_CAST(VisualServer::ShaderMode); VARIANT_ENUM_CAST(VisualServer::ArrayType); VARIANT_ENUM_CAST(VisualServer::ArrayFormat); @@ -1098,7 +1088,6 @@ VARIANT_ENUM_CAST(VisualServer::EnvironmentSSAOQuality); VARIANT_ENUM_CAST(VisualServer::EnvironmentSSAOBlur); VARIANT_ENUM_CAST(VisualServer::InstanceFlags); VARIANT_ENUM_CAST(VisualServer::ShadowCastingSetting); -VARIANT_ENUM_CAST(VisualServer::TextureType); //typedef VisualServer VS; // makes it easier to use #define VS VisualServer |