diff options
Diffstat (limited to 'servers')
31 files changed, 417 insertions, 212 deletions
diff --git a/servers/physics_2d/godot_space_2d.cpp b/servers/physics_2d/godot_space_2d.cpp index 63e3af1395..a2459501c8 100644 --- a/servers/physics_2d/godot_space_2d.cpp +++ b/servers/physics_2d/godot_space_2d.cpp @@ -1033,9 +1033,9 @@ void GodotSpace2D::_broadphase_unpair(GodotCollisionObject2D *A, int p_subindex_ return; } - GodotSpace2D *self = (GodotSpace2D *)p_self; + GodotSpace2D *self = static_cast<GodotSpace2D *>(p_self); self->collision_pairs--; - GodotConstraint2D *c = (GodotConstraint2D *)p_data; + GodotConstraint2D *c = static_cast<GodotConstraint2D *>(p_data); memdelete(c); } diff --git a/servers/physics_server_2d_wrap_mt.cpp b/servers/physics_server_2d_wrap_mt.cpp index 02223b83f0..699f515270 100644 --- a/servers/physics_server_2d_wrap_mt.cpp +++ b/servers/physics_server_2d_wrap_mt.cpp @@ -37,7 +37,7 @@ void PhysicsServer2DWrapMT::thread_exit() { } void PhysicsServer2DWrapMT::thread_step(real_t p_delta) { - physics_2d_server->step(p_delta); + physics_server_2d->step(p_delta); step_sem.post(); } @@ -50,7 +50,7 @@ void PhysicsServer2DWrapMT::_thread_callback(void *_instance) { void PhysicsServer2DWrapMT::thread_loop() { server_thread = Thread::get_caller_id(); - physics_2d_server->init(); + physics_server_2d->init(); exit.clear(); step_thread_up.set(); @@ -61,7 +61,7 @@ void PhysicsServer2DWrapMT::thread_loop() { command_queue.flush_all(); // flush all - physics_2d_server->finish(); + physics_server_2d->finish(); } /* EVENT QUEUING */ @@ -71,7 +71,7 @@ void PhysicsServer2DWrapMT::step(real_t p_step) { command_queue.push(this, &PhysicsServer2DWrapMT::thread_step, p_step); } else { command_queue.flush_all(); //flush all pending from other threads - physics_2d_server->step(p_step); + physics_server_2d->step(p_step); } } @@ -83,15 +83,15 @@ void PhysicsServer2DWrapMT::sync() { step_sem.wait(); //must not wait if a step was not issued } } - physics_2d_server->sync(); + physics_server_2d->sync(); } void PhysicsServer2DWrapMT::flush_queries() { - physics_2d_server->flush_queries(); + physics_server_2d->flush_queries(); } void PhysicsServer2DWrapMT::end_sync() { - physics_2d_server->end_sync(); + physics_server_2d->end_sync(); } void PhysicsServer2DWrapMT::init() { @@ -102,7 +102,7 @@ void PhysicsServer2DWrapMT::init() { OS::get_singleton()->delay_usec(1000); } } else { - physics_2d_server->init(); + physics_server_2d->init(); } } @@ -111,13 +111,13 @@ void PhysicsServer2DWrapMT::finish() { command_queue.push(this, &PhysicsServer2DWrapMT::thread_exit); thread.wait_to_finish(); } else { - physics_2d_server->finish(); + physics_server_2d->finish(); } } PhysicsServer2DWrapMT::PhysicsServer2DWrapMT(PhysicsServer2D *p_contained, bool p_create_thread) : command_queue(p_create_thread) { - physics_2d_server = p_contained; + physics_server_2d = p_contained; create_thread = p_create_thread; pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc"); @@ -132,6 +132,6 @@ PhysicsServer2DWrapMT::PhysicsServer2DWrapMT(PhysicsServer2D *p_contained, bool } PhysicsServer2DWrapMT::~PhysicsServer2DWrapMT() { - memdelete(physics_2d_server); + memdelete(physics_server_2d); //finish(); } diff --git a/servers/physics_server_2d_wrap_mt.h b/servers/physics_server_2d_wrap_mt.h index aa3a8bc04a..ddb071f603 100644 --- a/servers/physics_server_2d_wrap_mt.h +++ b/servers/physics_server_2d_wrap_mt.h @@ -44,7 +44,7 @@ #endif class PhysicsServer2DWrapMT : public PhysicsServer2D { - mutable PhysicsServer2D *physics_2d_server; + mutable PhysicsServer2D *physics_server_2d; mutable CommandQueueMT command_queue; @@ -71,7 +71,7 @@ class PhysicsServer2DWrapMT : public PhysicsServer2D { public: #define ServerName PhysicsServer2D #define ServerNameWrapMT PhysicsServer2DWrapMT -#define server_name physics_2d_server +#define server_name physics_server_2d #define WRITE_ACTION #include "servers/server_wrap_mt_common.h" @@ -96,7 +96,7 @@ public: //these work well, but should be used from the main thread only bool shape_collide(RID p_shape_A, const Transform2D &p_xform_A, const Vector2 &p_motion_A, RID p_shape_B, const Transform2D &p_xform_B, const Vector2 &p_motion_B, Vector2 *r_results, int p_result_max, int &r_result_count) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); - return physics_2d_server->shape_collide(p_shape_A, p_xform_A, p_motion_A, p_shape_B, p_xform_B, p_motion_B, r_results, p_result_max, r_result_count); + return physics_server_2d->shape_collide(p_shape_A, p_xform_A, p_motion_A, p_shape_B, p_xform_B, p_motion_B, r_results, p_result_max, r_result_count); } /* SPACE API */ @@ -111,18 +111,18 @@ public: // this function only works on physics process, errors and returns null otherwise PhysicsDirectSpaceState2D *space_get_direct_state(RID p_space) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), nullptr); - return physics_2d_server->space_get_direct_state(p_space); + return physics_server_2d->space_get_direct_state(p_space); } FUNC2(space_set_debug_contacts, RID, int); virtual Vector<Vector2> space_get_contacts(RID p_space) const override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), Vector<Vector2>()); - return physics_2d_server->space_get_contacts(p_space); + return physics_server_2d->space_get_contacts(p_space); } virtual int space_get_contact_count(RID p_space) const override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), 0); - return physics_2d_server->space_get_contact_count(p_space); + return physics_server_2d->space_get_contact_count(p_space); } /* AREA API */ @@ -250,20 +250,20 @@ public: FUNC3(body_set_force_integration_callback, RID, const Callable &, const Variant &); bool body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) override { - return physics_2d_server->body_collide_shape(p_body, p_body_shape, p_shape, p_shape_xform, p_motion, r_results, p_result_max, r_result_count); + return physics_server_2d->body_collide_shape(p_body, p_body_shape, p_shape, p_shape_xform, p_motion, r_results, p_result_max, r_result_count); } FUNC2(body_set_pickable, RID, bool); bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); - return physics_2d_server->body_test_motion(p_body, p_parameters, r_result); + return physics_server_2d->body_test_motion(p_body, p_parameters, r_result); } // this function only works on physics process, errors and returns null otherwise PhysicsDirectBodyState2D *body_get_direct_state(RID p_body) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), nullptr); - return physics_2d_server->body_get_direct_state(p_body); + return physics_server_2d->body_get_direct_state(p_body); } /* JOINT API */ @@ -309,11 +309,11 @@ public: virtual void finish() override; virtual bool is_flushing_queries() const override { - return physics_2d_server->is_flushing_queries(); + return physics_server_2d->is_flushing_queries(); } int get_process_info(ProcessInfo p_info) override { - return physics_2d_server->get_process_info(p_info); + return physics_server_2d->get_process_info(p_info); } PhysicsServer2DWrapMT(PhysicsServer2D *p_contained, bool p_create_thread); diff --git a/servers/physics_server_3d_wrap_mt.cpp b/servers/physics_server_3d_wrap_mt.cpp index 822ca44b72..7faa193ec2 100644 --- a/servers/physics_server_3d_wrap_mt.cpp +++ b/servers/physics_server_3d_wrap_mt.cpp @@ -37,7 +37,7 @@ void PhysicsServer3DWrapMT::thread_exit() { } void PhysicsServer3DWrapMT::thread_step(real_t p_delta) { - physics_3d_server->step(p_delta); + physics_server_3d->step(p_delta); step_sem.post(); } @@ -50,7 +50,7 @@ void PhysicsServer3DWrapMT::_thread_callback(void *_instance) { void PhysicsServer3DWrapMT::thread_loop() { server_thread = Thread::get_caller_id(); - physics_3d_server->init(); + physics_server_3d->init(); exit = false; step_thread_up = true; @@ -61,7 +61,7 @@ void PhysicsServer3DWrapMT::thread_loop() { command_queue.flush_all(); // flush all - physics_3d_server->finish(); + physics_server_3d->finish(); } /* EVENT QUEUING */ @@ -71,7 +71,7 @@ void PhysicsServer3DWrapMT::step(real_t p_step) { command_queue.push(this, &PhysicsServer3DWrapMT::thread_step, p_step); } else { command_queue.flush_all(); //flush all pending from other threads - physics_3d_server->step(p_step); + physics_server_3d->step(p_step); } } @@ -83,15 +83,15 @@ void PhysicsServer3DWrapMT::sync() { step_sem.wait(); //must not wait if a step was not issued } } - physics_3d_server->sync(); + physics_server_3d->sync(); } void PhysicsServer3DWrapMT::flush_queries() { - physics_3d_server->flush_queries(); + physics_server_3d->flush_queries(); } void PhysicsServer3DWrapMT::end_sync() { - physics_3d_server->end_sync(); + physics_server_3d->end_sync(); } void PhysicsServer3DWrapMT::init() { @@ -102,7 +102,7 @@ void PhysicsServer3DWrapMT::init() { OS::get_singleton()->delay_usec(1000); } } else { - physics_3d_server->init(); + physics_server_3d->init(); } } @@ -111,13 +111,13 @@ void PhysicsServer3DWrapMT::finish() { command_queue.push(this, &PhysicsServer3DWrapMT::thread_exit); thread.wait_to_finish(); } else { - physics_3d_server->finish(); + physics_server_3d->finish(); } } PhysicsServer3DWrapMT::PhysicsServer3DWrapMT(PhysicsServer3D *p_contained, bool p_create_thread) : command_queue(p_create_thread) { - physics_3d_server = p_contained; + physics_server_3d = p_contained; create_thread = p_create_thread; pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc"); @@ -132,6 +132,6 @@ PhysicsServer3DWrapMT::PhysicsServer3DWrapMT(PhysicsServer3D *p_contained, bool } PhysicsServer3DWrapMT::~PhysicsServer3DWrapMT() { - memdelete(physics_3d_server); + memdelete(physics_server_3d); //finish(); } diff --git a/servers/physics_server_3d_wrap_mt.h b/servers/physics_server_3d_wrap_mt.h index e44f82672d..d4a4ad3132 100644 --- a/servers/physics_server_3d_wrap_mt.h +++ b/servers/physics_server_3d_wrap_mt.h @@ -43,7 +43,7 @@ #endif class PhysicsServer3DWrapMT : public PhysicsServer3D { - mutable PhysicsServer3D *physics_3d_server; + mutable PhysicsServer3D *physics_server_3d; mutable CommandQueueMT command_queue; @@ -70,7 +70,7 @@ class PhysicsServer3DWrapMT : public PhysicsServer3D { public: #define ServerName PhysicsServer3D #define ServerNameWrapMT PhysicsServer3DWrapMT -#define server_name physics_3d_server +#define server_name physics_server_3d #define WRITE_ACTION #include "servers/server_wrap_mt_common.h" @@ -100,7 +100,7 @@ public: //these work well, but should be used from the main thread only bool shape_collide(RID p_shape_A, const Transform &p_xform_A, const Vector3 &p_motion_A, RID p_shape_B, const Transform &p_xform_B, const Vector3 &p_motion_B, Vector3 *r_results, int p_result_max, int &r_result_count) { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); - return physics_3d_server->shape_collide(p_shape_A, p_xform_A, p_motion_A, p_shape_B, p_xform_B, p_motion_B, r_results, p_result_max, r_result_count); + return physics_server_3d->shape_collide(p_shape_A, p_xform_A, p_motion_A, p_shape_B, p_xform_B, p_motion_B, r_results, p_result_max, r_result_count); } #endif /* SPACE API */ @@ -115,18 +115,18 @@ public: // this function only works on physics process, errors and returns null otherwise PhysicsDirectSpaceState3D *space_get_direct_state(RID p_space) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), nullptr); - return physics_3d_server->space_get_direct_state(p_space); + return physics_server_3d->space_get_direct_state(p_space); } FUNC2(space_set_debug_contacts, RID, int); virtual Vector<Vector3> space_get_contacts(RID p_space) const override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), Vector<Vector3>()); - return physics_3d_server->space_get_contacts(p_space); + return physics_server_3d->space_get_contacts(p_space); } virtual int space_get_contact_count(RID p_space) const override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), 0); - return physics_3d_server->space_get_contact_count(p_space); + return physics_server_3d->space_get_contact_count(p_space); } /* AREA API */ @@ -256,13 +256,13 @@ public: bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); - return physics_3d_server->body_test_motion(p_body, p_parameters, r_result); + return physics_server_3d->body_test_motion(p_body, p_parameters, r_result); } // this function only works on physics process, errors and returns null otherwise PhysicsDirectBodyState3D *body_get_direct_state(RID p_body) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), nullptr); - return physics_3d_server->body_get_direct_state(p_body); + return physics_server_3d->body_get_direct_state(p_body); } /* SOFT BODY API */ @@ -385,11 +385,11 @@ public: virtual void finish() override; virtual bool is_flushing_queries() const override { - return physics_3d_server->is_flushing_queries(); + return physics_server_3d->is_flushing_queries(); } int get_process_info(ProcessInfo p_info) override { - return physics_3d_server->get_process_info(p_info); + return physics_server_3d->get_process_info(p_info); } PhysicsServer3DWrapMT(PhysicsServer3D *p_contained, bool p_create_thread); diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index 9843492316..f02bf80645 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -85,17 +85,17 @@ ShaderTypes *shader_types = nullptr; PhysicsServer3D *_createGodotPhysics3DCallback() { bool using_threads = GLOBAL_GET("physics/3d/run_on_separate_thread"); - PhysicsServer3D *physics_server = memnew(GodotPhysicsServer3D(using_threads)); + PhysicsServer3D *physics_server_3d = memnew(GodotPhysicsServer3D(using_threads)); - return memnew(PhysicsServer3DWrapMT(physics_server, using_threads)); + return memnew(PhysicsServer3DWrapMT(physics_server_3d, using_threads)); } PhysicsServer2D *_createGodotPhysics2DCallback() { bool using_threads = GLOBAL_GET("physics/2d/run_on_separate_thread"); - PhysicsServer2D *physics_server = memnew(GodotPhysicsServer2D(using_threads)); + PhysicsServer2D *physics_server_2d = memnew(GodotPhysicsServer2D(using_threads)); - return memnew(PhysicsServer2DWrapMT(physics_server, using_threads)); + return memnew(PhysicsServer2DWrapMT(physics_server_2d, using_threads)); } static bool has_server_feature_callback(const String &p_feature) { diff --git a/servers/rendering/dummy/rasterizer_scene_dummy.h b/servers/rendering/dummy/rasterizer_scene_dummy.h index 3855222554..fa58322ea8 100644 --- a/servers/rendering/dummy/rasterizer_scene_dummy.h +++ b/servers/rendering/dummy/rasterizer_scene_dummy.h @@ -184,7 +184,7 @@ public: void voxel_gi_set_quality(RS::VoxelGIQuality) override {} void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, const PagedArray<RID> &p_fog_volumes, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_mesh_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr, RendererScene::RenderInfo *r_info = nullptr) override {} - void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override {} + void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override {} void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) override {} void set_scene_pass(uint64_t p_pass) override {} diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index 925b5c180c..ace948d149 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -210,7 +210,7 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::configure(RID p_c tf.array_layers = view_count; // create a layer for every view tf.usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT; - RD::TextureSamples ts[RS::VIEWPORT_MSAA_MAX] = { + const RD::TextureSamples ts[RS::VIEWPORT_MSAA_MAX] = { RD::TEXTURE_SAMPLES_1, RD::TEXTURE_SAMPLES_2, RD::TEXTURE_SAMPLES_4, @@ -1124,7 +1124,7 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con distance = -distance_max; } - if (p_render_data->cam_ortogonal) { + if (p_render_data->cam_orthogonal) { distance = 1.0; } @@ -1815,7 +1815,7 @@ void RenderForwardClustered::_render_particle_collider_heightfield(RID p_fb, con RD::get_singleton()->draw_command_end_label(); } -void RenderForwardClustered::_render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) { +void RenderForwardClustered::_render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) { RENDER_TIMESTAMP("Setup Rendering 3D Material"); RD::get_singleton()->draw_command_begin_label("Render 3D Material"); @@ -2668,7 +2668,7 @@ void RenderForwardClustered::_geometry_instance_add_surface_with_material(Geomet SceneShaderForwardClustered::MaterialData *material_shadow = nullptr; void *surface_shadow = nullptr; - if (!p_material->shader_data->uses_particle_trails && !p_material->shader_data->writes_modelview_or_projection && !p_material->shader_data->uses_vertex && !p_material->shader_data->uses_position && !p_material->shader_data->uses_discard && !p_material->shader_data->uses_depth_pre_pass && !p_material->shader_data->uses_alpha_clip) { + if (!p_material->shader_data->uses_particle_trails && !p_material->shader_data->writes_modelview_or_projection && !p_material->shader_data->uses_vertex && !p_material->shader_data->uses_position && !p_material->shader_data->uses_discard && !p_material->shader_data->uses_depth_pre_pass && !p_material->shader_data->uses_alpha_clip && p_material->shader_data->cull_mode == SceneShaderForwardClustered::ShaderData::CULL_BACK) { flags |= GeometryInstanceSurfaceDataCache::FLAG_USES_SHARED_SHADOW_MATERIAL; material_shadow = static_cast<SceneShaderForwardClustered::MaterialData *>(RendererRD::MaterialStorage::get_singleton()->material_get_data(scene_shader.default_material, RendererRD::SHADER_TYPE_3D)); diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h index 37366d3e14..0e588aecb4 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h @@ -218,7 +218,7 @@ class RenderForwardClustered : public RendererSceneRenderRD { INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF, INSTANCE_DATA_FLAGS_FADE_SHIFT = 24, - INSTANCE_DATA_FLAGS_FADE_MASK = 0xFF << INSTANCE_DATA_FLAGS_FADE_SHIFT + INSTANCE_DATA_FLAGS_FADE_MASK = 0xFFUL << INSTANCE_DATA_FLAGS_FADE_SHIFT }; struct SceneState { @@ -611,7 +611,7 @@ protected: virtual void _render_shadow_process() override; virtual void _render_shadow_end(uint32_t p_barrier = RD::BARRIER_MASK_ALL) override; - virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; + virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; virtual void _render_uv2(const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<GeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture) override; virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, const PagedArray<GeometryInstance *> &p_instances) override; diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp index 6b0d245e44..3c115c942b 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp @@ -55,7 +55,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { int blend_mode = BLEND_MODE_MIX; int depth_testi = DEPTH_TEST_ENABLED; int alpha_antialiasing_mode = ALPHA_ANTIALIASING_OFF; - int cull = CULL_BACK; + int cull_modei = CULL_BACK; uses_point_size = false; uses_alpha = false; @@ -101,9 +101,9 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { actions.render_mode_values["depth_test_disabled"] = Pair<int *, int>(&depth_testi, DEPTH_TEST_DISABLED); - actions.render_mode_values["cull_disabled"] = Pair<int *, int>(&cull, CULL_DISABLED); - actions.render_mode_values["cull_front"] = Pair<int *, int>(&cull, CULL_FRONT); - actions.render_mode_values["cull_back"] = Pair<int *, int>(&cull, CULL_BACK); + actions.render_mode_values["cull_disabled"] = Pair<int *, int>(&cull_modei, CULL_DISABLED); + actions.render_mode_values["cull_front"] = Pair<int *, int>(&cull_modei, CULL_FRONT); + actions.render_mode_values["cull_back"] = Pair<int *, int>(&cull_modei, CULL_BACK); actions.render_mode_flags["unshaded"] = &unshaded; actions.render_mode_flags["wireframe"] = &wireframe; @@ -145,6 +145,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { depth_draw = DepthDraw(depth_drawi); depth_test = DepthTest(depth_testi); + cull_mode = Cull(cull_modei); #if 0 print_line("**compiling shader:"); @@ -258,7 +259,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { { RD::POLYGON_CULL_DISABLED, RD::POLYGON_CULL_DISABLED, RD::POLYGON_CULL_DISABLED } }; - RD::PolygonCullMode cull_mode_rd = cull_mode_rd_table[i][cull]; + RD::PolygonCullMode cull_mode_rd = cull_mode_rd_table[i][cull_mode]; for (int j = 0; j < RS::PRIMITIVE_MAX; j++) { RD::RenderPrimitive primitive_rd_table[RS::PRIMITIVE_MAX] = { @@ -554,10 +555,21 @@ void SceneShaderForwardClustered::init(RendererStorageRD *p_storage, const Strin } valid_color_pass_pipelines.insert(0); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_TRANSPARENT); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_TRANSPARENT | PIPELINE_COLOR_PASS_FLAG_LIGHTMAP); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_TRANSPARENT | PIPELINE_COLOR_PASS_FLAG_MULTIVIEW); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_TRANSPARENT | PIPELINE_COLOR_PASS_FLAG_MULTIVIEW | PIPELINE_COLOR_PASS_FLAG_LIGHTMAP); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_SEPARATE_SPECULAR); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_SEPARATE_SPECULAR | PIPELINE_COLOR_PASS_FLAG_LIGHTMAP); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_SEPARATE_SPECULAR | PIPELINE_COLOR_PASS_FLAG_MULTIVIEW); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_SEPARATE_SPECULAR | PIPELINE_COLOR_PASS_FLAG_MULTIVIEW | PIPELINE_COLOR_PASS_FLAG_LIGHTMAP); + + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_LIGHTMAP); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_LIGHTMAP | PIPELINE_COLOR_PASS_FLAG_MULTIVIEW); + valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_MULTIVIEW); - valid_color_pass_pipelines.insert(PIPELINE_COLOR_PASS_FLAG_TRANSPARENT | PIPELINE_COLOR_PASS_FLAG_MULTIVIEW); material_storage->shader_set_data_request_function(RendererRD::SHADER_TYPE_3D, _create_shader_funcs); material_storage->material_set_data_request_function(RendererRD::SHADER_TYPE_3D, _create_material_funcs); diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h index 1b7709bedb..6185fa7413 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h @@ -171,6 +171,7 @@ public: bool uses_time; bool writes_modelview_or_projection; bool uses_world_coordinates; + Cull cull_mode; uint64_t last_pass = 0; uint32_t index = 0; diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index ade2b976c8..b9f49cf008 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -158,7 +158,7 @@ void RenderForwardMobile::RenderBufferDataForwardMobile::configure(RID p_color_b tf.array_layers = view_count; // create a layer for every view tf.usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT; - RD::TextureSamples ts[RS::VIEWPORT_MSAA_MAX] = { + const RD::TextureSamples ts[RS::VIEWPORT_MSAA_MAX] = { RD::TEXTURE_SAMPLES_1, RD::TEXTURE_SAMPLES_2, RD::TEXTURE_SAMPLES_4, @@ -977,7 +977,7 @@ void RenderForwardMobile::_render_shadow_end(uint32_t p_barrier) { /* */ -void RenderForwardMobile::_render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) { +void RenderForwardMobile::_render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) { RENDER_TIMESTAMP("Setup Rendering 3D Material"); RD::get_singleton()->draw_command_begin_label("Render 3D Material"); @@ -1441,7 +1441,7 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const distance = -distance_max; } - if (p_render_data->cam_ortogonal) { + if (p_render_data->cam_orthogonal) { distance = 1.0; } diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h index 0ddfe89eea..0a7e973120 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h @@ -214,7 +214,7 @@ protected: virtual void _render_shadow_process() override; virtual void _render_shadow_end(uint32_t p_barrier = RD::BARRIER_MASK_ALL) override; - virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; + virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; virtual void _render_uv2(const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<GeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture) override; virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, const PagedArray<GeometryInstance *> &p_instances) override; diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index fce798e3df..8c727b2512 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -132,9 +132,9 @@ RendererCanvasRender::PolygonID RendererCanvasRenderRD::request_polygon(const Ve buffers.resize(5); { - const uint8_t *r = polygon_buffer.ptr(); - float *fptr = (float *)r; - uint32_t *uptr = (uint32_t *)r; + uint8_t *r = polygon_buffer.ptrw(); + float *fptr = reinterpret_cast<float *>(r); + uint32_t *uptr = reinterpret_cast<uint32_t *>(r); uint32_t base_offset = 0; { //vertices RD::VertexAttribute vd; @@ -1367,6 +1367,8 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p bool update_skeletons = false; bool time_used = false; + bool backbuffer_cleared = false; + while (ci) { if (ci->copy_back_buffer && canvas_group_owner == nullptr) { backbuffer_copy = true; @@ -1416,11 +1418,12 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p if (ci->canvas_group_owner != nullptr) { if (canvas_group_owner == nullptr) { - //Canvas group begins here, render until before this item + // Canvas group begins here, render until before this item if (update_skeletons) { mesh_storage->update_mesh_instances(); update_skeletons = false; } + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list); item_count = 0; @@ -1428,8 +1431,9 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p if (ci->canvas_group_owner->canvas_group->mode == RS::CANVAS_GROUP_MODE_OPAQUE) { texture_storage->render_target_copy_to_back_buffer(p_to_render_target, group_rect, false); - } else { - texture_storage->render_target_clear_back_buffer(p_to_render_target, group_rect, Color(0, 0, 0, 0)); + } else if (!backbuffer_cleared) { + texture_storage->render_target_clear_back_buffer(p_to_render_target, Rect2i(), Color(0, 0, 0, 0)); + backbuffer_cleared = true; } backbuffer_copy = false; @@ -1439,6 +1443,11 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p ci->canvas_group_owner = nullptr; //must be cleared } + if (!backbuffer_cleared && canvas_group_owner == nullptr && ci->canvas_group != nullptr && !backbuffer_copy) { + texture_storage->render_target_clear_back_buffer(p_to_render_target, Rect2i(), Color(0, 0, 0, 0)); + backbuffer_cleared = true; + } + if (ci == canvas_group_owner) { if (update_skeletons) { mesh_storage->update_mesh_instances(); @@ -1461,6 +1470,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p mesh_storage->update_mesh_instances(); update_skeletons = false; } + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list); item_count = 0; @@ -1833,7 +1843,7 @@ void RendererCanvasRenderRD::occluder_polygon_set_shape(RID p_occluder, const Ve { uint8_t *vw = geometry.ptrw(); - float *vwptr = (float *)vw; + float *vwptr = reinterpret_cast<float *>(vw); uint8_t *iw = indices.ptrw(); uint16_t *iwptr = (uint16_t *)iw; diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp index d8b7d5384e..0a16bf4bd1 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp @@ -879,7 +879,7 @@ void RendererSceneGIRD::SDFGI::update_light() { push_constant.process_offset = 0; push_constant.process_increment = 1; } else { - static uint32_t frames_to_update_table[RS::ENV_SDFGI_UPDATE_LIGHT_MAX] = { + static const uint32_t frames_to_update_table[RS::ENV_SDFGI_UPDATE_LIGHT_MAX] = { 1, 2, 4, 8, 16 }; diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index bdbc228bde..b1dab1f02a 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -2391,7 +2391,7 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende float bokeh_size = camfx->dof_blur_amount * 64.0; if (can_use_storage) { - storage->get_effects()->bokeh_dof(buffers, camfx->dof_blur_far_enabled, camfx->dof_blur_far_distance, camfx->dof_blur_far_transition, camfx->dof_blur_near_enabled, camfx->dof_blur_near_distance, camfx->dof_blur_near_transition, bokeh_size, dof_blur_bokeh_shape, dof_blur_quality, dof_blur_use_jitter, p_render_data->z_near, p_render_data->z_far, p_render_data->cam_ortogonal); + storage->get_effects()->bokeh_dof(buffers, camfx->dof_blur_far_enabled, camfx->dof_blur_far_distance, camfx->dof_blur_far_transition, camfx->dof_blur_near_enabled, camfx->dof_blur_near_distance, camfx->dof_blur_near_transition, bokeh_size, dof_blur_bokeh_shape, dof_blur_quality, dof_blur_use_jitter, p_render_data->z_near, p_render_data->z_far, p_render_data->cam_orthogonal); } else { // Set framebuffers. buffers.base_fb = rb->texture_fb; @@ -2406,7 +2406,7 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende // Set weight buffers. buffers.base_weight_fb = rb->base_weight_fb; - storage->get_effects()->bokeh_dof_raster(buffers, camfx->dof_blur_far_enabled, camfx->dof_blur_far_distance, camfx->dof_blur_far_transition, camfx->dof_blur_near_enabled, camfx->dof_blur_near_distance, camfx->dof_blur_near_transition, bokeh_size, dof_blur_bokeh_shape, dof_blur_quality, p_render_data->z_near, p_render_data->z_far, p_render_data->cam_ortogonal); + storage->get_effects()->bokeh_dof_raster(buffers, camfx->dof_blur_far_enabled, camfx->dof_blur_far_distance, camfx->dof_blur_far_transition, camfx->dof_blur_near_enabled, camfx->dof_blur_near_distance, camfx->dof_blur_near_transition, bokeh_size, dof_blur_bokeh_shape, dof_blur_quality, p_render_data->z_near, p_render_data->z_far, p_render_data->cam_orthogonal); } RD::get_singleton()->draw_command_end_label(); } @@ -4998,7 +4998,7 @@ void RendererSceneRenderRD::render_scene(RID p_render_buffers, const CameraData render_data.cam_transform = p_camera_data->main_transform; render_data.cam_projection = p_camera_data->main_projection; render_data.view_projection[0] = p_camera_data->main_projection; - render_data.cam_ortogonal = p_camera_data->is_ortogonal; + render_data.cam_orthogonal = p_camera_data->is_orthogonal; render_data.view_count = p_camera_data->view_count; for (uint32_t v = 0; v < p_camera_data->view_count; v++) { @@ -5327,8 +5327,8 @@ void RendererSceneRenderRD::_render_shadow_pass(RID p_light, RID p_shadow_atlas, } } -void RendererSceneRenderRD::render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) { - _render_material(p_cam_transform, p_cam_projection, p_cam_ortogonal, p_instances, p_framebuffer, p_region); +void RendererSceneRenderRD::render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) { + _render_material(p_cam_transform, p_cam_projection, p_cam_orthogonal, p_instances, p_framebuffer, p_region); } void RendererSceneRenderRD::render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) { diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.h b/servers/rendering/renderer_rd/renderer_scene_render_rd.h index b2c8daffb1..a36df15023 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.h @@ -50,7 +50,7 @@ struct RenderDataRD { Transform3D cam_transform = Transform3D(); CameraMatrix cam_projection = CameraMatrix(); - bool cam_ortogonal = false; + bool cam_orthogonal = false; // For stereo rendering uint32_t view_count = 1; @@ -113,7 +113,7 @@ protected: virtual void _render_shadow_process() = 0; virtual void _render_shadow_end(uint32_t p_barrier = RD::BARRIER_MASK_ALL) = 0; - virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) = 0; + virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) = 0; virtual void _render_uv2(const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) = 0; virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<GeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture) = 0; virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, const PagedArray<GeometryInstance *> &p_instances) = 0; @@ -1411,7 +1411,7 @@ public: virtual void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, const PagedArray<RID> &p_fog_volumes, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_mesh_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr, RendererScene::RenderInfo *r_render_info = nullptr) override; - virtual void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; + virtual void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; virtual void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) override; diff --git a/servers/rendering/renderer_rd/shaders/canvas.glsl b/servers/rendering/renderer_rd/shaders/canvas.glsl index fbc641ee9e..f8e9020f9f 100644 --- a/servers/rendering/renderer_rd/shaders/canvas.glsl +++ b/servers/rendering/renderer_rd/shaders/canvas.glsl @@ -461,10 +461,6 @@ float msdf_median(float r, float g, float b, float a) { return min(max(min(r, g), min(max(r, g), b)), a); } -vec2 msdf_map(vec2 value, vec2 in_min, vec2 in_max, vec2 out_min, vec2 out_max) { - return out_min + (out_max - out_min) * (value - in_min) / (in_max - in_min); -} - void main() { vec4 color = color_interp; vec2 uv = uv_interp; diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp index 75c502c666..d939a0d641 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp @@ -339,7 +339,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } } break; case ShaderLanguage::TYPE_FLOAT: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); if (p_array_size > 0) { const PackedFloat32Array &a = value; @@ -361,7 +361,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } } break; case ShaderLanguage::TYPE_VEC2: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); if (p_array_size > 0) { const PackedVector2Array &a = value; @@ -385,7 +385,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } } break; case ShaderLanguage::TYPE_VEC3: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); if (p_array_size > 0) { const PackedVector3Array &a = value; @@ -411,7 +411,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } } break; case ShaderLanguage::TYPE_VEC4: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); if (p_array_size > 0) { if (value.get_type() == Variant::PACKED_COLOR_ARRAY) { @@ -491,7 +491,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } } break; case ShaderLanguage::TYPE_MAT2: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); if (p_array_size > 0) { const PackedFloat32Array &a = value; @@ -532,7 +532,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } } break; case ShaderLanguage::TYPE_MAT3: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); if (p_array_size > 0) { const PackedFloat32Array &a = value; @@ -587,7 +587,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } } break; case ShaderLanguage::TYPE_MAT4: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); if (p_array_size > 0) { const PackedFloat32Array &a = value; @@ -748,12 +748,12 @@ _FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type, } } break; case ShaderLanguage::TYPE_FLOAT: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); gui[0] = value[0].real; } break; case ShaderLanguage::TYPE_VEC2: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); for (int i = 0; i < 2; i++) { gui[i] = value[i].real; @@ -761,7 +761,7 @@ _FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type, } break; case ShaderLanguage::TYPE_VEC3: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); for (int i = 0; i < 3; i++) { gui[i] = value[i].real; @@ -769,14 +769,14 @@ _FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type, } break; case ShaderLanguage::TYPE_VEC4: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); for (int i = 0; i < 4; i++) { gui[i] = value[i].real; } } break; case ShaderLanguage::TYPE_MAT2: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); //in std140 members of mat2 are treated as vec4s gui[0] = value[0].real; @@ -789,7 +789,7 @@ _FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type, gui[7] = 0; } break; case ShaderLanguage::TYPE_MAT3: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); gui[0] = value[0].real; gui[1] = value[1].real; @@ -805,7 +805,7 @@ _FORCE_INLINE_ static void _fill_std140_ubo_value(ShaderLanguage::DataType type, gui[11] = 0; } break; case ShaderLanguage::TYPE_MAT4: { - float *gui = (float *)data; + float *gui = reinterpret_cast<float *>(data); for (int i = 0; i < 16; i++) { gui[i] = value[i].real; @@ -1885,7 +1885,7 @@ void MaterialStorage::global_variable_remove(const StringName &p_name) { if (!global_variables.variables.has(p_name)) { return; } - GlobalVariables::Variable &gv = global_variables.variables[p_name]; + const GlobalVariables::Variable &gv = global_variables.variables[p_name]; if (gv.buffer_index >= 0) { global_variables.buffer_usage[gv.buffer_index].elements = 0; @@ -2110,7 +2110,7 @@ void MaterialStorage::global_variables_instance_update(RID p_instance, int p_ind ERR_FAIL_INDEX(p_index, ShaderLanguage::MAX_INSTANCE_UNIFORM_INDICES); ERR_FAIL_COND_MSG(p_value.get_type() > Variant::COLOR, "Unsupported variant type for instance parameter: " + Variant::get_type_name(p_value.get_type())); //anything greater not supported - ShaderLanguage::DataType datatype_from_value[Variant::COLOR + 1] = { + const ShaderLanguage::DataType datatype_from_value[Variant::COLOR + 1] = { ShaderLanguage::TYPE_MAX, //nil ShaderLanguage::TYPE_BOOL, //bool ShaderLanguage::TYPE_INT, //int diff --git a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp index 8c60264ce3..0f74c591c6 100644 --- a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp @@ -50,7 +50,7 @@ MeshStorage::MeshStorage() { buffer.resize(sizeof(float) * 3); { uint8_t *w = buffer.ptrw(); - float *fptr = (float *)w; + float *fptr = reinterpret_cast<float *>(w); fptr[0] = 0.0; fptr[1] = 0.0; fptr[2] = 0.0; @@ -62,7 +62,7 @@ MeshStorage::MeshStorage() { buffer.resize(sizeof(float) * 3); { uint8_t *w = buffer.ptrw(); - float *fptr = (float *)w; + float *fptr = reinterpret_cast<float *>(w); fptr[0] = 1.0; fptr[1] = 0.0; fptr[2] = 0.0; @@ -74,7 +74,7 @@ MeshStorage::MeshStorage() { buffer.resize(sizeof(float) * 4); { uint8_t *w = buffer.ptrw(); - float *fptr = (float *)w; + float *fptr = reinterpret_cast<float *>(w); fptr[0] = 1.0; fptr[1] = 0.0; fptr[2] = 0.0; @@ -87,7 +87,7 @@ MeshStorage::MeshStorage() { buffer.resize(sizeof(float) * 4); { uint8_t *w = buffer.ptrw(); - float *fptr = (float *)w; + float *fptr = reinterpret_cast<float *>(w); fptr[0] = 1.0; fptr[1] = 1.0; fptr[2] = 1.0; @@ -100,7 +100,7 @@ MeshStorage::MeshStorage() { buffer.resize(sizeof(float) * 2); { uint8_t *w = buffer.ptrw(); - float *fptr = (float *)w; + float *fptr = reinterpret_cast<float *>(w); fptr[0] = 0.0; fptr[1] = 0.0; } @@ -110,7 +110,7 @@ MeshStorage::MeshStorage() { buffer.resize(sizeof(float) * 2); { uint8_t *w = buffer.ptrw(); - float *fptr = (float *)w; + float *fptr = reinterpret_cast<float *>(w); fptr[0] = 0.0; fptr[1] = 0.0; } @@ -121,7 +121,7 @@ MeshStorage::MeshStorage() { buffer.resize(sizeof(float) * 4); { uint8_t *w = buffer.ptrw(); - float *fptr = (float *)w; + float *fptr = reinterpret_cast<float *>(w); fptr[0] = 0.0; fptr[1] = 0.0; fptr[2] = 0.0; @@ -134,7 +134,7 @@ MeshStorage::MeshStorage() { buffer.resize(sizeof(uint32_t) * 4); { uint8_t *w = buffer.ptrw(); - uint32_t *fptr = (uint32_t *)w; + uint32_t *fptr = reinterpret_cast<uint32_t *>(w); fptr[0] = 0; fptr[1] = 0; fptr[2] = 0; @@ -147,7 +147,7 @@ MeshStorage::MeshStorage() { buffer.resize(sizeof(float) * 4); { uint8_t *w = buffer.ptrw(); - float *fptr = (float *)w; + float *fptr = reinterpret_cast<float *>(w); fptr[0] = 0.0; fptr[1] = 0.0; fptr[2] = 0.0; @@ -284,9 +284,9 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) case RS::ARRAY_CUSTOM2: case RS::ARRAY_CUSTOM3: { int idx = i - RS::ARRAY_CUSTOM0; - uint32_t fmt_shift[RS::ARRAY_CUSTOM_COUNT] = { RS::ARRAY_FORMAT_CUSTOM0_SHIFT, RS::ARRAY_FORMAT_CUSTOM1_SHIFT, RS::ARRAY_FORMAT_CUSTOM2_SHIFT, RS::ARRAY_FORMAT_CUSTOM3_SHIFT }; + const uint32_t fmt_shift[RS::ARRAY_CUSTOM_COUNT] = { RS::ARRAY_FORMAT_CUSTOM0_SHIFT, RS::ARRAY_FORMAT_CUSTOM1_SHIFT, RS::ARRAY_FORMAT_CUSTOM2_SHIFT, RS::ARRAY_FORMAT_CUSTOM3_SHIFT }; uint32_t fmt = (p_surface.format >> fmt_shift[idx]) & RS::ARRAY_FORMAT_CUSTOM_MASK; - uint32_t fmtsize[RS::ARRAY_CUSTOM_MAX] = { 4, 4, 4, 8, 4, 8, 12, 16 }; + const uint32_t fmtsize[RS::ARRAY_CUSTOM_MAX] = { 4, 4, 4, 8, 4, 8, 12, 16 }; attrib_stride += fmtsize[fmt]; } break; @@ -1098,10 +1098,10 @@ void MeshStorage::_mesh_surface_generate_version_for_input_mask(Mesh::Surface::V vd.offset = attribute_stride; int idx = i - RS::ARRAY_CUSTOM0; - uint32_t fmt_shift[RS::ARRAY_CUSTOM_COUNT] = { RS::ARRAY_FORMAT_CUSTOM0_SHIFT, RS::ARRAY_FORMAT_CUSTOM1_SHIFT, RS::ARRAY_FORMAT_CUSTOM2_SHIFT, RS::ARRAY_FORMAT_CUSTOM3_SHIFT }; + const uint32_t fmt_shift[RS::ARRAY_CUSTOM_COUNT] = { RS::ARRAY_FORMAT_CUSTOM0_SHIFT, RS::ARRAY_FORMAT_CUSTOM1_SHIFT, RS::ARRAY_FORMAT_CUSTOM2_SHIFT, RS::ARRAY_FORMAT_CUSTOM3_SHIFT }; uint32_t fmt = (s->format >> fmt_shift[idx]) & RS::ARRAY_FORMAT_CUSTOM_MASK; - uint32_t fmtsize[RS::ARRAY_CUSTOM_MAX] = { 4, 4, 4, 8, 4, 8, 12, 16 }; - RD::DataFormat fmtrd[RS::ARRAY_CUSTOM_MAX] = { RD::DATA_FORMAT_R8G8B8A8_UNORM, RD::DATA_FORMAT_R8G8B8A8_SNORM, RD::DATA_FORMAT_R16G16_SFLOAT, RD::DATA_FORMAT_R16G16B16A16_SFLOAT, RD::DATA_FORMAT_R32_SFLOAT, RD::DATA_FORMAT_R32G32_SFLOAT, RD::DATA_FORMAT_R32G32B32_SFLOAT, RD::DATA_FORMAT_R32G32B32A32_SFLOAT }; + const uint32_t fmtsize[RS::ARRAY_CUSTOM_MAX] = { 4, 4, 4, 8, 4, 8, 12, 16 }; + const RD::DataFormat fmtrd[RS::ARRAY_CUSTOM_MAX] = { RD::DATA_FORMAT_R8G8B8A8_UNORM, RD::DATA_FORMAT_R8G8B8A8_SNORM, RD::DATA_FORMAT_R16G16_SFLOAT, RD::DATA_FORMAT_R16G16B16A16_SFLOAT, RD::DATA_FORMAT_R32_SFLOAT, RD::DATA_FORMAT_R32G32_SFLOAT, RD::DATA_FORMAT_R32G32B32_SFLOAT, RD::DATA_FORMAT_R32G32B32A32_SFLOAT }; vd.format = fmtrd[fmt]; attribute_stride += fmtsize[fmt]; buffer = s->attribute_buffer; @@ -1238,7 +1238,7 @@ void MeshStorage::multimesh_set_mesh(RID p_multimesh, RID p_mesh) { if (multimesh->buffer_set) { Vector<uint8_t> buffer = RD::get_singleton()->buffer_get_data(multimesh->buffer); const uint8_t *r = buffer.ptr(); - const float *data = (const float *)r; + const float *data = reinterpret_cast<const float *>(r); _multimesh_re_create_aabb(multimesh, data, multimesh->instances); } } diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp index 75dd20bdbd..402536de88 100644 --- a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp @@ -1722,7 +1722,7 @@ RID ParticlesStorage::particles_collision_get_heightfield_framebuffer(RID p_part if (particles_collision->heightfield_texture == RID()) { //create - int resolutions[RS::PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_MAX] = { 256, 512, 1024, 2048, 4096, 8192 }; + const int resolutions[RS::PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_MAX] = { 256, 512, 1024, 2048, 4096, 8192 }; Size2i size; if (particles_collision->extents.x > particles_collision->extents.z) { size.x = resolutions[particles_collision->heightfield_resolution]; diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp index 55193a45f0..528f381139 100644 --- a/servers/rendering/renderer_scene_cull.cpp +++ b/servers/rendering/renderer_scene_cull.cpp @@ -2444,7 +2444,7 @@ void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_ Transform3D transform = camera->transform; CameraMatrix projection; bool vaspect = camera->vaspect; - bool is_ortogonal = false; + bool is_orthogonal = false; switch (camera->type) { case Camera::ORTHOGONAL: { @@ -2454,7 +2454,7 @@ void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_ camera->znear, camera->zfar, camera->vaspect); - is_ortogonal = true; + is_orthogonal = true; } break; case Camera::PERSPECTIVE: { projection.set_perspective( @@ -2476,7 +2476,7 @@ void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_ } break; } - camera_data.set_camera(transform, projection, is_ortogonal, vaspect); + camera_data.set_camera(transform, projection, is_orthogonal, vaspect); } else { // Setup our camera for our XR interface. // We can support multiple views here each with their own camera @@ -2510,7 +2510,7 @@ void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_ RENDER_TIMESTAMP("Update Occlusion Buffer") // For now just cull on the first camera - RendererSceneOcclusionCull::get_singleton()->buffer_update(p_viewport, camera_data.main_transform, camera_data.main_projection, camera_data.is_ortogonal, RendererThreadPool::singleton->thread_work_pool); + RendererSceneOcclusionCull::get_singleton()->buffer_update(p_viewport, camera_data.main_transform, camera_data.main_projection, camera_data.is_orthogonal, RendererThreadPool::singleton->thread_work_pool); _render_scene(&camera_data, p_render_buffers, environment, camera->effects, camera->visible_layers, p_scenario, p_viewport, p_shadow_atlas, RID(), -1, p_screen_mesh_lod_threshold, true, r_render_info); #endif @@ -2920,7 +2920,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c RENDER_TIMESTAMP("Cull 3D Scene"); - //rasterizer->set_camera(p_camera_data->main_transform, p_camera_data.main_projection, p_camera_data.is_ortogonal); + //rasterizer->set_camera(p_camera_data->main_transform, p_camera_data.main_projection, p_camera_data.is_orthogonal); /* STEP 2 - CULL */ @@ -2959,7 +2959,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c scene_render->set_directional_shadow_count(lights_with_shadow.size()); for (int i = 0; i < lights_with_shadow.size(); i++) { - _light_instance_setup_directional_shadow(i, lights_with_shadow[i], p_camera_data->main_transform, p_camera_data->main_projection, p_camera_data->is_ortogonal, p_camera_data->vaspect); + _light_instance_setup_directional_shadow(i, lights_with_shadow[i], p_camera_data->main_transform, p_camera_data->main_projection, p_camera_data->is_orthogonal, p_camera_data->vaspect); } } @@ -3097,7 +3097,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c ins->transform.origin + cam_xf.basis.get_axis(0) * radius }; - if (!p_camera_data->is_ortogonal) { + if (!p_camera_data->is_orthogonal) { //if using perspetive, map them to near plane for (int j = 0; j < 2; j++) { if (p.distance_to(points[j]) < 0) { @@ -3125,7 +3125,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c base + cam_xf.basis.get_axis(0) * w }; - if (!p_camera_data->is_ortogonal) { + if (!p_camera_data->is_orthogonal) { //if using perspetive, map them to near plane for (int j = 0; j < 2; j++) { if (p.distance_to(points[j]) < 0) { @@ -3156,7 +3156,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c if (redraw && max_shadows_used < MAX_UPDATE_SHADOWS) { //must redraw! RENDER_TIMESTAMP("> Render Light3D " + itos(i)); - light->shadow_dirty = _light_instance_update_shadow(ins, p_camera_data->main_transform, p_camera_data->main_projection, p_camera_data->is_ortogonal, p_camera_data->vaspect, p_shadow_atlas, scenario, p_screen_mesh_lod_threshold); + light->shadow_dirty = _light_instance_update_shadow(ins, p_camera_data->main_transform, p_camera_data->main_projection, p_camera_data->is_orthogonal, p_camera_data->vaspect, p_shadow_atlas, scenario, p_screen_mesh_lod_threshold); RENDER_TIMESTAMP("< Render Light3D " + itos(i)); } else { light->shadow_dirty = redraw; @@ -3229,7 +3229,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c render_sdfgi_data[i].instances.clear(); } - // virtual void render_scene(RID p_render_buffers, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_mesh_lod_threshold,const RenderShadowData *p_render_shadows,int p_render_shadow_count,const RenderSDFGIData *p_render_sdfgi_regions,int p_render_sdfgi_region_count,const RenderSDFGIStaticLightData *p_render_sdfgi_static_lights=nullptr) = 0; + // virtual void render_scene(RID p_render_buffers, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_mesh_lod_threshold,const RenderShadowData *p_render_shadows,int p_render_shadow_count,const RenderSDFGIData *p_render_sdfgi_regions,int p_render_sdfgi_region_count,const RenderSDFGIStaticLightData *p_render_sdfgi_static_lights=nullptr) = 0; } RID RendererSceneCull::_render_get_environment(RID p_camera, RID p_scenario) { diff --git a/servers/rendering/renderer_scene_render.cpp b/servers/rendering/renderer_scene_render.cpp index c802f72fdf..fadece317a 100644 --- a/servers/rendering/renderer_scene_render.cpp +++ b/servers/rendering/renderer_scene_render.cpp @@ -30,9 +30,9 @@ #include "renderer_scene_render.h" -void RendererSceneRender::CameraData::set_camera(const Transform3D p_transform, const CameraMatrix p_projection, bool p_is_ortogonal, bool p_vaspect) { +void RendererSceneRender::CameraData::set_camera(const Transform3D p_transform, const CameraMatrix p_projection, bool p_is_orthogonal, bool p_vaspect) { view_count = 1; - is_ortogonal = p_is_ortogonal; + is_orthogonal = p_is_orthogonal; vaspect = p_vaspect; main_transform = p_transform; @@ -42,11 +42,11 @@ void RendererSceneRender::CameraData::set_camera(const Transform3D p_transform, view_projection[0] = p_projection; } -void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count, const Transform3D *p_transforms, const CameraMatrix *p_projections, bool p_is_ortogonal, bool p_vaspect) { +void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count, const Transform3D *p_transforms, const CameraMatrix *p_projections, bool p_is_orthogonal, bool p_vaspect) { ERR_FAIL_COND_MSG(p_view_count != 2, "Incorrect view count for stereoscopic view"); view_count = p_view_count; - is_ortogonal = p_is_ortogonal; + is_orthogonal = p_is_orthogonal; vaspect = p_vaspect; Vector<Plane> planes[2]; diff --git a/servers/rendering/renderer_scene_render.h b/servers/rendering/renderer_scene_render.h index 0b8734e68c..d43bfb170e 100644 --- a/servers/rendering/renderer_scene_render.h +++ b/servers/rendering/renderer_scene_render.h @@ -234,7 +234,7 @@ public: struct CameraData { // flags uint32_t view_count; - bool is_ortogonal; + bool is_orthogonal; bool vaspect; // Main/center projection @@ -244,13 +244,13 @@ public: Transform3D view_offset[RendererSceneRender::MAX_RENDER_VIEWS]; CameraMatrix view_projection[RendererSceneRender::MAX_RENDER_VIEWS]; - void set_camera(const Transform3D p_transform, const CameraMatrix p_projection, bool p_is_ortogonal, bool p_vaspect); - void set_multiview_camera(uint32_t p_view_count, const Transform3D *p_transforms, const CameraMatrix *p_projections, bool p_is_ortogonal, bool p_vaspect); + void set_camera(const Transform3D p_transform, const CameraMatrix p_projection, bool p_is_orthogonal, bool p_vaspect); + void set_multiview_camera(uint32_t p_view_count, const Transform3D *p_transforms, const CameraMatrix *p_projections, bool p_is_orthogonal, bool p_vaspect); }; virtual void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, const PagedArray<RID> &p_fog_volumes, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_mesh_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr, RendererScene::RenderInfo *r_render_info = nullptr) = 0; - virtual void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) = 0; + virtual void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) = 0; virtual void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) = 0; virtual void set_scene_pass(uint64_t p_pass) = 0; diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 816a02761d..54d1a6fd8d 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -3467,7 +3467,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C } value = Variant(array); } else { - value = Variant(Plane(p_value[0].sint, p_value[1].sint, p_value[2].sint, p_value[3].sint)); + value = Variant(Quaternion(p_value[0].sint, p_value[1].sint, p_value[2].sint, p_value[3].sint)); } break; case ShaderLanguage::TYPE_UINT: @@ -3517,7 +3517,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C } value = Variant(array); } else { - value = Variant(Plane(p_value[0].uint, p_value[1].uint, p_value[2].uint, p_value[3].uint)); + value = Variant(Quaternion(p_value[0].uint, p_value[1].uint, p_value[2].uint, p_value[3].uint)); } break; case ShaderLanguage::TYPE_FLOAT: @@ -3581,7 +3581,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { value = Variant(Color(p_value[0].real, p_value[1].real, p_value[2].real, p_value[3].real)); } else { - value = Variant(Plane(p_value[0].real, p_value[1].real, p_value[2].real, p_value[3].real)); + value = Variant(Quaternion(p_value[0].real, p_value[1].real, p_value[2].real, p_value[3].real)); } } break; @@ -3776,7 +3776,7 @@ PropertyInfo ShaderLanguage::uniform_to_property_info(const ShaderNode::Uniform if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { pi.type = Variant::COLOR; } else { - pi.type = Variant::PLANE; + pi.type = Variant::QUATERNION; } } } break; @@ -4670,16 +4670,18 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons expr = _parse_array_constructor(p_block, p_function_info); } else { DataType datatype; - DataPrecision precision; - bool precision_defined = false; + DataPrecision precision = PRECISION_DEFAULT; if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); - precision_defined = true; tk = _get_token(); } datatype = get_token_datatype(tk.type); + if (precision != PRECISION_DEFAULT && _validate_precision(datatype, precision) != OK) { + return nullptr; + } + tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { @@ -4697,7 +4699,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons OperatorNode *func = alloc_node<OperatorNode>(); func->op = OP_CONSTRUCT; - if (precision_defined) { + if (precision != PRECISION_DEFAULT) { func->return_precision_cache = precision; } @@ -6426,10 +6428,6 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun if (!is_struct) { is_struct = shader->structs.has(tk.text); // check again. } - if (is_struct && precision != PRECISION_DEFAULT) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } if (!is_token_nonvoid_datatype(tk.type)) { _set_error(RTR("Expected variable type after precision modifier.")); return ERR_PARSE_ERROR; @@ -6449,6 +6447,10 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } + if (precision != PRECISION_DEFAULT && _validate_precision(type, precision) != OK) { + return ERR_PARSE_ERROR; + } + int array_size = 0; bool fixed_array_size = false; bool first = true; @@ -6600,10 +6602,6 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun if (is_token_precision(tk.type)) { precision2 = get_token_precision(tk.type); tk = _get_token(); - if (shader->structs.has(tk.text)) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } if (!is_token_nonvoid_datatype(tk.type)) { _set_error(RTR("Expected data type after precision modifier.")); return ERR_PARSE_ERROR; @@ -6624,6 +6622,10 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun type2 = get_token_datatype(tk.type); } + if (precision2 != PRECISION_DEFAULT && _validate_precision(type2, precision2) != OK) { + return ERR_PARSE_ERROR; + } + int array_size2 = 0; tk = _get_token(); @@ -7427,6 +7429,25 @@ String ShaderLanguage::_get_qualifier_str(ArgumentQualifier p_qualifier) const { return ""; } +Error ShaderLanguage::_validate_precision(DataType p_type, DataPrecision p_precision) { + switch (p_type) { + case TYPE_STRUCT: { + _set_error(RTR("The precision modifier cannot be used on structs.")); + return FAILED; + } break; + case TYPE_BOOL: + case TYPE_BVEC2: + case TYPE_BVEC3: + case TYPE_BVEC4: { + _set_error(RTR("The precision modifier cannot be used on boolean types.")); + return FAILED; + } break; + default: + break; + } + return OK; +} + Error ShaderLanguage::_validate_datatype(DataType p_type) { if (RenderingServer::get_singleton()->is_low_end()) { bool invalid_type = false; @@ -7608,8 +7629,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } StringName struct_name = ""; bool struct_dt = false; - bool use_precision = false; - DataPrecision precision = DataPrecision::PRECISION_DEFAULT; + DataPrecision precision = PRECISION_DEFAULT; if (tk.type == TK_STRUCT) { _set_error(RTR("Nested structs are not allowed.")); @@ -7618,7 +7638,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); - use_precision = true; tk = _get_token(); } @@ -7630,10 +7649,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } #endif // DEBUG_ENABLED struct_dt = true; - if (use_precision) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } } if (!is_token_datatype(tk.type) && !struct_dt) { @@ -7642,6 +7657,10 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } else { type = struct_dt ? TYPE_STRUCT : get_token_datatype(tk.type); + if (precision != PRECISION_DEFAULT && _validate_precision(type, precision) != OK) { + return ERR_PARSE_ERROR; + } + if (type == TYPE_VOID || is_sampler_type(type)) { _set_error(vformat(RTR("A '%s' data type is not allowed here."), get_datatype_name(type))); return ERR_PARSE_ERROR; @@ -7762,7 +7781,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } } - bool precision_defined = false; DataPrecision precision = PRECISION_DEFAULT; DataInterpolation interpolation = INTERPOLATION_SMOOTH; DataType type; @@ -7781,16 +7799,11 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); - precision_defined = true; tk = _get_token(); } if (shader->structs.has(tk.text)) { if (uniform) { - if (precision_defined) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } _set_error(vformat(RTR("The '%s' data type is not supported for uniforms."), "struct")); return ERR_PARSE_ERROR; } else { @@ -7806,6 +7819,10 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct type = get_token_datatype(tk.type); + if (precision != PRECISION_DEFAULT && _validate_precision(type, precision) != OK) { + return ERR_PARSE_ERROR; + } + if (type == TYPE_VOID) { _set_error(vformat(RTR("The '%s' data type is not allowed here."), "void")); return ERR_PARSE_ERROR; @@ -8249,10 +8266,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } if (shader->structs.has(tk.text)) { - if (precision != PRECISION_DEFAULT) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } is_struct = true; struct_name = tk.text; } else { @@ -8276,6 +8289,11 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } else { type = get_token_datatype(tk.type); } + + if (precision != PRECISION_DEFAULT && _validate_precision(type, precision) != OK) { + return ERR_PARSE_ERROR; + } + prev_pos = _get_tkpos(); tk = _get_token(); @@ -8652,44 +8670,41 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct break; } - bool is_const = false; + bool param_is_const = false; if (tk.type == TK_CONST) { - is_const = true; + param_is_const = true; tk = _get_token(); } - ArgumentQualifier qualifier = ARGUMENT_QUALIFIER_IN; - + ArgumentQualifier param_qualifier = ARGUMENT_QUALIFIER_IN; if (tk.type == TK_ARG_IN) { - qualifier = ARGUMENT_QUALIFIER_IN; + param_qualifier = ARGUMENT_QUALIFIER_IN; tk = _get_token(); } else if (tk.type == TK_ARG_OUT) { - if (is_const) { + if (param_is_const) { _set_error(vformat(RTR("The '%s' qualifier cannot be used within a function parameter declared with '%s'."), "out", "const")); return ERR_PARSE_ERROR; } - qualifier = ARGUMENT_QUALIFIER_OUT; + param_qualifier = ARGUMENT_QUALIFIER_OUT; tk = _get_token(); } else if (tk.type == TK_ARG_INOUT) { - if (is_const) { + if (param_is_const) { _set_error(vformat(RTR("The '%s' qualifier cannot be used within a function parameter declared with '%s'."), "inout", "const")); return ERR_PARSE_ERROR; } - qualifier = ARGUMENT_QUALIFIER_INOUT; + param_qualifier = ARGUMENT_QUALIFIER_INOUT; tk = _get_token(); } - DataType ptype; - StringName pname; + DataType param_type; + StringName param_name; StringName param_struct_name; - DataPrecision pprecision = PRECISION_DEFAULT; - bool use_precision = false; + DataPrecision param_precision = PRECISION_DEFAULT; int arg_array_size = 0; if (is_token_precision(tk.type)) { - pprecision = get_token_precision(tk.type); + param_precision = get_token_precision(tk.type); tk = _get_token(); - use_precision = true; } is_struct = false; @@ -8702,10 +8717,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct used_structs[param_struct_name].used = true; } #endif // DEBUG_ENABLED - if (use_precision) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } } if (!is_struct && !is_token_datatype(tk.type)) { @@ -8713,7 +8724,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } - if (qualifier == ARGUMENT_QUALIFIER_OUT || qualifier == ARGUMENT_QUALIFIER_INOUT) { + if (param_qualifier == ARGUMENT_QUALIFIER_OUT || param_qualifier == ARGUMENT_QUALIFIER_INOUT) { if (is_sampler_type(get_token_datatype(tk.type))) { _set_error(RTR("Opaque types cannot be output parameters.")); return ERR_PARSE_ERROR; @@ -8721,18 +8732,22 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } if (is_struct) { - ptype = TYPE_STRUCT; + param_type = TYPE_STRUCT; } else { - ptype = get_token_datatype(tk.type); - if (_validate_datatype(ptype) != OK) { + param_type = get_token_datatype(tk.type); + if (_validate_datatype(param_type) != OK) { return ERR_PARSE_ERROR; } - if (ptype == TYPE_VOID) { + if (param_type == TYPE_VOID) { _set_error(RTR("Void type not allowed as argument.")); return ERR_PARSE_ERROR; } } + if (param_precision != PRECISION_DEFAULT && _validate_precision(param_type, param_precision) != OK) { + return ERR_PARSE_ERROR; + } + tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { @@ -8747,32 +8762,32 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } - pname = tk.text; + param_name = tk.text; ShaderLanguage::IdentifierType itype; - if (_find_identifier(func_node->body, false, builtins, pname, (ShaderLanguage::DataType *)nullptr, &itype)) { + if (_find_identifier(func_node->body, false, builtins, param_name, (ShaderLanguage::DataType *)nullptr, &itype)) { if (itype != IDENTIFIER_FUNCTION) { - _set_redefinition_error(String(pname)); + _set_redefinition_error(String(param_name)); return ERR_PARSE_ERROR; } } - if (has_builtin(p_functions, pname)) { - _set_redefinition_error(String(pname)); + if (has_builtin(p_functions, param_name)) { + _set_redefinition_error(String(param_name)); return ERR_PARSE_ERROR; } FunctionNode::Argument arg; - arg.type = ptype; - arg.name = pname; + arg.type = param_type; + arg.name = param_name; arg.type_str = param_struct_name; - arg.precision = pprecision; - arg.qualifier = qualifier; + arg.precision = param_precision; + arg.qualifier = param_qualifier; arg.tex_argument_check = false; arg.tex_builtin_check = false; arg.tex_argument_filter = FILTER_DEFAULT; arg.tex_argument_repeat = REPEAT_DEFAULT; - arg.is_const = is_const; + arg.is_const = param_is_const; tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index 66ae220edf..de6d912a4f 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -1038,6 +1038,7 @@ private: static bool is_const_suffix_lut_initialized; + Error _validate_precision(DataType p_type, DataPrecision p_precision); Error _validate_datatype(DataType p_type); bool _compare_datatypes(DataType p_datatype_a, String p_datatype_name_a, int p_array_size_a, DataType p_datatype_b, String p_datatype_name_b, int p_array_size_b); bool _compare_datatypes_in_nodes(Node *a, Node *b); diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index b58e6138eb..c2a6b83485 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -424,7 +424,7 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint value |= CLAMP(int((src[i * 4 + 1] * 0.5 + 0.5) * 1023.0), 0, 1023) << 10; value |= CLAMP(int((src[i * 4 + 2] * 0.5 + 0.5) * 1023.0), 0, 1023) << 20; if (src[i * 4 + 3] > 0) { - value |= 3 << 30; + value |= 3UL << 30; } memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], &value, 4); @@ -440,7 +440,7 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint value |= CLAMP(int((src[i * 4 + 1] * 0.5 + 0.5) * 1023.0), 0, 1023) << 10; value |= CLAMP(int((src[i * 4 + 2] * 0.5 + 0.5) * 1023.0), 0, 1023) << 20; if (src[i * 4 + 3] > 0) { - value |= 3 << 30; + value |= 3UL << 30; } memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], &value, 4); } @@ -1093,7 +1093,7 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t Vector2 *w = arr_2d.ptrw(); for (int j = 0; j < p_vertex_len; j++) { - const float *v = (const float *)&r[j * vertex_elem_size + offsets[i]]; + const float *v = reinterpret_cast<const float *>(&r[j * vertex_elem_size + offsets[i]]); w[j] = Vector2(v[0], v[1]); } } @@ -1107,7 +1107,7 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t Vector3 *w = arr_3d.ptrw(); for (int j = 0; j < p_vertex_len; j++) { - const float *v = (const float *)&r[j * vertex_elem_size + offsets[i]]; + const float *v = reinterpret_cast<const float *>(&r[j * vertex_elem_size + offsets[i]]); w[j] = Vector3(v[0], v[1], v[2]); } } @@ -1156,7 +1156,7 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t Color *w = arr.ptrw(); for (int32_t j = 0; j < p_vertex_len; j++) { - const uint8_t *v = (const uint8_t *)&ar[j * attrib_elem_size + offsets[i]]; + const uint8_t *v = reinterpret_cast<const uint8_t *>(&ar[j * attrib_elem_size + offsets[i]]); w[j] = Color(v[0] / 255.0, v[1] / 255.0, v[2] / 255.0, v[3] / 255.0); } @@ -1170,7 +1170,7 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t Vector2 *w = arr.ptrw(); for (int j = 0; j < p_vertex_len; j++) { - const float *v = (const float *)&ar[j * attrib_elem_size + offsets[i]]; + const float *v = reinterpret_cast<const float *>(&ar[j * attrib_elem_size + offsets[i]]); w[j] = Vector2(v[0], v[1]); } @@ -1184,7 +1184,7 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t Vector2 *w = arr.ptrw(); for (int j = 0; j < p_vertex_len; j++) { - const float *v = (const float *)&ar[j * attrib_elem_size + offsets[i]]; + const float *v = reinterpret_cast<const float *>(&ar[j * attrib_elem_size + offsets[i]]); w[j] = Vector2(v[0], v[1]); } @@ -1209,7 +1209,7 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t uint8_t *w = arr.ptrw(); for (int j = 0; j < p_vertex_len; j++) { - const uint8_t *v = (const uint8_t *)&ar[j * attrib_elem_size + offsets[i]]; + const uint8_t *v = reinterpret_cast<const uint8_t *>(&ar[j * attrib_elem_size + offsets[i]]); memcpy(&w[j * s], v, s); } @@ -1228,7 +1228,7 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t float *w = arr.ptrw(); for (int j = 0; j < p_vertex_len; j++) { - const float *v = (const float *)&ar[j * attrib_elem_size + offsets[i]]; + const float *v = reinterpret_cast<const float *>(&ar[j * attrib_elem_size + offsets[i]]); memcpy(&w[j * s], v, s * sizeof(float)); } ret[i] = arr; diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp index c8efacc9c5..001706bb6f 100644 --- a/servers/text/text_server_extension.cpp +++ b/servers/text/text_server_extension.cpp @@ -67,6 +67,9 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(font_set_antialiased, "font_rid", "antialiased"); GDVIRTUAL_BIND(font_is_antialiased, "font_rid"); + GDVIRTUAL_BIND(font_set_generate_mipmaps, "font_rid", "generate_mipmaps"); + GDVIRTUAL_BIND(font_get_generate_mipmaps, "font_rid"); + GDVIRTUAL_BIND(font_set_multichannel_signed_distance_field, "font_rid", "msdf"); GDVIRTUAL_BIND(font_is_multichannel_signed_distance_field, "font_rid"); @@ -151,6 +154,9 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(font_get_glyph_texture_idx, "font_rid", "size", "glyph"); GDVIRTUAL_BIND(font_set_glyph_texture_idx, "font_rid", "size", "glyph", "texture_idx"); + GDVIRTUAL_BIND(font_get_glyph_texture_rid, "font_rid", "size", "glyph"); + GDVIRTUAL_BIND(font_get_glyph_texture_size, "font_rid", "size", "glyph"); + GDVIRTUAL_BIND(font_get_glyph_contours, "font_rid", "size", "index"); GDVIRTUAL_BIND(font_get_kerning_list, "font_rid", "size"); @@ -289,6 +295,8 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(string_to_upper, "string", "language"); GDVIRTUAL_BIND(string_to_lower, "string", "language"); + + GDVIRTUAL_BIND(parse_structured_text, "parser_type", "args", "text"); } bool TextServerExtension::has_feature(Feature p_feature) const { @@ -451,6 +459,18 @@ bool TextServerExtension::font_is_antialiased(const RID &p_font_rid) const { return false; } +void TextServerExtension::font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) { + GDVIRTUAL_CALL(font_set_generate_mipmaps, p_font_rid, p_generate_mipmaps); +} + +bool TextServerExtension::font_get_generate_mipmaps(const RID &p_font_rid) const { + bool ret; + if (GDVIRTUAL_CALL(font_get_generate_mipmaps, p_font_rid, ret)) { + return ret; + } + return false; +} + void TextServerExtension::font_set_multichannel_signed_distance_field(const RID &p_font_rid, bool p_msdf) { GDVIRTUAL_CALL(font_set_multichannel_signed_distance_field, p_font_rid, p_msdf); } @@ -787,6 +807,22 @@ void TextServerExtension::font_set_glyph_texture_idx(const RID &p_font_rid, cons GDVIRTUAL_CALL(font_set_glyph_texture_idx, p_font_rid, p_size, p_glyph, p_texture_idx); } +RID TextServerExtension::font_get_glyph_texture_rid(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { + RID ret; + if (GDVIRTUAL_CALL(font_get_glyph_texture_rid, p_font_rid, p_size, p_glyph, ret)) { + return ret; + } + return RID(); +} + +Size2 TextServerExtension::font_get_glyph_texture_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { + Size2 ret; + if (GDVIRTUAL_CALL(font_get_glyph_texture_size, p_font_rid, p_size, p_glyph, ret)) { + return ret; + } + return Size2(); +} + Dictionary TextServerExtension::font_get_glyph_contours(const RID &p_font_rid, int64_t p_size, int64_t p_index) const { Dictionary ret; if (GDVIRTUAL_CALL(font_get_glyph_contours, p_font_rid, p_size, p_index, ret)) { @@ -1459,6 +1495,14 @@ String TextServerExtension::string_to_lower(const String &p_string, const String return p_string; } +Array TextServerExtension::parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const { + Array ret; + if (GDVIRTUAL_CALL(parse_structured_text, p_parser_type, p_args, p_text, ret)) { + return ret; + } + return Array(); +} + TextServerExtension::TextServerExtension() { //NOP } diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h index c6e7bef4e8..ce781097f3 100644 --- a/servers/text/text_server_extension.h +++ b/servers/text/text_server_extension.h @@ -104,6 +104,11 @@ public: GDVIRTUAL2(font_set_antialiased, RID, bool); GDVIRTUAL1RC(bool, font_is_antialiased, RID); + virtual void font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) override; + virtual bool font_get_generate_mipmaps(const RID &p_font_rid) const override; + GDVIRTUAL2(font_set_generate_mipmaps, RID, bool); + GDVIRTUAL1RC(bool, font_get_generate_mipmaps, RID); + virtual void font_set_multichannel_signed_distance_field(const RID &p_font_rid, bool p_msdf) override; virtual bool font_is_multichannel_signed_distance_field(const RID &p_font_rid) const override; GDVIRTUAL2(font_set_multichannel_signed_distance_field, RID, bool); @@ -245,6 +250,12 @@ public: GDVIRTUAL3RC(int64_t, font_get_glyph_texture_idx, RID, const Vector2i &, int64_t); GDVIRTUAL4(font_set_glyph_texture_idx, RID, const Vector2i &, int64_t, int64_t); + virtual RID font_get_glyph_texture_rid(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const override; + GDVIRTUAL3RC(RID, font_get_glyph_texture_rid, RID, const Vector2i &, int64_t); + + virtual Size2 font_get_glyph_texture_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const override; + GDVIRTUAL3RC(Size2, font_get_glyph_texture_size, RID, const Vector2i &, int64_t); + virtual Dictionary font_get_glyph_contours(const RID &p_font, int64_t p_size, int64_t p_index) const override; GDVIRTUAL3RC(Dictionary, font_get_glyph_contours, RID, int64_t, int64_t); @@ -479,6 +490,9 @@ public: GDVIRTUAL2RC(String, string_to_upper, const String &, const String &); GDVIRTUAL2RC(String, string_to_lower, const String &, const String &); + Array parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const; + GDVIRTUAL3RC(Array, parse_structured_text, StructuredTextParser, const Array &, const String &); + TextServerExtension(); ~TextServerExtension(); }; diff --git a/servers/text_server.cpp b/servers/text_server.cpp index 7e3fde6a1f..d66e769e3c 100644 --- a/servers/text_server.cpp +++ b/servers/text_server.cpp @@ -220,6 +220,9 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("font_set_antialiased", "font_rid", "antialiased"), &TextServer::font_set_antialiased); ClassDB::bind_method(D_METHOD("font_is_antialiased", "font_rid"), &TextServer::font_is_antialiased); + ClassDB::bind_method(D_METHOD("font_set_generate_mipmaps", "font_rid", "generate_mipmaps"), &TextServer::font_set_generate_mipmaps); + ClassDB::bind_method(D_METHOD("font_get_generate_mipmaps", "font_rid"), &TextServer::font_get_generate_mipmaps); + ClassDB::bind_method(D_METHOD("font_set_multichannel_signed_distance_field", "font_rid", "msdf"), &TextServer::font_set_multichannel_signed_distance_field); ClassDB::bind_method(D_METHOD("font_is_multichannel_signed_distance_field", "font_rid"), &TextServer::font_is_multichannel_signed_distance_field); @@ -304,6 +307,9 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("font_get_glyph_texture_idx", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_texture_idx); ClassDB::bind_method(D_METHOD("font_set_glyph_texture_idx", "font_rid", "size", "glyph", "texture_idx"), &TextServer::font_set_glyph_texture_idx); + ClassDB::bind_method(D_METHOD("font_get_glyph_texture_rid", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_texture_rid); + ClassDB::bind_method(D_METHOD("font_get_glyph_texture_size", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_texture_size); + ClassDB::bind_method(D_METHOD("font_get_glyph_contours", "font", "size", "index"), &TextServer::font_get_glyph_contours); ClassDB::bind_method(D_METHOD("font_get_kerning_list", "font_rid", "size"), &TextServer::font_get_kerning_list); @@ -438,6 +444,8 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("string_to_upper", "string", "language"), &TextServer::string_to_upper, DEFVAL("")); ClassDB::bind_method(D_METHOD("string_to_lower", "string", "language"), &TextServer::string_to_lower, DEFVAL("")); + ClassDB::bind_method(D_METHOD("parse_structured_text", "parser_type", "args", "text"), &TextServer::parse_structured_text); + /* Direction */ BIND_ENUM_CONSTANT(DIRECTION_AUTO); BIND_ENUM_CONSTANT(DIRECTION_LTR); @@ -526,6 +534,15 @@ void TextServer::_bind_methods() { BIND_ENUM_CONSTANT(FONT_BOLD); BIND_ENUM_CONSTANT(FONT_ITALIC); BIND_ENUM_CONSTANT(FONT_FIXED_WIDTH); + + /* Structured text parser */ + BIND_ENUM_CONSTANT(STRUCTURED_TEXT_DEFAULT); + BIND_ENUM_CONSTANT(STRUCTURED_TEXT_URI); + BIND_ENUM_CONSTANT(STRUCTURED_TEXT_FILE); + BIND_ENUM_CONSTANT(STRUCTURED_TEXT_EMAIL); + BIND_ENUM_CONSTANT(STRUCTURED_TEXT_LIST); + BIND_ENUM_CONSTANT(STRUCTURED_TEXT_NONE); + BIND_ENUM_CONSTANT(STRUCTURED_TEXT_CUSTOM); } Vector2 TextServer::get_hex_code_box_size(int64_t p_size, int64_t p_index) const { @@ -1533,6 +1550,83 @@ String TextServer::strip_diacritics(const String &p_string) const { return result; } +Array TextServer::parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const { + Array ret; + switch (p_parser_type) { + case STRUCTURED_TEXT_URI: { + int prev = 0; + for (int i = 0; i < p_text.length(); i++) { + if ((p_text[i] == '\\') || (p_text[i] == '/') || (p_text[i] == '.') || (p_text[i] == ':') || (p_text[i] == '&') || (p_text[i] == '=') || (p_text[i] == '@') || (p_text[i] == '?') || (p_text[i] == '#')) { + if (prev != i) { + ret.push_back(Vector2i(prev, i)); + } + ret.push_back(Vector2i(i, i + 1)); + prev = i + 1; + } + } + if (prev != p_text.length()) { + ret.push_back(Vector2i(prev, p_text.length())); + } + } break; + case STRUCTURED_TEXT_FILE: { + int prev = 0; + for (int i = 0; i < p_text.length(); i++) { + if ((p_text[i] == '\\') || (p_text[i] == '/') || (p_text[i] == ':')) { + if (prev != i) { + ret.push_back(Vector2i(prev, i)); + } + ret.push_back(Vector2i(i, i + 1)); + prev = i + 1; + } + } + if (prev != p_text.length()) { + ret.push_back(Vector2i(prev, p_text.length())); + } + } break; + case STRUCTURED_TEXT_EMAIL: { + bool local = true; + int prev = 0; + for (int i = 0; i < p_text.length(); i++) { + if ((p_text[i] == '@') && local) { // Add full "local" as single context. + local = false; + ret.push_back(Vector2i(prev, i)); + ret.push_back(Vector2i(i, i + 1)); + prev = i + 1; + } else if (!local & (p_text[i] == '.')) { // Add each dot separated "domain" part as context. + if (prev != i) { + ret.push_back(Vector2i(prev, i)); + } + ret.push_back(Vector2i(i, i + 1)); + prev = i + 1; + } + } + if (prev != p_text.length()) { + ret.push_back(Vector2i(prev, p_text.length())); + } + } break; + case STRUCTURED_TEXT_LIST: { + if (p_args.size() == 1 && p_args[0].get_type() == Variant::STRING) { + Vector<String> tags = p_text.split(String(p_args[0])); + int prev = 0; + for (int i = 0; i < tags.size(); i++) { + if (prev != i) { + ret.push_back(Vector2i(prev, prev + tags[i].length())); + } + ret.push_back(Vector2i(prev + tags[i].length(), prev + tags[i].length() + 1)); + prev = prev + tags[i].length() + 1; + } + } + } break; + case STRUCTURED_TEXT_CUSTOM: + case STRUCTURED_TEXT_NONE: + case STRUCTURED_TEXT_DEFAULT: + default: { + ret.push_back(Vector2i(0, p_text.length())); + } + } + return ret; +} + Array TextServer::_shaped_text_get_glyphs_wrapper(const RID &p_shaped) const { Array ret; diff --git a/servers/text_server.h b/servers/text_server.h index 365b7ff663..7e7f26b32d 100644 --- a/servers/text_server.h +++ b/servers/text_server.h @@ -146,6 +146,16 @@ public: FONT_FIXED_WIDTH = 1 << 2, }; + enum StructuredTextParser { + STRUCTURED_TEXT_DEFAULT, + STRUCTURED_TEXT_URI, + STRUCTURED_TEXT_FILE, + STRUCTURED_TEXT_EMAIL, + STRUCTURED_TEXT_LIST, + STRUCTURED_TEXT_NONE, + STRUCTURED_TEXT_CUSTOM + }; + void _draw_hex_code_box_number(const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, uint8_t p_index, const Color &p_color) const; protected: @@ -191,6 +201,9 @@ public: virtual void font_set_antialiased(const RID &p_font_rid, bool p_antialiased) = 0; virtual bool font_is_antialiased(const RID &p_font_rid) const = 0; + virtual void font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) = 0; + virtual bool font_get_generate_mipmaps(const RID &p_font_rid) const = 0; + virtual void font_set_multichannel_signed_distance_field(const RID &p_font_rid, bool p_msdf) = 0; virtual bool font_is_multichannel_signed_distance_field(const RID &p_font_rid) const = 0; @@ -274,6 +287,8 @@ public: virtual int64_t font_get_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const = 0; virtual void font_set_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, int64_t p_texture_idx) = 0; + virtual RID font_get_glyph_texture_rid(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const = 0; + virtual Size2 font_get_glyph_texture_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const = 0; virtual Dictionary font_get_glyph_contours(const RID &p_font, int64_t p_size, int64_t p_index) const = 0; @@ -422,6 +437,8 @@ public: virtual String string_to_upper(const String &p_string, const String &p_language = "") const = 0; virtual String string_to_lower(const String &p_string, const String &p_language = "") const = 0; + Array parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const; + TextServer(); ~TextServer(); }; @@ -509,6 +526,7 @@ VARIANT_ENUM_CAST(TextServer::Feature); VARIANT_ENUM_CAST(TextServer::ContourPointTag); VARIANT_ENUM_CAST(TextServer::SpacingType); VARIANT_ENUM_CAST(TextServer::FontStyle); +VARIANT_ENUM_CAST(TextServer::StructuredTextParser); GDVIRTUAL_NATIVE_PTR(Glyph); GDVIRTUAL_NATIVE_PTR(CaretInfo); |