diff --git a/CMakeLists.txt b/CMakeLists.txt index bccce9c..f4b44da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,7 +93,6 @@ set(CLIENT_ONLY_SOURCES "src/gfx/draw_list.hpp" "src/gfx/frustum.hpp" "src/gfx/frustum.cpp" - "src/gfx/hud.hpp" "src/gfx/renderer.hpp" "src/gfx/renderer.cpp" "src/gfx/shader_defs.hpp" diff --git a/src/gfx/draw_list.hpp b/src/gfx/draw_list.hpp index 722aa40..c4741f3 100644 --- a/src/gfx/draw_list.hpp +++ b/src/gfx/draw_list.hpp @@ -3,7 +3,6 @@ #include #include "assets/skeleton.hpp" -#include "hud.hpp" #include "surface.hpp" #include "uniform_buffer.hpp" @@ -41,8 +40,6 @@ struct DrawHudCmd { const VertexArray* va = nullptr; const Texture* texture = nullptr; - const HudPosition* pos = nullptr; - const glm::vec4* color = nullptr; size_t first = 0; size_t count = 0; }; diff --git a/src/gfx/hud.hpp b/src/gfx/hud.hpp deleted file mode 100644 index bfab10e..0000000 --- a/src/gfx/hud.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -namespace gfx -{ - -struct HudPosition -{ - glm::vec2 anchor = glm::vec2(0.0f); // <0;1> - glm::vec2 pos = glm::vec2(0.0f); // px or px multiplies (scale != 1) - glm::vec2 scale = glm::vec2(1.0f); -}; - -} \ No newline at end of file diff --git a/src/gfx/renderer.cpp b/src/gfx/renderer.cpp index 8df8f6b..ecc144b 100644 --- a/src/gfx/renderer.cpp +++ b/src/gfx/renderer.cpp @@ -417,39 +417,24 @@ void gfx::Renderer::DrawHudList(std::span queue, const DrawListParam glm::vec2 ndc_scale(2.0f / screen_size_px.x, -2.0f / screen_size_px.y); constexpr glm::vec2 ndc_offset(-1.0f, 1.0f); + glm::mat3 matrix(1.0f); + matrix[0][0] = ndc_scale.x; + matrix[1][1] = ndc_scale.y; + matrix[2][0] = ndc_offset.x; + matrix[2][1] = ndc_offset.y; + + glUniformMatrix3fv(shader->U(SU_MODEL), 1, GL_FALSE, &matrix[0][0]); + const gfx::Texture* last_texture = nullptr; const gfx::VertexArray* last_vao = nullptr; - glm::vec4 last_color = glm::vec4(-1.0f); for (const auto& cmd : queue) { - if (!cmd.va || !cmd.texture || !cmd.pos) + if (!cmd.va || !cmd.texture) { throw std::runtime_error("invalid hud draw"); } - // calculate transform - const auto& hp = *cmd.pos; - - glm::vec2 pos_px = hp.anchor * screen_size_px + hp.pos; - glm::vec2 trans_ndc = ndc_offset + pos_px * ndc_scale; - - glm::mat3 matrix(1.0f); - matrix[0][0] = hp.scale.x * ndc_scale.x; - matrix[1][1] = hp.scale.y * ndc_scale.y; - matrix[2][0] = trans_ndc.x; - matrix[2][1] = trans_ndc.y; - - glUniformMatrix3fv(shader->U(SU_MODEL), 1, GL_FALSE, &matrix[0][0]); - - //sync color - glm::vec4 color = cmd.color ? *cmd.color : glm::vec4(1.0f); - if (last_color != color) - { - glUniform4fv(shader->U(SU_COLOR), 1, &color[0]); - last_color = color; - } - // bind texture if (last_texture != cmd.texture) { diff --git a/src/gfx/shader_sources.cpp b/src/gfx/shader_sources.cpp index 85e8c23..e1821ec 100644 --- a/src/gfx/shader_sources.cpp +++ b/src/gfx/shader_sources.cpp @@ -250,7 +250,6 @@ layout (location = 2) in vec4 a_color; layout (location = 3) in vec2 a_uv; uniform mat3 u_model; -uniform vec4 u_color; out vec4 v_color; out vec2 v_uv; @@ -258,7 +257,7 @@ out vec2 v_uv; void main() { vec3 pos2d = u_model * vec3(a_pos.xy, 1.0); gl_Position = vec4(pos2d.xy, 0.0, 1.0); - v_color = a_color * u_color; + v_color = a_color; v_uv = a_uv; } )GLSL", diff --git a/src/gui/context.cpp b/src/gui/context.cpp index 39c4078..f8564e3 100644 --- a/src/gui/context.cpp +++ b/src/gui/context.cpp @@ -204,13 +204,10 @@ void gui::Context::Render() va_.SetVBOData(vertices_.data(), vertices_.size() * sizeof(vertices_[0])); va_.SetIndices(indices_.data(), indices_.size()); - static const gfx::HudPosition pos; - for (const auto& range : ranges_) { gfx::DrawHudCmd hudcmd; hudcmd.va = &va_; - hudcmd.pos = &pos; hudcmd.texture = range.texture; hudcmd.first = range.start; hudcmd.count = range.count;