Browse Source

replace assimp dependancy with TinyGLTF

render_group_fix
cinnaboot 5 years ago
parent
commit
2ebbf895ea
  1. 3
      .gitmodules
  2. 34
      Makefile
  3. 14
      README
  4. 11
      examples/Makefile
  5. 6
      examples/render_groups/main.cpp
  6. 1
      ext/tinygltf
  7. 41
      include/asset.h
  8. 3
      include/mesh.h
  9. 35
      include/renderer.h
  10. 28
      src/asset.cpp
  11. 28
      src/mesh.cpp
  12. 3
      src/renderer.cpp

3
.gitmodules vendored

@ -1,3 +1,6 @@
[submodule "ext/stb_libs"] [submodule "ext/stb_libs"]
path = ext/stb_libs path = ext/stb_libs
url = https://github.com/nothings/stb.git url = https://github.com/nothings/stb.git
[submodule "ext/tinygltf"]
path = ext/tinygltf
url = https://github.com/syoyo/tinygltf

34
Makefile

@ -4,7 +4,8 @@ CXX = g++
CXXFLAGS = -std=c++11 -g -ggdb3 -Wall \ CXXFLAGS = -std=c++11 -g -ggdb3 -Wall \
-Iinclude \ -Iinclude \
-I/usr/include/SDL2 \ -I/usr/include/SDL2 \
-Iext/stb_libs -Iext/stb_libs \
-Iext/tinygltf
EXAMPLEDIR = examples EXAMPLEDIR = examples
OBJDIR = build OBJDIR = build
SRCDIR = src SRCDIR = src
@ -13,41 +14,13 @@ LIBNAME = libTangerine.a
RENDER_SOURCES = $(wildcard $(SRCDIR)/*.cpp) RENDER_SOURCES = $(wildcard $(SRCDIR)/*.cpp)
RENDER_OBJECTS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(RENDER_SOURCES)) RENDER_OBJECTS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(RENDER_SOURCES))
# NOTE: target to automatically build a current release of assimp. Fixes
# issue on Fedora where the default assimp version doesn't support glTF2
ASSIMP_DIR=ext/assimp
ifeq ($(USE_INTERNAL_ASSIMP), y)
CXXFLAGS += -I$(ASSIMP_DIR)/include -I$(ASSIMP_DIR)/build/include
ASSIMP_LIB := $(ASSIMP_DIR)/build/code/libassimp.a
CLEAN_ASSIMP_TARGET := $(MAKE) -C $(ASSIMP_DIR)/build clean
endif
all: mkdirs $(LIBNAME) all: mkdirs $(LIBNAME)
ifeq ($(USE_INTERNAL_ASSIMP), y)
$(MAKE) $(ASSIMP_LIB)
endif
$(MAKE) examples $(MAKE) examples
.PHONY: all .PHONY: all
-include $(OBJDIR)/*.d -include $(OBJDIR)/*.d
$(ASSIMP_LIB):
@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)/build \
-DBUILD_SHARED_LIBS=OFF \
-DASSIMP_BUILD_TOOLS=OFF -DASSIMP_BUILD_TESTS=OFF \
-DASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT=OFF \
-DASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT=OFF \
-DASSIMP_BUILD_GLTF_IMPORTER=ON ./
$(MAKE) -C $(ASSIMP_DIR)/build
mkdirs: mkdirs:
@mkdir -p $(OBJDIR) @mkdir -p $(OBJDIR)
.PHONY: mkdirs .PHONY: mkdirs
@ -59,11 +32,10 @@ $(RENDER_OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -c -MMD $< -o $@ $(CXX) $(CXXFLAGS) -c -MMD $< -o $@
examples: examples:
ASSIMP_DIR=$(ASSIMP_DIR) $(MAKE) -C $(EXAMPLEDIR) $(MAKE) -C $(EXAMPLEDIR)
.PHONY: examples .PHONY: examples
clean: clean:
rm -rf $(OBJDIR)/* rm -rf $(OBJDIR)/*
$(MAKE) clean -C $(EXAMPLEDIR) $(MAKE) clean -C $(EXAMPLEDIR)
$(CLEAN_ASSIMP_TARGET)
.PHONY: clean .PHONY: clean

14
README

@ -18,20 +18,18 @@ TODO:
update camera to use quaternions for rotation update camera to use quaternions for rotation
Dependencies: Dependencies:
assimp >= 5.0.0
glew glew
glm glm
SDL2 SDL2
stb_image stb_image
TinyGLTF
Build Instructions: Build Instructions:
install dependencies: install dependencies:
Arch) Arch)
$ sudo pacman -S assimp glew glm sd2 catch2 gcc make $ sudo pacman -S glew glm sdl2 gcc make
Fedora) Fedora)
NOTE: Fedora (33) see note below about building assimp $ sudo dnf install glew-devel glm-devel SDL2-devel gcc-c++ make
$ sudo dnf install glew-devel glm-devel catch-devel SDL2-devel \
gcc-c++ make cmake
checkout, and initialize submodules: (stb_image) checkout, and initialize submodules: (stb_image)
$ git submodule init $ git submodule init
$ git submodule update $ git submodule update
@ -43,9 +41,3 @@ Build Instructions:
examples will be in examples/bin examples will be in examples/bin
NOTE: if build fails with errors from assimp or mesh.cpp, you can build
a recent version of assimp that supports glTF2
https://en.wikipedia.org/wiki/GlTF. Requires cmake
$ make build_assimp && USE_INTERNAL_ASSIMP=y make

11
examples/Makefile

@ -2,17 +2,11 @@
SHELL = /bin/sh SHELL = /bin/sh
CXX = g++ CXX = g++
CXXFLAGS = -std=c++11 -g -ggdb3 -Wall -I../include -I/usr/include/SDL2 CXXFLAGS = -std=c++11 -g -ggdb3 -Wall -I../include -I/usr/include/SDL2
LDFLAGS = -lSDL2 -lGLEW -lGL -lassimp LDFLAGS = -lSDL2 -lGLEW -lGL
OBJDIR = build OBJDIR = build
LIB = ../build/libTangerine.a LIB = ../build/libTangerine.a
BINDIR = bin BINDIR = bin
ifeq ($(USE_INTERNAL_ASSIMP), y)
CXXFLAGS += -I../$(ASSIMP_DIR)/include -I../$(ASSIMP_DIR)/build/include
LDFLAGS = -lSDL2 -lGLEW -lGL
ASSIMP_LIB := ../$(ASSIMP_DIR)/build/code/libassimp.a
endif
EXAMPLE_SOURCES = \ EXAMPLE_SOURCES = \
render_groups/main.cpp \ render_groups/main.cpp \
#assimp_loading/main.cpp #assimp_loading/main.cpp
@ -26,8 +20,7 @@ all: mkdirs $(EXAMPLE_OBJECTS)
$(EXAMPLE_OBJECTS): $(LIB) $(EXAMPLE_OBJECTS): $(LIB)
$(CXX) $(CXXFLAGS) -c -MMD $(basename $(notdir $@))/main.cpp -o $@ $(CXX) $(CXXFLAGS) -c -MMD $(basename $(notdir $@))/main.cpp -o $@
$(CXX) -o $(BINDIR)/$(notdir $(basename $@)) $(LDFLAGS) $@ $(LIB) \ $(CXX) -o $(BINDIR)/$(notdir $(basename $@)) $(LDFLAGS) $@ $(LIB)
$(ASSIMP_LIB)
mkdirs: mkdirs:
@mkdir -p $(BINDIR) $(OBJDIR) @mkdir -p $(BINDIR) $(OBJDIR)

6
examples/render_groups/main.cpp

@ -4,6 +4,7 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "asset.h"
#include "dumbLog.h" #include "dumbLog.h"
#include "input.h" #include "input.h"
#include "mesh.h" #include "mesh.h"
@ -180,8 +181,9 @@ main()
rs->asset_list = rs->asset_list =
(render_asset*) arenaAllocateBlock(rs->arena, sizeof(render_asset)); (render_asset*) arenaAllocateBlock(rs->arena, sizeof(render_asset));
mesh_group mg; //mesh_group mg;
meLoadFromFile(mg, "../data/blender/icosphere.gltf"); //meLoadFromFile(mg, "../data/blender/icosphere.gltf");
render_asset* rass = assetLoadFromFile("../data/blender/icosphere.gltf");
renShutdown(rs); renShutdown(rs);
return 0; return 0;

1
ext/tinygltf

@ -0,0 +1 @@
Subproject commit 19a41d20ec03d35cee68ff85511bc5875f6037b8

41
include/asset.h

@ -0,0 +1,41 @@
#pragma once
#include <glm/glm.hpp>
#include "animation.h"
#include "util.h"
#include "util_image.h"
struct mesh_asset
{
uint asset_size;
uint num_vertices;
uint num_indices;
mesh_asset* next;
glm::mat4 model_transform;
glm::vec3* vertices;
uint* indices;
glm::vec3* texture_coords;
};
#define MAX_PATH_SIZE 256
struct render_asset
{
uint total_size;
uint num_meshes;
uint name_len;
render_asset* next;
char* filepath;
mesh_asset* meshes; // NOTE: fixed sized array
// NOTE: pointer to a texture in render_state->textures
util_image* diffuse_texture;
// FIXME: node_animation has a pointer to a render_object. need to decouple
// that somehow
//node_animation* node_anim;
};
render_asset*
assetLoadFromFile(const char* filename);

3
include/mesh.h

@ -45,9 +45,6 @@ struct simple_mesh
}; };
bool
meInitAssimp();
// NOTE: meshes loaded from assimp require texture coordinates, and a diffuse // NOTE: meshes loaded from assimp require texture coordinates, and a diffuse
// texture, which can be a seperate file, or embedded in the input file // texture, which can be a seperate file, or embedded in the input file
bool bool

35
include/renderer.h

@ -9,6 +9,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "asset.h"
#include "camera.h" #include "camera.h"
#include "entity.h" #include "entity.h"
#include "lights.h" #include "lights.h"
@ -41,40 +42,6 @@ struct SDL_Handles
SDL_DisplayMode currentDisplayMode; SDL_DisplayMode currentDisplayMode;
}; };
// --------------------------
// Memory allocation WIP
struct mesh_asset
{
uint asset_size;
uint num_vertices;
uint num_indices;
mesh_asset* next;
glm::mat4 model_transform;
glm::vec3* vertices;
uint* indices;
glm::vec3* texture_coords;
};
#define MAX_PATH_SIZE 256
struct render_asset
{
uint total_size;
uint num_meshes;
uint name_len;
render_asset* next;
char* filepath;
mesh_asset* meshes; // NOTE: fixed sized array
// NOTE: pointer to a texture in render_state->textures
util_image* diffuse_texture;
// FIXME: node_animation has a pointer to a render_object. need to decouple
// that somehow
//node_animation* node_anim;
};
// Memory allocation WIP
// --------------------------
struct render_state struct render_state
{ {
glm::vec2 viewport_dims; glm::vec2 viewport_dims;

28
src/asset.cpp

@ -0,0 +1,28 @@
#include <iostream>
#define TINYGLTF_IMPLEMENTATION
//#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "tiny_gltf.h"
#include "asset.h"
render_asset*
assetLoadFromFile(const char* filename)
{
tinygltf::Model model;
// TODO: see if there's any impact in creating a new context for each file
tinygltf::TinyGLTF gltf_ctx;
std::string err;
std::string warn;
bool ret = false;
ret = gltf_ctx.LoadASCIIFromFile(&model, &err, &warn, filename);
return nullptr;
}

28
src/mesh.cpp

@ -1,8 +1,10 @@
#include <cassert> #include <cassert>
#if 0
#include <assimp/cimport.h> #include <assimp/cimport.h>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#endif
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/geometric.hpp> #include <glm/geometric.hpp>
@ -13,6 +15,30 @@
#include "mesh.h" #include "mesh.h"
// WIP
bool meInitAssimp() { return false; }
bool meLoadFromFile(mesh_group& mesh_group, const char* filepath)
{
return false;
}
simple_mesh*
meInitMesh(uint num_vertices) { return nullptr; }
void
meFreeMeshGroup(mesh_group& mesh_group) {}
void
meFreeSimpleMesh(simple_mesh* mesh) {}
void
meShutdownAssimp() {}
// WIP
#if 0
// forward declarations // forward declarations
mesh_info* allocateMeshInfo(uint num_vertices, uint num_indices); mesh_info* allocateMeshInfo(uint num_vertices, uint num_indices);
@ -232,3 +258,5 @@ validateScene(const aiScene* scene, const char* filepath)
return true; return true;
} }
#endif

3
src/renderer.cpp

@ -48,8 +48,7 @@ renInit(const char* title, glm::vec2 viewport_dims, Uint32 SDL_init_flags)
createWindow(title, rs->handles, rs->viewport_dims) && createWindow(title, rs->handles, rs->viewport_dims) &&
initContext(rs->handles) && initContext(rs->handles) &&
initGlOptions() && initGlOptions() &&
initShaders(rs) && initShaders(rs))
meInitAssimp())
{ {
return rs; return rs;
} }

Loading…
Cancel
Save