Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
oe::render::Texture Class Reference

#include <OxygenEngine/render/texture.h>

+ Inheritance diagram for oe::render::Texture:

Public Member Functions

 Texture (const uint32_t opengl_id)
 Create a texture using an existing OpenGL handle.
 
 Texture (const Texture &)=delete
 
Textureoperator= (const Texture &)=delete
 
 Texture (Texture &&other) noexcept
 
 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 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.
 
 Texture (const std::string &filename, const ColorSpace color_space, const uint8_t max_mips=1)
 Load texture from a file.
 
 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 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.
 
void use (const uint8_t layer)
 
virtual void enableBilinearFiltering (bool enabled=true)
 
virtual void generateMipMaps ()
 
void clampToEdge ()
 
void wrapRepeat ()
 
void fillTextureData (ByteSpan data, const uint32_t face, const uint32_t mip_level)
 
ByteArray fetchTextureData (const uint32_t face, const uint32_t mip_level)
 Get texture data from OpenGL memory.
 
glm::ivec2 getDimensions (const uint8_t mip_level=0) const
 Get dimensions of the texture.
 
uint32_t releaseOwnership ()
 Get ownership of the internal handle (to prevent external texture being destroyed) Only do this if you know what you are doing.
 

Protected Member Functions

void _generate_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)
 

Protected Attributes

uint32_t _internal_id = 0
 
int32_t _internal_format = 0
 
int32_t _format = 0
 
int32_t _type = 0
 

Friends

class Framebuffer
 
class DynamicCubemap
 

Detailed Description

Texture wrapper

Constructor & Destructor Documentation

◆ Texture() [1/3]

oe::render::Texture::Texture ( const uint32_t  opengl_id)
explicit

Create a texture using an existing OpenGL handle.

Note
If you want to prevent the handle being destroyed with the Texture, call release() before instance destruction

◆ Texture() [2/3]

oe::render::Texture::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.

Parameters
dataThe image file data
color_spaceTexture color space (sRGB or linear)
wanted_channelsNumber of channels wanted in the final texture (1 for greyscale, 2 for "greyscale + alpha", 3 is for RGB, and 4 is for RGBA)
max_mipsMaximum mipmaps

Supports JPG, PNG, GIF (first frame only), TGA, BMP images

See also
stbi_load_from_memory documentation for more info about images formats

◆ Texture() [3/3]

oe::render::Texture::Texture ( const std::string &  filename,
const ColorSpace  color_space,
const uint8_t  max_mips = 1 
)

Load texture from a file.

Parameters
filenameThe image file
color_spaceTexture color space (sRGB or linear)
Note
You can omit the extension, this method will try the following extensions in order: .tga, .jpg, .png

Member Function Documentation

◆ getDimensions()

glm::ivec2 oe::render::Texture::getDimensions ( const uint8_t  mip_level = 0) const

Get dimensions of the texture.

Parameters
mip_levelLevel of MipMap to fetch dimensions

◆ releaseOwnership()

uint32_t oe::render::Texture::releaseOwnership ( )

Get ownership of the internal handle (to prevent external texture being destroyed) Only do this if you know what you are doing.

Mainly used when the texture has been created using an external id and is managed by other library

Note
Please don't use this instance anymore: The texture instance won't work after calling this function
Returns
Texture handle

The documentation for this class was generated from the following file: