From 3b02022fd79ad0e130b8c49e7707d221bfc97bb5 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 12 Aug 2025 19:17:50 +0200 Subject: feat: texture and pixel buffers --- src/rendering/renderer.h | 6 ++++++ src/rendering/texture.cpp | 32 ++++++++++++++++++++++++++++++++ src/rendering/texture.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/rendering/texture.cpp create mode 100644 src/rendering/texture.h (limited to 'src/rendering') diff --git a/src/rendering/renderer.h b/src/rendering/renderer.h index 09e9521..7bbdd4b 100644 --- a/src/rendering/renderer.h +++ b/src/rendering/renderer.h @@ -34,6 +34,7 @@ namespace Donut virtual void set_clear_color(const glm::vec4& color) = 0; virtual void clear() = 0; virtual void enable_depth_test() = 0; + virtual void set_face_culling(bool enabled) = 0; virtual void draw_indexed(const std::shared_ptr& vertex_array, uint32_t index_count = 0) = 0; @@ -72,6 +73,11 @@ namespace Donut s_renderer_api->enable_depth_test(); } + inline static void set_face_culling(bool enabled) + { + s_renderer_api->set_face_culling(enabled); + } + inline static void draw_indexed(const std::shared_ptr& vertex_array, uint32_t index_count = 0) { s_renderer_api->draw_indexed(vertex_array, index_count); diff --git a/src/rendering/texture.cpp b/src/rendering/texture.cpp new file mode 100644 index 0000000..9603034 --- /dev/null +++ b/src/rendering/texture.cpp @@ -0,0 +1,32 @@ +#include "texture.h" +#include "renderer.h" +#include "../platform/opengl/opengl_texture.h" + +namespace Donut +{ + std::shared_ptr Texture2D::create(uint32_t width, uint32_t height) + { + switch (Renderer::get_api()) + { + case RendererAPI::API::OpenGL: + return std::make_shared(width, height); + case RendererAPI::API::None: + return nullptr; + default: + return nullptr; + } + } + + std::shared_ptr Texture2D::create(const std::string& path) + { + switch (Renderer::get_api()) + { + case RendererAPI::API::OpenGL: + return std::make_shared(path); + case RendererAPI::API::None: + return nullptr; + default: + return nullptr; + } + } +}; diff --git a/src/rendering/texture.h b/src/rendering/texture.h new file mode 100644 index 0000000..e3c53f8 --- /dev/null +++ b/src/rendering/texture.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include + +namespace Donut +{ + class Texture + { + public: + virtual ~Texture() = default; + + virtual uint32_t get_width() const = 0; + virtual uint32_t get_height() const = 0; + virtual uint32_t get_renderer_id() const = 0; + + virtual void set_data(void* data, uint32_t size) = 0; + virtual void bind(uint32_t slot = 0) const = 0; + + virtual bool operator==(const Texture& other) const = 0; + }; + + class Texture2D : public Texture + { + public: + static std::shared_ptr create(uint32_t width, uint32_t height); + static std::shared_ptr create(const std::string& path); + }; +}; -- cgit v1.3