Axmol 3.0.0-89d6d9a
Loading...
Searching...
No Matches
Texture2D Class Reference

Texture2D class. More...

#include <Texture2D.h>

Inherits Object.

Inherited by RenderTexture.

Public Types

using TexParams = rhi::SamplerDesc
 Extension to set the Min / Mag filter.

Public Member Functions

virtual ~Texture2D ()
 @lua NA
bool initWithImage (Image *image, PixelFormat renderFormat=PixelFormat::NONE, bool autoGenMipmaps=false)
 Initializes a texture from a Image object.
bool initWithString (std::string_view text, std::string_view fontName, float fontSize, const Vec2 &dimensions=Vec2(0, 0), TextHAlignment hAlignment=TextHAlignment::CENTER, TextVAlignment vAlignment=TextVAlignment::TOP, bool enableWrap=true, int overflow=0)
 Initializes a texture from a string with dimensions, alignment, font name and font size.
bool initWithString (std::string_view text, const FontDefinition &textDefinition)
 Initializes a texture from a string using a text definition.
bool initWithData (const void *data, ssize_t dataSize, rhi::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, bool preMultipliedAlpha=false, bool autoGenMipmaps=false)
 Initializes with a texture2d with data.
bool initWithData (const void *data, ssize_t dataSize, rhi::PixelFormat pixelFormat, rhi::PixelFormat renderFormat, int pixelsWide, int pixelsHigh, bool preMultipliedAlpha=false, bool autoGenMipmaps=false)
 Initializes with a texture2d with data.
bool initWithMipmaps (std::span< MipmapInfo > mipmaps, rhi::PixelFormat pixelFormat, rhi::PixelFormat renderFormat, int pixelsWide, int pixelsHigh, bool preMultipliedAlpha=false)
 Initializes with mipmaps.
bool updateData (Image *image)
 update data by image
bool updateData (std::span< const TextureSliceData > subDatas)
 update data by subDatas
bool updateData (const void *data, int width, int height, int level=0, int layerIndex=0)
 Update the texture with a new image data.
bool updateSubData (const void *data, int offsetX, int offsetY, int width, int height, int level=0, int layerIndex=0)
 Update texture sub data.
int getWidth () const
 Returns the texture width in physical pixels.
int getHeight () const
 Returns the texture height in physical pixels.
Vec2 getPixelSize () const
 Returns the physical pixel size of the texture as a float vector.
Vec2 getContentSize () const
 Returns the logical content size of the texture in points.
float getMaxS () const
 Gets max S.
void setMaxS (float maxS)
 Sets max S.
float getMaxT () const
 Gets max T.
void setMaxT (float maxT)
 Sets max T.
void setAntiAliasTexParameters ()
 Sets antialias texture parameters:
void setAliasTexParameters ()
 Sets alias texture parameters:
const char * getStringForFormat () const
 Returns the pixel format.
unsigned int getBitsPerPixelForFormat () const
 Returns the bits-per-pixel of the in-memory OpenGL texture.
unsigned int getBitsPerPixelForFormat (rhi::PixelFormat format) const
 Helper functions that returns bits per pixels for a given format.
bool hasPremultipliedAlpha () const
 Whether or not the texture has their Alpha premultiplied.
bool hasMipmaps () const
 Whether or not the texture has mip maps.
rhi::PixelFormat getPixelFormat () const
 Gets the pixel format of the texture.
Public Member Functions inherited from Object
void retain ()
 Retains the ownership.
void release ()
 Releases the ownership immediately.
Object * autorelease ()
 Releases the ownership sometime soon automatically.
unsigned int getReferenceCount () const
 Returns the Object's current reference count.
uint64_t getObjectID () const noexcept
 Returns the process-local diagnostic identifier assigned at construction.
virtual ~Object ()
 Destructor.

Detailed Description

Texture2D class.

This class allows to easily create OpenGL 2D textures from images, text or raw data. The created Texture2D object will always have power-of-two dimensions. Depending on how you create the Texture2D object, the actual image area of the texture might be smaller than the texture dimensions i.e. "contentSize" != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0). Be aware that the content of the generated textures will be upside-down!

Member Function Documentation

◆ initWithImage()

bool initWithImage ( Image * image,
PixelFormat renderFormat = PixelFormat::NONE,
bool autoGenMipmaps = false )

Initializes a texture from a Image object.

We will use the format you passed to the function to convert the image format to the texture format. If you pass PixelFormat::NONE, we will auto detect the image render type and use that type for texture to render.

Parameters
imageAn Image object.
formatTexture pixel formats.

◆ initWithString() [1/2]

bool initWithString ( std::string_view text,
std::string_view fontName,
float fontSize,
const Vec2 & dimensions = Vec2(0, 0),
TextHAlignment hAlignment = TextHAlignment::CENTER,
TextVAlignment vAlignment = TextVAlignment::TOP,
bool enableWrap = true,
int overflow = 0 )

Initializes a texture from a string with dimensions, alignment, font name and font size.

Parameters
textA null terminated string.
fontNameThe font name.
fontSizeThe font size.
dimensionsThe font dimension.
hAlignmentThe font horizontal text alignment type.
vAlignmentThe font vertical text alignment type.
enableWrapWhether enable text wrap or not.
overflowWhether shrink font size when content larger than the dimensions.

