diff --git a/14-refactor/assets/crate.glb b/14-refactor/assets/crate.glb index dc2117a..281c351 100644 Binary files a/14-refactor/assets/crate.glb and b/14-refactor/assets/crate.glb differ diff --git a/17-refactor-bug-fix/src/main.cpp b/17-refactor-bug-fix/src/main.cpp index 5340edc..01b88ad 100644 --- a/17-refactor-bug-fix/src/main.cpp +++ b/17-refactor-bug-fix/src/main.cpp @@ -83,7 +83,6 @@ Scene setup() { components::Scene config = utils::load_scene_config("config.json"); Scene scene(config); - scene.configure(); return scene; } @@ -91,7 +90,7 @@ Scene setup() { void update(GLFWwindow* window, Scene& scene) { glfwPollEvents(); process_input(window, scene); - scene.updateDelta(); + scene.update(); } void render(GLFWwindow* window, Scene& scene) { diff --git a/17-refactor-bug-fix/src/mesh.cpp b/17-refactor-bug-fix/src/mesh.cpp index 4e24487..5c40960 100644 --- a/17-refactor-bug-fix/src/mesh.cpp +++ b/17-refactor-bug-fix/src/mesh.cpp @@ -2,22 +2,25 @@ #include "dbc.hpp" void Mesh::draw(Shader &shader) { + // CAN WE DO THIS LESS OFTEN OUTSIDE DRAWING? + apply_textures(shader); + glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0); glBindVertexArray(0); glActiveTexture(GL_TEXTURE0); } -void Mesh::connect_shader(const Shader& shader) { +void Mesh::apply_textures(const Shader& shader) { for(unsigned int i = 0; i < textures.size(); i++) { Texture& texture = textures[i]; + + texture.uniform_id = glGetUniformLocation(shader.ID, texture.target.c_str()); glActiveTexture(GL_TEXTURE0 + i); // move this to setup_mesh glUniform1i(texture.uniform_id, i); glBindTexture(GL_TEXTURE_2D, texture.id); - - texture.uniform_id = glGetUniformLocation(shader.ID, texture.target.c_str()); } } diff --git a/17-refactor-bug-fix/src/mesh.hpp b/17-refactor-bug-fix/src/mesh.hpp index b4f4e32..21160e7 100644 --- a/17-refactor-bug-fix/src/mesh.hpp +++ b/17-refactor-bug-fix/src/mesh.hpp @@ -68,5 +68,5 @@ struct Mesh { void draw(Shader &shader); void setup_mesh(); - void connect_shader(const Shader& shader); + void apply_textures(const Shader& shader); }; diff --git a/17-refactor-bug-fix/src/model.cpp b/17-refactor-bug-fix/src/model.cpp index 25cd439..0c9f55c 100644 --- a/17-refactor-bug-fix/src/model.cpp +++ b/17-refactor-bug-fix/src/model.cpp @@ -209,9 +209,3 @@ void Model::load_material_textures(const aiScene *scene, std::vector& t } } } - -void Model::connect_shader(const Shader& shader) { - for(auto& mesh : meshes) { - mesh.connect_shader(shader); - } -} diff --git a/17-refactor-bug-fix/src/model.hpp b/17-refactor-bug-fix/src/model.hpp index 79af923..5029439 100644 --- a/17-refactor-bug-fix/src/model.hpp +++ b/17-refactor-bug-fix/src/model.hpp @@ -39,6 +39,4 @@ struct Model { Mesh process_mesh(const aiScene *scene, aiMesh *mesh); void load_material_textures(const aiScene *scene, std::vector& textures, aiMaterial *mat, aiTextureType type, std::string typeName); - - void connect_shader(const Shader& shader); }; diff --git a/17-refactor-bug-fix/src/scene.cpp b/17-refactor-bug-fix/src/scene.cpp index 2ccb104..5836d5d 100644 --- a/17-refactor-bug-fix/src/scene.cpp +++ b/17-refactor-bug-fix/src/scene.cpp @@ -2,17 +2,12 @@ #include "dbc.hpp" #include -void Scene::updateDelta() { +void Scene::update() { float currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; -} -void Scene::configure() { - // REFACTOR: really this should be done somewhere else - for(auto& [name, model] : models) { - model.connect_shader(shader); - } + camera.update(deltaTime); } void Scene::draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position) @@ -38,8 +33,6 @@ void Scene::render(GLFWwindow* window) { // time is used for fake 3d rotation float time = glfwGetTime(); - camera.update(deltaTime); - glm::mat4 view = camera.look_at(); glm::mat4 projection = glm::mat4(1.0f); diff --git a/17-refactor-bug-fix/src/scene.hpp b/17-refactor-bug-fix/src/scene.hpp index 828c75e..b5dd673 100644 --- a/17-refactor-bug-fix/src/scene.hpp +++ b/17-refactor-bug-fix/src/scene.hpp @@ -56,8 +56,7 @@ struct Scene { } } - void updateDelta(); - void configure(); + void update(); void draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position); void render(GLFWwindow* window); void cleanup();