From 1ad6bc34323f5b30d463ebe47a58d47ff9d4f328 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 12 Aug 2025 19:17:50 +0200 Subject: [add]: 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 d08d015..82c156e 100644 --- a/src/Rendering/Renderer.h +++ b/src/Rendering/Renderer.h @@ -34,6 +34,7 @@ namespace Donut virtual void SetClearColor(const glm::vec4& color) = 0; virtual void Clear() = 0; virtual void EnableDepthTest() = 0; + virtual void SetFaceCulling(bool enabled) = 0; virtual void DrawIndexed(const std::shared_ptr& vertexArray, uint32_t indexCount = 0) = 0; @@ -72,6 +73,11 @@ namespace Donut s_RendererAPI->EnableDepthTest(); } + inline static void SetFaceCulling(bool enabled) + { + s_RendererAPI->SetFaceCulling(enabled); + } + inline static void DrawIndexed(const std::shared_ptr& vertexArray, uint32_t indexCount = 0) { s_RendererAPI->DrawIndexed(vertexArray, indexCount); diff --git a/src/Rendering/Texture.cpp b/src/Rendering/Texture.cpp new file mode 100644 index 0000000..a52a469 --- /dev/null +++ b/src/Rendering/Texture.cpp @@ -0,0 +1,32 @@ +#include "Texture.h" +#include "Renderer.h" +#include "../Platform/OpenGL/OpenGLTexture.h" + +namespace Donut +{ + std::shared_ptr Texture2D::Create(uint32_t width, uint32_t height) + { + switch (Renderer::GetAPI()) + { + 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::GetAPI()) + { + case RendererAPI::API::OpenGL: + return std::make_shared(path); + case RendererAPI::API::None: + return nullptr; + default: + return nullptr; + } + } +}; \ No newline at end of file diff --git a/src/Rendering/Texture.h b/src/Rendering/Texture.h new file mode 100644 index 0000000..eebce85 --- /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 GetWidth() const = 0; + virtual uint32_t GetHeight() const = 0; + virtual uint32_t GetRendererID() const = 0; + + virtual void SetData(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); + }; +}; \ No newline at end of file -- cgit v1.3