]> git.localhorst.tv Git - blank.git/commitdiff
model -> mesh
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 12 Oct 2015 08:22:17 +0000 (10:22 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 12 Oct 2015 08:41:30 +0000 (10:41 +0200)
29 files changed:
src/graphics/BlockMesh.hpp [new file with mode: 0644]
src/graphics/EntityMesh.hpp [new file with mode: 0644]
src/graphics/OutlineMesh.hpp [new file with mode: 0644]
src/graphics/SkyBox.hpp
src/graphics/SkyBoxMesh.hpp [new file with mode: 0644]
src/graphics/SpriteMesh.hpp [new file with mode: 0644]
src/graphics/mesh.cpp [new file with mode: 0644]
src/graphics/viewport.cpp
src/io/WorldSave.cpp
src/model/BlockModel.hpp [deleted file]
src/model/CompositeModel.hpp
src/model/EntityModel.hpp [deleted file]
src/model/OutlineModel.hpp [deleted file]
src/model/Shape.hpp
src/model/Skeletons.hpp
src/model/SkyBoxModel.hpp [deleted file]
src/model/SpriteModel.hpp [deleted file]
src/model/composite.cpp
src/model/model.cpp [deleted file]
src/model/shape.cpp
src/ui/HUD.hpp
src/ui/Text.hpp
src/ui/ui.cpp
src/ui/widgets.cpp
src/world/BlockType.hpp
src/world/Chunk.hpp
src/world/ChunkRenderer.hpp
src/world/block.cpp
src/world/chunk.cpp

diff --git a/src/graphics/BlockMesh.hpp b/src/graphics/BlockMesh.hpp
new file mode 100644 (file)
index 0000000..e62b601
--- /dev/null
@@ -0,0 +1,81 @@
+#ifndef BLANK_GRAPHICS_BLOCKMESH_HPP_
+#define BLANK_GRAPHICS_BLOCKMESH_HPP_
+
+#include "VertexArray.hpp"
+
+#include <vector>
+#include <GL/glew.h>
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class BlockMesh {
+
+public:
+       using Position = glm::vec3;
+       using TexCoord = glm::vec3;
+       using ColorMod = glm::vec3;
+       using Light = float;
+       using Index = unsigned int;
+
+       using Positions = std::vector<Position>;
+       using TexCoords = std::vector<TexCoord>;
+       using ColorMods = std::vector<ColorMod>;
+       using Lights = std::vector<Light>;
+       using Indices = std::vector<Index>;
+
+       enum Attribute {
+               ATTRIB_VERTEX,
+               ATTRIB_TEXCOORD,
+               ATTRIB_HSL,
+               ATTRIB_RGB,
+               ATTRIB_LIGHT,
+               ATTRIB_INDEX,
+               ATTRIB_COUNT,
+       };
+
+       struct Buffer {
+
+               Positions vertices;
+               TexCoords tex_coords;
+               ColorMods hsl_mods;
+               ColorMods rgb_mods;
+               Lights lights;
+               Indices indices;
+
+               void Clear() noexcept {
+                       vertices.clear();
+                       tex_coords.clear();
+                       hsl_mods.clear();
+                       rgb_mods.clear();
+                       lights.clear();
+                       indices.clear();
+               }
+
+               void Reserve(size_t p, size_t i) {
+                       vertices.reserve(p);
+                       tex_coords.reserve(p);
+                       hsl_mods.reserve(p);
+                       rgb_mods.reserve(p);
+                       lights.reserve(p);
+                       indices.reserve(i);
+               }
+
+       };
+
+       using VAO = VertexArray<ATTRIB_COUNT>;
+
+public:
+       void Update(const Buffer &) noexcept;
+
+       void Draw() const noexcept;
+
+private:
+       VAO vao;
+
+};
+
+}
+
+#endif
diff --git a/src/graphics/EntityMesh.hpp b/src/graphics/EntityMesh.hpp
new file mode 100644 (file)
index 0000000..6b894f9
--- /dev/null
@@ -0,0 +1,81 @@
+#ifndef BLANK_GRAPHICS_ENTITYMESH_HPP_
+#define BLANK_GRAPHICS_ENTITYMESH_HPP_
+
+#include "VertexArray.hpp"
+
+#include <vector>
+#include <GL/glew.h>
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class EntityMesh {
+
+public:
+       using Position = glm::vec3;
+       using TexCoord = glm::vec3;
+       using ColorMod = glm::vec3;
+       using Normal = glm::vec3;
+       using Index = unsigned int;
+
+       using Positions = std::vector<Position>;
+       using TexCoords = std::vector<TexCoord>;
+       using ColorMods = std::vector<ColorMod>;
+       using Normals = std::vector<Normal>;
+       using Indices = std::vector<Index>;
+
+       enum Attribute {
+               ATTRIB_VERTEX,
+               ATTRIB_TEXCOORD,
+               ATTRIB_HSL,
+               ATTRIB_RGB,
+               ATTRIB_NORMAL,
+               ATTRIB_INDEX,
+               ATTRIB_COUNT,
+       };
+
+       struct Buffer {
+
+               Positions vertices;
+               TexCoords tex_coords;
+               ColorMods hsl_mods;
+               ColorMods rgb_mods;
+               Normals normals;
+               Indices indices;
+
+               void Clear() noexcept {
+                       vertices.clear();
+                       tex_coords.clear();
+                       hsl_mods.clear();
+                       rgb_mods.clear();
+                       normals.clear();
+                       indices.clear();
+               }
+
+               void Reserve(size_t p, size_t i) {
+                       vertices.reserve(p);
+                       tex_coords.reserve(p);
+                       hsl_mods.reserve(p);
+                       rgb_mods.reserve(p);
+                       normals.reserve(p);
+                       indices.reserve(i);
+               }
+
+       };
+
+       using VAO = VertexArray<ATTRIB_COUNT>;
+
+public:
+       void Update(const Buffer &) noexcept;
+
+       void Draw() const noexcept;
+
+private:
+       VAO vao;
+
+};
+
+}
+
+#endif
diff --git a/src/graphics/OutlineMesh.hpp b/src/graphics/OutlineMesh.hpp
new file mode 100644 (file)
index 0000000..77e0436
--- /dev/null
@@ -0,0 +1,65 @@
+#ifndef BLANK_GRAPHICS_OUTLINEMESH_HPP_
+#define BLANK_GRAPHICS_OUTLINEMESH_HPP_
+
+#include "VertexArray.hpp"
+
+#include <vector>
+#include <GL/glew.h>
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class OutlineMesh {
+
+public:
+       using Position = glm::vec3;
+       using Color = glm::vec3;
+       using Index = unsigned short;
+
+       using Positions = std::vector<Position>;
+       using Colors = std::vector<Color>;
+       using Indices = std::vector<Index>;
+
+       enum Attribute {
+               ATTRIB_VERTEX,
+               ATTRIB_COLOR,
+               ATTRIB_INDEX,
+               ATTRIB_COUNT,
+       };
+
+       struct Buffer {
+
+               Positions vertices;
+               Colors colors;
+               Indices indices;
+
+               void Clear() noexcept {
+                       vertices.clear();
+                       colors.clear();
+                       indices.clear();
+               }
+
+               void Reserve(size_t p, size_t i) {
+                       vertices.reserve(p);
+                       colors.reserve(p);
+                       indices.reserve(i);
+               }
+
+       };
+
+       using VAO = VertexArray<ATTRIB_COUNT>;
+
+public:
+       void Update(const Buffer &) noexcept;
+
+       void Draw() noexcept;
+
+private:
+       VAO vao;
+
+};
+
+}
+
+#endif
index 1254fe2dde0b4c4c9c536aa7da66d3d2e404e229..c2bb6f8d5da5a9a012757fbf7229e215a1311d8c 100644 (file)
@@ -2,7 +2,7 @@
 #define BLANK_GRAPHICS_SKYBOX_HPP_
 
 #include "CubeMap.hpp"
