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 "") if (${DRACO_DIR} STREQUAL "")
else () else ()
add_definitions(-DTINYGLTF_USE_DRACO) # TODO(syoyo): better CMake script for draco
add_definitions(-DTINYGLTF_ENABLE_DRACO)
include_directories(${DRACO_DIR}/include) include_directories(${DRACO_DIR}/include)
link_directories(${DRACO_DIR}/lib)
set(DRACO_LIBRARY draco)
endif () endif ()
include_directories( include_directories(
@ -43,6 +47,7 @@ add_executable(glview
) )
target_link_libraries ( glview target_link_libraries ( glview
${DRACO_LIBRARY}
${GLFW3_UNIX_LINK_LIBRARIES} ${GLFW3_UNIX_LINK_LIBRARIES}
${GLEW_LIBRARY} ${GLEW_LIBRARY}
${GLFW3_glfw_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. 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 ## TODO
* [ ] PBR Material * [ ] PBR Material

View File

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