mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-07 18:50:28 +02:00
Reformat the code, using:
find -type f | # list all regular files grep -E '\.(h|cpp|mm)$' | # filter for source files grep -v '/mt_' | # filter out generated files grep -v '/vendor/' | # and vendored GL grep -v '/test/image_loader_test.cpp' | # and this file (has giant literals arrays) xargs -n 1 -P $(nproc) clang-format -i # reformat everything Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
@ -25,9 +25,10 @@ class COpenGLCoreTexture : public ITexture
|
||||
public:
|
||||
struct SStatesCache
|
||||
{
|
||||
SStatesCache() : WrapU(ETC_REPEAT), WrapV(ETC_REPEAT), WrapW(ETC_REPEAT),
|
||||
LODBias(0), AnisotropicFilter(0), MinFilter(video::ETMINF_NEAREST_MIPMAP_NEAREST),
|
||||
MagFilter(video::ETMAGF_NEAREST), MipMapStatus(false), IsCached(false)
|
||||
SStatesCache() :
|
||||
WrapU(ETC_REPEAT), WrapV(ETC_REPEAT), WrapW(ETC_REPEAT),
|
||||
LODBias(0), AnisotropicFilter(0), MinFilter(video::ETMINF_NEAREST_MIPMAP_NEAREST),
|
||||
MagFilter(video::ETMAGF_NEAREST), MipMapStatus(false), IsCached(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -42,9 +43,10 @@ public:
|
||||
bool IsCached;
|
||||
};
|
||||
|
||||
COpenGLCoreTexture(const io::path& name, const core::array<IImage*>& images, E_TEXTURE_TYPE type, TOpenGLDriver* driver) : ITexture(name, type), Driver(driver), TextureType(GL_TEXTURE_2D),
|
||||
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0),
|
||||
KeepImage(false), MipLevelStored(0), LegacyAutoGenerateMipMaps(false)
|
||||
COpenGLCoreTexture(const io::path &name, const core::array<IImage *> &images, E_TEXTURE_TYPE type, TOpenGLDriver *driver) :
|
||||
ITexture(name, type), Driver(driver), TextureType(GL_TEXTURE_2D),
|
||||
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0),
|
||||
KeepImage(false), MipLevelStored(0), LegacyAutoGenerateMipMaps(false)
|
||||
{
|
||||
_IRR_DEBUG_BREAK_IF(images.size() == 0)
|
||||
|
||||
@ -57,14 +59,12 @@ public:
|
||||
if (!InternalFormat)
|
||||
return;
|
||||
|
||||
const core::array<IImage*>* tmpImages = &images;
|
||||
const core::array<IImage *> *tmpImages = &images;
|
||||
|
||||
if (KeepImage || OriginalSize != Size || OriginalColorFormat != ColorFormat)
|
||||
{
|
||||
if (KeepImage || OriginalSize != Size || OriginalColorFormat != ColorFormat) {
|
||||
Images.set_used(images.size());
|
||||
|
||||
for (u32 i = 0; i < images.size(); ++i)
|
||||
{
|
||||
for (u32 i = 0; i < images.size(); ++i) {
|
||||
Images[i] = Driver->createImage(ColorFormat, Size);
|
||||
|
||||
if (images[i]->getDimension() == Size)
|
||||
@ -72,14 +72,10 @@ public:
|
||||
else
|
||||
images[i]->copyToScaling(Images[i]);
|
||||
|
||||
if ( images[i]->getMipMapsData() )
|
||||
{
|
||||
if ( OriginalSize == Size && OriginalColorFormat == ColorFormat )
|
||||
{
|
||||
Images[i]->setMipMapsData( images[i]->getMipMapsData(), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (images[i]->getMipMapsData()) {
|
||||
if (OriginalSize == Size && OriginalColorFormat == ColorFormat) {
|
||||
Images[i]->setMipMapsData(images[i]->getMipMapsData(), false);
|
||||
} else {
|
||||
// TODO: handle at least mipmap with changing color format
|
||||
os::Printer::log("COpenGLCoreTexture: Can't handle format changes for mipmap data. Mipmap data dropped", ELL_WARNING);
|
||||
}
|
||||
@ -91,15 +87,14 @@ public:
|
||||
|
||||
GL.GenTextures(1, &TextureName);
|
||||
|
||||
const COpenGLCoreTexture* prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
const COpenGLCoreTexture *prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, this);
|
||||
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
#ifdef GL_GENERATE_MIPMAP_HINT
|
||||
if (HasMipMaps)
|
||||
{
|
||||
if (HasMipMaps) {
|
||||
if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
|
||||
GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
|
||||
else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY))
|
||||
@ -112,35 +107,31 @@ public:
|
||||
for (u32 i = 0; i < (*tmpImages).size(); ++i)
|
||||
uploadTexture(true, i, 0, (*tmpImages)[i]->getData());
|
||||
|
||||
if (HasMipMaps && !LegacyAutoGenerateMipMaps)
|
||||
{
|
||||
if (HasMipMaps && !LegacyAutoGenerateMipMaps) {
|
||||
// Create mipmaps (either from image mipmaps or generate them)
|
||||
for (u32 i = 0; i < (*tmpImages).size(); ++i)
|
||||
{
|
||||
void* mipmapsData = (*tmpImages)[i]->getMipMapsData();
|
||||
for (u32 i = 0; i < (*tmpImages).size(); ++i) {
|
||||
void *mipmapsData = (*tmpImages)[i]->getMipMapsData();
|
||||
regenerateMipMapLevels(mipmapsData, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (!KeepImage)
|
||||
{
|
||||
if (!KeepImage) {
|
||||
for (u32 i = 0; i < Images.size(); ++i)
|
||||
Images[i]->drop();
|
||||
|
||||
Images.clear();
|
||||
}
|
||||
|
||||
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, prevTexture);
|
||||
|
||||
Driver->testGLError(__LINE__);
|
||||
}
|
||||
|
||||
COpenGLCoreTexture(const io::path& name, const core::dimension2d<u32>& size, E_TEXTURE_TYPE type, ECOLOR_FORMAT format, TOpenGLDriver* driver)
|
||||
: ITexture(name, type),
|
||||
Driver(driver), TextureType(GL_TEXTURE_2D),
|
||||
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0), KeepImage(false),
|
||||
MipLevelStored(0), LegacyAutoGenerateMipMaps(false)
|
||||
COpenGLCoreTexture(const io::path &name, const core::dimension2d<u32> &size, E_TEXTURE_TYPE type, ECOLOR_FORMAT format, TOpenGLDriver *driver) :
|
||||
ITexture(name, type),
|
||||
Driver(driver), TextureType(GL_TEXTURE_2D),
|
||||
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0), KeepImage(false),
|
||||
MipLevelStored(0), LegacyAutoGenerateMipMaps(false)
|
||||
{
|
||||
DriverType = Driver->getDriverType();
|
||||
TextureType = TextureTypeIrrToGL(Type);
|
||||
@ -159,18 +150,16 @@ public:
|
||||
|
||||
Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8;
|
||||
|
||||
if ( !Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter) )
|
||||
{
|
||||
os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN?ColorFormat:ECF_UNKNOWN], ELL_ERROR);
|
||||
if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) {
|
||||
os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN ? ColorFormat : ECF_UNKNOWN], ELL_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
GL.GenTextures(1, &TextureName);
|
||||
|
||||
const COpenGLCoreTexture* prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
const COpenGLCoreTexture *prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, this);
|
||||
|
||||
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
@ -184,8 +173,7 @@ public:
|
||||
StatesCache.WrapV = ETC_CLAMP_TO_EDGE;
|
||||
StatesCache.WrapW = ETC_CLAMP_TO_EDGE;
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
switch (Type) {
|
||||
case ETT_2D:
|
||||
GL.TexImage2D(GL_TEXTURE_2D, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
break;
|
||||
@ -200,8 +188,7 @@ public:
|
||||
}
|
||||
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, prevTexture);
|
||||
if ( Driver->testGLError(__LINE__) )
|
||||
{
|
||||
if (Driver->testGLError(__LINE__)) {
|
||||
char msg[256];
|
||||
snprintf_irr(msg, 256, "COpenGLCoreTexture: InternalFormat:0x%04x PixelFormat:0x%04x", (int)InternalFormat, (int)PixelFormat);
|
||||
os::Printer::log(msg, ELL_ERROR);
|
||||
@ -220,7 +207,7 @@ public:
|
||||
Images[i]->drop();
|
||||
}
|
||||
|
||||
void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel=0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) override
|
||||
void *lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel = 0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) override
|
||||
{
|
||||
if (LockImage)
|
||||
return getLockImageData(MipLevelStored);
|
||||
@ -232,38 +219,33 @@ public:
|
||||
LockLayer = layer;
|
||||
MipLevelStored = mipmapLevel;
|
||||
|
||||
if (KeepImage)
|
||||
{
|
||||
if (KeepImage) {
|
||||
_IRR_DEBUG_BREAK_IF(LockLayer > Images.size())
|
||||
|
||||
if ( mipmapLevel == 0 || (Images[LockLayer] && Images[LockLayer]->getMipMapsData(mipmapLevel)) )
|
||||
{
|
||||
if (mipmapLevel == 0 || (Images[LockLayer] && Images[LockLayer]->getMipMapsData(mipmapLevel))) {
|
||||
LockImage = Images[LockLayer];
|
||||
LockImage->grab();
|
||||
}
|
||||
}
|
||||
|
||||
if ( !LockImage )
|
||||
{
|
||||
core::dimension2d<u32> lockImageSize( IImage::getMipMapsSize(Size, MipLevelStored));
|
||||
if (!LockImage) {
|
||||
core::dimension2d<u32> lockImageSize(IImage::getMipMapsSize(Size, MipLevelStored));
|
||||
|
||||
// note: we save mipmap data also in the image because IImage doesn't allow saving single mipmap levels to the mipmap data
|
||||
LockImage = Driver->createImage(ColorFormat, lockImageSize);
|
||||
|
||||
if (LockImage && mode != ETLM_WRITE_ONLY)
|
||||
{
|
||||
if (LockImage && mode != ETLM_WRITE_ONLY) {
|
||||
bool passed = true;
|
||||
|
||||
#ifdef IRR_COMPILE_GL_COMMON
|
||||
IImage* tmpImage = LockImage; // not sure yet if the size required by glGetTexImage is always correct, if not we might have to allocate a different tmpImage and convert colors later on.
|
||||
IImage *tmpImage = LockImage; // not sure yet if the size required by glGetTexImage is always correct, if not we might have to allocate a different tmpImage and convert colors later on.
|
||||
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, this);
|
||||
Driver->testGLError(__LINE__);
|
||||
|
||||
GLenum tmpTextureType = TextureType;
|
||||
|
||||
if (tmpTextureType == GL_TEXTURE_CUBE_MAP)
|
||||
{
|
||||
if (tmpTextureType == GL_TEXTURE_CUBE_MAP) {
|
||||
_IRR_DEBUG_BREAK_IF(layer > 5)
|
||||
|
||||
tmpTextureType = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
|
||||
@ -272,17 +254,15 @@ public:
|
||||
GL.GetTexImage(tmpTextureType, MipLevelStored, PixelFormat, PixelType, tmpImage->getData());
|
||||
Driver->testGLError(__LINE__);
|
||||
|
||||
if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT)
|
||||
{
|
||||
if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT) {
|
||||
const s32 pitch = tmpImage->getPitch();
|
||||
|
||||
u8* srcA = static_cast<u8*>(tmpImage->getData());
|
||||
u8* srcB = srcA + (tmpImage->getDimension().Height - 1) * pitch;
|
||||
u8 *srcA = static_cast<u8 *>(tmpImage->getData());
|
||||
u8 *srcB = srcA + (tmpImage->getDimension().Height - 1) * pitch;
|
||||
|
||||
u8* tmpBuffer = new u8[pitch];
|
||||
u8 *tmpBuffer = new u8[pitch];
|
||||
|
||||
for (u32 i = 0; i < tmpImage->getDimension().Height; i += 2)
|
||||
{
|
||||
for (u32 i = 0; i < tmpImage->getDimension().Height; i += 2) {
|
||||
memcpy(tmpBuffer, srcA, pitch);
|
||||
memcpy(srcA, srcB, pitch);
|
||||
memcpy(srcB, tmpBuffer, pitch);
|
||||
@ -292,9 +272,9 @@ public:
|
||||
|
||||
delete[] tmpBuffer;
|
||||
}
|
||||
#elif (defined(IRR_COMPILE_GLES2_COMMON) || defined(IRR_COMPILE_GLES_COMMON))
|
||||
// TODO: on ES2 we can likely also work with glCopyTexImage2D instead of rendering which should be faster.
|
||||
COpenGLCoreTexture* tmpTexture = new COpenGLCoreTexture("OGL_CORE_LOCK_TEXTURE", Size, ETT_2D, ColorFormat, Driver);
|
||||
#elif (defined(IRR_COMPILE_GLES2_COMMON) || defined(IRR_COMPILE_GLES_COMMON))
|
||||
// TODO: on ES2 we can likely also work with glCopyTexImage2D instead of rendering which should be faster.
|
||||
COpenGLCoreTexture *tmpTexture = new COpenGLCoreTexture("OGL_CORE_LOCK_TEXTURE", Size, ETT_2D, ColorFormat, Driver);
|
||||
|
||||
GLuint tmpFBO = 0;
|
||||
Driver->irrGlGenFramebuffers(1, &tmpFBO);
|
||||
@ -316,7 +296,7 @@ public:
|
||||
|
||||
Driver->draw2DImage(this, layer, true);
|
||||
|
||||
IImage* tmpImage = Driver->createImage(ECF_A8R8G8B8, Size);
|
||||
IImage *tmpImage = Driver->createImage(ECF_A8R8G8B8, Size);
|
||||
GL.ReadPixels(0, 0, Size.Width, Size.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
|
||||
|
||||
Driver->getCacheHandler()->setFBO(prevFBO);
|
||||
@ -325,11 +305,10 @@ public:
|
||||
Driver->irrGlDeleteFramebuffers(1, &tmpFBO);
|
||||
delete tmpTexture;
|
||||
|
||||
void* src = tmpImage->getData();
|
||||
void* dest = LockImage->getData();
|
||||
void *src = tmpImage->getData();
|
||||
void *dest = LockImage->getData();
|
||||
|
||||
switch (ColorFormat)
|
||||
{
|
||||
switch (ColorFormat) {
|
||||
case ECF_A1R5G5B5:
|
||||
CColorConverter::convert_A8R8G8B8toA1B5G5R5(src, tmpImage->getDimension().getArea(), dest);
|
||||
break;
|
||||
@ -349,8 +328,7 @@ public:
|
||||
tmpImage->drop();
|
||||
#endif
|
||||
|
||||
if (!passed)
|
||||
{
|
||||
if (!passed) {
|
||||
LockImage->drop();
|
||||
LockImage = 0;
|
||||
}
|
||||
@ -367,9 +345,8 @@ public:
|
||||
if (!LockImage)
|
||||
return;
|
||||
|
||||
if (!LockReadOnly)
|
||||
{
|
||||
const COpenGLCoreTexture* prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
if (!LockReadOnly) {
|
||||
const COpenGLCoreTexture *prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, this);
|
||||
|
||||
uploadTexture(false, LockLayer, MipLevelStored, getLockImageData(MipLevelStored));
|
||||
@ -384,24 +361,22 @@ public:
|
||||
LockLayer = 0;
|
||||
}
|
||||
|
||||
void regenerateMipMapLevels(void* data = 0, u32 layer = 0) override
|
||||
void regenerateMipMapLevels(void *data = 0, u32 layer = 0) override
|
||||
{
|
||||
if (!HasMipMaps || LegacyAutoGenerateMipMaps || (Size.Width <= 1 && Size.Height <= 1))
|
||||
return;
|
||||
|
||||
const COpenGLCoreTexture* prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
const COpenGLCoreTexture *prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, this);
|
||||
|
||||
if (data)
|
||||
{
|
||||
if (data) {
|
||||
u32 width = Size.Width;
|
||||
u32 height = Size.Height;
|
||||
u8* tmpData = static_cast<u8*>(data);
|
||||
u8 *tmpData = static_cast<u8 *>(data);
|
||||
u32 dataSize = 0;
|
||||
u32 level = 0;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
if (width > 1)
|
||||
width >>= 1;
|
||||
|
||||
@ -414,11 +389,8 @@ public:
|
||||
uploadTexture(true, layer, level, tmpData);
|
||||
|
||||
tmpData += dataSize;
|
||||
}
|
||||
while (width != 1 || height != 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} while (width != 1 || height != 1);
|
||||
} else {
|
||||
Driver->irrGlGenerateMipmap(TextureType);
|
||||
}
|
||||
|
||||
@ -435,18 +407,15 @@ public:
|
||||
return TextureName;
|
||||
}
|
||||
|
||||
SStatesCache& getStatesCache() const
|
||||
SStatesCache &getStatesCache() const
|
||||
{
|
||||
return StatesCache;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void * getLockImageData(irr::u32 miplevel) const
|
||||
void *getLockImageData(irr::u32 miplevel) const
|
||||
{
|
||||
if ( KeepImage && MipLevelStored > 0
|
||||
&& LockImage->getMipMapsData(MipLevelStored) )
|
||||
{
|
||||
if (KeepImage && MipLevelStored > 0 && LockImage->getMipMapsData(MipLevelStored)) {
|
||||
return LockImage->getMipMapsData(MipLevelStored);
|
||||
}
|
||||
return LockImage->getData();
|
||||
@ -457,8 +426,7 @@ protected:
|
||||
// We only try for to adapt "simple" formats
|
||||
ECOLOR_FORMAT destFormat = (format <= ECF_A8R8G8B8) ? ECF_A8R8G8B8 : format;
|
||||
|
||||
switch (format)
|
||||
{
|
||||
switch (format) {
|
||||
case ECF_A1R5G5B5:
|
||||
if (!Driver->getTextureCreationFlag(ETCF_ALWAYS_32_BIT))
|
||||
destFormat = ECF_A1R5G5B5;
|
||||
@ -469,7 +437,7 @@ protected:
|
||||
break;
|
||||
case ECF_A8R8G8B8:
|
||||
if (Driver->getTextureCreationFlag(ETCF_ALWAYS_16_BIT) ||
|
||||
Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
|
||||
Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
|
||||
destFormat = ECF_A1R5G5B5;
|
||||
break;
|
||||
case ECF_R8G8B8:
|
||||
@ -480,10 +448,8 @@ protected:
|
||||
break;
|
||||
}
|
||||
|
||||
if (Driver->getTextureCreationFlag(ETCF_NO_ALPHA_CHANNEL))
|
||||
{
|
||||
switch (destFormat)
|
||||
{
|
||||
if (Driver->getTextureCreationFlag(ETCF_NO_ALPHA_CHANNEL)) {
|
||||
switch (destFormat) {
|
||||
case ECF_A1R5G5B5:
|
||||
destFormat = ECF_R5G6B5;
|
||||
break;
|
||||
@ -498,41 +464,35 @@ protected:
|
||||
return destFormat;
|
||||
}
|
||||
|
||||
void getImageValues(const IImage* image)
|
||||
void getImageValues(const IImage *image)
|
||||
{
|
||||
OriginalColorFormat = image->getColorFormat();
|
||||
ColorFormat = getBestColorFormat(OriginalColorFormat);
|
||||
|
||||
if ( !Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter) )
|
||||
{
|
||||
os::Printer::log("getImageValues: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN?ColorFormat:ECF_UNKNOWN], ELL_ERROR);
|
||||
if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) {
|
||||
os::Printer::log("getImageValues: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN ? ColorFormat : ECF_UNKNOWN], ELL_ERROR);
|
||||
InternalFormat = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (IImage::isCompressedFormat(image->getColorFormat()))
|
||||
{
|
||||
if (IImage::isCompressedFormat(image->getColorFormat())) {
|
||||
KeepImage = false;
|
||||
}
|
||||
|
||||
OriginalSize = image->getDimension();
|
||||
Size = OriginalSize;
|
||||
|
||||
if (Size.Width == 0 || Size.Height == 0)
|
||||
{
|
||||
if (Size.Width == 0 || Size.Height == 0) {
|
||||
os::Printer::log("Invalid size of image for texture.", ELL_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
const f32 ratio = (f32)Size.Width / (f32)Size.Height;
|
||||
|
||||
if ((Size.Width > Driver->MaxTextureSize) && (ratio >= 1.f))
|
||||
{
|
||||
if ((Size.Width > Driver->MaxTextureSize) && (ratio >= 1.f)) {
|
||||
Size.Width = Driver->MaxTextureSize;
|
||||
Size.Height = (u32)(Driver->MaxTextureSize / ratio);
|
||||
}
|
||||
else if (Size.Height > Driver->MaxTextureSize)
|
||||
{
|
||||
} else if (Size.Height > Driver->MaxTextureSize) {
|
||||
Size.Height = Driver->MaxTextureSize;
|
||||
Size.Width = (u32)(Driver->MaxTextureSize * ratio);
|
||||
}
|
||||
@ -544,7 +504,7 @@ protected:
|
||||
Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8;
|
||||
}
|
||||
|
||||
void uploadTexture(bool initTexture, u32 layer, u32 level, void* data)
|
||||
void uploadTexture(bool initTexture, u32 layer, u32 level, void *data)
|
||||
{
|
||||
if (!data)
|
||||
return;
|
||||
@ -558,20 +518,17 @@ protected:
|
||||
|
||||
GLenum tmpTextureType = TextureType;
|
||||
|
||||
if (tmpTextureType == GL_TEXTURE_CUBE_MAP)
|
||||
{
|
||||
if (tmpTextureType == GL_TEXTURE_CUBE_MAP) {
|
||||
_IRR_DEBUG_BREAK_IF(layer > 5)
|
||||
|
||||
tmpTextureType = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
|
||||
}
|
||||
|
||||
if (!IImage::isCompressedFormat(ColorFormat))
|
||||
{
|
||||
CImage* tmpImage = 0;
|
||||
void* tmpData = data;
|
||||
if (!IImage::isCompressedFormat(ColorFormat)) {
|
||||
CImage *tmpImage = 0;
|
||||
void *tmpData = data;
|
||||
|
||||
if (Converter)
|
||||
{
|
||||
if (Converter) {
|
||||
const core::dimension2d<u32> tmpImageSize(width, height);
|
||||
|
||||
tmpImage = new CImage(ColorFormat, tmpImageSize);
|
||||
@ -580,8 +537,7 @@ protected:
|
||||
Converter(data, tmpImageSize.getArea(), tmpData);
|
||||
}
|
||||
|
||||
switch (TextureType)
|
||||
{
|
||||
switch (TextureType) {
|
||||
case GL_TEXTURE_2D:
|
||||
case GL_TEXTURE_CUBE_MAP:
|
||||
if (initTexture)
|
||||
@ -595,13 +551,10 @@ protected:
|
||||
}
|
||||
|
||||
delete tmpImage;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
u32 dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);
|
||||
|
||||
switch (TextureType)
|
||||
{
|
||||
switch (TextureType) {
|
||||
case GL_TEXTURE_2D:
|
||||
case GL_TEXTURE_CUBE_MAP:
|
||||
if (initTexture)
|
||||
@ -618,8 +571,7 @@ protected:
|
||||
|
||||
GLenum TextureTypeIrrToGL(E_TEXTURE_TYPE type) const
|
||||
{
|
||||
switch ( type)
|
||||
{
|
||||
switch (type) {
|
||||
case ETT_2D:
|
||||
return GL_TEXTURE_2D;
|
||||
case ETT_CUBEMAP:
|
||||
@ -630,21 +582,21 @@ protected:
|
||||
return GL_TEXTURE_2D;
|
||||
}
|
||||
|
||||
TOpenGLDriver* Driver;
|
||||
TOpenGLDriver *Driver;
|
||||
|
||||
GLenum TextureType;
|
||||
GLuint TextureName;
|
||||
GLint InternalFormat;
|
||||
GLenum PixelFormat;
|
||||
GLenum PixelType;
|
||||
void (*Converter)(const void*, s32, void*);
|
||||
void (*Converter)(const void *, s32, void *);
|
||||
|
||||
bool LockReadOnly;
|
||||
IImage* LockImage;
|
||||
IImage *LockImage;
|
||||
u32 LockLayer;
|
||||
|
||||
bool KeepImage;
|
||||
core::array<IImage*> Images;
|
||||
core::array<IImage *> Images;
|
||||
|
||||
u8 MipLevelStored;
|
||||
bool LegacyAutoGenerateMipMaps;
|
||||
|
Reference in New Issue
Block a user