⚠️ This documentation corresponds to the latest development branch of axmol. It might diverge from the official releases.
|
Axmol Engine 3.0.0-dff292a
|
#include <Texture2D.h>
Inherits Object.
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. | |
| void | drawAtPoint (const Vec2 &point, float globalZOrder) |
| Drawing extensions to make it easy to draw basic quads using a Texture2D object. | |
| void | drawInRect (const Rect &rect, float globalZOrder) |
| Draws a texture inside a rect. | |
| 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. | |
| const Vec2 & | getContentSizeInPixels () |
| Get content size. | |
| 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. | |
| int | getPixelsWide () const |
| Gets the width of the texture in pixels. | |
| int | getPixelsHigh () const |
| Gets the height of the texture in pixels. | |
| 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. | |
| Vec2 | getContentSize () const |
| Get the texture content size. | |
| 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. | |
| virtual | ~Object () |
| Destructor. | |
Additional Inherited Members | |
| Public Attributes inherited from Object | |
| unsigned int | _ID |
| object id, ScriptSupport need public _ID | |
| int | _luaID |
| Lua reference id. | |
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!
| 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.
| image | An Image object. |
| format | Texture pixel formats. |
| 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.
| text | A null terminated string. |
| fontName | The font name. |
| fontSize | The font size. |
| dimensions | The font dimension. |
| hAlignment | The font horizontal text alignment type. |
| vAlignment | The font vertical text alignment type. |
| enableWrap | Whether enable text wrap or not. |
| overflow | Whether shrink font size when content larger than the dimensions. |
| bool initWithString | ( | std::string_view | text, |
| const FontDefinition & | textDefinition ) |
Initializes a texture from a string using a text definition.
| text | A null terminated string. |
| textDefinition | A FontDefinition object contains font attributes. |
|
inline |
Initializes with a texture2d with data.
| data | Specifies a pointer to the image data in memory. |
| dataSize | The image data length. |
| pixelFormat | The image pixelFormat. |
| pixelsWide | The image width. |
| pixelsHigh | The image height. |
| contentSize | The image content size. |
| preMultipliedAlpha | The texture has premultiplied alpha @lua NA |
| 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.
| data | Specifies a pointer to the image data in memory. |
| dataSize | The image data length. |
| pixelFormat | The image pixelFormat. |
| renderFormat | The format converted to. |
| pixelsWide | The image width. |
| pixelsHigh | The image height. |
| contentSize | The image content size. |
| preMultipliedAlpha | The texture has premultiplied alpha @lua NA |
| bool initWithMipmaps | ( | std::span< MipmapInfo > | mipmaps, |
| rhi::PixelFormat | pixelFormat, | ||
| rhi::PixelFormat | renderFormat, | ||
| int | pixelsWide, | ||
| int | pixelsHigh, | ||
| bool | preMultipliedAlpha = false ) |
Initializes with mipmaps.
| mipmaps | Specifies a pointer to the image data in memory. |
| mipmapsNum | The mipmaps number. |
| pixelFormat | The image pixelFormat. |
| pixelsWide | The image width. |
| pixelsHigh | The image height. |
| preMultipliedAlpha | The texture has premultiplied alpha |
| bool updateData | ( | Image * | image | ) |
update data by image
| image |
| bool updateData | ( | std::span< const TextureSliceData > | subDatas | ) |
update data by subDatas
| subDatas |
| bool updateData | ( | const void * | data, |
| int | width, | ||
| int | height, | ||
| int | level = 0, | ||
| int | layerIndex = 0 ) |
Update the texture with a new image data.
| data | Specifies a pointer to the image data in memory. |
| width | Specifies the width of the texture. |
| height | Specifies the height of the texture. |
| level | Specifies the mipmap level to update. Default is 0. |
| layerIndex | Specifies the layer index to update. Default is 0. |
| bool updateSubData | ( | const void * | data, |
| int | offsetX, | ||
| int | offsetY, | ||
| int | width, | ||
| int | height, | ||
| int | level = 0, | ||
| int | layerIndex = 0 ) |
Update texture sub data.
| data | Specifies a pointer to the image data in memory. |
| offsetX | Specifies a texel offset in the x direction within the texture array. |
| offsetY | Specifies a texel offset in the y direction within the texture array. |
| width | Specifies the width of the texture subimage. |
| height | Specifies the height of the texture subimage. |
| void drawAtPoint | ( | const Vec2 & | point, |
| float | globalZOrder ) |
Drawing extensions to make it easy to draw basic quads using a Texture2D object.
These functions require GL_TEXTURE_2D and both GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY client states to be enabled. Draws a texture at a given point.
| 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.