Josh's Graphics Library
Texture.h
Go to the documentation of this file.
1#pragma once
2#include <ReImage/Image.h>
3#include <J3ML/LinearAlgebra.hpp>
4#include <Color3.hpp>
5#include <Color4.hpp>
6#include <glad/glad.h>
7
8namespace JGL {
9 using namespace ReImage;
10 enum class TextureFilteringMode : u8 {
11 NEAREST = 0, //Fastest for 2D, Sometimes causes graphical issues.
12 BILINEAR = 1, //Fast and pretty, The best for 2D.
13
14 MIPMAP_NEAREST = 2, //Nearest with mipmaps. The fastest for 3D, Sometimes causes graphical issues. Uses more vram.
15 MIPMAP_BILINEAR = 3, //Bilinear with mipmaps, Fast and pretty. Uses more vram.
16 MIPMAP_TRILINEAR = 4 //The prettiest. Still decent speed. Uses more vram.
17 };
18
19 enum class TextureWrappingMode : u8 {
20 REPEAT = 0,
22 CLAMP_TO_EDGE = 2,
23 CLAMP_TO_BORDER = 3 //Effectively the same as clamp_to_edge
24 };
25
27 class Texture {
28 private:
29 void Erase();
30 protected:
31 GLuint texture_handle = 0;
32 Vector2 texture_size = {0, 0};
33 ReImage::TextureFlag texture_flags;
34 ReImage::TextureFormat texture_format;
37 void load(Image* software_texture, const Vector2& size, const TextureFormat& format, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode);
38 public:
40 explicit Texture(const std::string& file, TextureFilteringMode filtering_mode = TextureFilteringMode::BILINEAR, TextureWrappingMode wrapping_mode = TextureWrappingMode::CLAMP_TO_EDGE, const TextureFlag& flags = TextureFlag::INVERT_Y);
41 Texture(Image* software_texture, const Vector2& size, const TextureFormat& format, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode);
42 /* Initialize a texture filled with trash data
43 this is primarily for the RenderTarget */
44 explicit Texture(const Vector2& size);
45 Texture(const Texture& rhs);
46 ~Texture();
47 public:
48 [[nodiscard]] GLuint GetGLTextureHandle() const;
49 [[nodiscard]] Vector2 GetDimensions() const;
50 [[nodiscard]] TextureFilteringMode GetFilteringMode() const;
51 [[nodiscard]] TextureWrappingMode GetWrappingMode() const;
52 [[nodiscard]] TextureFlag GetFlags() const;
53 [[nodiscard]] TextureFormat GetFormat() const;
54 [[nodiscard]] std::vector<Color4> GetPixelData() const;
55 };
56
57}
Represents texture data loaded on the GPU. Contains a handle that can be passed to OpenGL draw calls.
Definition: Texture.h:27
GLuint texture_handle
Definition: Texture.h:31
Vector2 texture_size
Definition: Texture.h:32
ReImage::TextureFormat texture_format
Definition: Texture.h:34
TextureFormat GetFormat() const
Definition: Texture.cpp:153
TextureFilteringMode texture_filtering_mode
Definition: Texture.h:35
~Texture()
Definition: Texture.cpp:170
void load(Image *software_texture, const Vector2 &size, const TextureFormat &format, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode)
Definition: Texture.cpp:47
std::vector< Color4 > GetPixelData() const
Definition: Texture.cpp:112
GLuint GetGLTextureHandle() const
Definition: Texture.cpp:141
TextureFilteringMode GetFilteringMode() const
Definition: Texture.cpp:157
ReImage::TextureFlag texture_flags
Definition: Texture.h:33
TextureWrappingMode GetWrappingMode() const
Definition: Texture.cpp:161
TextureFlag GetFlags() const
Definition: Texture.cpp:149
TextureWrappingMode texture_wrapping_mode
Definition: Texture.h:36
Texture(const std::string &file, TextureFilteringMode filtering_mode=TextureFilteringMode::BILINEAR, TextureWrappingMode wrapping_mode=TextureWrappingMode::CLAMP_TO_EDGE, const TextureFlag &flags=TextureFlag::INVERT_Y)
Load a texture from a file,.
Definition: Texture.cpp:9
Vector2 GetDimensions() const
Definition: Texture.cpp:145
OpenGL Wrapper for rendering 2D & 3D graphics in both a 2D and 3D context.
Definition: JGL.h:31
TextureWrappingMode
Definition: Texture.h:19
TextureFilteringMode
Definition: Texture.h:10