◆ initWithString() [2/2]

bool initWithString ( std::string_view text,
const FontDefinition & textDefinition )

Initializes a texture from a string using a text definition.

Parameters
textA null terminated string.
textDefinitionA FontDefinition object contains font attributes.

◆ initWithData() [1/2]

bool initWithData ( const void * data,
ssize_t dataSize,
rhi::PixelFormat pixelFormat,
int pixelsWide,
int pixelsHigh,
bool preMultipliedAlpha = false,
bool autoGenMipmaps = false )
inline

Initializes with a texture2d with data.

Parameters
dataSpecifies a pointer to the image data in memory.
dataSizeThe image data length.
pixelFormatThe image pixelFormat.
pixelsWideThe image width.
pixelsHighThe image height.
contentSizeThe image content size.
preMultipliedAlphaThe texture has premultiplied alpha @lua NA

◆ initWithData() [2/2]

bool initWithData ( const void * data,
ssize_t dataSize,
rhi::PixelFormat pixelFormat,
rhi::PixelFormat renderFormat,
int pixelsWide,
int pixelsHigh,
bool preMultipliedAlpha = false,
bool autoGenMipmaps = false )

Initializes with a texture2d with data.

Parameters
dataSpecifies a pointer to the image data in memory.
dataSizeThe image data length.
pixelFormatThe image pixelFormat.
renderFormatThe format converted to.
pixelsWideThe image width.
pixelsHighThe image height.
contentSizeThe image content size.
preMultipliedAlphaThe texture has premultiplied alpha @lua NA

◆ initWithMipmaps()

bool initWithMipmaps ( std::span< MipmapInfo > mipmaps,
rhi::PixelFormat pixelFormat,
rhi::PixelFormat renderFormat,
int pixelsWide,
int pixelsHigh,
bool preMultipliedAlpha = false )

Initializes with mipmaps.

Parameters
mipmapsSpecifies a pointer to the image data in memory.
mipmapsNumThe mipmaps number.
pixelFormatThe image pixelFormat.
pixelsWideThe image width.
pixelsHighThe image height.
preMultipliedAlphaThe texture has premultiplied alpha

◆ updateData() [1/3]

bool updateData ( Image * image)

update data by image

Parameters
image

◆ updateData() [2/3]

bool updateData ( std::span< const TextureSliceData > subDatas)

update data by subDatas

Parameters
subDatas

◆ updateData() [3/3]

bool updateData ( const void * data,
int width,
int height,
int level = 0,
int layerIndex = 0 )

Update the texture with a new image data.

Parameters
dataSpecifies a pointer to the image data in memory.
widthSpecifies the width of the texture.
heightSpecifies the height of the texture.
levelSpecifies the mipmap level to update. Default is 0.
layerIndexSpecifies the layer index to update. Default is 0.

◆ updateSubData()

bool updateSubData ( const void * data,
int offsetX,
int offsetY,
int width,
int height,
int level = 0,
int layerIndex = 0 )

Update texture sub data.

Parameters
dataSpecifies a pointer to the image data in memory.
offsetXSpecifies a texel offset in the x direction within the texture array.
offsetYSpecifies a texel offset in the y direction within the texture array.
widthSpecifies the width of the texture subimage.
heightSpecifies the height of the texture subimage.

◆ getWidth()

int getWidth ( ) const
inline

Returns the texture width in physical pixels.

◆ getHeight()

int getHeight ( ) const
inline

Returns the texture height in physical pixels.

◆ getPixelSize()

Vec2 getPixelSize ( ) const
inline

Returns the physical pixel size of the texture as a float vector.

*

Note
Convenience wrapper to avoid static_casting width and height to float.

◆ getContentSize()

Vec2 getContentSize ( ) const

Returns the logical content size of the texture in points.

*

Note
This value is calculated by dividing the physical pixel size by AX_CONTENT_SCALE_FACTOR. For example, on a Retina display, a 200x200 pixel texture might return (100, 100) points.

◆ setAntiAliasTexParameters()

void setAntiAliasTexParameters ( )

Sets antialias texture parameters:

  • GL_TEXTURE_MIN_FILTER = GL_LINEAR
  • GL_TEXTURE_MAG_FILTER = GL_LINEAR
Warning
Calling this method could allocate additional texture memory.
Since
v0.8

◆ setAliasTexParameters()

void setAliasTexParameters ( )

Sets alias texture parameters:

  • GL_TEXTURE_MIN_FILTER = GL_NEAREST
  • GL_TEXTURE_MAG_FILTER = GL_NEAREST
Warning
Calling this method could allocate additional texture memory.
Since
v0.8

◆ getStringForFormat()

const char * getStringForFormat ( ) const

Returns the pixel format.

Since
v2.0

◆ getBitsPerPixelForFormat() [1/2]

unsigned int getBitsPerPixelForFormat ( ) const

Returns the bits-per-pixel of the in-memory OpenGL texture.

Since
v1.0

◆ getBitsPerPixelForFormat() [2/2]

unsigned int getBitsPerPixelForFormat ( rhi::PixelFormat format) const

Helper functions that returns bits per pixels for a given format.

Since
v2.0

The documentation for this class was generated from the following file:
  • Texture2D.h