cleanup and instrumentation
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#ifndef SANDBOX_HPP
|
#ifndef SANDBOX_HPP
|
||||||
#define SANDBOX_HPP
|
#define SANDBOX_HPP
|
||||||
|
|
||||||
|
#include "open_engine/core/time.hpp"
|
||||||
|
#include <glm/fwd.hpp>
|
||||||
#include <open_engine.hpp>
|
#include <open_engine.hpp>
|
||||||
|
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
@@ -27,8 +29,7 @@ class SandboxLayer : public OpenEngine::Layer
|
|||||||
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
OpenEngine::Ref<OpenEngine::VertexBuffer> vertex_buffer;
|
OpenEngine::Ref<OpenEngine::VertexBuffer> vertex_buffer = OpenEngine::VertexBuffer::Create(square_vertices, sizeof(square_vertices));
|
||||||
vertex_buffer.reset(OpenEngine::VertexBuffer::Create(square_vertices, sizeof(square_vertices)));
|
|
||||||
|
|
||||||
OpenEngine::BufferLayout layout = {
|
OpenEngine::BufferLayout layout = {
|
||||||
{ OpenEngine::ShaderDataType::Float3, "a_Position" },
|
{ OpenEngine::ShaderDataType::Float3, "a_Position" },
|
||||||
@@ -39,8 +40,7 @@ class SandboxLayer : public OpenEngine::Layer
|
|||||||
square_vertex_array->AddVertexBuffer(vertex_buffer);
|
square_vertex_array->AddVertexBuffer(vertex_buffer);
|
||||||
|
|
||||||
uint32_t indices[6] = { 0, 1, 2, 2, 3, 0 };
|
uint32_t indices[6] = { 0, 1, 2, 2, 3, 0 };
|
||||||
OpenEngine::Ref<OpenEngine::IndexBuffer> index_buffer;
|
OpenEngine::Ref<OpenEngine::IndexBuffer> index_buffer = OpenEngine::IndexBuffer::Create(indices, sizeof(indices) / sizeof(uint32_t));
|
||||||
index_buffer.reset(OpenEngine::IndexBuffer::Create(indices, sizeof(indices) / sizeof(uint32_t)));
|
|
||||||
|
|
||||||
square_vertex_array->SetIndexBuffer(index_buffer);
|
square_vertex_array->SetIndexBuffer(index_buffer);
|
||||||
|
|
||||||
@@ -57,8 +57,12 @@ class SandboxLayer : public OpenEngine::Layer
|
|||||||
camera((float)OpenEngine::Application::Get().GetWindow().GetWidth() /
|
camera((float)OpenEngine::Application::Get().GetWindow().GetWidth() /
|
||||||
OpenEngine::Application::Get().GetWindow().GetHeight(), 1.0f)
|
OpenEngine::Application::Get().GetWindow().GetHeight(), 1.0f)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
//vertex_array.reset(OpenEngine::VertexArray::Create());
|
//vertex_array.reset(OpenEngine::VertexArray::Create());
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Creating Square");
|
||||||
square = CreateSquare();
|
square = CreateSquare();
|
||||||
|
}
|
||||||
|
|
||||||
//float vertices[3 * 7] = {
|
//float vertices[3 * 7] = {
|
||||||
// -0.5f, -0.5f, 0.0f, 0.8f, 0.2f, 0.8f, 1.0f,
|
// -0.5f, -0.5f, 0.0f, 0.8f, 0.2f, 0.8f, 1.0f,
|
||||||
@@ -86,14 +90,24 @@ class SandboxLayer : public OpenEngine::Layer
|
|||||||
|
|
||||||
//texture_shader = OpenEngine::Shader::Create("./assets/shaders/texture.glsl");
|
//texture_shader = OpenEngine::Shader::Create("./assets/shaders/texture.glsl");
|
||||||
auto texture_shader = shader_library.Load("./assets/shaders/texture.glsl");
|
auto texture_shader = shader_library.Load("./assets/shaders/texture.glsl");
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Creating Textures");
|
||||||
texture = OpenEngine::Texture2D::Create("./assets/textures/container.jpg");
|
texture = OpenEngine::Texture2D::Create("./assets/textures/container.jpg");
|
||||||
face = OpenEngine::Texture2D::Create("./assets/textures/awesomeface.png");
|
face = OpenEngine::Texture2D::Create("./assets/textures/awesomeface.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Setting up shader uniforms");
|
||||||
texture_shader->Bind();
|
texture_shader->Bind();
|
||||||
texture_shader->SetInt("u_Texture", 0);
|
texture_shader->SetInt("u_Texture", 0);
|
||||||
|
texture_shader->SetVec4("u_Color", glm::vec4(1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Listing Joysticks");
|
||||||
for (auto joystick : OpenEngine::Input::GetJoystickList())
|
for (auto joystick : OpenEngine::Input::GetJoystickList())
|
||||||
OE_DEBUG("Joystick {}: {}", joystick.first, joystick.second);
|
OE_DEBUG("Joystick {}: {}", joystick.first, joystick.second);
|
||||||
|
}
|
||||||
|
|
||||||
bindings = {
|
bindings = {
|
||||||
{"fwd/bckwd", 1},
|
{"fwd/bckwd", 1},
|
||||||
|
|||||||
38
application/include/sandbox2d.hpp
Normal file → Executable file
38
application/include/sandbox2d.hpp
Normal file → Executable file
@@ -1,9 +1,9 @@
|
|||||||
#ifndef SANDBOX2D_HPP
|
#ifndef SANDBOX2D_HPP
|
||||||
#define SANDBOX2D_HPP
|
#define SANDBOX2D_HPP
|
||||||
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <open_engine.hpp>
|
#include <open_engine.hpp>
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
@@ -22,14 +22,18 @@ class Sandbox2DLayer : public OpenEngine::Layer
|
|||||||
|
|
||||||
void OnAttach() override
|
void OnAttach() override
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
bindings = {
|
bindings = {
|
||||||
{"fwd/bckwd", 1},
|
{"fwd/bckwd", 1},
|
||||||
{"right/left", 0},
|
{"right/left", 0},
|
||||||
{"yaw", 2}
|
{"yaw", 2}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Texture2D Creation");
|
||||||
face = OpenEngine::Texture2D::Create("assets/textures/awesomeface.png");
|
face = OpenEngine::Texture2D::Create("assets/textures/awesomeface.png");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OnDetach() override
|
void OnDetach() override
|
||||||
{
|
{
|
||||||
@@ -37,15 +41,19 @@ class Sandbox2DLayer : public OpenEngine::Layer
|
|||||||
|
|
||||||
void OnUpdate() override
|
void OnUpdate() override
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION()
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Setting up Rendering");
|
||||||
OpenEngine::RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
|
OpenEngine::RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
|
||||||
OpenEngine::RenderCommand::Clear();
|
OpenEngine::RenderCommand::Clear();
|
||||||
|
|
||||||
OpenEngine::Renderer2D::BeginScene(camera.GetCamera());
|
OpenEngine::Renderer2D::BeginScene(camera.GetCamera());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Drawing Quads");
|
||||||
OpenEngine::Renderer2D::DrawQuad(glm::vec2(0.5f, 0.5f), glm::vec2(0.3f), glm::vec4(color[0], color[1], color[2], color[3]));
|
OpenEngine::Renderer2D::DrawQuad(glm::vec2(0.5f, 0.5f), glm::vec2(0.3f), glm::vec4(color[0], color[1], color[2], color[3]));
|
||||||
OpenEngine::Renderer2D::DrawQuad(glm::vec2(-0.2f, -0.2f), glm::vec2(0.5f, 0.2f), {0.5f, 0.3f, 0.8f, 1.0f});
|
OpenEngine::Renderer2D::DrawQuad(glm::vec2(-0.2f, -0.2f), glm::vec2(0.5f, 0.2f), {0.5f, 0.3f, 0.8f, 1.0f});
|
||||||
OpenEngine::Renderer2D::DrawQuad(glm::vec3(0.0f, 0.0f, -0.1f), glm::vec2(1.0f, 1.0f), face);
|
OpenEngine::Renderer2D::DrawQuad(glm::vec3(0.0f, 0.0f, -0.1f), glm::vec2(1.0f, 1.0f), face);
|
||||||
|
}
|
||||||
OpenEngine::Renderer2D::EndScene();
|
OpenEngine::Renderer2D::EndScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,22 +70,38 @@ class Sandbox2DLayer : public OpenEngine::Layer
|
|||||||
|
|
||||||
void OnEvent(OpenEngine::Event& event) override
|
void OnEvent(OpenEngine::Event& event) override
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
OpenEngine::EventDispatcher dispatcher(event);
|
OpenEngine::EventDispatcher dispatcher(event);
|
||||||
|
|
||||||
//dispatcher.Dispatch<OpenEngine::KeyPressedEvent>(BIND_EVENT_FN(Sandbox2DLayer::StopRunning));
|
//dispatcher.Dispatch<OpenEngine::KeyPressedEvent>(BIND_EVENT_FN(Sandbox2DLayer::StopRunning));
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Camera OnEvent");
|
||||||
camera.OnEvent(event);
|
camera.OnEvent(event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OnImGuiRender() override
|
void OnImGuiRender() override
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
ImGui::Begin("Square settings");
|
ImGui::Begin("Square settings");
|
||||||
ImGui::ColorEdit4("Square color", color);
|
ImGui::ColorEdit4("Square color", color);
|
||||||
|
|
||||||
|
for (auto& result : profiling_results)
|
||||||
|
{
|
||||||
|
char label[50];
|
||||||
|
strcpy(label, "%.3fms ");
|
||||||
|
strcat(label, result.name);
|
||||||
|
ImGui::Text(label, result.duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
profiling_results.clear();
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//OpenEngine::ShaderLibrary shader_library;
|
//OpenEngine::ShaderLibrary shader_library;
|
||||||
|
|
||||||
glm::vec3 square_pos = glm::vec3(0.0f);
|
glm::vec3 square_pos = glm::vec3(0.0f);
|
||||||
glm::vec4 square_color = glm::vec4(1.0f);
|
glm::vec4 square_color = glm::vec4(1.0f);
|
||||||
|
|
||||||
@@ -85,7 +109,9 @@ class Sandbox2DLayer : public OpenEngine::Layer
|
|||||||
OpenEngine::Ref<OpenEngine::Texture2D> face;
|
OpenEngine::Ref<OpenEngine::Texture2D> face;
|
||||||
|
|
||||||
std::unordered_map<std::string, unsigned int> bindings;
|
std::unordered_map<std::string, unsigned int> bindings;
|
||||||
OpenEngine::OrthographicCameraController camera = {1280.0f / 1440.0f, 1.0f};
|
OpenEngine::OrthographicCameraController camera;
|
||||||
|
|
||||||
|
std::vector<OpenEngine::Time::ProfilingResult> profiling_results;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SANDBOX2D_HPP
|
#endif // SANDBOX2D_HPP
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "open_engine/core.hpp"
|
#include <open_engine/core.hpp>
|
||||||
|
#include <control_layer.hpp>
|
||||||
#include <sandbox2d.hpp>
|
#include <sandbox2d.hpp>
|
||||||
#include <sandbox.hpp>
|
#include <sandbox.hpp>
|
||||||
#include <control_layer.hpp>
|
|
||||||
|
|
||||||
ControlLayer::ControlLayer(OpenEngine::Ref<OpenEngine::Layer> layer)
|
ControlLayer::ControlLayer(OpenEngine::Ref<OpenEngine::Layer> layer)
|
||||||
: active_layer(layer), OpenEngine::Layer("control_layer")
|
: active_layer(layer), OpenEngine::Layer("control_layer")
|
||||||
@@ -14,12 +14,19 @@ void ControlLayer::OnUpdate()
|
|||||||
|
|
||||||
bool ControlLayer::SwitchLayer(OpenEngine::KeyPressedEvent& event)
|
bool ControlLayer::SwitchLayer(OpenEngine::KeyPressedEvent& event)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
auto& app = OpenEngine::Application::Get();
|
auto& app = OpenEngine::Application::Get();
|
||||||
OpenEngine::Ref<Layer> layer;
|
OpenEngine::Ref<Layer> layer;
|
||||||
|
|
||||||
if (event.GetKeyCode() == OE_KEY_1) {
|
if (event.GetKeyCode() == OE_KEY_1) {
|
||||||
|
OE_PROFILE_SCOPE("Press Key 1");
|
||||||
|
|
||||||
OE_DEBUG("Sandbox2D Layer");
|
OE_DEBUG("Sandbox2D Layer");
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Creating SB2D");
|
||||||
layer = OpenEngine::CreateRef<Sandbox2DLayer>();
|
layer = OpenEngine::CreateRef<Sandbox2DLayer>();
|
||||||
|
}
|
||||||
|
|
||||||
app.QueueLayerPush(layer);
|
app.QueueLayerPush(layer);
|
||||||
app.QueueLayerPop(active_layer);
|
app.QueueLayerPop(active_layer);
|
||||||
@@ -27,8 +34,13 @@ bool ControlLayer::SwitchLayer(OpenEngine::KeyPressedEvent& event)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (event.GetKeyCode() == OE_KEY_2) {
|
} else if (event.GetKeyCode() == OE_KEY_2) {
|
||||||
|
OE_PROFILE_SCOPE("Press Key 2");
|
||||||
|
|
||||||
OE_DEBUG("Sandbox Layer");
|
OE_DEBUG("Sandbox Layer");
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Creating SB");
|
||||||
layer = OpenEngine::CreateRef<SandboxLayer>();
|
layer = OpenEngine::CreateRef<SandboxLayer>();
|
||||||
|
}
|
||||||
|
|
||||||
app.QueueLayerPush(layer);
|
app.QueueLayerPush(layer);
|
||||||
app.QueueLayerPop(active_layer);
|
app.QueueLayerPop(active_layer);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef OPEN_ENGINE_HPP
|
#ifndef OPEN_ENGINE_HPP
|
||||||
#define OPEN_ENGINE_HPP
|
#define OPEN_ENGINE_HPP
|
||||||
|
|
||||||
|
#include "open_engine/core.hpp"
|
||||||
#include "open_engine/application.hpp"
|
#include "open_engine/application.hpp"
|
||||||
#include "open_engine/logging.hpp"
|
#include "open_engine/logging.hpp"
|
||||||
#include "open_engine/events/key_event.hpp"
|
#include "open_engine/events/key_event.hpp"
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
#ifndef APPLICATION_HPP
|
#ifndef APPLICATION_HPP
|
||||||
#define APPLICATION_HPP
|
#define APPLICATION_HPP
|
||||||
|
|
||||||
#include "core.hpp"
|
#include "open_engine/core.hpp"
|
||||||
|
#include "open_engine/events/application_event.hpp"
|
||||||
#include "events/application_event.hpp"
|
#include "open_engine/imgui/imgui_layer.hpp"
|
||||||
#include "imgui/imgui_layer.hpp"
|
#include "open_engine/window/window.hpp"
|
||||||
#include "layer.hpp"
|
#include "open_engine/layer_stack.hpp"
|
||||||
#include "layer_stack.hpp"
|
#include "open_engine/layer.hpp"
|
||||||
#include "window/window.hpp"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OE_API Application
|
class Application
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Application();
|
Application();
|
||||||
@@ -21,20 +19,15 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
virtual void OnEvent(Event& event);
|
virtual void OnEvent(Event& event);
|
||||||
|
|
||||||
//void PushOverlay(Ref<Layer> overlay);
|
|
||||||
//void PopOverlay(Ref<Layer> overlay);
|
|
||||||
|
|
||||||
//void PushLayer(Ref<Layer> layer);
|
|
||||||
//void PopLayer();
|
|
||||||
void QueueLayerPush(Ref<Layer> layer);
|
void QueueLayerPush(Ref<Layer> layer);
|
||||||
void QueueLayerPop(Ref<Layer> layer);
|
void QueueLayerPop(Ref<Layer> layer);
|
||||||
void QueueOverlayPush(Ref<Layer> layer);
|
void QueueOverlayPush(Ref<Layer> layer);
|
||||||
void QueueOverlayPop(Ref<Layer> layer);
|
void QueueOverlayPop(Ref<Layer> layer);
|
||||||
|
|
||||||
inline static Application& Get() { return *instance; }
|
inline static Application& Get() { return *instance; };
|
||||||
|
|
||||||
inline Window& GetWindow() { return *window; }
|
inline Window& GetWindow() { return *window; };
|
||||||
inline void StopRunning() { running = false; }
|
inline void StopRunning() { running = false; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool OnWindowClose(WindowCloseEvent& event);
|
bool OnWindowClose(WindowCloseEvent& event);
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
#ifndef CORE_HPP
|
#ifndef CORE_HPP
|
||||||
#define CORE_HPP
|
#define CORE_HPP
|
||||||
|
|
||||||
|
#include "open_engine/instrumentor.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#ifdef __linux__
|
|
||||||
#ifdef OE_EXPORT
|
|
||||||
#define OE_API __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
#define OE_API
|
|
||||||
#endif
|
|
||||||
#elif defined(_WIN32) || defined(WIN32)
|
|
||||||
#error Windows is not yet supported
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef OE_ENABLE_ASSERTS
|
#ifdef OE_ENABLE_ASSERTS
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|||||||
74
open_engine/include/open_engine/core/time.hpp
Normal file → Executable file
74
open_engine/include/open_engine/core/time.hpp
Normal file → Executable file
@@ -1,13 +1,16 @@
|
|||||||
#ifndef TIME_HPP
|
#ifndef TIME_HPP
|
||||||
#define TIME_HPP
|
#define TIME_HPP
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
using highres_time_point = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
||||||
|
|
||||||
class Time
|
class Time
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Time(const Time&) = delete; // No copy constructor
|
Time(const Time&) = delete;
|
||||||
Time& operator=(const Time&) = delete;
|
Time& operator=(const Time&) = delete;
|
||||||
|
|
||||||
static void Update();
|
static void Update();
|
||||||
@@ -16,19 +19,76 @@ namespace OpenEngine {
|
|||||||
{
|
{
|
||||||
if (instance == nullptr)
|
if (instance == nullptr)
|
||||||
instance.reset(new Time);
|
instance.reset(new Time);
|
||||||
}
|
};
|
||||||
|
|
||||||
static double DeltaTime() {
|
static double DeltaTime() {
|
||||||
return instance->delta_time.count();
|
return instance->delta_time.count();
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
struct ProfilingResult
|
||||||
Time() {};
|
{
|
||||||
std::chrono::high_resolution_clock::time_point previous_frame;
|
double duration = 0;
|
||||||
static std::unique_ptr<Time> instance;
|
const char* name;
|
||||||
std::chrono::duration<double> delta_time;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* TODO: Consider:
|
||||||
|
*
|
||||||
|
* Timer::Start();
|
||||||
|
*
|
||||||
|
* Timer::SetMark("name");
|
||||||
|
* Timer::GetSinceMark("name");
|
||||||
|
* Timer::StopMark("name");
|
||||||
|
* Timer::GetMarkDuration("name");
|
||||||
|
*
|
||||||
|
* Timer::Stop();
|
||||||
|
*/
|
||||||
|
template<typename Fn>
|
||||||
|
class Timer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Timer(const char* name, Fn funct)
|
||||||
|
: name(name), func(funct)
|
||||||
|
{
|
||||||
|
start_timepoint = std::chrono::high_resolution_clock::now();
|
||||||
|
};
|
||||||
|
~Timer()
|
||||||
|
{
|
||||||
|
if (!stopped)
|
||||||
|
Stop();
|
||||||
|
};
|
||||||
|
|
||||||
|
void Stop()
|
||||||
|
{
|
||||||
|
auto end_timepoint = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
long long start = std::chrono::time_point_cast<std::chrono::microseconds>(start_timepoint).time_since_epoch().count();
|
||||||
|
long long end = std::chrono::time_point_cast<std::chrono::microseconds>(end_timepoint).time_since_epoch().count();
|
||||||
|
|
||||||
|
stopped = true;
|
||||||
|
|
||||||
|
ProfilingResult result = {0.001f * (end - start), name};
|
||||||
|
|
||||||
|
func(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<const char*, highres_time_point> time_points;
|
||||||
|
const char* name;
|
||||||
|
highres_time_point start_timepoint;
|
||||||
|
bool stopped = false;
|
||||||
|
Fn func;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
Time() {};
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::unique_ptr<Time> instance;
|
||||||
|
|
||||||
|
std::chrono::high_resolution_clock::time_point previous_frame;
|
||||||
|
std::chrono::duration<double> delta_time;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TIME_HPP
|
#endif // TIME_HPP
|
||||||
|
|||||||
14
open_engine/include/open_engine/entry_point.hpp
Normal file → Executable file
14
open_engine/include/open_engine/entry_point.hpp
Normal file → Executable file
@@ -1,18 +1,26 @@
|
|||||||
#ifndef ENTRY_POINT_HPP
|
#ifndef ENTRY_POINT_HPP
|
||||||
#define ENTRY_POINT_HPP
|
#define ENTRY_POINT_HPP
|
||||||
|
|
||||||
#include "application.hpp"
|
#include "open_engine/instrumentor.hpp"
|
||||||
|
#include "open_engine/application.hpp"
|
||||||
|
#include "open_engine/logging.hpp"
|
||||||
|
|
||||||
extern OpenEngine::Application* OpenEngine::CreateApplication();
|
extern OpenEngine::Application* OpenEngine::CreateApplication();
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_BEGIN_SESSION("Startup", "open_engine-startup.json");
|
||||||
OpenEngine::Logger::Init();
|
OpenEngine::Logger::Init();
|
||||||
|
|
||||||
auto app = OpenEngine::CreateApplication();
|
auto app = OpenEngine::CreateApplication();
|
||||||
app->Run();
|
OE_PROFILE_END_SESSION();
|
||||||
|
|
||||||
|
OE_PROFILE_BEGIN_SESSION("Runtime", "open_engine-runtime.json");
|
||||||
|
app->Run();
|
||||||
|
OE_PROFILE_END_SESSION();
|
||||||
|
|
||||||
|
OE_PROFILE_BEGIN_SESSION("Shutdown", "open_engine-shutdown.json");
|
||||||
delete app;
|
delete app;
|
||||||
|
OE_PROFILE_END_SESSION();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENTRY_POINT_HPP
|
#endif // ENTRY_POINT_HPP
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
#ifndef APPLICATION_EVENT_HPP
|
#ifndef APPLICATION_EVENT_HPP
|
||||||
#define APPLICATION_EVENT_HPP
|
#define APPLICATION_EVENT_HPP
|
||||||
|
|
||||||
#include "event.hpp"
|
#include "open_engine/events/event.hpp"
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OE_API WindowResizeEvent
|
class WindowResizeEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowResizeEvent(unsigned int width, unsigned int height)
|
WindowResizeEvent(unsigned int width, unsigned int height)
|
||||||
: width(width), height(height)
|
: width(width), height(height)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
inline unsigned int GetWidth() const { return width; }
|
inline unsigned int GetWidth() const { return width; };
|
||||||
inline unsigned int GetHeight() const { return height; }
|
inline unsigned int GetHeight() const { return height; };
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string ToString() const override;
|
||||||
|
|
||||||
@@ -25,11 +25,11 @@ namespace OpenEngine {
|
|||||||
unsigned int width, height;
|
unsigned int width, height;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API WindowCloseEvent
|
class WindowCloseEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowCloseEvent() {}
|
WindowCloseEvent() = default;
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string ToString() const override;
|
||||||
|
|
||||||
@@ -37,11 +37,11 @@ namespace OpenEngine {
|
|||||||
EVENT_CLASS_CATEGORY(EventCategoryApplication)
|
EVENT_CLASS_CATEGORY(EventCategoryApplication)
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API AppUpdateEvent
|
class AppUpdateEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AppUpdateEvent() {}
|
AppUpdateEvent() = default;
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string ToString() const override;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef EVENT_HPP
|
#ifndef EVENT_HPP
|
||||||
#define EVENT_HPP
|
#define EVENT_HPP
|
||||||
|
|
||||||
#include "../core.hpp"
|
#include "open_engine/core.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -31,17 +31,17 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
#define EVENT_CLASS_CATEGORY(category) virtual int GetCategoryFlags() const override { return category; }
|
#define EVENT_CLASS_CATEGORY(category) virtual int GetCategoryFlags() const override { return category; }
|
||||||
|
|
||||||
class OE_API Event
|
class Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual EventType GetEventType() const = 0;
|
virtual EventType GetEventType() const = 0;
|
||||||
virtual const char* GetName() const = 0;
|
virtual const char* GetName() const = 0;
|
||||||
virtual int GetCategoryFlags() const = 0;
|
virtual int GetCategoryFlags() const = 0;
|
||||||
virtual std::string ToString() const { return GetName(); }
|
virtual std::string ToString() const { return GetName(); };
|
||||||
|
|
||||||
inline bool IsInCategory(EventCategory category) {
|
inline bool IsInCategory(EventCategory category) {
|
||||||
return GetCategoryFlags() & category;
|
return GetCategoryFlags() & category;
|
||||||
}
|
};
|
||||||
|
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
};
|
};
|
||||||
@@ -52,7 +52,7 @@ namespace OpenEngine {
|
|||||||
EventDispatcher(Event& event)
|
EventDispatcher(Event& event)
|
||||||
: event(event)
|
: event(event)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
template<typename T, typename F>
|
template<typename T, typename F>
|
||||||
bool Dispatch(const F& func)
|
bool Dispatch(const F& func)
|
||||||
@@ -63,7 +63,7 @@ namespace OpenEngine {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Event& event;
|
Event& event;
|
||||||
@@ -72,7 +72,7 @@ namespace OpenEngine {
|
|||||||
inline std::ostream& operator<<(std::ostream& os, const Event& e)
|
inline std::ostream& operator<<(std::ostream& os, const Event& e)
|
||||||
{
|
{
|
||||||
return os << e.ToString();
|
return os << e.ToString();
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EVENT_HPP
|
#endif // EVENT_HPP
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef KEY_EVENT_HPP
|
#ifndef KEY_EVENT_HPP
|
||||||
#define KEY_EVENT_HPP
|
#define KEY_EVENT_HPP
|
||||||
|
|
||||||
#include "event.hpp"
|
#include "open_engine/events/event.hpp"
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OE_API KeyEvent
|
class KeyEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -18,21 +18,21 @@ namespace OpenEngine {
|
|||||||
KeyEvent(int keycode, int scancode, int mods)
|
KeyEvent(int keycode, int scancode, int mods)
|
||||||
: keycode(keycode), scancode(scancode), mods(mods)
|
: keycode(keycode), scancode(scancode), mods(mods)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
int keycode;
|
int keycode;
|
||||||
int scancode;
|
int scancode;
|
||||||
int mods;
|
int mods;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API KeyPressedEvent
|
class KeyPressedEvent
|
||||||
: public KeyEvent
|
: public KeyEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeyPressedEvent(int keycode, int scancode, int repeat_count, int mods)
|
KeyPressedEvent(int keycode, int scancode, int repeat_count, int mods)
|
||||||
: KeyEvent(keycode, scancode, mods), repeat_count(repeat_count)
|
: KeyEvent(keycode, scancode, mods), repeat_count(repeat_count)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
inline int GetRepeatCount() { return repeat_count; };
|
inline int GetRepeatCount() { return repeat_count; };
|
||||||
|
|
||||||
@@ -44,28 +44,28 @@ namespace OpenEngine {
|
|||||||
int repeat_count;
|
int repeat_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API KeyReleasedEvent
|
class KeyReleasedEvent
|
||||||
: public KeyEvent
|
: public KeyEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeyReleasedEvent(int keycode, int scancode, int mods)
|
KeyReleasedEvent(int keycode, int scancode, int mods)
|
||||||
: KeyEvent(keycode, scancode, mods)
|
: KeyEvent(keycode, scancode, mods)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string ToString() const override;
|
||||||
|
|
||||||
EVENT_CLASS_TYPE(KeyReleased)
|
EVENT_CLASS_TYPE(KeyReleased)
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API KeyTypedEvent
|
class KeyTypedEvent
|
||||||
: public KeyEvent
|
: public KeyEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeyTypedEvent(int keycode)
|
KeyTypedEvent(int keycode)
|
||||||
: KeyEvent(keycode, 0, 0)
|
: KeyEvent(keycode, 0, 0)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string ToString() const override;
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#ifndef MOUSE_EVENT_HPP
|
#ifndef MOUSE_EVENT_HPP
|
||||||
#define MOUSE_EVENT_HPP
|
#define MOUSE_EVENT_HPP
|
||||||
|
|
||||||
#include "event.hpp"
|
#include "open_engine/events/event.hpp"
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OE_API MouseMovedEvent
|
class MouseMovedEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseMovedEvent(float mouse_x, float mouse_y)
|
MouseMovedEvent(float mouse_x, float mouse_y)
|
||||||
: mouse_x(mouse_x), mouse_y(mouse_y)
|
: mouse_x(mouse_x), mouse_y(mouse_y)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
inline float GetX() const { return mouse_x; };
|
inline float GetX() const { return mouse_x; };
|
||||||
inline float GetY() const { return mouse_y; };
|
inline float GetY() const { return mouse_y; };
|
||||||
@@ -25,17 +25,17 @@ namespace OpenEngine {
|
|||||||
float mouse_x, mouse_y;
|
float mouse_x, mouse_y;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API MouseScrolledEvent
|
class MouseScrolledEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseScrolledEvent(float x_offset, float y_offset)
|
MouseScrolledEvent(float x_offset, float y_offset)
|
||||||
: x_offset(x_offset), y_offset(y_offset)
|
: x_offset(x_offset), y_offset(y_offset)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
inline float GetXOffset() const { return x_offset; }
|
inline float GetXOffset() const { return x_offset; };
|
||||||
inline float GetYOffset() const { return y_offset; }
|
inline float GetYOffset() const { return y_offset; };
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string ToString() const override;
|
||||||
|
|
||||||
@@ -46,11 +46,11 @@ namespace OpenEngine {
|
|||||||
float x_offset, y_offset;
|
float x_offset, y_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API MouseButtonEvent
|
class MouseButtonEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline int GetMouseButton() const { return button; }
|
inline int GetMouseButton() const { return button; };
|
||||||
|
|
||||||
EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput)
|
EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput)
|
||||||
|
|
||||||
@@ -58,31 +58,31 @@ namespace OpenEngine {
|
|||||||
MouseButtonEvent(int button)
|
MouseButtonEvent(int button)
|
||||||
: button(button)
|
: button(button)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
int button;
|
int button;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API MouseButtonPressedEvent
|
class MouseButtonPressedEvent
|
||||||
: public MouseButtonEvent
|
: public MouseButtonEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseButtonPressedEvent(int button)
|
MouseButtonPressedEvent(int button)
|
||||||
: MouseButtonEvent(button)
|
: MouseButtonEvent(button)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string ToString() const override;
|
||||||
|
|
||||||
EVENT_CLASS_TYPE(MouseButtonPressed)
|
EVENT_CLASS_TYPE(MouseButtonPressed)
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API MouseButtonReleasedEvent
|
class MouseButtonReleasedEvent
|
||||||
: public MouseButtonEvent
|
: public MouseButtonEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseButtonReleasedEvent(int button)
|
MouseButtonReleasedEvent(int button)
|
||||||
: MouseButtonEvent(button) {}
|
: MouseButtonEvent(button) {};
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string ToString() const override;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#ifndef IMGUI_LAYER_HPP
|
#ifndef IMGUI_LAYER_HPP
|
||||||
#define IMGUI_LAYER_HPP
|
#define IMGUI_LAYER_HPP
|
||||||
|
|
||||||
#include "../core.hpp"
|
#include "open_engine/layer.hpp"
|
||||||
#include "../layer.hpp"
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OE_API ImGuiLayer : public Layer
|
class ImGuiLayer : public Layer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ImGuiLayer();
|
ImGuiLayer();
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
#ifndef INPUT_HPP
|
#ifndef INPUT_HPP
|
||||||
#define INPUT_HPP
|
#define INPUT_HPP
|
||||||
|
|
||||||
#include "../core.hpp"
|
#include "open_engine/core.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#define MAX_AXIS 10
|
#define MAX_AXIS 10
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OE_API Input
|
class Input
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Input() = default;
|
virtual ~Input() = default;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef LINUX_INPUT_HPP
|
#ifndef LINUX_INPUT_HPP
|
||||||
#define LINUX_INPUT_HPP
|
#define LINUX_INPUT_HPP
|
||||||
|
|
||||||
#include "input_system.hpp"
|
#include "open_engine/input/input_system.hpp"
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class LinuxInput : public Input
|
class LinuxInput : public Input
|
||||||
|
|||||||
138
open_engine/include/open_engine/instrumentor.hpp
Normal file
138
open_engine/include/open_engine/instrumentor.hpp
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
#ifndef INSTRUMENTOR_HPP
|
||||||
|
#define INSTRUMENTOR_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
namespace OpenEngine {
|
||||||
|
struct ProfileResult
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
long long start, end;
|
||||||
|
uint32_t thread_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct InstrumentationSession
|
||||||
|
{
|
||||||
|
const char* name;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Instrumentor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~Instrumentor()
|
||||||
|
{
|
||||||
|
EndSession();
|
||||||
|
};
|
||||||
|
|
||||||
|
void BeginSession(const char* name, const std::string& filepath = "results.json")
|
||||||
|
{
|
||||||
|
output_stream.open(filepath);
|
||||||
|
WriteHeader();
|
||||||
|
};
|
||||||
|
|
||||||
|
void EndSession()
|
||||||
|
{
|
||||||
|
WriteFooter();
|
||||||
|
output_stream.flush();
|
||||||
|
output_stream.close();
|
||||||
|
profile_count = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
void WriteProfile(const ProfileResult& result)
|
||||||
|
{
|
||||||
|
if (profile_count++ > 0)
|
||||||
|
output_stream << ",";
|
||||||
|
|
||||||
|
std::string name = result.name;
|
||||||
|
std::replace(name.begin(), name.end(), '"', '\'');
|
||||||
|
|
||||||
|
output_stream << "{";
|
||||||
|
output_stream << "\"cat\":\"function\",";
|
||||||
|
output_stream << "\"dur\":" << (result.end - result.start) << ',';
|
||||||
|
output_stream << "\"name\":\"" << name << "\",";
|
||||||
|
output_stream << "\"ph\":\"X\",";
|
||||||
|
output_stream << "\"pid\":0,";
|
||||||
|
output_stream << "\"tid\":" << result.thread_id << ",";
|
||||||
|
output_stream << "\"ts\":" << result.start;
|
||||||
|
output_stream << "}";
|
||||||
|
};
|
||||||
|
|
||||||
|
void WriteHeader()
|
||||||
|
{
|
||||||
|
output_stream << "{\"otherData\": {},\"traceEvents\":[";
|
||||||
|
};
|
||||||
|
|
||||||
|
void WriteFooter()
|
||||||
|
{
|
||||||
|
output_stream << "]}";
|
||||||
|
};
|
||||||
|
|
||||||
|
static Instrumentor& Get()
|
||||||
|
{
|
||||||
|
static Instrumentor instance;
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
Instrumentor()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::ofstream output_stream;
|
||||||
|
int profile_count = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class InstrumentationTimer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InstrumentationTimer(const char* name)
|
||||||
|
: name(name), stopped(false)
|
||||||
|
{
|
||||||
|
start_timepoint = std::chrono::high_resolution_clock::now();
|
||||||
|
};
|
||||||
|
|
||||||
|
~InstrumentationTimer()
|
||||||
|
{
|
||||||
|
if (!stopped)
|
||||||
|
Stop();
|
||||||
|
};
|
||||||
|
|
||||||
|
void Stop()
|
||||||
|
{
|
||||||
|
auto end_timepoint = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
long long start = std::chrono::time_point_cast<std::chrono::microseconds>(start_timepoint).time_since_epoch().count();
|
||||||
|
long long end = std::chrono::time_point_cast<std::chrono::microseconds>(end_timepoint).time_since_epoch().count();
|
||||||
|
|
||||||
|
uint32_t thread_id = std::hash<std::thread::id>{}(std::this_thread::get_id());
|
||||||
|
Instrumentor::Get().WriteProfile({ name, start, end, thread_id });
|
||||||
|
|
||||||
|
stopped = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* name;
|
||||||
|
std::chrono::time_point<std::chrono::high_resolution_clock> start_timepoint;
|
||||||
|
bool stopped;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#define OE_PROFILE 1
|
||||||
|
#if OE_PROFILE
|
||||||
|
#define OE_PROFILE_BEGIN_SESSION(name, filepath) ::OpenEngine::Instrumentor::Get().BeginSession(name, filepath)
|
||||||
|
#define OE_PROFILE_END_SESSION() ::OpenEngine::Instrumentor::Get().EndSession()
|
||||||
|
#define OE_PROFILE_SCOPE(name) ::OpenEngine::InstrumentationTimer timer##__LINE__(name);
|
||||||
|
#define OE_PROFILE_FUNCTION() OE_PROFILE_SCOPE(__PRETTY_FUNCTION__)
|
||||||
|
#else
|
||||||
|
#define OE_PROFILE_BEGIN_SESSION(name, filepath)
|
||||||
|
#define OE_PROFILE_END_SESSION()
|
||||||
|
#define OE_PROFILE_SCOPE(name)
|
||||||
|
#define OE_PROFILE_FUNCTION()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // INSTRUMENTOR_HPP
|
||||||
@@ -2,23 +2,24 @@
|
|||||||
#define LAYER_HPP
|
#define LAYER_HPP
|
||||||
|
|
||||||
#include "events/event.hpp"
|
#include "events/event.hpp"
|
||||||
#include "core.hpp"
|
|
||||||
#include "open_engine/logging.hpp"
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OE_API Layer
|
class Layer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Layer(const std::string& name = "layer");
|
Layer(const std::string& name = "layer")
|
||||||
|
: debug_name(name)
|
||||||
|
{
|
||||||
|
};
|
||||||
virtual ~Layer() = default;
|
virtual ~Layer() = default;
|
||||||
|
|
||||||
virtual void OnAttach() {}
|
virtual void OnAttach() {};
|
||||||
virtual void OnDetach() {}
|
virtual void OnDetach() {};
|
||||||
virtual void OnUpdate() {}
|
virtual void OnUpdate() {};
|
||||||
virtual void OnImGuiRender() {}
|
virtual void OnImGuiRender() {};
|
||||||
virtual void OnEvent(Event& event) {}
|
virtual void OnEvent(Event& event) {};
|
||||||
|
|
||||||
inline const std::string& GetName() const { return debug_name; }
|
inline const std::string& GetName() const { return debug_name; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string debug_name = "";
|
std::string debug_name = "";
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#ifndef LAYER_STACK_HPP
|
#ifndef LAYER_STACK_HPP
|
||||||
#define LAYER_STACK_HPP
|
#define LAYER_STACK_HPP
|
||||||
|
|
||||||
#include "core.hpp"
|
#include "open_engine/core.hpp"
|
||||||
#include "layer.hpp"
|
#include "open_engine/layer.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OE_API LayerStack
|
class LayerStack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LayerStack();
|
LayerStack() = default;
|
||||||
~LayerStack();
|
~LayerStack();
|
||||||
|
|
||||||
void QueueLayerPush(Ref<Layer> layer);
|
void QueueLayerPush(Ref<Layer> layer);
|
||||||
@@ -19,8 +19,8 @@ namespace OpenEngine {
|
|||||||
void QueueOverlayPop(Ref<Layer> layer);
|
void QueueOverlayPop(Ref<Layer> layer);
|
||||||
void UpdateLayers();
|
void UpdateLayers();
|
||||||
|
|
||||||
std::vector<Ref<Layer>>::iterator begin() { return layers.begin(); }
|
std::vector<Ref<Layer>>::iterator begin() { return layers.begin(); };
|
||||||
std::vector<Ref<Layer>>::iterator end() { return layers.end(); }
|
std::vector<Ref<Layer>>::iterator end() { return layers.end(); };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Ref<Layer>> layers;
|
std::vector<Ref<Layer>> layers;
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
#ifndef LOGGING_HPP
|
#ifndef LOGGING_HPP
|
||||||
#define LOGGING_HPP
|
#define LOGGING_HPP
|
||||||
|
|
||||||
#include "core.hpp"
|
#include "open_engine/core.hpp"
|
||||||
|
|
||||||
#include <spdlog/logger.h>
|
#include <spdlog/logger.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace OE_API OpenEngine {
|
namespace OpenEngine {
|
||||||
spdlog::level::level_enum stringToLogLevel(std::string level_str);
|
spdlog::level::level_enum stringToLogLevel(std::string level_str);
|
||||||
int setupMultisinkLogger(const std::string &file_path);
|
int setupMultisinkLogger(const std::string &file_path);
|
||||||
|
|
||||||
@@ -18,11 +16,12 @@ namespace OE_API OpenEngine {
|
|||||||
public:
|
public:
|
||||||
static void Init();
|
static void Init();
|
||||||
|
|
||||||
inline static std::shared_ptr<spdlog::logger>& GetCoreLogger() { return core_logger; }
|
inline static Ref<spdlog::logger>& GetCoreLogger() { return core_logger; };
|
||||||
inline static std::shared_ptr<spdlog::logger>& GetClientLogger() { return client_logger; }
|
inline static Ref<spdlog::logger>& GetClientLogger() { return client_logger; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::shared_ptr<spdlog::logger> core_logger;
|
static Ref<spdlog::logger> core_logger;
|
||||||
static std::shared_ptr<spdlog::logger> client_logger;
|
static Ref<spdlog::logger> client_logger;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
#define OPENGL_BUFFER_HPP
|
#define OPENGL_BUFFER_HPP
|
||||||
|
|
||||||
#include "renderer/buffer.hpp"
|
#include "renderer/buffer.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OpenGLVertexBuffer : public VertexBuffer
|
class OpenGLVertexBuffer : public VertexBuffer
|
||||||
{
|
{
|
||||||
@@ -13,8 +15,8 @@ namespace OpenEngine {
|
|||||||
virtual void Bind() const override;
|
virtual void Bind() const override;
|
||||||
virtual void UnBind() const override;
|
virtual void UnBind() const override;
|
||||||
|
|
||||||
virtual const BufferLayout& GetLayout() const override { return layout; }
|
virtual const BufferLayout& GetLayout() const override { return layout; };
|
||||||
virtual void SetLayout(const BufferLayout& layout) override { this->layout = layout; }
|
virtual void SetLayout(const BufferLayout& layout) override { this->layout = layout; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BufferLayout layout;
|
BufferLayout layout;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef OPENGL_CONTEXT_HPP
|
#ifndef OPENGL_CONTEXT_HPP
|
||||||
#define OPENGL_CONTEXT_HPP
|
#define OPENGL_CONTEXT_HPP
|
||||||
|
|
||||||
#include "renderer/graphics_context.hpp"
|
#include "open_engine/renderer/graphics_context.hpp"
|
||||||
|
|
||||||
struct GLFWwindow;
|
struct GLFWwindow;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef OPENGL_RENDERER_API_HPP
|
#ifndef OPENGL_RENDERER_API_HPP
|
||||||
#define OPENGL_RENDERER_API_HPP
|
#define OPENGL_RENDERER_API_HPP
|
||||||
|
|
||||||
#include "../renderer/renderer_api.hpp"
|
#include "open_engine/renderer/renderer_api.hpp"
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OpenGLRendererAPI : public RendererAPI
|
class OpenGLRendererAPI : public RendererAPI
|
||||||
@@ -14,7 +14,7 @@ namespace OpenEngine {
|
|||||||
virtual void SetClearColor(const glm::vec4& color) override;
|
virtual void SetClearColor(const glm::vec4& color) override;
|
||||||
virtual void Clear() override;
|
virtual void Clear() override;
|
||||||
|
|
||||||
virtual void DrawIndexed(const std::shared_ptr<VertexArray>& vertex_array) override;
|
virtual void DrawIndexed(const Ref<VertexArray>& vertex_array) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
#ifndef OPENGL_SHADER_HPP
|
#ifndef OPENGL_SHADER_HPP
|
||||||
#define OPENGL_SHADER_HPP
|
#define OPENGL_SHADER_HPP
|
||||||
|
|
||||||
#include "../renderer/shader.hpp"
|
#include "open_engine/renderer/shader.hpp"
|
||||||
#include <sys/types.h>
|
|
||||||
#include <string>
|
|
||||||
#include <glad/glad.h>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <glad/glad.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OpenGLShader : public Shader
|
class OpenGLShader : public Shader
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#ifndef OPENGL_TEXTURE_HPP
|
#ifndef OPENGL_TEXTURE_HPP
|
||||||
#define OPENGL_TEXTURE_HPP
|
#define OPENGL_TEXTURE_HPP
|
||||||
|
|
||||||
|
#include "open_engine/renderer/texture.hpp"
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <renderer/texture.hpp>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OpenGLTexture2D : public Texture2D
|
class OpenGLTexture2D : public Texture2D
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef OPENGL_VERTEX_ARRAY_HPP
|
#ifndef OPENGL_VERTEX_ARRAY_HPP
|
||||||
#define OPENGL_VERTEX_ARRAY_HPP
|
#define OPENGL_VERTEX_ARRAY_HPP
|
||||||
|
|
||||||
#include "renderer/vertex_array.hpp"
|
#include "open_engine/renderer/vertex_array.hpp"
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OpenGLVertexArray : public VertexArray
|
class OpenGLVertexArray : public VertexArray
|
||||||
@@ -13,19 +13,18 @@ namespace OpenEngine {
|
|||||||
virtual void Bind() const override;
|
virtual void Bind() const override;
|
||||||
virtual void UnBind() const override;
|
virtual void UnBind() const override;
|
||||||
|
|
||||||
virtual void AddVertexBuffer(const std::shared_ptr<VertexBuffer>& vertex_buffer) override;
|
virtual void AddVertexBuffer(const Ref<VertexBuffer>& vertex_buffer) override;
|
||||||
virtual void SetIndexBuffer(const std::shared_ptr<IndexBuffer>& index_buffer) override;
|
virtual void SetIndexBuffer(const Ref<IndexBuffer>& index_buffer) override;
|
||||||
|
|
||||||
virtual const std::vector<std::shared_ptr<VertexBuffer>>& GetVertexBuffers() const override { return vertex_buffers; }
|
virtual const std::vector<Ref<VertexBuffer>>& GetVertexBuffers() const override { return vertex_buffers; };
|
||||||
virtual const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const override { return index_buffer; }
|
virtual const Ref<IndexBuffer>& GetIndexBuffer() const override { return index_buffer; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
std::vector<std::shared_ptr<VertexBuffer>> vertex_buffers;
|
std::vector<Ref<VertexBuffer>> vertex_buffers;
|
||||||
std::shared_ptr<IndexBuffer> index_buffer;
|
Ref<IndexBuffer> index_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // OPENGL_VERTEX_ARRAY_HPP
|
#endif // OPENGL_VERTEX_ARRAY_HPP
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef ORTHOGRAPHIC_CAMERA_CONTROLLER_HPP
|
#ifndef ORTHOGRAPHIC_CAMERA_CONTROLLER_HPP
|
||||||
#define ORTHOGRAPHIC_CAMERA_CONTROLLER_HPP
|
#define ORTHOGRAPHIC_CAMERA_CONTROLLER_HPP
|
||||||
|
|
||||||
|
#include "open_engine/orthographic_camera.hpp"
|
||||||
#include "open_engine/events/application_event.hpp"
|
#include "open_engine/events/application_event.hpp"
|
||||||
#include "open_engine/events/mouse_event.hpp"
|
#include "open_engine/events/mouse_event.hpp"
|
||||||
#include "open_engine/events/event.hpp"
|
#include "open_engine/events/event.hpp"
|
||||||
#include "open_engine/orthographic_camera.hpp"
|
|
||||||
|
|
||||||
#include <glm/fwd.hpp>
|
#include <glm/fwd.hpp>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef PCH_HPP
|
#ifndef PCH_HPP
|
||||||
#define PCH_HPP
|
#define PCH_HPP
|
||||||
|
|
||||||
#include "logging.hpp"
|
#include "open_engine/logging.hpp"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace OpenEngine {
|
|||||||
BufferLayoutElement(ShaderDataType type, const std::string& name, bool normalized = false)
|
BufferLayoutElement(ShaderDataType type, const std::string& name, bool normalized = false)
|
||||||
: name(name), type(type), size(shaderDataTypeSize(type)), offset(0), normalized(normalized)
|
: name(name), type(type), size(shaderDataTypeSize(type)), offset(0), normalized(normalized)
|
||||||
{
|
{
|
||||||
}
|
};
|
||||||
|
|
||||||
uint32_t GetComponentCount() const;
|
uint32_t GetComponentCount() const;
|
||||||
};
|
};
|
||||||
@@ -39,15 +39,15 @@ namespace OpenEngine {
|
|||||||
: elements(elements)
|
: elements(elements)
|
||||||
{
|
{
|
||||||
CalculateOffsetsAndStride();
|
CalculateOffsetsAndStride();
|
||||||
}
|
};
|
||||||
|
|
||||||
inline uint32_t GetStride() const { return stride; }
|
inline uint32_t GetStride() const { return stride; };
|
||||||
inline const std::vector<BufferLayoutElement>& GetElements() const { return elements; }
|
inline const std::vector<BufferLayoutElement>& GetElements() const { return elements; };
|
||||||
|
|
||||||
std::vector<BufferLayoutElement>::iterator begin() { return elements.begin(); }
|
std::vector<BufferLayoutElement>::iterator begin() { return elements.begin(); };
|
||||||
std::vector<BufferLayoutElement>::iterator end() { return elements.end(); }
|
std::vector<BufferLayoutElement>::iterator end() { return elements.end(); };
|
||||||
std::vector<BufferLayoutElement>::const_iterator begin() const { return elements.begin(); }
|
std::vector<BufferLayoutElement>::const_iterator begin() const { return elements.begin(); };
|
||||||
std::vector<BufferLayoutElement>::const_iterator end() const { return elements.end(); }
|
std::vector<BufferLayoutElement>::const_iterator end() const { return elements.end(); };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CalculateOffsetsAndStride();
|
void CalculateOffsetsAndStride();
|
||||||
@@ -67,7 +67,7 @@ namespace OpenEngine {
|
|||||||
virtual const BufferLayout& GetLayout() const = 0;
|
virtual const BufferLayout& GetLayout() const = 0;
|
||||||
virtual void SetLayout(const BufferLayout& layout) = 0;
|
virtual void SetLayout(const BufferLayout& layout) = 0;
|
||||||
|
|
||||||
static VertexBuffer* Create(float* vertices, uint32_t size);
|
static Ref<VertexBuffer> Create(float* vertices, uint32_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
class IndexBuffer
|
class IndexBuffer
|
||||||
@@ -80,7 +80,7 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
virtual uint32_t GetCount() const = 0;
|
virtual uint32_t GetCount() const = 0;
|
||||||
|
|
||||||
static IndexBuffer* Create(uint32_t* indices, uint32_t size);
|
static Ref<IndexBuffer> Create(uint32_t* indices, uint32_t size);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#ifndef RENDER_COMMAND_HPP
|
#ifndef RENDER_COMMAND_HPP
|
||||||
#define RENDER_COMMAND_HPP
|
#define RENDER_COMMAND_HPP
|
||||||
|
|
||||||
#include "../renderer/renderer_api.hpp"
|
|
||||||
#include "../opengl/opengl_renderer_api.hpp"
|
|
||||||
#include "open_engine/core.hpp"
|
#include "open_engine/core.hpp"
|
||||||
|
#include "open_engine/renderer/renderer_api.hpp"
|
||||||
|
#include "open_engine/opengl/opengl_renderer_api.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
@@ -12,28 +13,34 @@ namespace OpenEngine {
|
|||||||
public:
|
public:
|
||||||
inline static void Init()
|
inline static void Init()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
api->Init();
|
api->Init();
|
||||||
}
|
};
|
||||||
|
|
||||||
inline static void SetClearColor(const glm::vec4& color)
|
inline static void SetClearColor(const glm::vec4& color)
|
||||||
{
|
{
|
||||||
api->SetClearColor(color);
|
api->SetClearColor(color);
|
||||||
}
|
};
|
||||||
|
|
||||||
inline static void Clear()
|
inline static void Clear()
|
||||||
{
|
{
|
||||||
api->Clear();
|
api->Clear();
|
||||||
}
|
};
|
||||||
|
|
||||||
inline static void DrawIndexed(const std::shared_ptr<VertexArray>& vertex_array)
|
inline static void DrawIndexed(const Ref<VertexArray>& vertex_array)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
api->DrawIndexed(vertex_array);
|
api->DrawIndexed(vertex_array);
|
||||||
}
|
};
|
||||||
|
|
||||||
inline static void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
|
inline static void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
api->SetViewport(x, y, width, height);
|
api->SetViewport(x, y, width, height);
|
||||||
}
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline Scope<RendererAPI> api = CreateScope<OpenGLRendererAPI>();
|
static inline Scope<RendererAPI> api = CreateScope<OpenGLRendererAPI>();
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#ifndef RENDERER_HPP
|
#ifndef RENDERER_HPP
|
||||||
#define RENDERER_HPP
|
#define RENDERER_HPP
|
||||||
|
|
||||||
|
#include "open_engine/core.hpp"
|
||||||
#include "open_engine/renderer/renderer_api.hpp"
|
#include "open_engine/renderer/renderer_api.hpp"
|
||||||
#include "open_engine/renderer/vertex_array.hpp"
|
#include "open_engine/renderer/vertex_array.hpp"
|
||||||
#include "open_engine/orthographic_camera.hpp"
|
#include "open_engine/orthographic_camera.hpp"
|
||||||
#include "open_engine/core.hpp"
|
#include "open_engine/renderer/shader.hpp"
|
||||||
#include <open_engine/renderer/shader.hpp>
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -15,6 +15,7 @@ namespace OpenEngine {
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Init();
|
static void Init();
|
||||||
|
static void ShutDown();
|
||||||
|
|
||||||
static void OnWindowResize(uint32_t width, uint32_t height);
|
static void OnWindowResize(uint32_t width, uint32_t height);
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ namespace OpenEngine {
|
|||||||
const Ref<VertexArray>& vertex_array,
|
const Ref<VertexArray>& vertex_array,
|
||||||
const glm::mat4& transform = glm::mat4(1.0f));
|
const glm::mat4& transform = glm::mat4(1.0f));
|
||||||
|
|
||||||
inline static RendererAPI::API GetApi() { return RendererAPI::GetAPI(); };
|
inline static RendererAPI::API GetAPI() { return RendererAPI::GetAPI(); };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct SceneData
|
struct SceneData
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#ifndef RENDERER_API_HPP
|
#ifndef RENDERER_API_HPP
|
||||||
#define RENDERER_API_HPP
|
#define RENDERER_API_HPP
|
||||||
|
|
||||||
#include "../renderer/vertex_array.hpp"
|
#include "open_engine/renderer/vertex_array.hpp"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class RendererAPI
|
class RendererAPI
|
||||||
@@ -23,7 +22,7 @@ namespace OpenEngine {
|
|||||||
virtual void SetClearColor(const glm::vec4& color) = 0;
|
virtual void SetClearColor(const glm::vec4& color) = 0;
|
||||||
virtual void Clear() = 0;
|
virtual void Clear() = 0;
|
||||||
|
|
||||||
virtual void DrawIndexed(const std::shared_ptr<VertexArray>& vertex_array) = 0;
|
virtual void DrawIndexed(const Ref<VertexArray>& vertex_array) = 0;
|
||||||
|
|
||||||
static inline API GetAPI() { return api; };
|
static inline API GetAPI() { return api; };
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#ifndef SHADER_HPP
|
#ifndef SHADER_HPP
|
||||||
#define SHADER_HPP
|
#define SHADER_HPP
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class Shader
|
class Shader
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define TEXTURE_HPP
|
#define TEXTURE_HPP
|
||||||
|
|
||||||
#include "open_engine/core.hpp"
|
#include "open_engine/core.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef VERTEX_ARRAY_HPP
|
#ifndef VERTEX_ARRAY_HPP
|
||||||
#define VERTEX_ARRAY_HPP
|
#define VERTEX_ARRAY_HPP
|
||||||
|
|
||||||
#include "open_engine/core.hpp"
|
|
||||||
#include "open_engine/renderer/buffer.hpp"
|
#include "open_engine/renderer/buffer.hpp"
|
||||||
|
#include "open_engine/core.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <vector>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class VertexArray
|
class VertexArray
|
||||||
@@ -15,11 +15,11 @@ namespace OpenEngine {
|
|||||||
virtual void Bind() const = 0;
|
virtual void Bind() const = 0;
|
||||||
virtual void UnBind() const = 0;
|
virtual void UnBind() const = 0;
|
||||||
|
|
||||||
virtual void AddVertexBuffer(const std::shared_ptr<VertexBuffer>& vertex_buffer) = 0;
|
virtual void AddVertexBuffer(const Ref<VertexBuffer>& vertex_buffer) = 0;
|
||||||
virtual void SetIndexBuffer(const std::shared_ptr<IndexBuffer>& index_buffer) = 0;
|
virtual void SetIndexBuffer(const Ref<IndexBuffer>& index_buffer) = 0;
|
||||||
|
|
||||||
virtual const std::vector<std::shared_ptr<VertexBuffer>>& GetVertexBuffers() const = 0;
|
virtual const std::vector<Ref<VertexBuffer>>& GetVertexBuffers() const = 0;
|
||||||
virtual const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const = 0;
|
virtual const Ref<IndexBuffer>& GetIndexBuffer() const = 0;
|
||||||
|
|
||||||
static Ref<VertexArray> Create();
|
static Ref<VertexArray> Create();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#ifndef LINUX_WINDOW_HPP
|
#ifndef LINUX_WINDOW_HPP
|
||||||
#define LINUX_WINDOW_HPP
|
#define LINUX_WINDOW_HPP
|
||||||
|
|
||||||
#include <core.hpp>
|
|
||||||
|
|
||||||
#include <window/window.hpp>
|
#include "open_engine/core.hpp"
|
||||||
#include <renderer/graphics_context.hpp>
|
#include "renderer/graphics_context.hpp"
|
||||||
|
#include "window/window.hpp"
|
||||||
|
|
||||||
#define GLFW_INCLUDE_NONE
|
#define GLFW_INCLUDE_NONE
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
class OE_API LinuxWindow
|
class LinuxWindow
|
||||||
: public Window
|
: public Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -19,11 +19,11 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void OnUpdate() override;
|
void OnUpdate() override;
|
||||||
|
|
||||||
inline unsigned int GetWidth() const override { return data.width; }
|
inline unsigned int GetWidth() const override { return data.width; };
|
||||||
inline unsigned int GetHeight() const override { return data.height; }
|
inline unsigned int GetHeight() const override { return data.height; };
|
||||||
|
|
||||||
inline void SetEventCallback(const EventCallbackFunction& callback) override
|
inline void SetEventCallback(const EventCallbackFunction& callback) override
|
||||||
{ data.event_callback = callback; }
|
{ data.event_callback = callback; };
|
||||||
void SetVSync(bool enabled) override;
|
void SetVSync(bool enabled) override;
|
||||||
bool IsVSync() const override;
|
bool IsVSync() const override;
|
||||||
|
|
||||||
@@ -33,6 +33,7 @@ namespace OpenEngine {
|
|||||||
virtual void Init(const WindowProps& props);
|
virtual void Init(const WindowProps& props);
|
||||||
virtual void Shutdown();
|
virtual void Shutdown();
|
||||||
|
|
||||||
|
int window_count;
|
||||||
WindowData data;
|
WindowData data;
|
||||||
GLFWwindow* gl_window;
|
GLFWwindow* gl_window;
|
||||||
Scope<GraphicsContext> context;
|
Scope<GraphicsContext> context;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#ifndef WINDOW_HPP
|
#ifndef WINDOW_HPP
|
||||||
#define WINDOW_HPP
|
#define WINDOW_HPP
|
||||||
|
|
||||||
#include "../core.hpp"
|
#include "open_engine/events/event.hpp"
|
||||||
#include "../events/event.hpp"
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
@@ -22,7 +21,7 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class OE_API Window
|
class Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using EventCallbackFunction = std::function<void(Event&)>;
|
using EventCallbackFunction = std::function<void(Event&)>;
|
||||||
@@ -49,7 +48,7 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
virtual void* GetNativeWindow() const = 0;
|
virtual void* GetNativeWindow() const = 0;
|
||||||
|
|
||||||
static std::unique_ptr<Window> Create(const WindowProps& props = WindowProps());
|
static Scope<Window> Create(const WindowProps& props = WindowProps());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,27 +3,32 @@
|
|||||||
#include <application.hpp>
|
#include <application.hpp>
|
||||||
|
|
||||||
#include <core.hpp>
|
#include <core.hpp>
|
||||||
#include <core/time.hpp>
|
|
||||||
#include <events/application_event.hpp>
|
#include <events/application_event.hpp>
|
||||||
#include <renderer/renderer2d.hpp>
|
#include <renderer/renderer2d.hpp>
|
||||||
#include <renderer/renderer.hpp>
|
|
||||||
#include <input/input_system.hpp>
|
#include <input/input_system.hpp>
|
||||||
#include <imgui/imgui_layer.hpp>
|
#include <imgui/imgui_layer.hpp>
|
||||||
|
#include <renderer/renderer.hpp>
|
||||||
|
#include <instrumentor.hpp>
|
||||||
|
#include <core/time.hpp>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
Application::Application()
|
Application::Application()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
OE_CORE_ASSERT(!instance, "Application already exists!");
|
OE_CORE_ASSERT(!instance, "Application already exists!");
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
window = Window::Create();
|
window = Window::Create();
|
||||||
window->SetEventCallback(BIND_EVENT_FN(Application::OnEvent));
|
window->SetEventCallback(BIND_EVENT_FN(Application::OnEvent));
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Initializing Renderers");
|
||||||
Renderer::Init();
|
Renderer::Init();
|
||||||
Renderer2D::Init();
|
Renderer2D::Init();
|
||||||
|
}
|
||||||
|
|
||||||
imgui_layer = std::make_shared<ImGuiLayer>();
|
imgui_layer = std::make_shared<ImGuiLayer>();
|
||||||
QueueOverlayPush(imgui_layer);
|
QueueOverlayPush(imgui_layer);
|
||||||
@@ -33,24 +38,34 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
{
|
{
|
||||||
Renderer2D::Shutdown();
|
Renderer::ShutDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::Run()
|
void Application::Run()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION()
|
||||||
|
|
||||||
while(running) {
|
while(running) {
|
||||||
|
OE_PROFILE_SCOPE("Frame");
|
||||||
|
|
||||||
Time::Update();
|
Time::Update();
|
||||||
layer_stack.UpdateLayers();
|
layer_stack.UpdateLayers();
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Updating all Layers");
|
||||||
for (auto layer : layer_stack)
|
for (auto layer : layer_stack)
|
||||||
layer->OnUpdate();
|
layer->OnUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Rendering ImGui");
|
||||||
imgui_layer->Begin();
|
imgui_layer->Begin();
|
||||||
|
|
||||||
for (auto layer : layer_stack)
|
for (auto layer : layer_stack)
|
||||||
layer->OnImGuiRender();
|
layer->OnImGuiRender();
|
||||||
|
|
||||||
imgui_layer->End();
|
imgui_layer->End();
|
||||||
|
}
|
||||||
|
|
||||||
window->OnUpdate();
|
window->OnUpdate();
|
||||||
}
|
}
|
||||||
@@ -58,16 +73,21 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void Application::OnEvent(Event& event)
|
void Application::OnEvent(Event& event)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
EventDispatcher dispatcher(event);
|
EventDispatcher dispatcher(event);
|
||||||
dispatcher.Dispatch<WindowCloseEvent>(BIND_EVENT_FN(Application::OnWindowClose));
|
dispatcher.Dispatch<WindowCloseEvent>(BIND_EVENT_FN(Application::OnWindowClose));
|
||||||
dispatcher.Dispatch<WindowResizeEvent>(BIND_EVENT_FN(Application::OnWindowResize));
|
dispatcher.Dispatch<WindowResizeEvent>(BIND_EVENT_FN(Application::OnWindowResize));
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Layers OnEvent");
|
||||||
for (auto it = layer_stack.end(); it != layer_stack.begin();) {
|
for (auto it = layer_stack.end(); it != layer_stack.begin();) {
|
||||||
(*--it)->OnEvent(event);
|
(*--it)->OnEvent(event);
|
||||||
if (event.handled)
|
if (event.handled)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Application::OnWindowClose(WindowCloseEvent& event)
|
bool Application::OnWindowClose(WindowCloseEvent& event)
|
||||||
{
|
{
|
||||||
@@ -78,6 +98,7 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
bool Application::OnWindowResize(WindowResizeEvent& event)
|
bool Application::OnWindowResize(WindowResizeEvent& event)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
Renderer::OnWindowResize(event.GetWidth(), event.GetHeight());
|
Renderer::OnWindowResize(event.GetWidth(), event.GetHeight());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <core/time.hpp>
|
#include <core/time.hpp>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
std::unique_ptr<Time> Time::instance = nullptr;
|
std::unique_ptr<Time> Time::instance = nullptr;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include <events/application_event.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
|
#include "open_engine/events/application_event.hpp"
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
std::string WindowResizeEvent::ToString() const
|
std::string WindowResizeEvent::ToString() const
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <events/key_event.hpp>
|
#include <events/key_event.hpp>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include <events/mouse_event.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
|
#include "open_engine/events/mouse_event.hpp"
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
std::string MouseMovedEvent::ToString() const
|
std::string MouseMovedEvent::ToString() const
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
|
#include "instrumentor.hpp"
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
#include "application.hpp"
|
|
||||||
#include "layer.hpp"
|
|
||||||
|
|
||||||
#include <imgui/imgui_layer.hpp>
|
#include <imgui/imgui_layer.hpp>
|
||||||
|
|
||||||
#include "opengl/imgui_opengl.h"
|
#include <opengl/imgui_opengl.h>
|
||||||
#include "opengl/imgui_glfw.h"
|
#include <opengl/imgui_glfw.h>
|
||||||
|
#include <application.hpp>
|
||||||
|
#include <layer.hpp>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
@@ -259,6 +260,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void ImGuiLayer::OnAttach()
|
void ImGuiLayer::OnAttach()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
@@ -287,6 +290,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void ImGuiLayer::OnDetach()
|
void ImGuiLayer::OnDetach()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
@@ -294,6 +299,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void ImGuiLayer::Begin()
|
void ImGuiLayer::Begin()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
@@ -301,6 +308,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void ImGuiLayer::End()
|
void ImGuiLayer::End()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
Application& app = Application::Get();
|
Application& app = Application::Get();
|
||||||
@@ -321,6 +330,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void ImGuiLayer::OnImGuiRender()
|
void ImGuiLayer::OnImGuiRender()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
static bool show = true;
|
static bool show = true;
|
||||||
if (show)
|
if (show)
|
||||||
ImGui::ShowDemoWindow(&show);
|
ImGui::ShowDemoWindow(&show);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include "application.hpp"
|
#include <core.hpp>
|
||||||
#include "core.hpp"
|
|
||||||
#include "logging.hpp"
|
|
||||||
#include <input/linux_input.hpp>
|
#include <input/linux_input.hpp>
|
||||||
|
#include <application.hpp>
|
||||||
|
#include <logging.hpp>
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
#include <layer.hpp>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
Layer::Layer(const std::string& name)
|
|
||||||
: debug_name(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
#include "logging.hpp"
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <layer_stack.hpp>
|
#include <layer_stack.hpp>
|
||||||
|
#include <core.hpp>
|
||||||
|
|
||||||
|
#include <logging.hpp>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
LayerStack::LayerStack()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
LayerStack::~LayerStack()
|
LayerStack::~LayerStack()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
for (auto& layer : layers)
|
for (auto& layer : layers)
|
||||||
layer->OnDetach();
|
layer->OnDetach();
|
||||||
}
|
}
|
||||||
@@ -34,6 +36,10 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void LayerStack::UpdateLayers()
|
void LayerStack::UpdateLayers()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Popping Layers");
|
||||||
// processing pop queue layers
|
// processing pop queue layers
|
||||||
for (auto& layer : layers_to_pop) {
|
for (auto& layer : layers_to_pop) {
|
||||||
auto it = std::find(layers.begin(), layers.begin() + layer_insert_index, layer);
|
auto it = std::find(layers.begin(), layers.begin() + layer_insert_index, layer);
|
||||||
@@ -56,7 +62,11 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
overlay_to_pop.clear();
|
overlay_to_pop.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Pushing Layers");
|
||||||
// processing push queue layers
|
// processing push queue layers
|
||||||
for (auto& layer : layers_to_push) {
|
for (auto& layer : layers_to_push) {
|
||||||
layers.emplace(layers.begin() + layer_insert_index, layer);
|
layers.emplace(layers.begin() + layer_insert_index, layer);
|
||||||
@@ -76,3 +86,4 @@ namespace OpenEngine {
|
|||||||
overlay_to_push.clear();
|
overlay_to_push.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <logging.hpp>
|
#include <logging.hpp>
|
||||||
|
|
||||||
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <spdlog/common.h>
|
#include <spdlog/common.h>
|
||||||
#include <spdlog/logger.h>
|
#include <spdlog/logger.h>
|
||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
|
||||||
#include <spdlog/sinks/basic_file_sink.h>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|
||||||
std::shared_ptr<spdlog::logger> Logger::core_logger;
|
Ref<spdlog::logger> Logger::core_logger;
|
||||||
std::shared_ptr<spdlog::logger> Logger::client_logger;
|
Ref<spdlog::logger> Logger::client_logger;
|
||||||
|
|
||||||
void Logger::Init()
|
void Logger::Init()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
spdlog::set_pattern("%^[%H:%M:%S] [%l] %n: %v%$");
|
spdlog::set_pattern("%^[%H:%M:%S] [%l] %n: %v%$");
|
||||||
core_logger = spdlog::stdout_color_mt("OpenEngine");
|
core_logger = spdlog::stdout_color_mt("OpenEngine");
|
||||||
core_logger->set_level(spdlog::level::trace);
|
core_logger->set_level(spdlog::level::trace);
|
||||||
@@ -23,6 +27,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
int setupMultisinkLogger(const std::string &file_path)
|
int setupMultisinkLogger(const std::string &file_path)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
if (spdlog::get("open-engine_logger"))
|
if (spdlog::get("open-engine_logger"))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <opengl/opengl_buffer.hpp>
|
#include <opengl/opengl_buffer.hpp>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
// ==================================================================
|
// ==================================================================
|
||||||
@@ -11,6 +12,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
OpenGLVertexBuffer::OpenGLVertexBuffer(float* vertices, uint32_t size)
|
OpenGLVertexBuffer::OpenGLVertexBuffer(float* vertices, uint32_t size)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
glCreateBuffers(1, &id);
|
glCreateBuffers(1, &id);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, id);
|
glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||||
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
|
||||||
@@ -36,6 +39,8 @@ namespace OpenEngine {
|
|||||||
OpenGLIndexBuffer::OpenGLIndexBuffer(uint32_t* indices, uint32_t count)
|
OpenGLIndexBuffer::OpenGLIndexBuffer(uint32_t* indices, uint32_t count)
|
||||||
: count(count)
|
: count(count)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
glCreateBuffers(1, &id);
|
glCreateBuffers(1, &id);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(uint32_t), indices, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(uint32_t), indices, GL_STATIC_DRAW);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
#include "opengl/opengl_context.hpp"
|
|
||||||
#include "logging.hpp"
|
#include <opengl/opengl_context.hpp>
|
||||||
|
#include <logging.hpp>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
@@ -14,14 +15,16 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void OpenGLContext::Init()
|
void OpenGLContext::Init()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
glfwMakeContextCurrent(window_handle);
|
glfwMakeContextCurrent(window_handle);
|
||||||
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||||
OE_CORE_ASSERT(status, "Failed to initialize Glad!");
|
OE_CORE_ASSERT(status, "Failed to initialize Glad!");
|
||||||
|
|
||||||
OE_CORE_INFO("Opengl info:");
|
OE_CORE_DEBUG("Opengl info:");
|
||||||
OE_CORE_INFO("\tVendor: {}", (char*)glGetString(GL_VENDOR));
|
OE_CORE_DEBUG("\tVendor: {}", (char*)glGetString(GL_VENDOR));
|
||||||
OE_CORE_INFO("\tRenderer: {}", (char*)glGetString(GL_RENDERER));
|
OE_CORE_DEBUG("\tRenderer: {}", (char*)glGetString(GL_RENDERER));
|
||||||
OE_CORE_INFO("\tVersion: {}", (char*)glGetString(GL_VERSION));
|
OE_CORE_DEBUG("\tVersion: {}", (char*)glGetString(GL_VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLContext::SwapBuffers()
|
void OpenGLContext::SwapBuffers()
|
||||||
|
|||||||
@@ -5,8 +5,39 @@
|
|||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
void OpenGLMessageCallback(
|
||||||
|
unsigned source,
|
||||||
|
unsigned type,
|
||||||
|
unsigned id,
|
||||||
|
unsigned severity,
|
||||||
|
int length,
|
||||||
|
const char* message,
|
||||||
|
const void* userParam)
|
||||||
|
{
|
||||||
|
switch (severity)
|
||||||
|
{
|
||||||
|
case GL_DEBUG_SEVERITY_HIGH: OE_CORE_CRITICAL(message); return;
|
||||||
|
case GL_DEBUG_SEVERITY_MEDIUM: OE_CORE_ERROR(message); return;
|
||||||
|
case GL_DEBUG_SEVERITY_LOW: OE_CORE_WARN(message); return;
|
||||||
|
case GL_DEBUG_SEVERITY_NOTIFICATION: OE_CORE_TRACE(message); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OE_CORE_ASSERT(false, "Unknown severity level!");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void OpenGLRendererAPI::Init()
|
void OpenGLRendererAPI::Init()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
#ifdef OE_DEBUG
|
||||||
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||||
|
glDebugMessageCallback(OpenGLMessageCallback, nullptr);
|
||||||
|
|
||||||
|
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, NULL, GL_FALSE);
|
||||||
|
#endif
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
@@ -28,8 +59,10 @@ namespace OpenEngine {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLRendererAPI::DrawIndexed(const std::shared_ptr<VertexArray>& vertex_array)
|
void OpenGLRendererAPI::DrawIndexed(const Ref<VertexArray>& vertex_array)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, vertex_array->GetIndexBuffer()->GetCount(), GL_UNSIGNED_INT, nullptr);
|
glDrawElements(GL_TRIANGLES, vertex_array->GetIndexBuffer()->GetCount(), GL_UNSIGNED_INT, nullptr);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
#include <alloca.h>
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
#include "logging.hpp"
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include <opengl/opengl_shader.hpp>
|
#include <opengl/opengl_shader.hpp>
|
||||||
|
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
#include <logging.hpp>
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <alloca.h>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
static GLenum ShaderTypeFromString(const std::string& type)
|
static GLenum ShaderTypeFromString(const std::string& type)
|
||||||
@@ -27,6 +26,8 @@ namespace OpenEngine {
|
|||||||
OpenGLShader::OpenGLShader(const std::string& name, const std::string& vertex_src, const std::string& fragment_src)
|
OpenGLShader::OpenGLShader(const std::string& name, const std::string& vertex_src, const std::string& fragment_src)
|
||||||
: name(name)
|
: name(name)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
std::unordered_map<GLenum, std::string> sources;
|
std::unordered_map<GLenum, std::string> sources;
|
||||||
sources[GL_VERTEX_SHADER] = vertex_src;
|
sources[GL_VERTEX_SHADER] = vertex_src;
|
||||||
sources[GL_FRAGMENT_SHADER] = fragment_src;
|
sources[GL_FRAGMENT_SHADER] = fragment_src;
|
||||||
@@ -36,9 +37,14 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
OpenGLShader::OpenGLShader(const std::string& shader_path)
|
OpenGLShader::OpenGLShader(const std::string& shader_path)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Compiling Shader");
|
||||||
std::string source = ReadFile(shader_path);
|
std::string source = ReadFile(shader_path);
|
||||||
auto shader_sources = PreProcess(source);
|
auto shader_sources = PreProcess(source);
|
||||||
Compile(shader_sources);
|
Compile(shader_sources);
|
||||||
|
}
|
||||||
|
|
||||||
// Getting file name
|
// Getting file name
|
||||||
auto last_slash = shader_path.find_last_of("/\\");
|
auto last_slash = shader_path.find_last_of("/\\");
|
||||||
@@ -51,6 +57,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void OpenGLShader::Compile(const std::unordered_map<GLenum, std::string> sources)
|
void OpenGLShader::Compile(const std::unordered_map<GLenum, std::string> sources)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
GLuint program = glCreateProgram();
|
GLuint program = glCreateProgram();
|
||||||
GLenum *gl_shader_ids = (GLenum*)alloca(sources.size());
|
GLenum *gl_shader_ids = (GLenum*)alloca(sources.size());
|
||||||
|
|
||||||
@@ -122,6 +130,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
std::unordered_map<GLenum, std::string> OpenGLShader::PreProcess(const std::string& shader_source)
|
std::unordered_map<GLenum, std::string> OpenGLShader::PreProcess(const std::string& shader_source)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
// TODO: Perhaps consider using getline to get the position of errors. or even regexes
|
// TODO: Perhaps consider using getline to get the position of errors. or even regexes
|
||||||
std::unordered_map<GLenum, std::string> sources;
|
std::unordered_map<GLenum, std::string> sources;
|
||||||
const char* type_token = "#type";
|
const char* type_token = "#type";
|
||||||
@@ -148,15 +158,23 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
std::string OpenGLShader::ReadFile(const std::string& shader_path)
|
std::string OpenGLShader::ReadFile(const std::string& shader_path)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
std::ifstream input(shader_path);
|
std::ifstream input(shader_path);
|
||||||
if (input) {
|
if (input) {
|
||||||
input.seekg(0, std::ios::end);
|
input.seekg(0, std::ios::end);
|
||||||
result.resize(input.tellg());
|
|
||||||
|
size_t size = input.tellg();
|
||||||
|
if (size != -1) {
|
||||||
|
result.resize(size);
|
||||||
input.seekg(0, std::ios::beg);
|
input.seekg(0, std::ios::beg);
|
||||||
input.read(&result[0], result.size());
|
input.read(&result[0], result.size());
|
||||||
input.close();
|
input.close();
|
||||||
|
} else {
|
||||||
|
OE_CORE_ERROR("Could not read from file {}", shader_path);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
OE_CORE_ERROR("Shader file could not be open or does not exist: {}", shader_path);
|
OE_CORE_ERROR("Shader file could not be open or does not exist: {}", shader_path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include "core.hpp"
|
#include <core.hpp>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <renderer/texture.hpp>
|
|
||||||
#include <opengl/opengl_texture.hpp>
|
#include <opengl/opengl_texture.hpp>
|
||||||
|
#include <renderer/texture.hpp>
|
||||||
|
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
OpenGLTexture2D::OpenGLTexture2D(uint32_t width, uint32_t height)
|
OpenGLTexture2D::OpenGLTexture2D(uint32_t width, uint32_t height)
|
||||||
: width(width), height(height)
|
: width(width), height(height)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
internal_format = GL_RGBA8;
|
internal_format = GL_RGBA8;
|
||||||
data_format = GL_RGBA;
|
data_format = GL_RGBA;
|
||||||
|
|
||||||
@@ -30,6 +31,8 @@ namespace OpenEngine {
|
|||||||
OpenGLTexture2D::OpenGLTexture2D(const std::string& path)
|
OpenGLTexture2D::OpenGLTexture2D(const std::string& path)
|
||||||
: path(path)
|
: path(path)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
int image_width, image_height, channels;
|
int image_width, image_height, channels;
|
||||||
stbi_set_flip_vertically_on_load(1);
|
stbi_set_flip_vertically_on_load(1);
|
||||||
stbi_uc* data = stbi_load(path.c_str(), &image_width, &image_height, &channels, 0);
|
stbi_uc* data = stbi_load(path.c_str(), &image_width, &image_height, &channels, 0);
|
||||||
@@ -65,11 +68,15 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
OpenGLTexture2D::~OpenGLTexture2D()
|
OpenGLTexture2D::~OpenGLTexture2D()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
glDeleteTextures(1, &id);
|
glDeleteTextures(1, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLTexture2D::SetData(void* data, uint32_t size)
|
void OpenGLTexture2D::SetData(void* data, uint32_t size)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
uint32_t bpp = data_format == GL_RGBA ? 4 : 3;
|
uint32_t bpp = data_format == GL_RGBA ? 4 : 3;
|
||||||
OE_CORE_ASSERT(size == width * height * bpp, "Data must be entire texture!");
|
OE_CORE_ASSERT(size == width * height * bpp, "Data must be entire texture!");
|
||||||
glTextureSubImage2D(id, 0, 0, 0, width, height, data_format, GL_UNSIGNED_BYTE, data);
|
glTextureSubImage2D(id, 0, 0, 0, width, height, data_format, GL_UNSIGNED_BYTE, data);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "core.hpp"
|
|
||||||
#include <cstdint>
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
|
#include <core.hpp>
|
||||||
#include <opengl/opengl_vertex_array.hpp>
|
#include <opengl/opengl_vertex_array.hpp>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
@@ -12,17 +12,17 @@ namespace OpenEngine {
|
|||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case OpenEngine::ShaderDataType::Float: return GL_FLOAT;
|
case ShaderDataType::Float: return GL_FLOAT;
|
||||||
case OpenEngine::ShaderDataType::Float2: return GL_FLOAT;
|
case ShaderDataType::Float2: return GL_FLOAT;
|
||||||
case OpenEngine::ShaderDataType::Float3: return GL_FLOAT;
|
case ShaderDataType::Float3: return GL_FLOAT;
|
||||||
case OpenEngine::ShaderDataType::Float4: return GL_FLOAT;
|
case ShaderDataType::Float4: return GL_FLOAT;
|
||||||
case OpenEngine::ShaderDataType::Mat3: return GL_FLOAT;
|
case ShaderDataType::Mat3: return GL_FLOAT;
|
||||||
case OpenEngine::ShaderDataType::Mat4: return GL_FLOAT;
|
case ShaderDataType::Mat4: return GL_FLOAT;
|
||||||
case OpenEngine::ShaderDataType::Int: return GL_INT;
|
case ShaderDataType::Int: return GL_INT;
|
||||||
case OpenEngine::ShaderDataType::Int2: return GL_INT;
|
case ShaderDataType::Int2: return GL_INT;
|
||||||
case OpenEngine::ShaderDataType::Int3: return GL_INT;
|
case ShaderDataType::Int3: return GL_INT;
|
||||||
case OpenEngine::ShaderDataType::Int4: return GL_INT;
|
case ShaderDataType::Int4: return GL_INT;
|
||||||
case OpenEngine::ShaderDataType::Bool: return GL_BOOL;
|
case ShaderDataType::Bool: return GL_BOOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
OE_CORE_ASSERT(false, "Unknown ShaderDataType!");
|
OE_CORE_ASSERT(false, "Unknown ShaderDataType!");
|
||||||
@@ -31,11 +31,15 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
OpenGLVertexArray::OpenGLVertexArray()
|
OpenGLVertexArray::OpenGLVertexArray()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
glCreateVertexArrays(1, &id);
|
glCreateVertexArrays(1, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenGLVertexArray::~OpenGLVertexArray()
|
OpenGLVertexArray::~OpenGLVertexArray()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
glDeleteVertexArrays(1, &id);
|
glDeleteVertexArrays(1, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,8 +52,10 @@ namespace OpenEngine {
|
|||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLVertexArray::AddVertexBuffer(const std::shared_ptr<VertexBuffer>& vertex_buffer)
|
void OpenGLVertexArray::AddVertexBuffer(const Ref<VertexBuffer>& vertex_buffer)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
glBindVertexArray(id);
|
glBindVertexArray(id);
|
||||||
vertex_buffer->Bind();
|
vertex_buffer->Bind();
|
||||||
|
|
||||||
@@ -70,8 +76,10 @@ namespace OpenEngine {
|
|||||||
vertex_buffers.emplace_back(vertex_buffer);
|
vertex_buffers.emplace_back(vertex_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLVertexArray::SetIndexBuffer(const std::shared_ptr<IndexBuffer>& index_buffer)
|
void OpenGLVertexArray::SetIndexBuffer(const Ref<IndexBuffer>& index_buffer)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
glBindVertexArray(id);
|
glBindVertexArray(id);
|
||||||
index_buffer->Bind();
|
index_buffer->Bind();
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#include <glm/trigonometric.hpp>
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <orthographic_camera.hpp>
|
#include <orthographic_camera.hpp>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/trigonometric.hpp>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
OrthographicCamera::OrthographicCamera(float left, float right, float bottom, float top)
|
OrthographicCamera::OrthographicCamera(float left, float right, float bottom, float top)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include "open_engine/orthographic_camera_controller.hpp"
|
#include <orthographic_camera_controller.hpp>
|
||||||
#include "open_engine/events/application_event.hpp"
|
#include <events/application_event.hpp>
|
||||||
#include "open_engine/events/event.hpp"
|
#include <orthographic_camera.hpp>
|
||||||
#include "open_engine/events/mouse_event.hpp"
|
#include <input/input_system.hpp>
|
||||||
#include "open_engine/core/time.hpp"
|
#include <events/mouse_event.hpp>
|
||||||
#include "open_engine/input/keycodes.hpp"
|
#include <input/keycodes.hpp>
|
||||||
#include "open_engine/input/input_system.hpp"
|
#include <events/event.hpp>
|
||||||
#include "open_engine/orthographic_camera.hpp"
|
#include <core/time.hpp>
|
||||||
|
|
||||||
#include <glm/fwd.hpp>
|
#include <glm/fwd.hpp>
|
||||||
|
|
||||||
@@ -20,18 +20,24 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void OrthographicCameraController::Translate(const glm::vec3& vector)
|
void OrthographicCameraController::Translate(const glm::vec3& vector)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
float velocity = translation_speed * Time::DeltaTime();
|
float velocity = translation_speed * Time::DeltaTime();
|
||||||
camera_position += vector * velocity;
|
camera_position += vector * velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrthographicCameraController::Rotate(float speed)
|
void OrthographicCameraController::Rotate(float speed)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
float multiple = rotation_speed * Time::DeltaTime();
|
float multiple = rotation_speed * Time::DeltaTime();
|
||||||
camera_rotation += speed * multiple;
|
camera_rotation += speed * multiple;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrthographicCameraController::OnUpdate()
|
void OrthographicCameraController::OnUpdate()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
if (Input::IsKeyPressed(OE_KEY_W))
|
if (Input::IsKeyPressed(OE_KEY_W))
|
||||||
Translate({0, -1, 0});
|
Translate({0, -1, 0});
|
||||||
if (Input::IsKeyPressed(OE_KEY_A))
|
if (Input::IsKeyPressed(OE_KEY_A))
|
||||||
@@ -52,8 +58,11 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
camera.SetPosition(camera_position);
|
camera.SetPosition(camera_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrthographicCameraController::OnEvent(Event& e)
|
void OrthographicCameraController::OnEvent(Event& e)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
EventDispatcher dispatcher(e);
|
EventDispatcher dispatcher(e);
|
||||||
dispatcher.Dispatch<MouseScrolledEvent>(BIND_EVENT_FN(OrthographicCameraController::OnMouseScrolled));
|
dispatcher.Dispatch<MouseScrolledEvent>(BIND_EVENT_FN(OrthographicCameraController::OnMouseScrolled));
|
||||||
dispatcher.Dispatch<WindowResizeEvent>(BIND_EVENT_FN(OrthographicCameraController::OnWindowResized));
|
dispatcher.Dispatch<WindowResizeEvent>(BIND_EVENT_FN(OrthographicCameraController::OnWindowResized));
|
||||||
@@ -61,6 +70,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
bool OrthographicCameraController::OnMouseScrolled(MouseScrolledEvent& e)
|
bool OrthographicCameraController::OnMouseScrolled(MouseScrolledEvent& e)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
zoom -= e.GetYOffset() * 0.25f;
|
zoom -= e.GetYOffset() * 0.25f;
|
||||||
zoom = std::max(zoom, 0.25f);
|
zoom = std::max(zoom, 0.25f);
|
||||||
camera.SetProjection(-aspect_ratio * zoom, aspect_ratio * zoom, -zoom, zoom);
|
camera.SetProjection(-aspect_ratio * zoom, aspect_ratio * zoom, -zoom, zoom);
|
||||||
@@ -69,6 +80,8 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
bool OrthographicCameraController::OnWindowResized(WindowResizeEvent& e)
|
bool OrthographicCameraController::OnWindowResized(WindowResizeEvent& e)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
aspect_ratio = (float)e.GetWidth() / (float)e.GetHeight();
|
aspect_ratio = (float)e.GetWidth() / (float)e.GetHeight();
|
||||||
camera.SetProjection(-aspect_ratio * zoom, aspect_ratio * zoom, -zoom, zoom);
|
camera.SetProjection(-aspect_ratio * zoom, aspect_ratio * zoom, -zoom, zoom);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#include "core.hpp"
|
|
||||||
#include "opengl/opengl_buffer.hpp"
|
|
||||||
#include <cstdint>
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <renderer/buffer.hpp>
|
#include <core.hpp>
|
||||||
|
#include <opengl/opengl_buffer.hpp>
|
||||||
#include <renderer/renderer.hpp>
|
#include <renderer/renderer.hpp>
|
||||||
|
#include <renderer/buffer.hpp>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|
||||||
@@ -52,6 +53,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void BufferLayout::CalculateOffsetsAndStride()
|
void BufferLayout::CalculateOffsetsAndStride()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
stride = 0;
|
stride = 0;
|
||||||
for (auto& element : elements)
|
for (auto& element : elements)
|
||||||
@@ -62,22 +65,26 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexBuffer* VertexBuffer::Create(float* vertices, uint32_t size)
|
Ref<VertexBuffer> VertexBuffer::Create(float* vertices, uint32_t size)
|
||||||
{
|
{
|
||||||
switch (Renderer::GetApi()) {
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
switch (Renderer::GetAPI()) {
|
||||||
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
||||||
case RendererAPI::API::OpenGL : return new OpenGLVertexBuffer(vertices, size);
|
case RendererAPI::API::OpenGL : return CreateRef<OpenGLVertexBuffer>(vertices, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
OE_CORE_ASSERT(false, "Selected API not supported");
|
OE_CORE_ASSERT(false, "Selected API not supported");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexBuffer* IndexBuffer::Create(uint32_t* indices, uint32_t count)
|
Ref<IndexBuffer> IndexBuffer::Create(uint32_t* indices, uint32_t count)
|
||||||
{
|
{
|
||||||
switch (Renderer::GetApi()) {
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
switch (Renderer::GetAPI()) {
|
||||||
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
||||||
case RendererAPI::API::OpenGL : return new OpenGLIndexBuffer(indices, count);
|
case RendererAPI::API::OpenGL : return CreateRef<OpenGLIndexBuffer>(indices, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
OE_CORE_ASSERT(false, "Selected API not supported");
|
OE_CORE_ASSERT(false, "Selected API not supported");
|
||||||
|
|||||||
@@ -2,27 +2,37 @@
|
|||||||
|
|
||||||
#include "open_engine/renderer/renderer.hpp"
|
#include "open_engine/renderer/renderer.hpp"
|
||||||
#include "open_engine/renderer/render_command.hpp"
|
#include "open_engine/renderer/render_command.hpp"
|
||||||
|
#include "renderer/renderer2d.hpp"
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
void Renderer::Init()
|
void Renderer::Init()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
RenderCommand::Init();
|
RenderCommand::Init();
|
||||||
}
|
}
|
||||||
|
void Renderer::ShutDown()
|
||||||
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
Renderer2D::Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::OnWindowResize(uint32_t width, uint32_t height)
|
void Renderer::OnWindowResize(uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
RenderCommand::SetViewport(0, 0, width, height);
|
RenderCommand::SetViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::BeginScene(const OrthographicCamera& camera)
|
void Renderer::BeginScene(const OrthographicCamera& camera)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
scene_data->view_projection_matrix = camera.GetViewProjectionMatrix();
|
scene_data->view_projection_matrix = camera.GetViewProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::EndScene()
|
void Renderer::EndScene()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -31,6 +41,8 @@ namespace OpenEngine {
|
|||||||
const std::shared_ptr<VertexArray>& vertex_array,
|
const std::shared_ptr<VertexArray>& vertex_array,
|
||||||
const glm::mat4& transform)
|
const glm::mat4& transform)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
shader->Bind();
|
shader->Bind();
|
||||||
shader->SetMat4("u_ViewProjection", scene_data->view_projection_matrix);
|
shader->SetMat4("u_ViewProjection", scene_data->view_projection_matrix);
|
||||||
shader->SetMat4("u_Transform", transform);
|
shader->SetMat4("u_Transform", transform);
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#include "renderer/texture.hpp"
|
|
||||||
#include <cstdint>
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
|
#include <renderer/buffer.hpp>
|
||||||
|
#include <renderer/texture.hpp>
|
||||||
#include <renderer/render_command.hpp>
|
#include <renderer/render_command.hpp>
|
||||||
#include <renderer/shader.hpp>
|
#include <renderer/shader.hpp>
|
||||||
#include <renderer/vertex_array.hpp>
|
#include <renderer/vertex_array.hpp>
|
||||||
#include <renderer/renderer2d.hpp>
|
#include <renderer/renderer2d.hpp>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <glm/fwd.hpp>
|
#include <glm/fwd.hpp>
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
|
|
||||||
@@ -22,6 +23,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void Renderer2D::Init()
|
void Renderer2D::Init()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
renderer_data = new Renderer2DData();
|
renderer_data = new Renderer2DData();
|
||||||
renderer_data->vertex_array = VertexArray::Create();
|
renderer_data->vertex_array = VertexArray::Create();
|
||||||
|
|
||||||
@@ -32,8 +35,7 @@ namespace OpenEngine {
|
|||||||
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ref<VertexBuffer> vertex_buffer;
|
Ref<VertexBuffer> vertex_buffer = VertexBuffer::Create(square_vertices, sizeof(square_vertices));
|
||||||
vertex_buffer.reset(VertexBuffer::Create(square_vertices, sizeof(square_vertices)));
|
|
||||||
|
|
||||||
BufferLayout layout = {
|
BufferLayout layout = {
|
||||||
{ ShaderDataType::Float3, "a_Position" },
|
{ ShaderDataType::Float3, "a_Position" },
|
||||||
@@ -44,8 +46,7 @@ namespace OpenEngine {
|
|||||||
renderer_data->vertex_array->AddVertexBuffer(vertex_buffer);
|
renderer_data->vertex_array->AddVertexBuffer(vertex_buffer);
|
||||||
|
|
||||||
uint32_t indices[6] = { 0, 1, 2, 2, 3, 0 };
|
uint32_t indices[6] = { 0, 1, 2, 2, 3, 0 };
|
||||||
Ref<IndexBuffer> index_buffer;
|
Ref<IndexBuffer> index_buffer = IndexBuffer::Create(indices, sizeof(indices) / sizeof(uint32_t));
|
||||||
index_buffer.reset(IndexBuffer::Create(indices, sizeof(indices) / sizeof(uint32_t)));
|
|
||||||
|
|
||||||
renderer_data->vertex_array->SetIndexBuffer(index_buffer);
|
renderer_data->vertex_array->SetIndexBuffer(index_buffer);
|
||||||
|
|
||||||
@@ -61,11 +62,15 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void Renderer2D::Shutdown()
|
void Renderer2D::Shutdown()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
delete renderer_data;
|
delete renderer_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer2D::BeginScene(const OrthographicCamera& camera)
|
void Renderer2D::BeginScene(const OrthographicCamera& camera)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
renderer_data->texture_shader->Bind();
|
renderer_data->texture_shader->Bind();
|
||||||
renderer_data->texture_shader->SetMat4("u_ViewProjection", camera.GetViewProjectionMatrix());
|
renderer_data->texture_shader->SetMat4("u_ViewProjection", camera.GetViewProjectionMatrix());
|
||||||
renderer_data->texture_shader->SetMat4("u_ViewProjection", camera.GetViewProjectionMatrix());
|
renderer_data->texture_shader->SetMat4("u_ViewProjection", camera.GetViewProjectionMatrix());
|
||||||
@@ -77,10 +82,14 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void Renderer2D::DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref<Texture2D>& texture)
|
void Renderer2D::DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref<Texture2D>& texture)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
DrawQuad(glm::vec3(position, 0.0f), size, texture);
|
DrawQuad(glm::vec3(position, 0.0f), size, texture);
|
||||||
}
|
}
|
||||||
void Renderer2D::DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref<Texture2D>& texture)
|
void Renderer2D::DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref<Texture2D>& texture)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
renderer_data->texture_shader->SetVec4("u_Color", glm::vec4(1.0f));
|
renderer_data->texture_shader->SetVec4("u_Color", glm::vec4(1.0f));
|
||||||
texture->Bind();
|
texture->Bind();
|
||||||
|
|
||||||
@@ -94,10 +103,14 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void Renderer2D::DrawQuad(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color)
|
void Renderer2D::DrawQuad(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
DrawQuad(glm::vec3(position, 0.0f), size, color);
|
DrawQuad(glm::vec3(position, 0.0f), size, color);
|
||||||
}
|
}
|
||||||
void Renderer2D::DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& color)
|
void Renderer2D::DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& color)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
renderer_data->texture_shader->SetVec4("u_Color", color);
|
renderer_data->texture_shader->SetVec4("u_Color", color);
|
||||||
renderer_data->white_texture->Bind();
|
renderer_data->white_texture->Bind();
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
#include "logging.hpp"
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
#include <open_engine/renderer/shader.hpp>
|
|
||||||
#include <open_engine/renderer/renderer.hpp>
|
|
||||||
#include <open_engine/renderer/renderer_api.hpp>
|
|
||||||
#include <opengl/opengl_shader.hpp>
|
|
||||||
|
|
||||||
#include <core.hpp>
|
#include <core.hpp>
|
||||||
|
#include <open_engine/renderer/shader.hpp>
|
||||||
|
#include <open_engine/renderer/renderer_api.hpp>
|
||||||
|
#include <open_engine/renderer/renderer.hpp>
|
||||||
|
#include <opengl/opengl_shader.hpp>
|
||||||
|
#include <logging.hpp>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
Ref<Shader> Shader::Create(const std::string& shader_path)
|
Ref<Shader> Shader::Create(const std::string& shader_path)
|
||||||
{
|
{
|
||||||
switch (Renderer::GetApi())
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
switch (Renderer::GetAPI())
|
||||||
{
|
{
|
||||||
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
||||||
case RendererAPI::API::OpenGL: return std::make_shared<OpenGLShader>(shader_path);
|
case RendererAPI::API::OpenGL: return CreateRef<OpenGLShader>(shader_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
OE_CORE_ASSERT(false, "Unknown RendererAPI!");
|
OE_CORE_ASSERT(false, "Unknown RendererAPI!");
|
||||||
@@ -22,10 +24,12 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
Ref<Shader> Shader::Create(const std::string& name, const std::string& vertex_src, const std::string& frament_src)
|
Ref<Shader> Shader::Create(const std::string& name, const std::string& vertex_src, const std::string& frament_src)
|
||||||
{
|
{
|
||||||
switch (Renderer::GetApi())
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
switch (Renderer::GetAPI())
|
||||||
{
|
{
|
||||||
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
||||||
case RendererAPI::API::OpenGL: return std::make_shared<OpenGLShader>(name, vertex_src, frament_src);
|
case RendererAPI::API::OpenGL: return CreateRef<OpenGLShader>(name, vertex_src, frament_src);
|
||||||
}
|
}
|
||||||
|
|
||||||
OE_CORE_ASSERT(false, "Unknown RendererAPI!");
|
OE_CORE_ASSERT(false, "Unknown RendererAPI!");
|
||||||
@@ -34,12 +38,16 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void ShaderLibrary::Add(const Ref<Shader>& shader)
|
void ShaderLibrary::Add(const Ref<Shader>& shader)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
auto shader_name = shader->GetName();
|
auto shader_name = shader->GetName();
|
||||||
Add(shader_name, shader);
|
Add(shader_name, shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderLibrary::Add(const std::string& name, const Ref<Shader>& shader)
|
void ShaderLibrary::Add(const std::string& name, const Ref<Shader>& shader)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
if (Exists(name))
|
if (Exists(name))
|
||||||
OE_CORE_ERROR("Shader with this name already exists: ", name);
|
OE_CORE_ERROR("Shader with this name already exists: ", name);
|
||||||
|
|
||||||
@@ -48,6 +56,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
Ref<Shader> ShaderLibrary::Load(const std::string& path)
|
Ref<Shader> ShaderLibrary::Load(const std::string& path)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
auto shader = Shader::Create(path);
|
auto shader = Shader::Create(path);
|
||||||
Add(shader);
|
Add(shader);
|
||||||
|
|
||||||
@@ -56,6 +66,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
Ref<Shader> ShaderLibrary::Load(const std::string& name, const std::string& path)
|
Ref<Shader> ShaderLibrary::Load(const std::string& name, const std::string& path)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
auto shader = Shader::Create(path);
|
auto shader = Shader::Create(path);
|
||||||
Add(name, shader);
|
Add(name, shader);
|
||||||
|
|
||||||
@@ -64,6 +76,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
Ref<Shader> ShaderLibrary::Get(const std::string& name) const
|
Ref<Shader> ShaderLibrary::Get(const std::string& name) const
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
if (!Exists(name))
|
if (!Exists(name))
|
||||||
OE_CORE_ERROR("Shader with this name doesn't exists: ", name);
|
OE_CORE_ERROR("Shader with this name doesn't exists: ", name);
|
||||||
return shaders.find(name)->second;
|
return shaders.find(name)->second;
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <core.hpp>
|
#include <core.hpp>
|
||||||
#include <open_engine/renderer/texture.hpp>
|
|
||||||
#include <open_engine/renderer/renderer.hpp>
|
|
||||||
#include <open_engine/opengl/opengl_texture.hpp>
|
#include <open_engine/opengl/opengl_texture.hpp>
|
||||||
|
#include <open_engine/renderer/renderer.hpp>
|
||||||
|
#include <open_engine/renderer/texture.hpp>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
Ref<Texture2D> Texture2D::Create(uint32_t width, uint32_t height)
|
Ref<Texture2D> Texture2D::Create(uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
switch (Renderer::GetApi()) {
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
switch (Renderer::GetAPI()) {
|
||||||
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
||||||
case RendererAPI::API::OpenGL : return CreateRef<OpenGLTexture2D>(width, height);
|
case RendererAPI::API::OpenGL : return CreateRef<OpenGLTexture2D>(width, height);
|
||||||
}
|
}
|
||||||
@@ -19,7 +21,9 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
Ref<Texture2D> Texture2D::Create(const std::string &path)
|
Ref<Texture2D> Texture2D::Create(const std::string &path)
|
||||||
{
|
{
|
||||||
switch (Renderer::GetApi()) {
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
switch (Renderer::GetAPI()) {
|
||||||
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
||||||
case RendererAPI::API::OpenGL : return CreateRef<OpenGLTexture2D>(path);
|
case RendererAPI::API::OpenGL : return CreateRef<OpenGLTexture2D>(path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include "opengl/opengl_vertex_array.hpp"
|
#include <core.hpp>
|
||||||
#include "renderer/renderer.hpp"
|
#include <opengl/opengl_vertex_array.hpp>
|
||||||
#include <renderer/vertex_array.hpp>
|
#include <renderer/vertex_array.hpp>
|
||||||
|
#include <renderer/renderer.hpp>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
Ref<VertexArray> VertexArray::Create()
|
Ref<VertexArray> VertexArray::Create()
|
||||||
{
|
{
|
||||||
switch (Renderer::GetApi()) {
|
switch (Renderer::GetAPI()) {
|
||||||
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr;
|
||||||
case RendererAPI::API::OpenGL : return std::make_shared<OpenGLVertexArray>();
|
case RendererAPI::API::OpenGL : return CreateRef<OpenGLVertexArray>();
|
||||||
}
|
}
|
||||||
|
|
||||||
OE_CORE_ASSERT(false, "Selected API not supported");
|
OE_CORE_ASSERT(false, "Selected API not supported");
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
#include "core.hpp"
|
#include <pch.hpp>
|
||||||
#include "events/application_event.hpp"
|
|
||||||
#include "events/key_event.hpp"
|
#include <core.hpp>
|
||||||
#include "events/mouse_event.hpp"
|
#include <window/linux_window.hpp>
|
||||||
#include "logging.hpp"
|
#include <renderer/graphics_context.hpp>
|
||||||
|
#include <events/application_event.hpp>
|
||||||
|
#include <opengl/opengl_context.hpp>
|
||||||
|
#include <events/mouse_event.hpp>
|
||||||
|
#include <renderer/renderer.hpp>
|
||||||
|
#include <events/key_event.hpp>
|
||||||
|
#include <instrumentor.hpp>
|
||||||
|
#include <logging.hpp>
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <window/linux_window.hpp>
|
|
||||||
#include <opengl/opengl_context.hpp>
|
|
||||||
#include "renderer/graphics_context.hpp"
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
static bool glfw_initialized = false;
|
static bool glfw_initialized = false;
|
||||||
@@ -18,9 +22,9 @@ namespace OpenEngine {
|
|||||||
OE_CORE_ERROR("GLFW Error {}: {}", error, description);
|
OE_CORE_ERROR("GLFW Error {}: {}", error, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Window> Window::Create(const WindowProps& props)
|
Scope<Window> Window::Create(const WindowProps& props)
|
||||||
{
|
{
|
||||||
return std::make_unique<LinuxWindow>(props);
|
return CreateScope<LinuxWindow>(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinuxWindow::LinuxWindow(const WindowProps& props)
|
LinuxWindow::LinuxWindow(const WindowProps& props)
|
||||||
@@ -35,12 +39,17 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void LinuxWindow::Init(const WindowProps& props)
|
void LinuxWindow::Init(const WindowProps& props)
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
data.title = props.title;
|
data.title = props.title;
|
||||||
data.height = props.height;
|
data.height = props.height;
|
||||||
data.width = props.width;
|
data.width = props.width;
|
||||||
|
|
||||||
OE_CORE_INFO("Creating window {} ({} {})", props.title, props.width, props.height);
|
OE_CORE_INFO("Creating window {} ({} {})", props.title, props.width, props.height);
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Initializing GLFW");
|
||||||
|
|
||||||
if (!glfw_initialized) {
|
if (!glfw_initialized) {
|
||||||
int success = glfwInit();
|
int success = glfwInit();
|
||||||
OE_CORE_ASSERT(success, "Could not initialize GLFW!");
|
OE_CORE_ASSERT(success, "Could not initialize GLFW!");
|
||||||
@@ -55,10 +64,16 @@ namespace OpenEngine {
|
|||||||
glfw_initialized = true;
|
glfw_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OE_DEBUG
|
||||||
|
if (Renderer::GetAPI() == RendererAPI::API::OpenGL)
|
||||||
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
|
||||||
|
#endif
|
||||||
gl_window = glfwCreateWindow((int)props.width, (int)props.height, props.title.c_str(), nullptr, nullptr);
|
gl_window = glfwCreateWindow((int)props.width, (int)props.height, props.title.c_str(), nullptr, nullptr);
|
||||||
|
|
||||||
context = CreateScope<OpenGLContext>(gl_window);
|
context = CreateScope<OpenGLContext>(gl_window);
|
||||||
context->Init();
|
context->Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
glfwSetWindowUserPointer(gl_window, &data);
|
glfwSetWindowUserPointer(gl_window, &data);
|
||||||
SetVSync(true);
|
SetVSync(true);
|
||||||
@@ -150,21 +165,28 @@ namespace OpenEngine {
|
|||||||
MouseMovedEvent event((float) xpos, (float)ypos);
|
MouseMovedEvent event((float) xpos, (float)ypos);
|
||||||
data.event_callback(event);
|
data.event_callback(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
//glViewport(0, 0, 100, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinuxWindow::Shutdown()
|
void LinuxWindow::Shutdown()
|
||||||
{
|
{
|
||||||
glfwDestroyWindow(gl_window);
|
glfwDestroyWindow(gl_window);
|
||||||
|
glfwTerminate();
|
||||||
gl_window = nullptr;
|
gl_window = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinuxWindow::OnUpdate()
|
void LinuxWindow::OnUpdate()
|
||||||
{
|
{
|
||||||
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Polling Events");
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
OE_PROFILE_SCOPE("Swapping Buffers");
|
||||||
context->SwapBuffers();
|
context->SwapBuffers();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LinuxWindow::SetVSync(bool enabled)
|
void LinuxWindow::SetVSync(bool enabled)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user