-#include "../model/SkyBoxModel.hpp"
+#include "SkyBoxMesh.hpp"
 
 
 namespace blank {
@@ -18,7 +18,7 @@ public:
 
 private:
        CubeMap texture;
-       SkyBoxModel model;
+       SkyBoxMesh mesh;
 
 };
 
diff --git a/src/graphics/SkyBoxMesh.hpp b/src/graphics/SkyBoxMesh.hpp
new file mode 100644 (file)
index 0000000..ab1da8d
--- /dev/null
@@ -0,0 +1,59 @@
+#ifndef BLANK_GRAPHICS_SKYBOXMESH_HPP_
+#define BLANK_GRAPHICS_SKYBOXMESH_HPP_
+
+#include "VertexArray.hpp"
+
+#include <vector>
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class SkyBoxMesh {
+
+public:
+       using Position = glm::vec3;
+       using Index = unsigned int;
+
+       using Positions = std::vector<Position>;
+       using Indices = std::vector<Index>;
+
+       enum Attribute {
+               ATTRIB_VERTEX,
+               ATTRIB_INDEX,
+               ATTRIB_COUNT,
+       };
+
+       struct Buffer {
+
+               Positions vertices;
+               Indices indices;
+
+               void Clear() noexcept {
+                       vertices.clear();
+                       indices.clear();
+               }
+
+               void Reserve(size_t p, size_t i) {
+                       vertices.reserve(p);
+                       indices.reserve(i);
+               }
+
+       };
+
+       using VAO = VertexArray<ATTRIB_COUNT>;
+
+public:
+       void LoadUnitBox();
+       void Update(const Buffer &) noexcept;
+
+       void Draw() const noexcept;
+
+private:
+       VAO vao;
+
+};
+
+}
+
+#endif
diff --git a/src/graphics/SpriteMesh.hpp b/src/graphics/SpriteMesh.hpp
new file mode 100644 (file)
index 0000000..a7cfd64
--- /dev/null
@@ -0,0 +1,72 @@
+#ifndef BLANK_GRPAHICS_SPRITEMESH_HPP_
+#define BLANK_GRPAHICS_SPRITEMESH_HPP_
+
+#include "VertexArray.hpp"
+
+#include <vector>
+#include <GL/glew.h>
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class SpriteMesh {
+
+public:
+       using Position = glm::vec3;
+       using TexCoord = glm::vec2;
+       using Index = unsigned short;
+
+       using Positions = std::vector<Position>;
+       using TexCoords = std::vector<TexCoord>;
+       using Indices = std::vector<Index>;
+
+       enum Attribute {
+               ATTRIB_VERTEX,
+               ATTRIB_TEXCOORD,
+               ATTRIB_INDEX,
+               ATTRIB_COUNT,
+       };
+
+       struct Buffer {
+
+               Positions vertices;
+               TexCoords coords;
+               Indices indices;
+
+               void Clear() noexcept {
+                       vertices.clear();
+                       coords.clear();
+                       indices.clear();
+               }
+
+               void Reserve(size_t p, size_t i) {
+                       vertices.reserve(p);
+                       coords.reserve(p);
+                       indices.reserve(i);
+               }
+
+               void LoadRect(
+                       float w, float h,
+                       const glm::vec2 &pivot = glm::vec2(0.0f),
+                       const glm::vec2 &tex_begin = glm::vec2(0.0f),
+                       const glm::vec2 &tex_end = glm::vec2(1.0f, 1.0f)
+               );
+
+       };
+
+       using VAO = VertexArray<ATTRIB_COUNT>;
+
+public:
+       void Update(const Buffer &) noexcept;
+
+       void Draw() noexcept;
+
+private:
+       VAO vao;
+
+};
+
+}
+
+#endif
diff --git a/src/graphics/mesh.cpp b/src/graphics/mesh.cpp
new file mode 100644 (file)
index 0000000..4b0f582
--- /dev/null
@@ -0,0 +1,171 @@
+#include "BlockMesh.hpp"
+#include "EntityMesh.hpp"
+#include "OutlineMesh.hpp"
+#include "SkyBoxMesh.hpp"
+#include "SpriteMesh.hpp"
+
+#include <algorithm>
+#include <iostream>
+
+
+namespace blank {
+
+void EntityMesh::Update(const Buffer &buf) noexcept {
+#ifndef NDEBUG
+       if (buf.tex_coords.size() < buf.vertices.size()) {
+               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;
+       }
+       if (buf.rgb_mods.size() < buf.vertices.size()) {
+               std::cerr << "BlockMesh: not enough RGB modifiers!" << std::endl;
+       }
+       if (buf.normals.size() < buf.vertices.size()) {
+               std::cerr << "EntityMesh: not enough normals!" << std::endl;
+       }
+#endif
+
+       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_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()) {
+               std::cerr << "BlockMesh: not enough tex coords!" << std::endl;
+       }
+       if (buf.hsl_mods.size() < buf.vertices.size()) {
+               std::cerr << "BlockMesh: not enough HSL modifiers!" << std::endl;
+       }
+       if (buf.rgb_mods.size() < buf.vertices.size()) {
+               std::cerr << "BlockMesh: not enough RGB modifiers!" << std::endl;
+       }
+       if (buf.lights.size() < buf.vertices.size()) {
+               std::cerr << "BlockMesh: not enough lights!" << std::endl;
+       }
+#endif
+
+       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_LIGHT, buf.lights);
+       vao.PushIndices(ATTRIB_INDEX, buf.indices);
+}
+
+
+void BlockMesh::Draw() const noexcept {
+       vao.DrawTriangleElements();
+}
+
+
+void OutlineMesh::Update(const Buffer &buf) noexcept {
+#ifndef NDEBUG
+       if (buf.colors.size() < buf.vertices.size()) {
+               std::cerr << "OutlineMesh: not enough colors!" << std::endl;
+       }
+#endif
+
+       vao.Bind();
+       vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
+       vao.PushAttribute(ATTRIB_COLOR, buf.colors);
+       vao.PushIndices(ATTRIB_INDEX, buf.indices);
+}
+
+
+void OutlineMesh::Draw() noexcept {
+       glEnable(GL_LINE_SMOOTH);
+       glLineWidth(2.0f);
+       vao.DrawLineElements();
+}
+
+
+void SkyBoxMesh::LoadUnitBox() {
+       Buffer buffer;
+       buffer.vertices = {
+               {  1.0f,  1.0f,  1.0f },
+               {  1.0f,  1.0f, -1.0f },
+               {  1.0f, -1.0f,  1.0f },
+               {  1.0f, -1.0f, -1.0f },
+               { -1.0f,  1.0f,  1.0f },
+               { -1.0f,  1.0f, -1.0f },
+               { -1.0f, -1.0f,  1.0f },
+               { -1.0f, -1.0f, -1.0f },
+       };
+       buffer.indices = {
+               5, 7, 3,  3, 1, 5,
+               6, 7, 5,  5, 4, 6,
+               3, 2, 0,  0, 1, 3,
+               6, 4, 0,  0, 2, 6,
+               5, 1, 0,  0, 4, 5,
+               7, 6, 3,  3, 6, 2,
+       };
+       Update(buffer);
+}
+
+void SkyBoxMesh::Update(const Buffer &buf) noexcept {
+       vao.Bind();
+       vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
+       vao.PushIndices(ATTRIB_INDEX, buf.indices);
+}
+
+void SkyBoxMesh::Draw() const noexcept {
+       vao.DrawTriangleElements();
+}
+
+
+void SpriteMesh::Buffer::LoadRect(
+       float w, float h,
+       const glm::vec2 &pivot,
+       const glm::vec2 &tex_begin,
+       const glm::vec2 &tex_end
+) {
+       Clear();
+       Reserve(4, 6);
+
+       vertices.emplace_back( -pivot.x,  -pivot.y, 0.0f);
+       vertices.emplace_back(w-pivot.x,  -pivot.y, 0.0f);
+       vertices.emplace_back( -pivot.x, h-pivot.y, 0.0f);
+       vertices.emplace_back(w-pivot.x, h-pivot.y, 0.0f);
+
+       coords.emplace_back(tex_begin.x, tex_begin.y);
+       coords.emplace_back(tex_end.x,   tex_begin.y);
+       coords.emplace_back(tex_begin.x, tex_end.y);
+       coords.emplace_back(tex_end.x,   tex_end.y);
+
+       indices.assign({ 0, 2, 1, 1, 2, 3 });
+}
+
+
+void SpriteMesh::Update(const Buffer &buf) noexcept {
+#ifndef NDEBUG
+       if (buf.coords.size() < buf.vertices.size()) {
+               std::cerr << "SpriteMesh: not enough coords!" << std::endl;
+       }
+#endif
+
+       vao.Bind();
+       vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
+       vao.PushAttribute(ATTRIB_TEXCOORD, buf.coords);
+       vao.PushIndices(ATTRIB_INDEX, buf.indices);
+}
+
+
+void SpriteMesh::Draw() noexcept {
+       vao.DrawTriangleElements();
+}
+
+}
index ddc609baad6599a88012ba8b8dd4128c31e600a2..ad58b58be677d033962a2687d88f961e6ebe71e1 100644 (file)
@@ -76,14 +76,14 @@ void Canvas::UpdateProjection() noexcept {
 
 SkyBox::SkyBox(CubeMap &&tex)
 : texture(std::move(tex))
-, model() {
-       model.LoadUnitBox();
+, mesh() {
+       mesh.LoadUnitBox();
 }
 
 void SkyBox::Render(Viewport &viewport) noexcept {
        SkyBoxShader &prog = viewport.SkyBoxProgram();
        prog.SetTexture(texture);
-       model.Draw();
+       mesh.Draw();
 }
 
 
index f45410b8d75b2eb0a2cbb145958584b2402d845c..6414dd0a7be43129f2840562454ead38ae12bc79 100644 (file)
@@ -177,7 +177,7 @@ void WorldSave::Read(Chunk &chunk) const {
        if (gzclose(file) != Z_OK) {
                throw runtime_error("failed to read chunk file");
        }
-       chunk.InvalidateModel();
+       chunk.InvalidateMesh();
        chunk.ClearSave();
 }
 
diff --git a/src/model/BlockModel.hpp b/src/model/BlockModel.hpp
deleted file mode 100644 (file)
index 0c1543b..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-#ifndef BLANK_MODEL_BLOCKMODEL_HPP_
-#define BLANK_MODEL_BLOCKMODEL_HPP_
-
-#include "../graphics/VertexArray.hpp"
-
-#include <vector>
-#include <GL/glew.h>
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-class BlockModel {
-
-public:
-       using Position = glm::vec3;
-       using TexCoord = glm::vec3;
-       using ColorMod = glm::vec3;
-       using Light = float;
-       using Index = unsigned int;
-
-       using Positions = std::vector<Position>;
-       using TexCoords = std::vector<TexCoord>;
-       using ColorMods = std::vector<ColorMod>;
-       using Lights = std::vector<Light>;
-       using Indices = std::vector<Index>;
-
-       enum Attribute {
-               ATTRIB_VERTEX,
-               ATTRIB_TEXCOORD,
-               ATTRIB_HSL,
-               ATTRIB_RGB,
-               ATTRIB_LIGHT,
-               ATTRIB_INDEX,
-               ATTRIB_COUNT,
-       };
-
-       struct Buffer {
-
-               Positions vertices;
-               TexCoords tex_coords;
-               ColorMods hsl_mods;
-               ColorMods rgb_mods;
-               Lights lights;
-               Indices indices;
-
-               void Clear() noexcept {
-                       vertices.clear();
-                       tex_coords.clear();
-                       hsl_mods.clear();
-                       rgb_mods.clear();
-                       lights.clear();
-                       indices.clear();
-               }
-
-               void Reserve(size_t p, size_t i) {
-                       vertices.reserve(p);
-                       tex_coords.reserve(p);
-                       hsl_mods.reserve(p);
-                       rgb_mods.reserve(p);
-                       lights.reserve(p);
-                       indices.reserve(i);
-               }
-
-       };
-
-       using VAO = VertexArray<ATTRIB_COUNT>;
-
-public:
-       void Update(const Buffer &) noexcept;
-
-       void Draw() const noexcept;
-
-private:
-       VAO vao;
-
-};
-
-}
-
-#endif
index 947db0140b4a32219a26b44b57301070ed65ada9..4b3d2a9b9549ddcc4b2b8940131d66d52a21303d 100644 (file)
@@ -12,7 +12,7 @@
 namespace blank {
 
 class CompositeInstance;
-class EntityModel;
+class EntityMesh;
 
 class CompositeModel {
 
@@ -34,10 +34,10 @@ public:
        const glm::quat &Orientation() const noexcept { return orientation; }
        void Orientation(const glm::quat &o) noexcept { orientation = o; }
 
-       bool HasNodeModel() const noexcept { return node_model; }
-       void SetNodeModel(const EntityModel *m) noexcept { node_model = m; }
+       bool HasNodeMesh() const noexcept { return node_mesh; }
+       void SetNodeMesh(const EntityMesh *m) noexcept { node_mesh = m; }
 
-       const EntityModel &NodeModel() const noexcept { return *node_model; }
+       const EntityMesh &NodeMesh() const noexcept { return *node_mesh; }
 
        CompositeModel &AddPart();
        bool HasParent() const noexcept { return parent; }
@@ -51,7 +51,7 @@ public:
 
 private:
        CompositeModel *parent;
-       const EntityModel *node_model;
+       const EntityMesh *node_mesh;
 
        std::uint32_t id;
 
diff --git a/src/model/EntityModel.hpp b/src/model/EntityModel.hpp
deleted file mode 100644 (file)
index a89d00b..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-#ifndef BLANK_MODEL_ENTITYMODEL_HPP_
-#define BLANK_MODEL_ENTITYMODEL_HPP_
-
-#include "../graphics/VertexArray.hpp"
-
-#include <vector>
-#include <GL/glew.h>
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-class EntityModel {
-
-public:
-       using Position = glm::vec3;
-       using TexCoord = glm::vec3;
-       using ColorMod = glm::vec3;
-       using Normal = glm::vec3;
-       using Index = unsigned int;
-
-       using Positions = std::vector<Position>;
-       using TexCoords = std::vector<TexCoord>;
-       using ColorMods = std::vector<ColorMod>;
-       using Normals = std::vector<Normal>;
-       using Indices = std::vector<Index>;
-
-       enum Attribute {
-               ATTRIB_VERTEX,
-               ATTRIB_TEXCOORD,
-               ATTRIB_HSL,
-               ATTRIB_RGB,
-               ATTRIB_NORMAL,
-               ATTRIB_INDEX,
-               ATTRIB_COUNT,
-       };
-
-       struct Buffer {
-
-               Positions vertices;
-               TexCoords tex_coords;
-               ColorMods hsl_mods;
-               ColorMods rgb_mods;
-               Normals normals;
-               Indices indices;
-
-               void Clear() noexcept {
-                       vertices.clear();
-                       tex_coords.clear();
-                       hsl_mods.clear();
-                       rgb_mods.clear();
-                       normals.clear();
-                       indices.clear();
-               }
-
-               void Reserve(size_t p, size_t i) {
-                       vertices.reserve(p);
-                       tex_coords.reserve(p);
-                       hsl_mods.reserve(p);
-                       rgb_mods.reserve(p);
-                       normals.reserve(p);
-                       indices.reserve(i);
-               }
-
-       };
-
-       using VAO = VertexArray<ATTRIB_COUNT>;
-
-public:
-       void Update(const Buffer &) noexcept;
-
-       void Draw() const noexcept;
-
-private:
-       VAO vao;
-
-};
-
-}
-
-#endif
diff --git a/src/model/OutlineModel.hpp b/src/model/OutlineModel.hpp
deleted file mode 100644 (file)
index ba85fc8..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-#ifndef BLANK_MODEL_OUTLINEMODEL_HPP_
-#define BLANK_MODEL_OUTLINEMODEL_HPP_
-
-#include "../graphics/VertexArray.hpp"
-
-#include <vector>
-#include <GL/glew.h>
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-class OutlineModel {
-
-public:
-       using Position = glm::vec3;
-       using Color = glm::vec3;
-       using Index = unsigned short;
-
-       using Positions = std::vector<Position>;
-       using Colors = std::vector<Color>;
-       using Indices = std::vector<Index>;
-
-       enum Attribute {
-               ATTRIB_VERTEX,
-               ATTRIB_COLOR,
-               ATTRIB_INDEX,
-               ATTRIB_COUNT,
-       };
-
-       struct Buffer {
-
-               Positions vertices;
-               Colors colors;
-               Indices indices;
-
-               void Clear() noexcept {
-                       vertices.clear();
-                       colors.clear();
-                       indices.clear();
-               }
-
-               void Reserve(size_t p, size_t i) {
-                       vertices.reserve(p);
-                       colors.reserve(p);
-                       indices.reserve(i);
-               }
-
-       };
-
-       using VAO = VertexArray<ATTRIB_COUNT>;
-
-public:
-       void Update(const Buffer &) noexcept;
-
-       void Draw() noexcept;
-
-private:
-       VAO vao;
-
-};
-
-}
-
-#endif
index 312b1aafd1cf212951ffeee433ed2a22b99da5bf..d2e06952ed2eae5410ae4657e6a5d6af7c5249de 100644 (file)
@@ -1,10 +1,9 @@
 #ifndef BLANK_MODEL_SHAPE_HPP_
 #define BLANK_MODEL_SHAPE_HPP_
 
-#include "BlockModel.hpp"
-#include "EntityModel.hpp"
-#include "OutlineModel.hpp"
-#include "SkyBoxModel.hpp"
+#include "../graphics/BlockMesh.hpp"
+#include "../graphics/EntityMesh.hpp"
+#include "../graphics/OutlineMesh.hpp"
 
 #include <glm/glm.hpp>
 
@@ -21,33 +20,30 @@ struct Shape {
        /// the number of vertex indices this shape has
        size_t VertexIndexCount() const noexcept { return vtx_idx.size(); }
 
-       const EntityModel::Normal &VertexNormal(size_t idx) const noexcept { return vtx_nrm[idx]; }
-       EntityModel::Normal VertexNormal(
+       const EntityMesh::Normal &VertexNormal(size_t idx) const noexcept { return vtx_nrm[idx]; }
+       EntityMesh::Normal VertexNormal(
                size_t idx, const glm::mat4 &transform
        ) const noexcept {
-               return EntityModel::Normal(transform * glm::vec4(vtx_nrm[idx], 0.0f));
+               return EntityMesh::Normal(transform * glm::vec4(vtx_nrm[idx], 0.0f));
        }
 
        /// fill given buffers with this shape's elements with an
        /// optional transform and offset
        void Vertices(
-               EntityModel::Buffer &out,
+               EntityMesh::Buffer &out,
                float tex_offset = 0.0f
        ) const;
        void Vertices(
-               EntityModel::Buffer &out,
+               EntityMesh::Buffer &out,
                const glm::mat4 &transform,
                float tex_offset = 0.0f,
-               EntityModel::Index idx_offset = 0
+               EntityMesh::Index idx_offset = 0
        ) const;
        void Vertices(
-               BlockModel::Buffer &out,
+               BlockMesh::Buffer &out,
                const glm::mat4 &transform,
                float tex_offset = 0.0f,
-               BlockModel::Index idx_offset = 0
-       ) const;
-       void Vertices(
-               SkyBoxModel::Buffer &out
+               BlockMesh::Index idx_offset = 0
        ) const;
 
        /// the number of vertices this shape's outline has
@@ -56,7 +52,7 @@ struct Shape {
        size_t OutlineIndexCount() const { return out_idx.size(); }
 
        /// fill given buffers with this shape's outline's elements
-       void Outline(OutlineModel::Buffer &out) const;
+       void Outline(OutlineMesh::Buffer &out) const;
 
        /// Check if given ray would pass though this shape if it were
        /// transformed with given matrix.
@@ -81,24 +77,24 @@ struct Shape {
 
 protected:
        void SetShape(
-               const EntityModel::Positions &pos,
-               const EntityModel::Normals &nrm,
-               const EntityModel::Indices &idx);
+               const EntityMesh::Positions &pos,
+               const EntityMesh::Normals &nrm,
+               const EntityMesh::Indices &idx);
        void SetTexture(
-               const BlockModel::TexCoords &tex_coords);
+               const BlockMesh::TexCoords &tex_coords);
        void SetOutline(
-               const OutlineModel::Positions &pos,
-               const OutlineModel::Indices &idx);
+               const OutlineMesh::Positions &pos,
+               const OutlineMesh::Indices &idx);
 
 private:
-       EntityModel::Positions vtx_pos;
-       EntityModel::Normals vtx_nrm;
-       EntityModel::Indices vtx_idx;
+       EntityMesh::Positions vtx_pos;
+       EntityMesh::Normals vtx_nrm;
+       EntityMesh::Indices vtx_idx;
 
-       BlockModel::TexCoords vtx_tex_coords;
+       BlockMesh::TexCoords vtx_tex_coords;
 
-       OutlineModel::Positions out_pos;
-       OutlineModel::Indices out_idx;
+       OutlineMesh::Positions out_pos;
+       OutlineMesh::Indices out_idx;
 
 };
 
index 131bf0cfd1218258b56eecbe6eb64a53301e034a..250ebce1dff22f7a329c217930578519f0dee4da 100644 (file)
@@ -9,7 +9,7 @@
 namespace blank {
 
 class CompositeModel;
-class EntityModel;
+class EntityMesh;
 
 class Skeletons {
 
@@ -35,7 +35,7 @@ public:
 
 private:
        std::vector<std::unique_ptr<CompositeModel>> skeletons;
-       std::vector<EntityModel> models;
+       std::vector<EntityMesh> meshes;
 
 };
 
diff --git a/src/model/SkyBoxModel.hpp b/src/model/SkyBoxModel.hpp
deleted file mode 100644 (file)
index 84555ee..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#ifndef BLANK_MODEL_SKYBOXMODEL_HPP_
-#define BLANK_MODEL_SKYBOXMODEL_HPP_
-
-#include "../graphics/VertexArray.hpp"
-
-#include <vector>
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-class SkyBoxModel {
-
-public:
-       using Position = glm::vec3;
-       using Index = unsigned int;
-
-       using Positions = std::vector<Position>;
-       using Indices = std::vector<Index>;
-
-       enum Attribute {
-               ATTRIB_VERTEX,
-               ATTRIB_INDEX,
-               ATTRIB_COUNT,
-       };
-
-       struct Buffer {
-
-               Positions vertices;
-               Indices indices;
-
-               void Clear() noexcept {
-                       vertices.clear();
-                       indices.clear();
-               }
-
-               void Reserve(size_t p, size_t i) {
-                       vertices.reserve(p);
-                       indices.reserve(i);
-               }
-
-       };
-
-       using VAO = VertexArray<ATTRIB_COUNT>;
-
-public:
-       void LoadUnitBox();
-       void Update(const Buffer &) noexcept;
-
-       void Draw() const noexcept;
-
-private:
-       VAO vao;
-
-};
-
-}
-
-#endif
diff --git a/src/model/SpriteModel.hpp b/src/model/SpriteModel.hpp
deleted file mode 100644 (file)
index c5670fc..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#ifndef BLANK_MODEL_SPRITEMODEL_HPP_
-#define BLANK_MODEL_SPRITEMODEL_HPP_
-
-#include "../graphics/VertexArray.hpp"
-
-#include <vector>
-#include <GL/glew.h>
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-class SpriteModel {
-
-public:
-       using Position = glm::vec3;
-       using TexCoord = glm::vec2;
-       using Index = unsigned short;
-
-       using Positions = std::vector<Position>;
-       using TexCoords = std::vector<TexCoord>;
-       using Indices = std::vector<Index>;
-
-       enum Attribute {
-               ATTRIB_VERTEX,
-               ATTRIB_TEXCOORD,
-               ATTRIB_INDEX,
-               ATTRIB_COUNT,
-       };
-
-       struct Buffer {
-
-               Positions vertices;
-               TexCoords coords;
-               Indices indices;
-
-               void Clear() noexcept {
-                       vertices.clear();
-                       coords.clear();
-                       indices.clear();
-               }
-
-               void Reserve(size_t p, size_t i) {
-                       vertices.reserve(p);
-                       coords.reserve(p);
-                       indices.reserve(i);
-               }
-
-               void LoadRect(
-                       float w, float h,
-                       const glm::vec2 &pivot = glm::vec2(0.0f),
-                       const glm::vec2 &tex_begin = glm::vec2(0.0f),
-                       const glm::vec2 &tex_end = glm::vec2(1.0f, 1.0f)
-               );
-
-       };
-
-       using VAO = VertexArray<ATTRIB_COUNT>;
-
-public:
-       void Update(const Buffer &) noexcept;
-
-       void Draw() noexcept;
-
-private:
-       VAO vao;
-
-};
-
-}
-
-#endif
index b2e7022524badf60be55898efa7bb1d33dfb1aa0..850777078b72d8b8b113025c8bdb2d6d9162b255 100644 (file)
@@ -2,9 +2,9 @@
 #include "CompositeInstance.hpp"
 #include "Skeletons.hpp"
 
