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

@@ -1,14 +1,9 @@
#ifndef EDITOR_HPP
#define EDITOR_HPP
#include <filesystem>
#include <open_engine.hpp>
#include "open_engine/application.hpp"
#include "open_engine/logging.hpp"
#include "open_engine/renderer/texture.hpp"
#include "open_engine/scene/entity.hpp"
#include "open_engine/scene/scene_serializer.hpp"
#include "open_engine/scene/components.hpp"
#include "panels/content_browser.hpp"
#include "panels/scene_hierarchy.hpp"
@@ -19,6 +14,7 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <ImGuizmo.h>
#include <filesystem>
#include <cstdint>
#include <imgui.h>
#include <vector>
@@ -95,6 +91,34 @@ namespace OpenEngine {
icons["play"] = Texture2D::Create("resources/textures/icons/play.png");
icons["stop"] = Texture2D::Create("resources/textures/icons/stop.png");
Entity cube = scene->CreateEntity("cube");
cube.AddComponent<TransformComponent>();
Ref<Mesh> mesh = CreateCube(cube);
cube.AddComponent<MeshComponent>(mesh);
Entity cube2 = scene->CreateEntity("cube2");
cube2.AddComponent<TransformComponent>();
cube2.GetComponents<TransformComponent>().translation = {2, 0, 0};
Ref<Mesh> mesh2 = CreateCube(cube2);
cube2.AddComponent<MeshComponent>(mesh2);
OE_DEBUG("cubes is like {} {}", (uint32_t)cube, (uint32_t)cube2);
/*
auto view = scene->GetRegistry().view<TagComponent>();
for (auto& entity : view) {
auto tag = view->get(entity);
OE_DEBUG("entity: {}, tag: {}", (uint32_t)entity, tag.tag);
}
*/
// TODO: Add file texture. Get free icons and add license
//icons["folder"] = Texture2D::Create("resources/textures/icons/folder.png");
/*
@@ -140,7 +164,7 @@ namespace OpenEngine {
}
framebuffer->Bind();
Renderer2D::ResetStats();
//Renderer2D::ResetStats();
RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
RenderCommand::Clear();
framebuffer->ClearBufferI(1, -1);
@@ -318,7 +342,7 @@ namespace OpenEngine {
void DrawStats()
{
auto stats = Renderer2D::GetStats();
//auto stats = Renderer2D::GetStats();
static float time = 0;
time += Time::DeltaTime();
@@ -330,17 +354,17 @@ namespace OpenEngine {
ImGui::Begin("Statistics");
ImGui::SeparatorText("Performance");
ImGui::Text("FPS: %0.0f", 1 / Time::DeltaTime());
ImGui::Text("Renderer2D:");
ImGui::Text("\t\tDraw calls: %d", stats.draw_calls);
ImGui::Text("\t\tQuad count: %d", stats.quad_count);
ImGui::Text("\t\tVertices count: %d", stats.GetTotalVertexCount());
ImGui::Text("\t\tIndices count: %d", stats.GetTotalIndexCount());
if (selected_entity) {
ImGui::SeparatorText("Entities");
ImGui::Text("Selected entity:");
ImGui::Text("\t\tname: %s", selected_entity.GetComponents<TagComponent>().tag.c_str());
ImGui::Text("\t\tid: %d", (uint32_t)selected_entity);
}
//ImGui::Text("Renderer2D:");
//ImGui::Text("\t\tDraw calls: %d", stats.draw_calls);
//ImGui::Text("\t\tQuad count: %d", stats.quad_count);
//ImGui::Text("\t\tVertices count: %d", stats.GetTotalVertexCount());
//ImGui::Text("\t\tIndices count: %d", stats.GetTotalIndexCount());
//if (selected_entity) {
// ImGui::SeparatorText("Entities");
// ImGui::Text("Selected entity:");
// ImGui::Text("\t\tname: %s", selected_entity.GetComponents<TagComponent>().tag.c_str());
// ImGui::Text("\t\tid: %d", (uint32_t)selected_entity);
//}
ImGui::End();
};

View File

@@ -13,12 +13,10 @@ namespace OpenEngine {
const std::array<const char*, 3> labels = {"x", "y", "z"});
void TagOnImGuiRender(entt::registry& registry, entt::entity entity);
void TransformOnImGuiRender(entt::registry& registry, entt::entity entity);
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity);
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity);
void MeshOnImGuiRender(entt::registry&registry, entt::entity entity);
}
#endif // EDITOR_COMPONENT_HPP

View File

@@ -6,6 +6,8 @@
namespace OpenEngine {
class EditorLayer;
class ContentBrowserPanel
{
public:

View File

@@ -170,4 +170,9 @@ namespace OpenEngine {
}
};
void MeshOnImGuiRender(entt::registry&registry, entt::entity entity)
{
}
}

View File

@@ -22,6 +22,7 @@ namespace OpenEngine {
RegisterDrawer<TransformComponent>("Transform", &TransformOnImGuiRender);
RegisterDrawer<SpriteRendererComponent>("Sprite Renderer", &SpriteOnImGuiRender);
RegisterDrawer<CameraComponent>("Camera", &CameraOnImGuiRender);
RegisterDrawer<MeshComponent>("Mesh", &MeshOnImGuiRender);
scene = context;
selected_context = {};
@@ -32,17 +33,22 @@ namespace OpenEngine {
ImGui::SeparatorText("Add");
if (!selected_context.HasComponent<TransformComponent>())
if (ImGui::MenuItem("Transform")) {
selected_context.AddComponents<TransformComponent>();
selected_context.AddComponent<TransformComponent>();
ImGui::CloseCurrentPopup();
}
if (!selected_context.HasComponent<SpriteRendererComponent>())
if (ImGui::MenuItem("Sprite")) {
selected_context.AddComponents<SpriteRendererComponent>();
selected_context.AddComponent<SpriteRendererComponent>();
ImGui::CloseCurrentPopup();
}
if (!selected_context.HasComponent<CameraComponent>())
if (ImGui::MenuItem("Camera")) {
selected_context.AddComponents<CameraComponent>();
selected_context.AddComponent<CameraComponent>();
ImGui::CloseCurrentPopup();
}
if (!selected_context.HasComponent<MeshComponent>())
if (ImGui::MenuItem("Mesh")) {
selected_context.AddComponent<MeshComponent>();
ImGui::CloseCurrentPopup();
}
}
@@ -202,6 +208,7 @@ namespace OpenEngine {
entity.GetComponents<TagComponent>();
TagOnImGuiRender(reg, entity);
std::vector<entt::id_type> component_to_delete; // 0 is null/invalid in entt usually
// Iterate through every component type entt knows about
for (auto [id, storage] : reg.storage()) {