GLTexture class
#include <nCine/Graphics/RHI/GL/GLTexture.h>
Wraps an OpenGL texture object.
Manages the lifetime of a single OpenGL texture object of a given TextureTarget. Binding is cached per texture unit, and the currently active unit is tracked, so that redundant glActiveTexture() and glBindTexture() calls are skipped. Provides image upload, immutable storage allocation, readback and parameter setting through a backend-neutral surface (aliased as RHI::Texture): all OpenGL formats, filters, wrap and swizzle enums are translated inside the backend, so callers only ever pass PixelFormat, SamplerFilter, SamplerWrapping and SwizzleChannel values.
Public static variables
-
static std::
uint32_t MaxTextureUnits constexpr - Number of texture units tracked by the bind cache.
Public static functions
-
static auto Unbind(GLenum target,
std::
uint32_t textureUnit) -> bool - Unbinds any texture of the given target from the specified texture unit.
-
static auto Unbind(std::
uint32_t textureUnit) -> bool - Unbinds any
GL_TEXTURE_2Dtexture from the specified texture unit. -
static void SetUnpackAlignment(std::
int32_t alignment) - Sets the byte alignment of client pixel rows read by the upload calls.
- static auto SupportsImmutableStorage() -> bool
- Returns
trueif immutable texture storage (TexStorage2D) is available. - static auto SupportsTextureReadback() -> bool
- Returns
trueif the device can read texel data back into client memory. - static void ClearErrors()
- Discards any pending device error state.
- static auto CheckErrors() -> bool
- Returns
trueif the device reported an error since the last ClearErrors(), and clears it. - static void CheckFormatSupport(PixelFormat format)
- Verifies that the device supports the given pixel format, aborting if it does not.
Constructors, destructors, conversion operators
- GLTexture(TextureTarget target) explicit
- ~GLTexture()
- GLTexture(const GLTexture&) deleted
Public functions
- auto operator=(const GLTexture&) -> GLTexture& deleted
- auto GetGLHandle() const -> GLuint
- Returns the OpenGL handle of the texture object.
-
auto GetUniqueId() const -> std::
uint32_t - Returns a backend-neutral identifier uniquely identifying the texture (feeds material sort keys).
- auto GetTarget() const -> GLenum
- Returns the target of the texture (e.g.,
GL_TEXTURE_2D). -
auto Bind(std::
uint32_t textureUnit) const -> bool - Binds the texture to the specified texture unit.
- auto Bind() const -> bool
- Binds the texture to texture unit 0.
- auto Unbind() const -> bool
- Unbinds the texture from the unit it was last bound to.
-
void TexImage2D(std::
int32_t level, PixelFormat format, bool bgr, std:: int32_t width, std:: int32_t height, const void* data) - Specifies a two-dimensional image for the given mipmap level.
-
void TexSubImage2D(std::
int32_t level, std:: int32_t xoffset, std:: int32_t yoffset, std:: int32_t width, std:: int32_t height, PixelFormat format, bool bgr, const void* data) - Updates a rectangular subregion of a two-dimensional mipmap level.
-
void CompressedTexImage2D(std::
int32_t level, PixelFormat format, std:: int32_t width, std:: int32_t height, std:: int32_t imageSize, const void* data) - Specifies a compressed two-dimensional image for the given mipmap level.
-
void CompressedTexSubImage2D(std::
int32_t level, std:: int32_t xoffset, std:: int32_t yoffset, std:: int32_t width, std:: int32_t height, PixelFormat format, std:: int32_t imageSize, const void* data) - Updates a rectangular subregion of a compressed two-dimensional mipmap level.
-
void TexStorage2D(std::
int32_t levels, PixelFormat format, std:: int32_t width, std:: int32_t height) - Allocates an immutable two-dimensional storage with the given number of mipmap levels.
-
void GetTexImage(std::
int32_t level, PixelFormat format, bool bgr, void* pixels) - Reads back a mipmap level of the texture into client memory (desktop only).
- void SetMinFiltering(SamplerFilter filter)
- Sets the minification filtering mode.
- void SetMagFiltering(SamplerFilter filter)
- Sets the magnification filtering mode.
- void SetWrap(SamplerWrapping wrap)
- Sets the wrapping mode for both
sandtcoordinates. - void SetSwizzle(SwizzleChannel r, SwizzleChannel g, SwizzleChannel b, SwizzleChannel a)
- Remaps the channels returned when the texture is sampled.
-
void SetMaxLevel(std::
int32_t maxLevel) - Sets the highest mipmap level that is defined.
- void TexParameterf(GLenum pname, GLfloat param)
- Sets a floating-point texture parameter.
- void TexParameteri(GLenum pname, GLint param)
- Sets an integer texture parameter (e.g., filter or wrap mode).
- void SetObjectLabel(StringView label)
- Sets an OpenGL object label for the texture, for debugging.
Function documentation
bool nCine:: RHI:: GL:: GLTexture:: Bind(std:: uint32_t textureUnit) const
Binds the texture to the specified texture unit.
| Returns | true if a glBindTexture() call was issued, false if it was already bound |
|---|