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.colors.size() < buf.vertices.size()) {
21 std::cerr << "EntityModel: not enough colors!" << std::endl;
23 if (buf.normals.size() < buf.vertices.size()) {
24 std::cerr << "EntityModel: not enough normals!" << std::endl;
29 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
30 vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
31 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
32 vao.PushAttribute(ATTRIB_NORMAL, buf.normals);
33 vao.PushIndices(ATTRIB_INDEX, buf.indices);
37 void EntityModel::Draw() const noexcept {
38 vao.DrawTriangleElements();
42 void BlockModel::Update(const Buffer &buf) noexcept {
44 if (buf.tex_coords.size() < buf.vertices.size()) {
45 std::cerr << "BlockModel: not enough tex coords!" << std::endl;
47 if (buf.colors.size() < buf.vertices.size()) {
48 std::cerr << "BlockModel: not enough colors!" << std::endl;
50 if (buf.lights.size() < buf.vertices.size()) {
51 std::cerr << "BlockModel: not enough lights!" << std::endl;
56 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
57 vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
58 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
59 vao.PushAttribute(ATTRIB_LIGHT, buf.lights);
60 vao.PushIndices(ATTRIB_INDEX, buf.indices);
64 void BlockModel::Draw() const noexcept {
65 vao.DrawTriangleElements();
69 void OutlineModel::Update(const Buffer &buf) noexcept {
71 if (buf.colors.size() < buf.vertices.size()) {
72 std::cerr << "OutlineModel: not enough colors!" << std::endl;
77 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
78 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
79 vao.PushIndices(ATTRIB_INDEX, buf.indices);
83 void OutlineModel::Draw() noexcept {
84 glEnable(GL_LINE_SMOOTH);
86 vao.DrawLineElements();
90 void SkyBoxModel::LoadUnitBox() {
92 CuboidShape shape({{ -1, -1, -1 }, { 1, 1, 1 }});
93 shape.Vertices(buffer);
97 void SkyBoxModel::Update(const Buffer &buf) noexcept {
99 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
100 vao.PushIndices(ATTRIB_INDEX, buf.indices);
103 void SkyBoxModel::Draw() const noexcept {
104 vao.DrawTriangleElements();
108 void SpriteModel::Buffer::LoadRect(
110 const glm::vec2 &pivot,
111 const glm::vec2 &tex_begin,
112 const glm::vec2 &tex_end
117 vertices.emplace_back( -pivot.x, -pivot.y, 0.0f);
118 vertices.emplace_back(w-pivot.x, -pivot.y, 0.0f);
119 vertices.emplace_back( -pivot.x, h-pivot.y, 0.0f);
120 vertices.emplace_back(w-pivot.x, h-pivot.y, 0.0f);
122 coords.emplace_back(tex_begin.x, tex_begin.y);
123 coords.emplace_back(tex_end.x, tex_begin.y);
124 coords.emplace_back(tex_begin.x, tex_end.y);
125 coords.emplace_back(tex_end.x, tex_end.y);
127 indices.assign({ 0, 2, 1, 1, 2, 3 });
131 void SpriteModel::Update(const Buffer &buf) noexcept {
133 if (buf.coords.size() < buf.vertices.size()) {
134 std::cerr << "SpriteModel: not enough coords!" << std::endl;
139 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
140 vao.PushAttribute(ATTRIB_TEXCOORD, buf.coords);
141 vao.PushIndices(ATTRIB_INDEX, buf.indices);
145 void SpriteModel::Draw() noexcept {
146 vao.DrawTriangleElements();