Skip to content

Bugfixes and make improvements #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions MP-APS/Core/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ void RenderSystem::Update(const Camera& camera) {
}

/***********************************************************************************/
void RenderSystem::Shutdown() const {
for (const auto& shader : m_shaderCache) {
shader.second.DeleteProgram();
}
void RenderSystem::Shutdown() {
m_shaderCache.clear();
}

/***********************************************************************************/
Expand Down
7 changes: 4 additions & 3 deletions MP-APS/Core/RenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ class GLShaderProgram;
class RenderSystem {
using RenderListIterator = std::vector<ModelPtr>::const_iterator;
public:
~RenderSystem() = default;

void Init(const pugi::xml_node& rendererNode);
void Update(const Camera& camera);
// Release OpenGL resources
void Shutdown() const;
//! Release OpenGL resources
void Shutdown();

//
void UpdateView(const Camera& camera);

// Where the magic happens
//! Where the magic happens
void Render(const Camera& camera,
RenderListIterator renderListBegin,
RenderListIterator renderListEnd,
Expand Down
2 changes: 1 addition & 1 deletion MP-APS/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void Engine::Execute() {
}

/***********************************************************************************/
void Engine::shutdown() const {
void Engine::shutdown() {
m_guiSystem.Shutdown();
m_renderer.Shutdown();
ResourceManager::GetInstance().ReleaseAllResources();
Expand Down
2 changes: 1 addition & 1 deletion MP-APS/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Engine {
void Execute();

private:
void shutdown() const;
void shutdown();

// Performs view-frustum culling.
// Returns meshes visible by the camera.
Expand Down
7 changes: 4 additions & 3 deletions MP-APS/Graphics/GLShaderProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ GLShaderProgram::~GLShaderProgram() {

/***********************************************************************************/
void GLShaderProgram::Bind() const {
assert(m_programID != 0);
assert(m_programID != GLShaderProgram::noId);

glUseProgram(m_programID);
}

/***********************************************************************************/
void GLShaderProgram::DeleteProgram() const {
if (m_programID != 0) {
void GLShaderProgram::DeleteProgram() {
if (m_programID != GLShaderProgram::noId) {
std::cout << "Deleting program: " << m_programName << '\n';
glDeleteProgram(m_programID);
m_programID = GLShaderProgram::noId;
}
}

Expand Down
15 changes: 6 additions & 9 deletions MP-APS/Graphics/GLShaderProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ class GLShaderProgram {
~GLShaderProgram();

GLShaderProgram(GLShaderProgram&& other) {
m_uniforms = other.m_uniforms;
m_programID = other.m_programID;
m_programName = other.m_programName;

other.m_uniforms.clear();
other.m_programID = 0;
other.m_programName.clear();
std::swap(m_uniforms, other.m_uniforms);
std::swap(m_programID, other.m_programID);
std::swap(m_programName, other.m_programName);
}

GLShaderProgram& operator=(GLShaderProgram other) noexcept(true) {
Expand All @@ -40,7 +36,7 @@ class GLShaderProgram {
GLShaderProgram& operator=(const GLShaderProgram&) = delete;

void Bind() const;
void DeleteProgram() const;
void DeleteProgram();

GLShaderProgram& SetUniformi(const std::string& uniformName, const int value);
GLShaderProgram& SetUniformf(const std::string& uniformName, const float value);
Expand All @@ -58,6 +54,7 @@ class GLShaderProgram {

std::unordered_map<std::string, int> m_uniforms;

GLuint m_programID{ 0 };
static const GLuint noId = 0;
GLuint m_programID{ noId };
std::string m_programName;
};
2 changes: 1 addition & 1 deletion MP-APS/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void Model::processNode(aiNode* node, const aiScene* scene, const bool loadMater
/***********************************************************************************/
Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene, const bool loadMaterial) {
std::vector<Vertex> vertices;
glm::vec3 min, max;
glm::vec3 min(std::numeric_limits<float>::max()), max(std::numeric_limits<float>::lowest());

for (auto i = 0; i < mesh->mNumVertices; ++i) {
Vertex vertex;
Expand Down
61 changes: 44 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@

# directory definitions
output_dir := ./build
create_output_dir := mkdir -p $(output_dir)

glm_dir := ./MP-APS/3rdParty/glm/
glad_dir := ./MP-APS/3rdParty/glad/include/
glad_src := ./MP-APS/3rdParty/glad/src/glad.c
stb_dir := ./MP-APS/3rdParty/stb/
pugixml_dir := ./MP-APS/3rdParty/pugixml/include/
nuklear_dir := ./MP-APS/3rdParty/nuklear/include/
fmt_dir := ./MP-APS/3rdParty/fmt/include/
fmt_src := ./MP-APS/3rdParty/fmt/src/
APPNAME := $(output_dir)/MP-APS

# collect all source files
SRC += $(wildcard ./MP-APS/*.cpp)
SRC += $(wildcard ./MP-APS/Core/*.cpp)
SRC += $(wildcard ./MP-APS/Demos/*.cpp)
SRC += $(wildcard ./MP-APS/Graphics/*.cpp)
SRC += ./MP-APS/3rdParty/fmt/src/format.cc
SRC += ./MP-APS/3rdParty/glad/src/glad.c

# Use implicit rules to build object files from source files.
# We have *.cpp *.cc *.c source files.
OBJ := $(SRC:.cpp=.o)
OBJ := $(OBJ:.cc=.o)
OBJ := $(OBJ:.c=.o)

CPPFLAGS += -I./MP-APS/3rdParty/glm
CPPFLAGS += -I./MP-APS/3rdParty/glad/include
CPPFLAGS += -I./MP-APS/3rdParty/stb
CPPFLAGS += -I./MP-APS/3rdParty/fmt/include
CPPFLAGS += -I./MP-APS/3rdParty/pugixml/include
CPPFLAGS += -I./MP-APS/3rdParty/nuklear/include

CXXFLAGS += -std=c++17 -Wall -Wextra -Wno-unused-variable -march=native -isystem -O3

LDFLAGS +=

LDLIBS += -lstdc++fs -lGL -lglfw -lpthread -lassimp -ltbb

# virtual targets
.PHONY : all clean

all: $(APPNAME) copydata

$(output_dir):
mkdir -p $(output_dir)

libs := -lstdc++fs -lGL -lglfw -lpthread -lassimp -ltbb
copydata: $(output_dir)
# only update (this is faster, if already copied once)
cp -r -u ./MP-APS/Data $(output_dir)

all:
make clean
$(create_output_dir)
g++ -std=c++17 -Wall -Wextra -Wno-unused-variable -march=native -isystem -O3 -o $(output_dir)/MP-APS -I$(glm_dir) -I$(glad_dir) -I$(stb_dir) -I$(fmt_dir) -I$(pugixml_dir) -I$(nuklear_dir) ./MP-APS/*.cpp ./MP-APS/Core/*.cpp ./MP-APS/Demos/*.cpp ./MP-APS/Graphics/*.cpp $(glad_src) $(fmt_src)/format.cc $(libs)
cp -r ./MP-APS/Data/ $(output_dir)
$(APPNAME): $(OBJ) $(output_dir)
$(CXX) $(OBJ) -o $(APPNAME) $(LDFLAGS) $(LDLIBS)

clean:
rm -rf $(output_dir)
$(RM) $(OBJ)
$(RM) -r $(output_dir)
Empty file modified install-deps-ubuntu.sh
100644 → 100755
Empty file.