Textures¶
/* Declaration */
GPUTexture m_texture;
/* Loading a .png file */
Texture::CreateFromRGBAFile(&m_texture, "myimage.png");
/* Set a default sampler (trilinear) */
Texture::SetParameters(&m_texture, SamplerDesc::Default2D());
/* Bind before renderin */
Texture::BindToUnit(m_texture,0u);
How to create an empty texture for a framebuffer:
TextureDesc desc = {};
desc.width = 256u;
desc.height = 256u;
desc.pixeltype = GL_UNSIGNED_BYTE;
desc.internal = GL_RGBA8;
desc.format = GL_RGBA;
Texture::CreateEmpty2D(&m_simple_texture,desc);
TextureDesc Description¶
-
struct SamplerDesc¶
OpenGL texture sampler description data structure.
Public Members
-
uint32_t wrap_u = 0¶
OpenGL flag for texture wrapping U
-
uint32_t wrap_v = 0¶
OpenGL flag for texture wrapping V
-
uint32_t wrap_w = 0¶
OpenGL flag for texture wrapping W
-
uint32_t minification = 0¶
OpenGL flag for texture minification
-
uint32_t magnification = 0¶
OpenGL flag for texture magnification
-
bool mipmap = false¶
is mipmap generation enabled ?
-
bool anisotropy = false¶
is anisotropic filtering enabled ? does the the hardware supports it ?
Public Static Functions
-
static SamplerDesc Default2D()¶
Create a 2D default sampler object.
Create a 2D sampler with the following parameters:
wrap : GL_REPEAT
mag : GL_LINEAR
min : GL_LINEAR_MIPMAP_LINEAR
mips : true
- Parameters:
s – A pointer to a GPUSampler
-
static SamplerDesc Default3D()¶
Create a 3D default sampler object.
Create a 2D sampler with the following parameters:
wrap : GL_REPEAT
mag : GL_LINEAR
min : GL_LINEAR_MIPMAP_LINEAR
mips : true
- Parameters:
s – A pointer to a GPUSampler
-
static SamplerDesc Create2D(uint32_t wrap, uint32_t mag, uint32_t min, bool mips)¶
Create a 2D sampler.
- Parameters:
wrap – Wrap parameter for texture coordinates s,t in
GL_CLAMP_TO_EDGE
GL_MIRRORED_REPEAT
GL_REPEAT
mag – Texture magnification flag (used when pixel maps to an area less than or equal to one texture element )
GL_NEAREST : nearest manhattan distance value to the center of the textured pixel.
GL_LINEAR : weighted average of the four elements thats are closest to the center of the textured pixel.
min – Texture minification flag (used when pixel maps to an area greater than one texture element )
GL_NEAREST : nearest manhattan distance value to the center of the textured pixel.
GL_LINEAR : weighted average of the four elements thats are closest to the center of the textured pixel.
GL_NEAREST_MIPMAP_NEAREST : closest mipmap matching the size of the texture pixel and uses the nearest criterion.
GL_NEAREST_MIPMAP_LINEAR : closest mipmap matching the size of the texture pixel and uses the weighted average criterion.
GL_LINEAR_MIPMAP_NEAREST : choses the two closest mipmaps and averages the two nearest values for the textured pixel.
GL_LINEAR_MIPMAP_LINEAR : choses the two closest mipmaps and averages the two averaged values for the final textured pixel.
mips – Enables MipMapping
-
static SamplerDesc Create3D(uint32_t wrap, uint32_t mag, uint32_t min, bool mips)¶
Create a 3D sampler.
- Parameters:
wrap – Wrap parameter for texture coordinates s,t,u in
GL_CLAMP_TO_EDGE
GL_MIRRORED_REPEAT
GL_REPEAT
mag – Texture magnification flag (used when pixel maps to an area less than or equal to one texture element )
GL_NEAREST : nearest manhattan distance value to the center of the textured pixel.
GL_LINEAR : weighted average of the four elements thats are closest to the center of the textured pixel.
min – Texture minification flag (used when pixel maps to an area greater than one texture element )
GL_NEAREST : nearest manhattan distance value to the center of the textured pixel.
GL_LINEAR : weighted average of the four elements thats are closest to the center of the textured pixel.
GL_NEAREST_MIPMAP_NEAREST : closest mipmap matching the size of the texture pixel and uses the nearest criterion.
GL_NEAREST_MIPMAP_LINEAR : closest mipmap matching the size of the texture pixel and uses the weighted average criterion.
GL_LINEAR_MIPMAP_NEAREST : choses the two closest mipmaps and averages the two nearest values for the textured pixel.
GL_LINEAR_MIPMAP_LINEAR : choses the two closest mipmaps and averages the two averaged values for the final textured pixel.
mips – Enables MipMapping
-
static SamplerDesc Create2DAnisotropic(uint32_t wrap)¶
Create a 2D sampler and prepare anisotropic mipmapping if hardware supports it.
Texture minification and magnification are automatically set. If hardware doesn’t support anisotropy, switch to trilinear. REQUIRES GL BACKEND 4.6
- Parameters:
wrap – Wrap parameter for texture coordinates s,t,u in
GL_CLAMP_TO_EDGE
GL_MIRRORED_REPEAT
GL_REPEAT
-
uint32_t wrap_u = 0¶
-
struct TextureDesc¶
OpenGL texture description data structure.
Public Members
-
uint32_t width = 0¶
OpenGL GLuint texture Width (pixels)
-
uint32_t height = 0¶
OpenGL GLuint texture Height (pixels)
-
uint32_t depth = 0¶
OpenGL GLuint texture Depth or Layers (pixels/layers)
-
uint32_t internal = 0¶
OpenGL GLuint texture sized format (GL_RGBA8, GL_R32F, etc.)
-
uint32_t format = 0¶
OpenGL 3.3 GLuint texture format (GL_RED, GL_RGB, GL_RGBA, etc.)
-
uint32_t pixeltype = 0¶
OpenGL 3.3 GLuint texture pixel data type (GL_UNSIGNED_BYTE, GL_FLOAT, etc.)
Public Static Functions
-
static TextureDesc Create2D(uint32_t width, uint32_t height, uint32_t internal)¶
Returns a 2D texture description (width, height, internal sized format)
-
static TextureDesc Create2D(uint32_t width, uint32_t height, uint32_t internal, uint32_t format, uint32_t pixeltype)¶
Returns a 2D texture description (width, height, internal sized format, format, pixel data type)
-
static TextureDesc Create3D(uint32_t width, uint32_t height, uint32_t depth, uint32_t internal)¶
Returns a 3D texture description (width, height, depth, internal sized format)
-
static TextureDesc Create3D(uint32_t width, uint32_t height, uint32_t depth, uint32_t internal, uint32_t format, uint32_t pixeltype)¶
Returns a 3D texture description (width, height, depth, internal sized format, format, pixel data type)
-
static TextureDesc CreateCubeMap(uint32_t size, uint32_t internal)¶
Returns a Cubemap texture description (cube size, internal sized format)
-
static TextureDesc CreateCubeMap(uint32_t size, uint32_t internal, uint32_t format, uint32_t pixeltype)¶
Returns a Cubemap texture description (cube size, internal sized format, format, pixel data type)
-
uint32_t width = 0¶
-
struct GPUTexture¶
OpenGL texture data structure.
Texture API Description¶
-
namespace Texture¶
Functions
-
void CreateEmpty2D(GPUTexture *t, const TextureDesc &desc)¶
Create a empty 2D texture.
- Parameters:
t – A GPUTexture pointer
desc – The requested texture description (Required: desc.width, desc.height, desc.internal, (gl3.3 desc.format), (gl3.3 desc.pixeltype))
-
void CreateEmpty3D(GPUTexture *t, const TextureDesc &desc)¶
Create a empty 3D texture.
- Parameters:
t – A GPUTexture pointer
desc – The requested texture description (Required: desc.width, desc.height, desc.depth, desc.internal, (gl3.3 desc.format), (gl3.3 desc.pixeltype))
-
void CreateEmpty2DArray(GPUTexture *t, const TextureDesc &desc)¶
Create a empty 2D texture array.
- Parameters:
t – A GPUTexture pointer
desc – The requested texture description (Required: desc.width, desc.height, desc.depth, desc.internal, (gl3.3 desc.format), (gl3.3 desc.pixeltype))
-
void CreateEmptyCubemap(GPUTexture *t, const TextureDesc &desc)¶
Create a empty 2D cubemap texture.
- Parameters:
t – A GPUTexture pointer
desc – The requested texture description (Required: desc.width, desc.internal, (gl3.3 desc.format), (gl3.3 desc.pixeltype))
-
void CreateEmpty2DMultisample(GPUTexture *t, const TextureDesc &desc, uint8_t samples)¶
Create a empty 2D multisampled texture.
- Parameters:
t – A GPUTexture pointer
desc – The requested texture description (Required: desc.width, desc.height, desc.internal, (gl3.3 desc.format), (gl3.3 desc.pixeltype))
samples – Number of samples in the texture
-
void CreateEmpty2DArrayMultisample(GPUTexture *t, const TextureDesc &desc, uint8_t samples)¶
Create a empty 2D multisampled texture array.
- Parameters:
t – A GPUTexture pointer
desc – The requested texture description (Required: desc.width, desc.height, desc.internal, (gl3.3 desc.format), (gl3.3 desc.pixeltype))
samples – Number of samples in the texture
-
void CreateFromRGBAFile(GPUTexture *t, const std::string &filepath, bool flip = true)¶
Create a texture from a rgba file (png, jpg)
- Parameters:
t – A GPUTexture pointer
filepath – The path to the .hdr file
flip – Performs a vertical flip of the texture content
-
void CreateFromHDRIFile(GPUTexture *t, const std::string &filepath, bool flip = true)¶
Create a texture from hdri file.
- Parameters:
t – A GPUTexture pointer
filepath – The path to the .hdr file
flip – Performs a vertical flip of the texture content
-
void CreateFromCopy2D(GPUTexture *t, const GPUTexture &texture_to_copy)¶
Create a copy of a 2D texture.
-
void CreateFromCopy3D(GPUTexture *t, const GPUTexture &texture_to_copy)¶
Create a copy of a 3D texture.
-
void Destroy(GPUTexture *t)¶
Destroy gpu texture ressource.
-
void Copy(const GPUTexture &source, const GPUTexture &target)¶
Copy content from another gpu texture ressource.
-
void SetParameters(GPUTexture *t, const SamplerDesc &s)¶
Apply sampler parameters to the input texture.
-
void SetParameters(GPUTexture *t, uint32_t wrap, uint32_t mag, uint32_t min, bool mips)¶
Manually apply specific parameters to the input texture.
-
void SetBorderColor(GPUTexture *t, float *c)¶
Manually set the border color of the input texture.
-
void GenerateMipmap(GPUTexture *t)¶
Manually generate the mipmap chain of the input texture.
-
void BindToUnit(const GPUTexture &t, uint32_t unit)¶
Bind the texture ressource to the binding point.
-
void BindImageTexture(const GPUTexture &t, uint32_t unit, uint32_t access, uint32_t level = 0u)¶
Bind the image texture ressource to the binding point with the following access (used in compute shader)
-
void BindImageTextureLayered(const GPUTexture &t, uint32_t unit, uint32_t layer, uint32_t access, uint32_t level = 0u)¶
Bind the layered image texture ressource to the binding point with the following access (used in compute shader)
-
void CreateEmpty2D(GPUTexture *t, const TextureDesc &desc)¶