]> git.localhorst.tv Git - blank.git/blobdiff - src/graphics/mesh.cpp
ignore apitrace files
[blank.git] / src / graphics / mesh.cpp
index 3aa631eb77e5e266f156d9516e75760ed92f5c28..9cb8c92ae9736a0337a1c7f681e1a2fe1115f5c1 100644 (file)
@@ -4,6 +4,8 @@
 #include "SkyBoxMesh.hpp"
 #include "SpriteMesh.hpp"
 
+#include "../geometry/primitive.hpp"
+
 #include <algorithm>
 #include <iostream>
 
@@ -29,8 +31,8 @@ void EntityMesh::Update(const Buffer &buf) noexcept {
        vao.Bind();
        vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
        vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
-       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
-       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
+       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods, true);
+       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods, true);
        vao.PushAttribute(ATTRIB_NORMAL, buf.normals);
        vao.PushIndices(ATTRIB_INDEX, buf.indices);
 }
@@ -60,8 +62,8 @@ void BlockMesh::Update(const Buffer &buf) noexcept {
        vao.Bind();
        vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
        vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
-       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
-       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
+       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods, true);
+       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods, true);
        vao.PushAttribute(ATTRIB_LIGHT, buf.lights);
        vao.PushIndices(ATTRIB_INDEX, buf.indices);
 }
@@ -74,7 +76,7 @@ void BlockMesh::Draw() const noexcept {
 
 void PrimitiveMesh::Buffer::FillRect(
        float w, float h,
-       const glm::vec4 &color,
+       const Color &color,
        const glm::vec2 &pivot
 ) {
        Clear();
@@ -90,6 +92,28 @@ void PrimitiveMesh::Buffer::FillRect(
        indices.assign({ 0, 2, 1, 1, 2, 3 });
 }
 
+void PrimitiveMesh::Buffer::OutlineBox(const AABB &box, const Color &color) {
+       Clear();
+       Reserve(8, 24);
+
+       vertices.emplace_back(box.min.x, box.min.y, box.min.z);
+       vertices.emplace_back(box.min.x, box.min.y, box.max.z);
+       vertices.emplace_back(box.min.x, box.max.y, box.min.z);
+       vertices.emplace_back(box.min.x, box.max.y, box.max.z);
+       vertices.emplace_back(box.max.x, box.min.y, box.min.z);
+       vertices.emplace_back(box.max.x, box.min.y, box.max.z);
+       vertices.emplace_back(box.max.x, box.max.y, box.min.z);
+       vertices.emplace_back(box.max.x, box.max.y, box.max.z);
+
+       colors.resize(8, color);
+
+       indices.assign({
+               0, 1, 1, 3, 3, 2, 2, 0, // left
+               4, 5, 5, 7, 7, 6, 6, 4, // right
+               0, 4, 1, 5, 3, 7, 2, 6, // others
+       });
+}
+
 
 void PrimitiveMesh::Update(const Buffer &buf) noexcept {
 #ifndef NDEBUG
@@ -100,7 +124,7 @@ void PrimitiveMesh::Update(const Buffer &buf) noexcept {
 
        vao.Bind();
        vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
-       vao.PushAttribute(ATTRIB_COLOR, buf.colors);
+       vao.PushAttribute(ATTRIB_COLOR, buf.colors, true);
        vao.PushIndices(ATTRIB_INDEX, buf.indices);
 }