content browser and textures on entity sprites

This commit is contained in:
Erris
2026-02-27 10:45:44 +01:00
parent cee0f42164
commit 9de9609dee
23 changed files with 809 additions and 213 deletions

View File

@@ -10,10 +10,25 @@
int main(int argc, char **argv);
namespace OpenEngine {
struct ApplicationCommandLineArgs
{
int count = 0;
char** args = nullptr;
const char* operator[](int index)
{
OE_CORE_ASSERT(index < count, "Index is higher than argument count.");
return args[index];
};
};
class Application
{
public:
Application(const std::string& name = "OpenEngine Project");
Application(const std::string& name,
ApplicationCommandLineArgs& args);
~Application();
virtual void OnEvent(Event& event);
@@ -25,6 +40,7 @@ namespace OpenEngine {
ImGuiLayer* GetImGuiLayer() { return imgui_layer.get(); };
inline static Application& Get() { return *instance; };
ApplicationCommandLineArgs GetCommandLineArgs() const { return arguments; };
inline Window& GetWindow() { return *window; };
@@ -36,6 +52,7 @@ namespace OpenEngine {
bool OnWindowResize(WindowResizeEvent& event);
private:
ApplicationCommandLineArgs arguments;
const std::string name;
std::unique_ptr<Window> window;
@@ -49,7 +66,7 @@ namespace OpenEngine {
};
// Is defined by client
Application* CreateApplication();
Application* CreateApplication(ApplicationCommandLineArgs args);
}
#endif // APPLICATION_HPP

View File

@@ -1,17 +1,16 @@
#ifndef ENTRY_POINT_HPP
#define ENTRY_POINT_HPP
#include "open_engine/core.hpp"
#include "open_engine/application.hpp"
#include "open_engine/logging.hpp"
extern OpenEngine::Application* OpenEngine::CreateApplication();
extern OpenEngine::Application* OpenEngine::CreateApplication(OpenEngine::ApplicationCommandLineArgs args);
int main(int argc, char** argv)
{
OE_PROFILE_BEGIN_SESSION("Startup", "open_engine-startup.json");
OpenEngine::Logger::Init();
auto app = OpenEngine::CreateApplication();
auto app = OpenEngine::CreateApplication({ argc, argv });
OE_PROFILE_END_SESSION();
OE_PROFILE_BEGIN_SESSION("Runtime", "open_engine-runtime.json");

View File

@@ -14,7 +14,7 @@ namespace OpenEngine {
public:
OpenGLShader(const std::string& shader_path);
OpenGLShader(const std::string& name, const std::string& vertex_src, const std::string& frament_src);
virtual ~OpenGLShader() = default;
virtual ~OpenGLShader();
virtual const std::string& GetName() const override { return name; };
@@ -44,11 +44,21 @@ namespace OpenEngine {
private:
std::string ReadFile(const std::string& shader_path);
std::unordered_map<GLenum, std::string> PreProcess(const std::string& shader_source);
void Compile(const std::unordered_map<GLenum, std::string> sources);
void CheckCompileErrors(unsigned int shader, const std::string& type);
void CompileOrGetVulkanBinaries(const std::unordered_map<GLenum, std::string>& shader_sources);
void CompileOrGetOpenGLBinaries();
void CreateProgram();
void Reflect(GLenum stage, const std::vector<uint32_t>& shader_data);
//void CheckCompileErrors(unsigned int shader, const std::string& type);
private:
std::string name;
std::string file_path;
std::unordered_map<GLenum, std::vector<uint32_t>> vulkan_spirv;
std::unordered_map<GLenum, std::vector<uint32_t>> opengl_spirv;
std::unordered_map<GLenum, std::string> m_OpenGLSourceCode;
u_int32_t id;
};

View File

@@ -0,0 +1,24 @@
#ifndef OPENGL_UNIFORM_BUFFER_HPP
#define OPENGL_UNIFORM_BUFFER_HPP
#include "open_engine/renderer/uniform_buffer.hpp"
#include <cstdint>
namespace OpenEngine {
class OpenGLUniformBuffer : public UniformBuffer
{
public:
OpenGLUniformBuffer(uint32_t size, uint32_t binding);
virtual ~OpenGLUniformBuffer();
virtual void SetData(const void* data, uint32_t size,
uint32_t offset = 0) override;
private:
uint32_t id = 0;
};
}
#endif // OPENGL_UNIFORM_BUFFER_HPP

View File

@@ -44,6 +44,9 @@ namespace OpenEngine {
static void DrawQuad(const Transform& transform_data,
const Ref<Texture2D>& texture, int entity_id,
float tiling_factor = 1.0f);
static void DrawQuad(const Transform& transform_data,
const Ref<Texture2D>& texture, const glm::vec4& color,
int entity_id, float tiling_factor = 1.0f);
static void DrawQuad(const Transform& transform_data,
const Ref<Subtexture2D>& subtexture, int entity_id,
float tiling_factor = 1.0f);
@@ -53,6 +56,9 @@ namespace OpenEngine {
static void DrawQuad(const glm::mat4& transform,
const Ref<Texture2D>& texture, int entity_id,
float tiling_factor = 1.0f);
static void DrawQuad(const glm::mat4& transform,
const Ref<Texture2D>& texture, const glm::vec4& color,
int entity_id, float tiling_factor = 1.0f);
static void DrawQuad(const glm::mat4& transform,
const Ref<Subtexture2D>& subtexture, int entity_id,
float tiling_factor = 1.0f);

View File

@@ -0,0 +1,21 @@
#include <pch.hpp>
#include <renderer/uniform_buffer.hpp>
#include <opengl/opengl_uniform_buffer.hpp>
#include <renderer/renderer.hpp>
namespace OpenEngine {
Ref<UniformBuffer> UniformBuffer::Create(uint32_t size, uint32_t binding)
{
switch (Renderer::GetAPI())
{
case RendererAPI::API::None: OE_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr;
case RendererAPI::API::OpenGL: return CreateRef<OpenGLUniformBuffer>(size, binding);
}
OE_CORE_ASSERT(false, "Unknown RendererAPI!");
return nullptr;
}
}

View File

@@ -0,0 +1,20 @@
#ifndef UNIFORM_BUFFER_HPP
#define UNIFORM_BUFFER_HPP
#include <cstdint>
#include <glm/fwd.hpp>
namespace OpenEngine {
class UniformBuffer
{
public:
virtual ~UniformBuffer() {}
virtual void SetData(const void* data, uint32_t size,
uint32_t offset = 0) = 0;
static Ref<UniformBuffer> Create(uint32_t size, uint32_t binding);
};
}
#endif // UNIFORM_BUFFER_HPP

View File

@@ -3,6 +3,7 @@
#include "open_engine/scene/native_scriptable_entity.hpp"
#include "open_engine/scene/scene_camera.hpp"
#include "open_engine/renderer/texture.hpp"
#include <glm/ext/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
@@ -45,6 +46,8 @@ namespace OpenEngine {
struct SpriteRendererComponent
{
glm::vec4 color{ 1.0f, 1.0f, 1.0f, 1.0f };
Ref<Texture2D> texture;
float tiling_factor = 1.0f;
SpriteRendererComponent() = default;
SpriteRendererComponent(const SpriteRendererComponent&) = default;

View File

@@ -22,7 +22,10 @@ namespace OpenEngine {
T& AddComponents(Args&&... args)
{
OE_ASSERT(!HasComponent<T>(), "Entity already has component.");
return scene->registry.emplace<T>(handle, std::forward<Args>(args)...);
T& component = scene->registry.emplace<T>(handle, std::forward<Args>(args)...);
scene->OnComponentAdded(*this, component);
return component;
};
template<typename T, typename ... Args>

View File

@@ -27,6 +27,10 @@ namespace OpenEngine {
Entity GetPrimaryCamera();
private:
template<typename T>
void OnComponentAdded(Entity entity, T& component);
private:
entt::registry registry;