-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It vendors the header and does a minimal smoke test in RenderEngineGl's unit tests. In addition to vendoring: - we redirect tinygltf to use Drake's vendored json library. - We change the callback declaration from a C-style function pointer to a std::function to allow a callback with captures.
- Loading branch information
1 parent
dbc6210
commit a2b8df8
Showing
9 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This file exists to make our directory into a Bazel package, so that our | ||
# neighboring *.bzl file can be loaded elsewhere. | ||
|
||
load("//tools/lint:lint.bzl", "add_lint_tests") | ||
|
||
add_lint_tests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- bazel -*- | ||
|
||
load("@drake//tools/install:install.bzl", "install") | ||
load("@drake//tools/workspace:vendor_cxx.bzl", "cc_library_vendored") | ||
|
||
licenses(["notice"]) # MIT | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library_vendored( | ||
name = "tinygltf", | ||
srcs = ["tiny_gltf.cc"], | ||
srcs_vendored = ["drake_vendor/tiny_gltf.cc"], | ||
hdrs = ["tiny_gltf.h"], | ||
hdrs_vendored = ["drake_vendor/tiny_gltf.h"], | ||
defines = [ | ||
# Don't bother reading external images during glTF parsing; we'll | ||
# handle while processing the resulting RenderMaterial. | ||
"TINYGLTF_NO_EXTERNAL_IMAGE", | ||
# We also won't use tinygltf to decode embedded images; we'll process | ||
# the bytes in Drake. | ||
"TINYGLTF_NO_STB_IMAGE", | ||
"TINYGLTF_NO_STB_IMAGE_WRITE", | ||
], | ||
includes = ["drake_vendor"], | ||
linkstatic = 1, | ||
deps = [ | ||
"@nlohmann_internal//:nlohmann", | ||
], | ||
) | ||
|
||
install( | ||
name = "install", | ||
docs = ["LICENSE"], | ||
) |
77 changes: 77 additions & 0 deletions
77
tools/workspace/tinygltf_internal/patches/function_pointer.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
Replaces the typedef of a function pointer (for the image loading callback) | ||
with the equivalent std::function alias. | ||
|
||
This doesn't bind *all* function pointer typedefs, just the ones that Drake | ||
cares about right now. We've submitted a PR to tinygltf upgrading all such | ||
callbacks and can eliminate this patch when our upstream version adopts it and | ||
releases a new version. See https://github.com/syoyo/tinygltf/pull/489. | ||
|
||
--- tiny_gltf.h | ||
+++ tiny_gltf.h | ||
@@ -43,6 +43,7 @@ | ||
#include <cstdint> | ||
#include <cstdlib> | ||
#include <cstring> | ||
+#include <functional> | ||
#include <limits> | ||
#include <map> | ||
#include <string> | ||
@@ -1292,10 +1293,9 @@ struct URICallbacks { | ||
/// | ||
/// LoadImageDataFunction type. Signature for custom image loading callbacks. | ||
/// | ||
-typedef bool (*LoadImageDataFunction)(Image *, const int, std::string *, | ||
- std::string *, int, int, | ||
- const unsigned char *, int, | ||
- void *user_pointer); | ||
+using LoadImageDataFunction = | ||
+ std::function<bool(Image *, const int, std::string *, std::string *, int, | ||
+ int, const unsigned char *, int, void *)>; | ||
|
||
/// | ||
/// WriteImageDataFunction type. Signature for custom image writing callbacks. | ||
@@ -4218,7 +4218,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err, | ||
bool store_original_json_for_extras_and_extensions, | ||
const std::string &basedir, const size_t max_file_size, | ||
FsCallbacks *fs, const URICallbacks *uri_cb, | ||
- LoadImageDataFunction *LoadImageData = nullptr, | ||
+ LoadImageDataFunction LoadImageData = nullptr, | ||
void *load_image_user_data = nullptr) { | ||
// A glTF image must either reference a bufferView or an image uri | ||
|
||
@@ -4349,14 +4349,14 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err, | ||
#endif | ||
} | ||
|
||
- if (*LoadImageData == nullptr) { | ||
+ if (LoadImageData == nullptr) { | ||
if (err) { | ||
(*err) += "No LoadImageData callback specified.\n"; | ||
} | ||
return false; | ||
} | ||
- return (*LoadImageData)(image, image_idx, err, warn, 0, 0, &img.at(0), | ||
- static_cast<int>(img.size()), load_image_user_data); | ||
+ return LoadImageData(image, image_idx, err, warn, 0, 0, &img.at(0), | ||
+ static_cast<int>(img.size()), load_image_user_data); | ||
} | ||
|
||
static bool ParseTexture(Texture *texture, std::string *err, | ||
@@ -6307,7 +6307,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn, | ||
if (!ParseImage(&image, idx, err, warn, o, | ||
store_original_json_for_extras_and_extensions_, base_dir, | ||
max_external_file_size_, &fs, &uri_cb, | ||
- &this->LoadImageData, load_image_user_data)) { | ||
+ this->LoadImageData, load_image_user_data)) { | ||
return false; | ||
} | ||
|
||
@@ -6336,7 +6336,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn, | ||
} | ||
const Buffer &buffer = model->buffers[size_t(bufferView.buffer)]; | ||
|
||
- if (*LoadImageData == nullptr) { | ||
+ if (LoadImageData == nullptr) { | ||
if (err) { | ||
(*err) += "No LoadImageData callback specified.\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Redirects tinygltf to use Drake's vendored nlohmann json. | ||
|
||
--- tiny_gltf.h | ||
+++ tiny_gltf.h | ||
@@ -1705,7 +1705,7 @@ class TinyGLTF { | ||
|
||
#ifndef TINYGLTF_NO_INCLUDE_JSON | ||
#ifndef TINYGLTF_USE_RAPIDJSON | ||
-#include "json.hpp" | ||
+#include <nlohmann/json.hpp> | ||
#else | ||
#ifndef TINYGLTF_NO_INCLUDE_RAPIDJSON | ||
#include "document.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@drake//tools/workspace:github.bzl", "github_archive") | ||
|
||
def tinygltf_internal_repository( | ||
name, | ||
mirrors = None): | ||
github_archive( | ||
name = name, | ||
repository = "syoyo/tinygltf", | ||
commit = "v2.8.22", | ||
sha256 = "97c3eb1080c1657cd749d0b49af189c6a867d5af30689c48d5e19521e7b5a070", # noqa | ||
build_file = ":package.BUILD.bazel", | ||
patches = [ | ||
":patches/function_pointer.patch", | ||
":patches/json.patch", | ||
], | ||
mirrors = mirrors, | ||
) |