MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / ParseBufferView

Function ParseBufferView

external/tinygltf/tiny_gltf.h:4654–4713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4652}
4653
4654static bool ParseBufferView(
4655 BufferView *bufferView, std::string *err, const detail::json &o,
4656 bool store_original_json_for_extras_and_extensions) {
4657 int buffer = -1;
4658 if (!ParseIntegerProperty(&buffer, err, o, "buffer", true, "BufferView")) {
4659 return false;
4660 }
4661
4662 size_t byteOffset = 0;
4663 ParseUnsignedProperty(&byteOffset, err, o, "byteOffset", false);
4664
4665 size_t byteLength = 1;
4666 if (!ParseUnsignedProperty(&byteLength, err, o, "byteLength", true,
4667 "BufferView")) {
4668 return false;
4669 }
4670
4671 size_t byteStride = 0;
4672 if (!ParseUnsignedProperty(&byteStride, err, o, "byteStride", false)) {
4673 // Spec says: When byteStride of referenced bufferView is not defined, it
4674 // means that accessor elements are tightly packed, i.e., effective stride
4675 // equals the size of the element.
4676 // We cannot determine the actual byteStride until Accessor are parsed, thus
4677 // set 0(= tightly packed) here(as done in OpenGL's VertexAttribPoiner)
4678 byteStride = 0;
4679 }
4680
4681 if ((byteStride > 252) || ((byteStride % 4) != 0)) {
4682 if (err) {
4683 std::stringstream ss;
4684 ss << "Invalid `byteStride' value. `byteStride' must be the multiple of "
4685 "4 : "
4686 << byteStride << std::endl;
4687
4688 (*err) += ss.str();
4689 }
4690 return false;
4691 }
4692
4693 int target = 0;
4694 ParseIntegerProperty(&target, err, o, "target", false);
4695 if ((target == TINYGLTF_TARGET_ARRAY_BUFFER) ||
4696 (target == TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER)) {
4697 // OK
4698 } else {
4699 target = 0;
4700 }
4701 bufferView->target = target;
4702
4703 ParseStringProperty(&bufferView->name, err, o, "name", false);
4704
4705 ParseExtrasAndExtensions(bufferView, err, o,
4706 store_original_json_for_extras_and_extensions);
4707
4708 bufferView->buffer = buffer;
4709 bufferView->byteOffset = byteOffset;
4710 bufferView->byteLength = byteLength;
4711 bufferView->byteStride = byteStride;

Callers 1

LoadFromStringMethod · 0.85

Calls 4

ParseIntegerPropertyFunction · 0.85
ParseUnsignedPropertyFunction · 0.85
ParseStringPropertyFunction · 0.85
ParseExtrasAndExtensionsFunction · 0.85

Tested by

no test coverage detected