3d renderer

This commit is contained in:
Erris
2026-03-01 17:06:15 +01:00
parent abe8016f84
commit 90a6ea00c0
21 changed files with 365 additions and 76 deletions

View File

@@ -25,6 +25,7 @@
#include "open_engine/renderer/subtexture2d.hpp"
#include "open_engine/renderer/framebuffer.hpp"
#include "open_engine/renderer/renderer2d.hpp"
#include "open_engine/renderer/renderer3d.hpp"
#include "open_engine/renderer/renderer.hpp"
#include "open_engine/renderer/texture.hpp"
#include "open_engine/renderer/buffer.hpp"

View File

@@ -29,13 +29,14 @@ namespace OpenEngine {
class OpenGLIndexBuffer : public IndexBuffer
{
public:
OpenGLIndexBuffer(uint32_t* indices, uint32_t count);
OpenGLIndexBuffer(const uint32_t* indices, uint32_t count);
virtual ~OpenGLIndexBuffer();
virtual void Bind() const override;
virtual void UnBind() const override;
virtual uint32_t GetCount() const override { return count; };
virtual uint32_t GetID() const override { return id; };
private:
unsigned int id;

View File

@@ -1,6 +1,8 @@
#ifndef BUFFER_HPP
#define BUFFER_HPP
#include "open_engine/ref_scope.hpp"
#include <cstdint>
#include <vector>
#include <string>
@@ -82,8 +84,9 @@ namespace OpenEngine {
virtual void UnBind() const = 0;
virtual uint32_t GetCount() const = 0;
virtual uint32_t GetID() const = 0;
static Ref<IndexBuffer> Create(uint32_t* indices, uint32_t count);
static Ref<IndexBuffer> Create(const uint32_t* indices, uint32_t count);
};
}

View File

@@ -0,0 +1,61 @@
#ifndef RENDERER3D_HPP
#define RENDERER3D_HPP
#include "open_engine/renderer/editor_camera.hpp"
#include "open_engine/renderer/vertex_array.hpp"
#include "open_engine/renderer/camera.hpp"
#include "open_engine/renderer/buffer.hpp"
#include <cstdint>
namespace OpenEngine {
// SHOULD BE MOVED ==================================
struct MeshVertex
{
glm::vec3 position;
glm::vec4 color;
glm::vec3 normal;
glm::vec2 text_coords;
uint32_t id = -1;
};
struct Mesh
{
Ref<VertexArray> vertex_array;
Ref<VertexBuffer> vertex_buffer;
Ref<IndexBuffer> index_buffer;
// TODO: Make them a ptr or something
std::vector<MeshVertex> vertices;
std::vector<uint32_t> indices;
};
Ref<Mesh> CreateMesh(const std::vector<MeshVertex>& vertices,
const std::vector<uint32_t>& indices);
Ref<Mesh> CreateCube(uint32_t id = -1);
// ==================================================
class Renderer3D
{
public:
static void Init();
static void Shutdown();
static void BeginScene(const Camera& camera, const glm::mat4& transform);
static void BeginScene(const EditorCamera& camera);
static void EndScene();
static void DrawMesh(const Ref<Mesh>& mesh, const glm::mat4& transform);
/*
static void DrawCube(const glm::mat4& transform, const glm::vec4& color,
int entity_id);
static void DrawCube(const glm::mat4& transform, Ref<Texture2D>,
int entity_id);
static void DrawCube(const glm::mat4& transform, Ref<Texture2D>,
const glm::vec4& color, int entity_id);
*/
};
}
#endif // RENDERER3D_HPP

View File

@@ -1,21 +0,0 @@
#include <pch.hpp>
#include <renderer/uniform_buffer.hpp>
#include <opengl/opengl_uniform_buffer.hpp>
#include <renderer/renderer.hpp>
namespace OpenEngine {
Ref<UniformBuffer> UniformBuffer::Create(uint32_t size, uint32_t binding)
{
switch (Renderer::GetAPI())
{
case RendererAPI::API::None: OE_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr;
case RendererAPI::API::OpenGL: return CreateRef<OpenGLUniformBuffer>(size, binding);
}
OE_CORE_ASSERT(false, "Unknown RendererAPI!");
return nullptr;
}
}

View File

@@ -2,6 +2,7 @@
#define VERTEX_ARRAY_HPP
#include "open_engine/renderer/buffer.hpp"
#include "open_engine/ref_scope.hpp"
#include <vector>

View File

@@ -2,8 +2,10 @@
#define COMPONENTS_HPP
#include "open_engine/scene/native_scriptable_entity.hpp"
#include "open_engine/renderer/renderer3d.hpp"
#include "open_engine/scene/scene_camera.hpp"
#include "open_engine/renderer/texture.hpp"
#include "open_engine/renderer/renderer3d.hpp"
#include <glm/ext/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
@@ -87,6 +89,16 @@ namespace OpenEngine {
}
};
struct MeshComponent
{
Ref<Mesh> mesh;
MeshComponent() = default;
MeshComponent(const MeshComponent&) = default;
MeshComponent(const Ref<Mesh>& mesh)
: mesh(mesh) {}
};
}
#endif // COMPONENTS_HPP

View File

@@ -19,7 +19,7 @@ namespace OpenEngine {
Entity(const Entity& other) = default;
template<typename T, typename ... Args>
T& AddComponents(Args&&... args)
T& AddComponent(Args&&... args)
{
OE_ASSERT(!HasComponent<T>(), "Entity already has component.");