summaryrefslogtreecommitdiff
path: root/editor/import
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-11-25 00:07:54 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-11-25 00:09:40 -0300
commitbc2e8d99e5ae0dbd69e712cc71da3033f5f30139 (patch)
treed836011e3d5873e3ceea328ea3100f3c7719ab99 /editor/import
parent7dfba3cda9f13427f9f10a6eefbec52aef62274c (diff)
Made Vector::ptrw explicit for writing, compiler was sometimes using the wrong function,
leading to unnecesary copy on writes and reduced performance.
Diffstat (limited to 'editor/import')
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index 397bb6ad68..f704d97373 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -29,7 +29,7 @@ Error EditorSceneImporterGLTF::_parse_json(const String &p_path, GLTFState &stat
Vector<uint8_t> array;
array.resize(f->get_len());
- f->get_buffer(array.ptr(), array.size());
+ f->get_buffer(array.ptrw(), array.size());
String text;
text.parse_utf8((const char *)array.ptr(), array.size());
@@ -65,7 +65,7 @@ Error EditorSceneImporterGLTF::_parse_glb(const String &p_path, GLTFState &state
ERR_FAIL_COND_V(chunk_type != 0x4E4F534A, ERR_PARSE_ERROR); //JSON
Vector<uint8_t> json_data;
json_data.resize(chunk_length);
- uint32_t len = f->get_buffer(json_data.ptr(), chunk_length);
+ uint32_t len = f->get_buffer(json_data.ptrw(), chunk_length);
ERR_FAIL_COND_V(len != chunk_length, ERR_FILE_CORRUPT);
String text;
@@ -94,7 +94,7 @@ Error EditorSceneImporterGLTF::_parse_glb(const String &p_path, GLTFState &state
ERR_FAIL_COND_V(chunk_type != 0x004E4942, ERR_PARSE_ERROR); //BIN
state.glb_data.resize(chunk_length);
- len = f->get_buffer(state.glb_data.ptr(), chunk_length);
+ len = f->get_buffer(state.glb_data.ptrw(), chunk_length);
ERR_FAIL_COND_V(len != chunk_length, ERR_FILE_CORRUPT);
return OK;
@@ -467,9 +467,10 @@ Error EditorSceneImporterGLTF::_decode_buffer_view(GLTFState &state, int p_buffe
uint32_t offset = bv.byte_offset + byte_offset;
Vector<uint8_t> buffer = state.buffers[bv.buffer]; //copy on write, so no performance hit
+ const uint8_t *bufptr = buffer.ptr();
//use to debug
- print_line("type " + _get_type_name(type) + " component type: " + _get_component_type_name(component_type) + " stride: " + itos(stride) + " amount " + itos(count));
+ //print_line("type " + _get_type_name(type) + " component type: " + _get_component_type_name(component_type) + " stride: " + itos(stride) + " amount " + itos(count));
print_line("accessor offset" + itos(byte_offset) + " view offset: " + itos(bv.byte_offset) + " total buffer len: " + itos(buffer.size()) + " view len " + itos(bv.byte_length));
int buffer_end = (stride * (count - 1)) + element_size;
@@ -481,7 +482,7 @@ Error EditorSceneImporterGLTF::_decode_buffer_view(GLTFState &state, int p_buffe
for (int i = 0; i < count; i++) {
- const uint8_t *src = &buffer[offset + i * stride];
+ const uint8_t *src = &bufptr[offset + i * stride];
for (int j = 0; j < component_count; j++) {
@@ -605,7 +606,7 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, int p
Vector<double> dst_buffer;
dst_buffer.resize(component_count * a.count);
- double *dst = dst_buffer.ptr();
+ double *dst = dst_buffer.ptrw();
if (a.buffer_view >= 0) {
@@ -628,13 +629,13 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, int p
indices.resize(a.sparse_count);
int indices_component_size = _get_component_type_size(a.sparse_indices_component_type);
- Error err = _decode_buffer_view(state, a.sparse_indices_buffer_view, indices.ptr(), 0, 0, indices_component_size, a.sparse_count, TYPE_SCALAR, 1, a.sparse_indices_component_type, indices_component_size, false, a.sparse_indices_byte_offset, false);
+ Error err = _decode_buffer_view(state, a.sparse_indices_buffer_view, indices.ptrw(), 0, 0, indices_component_size, a.sparse_count, TYPE_SCALAR, 1, a.sparse_indices_component_type, indices_component_size, false, a.sparse_indices_byte_offset, false);
if (err != OK)
return Vector<double>();
Vector<double> data;
data.resize(component_count * a.sparse_count);
- err = _decode_buffer_view(state, a.sparse_values_buffer_view, data.ptr(), skip_every, skip_bytes, element_size, a.sparse_count, a.type, component_count, a.component_type, component_size, a.normalized, a.sparse_values_byte_offset, p_for_vertex);
+ err = _decode_buffer_view(state, a.sparse_values_buffer_view, data.ptrw(), skip_every, skip_bytes, element_size, a.sparse_count, a.type, component_count, a.component_type, component_size, a.normalized, a.sparse_values_byte_offset, p_for_vertex);
if (err != OK)
return Vector<double>();
@@ -813,6 +814,7 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
Array meshes = state.json["meshes"];
for (int i = 0; i < meshes.size(); i++) {
+ print_line("on mesh: " + itos(i));
Dictionary d = meshes[i];
GLTFMesh mesh;