--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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
#define BLANK_GRAPHICS_SKYBOX_HPP_
#include "CubeMap.hpp"
-#include "../model/SkyBoxModel.hpp"
+#include "SkyBoxMesh.hpp"
namespace blank {
private:
CubeMap texture;
- SkyBoxModel model;
+ SkyBoxMesh mesh;
};
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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();
+}
+
+}
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();
}
if (gzclose(file) != Z_OK) {
throw runtime_error("failed to read chunk file");
}
- chunk.InvalidateModel();
+ chunk.InvalidateMesh();
chunk.ClearSave();
}
+++ /dev/null
-#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
namespace blank {
class CompositeInstance;
-class EntityModel;
+class EntityMesh;
class CompositeModel {
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; }
private:
CompositeModel *parent;
- const EntityModel *node_model;
+ const EntityMesh *node_mesh;
std::uint32_t id;
+++ /dev/null
-#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
+++ /dev/null
-#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
#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>
/// 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
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.
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;
};
namespace blank {
class CompositeModel;
-class EntityModel;
+class EntityMesh;
class Skeletons {
private:
std::vector<std::unique_ptr<CompositeModel>> skeletons;
- std::vector<EntityModel> models;
+ std::vector<EntityMesh> meshes;
};
+++ /dev/null
-#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
+++ /dev/null
-#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
#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>
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)
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);
Skeletons::Skeletons()
: skeletons()
-, models() {
+, meshes() {
}
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());
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 });
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());
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]);
}
}
+++ /dev/null
-#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();
-}
-
-}
namespace blank {
void Shape::Vertices(
- EntityModel::Buffer &out,
+ EntityMesh::Buffer &out,
float tex_offset
) const {
for (const auto &pos : vtx_pos) {
}
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));
}
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));
}
}
-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;
}
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;
#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>
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;
IntervalTimer msg_timer;
// crosshair
- OutlineModel crosshair;
+ OutlineMesh crosshair;
};
#include "../graphics/align.hpp"
#include "../graphics/Texture.hpp"
-#include "../model/SpriteModel.hpp"
+#include "../graphics/SpriteMesh.hpp"
#include <string>
#include <glm/glm.hpp>
private:
Texture tex;
- SpriteModel sprite;
+ SpriteMesh sprite;
glm::vec2 size;
Gravity pivot;
bool dirty;
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 });
namespace {
-OutlineModel::Buffer outl_buf;
+OutlineMesh::Buffer outl_buf;
}
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);
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);
namespace {
-SpriteModel::Buffer sprite_buf;
+SpriteMesh::Buffer sprite_buf;
}
#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>
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;
};
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,
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;
Pos position;
int ref_count;
- bool dirty_model;
+ bool dirty_mesh;
bool dirty_save;
};
#include "Block.hpp"
#include "Chunk.hpp"
#include "../graphics/ArrayTexture.hpp"
-#include "../model/BlockModel.hpp"
+#include "../graphics/BlockMesh.hpp"
#include <vector>
namespace blank {
class AssetLoader;
-class BlockModel;
+class BlockMesh;
class ChunkIndex;
class TextureIndex;
class Viewport;
private:
ChunkIndex &index;
- std::vector<BlockModel> models;
+ std::vector<BlockMesh> models;
ArrayTexture block_tex;
}
-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);
}
#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>
, 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 {
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;
}
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);
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;
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) {
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();
}
model.Update(buf);
- ClearModel();
+ ClearMesh();
}
Block::FaceSet Chunk::Obstructed(const Pos &pos) const noexcept {
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;
}
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);
++i;
free.splice(free.end(), loaded, chunk);
chunk->Unlink();
- chunk->InvalidateModel();
+ chunk->InvalidateMesh();
}
}
}