summaryrefslogtreecommitdiff
path: root/src/GFX
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-10-23 02:48:51 +0200
committerMel <einebeere@gmail.com>2022-10-23 02:48:51 +0200
commit75a9c87b50cef2f1d749bd9042a9348bc28b4c09 (patch)
tree8d82f3cbbb5bdc63c7e5b6431dac3d49b23a478d /src/GFX
parent589bfb5cad0052856077ce867f3858ca3741d95d (diff)
downloadmeowcraft-75a9c87b50cef2f1d749bd9042a9348bc28b4c09.tar.zst
meowcraft-75a9c87b50cef2f1d749bd9042a9348bc28b4c09.zip
Sun lighting
Diffstat (limited to 'src/GFX')
-rw-r--r--src/GFX/Binder.cpp5
-rw-r--r--src/GFX/Mesh.cpp8
-rw-r--r--src/GFX/Mesh.hpp25
3 files changed, 33 insertions, 5 deletions
diff --git a/src/GFX/Binder.cpp b/src/GFX/Binder.cpp
index e7b7e4c..70d045c 100644
--- a/src/GFX/Binder.cpp
+++ b/src/GFX/Binder.cpp
@@ -10,7 +10,8 @@ BindableMesh Binder::load(Mesh& mesh) {
store_indices(mesh.raw_indices(), mesh.indices_size());
}
store_in_attribute_list(0, 3, mesh.raw(), mesh.size() * 3);
- store_in_attribute_list(1, 2, mesh.raw_tex_coords(), mesh.tex_coords_size() * 2);
+ store_in_attribute_list(1, 3, mesh.raw_normals(), mesh.normals_size() * 3);
+ store_in_attribute_list(2, 2, mesh.raw_tex_coords(), mesh.tex_coords_size() * 2);
unbind_vao();
return {vao, mesh.indices_size()};
@@ -50,12 +51,14 @@ void BindableMesh::bind() const {
glBindVertexArray(m_vao);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
+ glEnableVertexAttribArray(2);
}
void BindableMesh::unbind() {
glBindVertexArray(0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
+ glDisableVertexAttribArray(2);
}
size_t BindableMesh::size() const {
diff --git a/src/GFX/Mesh.cpp b/src/GFX/Mesh.cpp
index 12f8aaa..1bac9f1 100644
--- a/src/GFX/Mesh.cpp
+++ b/src/GFX/Mesh.cpp
@@ -10,6 +10,14 @@ size_t Mesh::size() {
return m_positions.size();
}
+float* Mesh::raw_normals() {
+ return (float*) m_normals.data();
+}
+
+size_t Mesh::normals_size() {
+ return m_normals.size();
+}
+
uint32_t* Mesh::raw_indices() {
return m_indices.data();
}
diff --git a/src/GFX/Mesh.hpp b/src/GFX/Mesh.hpp
index f027c8c..c20b419 100644
--- a/src/GFX/Mesh.hpp
+++ b/src/GFX/Mesh.hpp
@@ -9,15 +9,31 @@ namespace MC::GFX {
class Mesh {
public:
- Mesh(std::vector<Vector<3>> positions, std::vector<Vector<2>> tex_coords, std::vector<uint32_t> indices)
- : m_positions(std::move(positions)), m_tex_coords(std::move(tex_coords)), m_indices(std::move(indices)) {};
+ Mesh(
+ std::vector<Vector<3>> positions,
+ std::vector<Vector<3>> normals,
+ std::vector<Vector<2>> tex_coords,
+ std::vector<uint32_t> indices
+ ) : m_positions(std::move(positions)),
+ m_normals(std::move(normals)),
+ m_tex_coords(std::move(tex_coords)),
+ m_indices(std::move(indices)) {};
- Mesh(std::vector<Vector<3>> positions, std::vector<Vector<2>> tex_coords)
- : m_positions(std::move(positions)), m_tex_coords(std::move(tex_coords)), m_indices() {};
+ Mesh(
+ std::vector<Vector<3>> positions,
+ std::vector<Vector<3>> normals,
+ std::vector<Vector<2>> tex_coords
+ ) : m_positions(std::move(positions)),
+ m_normals(std::move(normals)),
+ m_tex_coords(std::move(tex_coords)),
+ m_indices() {};
float* raw();
size_t size();
+ float* raw_normals();
+ size_t normals_size();
+
uint32_t* raw_indices();
size_t indices_size();
@@ -26,6 +42,7 @@ public:
private:
std::vector<Vector<3>> m_positions;
+ std::vector<Vector<3>> m_normals;
std::vector<Vector<2>> m_tex_coords;
std::vector<uint32_t> m_indices;