cleanup and instrumentation

This commit is contained in:
Erris
2026-01-25 16:12:32 +01:00
parent c8cfed58da
commit 736591415c
61 changed files with 845 additions and 383 deletions

View File

@@ -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"

View File

@@ -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);

View File

@@ -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
View 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
View 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

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;

View File

@@ -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

View 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

View File

@@ -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 = "";

View File

@@ -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;

View File

@@ -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;
};
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
};
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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>

View File

@@ -1,7 +1,7 @@
#ifndef PCH_HPP
#define PCH_HPP
#include "logging.hpp"
#include "open_engine/logging.hpp"
#include <functional>

View File

@@ -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);
};
}

View File

@@ -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>();

View File

@@ -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

View File

@@ -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; };

View File

@@ -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

View File

@@ -2,6 +2,7 @@
#define TEXTURE_HPP
#include "open_engine/core.hpp"
#include <cstdint>
namespace OpenEngine {

View File

@@ -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();
};

View File

@@ -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;

View File

@@ -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());
};
}