summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/audio_stream_wav.cpp56
-rw-r--r--scene/resources/audio_stream_wav.h2
-rw-r--r--scene/resources/bit_map.cpp2
-rw-r--r--scene/resources/surface_tool.cpp18
-rw-r--r--scene/resources/texture.cpp3
5 files changed, 47 insertions, 34 deletions
diff --git a/scene/resources/audio_stream_wav.cpp b/scene/resources/audio_stream_wav.cpp
index f331e3a22c..669b455f89 100644
--- a/scene/resources/audio_stream_wav.cpp
+++ b/scene/resources/audio_stream_wav.cpp
@@ -87,21 +87,21 @@ void AudioStreamPlaybackWAV::seek(double p_time) {
}
template <class Depth, bool is_stereo, bool is_ima_adpcm>
-void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &offset, int32_t &increment, uint32_t amount, IMA_ADPCM_State *ima_adpcm) {
+void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &p_offset, int32_t &p_increment, uint32_t p_amount, IMA_ADPCM_State *p_ima_adpcm) {
// this function will be compiled branchless by any decent compiler
int32_t final, final_r, next, next_r;
- while (amount) {
- amount--;
- int64_t pos = offset >> MIX_FRAC_BITS;
+ while (p_amount) {
+ p_amount--;
+ int64_t pos = p_offset >> MIX_FRAC_BITS;
if (is_stereo && !is_ima_adpcm) {
pos <<= 1;
}
if (is_ima_adpcm) {
- int64_t sample_pos = pos + ima_adpcm[0].window_ofs;
+ int64_t sample_pos = pos + p_ima_adpcm[0].window_ofs;
- while (sample_pos > ima_adpcm[0].last_nibble) {
+ while (sample_pos > p_ima_adpcm[0].last_nibble) {
static const int16_t _ima_adpcm_step_table[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
@@ -122,20 +122,20 @@ void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst,
for (int i = 0; i < (is_stereo ? 2 : 1); i++) {
int16_t nibble, diff, step;
- ima_adpcm[i].last_nibble++;
+ p_ima_adpcm[i].last_nibble++;
const uint8_t *src_ptr = (const uint8_t *)base->data;
src_ptr += AudioStreamWAV::DATA_PAD;
- uint8_t nbb = src_ptr[(ima_adpcm[i].last_nibble >> 1) * (is_stereo ? 2 : 1) + i];
- nibble = (ima_adpcm[i].last_nibble & 1) ? (nbb >> 4) : (nbb & 0xF);
- step = _ima_adpcm_step_table[ima_adpcm[i].step_index];
+ uint8_t nbb = src_ptr[(p_ima_adpcm[i].last_nibble >> 1) * (is_stereo ? 2 : 1) + i];
+ nibble = (p_ima_adpcm[i].last_nibble & 1) ? (nbb >> 4) : (nbb & 0xF);
+ step = _ima_adpcm_step_table[p_ima_adpcm[i].step_index];
- ima_adpcm[i].step_index += _ima_adpcm_index_table[nibble];
- if (ima_adpcm[i].step_index < 0) {
- ima_adpcm[i].step_index = 0;
+ p_ima_adpcm[i].step_index += _ima_adpcm_index_table[nibble];
+ if (p_ima_adpcm[i].step_index < 0) {
+ p_ima_adpcm[i].step_index = 0;
}
- if (ima_adpcm[i].step_index > 88) {
- ima_adpcm[i].step_index = 88;
+ if (p_ima_adpcm[i].step_index > 88) {
+ p_ima_adpcm[i].step_index = 88;
}
diff = step >> 3;
@@ -152,26 +152,26 @@ void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst,
diff = -diff;
}
- ima_adpcm[i].predictor += diff;
- if (ima_adpcm[i].predictor < -0x8000) {
- ima_adpcm[i].predictor = -0x8000;
- } else if (ima_adpcm[i].predictor > 0x7FFF) {
- ima_adpcm[i].predictor = 0x7FFF;
+ p_ima_adpcm[i].predictor += diff;
+ if (p_ima_adpcm[i].predictor < -0x8000) {
+ p_ima_adpcm[i].predictor = -0x8000;
+ } else if (p_ima_adpcm[i].predictor > 0x7FFF) {
+ p_ima_adpcm[i].predictor = 0x7FFF;
}
/* store loop if there */
- if (ima_adpcm[i].last_nibble == ima_adpcm[i].loop_pos) {
- ima_adpcm[i].loop_step_index = ima_adpcm[i].step_index;
- ima_adpcm[i].loop_predictor = ima_adpcm[i].predictor;
+ if (p_ima_adpcm[i].last_nibble == p_ima_adpcm[i].loop_pos) {
+ p_ima_adpcm[i].loop_step_index = p_ima_adpcm[i].step_index;
+ p_ima_adpcm[i].loop_predictor = p_ima_adpcm[i].predictor;
}
- //printf("%i - %i - pred %i\n",int(ima_adpcm[i].last_nibble),int(nibble),int(ima_adpcm[i].predictor));
+ //printf("%i - %i - pred %i\n",int(p_ima_adpcm[i].last_nibble),int(nibble),int(p_ima_adpcm[i].predictor));
}
}
- final = ima_adpcm[0].predictor;
+ final = p_ima_adpcm[0].predictor;
if (is_stereo) {
- final_r = ima_adpcm[1].predictor;
+ final_r = p_ima_adpcm[1].predictor;
}
} else {
@@ -201,7 +201,7 @@ void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst,
}
}
- int32_t frac = int64_t(offset & MIX_FRAC_MASK);
+ int32_t frac = int64_t(p_offset & MIX_FRAC_MASK);
final = final + ((next - final) * frac >> MIX_FRAC_BITS);
if (is_stereo) {
@@ -217,7 +217,7 @@ void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst,
p_dst->r = final_r / 32767.0;
p_dst++;
- offset += increment;
+ p_offset += p_increment;
}
}
diff --git a/scene/resources/audio_stream_wav.h b/scene/resources/audio_stream_wav.h
index bea273720c..f150a17d21 100644
--- a/scene/resources/audio_stream_wav.h
+++ b/scene/resources/audio_stream_wav.h
@@ -61,7 +61,7 @@ class AudioStreamPlaybackWAV : public AudioStreamPlayback {
Ref<AudioStreamWAV> base;
template <class Depth, bool is_stereo, bool is_ima_adpcm>
- void do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &offset, int32_t &increment, uint32_t amount, IMA_ADPCM_State *ima_adpcm);
+ void do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &p_offset, int32_t &p_increment, uint32_t p_amount, IMA_ADPCM_State *p_ima_adpcm);
public:
virtual void start(double p_from_pos = 0.0) override;
diff --git a/scene/resources/bit_map.cpp b/scene/resources/bit_map.cpp
index 204adbcda0..dd20dc1c66 100644
--- a/scene/resources/bit_map.cpp
+++ b/scene/resources/bit_map.cpp
@@ -354,7 +354,7 @@ Vector<Vector<Vector2>> BitMap::_march_square(const Rect2i &p_rect, const Point2
prevx = stepx;
prevy = stepy;
- ERR_FAIL_COND_V((int)count > width * height, Vector<Vector<Vector2>>());
+ ERR_FAIL_COND_V((int)count > 2 * (width * height + 1), Vector<Vector<Vector2>>());
} while (curx != startx || cury != starty);
// Add remaining points to result.
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index ccb3ddee45..5ef3e09e3d 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -985,9 +985,21 @@ void SurfaceTool::create_from_blend_shape(const Ref<Mesh> &p_existing, int p_sur
}
ERR_FAIL_COND(shape_idx == -1);
ERR_FAIL_COND(shape_idx >= arr.size());
- Array mesh = arr[shape_idx];
- ERR_FAIL_COND(mesh.size() != RS::ARRAY_MAX);
- _create_list_from_arrays(arr[shape_idx], &vertex_array, &index_array, format);
+ Array blendshape_mesh_arrays = arr[shape_idx];
+ ERR_FAIL_COND(blendshape_mesh_arrays.size() != RS::ARRAY_MAX);
+
+ Array source_mesh_arrays = p_existing->surface_get_arrays(p_surface);
+ ERR_FAIL_COND(source_mesh_arrays.size() != RS::ARRAY_MAX);
+
+ // Copy BlendShape vertex data over while keeping e.g. bones, weights, index from existing mesh intact.
+ source_mesh_arrays[RS::ARRAY_VERTEX] = blendshape_mesh_arrays[RS::ARRAY_VERTEX];
+ source_mesh_arrays[RS::ARRAY_NORMAL] = blendshape_mesh_arrays[RS::ARRAY_NORMAL];
+ source_mesh_arrays[RS::ARRAY_TANGENT] = blendshape_mesh_arrays[RS::ARRAY_TANGENT];
+
+ _create_list_from_arrays(source_mesh_arrays, &vertex_array, &index_array, format);
+
+ material = p_existing->surface_get_material(p_surface);
+ format = p_existing->surface_get_format(p_surface);
for (int j = 0; j < RS::ARRAY_CUSTOM_COUNT; j++) {
if (format & custom_mask[j]) {
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 282c531555..7de10149db 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -168,7 +168,8 @@ void ImageTexture::_get_property_list(List<PropertyInfo> *p_list) const {
}
Ref<ImageTexture> ImageTexture::create_from_image(const Ref<Image> &p_image) {
- ERR_FAIL_COND_V_MSG(p_image.is_null() || p_image->is_empty(), Ref<ImageTexture>(), "Invalid image");
+ ERR_FAIL_COND_V_MSG(p_image.is_null(), Ref<ImageTexture>(), "Invalid image: null");
+ ERR_FAIL_COND_V_MSG(p_image->is_empty(), Ref<ImageTexture>(), "Invalid image: image is empty");
Ref<ImageTexture> image_texture;
image_texture.instantiate();