From e6c6f9e85c4a43ba88620f65ed9378f5bb6a5498 Mon Sep 17 00:00:00 2001 From: T1ti <40864460+T1ti@users.noreply.github.com> Date: Wed, 14 Aug 2024 05:05:55 +0200 Subject: [PATCH] https://github.com/wowdev/noggit3/commit/1d22ddce6150e86635e97dc55f78f36065ba372d noggit: model: only setup shader attributes once --- src/noggit/rendering/ModelRender.cpp | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/noggit/rendering/ModelRender.cpp b/src/noggit/rendering/ModelRender.cpp index f58dc22b..7c31f8bc 100755 --- a/src/noggit/rendering/ModelRender.cpp +++ b/src/noggit/rendering/ModelRender.cpp @@ -108,6 +108,21 @@ void ModelRender::draw(glm::mat4x4 const& model_view if (!_uploaded) { upload(); + + OpenGL::Scoped::vao_binder const _(_vao); + + { + OpenGL::Scoped::buffer_binder const binder(_vertices_buffer); + m2_shader.attrib("pos", 3, GL_FLOAT, GL_FALSE, sizeof(ModelVertex), 0); + m2_shader.attrib("normal", 3, GL_FLOAT, GL_FALSE, sizeof(ModelVertex), reinterpret_cast (sizeof(::glm::vec3) + 8)); + m2_shader.attrib("texcoord1", 2, GL_FLOAT, GL_FALSE, sizeof(ModelVertex), reinterpret_cast (sizeof(::glm::vec3) * 2 + 8)); + m2_shader.attrib("texcoord2", 2, GL_FLOAT, GL_FALSE, sizeof(ModelVertex), reinterpret_cast (sizeof(::glm::vec3) * 2 + 8 + sizeof(glm::vec2))); + } + + { + OpenGL::Scoped::buffer_binder const transform_binder(_transform_buffer); + m2_shader.uniform("transform", instance.transformMatrix()); + } } if (_model->animated && (!_model->animcalc || _model->_per_instance_animation)) @@ -116,20 +131,6 @@ void ModelRender::draw(glm::mat4x4 const& model_view _model->animcalc = true; } - OpenGL::Scoped::vao_binder const _(_vao); - - m2_shader.uniform("transform", instance.transformMatrix()); - - { - OpenGL::Scoped::buffer_binder const binder(_vertices_buffer); - m2_shader.attrib("pos", 3, GL_FLOAT, GL_FALSE, sizeof(ModelVertex), 0); - m2_shader.attrib("bones_weight", 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof (ModelVertex), reinterpret_cast (sizeof (::glm::vec3))); - m2_shader.attrib("bones_indices", 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof (ModelVertex), reinterpret_cast (sizeof (::glm::vec3) + 4)); - m2_shader.attrib("normal", 3, GL_FLOAT, GL_FALSE, sizeof(ModelVertex), reinterpret_cast (sizeof(::glm::vec3) + 8)); - m2_shader.attrib("texcoord1", 2, GL_FLOAT, GL_FALSE, sizeof(ModelVertex), reinterpret_cast (sizeof(::glm::vec3) * 2 + 8)); - m2_shader.attrib("texcoord2", 2, GL_FLOAT, GL_FALSE, sizeof(ModelVertex), reinterpret_cast (sizeof(::glm::vec3) * 2 + 8 + sizeof(glm::vec2))); - } - OpenGL::Scoped::buffer_binder indices_binder(_indices_buffer); for (ModelRenderPass& p : _render_passes)