Loading gfx/include/gfx/bone_ubo.hpp 0 → 100644 +13 −0 Original line number Diff line number Diff line #pragma once #include <osi/opengl.hpp> #define MAX_BONES 80 namespace gfx { struct BoneUBO { static GLuint BONE_UBO; }; }; gfx/include/gfx/shader.hpp +6 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,10 @@ struct Shader : public com::File { return true; } void set_ubo(GLint ubo_name, auto value) const { set_ubo(ubo_name, value); } /** * Sets the view matrix, projection matrix, and camera position uniforms, if present. * @param view view matrix Loading Loading @@ -130,6 +134,8 @@ struct Shader : public com::File { static void set_uniform(detail::ShaderGL *shader, std::string const &var_name, mat4x4 const &value); static void set_uniform(detail::ShaderGL *shader, std::string const &var_name, std::vector<mat4x4> const &value); static void set_ubo(GLuint id, std::vector<mat4x4> const &value); lighting m_lighting_type; std::unique_ptr<detail::ShaderGL> m_gl_shader; }; Loading gfx/src/bone_ubo.cpp 0 → 100644 +3 −0 Original line number Diff line number Diff line #include <gfx/bone_ubo.hpp> GLuint gfx::BoneUBO::BONE_UBO = 0; gfx/src/buffer.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #include <memory> #include <sstream> #include <iostream> #include <gfx/bone_ubo.hpp> namespace gfx::detail { Loading @@ -23,6 +24,7 @@ private: GLuint m_vao; GLuint m_ebo; std::vector<GLuint> m_vbos; GLuint m_bone_ubo; }; BufferGL::BufferGL() Loading Loading @@ -275,6 +277,20 @@ void BufferGL::compile(Buffer const* const buffer) glVertexAttribDivisor(layout, 0); INVARIANT(glGetError() == 0U); // create uniform buffer object for bone matrices glGenBuffers(1, &m_bone_ubo); INVARIANT(glGetError() == 0U); glBindBuffer(GL_UNIFORM_BUFFER, m_bone_ubo); INVARIANT(glGetError() == 0U); /// TODO: GL_DYNAMIC_DRAW glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * MAX_BONES, nullptr, GL_DYNAMIC_DRAW); INVARIANT(glGetError() == 0U); glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_bone_ubo); INVARIANT(glGetError() == 0U); } glBindVertexArray(0); Loading @@ -285,6 +301,12 @@ void BufferGL::compile(Buffer const* const buffer) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); ASSUMPTION(glGetError() == 0U); // BONE UBO static bool first_pass = true; if (first_pass) { } } catch(...) { Loading gfx/src/renderer.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ #include <utils/development.hpp> #include <utils/invariants.hpp> #include <algorithm> #include <gfx/bone_ubo.hpp> namespace gfx::detail { Loading Loading @@ -421,8 +422,14 @@ void Renderer::present_object(com::Folder *const object, CommonVisitData const & shader->maybe_set_uniform(uniform->name(), uniform->get()); } else if (auto uniform = dynamic_cast<com::VectorMat4x4*>(f)) { if (uniform->name() == "bones") { shader->set_ubo(BoneUBO::BONE_UBO, uniform->get()); } else { shader->maybe_set_uniform(uniform->name(), uniform->get()); } } /// TODO: Is there a better solution? /// dynamic_cast<com::MathFile>(f) does not work } Loading Loading
gfx/include/gfx/bone_ubo.hpp 0 → 100644 +13 −0 Original line number Diff line number Diff line #pragma once #include <osi/opengl.hpp> #define MAX_BONES 80 namespace gfx { struct BoneUBO { static GLuint BONE_UBO; }; };
gfx/include/gfx/shader.hpp +6 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,10 @@ struct Shader : public com::File { return true; } void set_ubo(GLint ubo_name, auto value) const { set_ubo(ubo_name, value); } /** * Sets the view matrix, projection matrix, and camera position uniforms, if present. * @param view view matrix Loading Loading @@ -130,6 +134,8 @@ struct Shader : public com::File { static void set_uniform(detail::ShaderGL *shader, std::string const &var_name, mat4x4 const &value); static void set_uniform(detail::ShaderGL *shader, std::string const &var_name, std::vector<mat4x4> const &value); static void set_ubo(GLuint id, std::vector<mat4x4> const &value); lighting m_lighting_type; std::unique_ptr<detail::ShaderGL> m_gl_shader; }; Loading
gfx/src/bone_ubo.cpp 0 → 100644 +3 −0 Original line number Diff line number Diff line #include <gfx/bone_ubo.hpp> GLuint gfx::BoneUBO::BONE_UBO = 0;
gfx/src/buffer.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #include <memory> #include <sstream> #include <iostream> #include <gfx/bone_ubo.hpp> namespace gfx::detail { Loading @@ -23,6 +24,7 @@ private: GLuint m_vao; GLuint m_ebo; std::vector<GLuint> m_vbos; GLuint m_bone_ubo; }; BufferGL::BufferGL() Loading Loading @@ -275,6 +277,20 @@ void BufferGL::compile(Buffer const* const buffer) glVertexAttribDivisor(layout, 0); INVARIANT(glGetError() == 0U); // create uniform buffer object for bone matrices glGenBuffers(1, &m_bone_ubo); INVARIANT(glGetError() == 0U); glBindBuffer(GL_UNIFORM_BUFFER, m_bone_ubo); INVARIANT(glGetError() == 0U); /// TODO: GL_DYNAMIC_DRAW glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * MAX_BONES, nullptr, GL_DYNAMIC_DRAW); INVARIANT(glGetError() == 0U); glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_bone_ubo); INVARIANT(glGetError() == 0U); } glBindVertexArray(0); Loading @@ -285,6 +301,12 @@ void BufferGL::compile(Buffer const* const buffer) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); ASSUMPTION(glGetError() == 0U); // BONE UBO static bool first_pass = true; if (first_pass) { } } catch(...) { Loading
gfx/src/renderer.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ #include <utils/development.hpp> #include <utils/invariants.hpp> #include <algorithm> #include <gfx/bone_ubo.hpp> namespace gfx::detail { Loading Loading @@ -421,8 +422,14 @@ void Renderer::present_object(com::Folder *const object, CommonVisitData const & shader->maybe_set_uniform(uniform->name(), uniform->get()); } else if (auto uniform = dynamic_cast<com::VectorMat4x4*>(f)) { if (uniform->name() == "bones") { shader->set_ubo(BoneUBO::BONE_UBO, uniform->get()); } else { shader->maybe_set_uniform(uniform->name(), uniform->get()); } } /// TODO: Is there a better solution? /// dynamic_cast<com::MathFile>(f) does not work } Loading