1 #include "BlockModel.hpp"
2 #include "EntityModel.hpp"
3 #include "OutlineModel.hpp"
4 #include "SkyBoxModel.hpp"
5 #include "SpriteModel.hpp"
15 void EntityModel::Update(const Buffer &buf) noexcept {
17 if (buf.tex_coords.size() < buf.vertices.size()) {
18 std::cerr << "EntityModel: not enough tex coords!" << std::endl;
20 if (buf.hsl_mods.size() < buf.vertices.size()) {
21 std::cerr << "BlockModel: not enough HSL modifiers!" << std::endl;
23 if (buf.rgb_mods.size() < buf.vertices.size()) {
24 std::cerr << "BlockModel: not enough RGB modifiers!" << std::endl;
26 if (buf.normals.size() < buf.vertices.size()) {
27 std::cerr << "EntityModel: not enough normals!" << std::endl;
32 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
33 vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
34 vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
35 vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
36 vao.PushAttribute(ATTRIB_NORMAL, buf.normals);
37 vao.PushIndices(ATTRIB_INDEX, buf.indices);
41 void EntityModel::Draw() const noexcept {
42 vao.DrawTriangleElements();
46 void BlockModel::Update(const Buffer &buf) noexcept {
48 if (buf.tex_coords.size() < buf.vertices.size()) {
49 std::cerr << "BlockModel: not enough tex coords!" << std::endl;
51 if (buf.hsl_mods.size() < buf.vertices.size()) {
52 std::cerr << "BlockModel: not enough HSL modifiers!" << std::endl;
54 if (buf.rgb_mods.size() < buf.vertices.size()) {
55 std::cerr << "BlockModel: not enough RGB modifiers!" << std::endl;
57 if (buf.lights.size() < buf.vertices.size()) {
58 std::cerr << "BlockModel: not enough lights!" << std::endl;
63 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
64 vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
65 vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
66 vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
67 vao.PushAttribute(ATTRIB_LIGHT, buf.lights);
68 vao.PushIndices(ATTRIB_INDEX, buf.indices);
72 void BlockModel::Draw() const noexcept {
73 vao.DrawTriangleElements();
77 void OutlineModel::Update(const Buffer &buf) noexcept {
79 if (buf.colors.size() < buf.vertices.size()) {
80 std::cerr << "OutlineModel: not enough colors!" << std::endl;
85 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
86 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
87 vao.PushIndices(ATTRIB_INDEX, buf.indices);
91 void OutlineModel::Draw() noexcept {
92 glEnable(GL_LINE_SMOOTH);
94 vao.DrawLineElements();
98 void SkyBoxModel::LoadUnitBox() {
100 CuboidShape shape({{ -1, -1, -1 }, { 1, 1, 1 }});
101 shape.Vertices(buffer);
105 void SkyBoxModel::Update(const Buffer &buf) noexcept {
107 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
108 vao.PushIndices(ATTRIB_INDEX, buf.indices);
111 void SkyBoxModel::Draw() const noexcept {
112 vao.DrawTriangleElements();
116 void SpriteModel::Buffer::LoadRect(
118 const glm::vec2 &pivot,
119 const glm::vec2 &tex_begin,
120 const glm::vec2 &tex_end
125 vertices.emplace_back( -pivot.x, -pivot.y, 0.0f);
126 vertices.emplace_back(w-pivot.x, -pivot.y, 0.0f);
127 vertices.emplace_back( -pivot.x, h-pivot.y, 0.0f);
128 vertices.emplace_back(w-pivot.x, h-pivot.y, 0.0f);
130 coords.emplace_back(tex_begin.x, tex_begin.y);
131 coords.emplace_back(tex_end.x, tex_begin.y);
132 coords.emplace_back(tex_begin.x, tex_end.y);
133 coords.emplace_back(tex_end.x, tex_end.y);
135 indices.assign({ 0, 2, 1, 1, 2, 3 });
139 void SpriteModel::Update(const Buffer &buf) noexcept {
141 if (buf.coords.size() < buf.vertices.size()) {
142 std::cerr << "SpriteModel: not enough coords!" << std::endl;
147 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
148 vao.PushAttribute(ATTRIB_TEXCOORD, buf.coords);
149 vao.PushIndices(ATTRIB_INDEX, buf.indices);
153 void SpriteModel::Draw() noexcept {
154 vao.DrawTriangleElements();