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