|
1 | 1 | #pragma once |
2 | 2 |
|
3 | 3 | #include "Pyramid/Graphics/Texture.hpp" |
4 | | -#include <glad/glad.h> |
5 | 4 |
|
6 | | -namespace Pyramid { |
| 5 | +#include <glad/glad.h> |
7 | 6 |
|
8 | | -class OpenGLTexture2D : public ITexture2D |
| 7 | +namespace Pyramid |
9 | 8 | { |
10 | | -public: |
11 | | - OpenGLTexture2D(const TextureSpecification& specification, const void* data); |
12 | | - OpenGLTexture2D(const std::string& filepath, bool srgb, bool generateMips); |
13 | | - ~OpenGLTexture2D() override; |
| 9 | + class OpenGLTexture2D final : public ITexture2D |
| 10 | + { |
| 11 | + public: |
| 12 | + OpenGLTexture2D(const TextureSpecification& specification, const void* data); |
| 13 | + OpenGLTexture2D(const std::string& filepath, bool srgb, bool generateMips); |
| 14 | + ~OpenGLTexture2D() override; |
| 15 | + |
| 16 | + OpenGLTexture2D(const OpenGLTexture2D&) = delete; |
| 17 | + OpenGLTexture2D& operator=(const OpenGLTexture2D&) = delete; |
14 | 18 |
|
15 | | - void Bind(u32 slot = 0) const override; |
16 | | - void Unbind(u32 slot = 0) const override; |
| 19 | + void Bind(u32 slot = 0) const override; |
| 20 | + void Unbind(u32 slot = 0) const override; |
17 | 21 |
|
18 | | - u32 GetWidth() const override { return m_Specification.Width; } |
19 | | - u32 GetHeight() const override { return m_Specification.Height; } |
20 | | - u32 GetRendererID() const override { return m_RendererID; } |
21 | | - const std::string& GetPath() const override { return m_Filepath; } |
| 22 | + u32 GetWidth() const override { return m_Specification.Width; } |
| 23 | + u32 GetHeight() const override { return m_Specification.Height; } |
| 24 | + u32 GetRendererID() const override { return m_RendererID; } |
| 25 | + TextureFormat GetFormat() const override { return m_Specification.Format; } |
| 26 | + const std::string& GetPath() const override { return m_Filepath; } |
| 27 | + bool IsLoaded() const override { return m_IsLoaded; } |
| 28 | + std::string GetLastError() const override { return m_LastError; } |
22 | 29 |
|
23 | | - // virtual void SetData(void* data, u32 size) override; // Implement if needed |
| 30 | + void SetData(const void* data, u32 size) override; |
| 31 | + void GenerateMipmaps() override; |
| 32 | + u32 GetMipLevels() const override; |
| 33 | + bool LoadFromFile(const std::string& filepath, bool srgb = false, bool generateMips = true) override; |
24 | 34 |
|
25 | | -private: |
26 | | - void Invalidate(const void* data); // Helper to create/recreate texture |
27 | | - void SetParameters(); |
| 35 | + private: |
| 36 | + static bool ResolveFormats( |
| 37 | + TextureFormat format, |
| 38 | + bool srgb, |
| 39 | + GLenum& internalFormat, |
| 40 | + GLenum& dataFormat, |
| 41 | + u32& bytesPerPixel); |
| 42 | + static GLenum ToGLMinFilter(TextureFilter filter, bool hasMipmaps); |
| 43 | + static GLenum ToGLMagFilter(TextureFilter filter); |
| 44 | + static GLenum ToGLWrap(TextureWrap wrap); |
| 45 | + static bool HasMipmapFilter(TextureFilter filter); |
28 | 46 |
|
29 | | - TextureSpecification m_Specification; |
30 | | - std::string m_Filepath; // Empty if not loaded from file |
31 | | - GLuint m_RendererID = 0; |
32 | | - GLenum m_InternalFormat = GL_RGBA8; // Determined from TextureSpecification::Format |
33 | | - GLenum m_DataFormat = GL_RGBA; // Determined from TextureSpecification::Format |
34 | | -}; |
| 47 | + bool CreateTextureObject( |
| 48 | + const TextureSpecification& specification, |
| 49 | + GLenum internalFormat, |
| 50 | + GLenum dataFormat, |
| 51 | + const void* data, |
| 52 | + GLuint& texture, |
| 53 | + std::string& error) const; |
| 54 | + void ApplyParameters(const TextureSpecification& specification) const; |
| 55 | + void SetError(const std::string& error); |
35 | 56 |
|
| 57 | + TextureSpecification m_Specification; |
| 58 | + std::string m_Filepath; |
| 59 | + std::string m_LastError; |
| 60 | + GLuint m_RendererID = 0; |
| 61 | + GLenum m_InternalFormat = GL_RGBA8; |
| 62 | + GLenum m_DataFormat = GL_RGBA; |
| 63 | + u32 m_BytesPerPixel = 4; |
| 64 | + bool m_IsLoaded = false; |
| 65 | + }; |
36 | 66 | } // namespace Pyramid |
0 commit comments