summary refs log tree commit diff
path: root/src/Entities
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2024-02-12 12:55:11 +0100
committerMel <einebeere@gmail.com>2024-02-12 12:55:11 +0100
commitd2b5fc5b3bc648afffa42375706429685ac63794 (patch)
treea2dfbb241e1d46e5616c5884e5f3d685de2a2cb6 /src/Entities
parent588c7e87b7cab270698d43ca5c22d67793ae5fc4 (diff)
downloadmeowcraft-d2b5fc5b3bc648afffa42375706429685ac63794.tar.zst
meowcraft-d2b5fc5b3bc648afffa42375706429685ac63794.zip
Split rendering into own thread and sync through render action lists
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Player.cpp74
-rw-r--r--src/Entities/Player.hpp18
2 files changed, 15 insertions, 77 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index b7bee24..652f3fd 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1,29 +1,8 @@
 #include "Player.hpp"
 #include "../Common/Casts.hpp"
-#include "../Math/MVP.hpp"
 #include <unordered_set>
 
 namespace MC::Entities {
-Player::Player(Position::World position, Real ascept, Real fov, Real near, Real far)
-    : m_transform(position),
-    m_outline_program(
-        {GFX::Shading::Shader::Type::Vertex, outline_vertex},
-        {GFX::Shading::Shader::Type::Fragment, outline_fragment}
-    ),
-    m_outline_mesh(create_outline_cube_mesh()),
-    m_outline_model_uniform(), m_outline_view_uniform(), m_outline_projection_uniform() {
-    m_outline_program.bind();
-
-    m_outline_model_uniform = m_outline_program.uniform("model_matrix");
-    m_outline_view_uniform = m_outline_program.uniform("view_matrix");
-    m_outline_projection_uniform = m_outline_program.uniform("projection_matrix");
-
-    m_outline_model_uniform.set(Math::MVP::model<F32>({}, {}, {}));
-    m_outline_view_uniform.set(Math::MVP::view<F32>({}, {}));
-    m_outline_projection_uniform.set(Math::MVP::perspective_projection<F32>(ascept, fov, near, far));
-
-    m_outline_program.unbind();
-}
 
 void Player::update(const Time& time, GFX::Window& window, GFX::Camera& camera, World::World& world) {
     auto const input_direction = directional_input(window);
@@ -51,24 +30,16 @@ void Player::update(const Time& time, GFX::Window& window, GFX::Camera& camera,
     actions(window, world);
 }
 
-// TODO: Proof-of-concept, will all be moved to the rendering system.
-void Player::render(const GFX::Camera& camera) {
-    // Render currently targeted block outline.
-
+void Player::render(GFX::Actions& actions) {
     if (m_targeted_block.has_value()) {
-        auto targeted_block = m_targeted_block.value();
-
-        m_outline_program.bind();
-
-        m_outline_view_uniform.set(Math::MVP::view<F32>(camera.position(), camera.angles()));
-        m_outline_model_uniform.set(Math::MVP::model<F32>(Vec3(targeted_block.position), Vec3::one(), {}));
-
-        m_outline_mesh.bind();
-        // TODO: These are very thin lines, do we have any better easy options?
-        glDrawElements(GL_LINES, m_outline_mesh.size(), GL_UNSIGNED_INT, nullptr);
-        m_outline_mesh.unbind();
-
-        m_outline_program.unbind();
+        auto position = Vec3(m_targeted_block->position);
+        actions.add({
+            .mesh = &m_outline_mesh,
+            .program = GFX::Resources::Program::BlockOutline,
+            .transform = Transform{position},
+            // TODO: These are very thin lines, do we have any better easy options?
+            .draw_mode = GFX::DrawMode::Lines,
+        });
     }
 }
 
@@ -371,31 +342,4 @@ GFX::Mesh Player::create_outline_cube_mesh() {
     return builder.mesh();
 }
 
-const Char* Player::outline_vertex = R"v(
-#version 330 core
-
-uniform mat4 model_matrix;
-uniform mat4 view_matrix;
-uniform mat4 projection_matrix;
-
-layout (location = 0) in vec3 position;
-
-void main() {
-    vec4 world_position = model_matrix * vec4(position, 1.0);
-    vec4 view_position = view_matrix * world_position;
-    vec4 clip_position = projection_matrix * view_position;
-
-    gl_Position = clip_position;
-}
-)v";
-
-const Char* Player::outline_fragment = R"f(
-#version 330 core
-
-out vec4 color;
-
-void main() {
-    color = vec4(0.0, 0.0, 0.0, 1.0);
-}
-)f";
 }
diff --git a/src/Entities/Player.hpp b/src/Entities/Player.hpp
index c829d1f..83ac091 100644
--- a/src/Entities/Player.hpp
+++ b/src/Entities/Player.hpp
@@ -2,10 +2,10 @@
 
 #include "../Time.hpp"
 #include "../Transform.hpp"
+#include "../GFX/Actions.hpp"
 #include "../GFX/Camera.hpp"
 #include "../World/World.hpp"
 #include "../GFX/Window.hpp"
-#include "../GFX/Shading/Program.hpp"
 #include "../Math/AABB.hpp"
 #include "../Math/Rotation.hpp"
 #include "../World/Position.hpp"
@@ -13,10 +13,13 @@
 namespace MC::Entities {
 class Player {
 public:
-    explicit Player(Position::World position, Real ascept, Real fov, Real near, Real far);
+    explicit Player(Position::World position)
+        : m_transform(position), m_outline_mesh(create_outline_cube_mesh()) {}
+
+    Position::World position() const { return m_transform.position(); }
 
     void update(const Time& time, GFX::Window& window, GFX::Camera& camera, World::World& world);
-    void render(const GFX::Camera& camera);
+    void render(GFX::Actions& actions);
 
     void move(Position::WorldOffset by);
     void move_to(Position::World to);
@@ -83,16 +86,7 @@ private:
     Transform m_transform;
     static inline AABB s_bounds{{0.35, 1.8, 0.35}};
 
-    // TODO: Put this into the rendering system
-    static const Char* outline_vertex;
-    static const Char* outline_fragment;
-
-    GFX::Shading::Program m_outline_program;
     GFX::Mesh m_outline_mesh;
-
-    GFX::Shading::Uniform m_outline_model_uniform;
-    GFX::Shading::Uniform m_outline_view_uniform;
-    GFX::Shading::Uniform m_outline_projection_uniform;
 };
 
 }