Add support for building glview with draco.

Fix out-of-bounds access when calling DrawMesh().
Fix potential out-of-bounds access when filling window title string.
This commit is contained in:
Syoyo Fujita 2019-01-27 00:38:34 +09:00
parent 5f34dab548
commit a32fa80102
3 changed files with 27 additions and 5 deletions

View File

@ -25,8 +25,12 @@ set(CMAKE_CXX_STANDARD 11)
if (${DRACO_DIR} STREQUAL "")
else ()
add_definitions(-DTINYGLTF_USE_DRACO)
# TODO(syoyo): better CMake script for draco
add_definitions(-DTINYGLTF_ENABLE_DRACO)
include_directories(${DRACO_DIR}/include)
link_directories(${DRACO_DIR}/lib)
set(DRACO_LIBRARY draco)
endif ()
include_directories(
@ -43,6 +47,7 @@ add_executable(glview
)
target_link_libraries ( glview
${DRACO_LIBRARY}
${GLFW3_UNIX_LINK_LIBRARIES}
${GLEW_LIBRARY}
${GLFW3_glfw_LIBRARY}

View File

@ -27,6 +27,17 @@ Open .sln in Visual Studio 2013
When running .exe, glew and glfw dll must exist in the working directory.
#### Build with Draco(optional)
Assume CMake build.
```
$ mkdir build
$ cd build
$ cmake -DDRACO_DIR=/path/to/draco ../
$ make
```
## TODO
* [ ] PBR Material

View File

@ -677,10 +677,14 @@ static void DrawNode(tinygltf::Model &model, const tinygltf::Node &node) {
// std::cout << it->first << std::endl;
// FIXME(syoyo): Refactor.
// DrawCurves(scene, it->second);
if (node.mesh > -1) {
assert(node.mesh < model.meshes.size());
DrawMesh(model, model.meshes[node.mesh]);
}
// Draw child nodes.
for (size_t i = 0; i < node.children.size(); i++) {
assert(node.children[i] < model.nodes.size());
DrawNode(model, model.nodes[node.children[i]]);
}
@ -786,10 +790,12 @@ int main(int argc, char **argv) {
return -1;
}
char title[1024];
sprintf(title, "Simple glTF viewer: %s", input_filename.c_str());
std::stringstream ss;
ss << "Simple glTF viewer: " << input_filename;
window = glfwCreateWindow(width, height, title, NULL, NULL);
std::string title = ss.str();
window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
if (window == NULL) {
std::cerr << "Failed to open GLFW window. " << std::endl;
glfwTerminate();