MCPcopy Create free account
hub / github.com/axmolengine/axmol / updateWithImage

Method updateWithImage

core/renderer/Texture2D.cpp:193–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193bool Texture2D::updateWithImage(Image* image, backend::PixelFormat format, int index)
194{
195 if (image == nullptr)
196 {
197 AXLOGW("axmol: Texture2D. Can't create Texture. UIImage is nil");
198 return false;
199 }
200
201 if (this->_filePath.empty())
202 this->_filePath = image->getFilePath();
203
204 int imageWidth = image->getWidth();
205 int imageHeight = image->getHeight();
206
207 Configuration* conf = Configuration::getInstance();
208
209 int maxTextureSize = conf->getMaxTextureSize();
210 if (imageWidth > maxTextureSize || imageHeight > maxTextureSize)
211 {
212 AXLOGW("axmol: WARNING: Image ({} x {}) is bigger than the supported {} x {}", imageWidth, imageHeight,
213 maxTextureSize, maxTextureSize);
214 return false;
215 }
216
217 unsigned char* tempData = image->getData();
218 // Vec2 imageSize = Vec2((float)imageWidth, (float)imageHeight);
219 backend::PixelFormat renderFormat = (PixelFormat::NONE == format) ? image->getPixelFormat() : format;
220 backend::PixelFormat imagePixelFormat = image->getPixelFormat();
221 size_t tempDataLen = image->getDataLen();
222
223#ifdef AX_USE_METAL
224 //! override renderFormat, since some render format is not supported by metal
225 switch (renderFormat)
226 {
227# if (AX_TARGET_PLATFORM != AX_PLATFORM_IOS || TARGET_OS_SIMULATOR)
228 // packed 16 bits pixels only available on iOS
229 case PixelFormat::RGB565:
230 case PixelFormat::RGB5A1:
231 case PixelFormat::RGBA4:
232# endif
233 case PixelFormat::R8:
234 case PixelFormat::RG8:
235 case PixelFormat::RGB8:
236 // Note: conversion to RGBA8 will happends
237 renderFormat = PixelFormat::RGBA8;
238 break;
239 default:
240 break;
241 }
242#elif !AX_GLES_PROFILE
243 // Non-GLES doesn't support follow render formats, needs convert PixelFormat::RGBA8
244 // Note: axmol-1.1 deprecated A8, L8, LA8 as renderFormat, preferred R8, RG8
245 switch (renderFormat)
246 {
247 case PixelFormat::R8:
248 case PixelFormat::RG8:
249 // Note: conversion to RGBA8 will happends
250 renderFormat = PixelFormat::RGBA8;

Callers 4

addImageAsyncCallBackMethod · 0.80
addImageMethod · 0.80
reloadAllTexturesMethod · 0.80
loadAtlasMethod · 0.80

Calls 9

getInstanceFunction · 0.85
getMaxTextureSizeMethod · 0.80
hasPremultipliedAlphaMethod · 0.80
isCompressedMethod · 0.80
emptyMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
getDataMethod · 0.45
getPixelFormatMethod · 0.45

Tested by

no test coverage detected