@@ -56,12 +56,6 @@ THE SOFTWARE.
56
56
namespace ax
57
57
{
58
58
59
- // CLASS IMPLEMENTATIONS:
60
-
61
- // If the image has alpha, you can create RGBA8 (32-bit) or RGBA4 (16-bit) or RGB5A1 (16-bit)
62
- // Default is: RGBA8888 (32-bit textures)
63
- static backend::PixelFormat g_defaultAlphaPixelFormat = backend::PixelFormat::RGBA8;
64
-
65
59
Texture2D::Texture2D ()
66
60
: _pixelFormat(backend::PixelFormat::NONE)
67
61
, _pixelsWide(0 )
@@ -188,6 +182,11 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps,
188
182
return true ;
189
183
}
190
184
185
+ bool Texture2D::updateWithImage (Image* image, int index)
186
+ {
187
+ return updateWithImage (image, image->getPixelFormat (), index);
188
+ }
189
+
191
190
bool Texture2D::updateWithImage (Image* image, backend::PixelFormat format, int index)
192
191
{
193
192
if (image == nullptr )
@@ -237,34 +236,24 @@ bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int i
237
236
default :
238
237
break ;
239
238
}
240
- #elif !AX_GLES_PROFILE
241
- // Non-GLES doesn't support follow render formats, needs convert PixelFormat::RGBA8
242
- // Note: axmol-1.1 deprecated A8, L8, LA8 as renderFormat, preferred R8, RG8
243
- switch (renderFormat)
244
- {
245
- case PixelFormat::R8:
246
- case PixelFormat::RG8:
247
- // Note: conversion to RGBA8 will happends
248
- renderFormat = PixelFormat::RGBA8;
249
- }
250
239
#endif
251
240
252
241
if (image->getNumberOfMipmaps () > 1 )
253
242
{
254
- if (renderFormat != image-> getPixelFormat () )
243
+ if (renderFormat != imagePixelFormat )
255
244
{
256
245
AXLOGW (" WARNING: This image has more than 1 mipmaps and we will not convert the data format" );
257
246
}
258
247
259
248
// pixel format of data is not converted, renderFormat can be different from pixelFormat
260
249
// it will be done later
261
- updateWithMipmaps (image->getMipmaps (), image->getNumberOfMipmaps (), image-> getPixelFormat () , renderFormat, imageHeight, imageWidth, image->hasPremultipliedAlpha (), index);
250
+ updateWithMipmaps (image->getMipmaps (), image->getNumberOfMipmaps (), imagePixelFormat , renderFormat, imageHeight, imageWidth, image->hasPremultipliedAlpha (), index);
262
251
}
263
252
else if (image->isCompressed ())
264
253
{ // !Only hardware support texture will be compression PixelFormat, otherwise, will convert to RGBA8 duraing image
265
254
// load
266
255
renderFormat = imagePixelFormat;
267
- updateWithData (tempData, tempDataLen, image-> getPixelFormat () , image->getPixelFormat (), imageWidth, imageHeight, image->hasPremultipliedAlpha (), index);
256
+ updateWithData (tempData, tempDataLen, imagePixelFormat , image->getPixelFormat (), imageWidth, imageHeight, image->hasPremultipliedAlpha (), index);
268
257
}
269
258
else
270
259
{
@@ -448,7 +437,13 @@ bool Texture2D::updateWithSubData(void* data, int offsetX, int offsetY, int widt
448
437
// implementation Texture2D (Image)
449
438
bool Texture2D::initWithImage (Image* image)
450
439
{
451
- return initWithImage (image, g_defaultAlphaPixelFormat);
440
+ if (image == nullptr )
441
+ {
442
+ AXLOGW (" Texture2D. Can't create Texture. UIImage is nil" );
443
+ return false ;
444
+ }
445
+
446
+ return initWithImage (image, image->getPixelFormat ());
452
447
}
453
448
454
449
bool Texture2D::initWithImage (Image* image, backend::PixelFormat format)
@@ -532,10 +527,6 @@ bool Texture2D::initWithString(std::string_view text, const FontDefinition& text
532
527
AXASSERT (textDefinition._stroke ._strokeEnabled == false , " Currently stroke only supported on iOS and Android!" );
533
528
#endif
534
529
535
- PixelFormat pixelFormat = g_defaultAlphaPixelFormat;
536
- unsigned char * outTempData = nullptr ;
537
- size_t outTempDataLen = 0 ;
538
-
539
530
int imageWidth;
540
531
int imageHeight;
541
532
auto textDef = textDefinition;
@@ -560,16 +551,10 @@ bool Texture2D::initWithString(std::string_view text, const FontDefinition& text
560
551
}
561
552
562
553
Vec2 imageSize = Vec2 ((float )imageWidth, (float )imageHeight);
563
- pixelFormat =
564
- backend::PixelFormatUtils::convertDataToFormat (outData.getBytes (), imageWidth * imageHeight * 4 ,
565
- PixelFormat::RGBA8, pixelFormat, &outTempData, &outTempDataLen);
554
+ const PixelFormat pixelFormat = PixelFormat::RGBA8;
566
555
567
- ret = initWithData (outTempData, outTempDataLen , pixelFormat, imageWidth, imageHeight);
556
+ ret = initWithData (outData. getBytes (), imageWidth * imageHeight * 4 , pixelFormat, imageWidth, imageHeight);
568
557
569
- if (outTempData != nullptr && outTempData != outData.getBytes ())
570
- {
571
- free (outTempData);
572
- }
573
558
setPremultipliedAlpha (hasPremultipliedAlpha);
574
559
575
560
return ret;
@@ -647,21 +632,6 @@ const char* Texture2D::getStringForFormat() const
647
632
return backend::PixelFormatUtils::getFormatDescriptor (_pixelFormat).name ;
648
633
}
649
634
650
- //
651
- // Texture options for images that contains alpha
652
- //
653
- // implementation Texture2D (PixelFormat)
654
-
655
- void Texture2D::setDefaultAlphaPixelFormat (backend::PixelFormat format)
656
- {
657
- g_defaultAlphaPixelFormat = format;
658
- }
659
-
660
- backend::PixelFormat Texture2D::getDefaultAlphaPixelFormat ()
661
- {
662
- return g_defaultAlphaPixelFormat;
663
- }
664
-
665
635
unsigned int Texture2D::getBitsPerPixelForFormat (backend::PixelFormat format) const
666
636
{
667
637
return backend::PixelFormatUtils::getFormatDescriptor (format).bpp ;
0 commit comments