summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
Diffstat (limited to 'servers')
-rw-r--r--servers/audio/audio_rb_resampler.cpp210
-rw-r--r--servers/audio/audio_rb_resampler.h49
-rw-r--r--servers/audio_server.cpp2
-rw-r--r--servers/register_server_types.cpp11
-rw-r--r--servers/visual/rasterizer.h2
-rw-r--r--servers/visual/visual_server_raster.cpp2
-rw-r--r--servers/visual/visual_server_raster.h517
-rw-r--r--servers/visual/visual_server_wrap_mt.h2
-rw-r--r--servers/visual_server.cpp2
-rw-r--r--servers/visual_server.h3
10 files changed, 133 insertions, 667 deletions
diff --git a/servers/audio/audio_rb_resampler.cpp b/servers/audio/audio_rb_resampler.cpp
index 113e356612..b0b94a1f49 100644
--- a/servers/audio/audio_rb_resampler.cpp
+++ b/servers/audio/audio_rb_resampler.cpp
@@ -28,6 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "audio_rb_resampler.h"
+#include "core/math/math_funcs.h"
+#include "os/os.h"
+#include "servers/audio_server.h"
int AudioRBResampler::get_channel_count() const {
@@ -37,8 +40,11 @@ int AudioRBResampler::get_channel_count() const {
return channels;
}
+// Linear interpolation based sample rate convertion (low quality)
+// Note that AudioStreamPlaybackResampled::mix has better algorithm,
+// but it wasn't obvious to integrate that with VideoPlayer
template <int C>
-uint32_t AudioRBResampler::_resample(int32_t *p_dest, int p_todo, int32_t p_increment) {
+uint32_t AudioRBResampler::_resample(AudioFrame *p_dest, int p_todo, int32_t p_increment) {
uint32_t read = offset & MIX_FRAC_MASK;
@@ -47,186 +53,128 @@ uint32_t AudioRBResampler::_resample(int32_t *p_dest, int p_todo, int32_t p_incr
offset = (offset + p_increment) & (((1 << (rb_bits + MIX_FRAC_BITS)) - 1));
read += p_increment;
uint32_t pos = offset >> MIX_FRAC_BITS;
- uint32_t frac = offset & MIX_FRAC_MASK;
-#ifndef FAST_AUDIO
+ float frac = float(offset & MIX_FRAC_MASK) / float(MIX_FRAC_LEN);
ERR_FAIL_COND_V(pos >= rb_len, 0);
-#endif
uint32_t pos_next = (pos + 1) & rb_mask;
- //printf("rb pos %i\n",pos);
// since this is a template with a known compile time value (C), conditionals go away when compiling.
if (C == 1) {
- int32_t v0 = rb[pos];
- int32_t v0n = rb[pos_next];
-#ifndef FAST_AUDIO
- v0 += (v0n - v0) * (int32_t)frac >> MIX_FRAC_BITS;
-#endif
- v0 <<= 16;
- p_dest[i] = v0;
+ float v0 = rb[pos];
+ float v0n = rb[pos_next];
+ v0 += (v0n - v0) * frac;
+ p_dest[i] = AudioFrame(v0, v0);
}
+
if (C == 2) {
- int32_t v0 = rb[(pos << 1) + 0];
- int32_t v1 = rb[(pos << 1) + 1];
- int32_t v0n = rb[(pos_next << 1) + 0];
- int32_t v1n = rb[(pos_next << 1) + 1];
-
-#ifndef FAST_AUDIO
- v0 += (v0n - v0) * (int32_t)frac >> MIX_FRAC_BITS;
- v1 += (v1n - v1) * (int32_t)frac >> MIX_FRAC_BITS;
-#endif
- v0 <<= 16;
- v1 <<= 16;
- p_dest[(i << 1) + 0] = v0;
- p_dest[(i << 1) + 1] = v1;
+ float v0 = rb[(pos << 1) + 0];
+ float v1 = rb[(pos << 1) + 1];
+ float v0n = rb[(pos_next << 1) + 0];
+ float v1n = rb[(pos_next << 1) + 1];
+
+ v0 += (v0n - v0) * frac;
+ v1 += (v1n - v1) * frac;
+ p_dest[i] = AudioFrame(v0, v1);
}
+ // For now, channels higher than stereo are almost ignored
if (C == 4) {
- int32_t v0 = rb[(pos << 2) + 0];
- int32_t v1 = rb[(pos << 2) + 1];
- int32_t v2 = rb[(pos << 2) + 2];
- int32_t v3 = rb[(pos << 2) + 3];
- int32_t v0n = rb[(pos_next << 2) + 0];
- int32_t v1n = rb[(pos_next << 2) + 1];
- int32_t v2n = rb[(pos_next << 2) + 2];
- int32_t v3n = rb[(pos_next << 2) + 3];
-
-#ifndef FAST_AUDIO
- v0 += (v0n - v0) * (int32_t)frac >> MIX_FRAC_BITS;
- v1 += (v1n - v1) * (int32_t)frac >> MIX_FRAC_BITS;
- v2 += (v2n - v2) * (int32_t)frac >> MIX_FRAC_BITS;
- v3 += (v3n - v3) * (int32_t)frac >> MIX_FRAC_BITS;
-#endif
- v0 <<= 16;
- v1 <<= 16;
- v2 <<= 16;
- v3 <<= 16;
- p_dest[(i << 2) + 0] = v0;
- p_dest[(i << 2) + 1] = v1;
- p_dest[(i << 2) + 2] = v2;
- p_dest[(i << 2) + 3] = v3;
+ float v0 = rb[(pos << 2) + 0];
+ float v1 = rb[(pos << 2) + 1];
+ float v2 = rb[(pos << 2) + 2];
+ float v3 = rb[(pos << 2) + 3];
+ float v0n = rb[(pos_next << 2) + 0];
+ float v1n = rb[(pos_next << 2) + 1];
+ float v2n = rb[(pos_next << 2) + 2];
+ float v3n = rb[(pos_next << 2) + 3];
+
+ v0 += (v0n - v0) * frac;
+ v1 += (v1n - v1) * frac;
+ v2 += (v2n - v2) * frac;
+ v3 += (v3n - v3) * frac;
+ p_dest[i] = AudioFrame(v0, v1);
}
if (C == 6) {
- int32_t v0 = rb[(pos * 6) + 0];
- int32_t v1 = rb[(pos * 6) + 1];
- int32_t v2 = rb[(pos * 6) + 2];
- int32_t v3 = rb[(pos * 6) + 3];
- int32_t v4 = rb[(pos * 6) + 4];
- int32_t v5 = rb[(pos * 6) + 5];
- int32_t v0n = rb[(pos_next * 6) + 0];
- int32_t v1n = rb[(pos_next * 6) + 1];
- int32_t v2n = rb[(pos_next * 6) + 2];
- int32_t v3n = rb[(pos_next * 6) + 3];
- int32_t v4n = rb[(pos_next * 6) + 4];
- int32_t v5n = rb[(pos_next * 6) + 5];
-
-#ifndef FAST_AUDIO
- v0 += (v0n - v0) * (int32_t)frac >> MIX_FRAC_BITS;
- v1 += (v1n - v1) * (int32_t)frac >> MIX_FRAC_BITS;
- v2 += (v2n - v2) * (int32_t)frac >> MIX_FRAC_BITS;
- v3 += (v3n - v3) * (int32_t)frac >> MIX_FRAC_BITS;
- v4 += (v4n - v4) * (int32_t)frac >> MIX_FRAC_BITS;
- v5 += (v5n - v5) * (int32_t)frac >> MIX_FRAC_BITS;
-#endif
- v0 <<= 16;
- v1 <<= 16;
- v2 <<= 16;
- v3 <<= 16;
- v4 <<= 16;
- v5 <<= 16;
- p_dest[(i * 6) + 0] = v0;
- p_dest[(i * 6) + 1] = v1;
- p_dest[(i * 6) + 2] = v2;
- p_dest[(i * 6) + 3] = v3;
- p_dest[(i * 6) + 4] = v4;
- p_dest[(i * 6) + 5] = v5;
+ float v0 = rb[(pos * 6) + 0];
+ float v1 = rb[(pos * 6) + 1];
+ float v2 = rb[(pos * 6) + 2];
+ float v3 = rb[(pos * 6) + 3];
+ float v4 = rb[(pos * 6) + 4];
+ float v5 = rb[(pos * 6) + 5];
+ float v0n = rb[(pos_next * 6) + 0];
+ float v1n = rb[(pos_next * 6) + 1];
+ float v2n = rb[(pos_next * 6) + 2];
+ float v3n = rb[(pos_next * 6) + 3];
+ float v4n = rb[(pos_next * 6) + 4];
+ float v5n = rb[(pos_next * 6) + 5];
+
+ p_dest[i] = AudioFrame(v0, v1);
}
}
- return read >> MIX_FRAC_BITS; //rb_read_pos=offset>>MIX_FRAC_BITS;
+ return read >> MIX_FRAC_BITS; //rb_read_pos = offset >> MIX_FRAC_BITS;
}
-bool AudioRBResampler::mix(int32_t *p_dest, int p_frames) {
+bool AudioRBResampler::mix(AudioFrame *p_dest, int p_frames) {
if (!rb)
return false;
- int write_pos_cache = rb_write_pos;
-
int32_t increment = (src_mix_rate * MIX_FRAC_LEN) / target_mix_rate;
-
- int rb_todo;
-
- if (write_pos_cache == rb_read_pos) {
- return false; //out of buffer
-
- } else if (rb_read_pos < write_pos_cache) {
-
- rb_todo = write_pos_cache - rb_read_pos; //-1?
- } else {
-
- rb_todo = (rb_len - rb_read_pos) + write_pos_cache; //-1?
- }
-
- int todo = MIN(((int64_t(rb_todo) << MIX_FRAC_BITS) / increment) + 1, p_frames);
+ int read_space = get_reader_space();
+ int target_todo = MIN(get_num_of_ready_frames(), p_frames);
{
-
- int read = 0;
+ int src_read = 0;
switch (channels) {
- case 1: read = _resample<1>(p_dest, todo, increment); break;
- case 2: read = _resample<2>(p_dest, todo, increment); break;
- case 4: read = _resample<4>(p_dest, todo, increment); break;
- case 6: read = _resample<6>(p_dest, todo, increment); break;
+ case 1: src_read = _resample<1>(p_dest, target_todo, increment); break;
+ case 2: src_read = _resample<2>(p_dest, target_todo, increment); break;
+ case 4: src_read = _resample<4>(p_dest, target_todo, increment); break;
+ case 6: src_read = _resample<6>(p_dest, target_todo, increment); break;
}
- //end of stream, fadeout
- int remaining = p_frames - todo;
- if (remaining && todo > 0) {
-
- //print_line("fadeout");
- for (uint32_t c = 0; c < channels; c++) {
+ if (src_read > read_space)
+ src_read = read_space;
- for (int i = 0; i < todo; i++) {
+ rb_read_pos = (rb_read_pos + src_read) & rb_mask;
- int32_t samp = p_dest[i * channels + c] >> 8;
- uint32_t mul = (todo - i) * 256 / todo;
- //print_line("mul: "+itos(i)+" "+itos(mul));
- p_dest[i * channels + c] = samp * mul;
- }
+ // Create fadeout effect for the end of stream (note that it can be because of slow writer)
+ if (p_frames - target_todo > 0) {
+ for (int i = 0; i < target_todo; i++) {
+ p_dest[i] = p_dest[i] * float(target_todo - i) / float(target_todo);
}
}
- //zero out what remains there to avoid glitches
- for (uint32_t i = todo * channels; i < int(p_frames) * channels; i++) {
-
- p_dest[i] = 0;
+ // Fill zeros (silence) for the rest of frames
+ for (uint32_t i = target_todo; i < p_frames; i++) {
+ p_dest[i] = AudioFrame(0, 0);
}
-
- if (read > rb_todo)
- read = rb_todo;
-
- rb_read_pos = (rb_read_pos + read) & rb_mask;
}
return true;
}
+int AudioRBResampler::get_num_of_ready_frames() {
+ if (!is_ready())
+ return 0;
+ int32_t increment = (src_mix_rate * MIX_FRAC_LEN) / target_mix_rate;
+ int read_space = get_reader_space();
+ return (int64_t(read_space) << MIX_FRAC_BITS) / increment;
+}
+
Error AudioRBResampler::setup(int p_channels, int p_src_mix_rate, int p_target_mix_rate, int p_buffer_msec, int p_minbuff_needed) {
ERR_FAIL_COND_V(p_channels != 1 && p_channels != 2 && p_channels != 4 && p_channels != 6, ERR_INVALID_PARAMETER);
- //float buffering_sec = int(GLOBAL_DEF("audio/stream_buffering_ms",500))/1000.0;
int desired_rb_bits = nearest_shift(MAX((p_buffer_msec / 1000.0) * p_src_mix_rate, p_minbuff_needed));
bool recreate = !rb;
if (rb && (uint32_t(desired_rb_bits) != rb_bits || channels != uint32_t(p_channels))) {
- //recreate
memdelete_arr(rb);
memdelete_arr(read_buf);
@@ -239,8 +187,8 @@ Error AudioRBResampler::setup(int p_channels, int p_src_mix_rate, int p_target_m
rb_bits = desired_rb_bits;
rb_len = (1 << rb_bits);
rb_mask = rb_len - 1;
- rb = memnew_arr(int16_t, rb_len * p_channels);
- read_buf = memnew_arr(int16_t, rb_len * p_channels);
+ rb = memnew_arr(float, rb_len *p_channels);
+ read_buf = memnew_arr(float, rb_len *p_channels);
}
src_mix_rate = p_src_mix_rate;
diff --git a/servers/audio/audio_rb_resampler.h b/servers/audio/audio_rb_resampler.h
index bc1f924ab5..08c7a5a668 100644
--- a/servers/audio/audio_rb_resampler.h
+++ b/servers/audio/audio_rb_resampler.h
@@ -31,6 +31,7 @@
#define AUDIO_RB_RESAMPLER_H
#include "os/memory.h"
+#include "servers/audio_server.h"
#include "typedefs.h"
struct AudioRBResampler {
@@ -53,11 +54,11 @@ struct AudioRBResampler {
MIX_FRAC_MASK = MIX_FRAC_LEN - 1,
};
- int16_t *read_buf;
- int16_t *rb;
+ float *read_buf;
+ float *rb;
template <int C>
- uint32_t _resample(int32_t *p_dest, int p_todo, int32_t p_increment);
+ uint32_t _resample(AudioFrame *p_dest, int p_todo, int32_t p_increment);
public:
_FORCE_INLINE_ void flush() {
@@ -71,33 +72,48 @@ public:
}
_FORCE_INLINE_ int get_total() const {
-
return rb_len - 1;
}
- _FORCE_INLINE_ int get_todo() const { //return amount of frames to mix
-
- int todo;
- int read_pos_cache = rb_read_pos;
+ _FORCE_INLINE_ int get_writer_space() const {
+ int space, r, w;
- if (read_pos_cache == rb_write_pos) {
- todo = rb_len - 1;
- } else if (read_pos_cache > rb_write_pos) {
+ r = rb_read_pos;
+ w = rb_write_pos;
- todo = read_pos_cache - rb_write_pos - 1;
+ if (r == w) {
+ space = rb_len - 1;
+ } else if (w < r) {
+ space = r - w - 1;
} else {
+ space = (rb_len - r) + w - 1;
+ }
+
+ return space;
+ }
+
+ _FORCE_INLINE_ int get_reader_space() const {
+ int space, r, w;
- todo = (rb_len - rb_write_pos) + read_pos_cache - 1;
+ r = rb_read_pos;
+ w = rb_write_pos;
+
+ if (r == w) {
+ space = 0;
+ } else if (w < r) {
+ space = rb_len - r + w;
+ } else {
+ space = w - r;
}
- return todo;
+ return space;
}
_FORCE_INLINE_ bool has_data() const {
return rb && rb_read_pos != rb_write_pos;
}
- _FORCE_INLINE_ int16_t *get_write_buffer() { return read_buf; }
+ _FORCE_INLINE_ float *get_write_buffer() { return read_buf; }
_FORCE_INLINE_ void write(uint32_t p_frames) {
ERR_FAIL_COND(p_frames >= rb_len);
@@ -151,7 +167,8 @@ public:
Error setup(int p_channels, int p_src_mix_rate, int p_target_mix_rate, int p_buffer_msec, int p_minbuff_needed = -1);
void clear();
- bool mix(int32_t *p_dest, int p_frames);
+ bool mix(AudioFrame *p_dest, int p_frames);
+ int get_num_of_ready_frames();
AudioRBResampler();
~AudioRBResampler();
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index 697abead68..6a10d7539d 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -876,6 +876,8 @@ void AudioServer::init() {
#ifdef TOOLS_ENABLED
set_edited(false); //avoid editors from thinking this was edited
#endif
+
+ GLOBAL_DEF("audio/video_delay_compensation_ms", 0);
}
void AudioServer::load_default_bus_layout() {
diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp
index 1ba9e7b174..99493afc40 100644
--- a/servers/register_server_types.cpp
+++ b/servers/register_server_types.cpp
@@ -28,6 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "register_server_types.h"
+#include "engine.h"
#include "project_settings.h"
#include "arvr/arvr_interface.h"
@@ -171,9 +172,9 @@ void unregister_server_types() {
}
void register_server_singletons() {
- ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("VisualServer", VisualServer::get_singleton()));
- ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("AudioServer", AudioServer::get_singleton()));
- ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("PhysicsServer", PhysicsServer::get_singleton()));
- ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("Physics2DServer", Physics2DServer::get_singleton()));
- ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("ARVRServer", ARVRServer::get_singleton()));
+ Engine::get_singleton()->add_singleton(Engine::Singleton("VisualServer", VisualServer::get_singleton()));
+ Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton()));
+ Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer", PhysicsServer::get_singleton()));
+ Engine::get_singleton()->add_singleton(Engine::Singleton("Physics2DServer", Physics2DServer::get_singleton()));
+ Engine::get_singleton()->add_singleton(Engine::Singleton("ARVRServer", ARVRServer::get_singleton()));
}
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index 164baa8c9b..333fe1e72a 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -242,6 +242,8 @@ public:
virtual void mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode) = 0;
virtual VS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const = 0;
+ virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const PoolVector<uint8_t> &p_data) = 0;
+
virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) = 0;
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const = 0;
diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp
index 69e2d1c162..9432d3fdd9 100644
--- a/servers/visual/visual_server_raster.cpp
+++ b/servers/visual/visual_server_raster.cpp
@@ -120,6 +120,8 @@ void VisualServerRaster::draw() {
frame_drawn_callbacks.pop_front();
}
+
+ emit_signal("frame_drawn_in_thread");
}
void VisualServerRaster::sync() {
}
diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h
index b579f4032f..67375e81b6 100644
--- a/servers/visual/visual_server_raster.h
+++ b/servers/visual/visual_server_raster.h
@@ -73,521 +73,6 @@ class VisualServerRaster : public VisualServer {
List<FrameDrawnCallbacks> frame_drawn_callbacks;
-// FIXME: Kept as reference for future implementation
-#if 0
- struct Room {
-
- bool occlude_exterior;
- BSP_Tree bounds;
- Room() { occlude_exterior=true; }
- };
-
-
- BalloonAllocator<> octree_allocator;
-
- struct OctreeAllocator {
-
- static BalloonAllocator<> *allocator;
-
- _FORCE_INLINE_ static void *alloc(size_t p_size) { return allocator->alloc(p_size); }
- _FORCE_INLINE_ static void free(void *p_ptr) { return allocator->free(p_ptr); }
-
- };
-
- struct Portal {
-
- bool enabled;
- float disable_distance;
- Color disable_color;
- float connect_range;
- Vector<Point2> shape;
- Rect2 bounds;
-
-
- Portal() { enabled=true; disable_distance=50; disable_color=Color(); connect_range=0.8; }
- };
-
- struct BakedLight {
-
- Rasterizer::BakedLightData data;
- PoolVector<int> sampler;
- Rect3 octree_aabb;
- Size2i octree_tex_size;
- Size2i light_tex_size;
-
- };
-
- struct BakedLightSampler {
-
- float params[BAKED_LIGHT_SAMPLER_MAX];
- int resolution;
- Vector<Vector3> dp_cache;
-
- BakedLightSampler() {
- params[BAKED_LIGHT_SAMPLER_STRENGTH]=1.0;
- params[BAKED_LIGHT_SAMPLER_ATTENUATION]=1.0;
- params[BAKED_LIGHT_SAMPLER_RADIUS]=1.0;
- params[BAKED_LIGHT_SAMPLER_DETAIL_RATIO]=0.1;
- resolution=16;
- }
- };
-
- void _update_baked_light_sampler_dp_cache(BakedLightSampler * blsamp);
- struct Camera {
-
- enum Type {
- PERSPECTIVE,
- ORTHOGONAL
- };
- Type type;
- float fov;
- float znear,zfar;
- float size;
- uint32_t visible_layers;
- bool vaspect;
- RID env;
-
- Transform transform;
-
- Camera() {
-
- visible_layers=0xFFFFFFFF;
- fov=60;
- type=PERSPECTIVE;
- znear=0.1; zfar=100;
- size=1.0;
- vaspect=false;
-
- }
- };
-
-
- struct Instance;
- typedef Set<Instance*,Comparator<Instance*>,OctreeAllocator> InstanceSet;
- struct Scenario;
-
- struct Instance {
-
- enum {
-
- MAX_LIGHTS=4
- };
-
- RID self;
- OctreeElementID octree_id;
- Scenario *scenario;
- bool update;
- bool update_aabb;
- bool update_materials;
- Instance *update_next;
- InstanceType base_type;
-
- RID base_rid;
-
- Rect3 aabb;
- Rect3 transformed_aabb;
- uint32_t object_ID;
- bool visible;
- bool visible_in_all_rooms;
- uint32_t layer_mask;
- float draw_range_begin;
- float draw_range_end;
- float extra_margin;
-
-
-
- Rasterizer::InstanceData data;
-
-
- Set<Instance*> auto_rooms;
- Set<Instance*> valid_auto_rooms;
- Instance *room;
- List<Instance*>::Element *RE;
- Instance *baked_light;
- List<Instance*>::Element *BLE;
- Instance *sampled_light;
- bool exterior;
-
- uint64_t last_render_pass;
- uint64_t last_frame_pass;
-
- uint64_t version; // changes to this, and changes to base increase version
-
- InstanceSet lights;
- bool light_cache_dirty;
-
-
-
- struct RoomInfo {
-
- Transform affine_inverse;
- Room *room;
- List<Instance*> owned_geometry_instances;
- List<Instance*> owned_portal_instances;
- List<Instance*> owned_room_instances;
- List<Instance*> owned_light_instances; //not used, but just for the sake of it
- Set<Instance*> disconnected_child_portals;
- Set<Instance*> owned_autoroom_geometry;
- uint64_t last_visited_pass;
- RoomInfo() { last_visited_pass=0; }
-
- };
-
- struct PortalInfo {
-
- Portal *portal;
- Set<Instance*> candidate_set;
- Instance *connected;
- uint64_t last_visited_pass;
-
- Plane plane_cache;
- Vector<Vector3> transformed_point_cache;
-
-
- PortalInfo() { connected=NULL; last_visited_pass=0;}
- };
-
- struct LightInfo {
-
- RID instance;
- int light_set_index;
- uint64_t last_version;
- uint64_t last_add_pass;
- List<RID>::Element *D; // directional light in scenario
- InstanceSet affected;
- bool enabled;
- float dtc; //distance to camera, used for sorting
-
-
- LightInfo() {
-
- D=NULL;
- light_set_index=-1;
- last_add_pass=0;
- enabled=true;
- }
- };
-
- struct BakedLightInfo {
-
- BakedLight *baked_light;
- Transform affine_inverse;
- List<Instance*> owned_instances;
- };
-
- struct BakedLightSamplerInfo {
-
- Set<Instance*> baked_lights;
- Set<Instance*> owned_instances;
- BakedLightSampler *sampler;
- int resolution;
- Vector<Color> light_buffer;
- RID sampled_light;
- uint64_t last_pass;
- Transform xform; // viewspace normal to lightspace, might not use one.
- BakedLightSamplerInfo() {
- sampler=NULL;
- last_pass=0;
- resolution=0;
- }
- };
-
- struct ParticlesInfo {
-
- RID instance;
- };
-
-
- RoomInfo *room_info;
- LightInfo *light_info;
- ParticlesInfo *particles_info;
- PortalInfo * portal_info;
- BakedLightInfo * baked_light_info;
- BakedLightSamplerInfo * baked_light_sampler_info;
-
-
- Instance() {
- octree_id=0;
- update_next=0;
- object_ID=0;
- last_render_pass=0;
- last_frame_pass=0;
- light_info=0;
- particles_info=0;
- update_next=NULL;
- update=false;
- visible=true;
- data.cast_shadows=SHADOW_CASTING_SETTING_ON;
- data.receive_shadows=true;
- data.depth_scale=false;
- data.billboard=false;
- data.billboard_y=false;
- data.baked_light=NULL;
- data.baked_light_octree_xform=NULL;
- data.baked_lightmap_id=-1;
- version=1;
- room_info=NULL;
- room=NULL;
- RE=NULL;
- portal_info=NULL;
- exterior=false;
- layer_mask=1;
- draw_range_begin=0;
- draw_range_end=0;
- extra_margin=0;
- visible_in_all_rooms=false;
- update_aabb=false;
- update_materials=false;
-
- baked_light=NULL;
- baked_light_info=NULL;
- baked_light_sampler_info=NULL;
- sampled_light=NULL;
- BLE=NULL;
-
- light_cache_dirty=true;
-
- }
-
- ~Instance() {
-
- if (light_info)
- memdelete(light_info);
- if (particles_info)
- memdelete(particles_info);
- if (room_info)
- memdelete(room_info);
- if (portal_info)
- memdelete(portal_info);
- if (baked_light_info)
- memdelete(baked_light_info);
- };
- };
-
- struct _InstanceLightsort {
-
- bool operator()(const Instance* p_A, const Instance* p_B) const { return p_A->light_info->dtc < p_B->light_info->dtc; }
- };
-
- struct Scenario {
-
-
- ScenarioDebugMode debug;
- RID self;
- // well wtf, balloon allocator is slower?
- typedef ::Octree<Instance,true> Octree;
-
- Octree octree;
-
- List<RID> directional_lights;
- RID environment;
- RID fallback_environment;
-
- Instance *dirty_instances;
-
- Scenario() { dirty_instances=NULL; debug=SCENARIO_DEBUG_DISABLED; }
- };
-
-
-
- mutable RID_Owner<Rasterizer::ShaderMaterial> canvas_item_material_owner;
-
-
-
- struct Viewport {
-
- RID self;
- RID parent;
-
- VisualServer::ViewportRect rect;
- RID camera;
- RID scenario;
- RID viewport_data;
-
- RenderTargetUpdateMode render_target_update_mode;
- RID render_target;
- RID render_target_texture;
-
- Rect2 rt_to_screen_rect;
-
- bool hide_scenario;
- bool hide_canvas;
- bool transparent_bg;
- bool queue_capture;
- bool render_target_vflip;
- bool render_target_clear_on_new_frame;
- bool render_target_clear;
- bool disable_environment;
-
- Image capture;
-
- bool rendered_in_prev_frame;
-
- struct CanvasKey {
-
- int layer;
- RID canvas;
- bool operator<(const CanvasKey& p_canvas) const { if (layer==p_canvas.layer) return canvas < p_canvas.canvas; return layer<p_canvas.layer; }
- CanvasKey() { layer=0; }
- CanvasKey(const RID& p_canvas, int p_layer) { canvas=p_canvas; layer=p_layer; }
- };
-
- struct CanvasData {
-
- Canvas *canvas;
- Transform2D transform;
- int layer;
- };
-
- Transform2D global_transform;
-
- Map<RID,CanvasData> canvas_map;
-
- SelfList<Viewport> update_list;
-
- Viewport() : update_list(this) { transparent_bg=false; render_target_update_mode=RENDER_TARGET_UPDATE_WHEN_VISIBLE; queue_capture=false; rendered_in_prev_frame=false; render_target_vflip=false; render_target_clear_on_new_frame=true; render_target_clear=true; disable_environment=false; }
- };
-
- SelfList<Viewport>::List viewport_update_list;
-
- Map<RID,int> screen_viewports;
-
- struct CullRange {
-
- Plane nearp;
- float min,max;
- float z_near,z_far;
-
- void add_aabb(const Rect3& p_aabb) {
-
-
- }
- };
-
- struct Cursor {
-
- Point2 pos;
- float rot;
- RID texture;
- Point2 center;
- bool visible;
- Rect2 region;
- Cursor() {
-
- rot = 0;
- visible = false;
- region = Rect2();
- };
- };
-
- Rect2 canvas_clip;
- Color clear_color;
- Cursor cursors[MAX_CURSORS];
- RID default_cursor_texture;
-
- static void* instance_pair(void *p_self, OctreeElementID,Instance *p_A,int, OctreeElementID,Instance *p_B,int);
- static void instance_unpair(void *p_self, OctreeElementID,Instance *p_A,int, OctreeElementID,Instance *p_B,int,void*);
-
- Instance *instance_cull_result[MAX_INSTANCE_CULL];
- Instance *instance_shadow_cull_result[MAX_INSTANCE_CULL]; //used for generating shadowmaps
- Instance *light_cull_result[MAX_LIGHTS_CULLED];
- int light_cull_count;
-
- Instance *exterior_portal_cull_result[MAX_EXTERIOR_PORTALS];
- int exterior_portal_cull_count;
- bool exterior_visited;
-
- Instance *light_sampler_cull_result[MAX_LIGHT_SAMPLERS];
- int light_samplers_culled;
-
- Instance *room_cull_result[MAX_ROOM_CULL];
- int room_cull_count;
- bool room_cull_enabled;
- bool light_discard_enabled;
- bool shadows_enabled;
- int black_margin[4];
- RID black_image[4];
-
- Vector<Vector3> aabb_random_points;
- Vector<Vector3> transformed_aabb_random_points;
-
- void _instance_validate_autorooms(Instance *p_geometry);
-
- void _portal_disconnect(Instance *p_portal,bool p_cleanup=false);
- void _portal_attempt_connect(Instance *p_portal);
- void _dependency_queue_update(RID p_rid, bool p_update_aabb=false, bool p_update_materials=false);
- _FORCE_INLINE_ void _instance_queue_update(Instance *p_instance,bool p_update_aabb=false,bool p_update_materials=false);
- void _update_instances();
- void _update_instance_aabb(Instance *p_instance);
- void _update_instance(Instance *p_instance);
- void _free_attached_instances(RID p_rid,bool p_free_scenario=false);
- void _clean_up_owner(RID_OwnerBase *p_owner,String p_type);
-
- Instance *instance_update_list;
-
- //RID default_scenario;
- //RID default_viewport;
-
- RID test_cube;
-
-
- mutable RID_Owner<Room> room_owner;
- mutable RID_Owner<Portal> portal_owner;
-
- mutable RID_Owner<BakedLight> baked_light_owner;
- mutable RID_Owner<BakedLightSampler> baked_light_sampler_owner;
-
- mutable RID_Owner<Camera> camera_owner;
- mutable RID_Owner<Viewport> viewport_owner;
-
- mutable RID_Owner<Scenario> scenario_owner;
- mutable RID_Owner<Instance> instance_owner;
-
- mutable RID_Owner<Canvas> canvas_owner;
- mutable RID_Owner<CanvasItem> canvas_item_owner;
-
- Map< RID, Set<RID> > instance_dependency_map;
- Map< RID, Set<Instance*> > skeleton_dependency_map;
-
-
- ViewportRect viewport_rect;
- _FORCE_INLINE_ void _instance_draw(Instance *p_instance);
-
- bool _test_portal_cull(Camera *p_camera, Instance *p_portal_from, Instance *p_portal_to);
- void _cull_portal(Camera *p_camera, Instance *p_portal,Instance *p_from_portal);
- void _cull_room(Camera *p_camera, Instance *p_room,Instance *p_from_portal=NULL);
- void _process_sampled_light(const Transform &p_camera, Instance *p_sampled_light, bool p_linear_colorspace);
-
- void _render_no_camera(Viewport *p_viewport,Camera *p_camera, Scenario *p_scenario);
- void _render_camera(Viewport *p_viewport,Camera *p_camera, Scenario *p_scenario);
- static void _render_canvas_item_viewport(VisualServer* p_self,void *p_vp,const Rect2& p_rect);
- void _render_canvas_item_tree(CanvasItem *p_canvas_item, const Transform2D& p_transform, const Rect2& p_clip_rect, const Color &p_modulate, Rasterizer::CanvasLight *p_lights);
- void _render_canvas_item(CanvasItem *p_canvas_item, const Transform2D& p_transform, const Rect2& p_clip_rect, float p_opacity, int p_z, Rasterizer::CanvasItem **z_list, Rasterizer::CanvasItem **z_last_list, CanvasItem *p_canvas_clip, CanvasItem *p_material_owner);
- void _render_canvas(Canvas *p_canvas, const Transform2D &p_transform, Rasterizer::CanvasLight *p_lights, Rasterizer::CanvasLight *p_masked_lights);
- void _light_mask_canvas_items(int p_z,Rasterizer::CanvasItem *p_canvas_item,Rasterizer::CanvasLight *p_masked_lights);
-
- Vector<Vector3> _camera_generate_endpoints(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max);
- Vector<Plane> _camera_generate_orthogonal_planes(Instance *p_light,Camera *p_camera,float p_range_min, float p_range_max);
-
- void _light_instance_update_lispsm_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range);
- void _light_instance_update_pssm_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range);
-
- void _light_instance_update_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range);
-
- uint64_t render_pass;
- int changes;
- bool draw_extra_frame;
-
- void _draw_viewport_camera(Viewport *p_viewport, bool p_ignore_camera);
- void _draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ofs_y,int p_parent_w,int p_parent_h);
- void _draw_viewports();
- void _draw_cursors_and_margins();
-
-
- Rasterizer *rasterizer;
-
-#endif
-
void _draw_margins();
static void _changes_changed() {}
@@ -726,6 +211,8 @@ public:
BIND2(mesh_set_blend_shape_mode, RID, BlendShapeMode)
BIND1RC(BlendShapeMode, mesh_get_blend_shape_mode, RID)
+ BIND4(mesh_surface_update_region, RID, int, int, const PoolVector<uint8_t> &)
+
BIND3(mesh_surface_set_material, RID, int, RID)
BIND2RC(RID, mesh_surface_get_material, RID, int)
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
index 80a1ef3879..1dddef7bd4 100644
--- a/servers/visual/visual_server_wrap_mt.h
+++ b/servers/visual/visual_server_wrap_mt.h
@@ -144,6 +144,8 @@ public:
FUNC2(mesh_set_blend_shape_mode, RID, BlendShapeMode)
FUNC1RC(BlendShapeMode, mesh_get_blend_shape_mode, RID)
+ FUNC4(mesh_surface_update_region, RID, int, int, const PoolVector<uint8_t> &)
+
FUNC3(mesh_surface_set_material, RID, int, RID)
FUNC2RC(RID, mesh_surface_get_material, RID, int)
diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp
index 2234ddda0d..039bbedbcc 100644
--- a/servers/visual_server.cpp
+++ b/servers/visual_server.cpp
@@ -1856,6 +1856,8 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(FEATURE_SHADERS);
BIND_ENUM_CONSTANT(FEATURE_MULTITHREADED);
+
+ ADD_SIGNAL(MethodInfo("frame_drawn_in_thread"));
}
void VisualServer::_canvas_item_add_style_box(RID p_item, const Rect2 &p_rect, const Rect2 &p_source, RID p_texture, const Vector<float> &p_margins, const Color &p_modulate) {
diff --git a/servers/visual_server.h b/servers/visual_server.h
index 7b0976b100..a36ba4a50a 100644
--- a/servers/visual_server.h
+++ b/servers/visual_server.h
@@ -227,6 +227,7 @@ public:
ARRAY_FLAG_USE_2D_VERTICES = ARRAY_COMPRESS_INDEX << 1,
ARRAY_FLAG_USE_16_BIT_BONES = ARRAY_COMPRESS_INDEX << 2,
+ ARRAY_FLAG_USE_DYNAMIC_UPDATE = ARRAY_COMPRESS_INDEX << 3,
ARRAY_COMPRESS_DEFAULT = ARRAY_COMPRESS_VERTEX | ARRAY_COMPRESS_NORMAL | ARRAY_COMPRESS_TANGENT | ARRAY_COMPRESS_COLOR | ARRAY_COMPRESS_TEX_UV | ARRAY_COMPRESS_TEX_UV2 | ARRAY_COMPRESS_WEIGHTS
@@ -259,6 +260,8 @@ public:
virtual void mesh_set_blend_shape_mode(RID p_mesh, BlendShapeMode p_mode) = 0;
virtual BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const = 0;
+ virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const PoolVector<uint8_t> &p_data) = 0;
+
virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) = 0;
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const = 0;