Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Texture.hpp
1#pragma once
2#include "resources/Image.hpp"
3#include "graphics/GPUTypes.hpp"
4#include "Common.hpp"
5
6class GPUTexture;
7
12class Texture {
13public:
14
18 Texture(const std::string & name);
19
24 void upload(const Layout & layout, bool updateMipmaps);
25
27 void clearImages();
28
34 void allocateImages(uint channels, uint firstMip = 0, uint mipCount = 0xFFFFFFFF);
35
39 void clean();
40
45 glm::vec3 sampleCubemap(const glm::vec3 & dir) const;
46
55 void setupAsDrawable(const Layout& layout, uint width, uint height, TextureShape shape = TextureShape::D2, uint mips = 1, uint depth = 1);
56
60 void resize(const glm::vec2& resolution);
61
66 void resize(uint w, uint h);
67
71 const std::string & name() const;
72
76 uint getMaxMipLevel() const;
77
81 Texture & operator=(const Texture &) = delete;
82
84 Texture(const Texture &) = delete;
85
89 Texture & operator=(Texture &&) = default;
90
93
94 ~Texture();
95
96 std::vector<Image> images;
97 std::unique_ptr<GPUTexture> gpu;
98
99 uint width = 0;
100 uint height = 0;
101 uint depth = 1;
102 uint levels = 1;
103
104 TextureShape shape = TextureShape::D2;
105
106 Layout format = Layout::NONE;
107 bool drawable = false;
108
109private:
110
111 std::string _name;
112
113};
114
115namespace ImGui {
116
125 void Image(const Texture & texture, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
126
137 bool ImageButton(const char* id, const Texture & texture, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1));
138
139}
Store a texture data on the GPU.
Definition: GPUObjects.hpp:18
Represents an image composed of pixels with values in [0,1]. Provide image loading/saving utilities,...
Definition: Image.hpp:8
Represents a texture containing one or more images, stored on the CPU and/or GPU.
Definition: Texture.hpp:12
uint levels
The mipmap count.
Definition: Texture.hpp:102
TextureShape shape
Texure type.
Definition: Texture.hpp:104
glm::vec3 sampleCubemap(const glm::vec3 &dir) const
Definition: Texture.cpp:141
uint getMaxMipLevel() const
Definition: Texture.cpp:34
void clean()
Definition: Texture.cpp:85
uint depth
The texture depth.
Definition: Texture.hpp:101
Texture & operator=(const Texture &)=delete
Layout format
Layout used.
Definition: Texture.hpp:106
void upload(const Layout &layout, bool updateMipmaps)
Definition: Texture.cpp:12
uint width
The texture width.
Definition: Texture.hpp:99
Texture(const Texture &)=delete
void setupAsDrawable(const Layout &layout, uint width, uint height, TextureShape shape=TextureShape::D2, uint mips=1, uint depth=1)
Definition: Texture.cpp:100
std::string _name
Resource name.
Definition: Texture.hpp:111
void resize(const glm::vec2 &resolution)
Definition: Texture.cpp:132
std::vector< Image > images
The images CPU data (optional).
Definition: Texture.hpp:96
bool drawable
Can the texture be rendered to.
Definition: Texture.hpp:107
Texture & operator=(Texture &&)=default
void clearImages()
Definition: Texture.cpp:46
std::unique_ptr< GPUTexture > gpu
The GPU data (optional).
Definition: Texture.hpp:97
const std::string & name() const
Definition: Texture.cpp:193
void allocateImages(uint channels, uint firstMip=0, uint mipCount=0xFFFFFFFF)
Definition: Texture.cpp:50
uint height
The texture height.
Definition: Texture.hpp:100
Texture(Texture &&)
TextureShape
The shape of a texture: dimensions, layers organisation.
Definition: GPUTypes.hpp:153
Layout
The layout of a texture: components count and type.
Definition: GPUTypes.hpp:225