Merge branch '3d'
This commit is contained in:
93
assets/shaders/color3d.glsl
Normal file
93
assets/shaders/color3d.glsl
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
#type vertex
|
||||||
|
#version 450 core
|
||||||
|
|
||||||
|
layout(location = 0) in vec3 a_Position;
|
||||||
|
layout(location = 1) in vec4 a_Color;
|
||||||
|
layout(location = 2) in vec3 a_Normal;
|
||||||
|
layout(location = 3) in vec2 a_TexCoord;
|
||||||
|
layout(location = 4) in int a_EntityID;
|
||||||
|
|
||||||
|
layout(std140, binding = 0) uniform Camera
|
||||||
|
{
|
||||||
|
mat4 u_ViewProjection;
|
||||||
|
vec3 u_ViewPosition;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(std140, binding = 1) uniform Transform
|
||||||
|
{
|
||||||
|
mat4 u_Transform;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexOutput
|
||||||
|
{
|
||||||
|
vec4 Color;
|
||||||
|
vec2 TexCoord;
|
||||||
|
vec3 Normal;
|
||||||
|
vec3 ViewPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout (location = 0) out VertexOutput Output;
|
||||||
|
layout (location = 4) out flat int v_EntityID;
|
||||||
|
layout (location = 5) out vec4 v_Pos;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
Output.Color = a_Color;
|
||||||
|
Output.TexCoord = a_TexCoord;
|
||||||
|
Output.Normal = mat3(transpose(inverse(u_Transform))) * a_Normal;
|
||||||
|
Output.ViewPos = u_ViewPosition;
|
||||||
|
|
||||||
|
v_EntityID = a_EntityID;
|
||||||
|
|
||||||
|
v_Pos = u_Transform * vec4(a_Position, 1.0);
|
||||||
|
gl_Position = u_ViewProjection * v_Pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
#type fragment
|
||||||
|
#version 450 core
|
||||||
|
|
||||||
|
layout (location = 0) out vec4 color;
|
||||||
|
layout (location = 1) out int color2;
|
||||||
|
|
||||||
|
struct VertexOutput
|
||||||
|
{
|
||||||
|
vec4 Color;
|
||||||
|
vec2 TexCoord;
|
||||||
|
vec3 Normal;
|
||||||
|
vec3 ViewPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout (location = 0) in VertexOutput Input;
|
||||||
|
layout (location = 4) in flat int v_EntityID;
|
||||||
|
layout (location = 5) in vec4 v_Pos;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 lightPos = vec3(0.0f, 1.0f, 0.0f);
|
||||||
|
vec3 lightColor = vec3(1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
|
// Ambiant lighting
|
||||||
|
float ambientStrength = 0.8;
|
||||||
|
vec3 ambient = ambientStrength * lightColor;
|
||||||
|
|
||||||
|
// Diffuse lighting
|
||||||
|
vec3 norm = normalize(Input.Normal);
|
||||||
|
vec3 lightDir = normalize(lightPos - v_Pos.xyz);
|
||||||
|
|
||||||
|
float diff = max(dot(norm, lightDir), 0.0);
|
||||||
|
vec3 diffuse = diff * lightColor;
|
||||||
|
|
||||||
|
// Specular highlight
|
||||||
|
float specularStrength = 0.5;
|
||||||
|
vec3 viewDir = normalize(Input.ViewPos - v_Pos.xyz); // .xyz here too
|
||||||
|
vec3 reflectDir = reflect(-lightDir, norm);
|
||||||
|
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||||
|
vec3 specular = specularStrength * spec * lightColor;
|
||||||
|
|
||||||
|
vec3 result = (ambient + diffuse + specular) * Input.Color.rgb; // objectColor → Input.Color.rgb
|
||||||
|
|
||||||
|
// Output
|
||||||
|
color = vec4(result, 1.0); // vec3 → vec4
|
||||||
|
color2 = v_EntityID;
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ imgui/1.92.5-docking
|
|||||||
spdlog/1.16.0
|
spdlog/1.16.0
|
||||||
entt/3.16.0
|
entt/3.16.0
|
||||||
yaml-cpp/0.8.0
|
yaml-cpp/0.8.0
|
||||||
|
joltphysics/5.2.0
|
||||||
|
|
||||||
[generators]
|
[generators]
|
||||||
CMakeDeps
|
CMakeDeps
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
#ifndef EDITOR_HPP
|
#ifndef EDITOR_HPP
|
||||||
#define EDITOR_HPP
|
#define EDITOR_HPP
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <open_engine.hpp>
|
#include <open_engine.hpp>
|
||||||
|
|
||||||
#include "open_engine/application.hpp"
|
#include "open_engine/scene/components.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 "panels/content_browser.hpp"
|
#include "panels/content_browser.hpp"
|
||||||
#include "panels/scene_hierarchy.hpp"
|
#include "panels/scene_hierarchy.hpp"
|
||||||
|
|
||||||
@@ -19,6 +14,7 @@
|
|||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <ImGuizmo.h>
|
#include <ImGuizmo.h>
|
||||||
|
#include <filesystem>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -95,6 +91,34 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
icons["play"] = Texture2D::Create("resources/textures/icons/play.png");
|
icons["play"] = Texture2D::Create("resources/textures/icons/play.png");
|
||||||
icons["stop"] = Texture2D::Create("resources/textures/icons/stop.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
|
// TODO: Add file texture. Get free icons and add license
|
||||||
//icons["folder"] = Texture2D::Create("resources/textures/icons/folder.png");
|
//icons["folder"] = Texture2D::Create("resources/textures/icons/folder.png");
|
||||||
/*
|
/*
|
||||||
@@ -140,7 +164,7 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
framebuffer->Bind();
|
framebuffer->Bind();
|
||||||
Renderer2D::ResetStats();
|
//Renderer2D::ResetStats();
|
||||||
RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
|
RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
|
||||||
RenderCommand::Clear();
|
RenderCommand::Clear();
|
||||||
framebuffer->ClearBufferI(1, -1);
|
framebuffer->ClearBufferI(1, -1);
|
||||||
@@ -282,12 +306,16 @@ namespace OpenEngine {
|
|||||||
void DrawViewport()
|
void DrawViewport()
|
||||||
{
|
{
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0, 0 });
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0, 0 });
|
||||||
|
|
||||||
ImGui::Begin("Viewport");
|
ImGui::Begin("Viewport");
|
||||||
|
|
||||||
|
bool was_focused = viewport_focused;
|
||||||
viewport_focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow);
|
viewport_focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow);
|
||||||
viewport_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow);
|
viewport_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow);
|
||||||
Application::Get().GetImGuiLayer()->SetBlockEvents((!viewport_focused && !viewport_hovered) || ImGui::IsAnyItemActive());
|
Application::Get().GetImGuiLayer()->SetBlockEvents((!viewport_focused && !viewport_hovered) || ImGui::IsAnyItemActive());
|
||||||
|
|
||||||
|
if (viewport_focused && !was_focused)
|
||||||
|
editor_camera.ResetMousePosition();
|
||||||
|
|
||||||
ImVec2 viewport_panel_size = ImGui::GetContentRegionAvail();
|
ImVec2 viewport_panel_size = ImGui::GetContentRegionAvail();
|
||||||
|
|
||||||
viewport_size = { viewport_panel_size.x, viewport_panel_size.y };
|
viewport_size = { viewport_panel_size.x, viewport_panel_size.y };
|
||||||
@@ -318,7 +346,7 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void DrawStats()
|
void DrawStats()
|
||||||
{
|
{
|
||||||
auto stats = Renderer2D::GetStats();
|
//auto stats = Renderer2D::GetStats();
|
||||||
static float time = 0;
|
static float time = 0;
|
||||||
|
|
||||||
time += Time::DeltaTime();
|
time += Time::DeltaTime();
|
||||||
@@ -330,17 +358,17 @@ namespace OpenEngine {
|
|||||||
ImGui::Begin("Statistics");
|
ImGui::Begin("Statistics");
|
||||||
ImGui::SeparatorText("Performance");
|
ImGui::SeparatorText("Performance");
|
||||||
ImGui::Text("FPS: %0.0f", 1 / Time::DeltaTime());
|
ImGui::Text("FPS: %0.0f", 1 / Time::DeltaTime());
|
||||||
ImGui::Text("Renderer2D:");
|
//ImGui::Text("Renderer2D:");
|
||||||
ImGui::Text("\t\tDraw calls: %d", stats.draw_calls);
|
//ImGui::Text("\t\tDraw calls: %d", stats.draw_calls);
|
||||||
ImGui::Text("\t\tQuad count: %d", stats.quad_count);
|
//ImGui::Text("\t\tQuad count: %d", stats.quad_count);
|
||||||
ImGui::Text("\t\tVertices count: %d", stats.GetTotalVertexCount());
|
//ImGui::Text("\t\tVertices count: %d", stats.GetTotalVertexCount());
|
||||||
ImGui::Text("\t\tIndices count: %d", stats.GetTotalIndexCount());
|
//ImGui::Text("\t\tIndices count: %d", stats.GetTotalIndexCount());
|
||||||
if (selected_entity) {
|
//if (selected_entity) {
|
||||||
ImGui::SeparatorText("Entities");
|
// ImGui::SeparatorText("Entities");
|
||||||
ImGui::Text("Selected entity:");
|
// ImGui::Text("Selected entity:");
|
||||||
ImGui::Text("\t\tname: %s", selected_entity.GetComponents<TagComponent>().tag.c_str());
|
// ImGui::Text("\t\tname: %s", selected_entity.GetComponents<TagComponent>().tag.c_str());
|
||||||
ImGui::Text("\t\tid: %d", (uint32_t)selected_entity);
|
// ImGui::Text("\t\tid: %d", (uint32_t)selected_entity);
|
||||||
}
|
//}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,10 @@ namespace OpenEngine {
|
|||||||
const std::array<const char*, 3> labels = {"x", "y", "z"});
|
const std::array<const char*, 3> labels = {"x", "y", "z"});
|
||||||
|
|
||||||
void TagOnImGuiRender(entt::registry& registry, entt::entity entity);
|
void TagOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
|
|
||||||
void TransformOnImGuiRender(entt::registry& registry, entt::entity entity);
|
void TransformOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
|
|
||||||
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity);
|
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
|
|
||||||
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity);
|
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
|
void MeshOnImGuiRender(entt::registry®istry, entt::entity entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EDITOR_COMPONENT_HPP
|
#endif // EDITOR_COMPONENT_HPP
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|
||||||
|
class EditorLayer;
|
||||||
|
|
||||||
class ContentBrowserPanel
|
class ContentBrowserPanel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -170,4 +170,9 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void MeshOnImGuiRender(entt::registry®istry, entt::entity entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace OpenEngine {
|
|||||||
RegisterDrawer<TransformComponent>("Transform", &TransformOnImGuiRender);
|
RegisterDrawer<TransformComponent>("Transform", &TransformOnImGuiRender);
|
||||||
RegisterDrawer<SpriteRendererComponent>("Sprite Renderer", &SpriteOnImGuiRender);
|
RegisterDrawer<SpriteRendererComponent>("Sprite Renderer", &SpriteOnImGuiRender);
|
||||||
RegisterDrawer<CameraComponent>("Camera", &CameraOnImGuiRender);
|
RegisterDrawer<CameraComponent>("Camera", &CameraOnImGuiRender);
|
||||||
|
RegisterDrawer<MeshComponent>("Mesh", &MeshOnImGuiRender);
|
||||||
|
|
||||||
scene = context;
|
scene = context;
|
||||||
selected_context = {};
|
selected_context = {};
|
||||||
@@ -32,17 +33,22 @@ namespace OpenEngine {
|
|||||||
ImGui::SeparatorText("Add");
|
ImGui::SeparatorText("Add");
|
||||||
if (!selected_context.HasComponent<TransformComponent>())
|
if (!selected_context.HasComponent<TransformComponent>())
|
||||||
if (ImGui::MenuItem("Transform")) {
|
if (ImGui::MenuItem("Transform")) {
|
||||||
selected_context.AddComponents<TransformComponent>();
|
selected_context.AddComponent<TransformComponent>();
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
if (!selected_context.HasComponent<SpriteRendererComponent>())
|
if (!selected_context.HasComponent<SpriteRendererComponent>())
|
||||||
if (ImGui::MenuItem("Sprite")) {
|
if (ImGui::MenuItem("Sprite")) {
|
||||||
selected_context.AddComponents<SpriteRendererComponent>();
|
selected_context.AddComponent<SpriteRendererComponent>();
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
if (!selected_context.HasComponent<CameraComponent>())
|
if (!selected_context.HasComponent<CameraComponent>())
|
||||||
if (ImGui::MenuItem("Camera")) {
|
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();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,6 +208,7 @@ namespace OpenEngine {
|
|||||||
entity.GetComponents<TagComponent>();
|
entity.GetComponents<TagComponent>();
|
||||||
TagOnImGuiRender(reg, entity);
|
TagOnImGuiRender(reg, entity);
|
||||||
|
|
||||||
|
|
||||||
std::vector<entt::id_type> component_to_delete; // 0 is null/invalid in entt usually
|
std::vector<entt::id_type> component_to_delete; // 0 is null/invalid in entt usually
|
||||||
// Iterate through every component type entt knows about
|
// Iterate through every component type entt knows about
|
||||||
for (auto [id, storage] : reg.storage()) {
|
for (auto [id, storage] : reg.storage()) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ add_definitions( -DOE_ENABLE_ASSERTS )
|
|||||||
find_package(imgui REQUIRED)
|
find_package(imgui REQUIRED)
|
||||||
find_package(EnTT REQUIRED)
|
find_package(EnTT REQUIRED)
|
||||||
find_package(yaml-cpp REQUIRED)
|
find_package(yaml-cpp REQUIRED)
|
||||||
|
find_package(Jolt REQUIRED)
|
||||||
|
|
||||||
file(GLOB_RECURSE SRC_FILES "src/*.cpp")
|
file(GLOB_RECURSE SRC_FILES "src/*.cpp")
|
||||||
file(GLOB IMGUIZMO_SRC_FILES "${CMAKE_SOURCE_DIR}/vendor/ImGuizmo/*.cpp")
|
file(GLOB IMGUIZMO_SRC_FILES "${CMAKE_SOURCE_DIR}/vendor/ImGuizmo/*.cpp")
|
||||||
@@ -52,6 +53,16 @@ target_link_libraries(${PROJECT_EXECUTABLE_NAME} PUBLIC
|
|||||||
X11
|
X11
|
||||||
yaml-cpp::yaml-cpp
|
yaml-cpp::yaml-cpp
|
||||||
nfd
|
nfd
|
||||||
|
shaderc_combined
|
||||||
|
glslang
|
||||||
|
glslang-default-resource-limits
|
||||||
|
SPIRV
|
||||||
|
SPIRV-Tools
|
||||||
|
SPIRV-Tools-opt
|
||||||
|
spirv-cross-core
|
||||||
|
spirv-cross-glsl
|
||||||
|
spirv-cross-reflect
|
||||||
|
Jolt::Jolt
|
||||||
)
|
)
|
||||||
|
|
||||||
#target_link_directories(${PROJECT_EXECUTABLE_NAME} PRIVATE
|
#target_link_directories(${PROJECT_EXECUTABLE_NAME} PRIVATE
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "open_engine/renderer/subtexture2d.hpp"
|
#include "open_engine/renderer/subtexture2d.hpp"
|
||||||
#include "open_engine/renderer/framebuffer.hpp"
|
#include "open_engine/renderer/framebuffer.hpp"
|
||||||
#include "open_engine/renderer/renderer2d.hpp"
|
#include "open_engine/renderer/renderer2d.hpp"
|
||||||
|
#include "open_engine/renderer/renderer3d.hpp"
|
||||||
#include "open_engine/renderer/renderer.hpp"
|
#include "open_engine/renderer/renderer.hpp"
|
||||||
#include "open_engine/renderer/texture.hpp"
|
#include "open_engine/renderer/texture.hpp"
|
||||||
#include "open_engine/renderer/buffer.hpp"
|
#include "open_engine/renderer/buffer.hpp"
|
||||||
|
|||||||
@@ -29,13 +29,14 @@ namespace OpenEngine {
|
|||||||
class OpenGLIndexBuffer : public IndexBuffer
|
class OpenGLIndexBuffer : public IndexBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OpenGLIndexBuffer(uint32_t* indices, uint32_t count);
|
OpenGLIndexBuffer(const uint32_t* indices, uint32_t count);
|
||||||
virtual ~OpenGLIndexBuffer();
|
virtual ~OpenGLIndexBuffer();
|
||||||
|
|
||||||
virtual void Bind() const override;
|
virtual void Bind() const override;
|
||||||
virtual void UnBind() const override;
|
virtual void UnBind() const override;
|
||||||
|
|
||||||
virtual uint32_t GetCount() const override { return count; };
|
virtual uint32_t GetCount() const override { return count; };
|
||||||
|
virtual uint32_t GetID() const override { return id; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef BUFFER_HPP
|
#ifndef BUFFER_HPP
|
||||||
#define BUFFER_HPP
|
#define BUFFER_HPP
|
||||||
|
|
||||||
|
#include "open_engine/ref_scope.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -82,8 +84,9 @@ namespace OpenEngine {
|
|||||||
virtual void UnBind() const = 0;
|
virtual void UnBind() const = 0;
|
||||||
|
|
||||||
virtual uint32_t GetCount() 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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ namespace OpenEngine {
|
|||||||
glm::vec3 GetForwardDirection() const;
|
glm::vec3 GetForwardDirection() const;
|
||||||
const glm::vec3& GetPosition() const { return position; }
|
const glm::vec3& GetPosition() const { return position; }
|
||||||
glm::quat GetOrientation() const;
|
glm::quat GetOrientation() const;
|
||||||
|
void ResetMousePosition();
|
||||||
|
|
||||||
float GetPitch() const { return pitch; }
|
float GetPitch() const { return pitch; }
|
||||||
float GetYaw() const { return yaw; }
|
float GetYaw() const { return yaw; }
|
||||||
@@ -61,6 +62,7 @@ namespace OpenEngine {
|
|||||||
glm::vec3 focal_point = { 0.0f, 0.0f, 0.0f };
|
glm::vec3 focal_point = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
glm::vec2 initial_mouse_position = { 0.0f, 0.0f };
|
glm::vec2 initial_mouse_position = { 0.0f, 0.0f };
|
||||||
|
bool mouse_button_was_pressed = false;
|
||||||
|
|
||||||
float distance = 10.0f;
|
float distance = 10.0f;
|
||||||
float pitch = 0.0f, yaw = 0.0f;
|
float pitch = 0.0f, yaw = 0.0f;
|
||||||
|
|||||||
61
open_engine/include/open_engine/renderer/renderer3d.hpp
Normal file
61
open_engine/include/open_engine/renderer/renderer3d.hpp
Normal 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
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#define VERTEX_ARRAY_HPP
|
#define VERTEX_ARRAY_HPP
|
||||||
|
|
||||||
#include "open_engine/renderer/buffer.hpp"
|
#include "open_engine/renderer/buffer.hpp"
|
||||||
|
#include "open_engine/ref_scope.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
#define COMPONENTS_HPP
|
#define COMPONENTS_HPP
|
||||||
|
|
||||||
#include "open_engine/scene/native_scriptable_entity.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/scene/scene_camera.hpp"
|
||||||
#include "open_engine/renderer/texture.hpp"
|
#include "open_engine/renderer/texture.hpp"
|
||||||
|
#include "open_engine/renderer/renderer3d.hpp"
|
||||||
|
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.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
|
#endif // COMPONENTS_HPP
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace OpenEngine {
|
|||||||
Entity(const Entity& other) = default;
|
Entity(const Entity& other) = default;
|
||||||
|
|
||||||
template<typename T, typename ... Args>
|
template<typename T, typename ... Args>
|
||||||
T& AddComponents(Args&&... args)
|
T& AddComponent(Args&&... args)
|
||||||
{
|
{
|
||||||
OE_ASSERT(!HasComponent<T>(), "Entity already has component.");
|
OE_ASSERT(!HasComponent<T>(), "Entity already has component.");
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <core.hpp>
|
#include <core.hpp>
|
||||||
#include <events/application_event.hpp>
|
#include <events/application_event.hpp>
|
||||||
|
#include <renderer/renderer3d.hpp>
|
||||||
#include <renderer/renderer2d.hpp>
|
#include <renderer/renderer2d.hpp>
|
||||||
#include <input/input_system.hpp>
|
#include <input/input_system.hpp>
|
||||||
#include <imgui/imgui_layer.hpp>
|
#include <imgui/imgui_layer.hpp>
|
||||||
@@ -28,7 +29,8 @@ namespace OpenEngine {
|
|||||||
{
|
{
|
||||||
OE_PROFILE_SCOPE("Initializing Renderers");
|
OE_PROFILE_SCOPE("Initializing Renderers");
|
||||||
Renderer::Init();
|
Renderer::Init();
|
||||||
Renderer2D::Init();
|
//Renderer2D::Init();
|
||||||
|
Renderer3D::Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
imgui_layer = std::make_shared<ImGuiLayer>();
|
imgui_layer = std::make_shared<ImGuiLayer>();
|
||||||
@@ -39,7 +41,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
{
|
{
|
||||||
OpenEngine::Renderer2D::Shutdown();
|
//OpenEngine::Renderer2D::Shutdown();
|
||||||
|
Renderer3D::Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::Run()
|
void Application::Run()
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace OpenEngine {
|
|||||||
// Index Buffer =====================================================
|
// Index Buffer =====================================================
|
||||||
// ==================================================================
|
// ==================================================================
|
||||||
|
|
||||||
OpenGLIndexBuffer::OpenGLIndexBuffer(uint32_t* indices, uint32_t count)
|
OpenGLIndexBuffer::OpenGLIndexBuffer(const uint32_t* indices, uint32_t count)
|
||||||
: count(count)
|
: count(count)
|
||||||
{
|
{
|
||||||
OE_PROFILE_FUNCTION();
|
OE_PROFILE_FUNCTION();
|
||||||
@@ -68,7 +68,7 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void OpenGLIndexBuffer::Bind() const
|
void OpenGLIndexBuffer::Bind() const
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, id);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||||
}
|
}
|
||||||
void OpenGLIndexBuffer::UnBind() const
|
void OpenGLIndexBuffer::UnBind() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ namespace OpenEngine {
|
|||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLRendererAPI::SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
|
void OpenGLRendererAPI::SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
|
||||||
@@ -66,6 +67,9 @@ namespace OpenEngine {
|
|||||||
{
|
{
|
||||||
OE_PROFILE_FUNCTION();
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
OE_CORE_ASSERT(vertex_array, "VertexArray is null!");
|
||||||
|
OE_CORE_ASSERT(vertex_array->GetIndexBuffer(), "IndexBuffer is null!");
|
||||||
|
|
||||||
uint32_t count = index_count? index_count : vertex_array->GetIndexBuffer()->GetCount();
|
uint32_t count = index_count? index_count : vertex_array->GetIndexBuffer()->GetCount();
|
||||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr);
|
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace OpenEngine {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<IndexBuffer> IndexBuffer::Create(uint32_t* indices, uint32_t count)
|
Ref<IndexBuffer> IndexBuffer::Create(const uint32_t* indices, uint32_t count)
|
||||||
{
|
{
|
||||||
OE_PROFILE_FUNCTION();
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include "logging.hpp"
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <renderer/editor_camera.hpp>
|
#include <renderer/editor_camera.hpp>
|
||||||
@@ -63,10 +62,11 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void EditorCamera::OnUpdate()
|
void EditorCamera::OnUpdate()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Input::IsKeyPressed(Key::LeftAlt)) {
|
if (Input::IsKeyPressed(Key::LeftAlt)) {
|
||||||
const glm::vec2& mouse{ Input::GetMouseX(), Input::GetMouseY() };
|
const glm::vec2& mouse{ Input::GetMouseX(), Input::GetMouseY() };
|
||||||
glm::vec2 delta = (mouse - initial_mouse_position) * 0.003f;
|
glm::vec2 delta = (mouse - initial_mouse_position) * 0.003f;
|
||||||
initial_mouse_position = mouse;
|
initial_mouse_position = mouse;
|
||||||
|
|
||||||
if (Input::IsMouseButtonPressed(Mouse::ButtonMiddle)) {
|
if (Input::IsMouseButtonPressed(Mouse::ButtonMiddle)) {
|
||||||
MousePan(delta);
|
MousePan(delta);
|
||||||
@@ -151,4 +151,10 @@ namespace OpenEngine {
|
|||||||
return glm::quat(glm::vec3(-pitch, -yaw, 0.0f));
|
return glm::quat(glm::vec3(-pitch, -yaw, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorCamera::ResetMousePosition()
|
||||||
|
{
|
||||||
|
initial_mouse_position = { Input::GetMouseX(), Input::GetMouseY() };
|
||||||
|
mouse_button_was_pressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "renderer/editor_camera.hpp"
|
|
||||||
#include "renderer/uniform_buffer.hpp"
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
|
#include "renderer/editor_camera.hpp"
|
||||||
|
#include "renderer/uniform_buffer.hpp"
|
||||||
#include <renderer/render_command.hpp>
|
#include <renderer/render_command.hpp>
|
||||||
#include <renderer/vertex_array.hpp>
|
#include <renderer/vertex_array.hpp>
|
||||||
#include <renderer/renderer2d.hpp>
|
#include <renderer/renderer2d.hpp>
|
||||||
@@ -121,6 +121,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void Renderer2D::Shutdown()
|
void Renderer2D::Shutdown()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
renderer_data.white_texture.reset();
|
renderer_data.white_texture.reset();
|
||||||
renderer_data.vertex_array.reset();
|
renderer_data.vertex_array.reset();
|
||||||
renderer_data.vertex_buffer.reset();
|
renderer_data.vertex_buffer.reset();
|
||||||
@@ -130,8 +132,6 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
for (uint32_t i = 0; i < renderer_data.texture_slot_index; i++)
|
for (uint32_t i = 0; i < renderer_data.texture_slot_index; i++)
|
||||||
renderer_data.texture_slots[i].reset();
|
renderer_data.texture_slots[i].reset();
|
||||||
|
|
||||||
OE_PROFILE_FUNCTION();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer2D::BeginScene(const OrthographicCamera& camera)
|
void Renderer2D::BeginScene(const OrthographicCamera& camera)
|
||||||
|
|||||||
200
open_engine/src/open_engine/renderer/renderer3d.cpp
Normal file
200
open_engine/src/open_engine/renderer/renderer3d.cpp
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
#include "logging.hpp"
|
||||||
|
#include <pch.hpp>
|
||||||
|
|
||||||
|
#include <renderer/render_command.hpp>
|
||||||
|
#include <renderer/uniform_buffer.hpp>
|
||||||
|
#include <renderer/editor_camera.hpp>
|
||||||
|
#include <renderer/vertex_array.hpp>
|
||||||
|
#include <renderer/renderer3d.hpp>
|
||||||
|
#include <renderer/shader.hpp>
|
||||||
|
#include <renderer/buffer.hpp>
|
||||||
|
#include <instrumentor.hpp>
|
||||||
|
#include <ref_scope.hpp>
|
||||||
|
|
||||||
|
#include <glm/ext/quaternion_common.hpp>
|
||||||
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
|
#include <glm/trigonometric.hpp>
|
||||||
|
#include <glm/fwd.hpp>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
namespace OpenEngine {
|
||||||
|
|
||||||
|
// SHOULD BE MOVED ==================================
|
||||||
|
Ref<Mesh> CreateMesh(const std::vector<MeshVertex>& vertices,
|
||||||
|
const std::vector<uint32_t>& indices)
|
||||||
|
{
|
||||||
|
Ref<Mesh> mesh = CreateRef<Mesh>();
|
||||||
|
mesh->vertices = vertices;
|
||||||
|
mesh->indices = indices;
|
||||||
|
|
||||||
|
mesh->index_buffer = IndexBuffer::Create(indices.data(), indices.size());
|
||||||
|
mesh->vertex_array = VertexArray::Create();
|
||||||
|
mesh->vertex_buffer = VertexBuffer::Create(vertices.size() * sizeof(MeshVertex));
|
||||||
|
|
||||||
|
mesh->vertex_buffer->SetData(vertices.data(), vertices.size() * sizeof(MeshVertex));
|
||||||
|
|
||||||
|
BufferLayout layout = {
|
||||||
|
{ ShaderDataType::Float3, "a_Position" },
|
||||||
|
{ ShaderDataType::Float4, "a_Color" },
|
||||||
|
{ ShaderDataType::Float3, "a_Normal" },
|
||||||
|
{ ShaderDataType::Float2, "a_TexCoord" },
|
||||||
|
{ ShaderDataType::Int, "a_EntityID"}
|
||||||
|
};
|
||||||
|
|
||||||
|
mesh->vertex_buffer->SetLayout(layout);
|
||||||
|
|
||||||
|
mesh->vertex_array->AddVertexBuffer(mesh->vertex_buffer);
|
||||||
|
mesh->vertex_array->SetIndexBuffer(mesh->index_buffer);
|
||||||
|
|
||||||
|
return mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Mesh> CreateCube(uint32_t id)
|
||||||
|
{
|
||||||
|
OE_CORE_DEBUG("Creating cube with id {}.", id);
|
||||||
|
std::vector<MeshVertex> vertices = {
|
||||||
|
// Back face (normal 0, 0, -1)
|
||||||
|
{{-0.5f, -0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {0,0,-1}, {0,0}, id},
|
||||||
|
{{-0.5f, 0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {0,0,-1}, {0,1}, id},
|
||||||
|
{{ 0.5f, 0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {0,0,-1}, {1,1}, id},
|
||||||
|
{{ 0.5f, -0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {0,0,-1}, {1,0}, id},
|
||||||
|
|
||||||
|
// Front face (normal 0, 0, 1)
|
||||||
|
{{-0.5f, -0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {0,0,1}, {0,0}, id},
|
||||||
|
{{-0.5f, 0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {0,0,1}, {0,1}, id},
|
||||||
|
{{ 0.5f, 0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {0,0,1}, {1,1}, id},
|
||||||
|
{{ 0.5f, -0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {0,0,1}, {1,0}, id},
|
||||||
|
|
||||||
|
// Left face (normal -1, 0, 0)
|
||||||
|
{{-0.5f, -0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {-1,0,0}, {0,0}, id},
|
||||||
|
{{-0.5f, 0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {-1,0,0}, {0,1}, id},
|
||||||
|
{{-0.5f, 0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {-1,0,0}, {1,1}, id},
|
||||||
|
{{-0.5f, -0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {-1,0,0}, {1,0}, id},
|
||||||
|
|
||||||
|
// Right face (normal 1, 0, 0)
|
||||||
|
{{ 0.5f, -0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {1,0,0}, {0,0}, id},
|
||||||
|
{{ 0.5f, 0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {1,0,0}, {0,1}, id},
|
||||||
|
{{ 0.5f, 0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {1,0,0}, {1,1}, id},
|
||||||
|
{{ 0.5f, -0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {1,0,0}, {1,0}, id},
|
||||||
|
|
||||||
|
// Top face (normal 0, 1, 0)
|
||||||
|
{{-0.5f, 0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {0,1,0}, {0,0}, id},
|
||||||
|
{{-0.5f, 0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {0,1,0}, {0,1}, id},
|
||||||
|
{{ 0.5f, 0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {0,1,0}, {1,1}, id},
|
||||||
|
{{ 0.5f, 0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {0,1,0}, {1,0}, id},
|
||||||
|
|
||||||
|
// Bottom face (normal 0, -1, 0)
|
||||||
|
{{-0.5f, -0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {0,-1,0}, {0,0}, id},
|
||||||
|
{{-0.5f, -0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {0,-1,0}, {0,1}, id},
|
||||||
|
{{ 0.5f, -0.5f, 0.5f}, {0.5f,0.5f,0.5f,1}, {0,-1,0}, {1,1}, id},
|
||||||
|
{{ 0.5f, -0.5f, -0.5f}, {0.5f,0.5f,0.5f,1}, {0,-1,0}, {1,0}, id},
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<uint32_t> indices = {
|
||||||
|
// Back face (z=-0.5)
|
||||||
|
0, 1, 2, 0, 2, 3,
|
||||||
|
// Front face (z=0.5)
|
||||||
|
4, 6, 5, 4, 7, 6,
|
||||||
|
// Right face
|
||||||
|
12, 13, 14, 12, 14, 15,
|
||||||
|
// Left face
|
||||||
|
8, 10, 9, 8, 11, 10,
|
||||||
|
// Top face
|
||||||
|
18, 16, 17, 18, 19, 16,
|
||||||
|
// Bottom face
|
||||||
|
20, 22, 21, 20, 23, 22
|
||||||
|
// TODO: Missing backface
|
||||||
|
};
|
||||||
|
|
||||||
|
return CreateMesh(vertices, indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================================================
|
||||||
|
struct Renderer3DData
|
||||||
|
{
|
||||||
|
Ref<Shader> color_shader_3d;
|
||||||
|
|
||||||
|
struct CameraData
|
||||||
|
{
|
||||||
|
glm::mat4 view_projection;
|
||||||
|
glm::vec3 view_position;
|
||||||
|
};
|
||||||
|
CameraData camera_buffer;
|
||||||
|
Ref<UniformBuffer> camera_uniform_buffer;
|
||||||
|
|
||||||
|
struct TransformData
|
||||||
|
{
|
||||||
|
glm::mat4 transform;
|
||||||
|
};
|
||||||
|
TransformData transform_buffer;
|
||||||
|
Ref<UniformBuffer> transform_uniform_buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
static Renderer3DData renderer_data;
|
||||||
|
|
||||||
|
void Renderer3D::Init()
|
||||||
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
|
renderer_data.color_shader_3d = Shader::Create("assets/shaders/color3d.glsl");
|
||||||
|
renderer_data.camera_uniform_buffer = UniformBuffer::Create(sizeof(Renderer3DData::CameraData), 0);
|
||||||
|
renderer_data.transform_uniform_buffer = UniformBuffer::Create(sizeof(Renderer3DData::TransformData), 1);
|
||||||
|
|
||||||
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||||
|
glDebugMessageCallback([](GLenum source, GLenum type, GLuint id, GLenum severity,
|
||||||
|
GLsizei length, const GLchar* message, const void* userParam) {
|
||||||
|
OE_CORE_ERROR("GL: {0}", message);
|
||||||
|
}, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer3D::Shutdown()
|
||||||
|
{
|
||||||
|
renderer_data.camera_uniform_buffer.reset();
|
||||||
|
renderer_data.color_shader_3d.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer3D::BeginScene(const Camera& camera, const glm::mat4& transform)
|
||||||
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
renderer_data.camera_buffer.view_projection = camera.GetProjection() * glm::inverse(transform);
|
||||||
|
renderer_data.camera_buffer.view_position = transform[3];
|
||||||
|
|
||||||
|
renderer_data.camera_uniform_buffer->SetData(&renderer_data.camera_buffer, sizeof(Renderer3DData::CameraData));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer3D::BeginScene(const EditorCamera& camera)
|
||||||
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
renderer_data.camera_buffer.view_projection = camera.GetViewProjection();
|
||||||
|
renderer_data.camera_buffer.view_position = camera.GetPosition();
|
||||||
|
|
||||||
|
renderer_data.camera_uniform_buffer->SetData(&renderer_data.camera_buffer, sizeof(Renderer3DData::CameraData));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer3D::EndScene()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer3D::DrawMesh(const Ref<Mesh>& mesh, const glm::mat4& transform)
|
||||||
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
renderer_data.color_shader_3d->Bind();
|
||||||
|
|
||||||
|
renderer_data.transform_buffer.transform = transform;
|
||||||
|
renderer_data.transform_uniform_buffer->SetData(&renderer_data.transform_buffer, sizeof(Renderer3DData::TransformData));
|
||||||
|
|
||||||
|
mesh->vertex_array->Bind();
|
||||||
|
|
||||||
|
RenderCommand::DrawIndexed(mesh->vertex_array, mesh->indices.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
|
#include <cstdint>
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <renderer/renderer2d.hpp>
|
#include <renderer/renderer3d.hpp>
|
||||||
#include <scene/components.hpp>
|
#include <scene/components.hpp>
|
||||||
#include <scene/entity.hpp>
|
#include <scene/entity.hpp>
|
||||||
#include <scene/scene.hpp>
|
#include <scene/scene.hpp>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|
||||||
Entity Scene::CreateEntity(const std::string& name)
|
Entity Scene::CreateEntity(const std::string& name)
|
||||||
{
|
{
|
||||||
Entity entity = { registry.create(), this };
|
Entity entity = { registry.create(), this };
|
||||||
|
|
||||||
auto& tag = entity.AddComponents<TagComponent>();
|
auto& tag = entity.AddComponent<TagComponent>();
|
||||||
tag.tag = name.empty() ? "Entity" : name;
|
tag.tag = name.empty() ? "Entity" : name;
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
@@ -52,6 +54,7 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (main_camera) {
|
if (main_camera) {
|
||||||
Renderer2D::BeginScene(main_camera->GetProjection(), main_transform);
|
Renderer2D::BeginScene(main_camera->GetProjection(), main_transform);
|
||||||
|
|
||||||
@@ -70,27 +73,23 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
Renderer2D::EndScene();
|
Renderer2D::EndScene();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::OnUpdateEditor(EditorCamera& camera)
|
void Scene::OnUpdateEditor(EditorCamera& camera)
|
||||||
{
|
{
|
||||||
Renderer2D::BeginScene(camera);
|
Renderer3D::BeginScene(camera);
|
||||||
|
|
||||||
auto group = registry.group<TransformComponent>(entt::get<SpriteRendererComponent>);
|
auto view = registry.view<TransformComponent, MeshComponent>();
|
||||||
for (auto entity : group)
|
|
||||||
{
|
|
||||||
auto [transform, sprite] = group.get<TransformComponent, SpriteRendererComponent>(entity);
|
|
||||||
|
|
||||||
if (sprite.texture)
|
for (const auto& entity : view) {
|
||||||
Renderer2D::DrawQuad(GetTransformFromComp(transform),
|
auto [transform, mesh] = view.get<TransformComponent, MeshComponent>(entity);
|
||||||
sprite.texture, sprite.color, (int)entity, sprite.tiling_factor);
|
|
||||||
else
|
|
||||||
Renderer2D::DrawQuad(GetTransformFromComp(transform),
|
|
||||||
sprite.color, (int)entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
Renderer2D::EndScene();
|
Renderer3D::DrawMesh(mesh.mesh, GetTransformFromComp(transform));
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer3D::EndScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::OnViewportResize(uint32_t width, uint32_t height)
|
void Scene::OnViewportResize(uint32_t width, uint32_t height)
|
||||||
@@ -151,4 +150,9 @@ namespace OpenEngine {
|
|||||||
void Scene::OnComponentAdded<NativeScriptComponent>(Entity entity, NativeScriptComponent& component)
|
void Scene::OnComponentAdded<NativeScriptComponent>(Entity entity, NativeScriptComponent& component)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
void Scene::OnComponentAdded<MeshComponent>(Entity entity, MeshComponent& component)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ namespace OpenEngine {
|
|||||||
auto transformComponent = entity["TransformComponent"];
|
auto transformComponent = entity["TransformComponent"];
|
||||||
if (transformComponent)
|
if (transformComponent)
|
||||||
{
|
{
|
||||||
auto& tc = deserializedEntity.AddComponents<TransformComponent>();
|
auto& tc = deserializedEntity.AddComponent<TransformComponent>();
|
||||||
tc.translation = transformComponent["Translation"].as<glm::vec3>();
|
tc.translation = transformComponent["Translation"].as<glm::vec3>();
|
||||||
tc.rotation = transformComponent["Rotation"].as<glm::vec3>();
|
tc.rotation = transformComponent["Rotation"].as<glm::vec3>();
|
||||||
tc.scale = transformComponent["Scale"].as<glm::vec3>();
|
tc.scale = transformComponent["Scale"].as<glm::vec3>();
|
||||||
@@ -218,7 +218,7 @@ namespace OpenEngine {
|
|||||||
auto cameraComponent = entity["CameraComponent"];
|
auto cameraComponent = entity["CameraComponent"];
|
||||||
if (cameraComponent)
|
if (cameraComponent)
|
||||||
{
|
{
|
||||||
auto& cc = deserializedEntity.AddComponents<CameraComponent>();
|
auto& cc = deserializedEntity.AddComponent<CameraComponent>();
|
||||||
|
|
||||||
auto camera_props = cameraComponent["Camera"];
|
auto camera_props = cameraComponent["Camera"];
|
||||||
cc.camera.SetProjectionType((SceneCamera::ProjectionType)camera_props["ProjectionType"].as<int>());
|
cc.camera.SetProjectionType((SceneCamera::ProjectionType)camera_props["ProjectionType"].as<int>());
|
||||||
@@ -238,7 +238,7 @@ namespace OpenEngine {
|
|||||||
auto spriteRendererComponent = entity["SpriteRendererComponent"];
|
auto spriteRendererComponent = entity["SpriteRendererComponent"];
|
||||||
if (spriteRendererComponent)
|
if (spriteRendererComponent)
|
||||||
{
|
{
|
||||||
auto& src = deserializedEntity.AddComponents<SpriteRendererComponent>();
|
auto& src = deserializedEntity.AddComponent<SpriteRendererComponent>();
|
||||||
src.color = spriteRendererComponent["Color"].as<glm::vec4>();
|
src.color = spriteRendererComponent["Color"].as<glm::vec4>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user