-#include "EntityModel.hpp"
 #include "shapes.hpp"
 #include "../graphics/DirectionalLighting.hpp"
+#include "../graphics/EntityMesh.hpp"
 
 #include <glm/gtx/quaternion.hpp>
 
@@ -13,7 +13,7 @@ namespace blank {
 
 CompositeModel::CompositeModel()
 : parent(nullptr)
-, node_model(nullptr)
+, node_mesh(nullptr)
 , id(0)
 , bounds{{ 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }}
 , position(0.0f)
@@ -95,9 +95,9 @@ glm::mat4 CompositeInstance::GlobalTransform() const noexcept {
 
 void CompositeInstance::Render(const glm::mat4 &M, DirectionalLighting &prog) const {
        glm::mat4 transform(M * LocalTransform());
-       if (part_model->HasNodeModel()) {
+       if (part_model->HasNodeMesh()) {
                prog.SetM(transform);
-               part_model->NodeModel().Draw();
+               part_model->NodeMesh().Draw();
        }
        for (const CompositeInstance &part : parts) {
                part.Render(transform, prog);
@@ -107,7 +107,7 @@ void CompositeInstance::Render(const glm::mat4 &M, DirectionalLighting &prog) co
 
 Skeletons::Skeletons()
 : skeletons()
-, models() {
+, meshes() {
 
 }
 
@@ -146,15 +146,15 @@ void Skeletons::LoadHeadless() {
 
 void Skeletons::Load() {
        LoadHeadless();
-       models.resize(4);
-       EntityModel::Buffer buf;
+       meshes.resize(4);
+       EntityMesh::Buffer buf;
        {
                CuboidShape shape(skeletons[0]->Bounds());
                shape.Vertices(buf, 3.0f);
                buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
                buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 1.0f, 0.0f });
-               models[0].Update(buf);
-               skeletons[0]->SetNodeModel(&models[0]);
+               meshes[0].Update(buf);
+               skeletons[0]->SetNodeMesh(&meshes[0]);
        }
        {
                CuboidShape shape(skeletons[1]->Bounds());
@@ -162,8 +162,8 @@ void Skeletons::Load() {
                shape.Vertices(buf, 0.0f);
                buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
                buf.rgb_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
-               models[1].Update(buf);
-               skeletons[1]->SetNodeModel(&models[1]);
+               meshes[1].Update(buf);
+               skeletons[1]->SetNodeMesh(&meshes[1]);
        }
        {
                StairShape shape(skeletons[2]->Bounds(), { 0.4f, 0.4f });
@@ -171,8 +171,8 @@ void Skeletons::Load() {
                shape.Vertices(buf, 1.0f);
                buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
                buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 0.0f, 1.0f });
-               models[2].Update(buf);
-               skeletons[2]->SetNodeModel(&models[2]);
+               meshes[2].Update(buf);
+               skeletons[2]->SetNodeMesh(&meshes[2]);
        }
        {
                CuboidShape shape(skeletons[3]->Bounds());
@@ -180,8 +180,8 @@ void Skeletons::Load() {
                shape.Vertices(buf, 2.0f);
                buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
                buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 0.25f, 0.5f });
-               models[3].Update(buf);
-               skeletons[3]->SetNodeModel(&models[3]);
+               meshes[3].Update(buf);
+               skeletons[3]->SetNodeMesh(&meshes[3]);
        }
 }
 
diff --git a/src/model/model.cpp b/src/model/model.cpp
deleted file mode 100644 (file)
index cc6e20e..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-#include "BlockModel.hpp"
-#include "EntityModel.hpp"
-#include "OutlineModel.hpp"
-#include "SkyBoxModel.hpp"
-#include "SpriteModel.hpp"
-
-#include "shapes.hpp"
-
-#include <algorithm>
-#include <iostream>
-
-
-namespace blank {
-
-void EntityModel::Update(const Buffer &buf) noexcept {
-#ifndef NDEBUG
-       if (buf.tex_coords.size() < buf.vertices.size()) {
-               std::cerr << "EntityModel: not enough tex coords!" << std::endl;
-       }
-       if (buf.hsl_mods.size() < buf.vertices.size()) {
-               std::cerr << "BlockModel: not enough HSL modifiers!" << std::endl;
-       }
-       if (buf.rgb_mods.size() < buf.vertices.size()) {
-               std::cerr << "BlockModel: not enough RGB modifiers!" << std::endl;
-       }
-       if (buf.normals.size() < buf.vertices.size()) {
-               std::cerr << "EntityModel: not enough normals!" << std::endl;
-       }
-#endif
-
-       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_NORMAL, buf.normals);
-       vao.PushIndices(ATTRIB_INDEX, buf.indices);
-}
-
-
-void EntityModel::Draw() const noexcept {
-       vao.DrawTriangleElements();
-}
-
-
-void BlockModel::Update(const Buffer &buf) noexcept {
-#ifndef NDEBUG
-       if (buf.tex_coords.size() < buf.vertices.size()) {
-               std::cerr << "BlockModel: not enough tex coords!" << std::endl;
-       }
-       if (buf.hsl_mods.size() < buf.vertices.size()) {
-               std::cerr << "BlockModel: not enough HSL modifiers!" << std::endl;
-       }
-       if (buf.rgb_mods.size() < buf.vertices.size()) {
-               std::cerr << "BlockModel: not enough RGB modifiers!" << std::endl;
-       }
-       if (buf.lights.size() < buf.vertices.size()) {
-               std::cerr << "BlockModel: not enough lights!" << std::endl;
-       }
-#endif
-
-       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_LIGHT, buf.lights);
-       vao.PushIndices(ATTRIB_INDEX, buf.indices);
-}
-
-
-void BlockModel::Draw() const noexcept {
-       vao.DrawTriangleElements();
-}
-
-
-void OutlineModel::Update(const Buffer &buf) noexcept {
-#ifndef NDEBUG
-       if (buf.colors.size() < buf.vertices.size()) {
-               std::cerr << "OutlineModel: not enough colors!" << std::endl;
-       }
-#endif
-
-       vao.Bind();
-       vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
-       vao.PushAttribute(ATTRIB_COLOR, buf.colors);
-       vao.PushIndices(ATTRIB_INDEX, buf.indices);
-}
-
-
-void OutlineModel::Draw() noexcept {
-       glEnable(GL_LINE_SMOOTH);
-       glLineWidth(2.0f);
-       vao.DrawLineElements();
-}
-
-
-void SkyBoxModel::LoadUnitBox() {
-       Buffer buffer;
-       CuboidShape shape({{ -1, -1, -1 }, { 1, 1, 1 }});
-       shape.Vertices(buffer);
-       Update(buffer);
-}
-
-void SkyBoxModel::Update(const Buffer &buf) noexcept {
-       vao.Bind();
-       vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
-       vao.PushIndices(ATTRIB_INDEX, buf.indices);
-}
-
-void SkyBoxModel::Draw() const noexcept {
-       vao.DrawTriangleElements();
-}
-
-
-void SpriteModel::Buffer::LoadRect(
-       float w, float h,
-       const glm::vec2 &pivot,
-       const glm::vec2 &tex_begin,
-       const glm::vec2 &tex_end
-) {
-       Clear();
-       Reserve(4, 6);
-
-       vertices.emplace_back( -pivot.x,  -pivot.y, 0.0f);
-       vertices.emplace_back(w-pivot.x,  -pivot.y, 0.0f);
-       vertices.emplace_back( -pivot.x, h-pivot.y, 0.0f);
-       vertices.emplace_back(w-pivot.x, h-pivot.y, 0.0f);
-
-       coords.emplace_back(tex_begin.x, tex_begin.y);
-       coords.emplace_back(tex_end.x,   tex_begin.y);
-       coords.emplace_back(tex_begin.x, tex_end.y);
-       coords.emplace_back(tex_end.x,   tex_end.y);
-
-       indices.assign({ 0, 2, 1, 1, 2, 3 });
-}
-
-
-void SpriteModel::Update(const Buffer &buf) noexcept {
-#ifndef NDEBUG
-       if (buf.coords.size() < buf.vertices.size()) {
-               std::cerr << "SpriteModel: not enough coords!" << std::endl;
-       }
-#endif
-
-       vao.Bind();
-       vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
-       vao.PushAttribute(ATTRIB_TEXCOORD, buf.coords);
-       vao.PushIndices(ATTRIB_INDEX, buf.indices);
-}
-
-
-void SpriteModel::Draw() noexcept {
-       vao.DrawTriangleElements();
-}
-
-}
index 7422f899e856297f7ccb2f49bbbf53c2c2fa991a..d69046e6c7c00523f93a2936c0c7e558eb88ff16 100644 (file)
@@ -5,7 +5,7 @@
 namespace blank {
 
 void Shape::Vertices(
-       EntityModel::Buffer &out,
+       EntityMesh::Buffer &out,
        float tex_offset
 ) const {
        for (const auto &pos : vtx_pos) {
@@ -23,10 +23,10 @@ void Shape::Vertices(
 }
 
 void Shape::Vertices(
-       EntityModel::Buffer &out,
+       EntityMesh::Buffer &out,
        const glm::mat4 &transform,
        float tex_offset,
-       EntityModel::Index idx_offset
+       EntityMesh::Index idx_offset
 ) const {
        for (const auto &pos : vtx_pos) {
                out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
@@ -43,10 +43,10 @@ void Shape::Vertices(
 }
 
 void Shape::Vertices(
-       BlockModel::Buffer &out,
+       BlockMesh::Buffer &out,
        const glm::mat4 &transform,
        float tex_offset,
-       BlockModel::Index idx_offset
+       BlockMesh::Index idx_offset
 ) const {
        for (const auto &pos : vtx_pos) {
                out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
@@ -59,26 +59,15 @@ void Shape::Vertices(
        }
 }
 
-void Shape::Vertices(
-       SkyBoxModel::Buffer &out
-) const {
-       for (const auto &pos : vtx_pos) {
-               out.vertices.emplace_back(pos);
-       }
-       for (auto idx : vtx_idx) {
-               out.indices.emplace_back(idx);
-       }
-}
-
-void Shape::Outline(OutlineModel::Buffer &out) const {
+void Shape::Outline(OutlineMesh::Buffer &out) const {
        out.vertices.insert(out.vertices.end(), out_pos.begin(), out_pos.end());
        out.indices.insert(out.indices.end(), out_idx.begin(), out_idx.end());
 }
 
 void Shape::SetShape(
-       const EntityModel::Positions &pos,
-       const EntityModel::Normals &nrm,
-       const EntityModel::Indices &idx
+       const EntityMesh::Positions &pos,
+       const EntityMesh::Normals &nrm,
+       const EntityMesh::Indices &idx
 ) {
        vtx_pos = pos;
        vtx_nrm = nrm;
@@ -86,14 +75,14 @@ void Shape::SetShape(
 }
 
 void Shape::SetTexture(
-       const BlockModel::TexCoords &tex_coords
+       const BlockMesh::TexCoords &tex_coords
 ) {
        vtx_tex_coords = tex_coords;
 }
 
 void Shape::SetOutline(
-       const OutlineModel::Positions &pos,
-       const OutlineModel::Indices &idx
+       const OutlineMesh::Positions &pos,
+       const OutlineMesh::Indices &idx
 ) {
        out_pos = pos;
        out_idx = idx;
index d15643f4d4476090fc98138e10bcdaeffc2cbd14..32a167b865d2979209f763a1e12341280f3b2f28 100644 (file)
@@ -3,8 +3,8 @@
 
 #include "FixedText.hpp"
 #include "MessageBox.hpp"
-#include "../model/EntityModel.hpp"
-#include "../model/OutlineModel.hpp"
+#include "../graphics/EntityMesh.hpp"
+#include "../graphics/OutlineMesh.hpp"
 
 #include <glm/glm.hpp>
 
@@ -57,13 +57,13 @@ private:
        const Player &player;
 
        // block focus
-       OutlineModel outline;
+       OutlineMesh outline;
        glm::mat4 outline_transform;
        bool outline_visible;
 
        // "inventory"
-       EntityModel block;
-       EntityModel::Buffer block_buf;
+       EntityMesh block;
+       EntityMesh::Buffer block_buf;
        glm::mat4 block_transform;
        FixedText block_label;
        bool block_visible;
@@ -82,7 +82,7 @@ private:
        IntervalTimer msg_timer;
 
        // crosshair
-       OutlineModel crosshair;
+       OutlineMesh crosshair;
 
 };
 
index 6c7c6a5a154be98f5062c9b7f6c84c1fc8da2cae..bdeb304daff1b79659486ce608733bf51f8a8dd3 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "../graphics/align.hpp"
 #include "../graphics/Texture.hpp"
-#include "../model/SpriteModel.hpp"
+#include "../graphics/SpriteMesh.hpp"
 
 #include <string>
 #include <glm/glm.hpp>
@@ -36,7 +36,7 @@ private:
 
 private:
        Texture tex;
-       SpriteModel sprite;
+       SpriteMesh sprite;
        glm::vec2 size;
        Gravity pivot;
        bool dirty;
index 4dd9711edac447276bc721235749a6d573b27e67..c249ed47148a3a67d5f0e38cc85a91064e64634a 100644 (file)
@@ -250,12 +250,12 @@ HUD::HUD(Environment &env, Config &config, const Player &player)
        messages.Background(glm::vec4(0.5f));
 
        // crosshair
-       OutlineModel::Buffer buf;
+       OutlineMesh::Buffer buf;
        buf.vertices = std::vector<glm::vec3>({
                { -10.0f,   0.0f, 0.0f }, { 10.0f,  0.0f, 0.0f },
                {   0.0f, -10.0f, 0.0f }, {  0.0f, 10.0f, 0.0f },
        });
-       buf.indices = std::vector<OutlineModel::Index>({
+       buf.indices = std::vector<OutlineMesh::Index>({
                0, 1, 2, 3
        });
        buf.colors.resize(4, { 10.0f, 10.0f, 10.0f });
@@ -264,7 +264,7 @@ HUD::HUD(Environment &env, Config &config, const Player &player)
 
 namespace {
 
-OutlineModel::Buffer outl_buf;
+OutlineMesh::Buffer outl_buf;
 
 }
 
@@ -272,7 +272,7 @@ void HUD::FocusBlock(const Chunk &chunk, int index) {
        const Block &block = chunk.BlockAt(index);
        const BlockType &type = chunk.Type(index);
        outl_buf.Clear();
-       type.FillOutlineModel(outl_buf);
+       type.FillOutlineMesh(outl_buf);
        outline.Update(outl_buf);
        outline_transform = chunk.Transform(player.GetEntity().ChunkCoords());
        outline_transform *= chunk.ToTransform(Chunk::ToPos(index), index);
@@ -312,7 +312,7 @@ void HUD::DisplayNone() {
 
 void HUD::Display(const BlockType &type) {
        block_buf.Clear();
-       type.FillEntityModel(block_buf);
+       type.FillEntityMesh(block_buf);
        block.Update(block_buf);
 
        block_label.Set(env.assets.small_ui_font, type.label);
index 852d2f15a4b092cec982576cf0710cee569c3634..b19dbcf62de2cc4e76275b57e5b8c4b087e45af2 100644 (file)
@@ -110,7 +110,7 @@ void Text::Set(const Font &font, const char *text) {
 
 namespace {
 
-SpriteModel::Buffer sprite_buf;
+SpriteMesh::Buffer sprite_buf;
 
 }
 
index a27b89bfd30016c66fcf677d64c23a3e51b78693..5fab9318dd2c44b5bd7066d048ca142b4dcc99eb 100644 (file)
@@ -2,9 +2,9 @@
 #define BLANK_WORLD_BLOCKTYPE_HPP_
 
 #include "Block.hpp"
-#include "../model/BlockModel.hpp"
-#include "../model/EntityModel.hpp"
-#include "../model/OutlineModel.hpp"
+#include "../graphics/BlockMesh.hpp"
+#include "../graphics/EntityMesh.hpp"
+#include "../graphics/OutlineMesh.hpp"
 #include "../model/shapes.hpp"
 
 #include <glm/glm.hpp>
@@ -81,17 +81,17 @@ struct BlockType {
                return fill[block.OrientedFace(face)];
        }
 
-       void FillEntityModel(
-               EntityModel::Buffer &m,
+       void FillEntityMesh(
+               EntityMesh::Buffer &m,
                const glm::mat4 &transform = glm::mat4(1.0f),
-               EntityModel::Index idx_offset = 0
+               EntityMesh::Index idx_offset = 0
        ) const noexcept;
-       void FillBlockModel(
-               BlockModel::Buffer &m,
+       void FillBlockMesh(
+               BlockMesh::Buffer &m,
                const glm::mat4 &transform = glm::mat4(1.0f),
-               BlockModel::Index idx_offset = 0
+               BlockMesh::Index idx_offset = 0
        ) const noexcept;
-       void FillOutlineModel(OutlineModel::Buffer &m) const noexcept;
+       void FillOutlineMesh(OutlineMesh::Buffer &m) const noexcept;
 
 };
 
index cc0ae8e0a9508b9e0369288f4b26dc9f5c624eed..eaed28a0fd48f727b0274f5cf1f6e6a3f7b20fe0 100644 (file)
@@ -127,7 +127,7 @@ public:
        int GetLight(const Pos &pos) const noexcept { return GetLight(ToIndex(pos)); }
        int GetLight(const Block::Pos &pos) const noexcept { return GetLight(ToIndex(pos)); }
 
-       float GetVertexLight(const Pos &, const BlockModel::Position &, const EntityModel::Normal &) const noexcept;
+       float GetVertexLight(const Pos &, const BlockMesh::Position &, const EntityMesh::Normal &) const noexcept;
 
        bool Intersection(
                const Ray &ray,
@@ -167,14 +167,14 @@ public:
        void UnRef() noexcept { --ref_count; }
        bool Referenced() const noexcept { return ref_count > 0; }
 
-       void Invalidate() noexcept { dirty_model = dirty_save = true; }
-       void InvalidateModel() noexcept { dirty_model = true; }
-       void ClearModel() noexcept { dirty_model = false; }
+       void Invalidate() noexcept { dirty_mesh = dirty_save = true; }
+       void InvalidateMesh() noexcept { dirty_mesh = true; }
+       void ClearMesh() noexcept { dirty_mesh = false; }
        void ClearSave() noexcept { dirty_save = false; }
-       bool ShouldUpdateModel() const noexcept { return dirty_model; }
+       bool ShouldUpdateMesh() const noexcept { return dirty_mesh; }
        bool ShouldUpdateSave() const noexcept { return dirty_save; }
 
-       void Update(BlockModel &) noexcept;
+       void Update(BlockMesh &) noexcept;
 
 private:
        const BlockTypeRegistry *types;
@@ -187,7 +187,7 @@ private:
 
        Pos position;
        int ref_count;
-       bool dirty_model;
+       bool dirty_mesh;
        bool dirty_save;
 
 };
index d45d0fd415f3f57f05ad209299fd0f0a7d256d4e..714bb847f5655495ea979ca6cc4ca07a4b2a9063 100644 (file)
@@ -4,7 +4,7 @@
 #include "Block.hpp"
 #include "Chunk.hpp"
 #include "../graphics/ArrayTexture.hpp"
-#include "../model/BlockModel.hpp"
+#include "../graphics/BlockMesh.hpp"
 
 #include <vector>
 
@@ -12,7 +12,7 @@
 namespace blank {
 
 class AssetLoader;
-class BlockModel;
+class BlockMesh;
 class ChunkIndex;
 class TextureIndex;
 class Viewport;
@@ -34,7 +34,7 @@ public:
 
 private:
        ChunkIndex &index;
-       std::vector<BlockModel> models;
+       std::vector<BlockMesh> models;
 
        ArrayTexture block_tex;
 
index aa8fc7772732f765ef684fdbed7e4d1b261936a7..d2453cf534a705fe5435a030500ca3e3960f64db 100644 (file)
@@ -100,27 +100,27 @@ BlockType::BlockType() noexcept
 
 }
 
-void BlockType::FillEntityModel(
-       EntityModel::Buffer &buf,
+void BlockType::FillEntityMesh(
+       EntityMesh::Buffer &buf,
        const glm::mat4 &transform,
-       EntityModel::Index idx_offset
+       EntityMesh::Index idx_offset
 ) const noexcept {
        shape->Vertices(buf, transform, texture, idx_offset);
        buf.hsl_mods.insert(buf.hsl_mods.end(), shape->VertexCount(), hsl_mod);
        buf.rgb_mods.insert(buf.rgb_mods.end(), shape->VertexCount(), rgb_mod);
 }
 
-void BlockType::FillBlockModel(
-       BlockModel::Buffer &buf,
+void BlockType::FillBlockMesh(
+       BlockMesh::Buffer &buf,
        const glm::mat4 &transform,
-       BlockModel::Index idx_offset
+       BlockMesh::Index idx_offset
 ) const noexcept {
        shape->Vertices(buf, transform, texture, idx_offset);
        buf.hsl_mods.insert(buf.hsl_mods.end(), shape->VertexCount(), hsl_mod);
        buf.rgb_mods.insert(buf.rgb_mods.end(), shape->VertexCount(), rgb_mod);
 }
 
-void BlockType::FillOutlineModel(OutlineModel::Buffer &buf) const noexcept {
+void BlockType::FillOutlineMesh(OutlineMesh::Buffer &buf) const noexcept {
        shape->Outline(buf);
        buf.colors.insert(buf.colors.end(), shape->OutlineCount(), outline_color);
 }
index baad4466cde01790851b5f8877e2350d4e8a53b5..14c3af5c9c9af0fdc6560a2718d3b118553db205 100644 (file)
@@ -9,9 +9,9 @@
 #include "WorldCollision.hpp"
 #include "../app/Assets.hpp"
 #include "../graphics/BlockLighting.hpp"
+#include "../graphics/BlockMesh.hpp"
 #include "../graphics/Viewport.hpp"
 #include "../io/WorldSave.hpp"
-#include "../model/BlockModel.hpp"
 
 #include <algorithm>
 #include <limits>
@@ -36,19 +36,23 @@ Chunk::Chunk(const BlockTypeRegistry &types) noexcept
 , lighted(false)
 , position(0, 0, 0)
 , ref_count(0)
-, dirty_model(false)
+, dirty_mesh(false)
 , dirty_save(false) {
 
 }
 
 Chunk::Chunk(Chunk &&other) noexcept
 : types(other.types)
+, generated(other.generated)
+, lighted(other.lighted)
 , position(other.position)
-, dirty_model(other.dirty_model)
+, ref_count(other.ref_count)
+, dirty_mesh(other.dirty_mesh)
 , dirty_save(other.dirty_save) {
        std::copy(other.neighbor, other.neighbor + sizeof(neighbor), neighbor);
        std::copy(other.blocks, other.blocks + sizeof(blocks), blocks);
        std::copy(other.light, other.light + sizeof(light), light);
+       other.ref_count = 0;
 }
 
 Chunk &Chunk::operator =(Chunk &&other) noexcept {
@@ -56,8 +60,11 @@ Chunk &Chunk::operator =(Chunk &&other) noexcept {
        std::copy(other.neighbor, other.neighbor + sizeof(neighbor), neighbor);
        std::copy(other.blocks, other.blocks + sizeof(blocks), blocks);
        std::copy(other.light, other.light + sizeof(light), light);
+       generated = other.generated;
+       lighted = other.lighted;
        position = other.position;
-       dirty_model = other.dirty_save;
+       std::swap(ref_count, other.ref_count);
+       dirty_mesh = other.dirty_save;
        dirty_save = other.dirty_save;
        return *this;
 }
@@ -246,7 +253,7 @@ int Chunk::GetLight(int index) const noexcept {
        return light[index];
 }
 
-float Chunk::GetVertexLight(const Pos &pos, const BlockModel::Position &vtx, const EntityModel::Normal &norm) const noexcept {
+float Chunk::GetVertexLight(const Pos &pos, const BlockMesh::Position &vtx, const EntityMesh::Normal &norm) const noexcept {
        int index = ToIndex(pos);
        float light = GetLight(index);
 
@@ -421,11 +428,11 @@ bool Chunk::Intersection(
 
 namespace {
 
-BlockModel::Buffer buf;
+BlockMesh::Buffer buf;
 
 }
 
-void Chunk::Update(BlockModel &model) noexcept {
+void Chunk::Update(BlockMesh &model) noexcept {
        int vtx_count = 0, idx_count = 0;
        for (const auto &block : blocks) {
                const Shape *shape = Type(block).shape;
@@ -436,7 +443,7 @@ void Chunk::Update(BlockModel &model) noexcept {
        buf.Reserve(vtx_count, idx_count);
 
        int idx = 0;
-       BlockModel::Index vtx_counter = 0;
+       BlockMesh::Index vtx_counter = 0;
        for (size_t z = 0; z < depth; ++z) {
                for (size_t y = 0; y < height; ++y) {
                        for (size_t x = 0; x < width; ++x, ++idx) {
@@ -445,7 +452,7 @@ void Chunk::Update(BlockModel &model) noexcept {
 
                                if (!type.visible || Obstructed(pos).All()) continue;
 
-                               type.FillBlockModel(buf, ToTransform(pos, idx), vtx_counter);
+                               type.FillBlockMesh(buf, ToTransform(pos, idx), vtx_counter);
                                size_t vtx_begin = vtx_counter;
                                vtx_counter += type.shape->VertexCount();
 
@@ -461,7 +468,7 @@ void Chunk::Update(BlockModel &model) noexcept {
        }
 
        model.Update(buf);
-       ClearModel();
+       ClearMesh();
 }
 
 Block::FaceSet Chunk::Obstructed(const Pos &pos) const noexcept {
@@ -672,7 +679,7 @@ void ChunkRenderer::Update(int dt) {
                if (!index[i]->Lighted() && index.HasAllSurrounding(index[i]->Position())) {
                        index[i]->ScanLights();
                }
-               if (index[i]->ShouldUpdateModel()) {
+               if (index[i]->ShouldUpdateMesh()) {
                        index[i]->Update(models[i]);
                        ++updates;
                }
@@ -689,7 +696,7 @@ void ChunkRenderer::Render(Viewport &viewport) {
                glm::mat4 m(index[i]->Transform(index.Base()));
                glm::mat4 mvp(chunk_prog.GetVP() * m);
                if (!CullTest(Chunk::Bounds(), mvp)) {
-                       if (index[i]->ShouldUpdateModel()) {
+                       if (index[i]->ShouldUpdateMesh()) {
                                index[i]->Update(models[i]);
                        }
                        chunk_prog.SetM(m);
@@ -1023,7 +1030,7 @@ void ChunkStore::Clean() {
                        ++i;
                        free.splice(free.end(), loaded, chunk);
                        chunk->Unlink();
-                       chunk->InvalidateModel();
+                       chunk->InvalidateMesh();
                }
        }
 }