class SGFXAPI::Texture

This class represents a GPU-side texture.

Does not store the data on the CPU side.

See
getHandle(const Texture&)

Public Functions

Texture(TextureType texture_type, TextureInternalFormat internal_format, int width, int height, int depth, size_t mipmaps, int rowalignment, ResourceUsage usage)

Parameters
  • texture_type -

    The type of texture, 1D,2D,3D,arrays etc.

  • internal_format -

    A suggestion to the GPU of the type of format to store the image in, internally, on the GPU.

  • width -

    The width of the image; for 1D, the length of the image.

  • height -

    The height of the image, for 1D, this will be 1. For a 1D array, this will be the length of the array.

  • depth -

    The depth of the image, for 1D,2D, this will be 1. For a 2D array, this will be the length of the array.

  • mipmaps -

    The number of mipmaps this texture will have. If left out, it will expect to have the maximum number of mipmaps.

  • rowalignment -

    The data uploaded to the GPU is uploaded in “rows” of size width. Each row will have a “row alignment” which means that if the row’s length does not align with specified rowalignment, there will be padding until it aligns. Can only be one of 1, 2, 4, or 8. Defaults to 4. See UpdateToGpu().

  • usage -

    If the texture parameters will change or not (they won’t change under normal use, because the parameters are set in the ctor and cannot be changed). Defaults to UsageImmutable.

int MaxMimpapLevels() const

Given the dimensions and type of texture, this function returns the maximum number of mipmap levels.

void UpdateToGpu(int width, int height, int depth, TextureFormat textureFormat, const uint8_t *data, size_t dataBytesSize, int level, const std::string &debugName)

Set the data of a mipmap level of the texture.

Parameters
  • textureFormat -

    The format of the data being uploaded. The data will be stored according to the internal_format parameter in the ctor Texture::Texture().

  • data -

    pointer to a buffer with the data for the texture. If a PBO is bound, data is the offset into the PBO.

  • dataBytesSize -

    the size of the entire buffer. This is basically rowsize*width*height, where rowsize is (sizeperpixel*width) adjusted for rowalignment, specified in the ctor.

  • level -

    this specifies the mipmap level to upload the data for. Level 0 must be uploaded. Other levels are optional, depending on the mipmaps parameter specified in the Texture() ctor. Call GenMipmaps() to automatically generate the mipmaps from level 0.

void GenMipmaps()

Automatically generate mipmaps.

Call this after setting mipmap level 0.

See UpdateToGpu()

void Bind()

Activate this texture, to be used in the following calls; some methods of this class may require that this texture is in the “bound” state before using them.

See
UnBind(), UnBindAll(), IsBound()

void UnBind()

Deactivate this texture; this function checks with the driver that this texture is bound; and if it is not already bound, it is a noop; use UnBindAll() to clear the bound state of all/any texture.

See
Bind(), UnBindAll(), IsBound()

bool IsBound() const

Check if this texture is “bound”.

See
Bind(), UnBind(), UnBindAll()

int Width() const

Returns the width of the base-texture (mipmap level 0)

int Height() const

Returns the height of the base-texture (mipmap level 0).

  • If this is a 1D texture this will return a height of 1.
  • If this is a 1D texture array, this will return the number of elements in the array.

int Depth() const

Returns the depth of the base-texture (mipmap level 0).

  • If this is a 1D texture this will return a depth of 1.
  • If this is a 2D texture this will return a depth of 1.
  • If this is a 2D texture array, this will return the number of elements in the array.

TextureFormat Format() const

Returns the TextureFormat specified in the constructor Texture::Texture()

Public Static Functions

static void UnBindAll()

Deactivate any texture that is bound.

See
Bind(), UnBind(), IsBound()

int LogicalSizeBytes(int width, int height, int depth, TextureFormat format, int rowalignment)

Given the required parameters, this determines the expected size of the CPU-side buffer expected to upload the data from.