#include "SkyBoxMesh.hpp"
#include "SpriteMesh.hpp"
+#include "../geometry/primitive.hpp"
+
#include <algorithm>
#include <iostream>
std::cerr << "EntityMesh: not enough tex coords!" << std::endl;
}
if (buf.hsl_mods.size() < buf.vertices.size()) {
- std::cerr << "BlockMesh: not enough HSL modifiers!" << std::endl;
+ std::cerr << "EntityMesh: not enough HSL modifiers!" << std::endl;
}
if (buf.rgb_mods.size() < buf.vertices.size()) {
- std::cerr << "BlockMesh: not enough RGB modifiers!" << std::endl;
+ std::cerr << "EntityMesh: not enough RGB modifiers!" << std::endl;
}
if (buf.normals.size() < buf.vertices.size()) {
std::cerr << "EntityMesh: not enough normals!" << std::endl;
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);
}
-void EntityMesh::Draw() const noexcept {
- vao.DrawTriangleElements();
-}
-
-
void BlockMesh::Update(const Buffer &buf) noexcept {
#ifndef NDEBUG
if (buf.tex_coords.size() < buf.vertices.size()) {
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);
}
-void BlockMesh::Draw() const noexcept {
- vao.DrawTriangleElements();
-}
-
-
void PrimitiveMesh::Buffer::FillRect(
float w, float h,
- const glm::vec4 &color,
+ const Color &color,
const glm::vec2 &pivot
) {
Clear();
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
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);
}
-void PrimitiveMesh::DrawLines() noexcept {
+void PrimitiveMesh::DrawLines() const noexcept {
glEnable(GL_LINE_SMOOTH);
glLineWidth(2.0f);
vao.DrawLineElements();
}
-void PrimitiveMesh::DrawTriangles() noexcept {
- vao.DrawTriangleElements();
-}
-
void SkyBoxMesh::LoadUnitBox() {
Buffer buffer;
vao.PushIndices(ATTRIB_INDEX, buf.indices);
}
-void SkyBoxMesh::Draw() const noexcept {
- vao.DrawTriangleElements();
-}
-
void SpriteMesh::Buffer::LoadRect(
float w, float h,
vao.PushIndices(ATTRIB_INDEX, buf.indices);
}
-
-void SpriteMesh::Draw() noexcept {
- vao.DrawTriangleElements();
-}
-
}