Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
texture.h
1#ifndef OE_RENDER_TEXTURE_H
2#define OE_RENDER_TEXTURE_H
3
4#include <string>
5#include <functional>
6#include <glm/vec2.hpp>
7#include <glm/vec4.hpp>
8#include "../util/byte_array.h"
9
10namespace oe::scene
11{
12 class Material;
13}
14
15namespace oe::render
16{
17 class Shader;
18 class TextureManager;
19 class Framebuffer;
20
21 enum class ColorSpace
22 {
23 SRGB,
24 Linear,
25 };
26
30 class Texture
31 {
32 public:
38 explicit Texture(const uint32_t opengl_id);
39
40 Texture(const Texture&) = delete;
41 Texture& operator=(const Texture&) = delete;
42
43 Texture(Texture&& other) noexcept:
44 _internal_id(other.releaseOwnership()),
45 _internal_format(other._internal_format),
46 _format(other._format),
47 _type(other._type)
48 {}
49
54 const int32_t width,
55 const int32_t height,
56 const uint8_t* data,
57 const int32_t nb_channels = 0, // Used as hint to fill formats/type if no other argument provided after
58 const int32_t internal_format = 0,
59 const int32_t format = 0,
60 const int32_t type = 0,
61 const uint8_t max_mips = 1
62 );
63
77 const ByteSpan data,
78 const ColorSpace color_space,
79 const int32_t wanted_channels = 4,
80 const uint8_t max_mips = 1
81 );
82
90 Texture(const std::string& filename, const ColorSpace color_space, const uint8_t max_mips = 1);
91
96 const uint32_t width,
97 const uint32_t height,
98 const std::function<glm::vec4(const uint32_t i, const uint32_t j)> generator,
99 const uint8_t max_mips = 1
100 );
101
106 const uint32_t width,
107 const uint32_t height,
108 const oe::scene::Material& generator,
109 const int32_t nb_channels = 0,
110 const int32_t internal_format = 0,
111 const int32_t format = 0,
112 const int32_t type = 0,
113 const uint8_t max_mips = 1
114 );
115
116 // Commented: Not work and never used and
117 /*static Texture* generateFromCompressed(
118 const int32_t compression,
119 const int32_t width,
120 const int32_t height,
121 const int32_t data_size,
122 const uint8_t* data
123 );*/
124
125 virtual ~Texture();
126
127 void use(const uint8_t layer);
128
129 virtual void enableBilinearFiltering(bool enabled = true);
130
131 virtual void generateMipMaps();
132
133 void clampToEdge();
134 void wrapRepeat();
135
136 void fillTextureData(ByteSpan data, const uint32_t face, const uint32_t mip_level);
137
141 ByteArray fetchTextureData(const uint32_t face, const uint32_t mip_level);
142
148 glm::ivec2 getDimensions(const uint8_t mip_level = 0) const;
149
161
162 protected:
163 Texture()
164 {}
165
166 void _generate_texture
167 (
168 const int32_t width,
169 const int32_t height,
170 const uint8_t* data,
171 const int32_t nb_channels = 0,
172 const int32_t internal_format = 0,
173 const int32_t format = 0,
174 const int32_t type = 0,
175 const uint8_t max_mips = 1
176 );
177
178 uint32_t _internal_id = 0;
179
180 // Might be removed (_format / _type depends on image to fill and not need to be stored)
181 int32_t _internal_format = 0;
182 int32_t _format = 0;
183 int32_t _type = 0;
184
185 friend class Framebuffer;
186 friend class DynamicCubemap;
187 };
188}
189
190#endif
Definition dynamic_cubemap.h:12
Definition framebuffer.h:53
Definition texture.h:31
uint32_t releaseOwnership()
Get ownership of the internal handle (to prevent external texture being destroyed) Only do this if yo...
Texture(const std::string &filename, const ColorSpace color_space, const uint8_t max_mips=1)
Load texture from a file.
ByteArray fetchTextureData(const uint32_t face, const uint32_t mip_level)
Get texture data from OpenGL memory.
Texture(const uint32_t opengl_id)
Create a texture using an existing OpenGL handle.
Texture(const uint32_t width, const uint32_t height, const oe::scene::Material &generator, const int32_t nb_channels=0, const int32_t internal_format=0, const int32_t format=0, const int32_t type=0, const uint8_t max_mips=1)
Generate a texture from a material.
Texture(const int32_t width, const int32_t height, const uint8_t *data, const int32_t nb_channels=0, const int32_t internal_format=0, const int32_t format=0, const int32_t type=0, const uint8_t max_mips=1)
Load texture from raw gpu image data.
Texture(const uint32_t width, const uint32_t height, const std::function< glm::vec4(const uint32_t i, const uint32_t j)> generator, const uint8_t max_mips=1)
Generate a RGBA texture from a function returning a vec4.
Texture(const ByteSpan data, const ColorSpace color_space, const int32_t wanted_channels=4, const uint8_t max_mips=1)
Load texture from an image stored in memory.
glm::ivec2 getDimensions(const uint8_t mip_level=0) const
Get dimensions of the texture.
Render agnostic material.
Definition material.h:90
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures)
Definition opengl.h:10
ColorSpace
Definition texture.h:22
@ SRGB
Texture contains sRGB color (Albedo or Emissive)
@ Linear
Texture technical data that should be kept as-is (Normalmap, RouMetAo)
Scene related management (Render-agnostic Geometry, Manger, etc...)
Definition debug.h:19