From 787234c96961bd2568cf5bcd0d8f13d297bb7694 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Fri, 5 Mar 2021 19:36:17 -0500 Subject: [PATCH] add option to build a recent version of assimp fixes bug on fedora 33 where the default assimp version doesn't support glTF2 --- Makefile | 29 ++++++++++++++++++++++++++--- README.txt | 31 ++++++++++++++++++++++++++++++- examples/Makefile | 6 ++++++ src/renderer.cpp | 5 ++--- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index df2af7a..a73910a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ +SHELL = /bin/sh CXX = g++ -CXXFLAGS = -std=c++11 -g -ggdb3 -Wall -Iinclude -I/usr/include/SDL2 -Iext/stb_libs +CXXFLAGS = -std=c++11 -g -ggdb3 -Wall \ + -Iinclude \ + -I/usr/include/SDL2 \ + -Iext/stb_libs EXAMPLEDIR = examples OBJDIR = build SRCDIR = src @@ -9,14 +13,33 @@ LIBNAME = libTangerine.a RENDER_SOURCES = $(wildcard $(SRCDIR)/*.cpp) RENDER_OBJECTS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(RENDER_SOURCES)) +ASSIMP_DIR=ext/assimp + +ifeq ($(USE_INTERNAL_ASSIMP), y) +$(info using internal assimp) +CXXFLAGS += -I$(ASSIMP_DIR)/include +endif all: mkdirs $(LIBNAME) examples .PHONY: all -include $(OBJDIR)/*.d +# NOTE: target to automatically build a current release of assimp. Fixes +# issue on Fedora where the default assimp version doesn't support glTF2 +build_assimp: + if [ ! -d $(ASSIMP_DIR) ]; then \ + git clone -n "https://github.com/assimp/assimp" $(ASSIMP_DIR); \ + cd $(ASSIMP_DIR); \ + git checkout -q v5.0.1; \ + fi + + cmake -S $(ASSIMP_DIR) -B $(ASSIMP_DIR) + $(MAKE) -C $(ASSIMP_DIR) +.PHONY: build_assimp + mkdirs: - mkdir -p $(OBJDIR) + @mkdir -p $(OBJDIR) .PHONY: mkdirs $(LIBNAME): $(RENDER_OBJECTS) @@ -26,7 +49,7 @@ $(RENDER_OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp $(CXX) $(CXXFLAGS) -c -MMD $< -o $@ examples: $(LIBNAME) - $(MAKE) -C $(EXAMPLEDIR) + ASSIMP_DIR=$(ASSIMP_DIR) $(MAKE) -C $(EXAMPLEDIR) .PHONY: examples clean: diff --git a/README.txt b/README.txt index c783b70..10eea53 100644 --- a/README.txt +++ b/README.txt @@ -15,8 +15,37 @@ TODO: add a function to update camera transforms only once per frame, per shader Dependencies: - assimp + assimp >= 5.0.0 glew glm SDL2 stb_image + +Build Instructions: + install dependencies: + Arch) + $ sudo pacman -S assimp glew glm sd2 catch2 gcc make + Fedora) + NOTE: Fedora (33) ships with assimp v3.3.1 which doesn't support + glTF2: https://en.wikipedia.org/wiki/GlTF + $ sudo dnf install glew-devel glm-devel catch-devel SDL2-devel \ + gcc-c++ make cmake + checkout, and initialize submodules: (stb_image) + $ git submodule init + $ git submodule update + (optional) checkout large files for running examples: + (NOTE: https://git-lfs.github.com/) + $ git lfs pull + build: + $ make + + NOTE: if build fails with errors from assimp or mesh.cpp, you can build + a recent version of assimp first. Requires cmake + + $ make build_assimp && USE_INTERNAL_ASSIMP=y make + + to run examples without installing assimp as a system library: + + $ cd examples/bin + $ LD_LIBRARY_PATH=../../ext/assimp/bin ./assimp_loading + diff --git a/examples/Makefile b/examples/Makefile index 0f871cc..6add76a 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,4 +1,5 @@ +SHELL = /bin/sh CXX = g++ CXXFLAGS = -std=c++11 -g -ggdb3 -Wall -I../include -I/usr/include/SDL2 LDFLAGS = -lSDL2 -lGLEW -lGL -lassimp @@ -6,6 +7,11 @@ OBJDIR = build LIB = ../build/libTangerine.a BINDIR = bin +ifeq ($(USE_INTERNAL_ASSIMP), y) +CXXFLAGS += -I../$(ASSIMP_DIR)/include +LDFLAGS = -lSDL2 -lGLEW -lGL -L../$(ASSIMP_DIR)/bin -lassimp +endif + all: mkdirs \ $(OBJDIR)/hello_world.o \ diff --git a/src/renderer.cpp b/src/renderer.cpp index 87f754f..185243f 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -201,10 +201,9 @@ initContext(SDL_Handles* handles) return false; } - if (SDL_GL_SetSwapInterval(1) != 0) { // vsync + // TODO: this doesn't work inside VM with QXL graphics + if (SDL_GL_SetSwapInterval(1) != 0) // vsync LOG(Error) << "SDL Errors: " << SDL_GetError() << "\n"; - return false; - } return true; }