mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Some minor code cleanups
This commit is contained in:
parent
7689f1f0fd
commit
03affa1bbb
15 changed files with 29 additions and 98 deletions
|
@ -71,18 +71,16 @@ void CGUIFont::setMaxHeight()
|
|||
|
||||
void CGUIFont::pushTextureCreationFlags(bool (&flags)[3])
|
||||
{
|
||||
flags[0] = Driver->getTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2);
|
||||
flags[0] = false;
|
||||
flags[1] = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
|
||||
flags[2] = Driver->getTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY);
|
||||
|
||||
Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, true);
|
||||
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
|
||||
Driver->setTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY, true);
|
||||
}
|
||||
|
||||
void CGUIFont::popTextureCreationFlags(const bool (&flags)[3])
|
||||
{
|
||||
Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, flags[0]);
|
||||
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, flags[1]);
|
||||
Driver->setTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY, flags[2]);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,10 @@ CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32> &size, void *d
|
|||
IImage(format, size, deleteMemory)
|
||||
{
|
||||
if (ownForeignMemory) {
|
||||
Data = (u8 *)data;
|
||||
_IRR_DEBUG_BREAK_IF(!data)
|
||||
Data = reinterpret_cast<u8*>(data);
|
||||
if (reinterpret_cast<uintptr_t>(data) % sizeof(u32) != 0)
|
||||
os::Printer::log("CImage created with foreign memory that's not aligned", ELL_WARNING);
|
||||
} else {
|
||||
const u32 dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height);
|
||||
const u32 allocSize = align_next(dataSize, 16);
|
||||
|
|
|
@ -71,7 +71,6 @@ CNullDriver::CNullDriver(io::IFileSystem *io, const core::dimension2d<u32> &scre
|
|||
|
||||
setTextureCreationFlag(ETCF_ALWAYS_32_BIT, true);
|
||||
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, true);
|
||||
setTextureCreationFlag(ETCF_AUTO_GENERATE_MIP_MAPS, true);
|
||||
setTextureCreationFlag(ETCF_ALLOW_MEMORY_COPY, false);
|
||||
|
||||
ViewPort = core::rect<s32>(core::position2d<s32>(0, 0), core::dimension2di(screenSize));
|
||||
|
@ -406,17 +405,13 @@ ITexture *CNullDriver::getTexture(const io::path &filename)
|
|||
const io::path absolutePath = FileSystem->getAbsolutePath(filename);
|
||||
|
||||
ITexture *texture = findTexture(absolutePath);
|
||||
if (texture) {
|
||||
texture->updateSource(ETS_FROM_CACHE);
|
||||
if (texture)
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Then try the raw filename, which might be in an Archive
|
||||
texture = findTexture(filename);
|
||||
if (texture) {
|
||||
texture->updateSource(ETS_FROM_CACHE);
|
||||
if (texture)
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Now try to open the file using the complete path.
|
||||
io::IReadFile *file = FileSystem->createAndOpenFile(absolutePath);
|
||||
|
@ -430,7 +425,6 @@ ITexture *CNullDriver::getTexture(const io::path &filename)
|
|||
// Re-check name for actual archive names
|
||||
texture = findTexture(file->getFileName());
|
||||
if (texture) {
|
||||
texture->updateSource(ETS_FROM_CACHE);
|
||||
file->drop();
|
||||
return texture;
|
||||
}
|
||||
|
@ -439,7 +433,6 @@ ITexture *CNullDriver::getTexture(const io::path &filename)
|
|||
file->drop();
|
||||
|
||||
if (texture) {
|
||||
texture->updateSource(ETS_FROM_FILE);
|
||||
addTexture(texture);
|
||||
texture->drop(); // drop it because we created it, one grab too much
|
||||
} else
|
||||
|
@ -459,15 +452,12 @@ ITexture *CNullDriver::getTexture(io::IReadFile *file)
|
|||
if (file) {
|
||||
texture = findTexture(file->getFileName());
|
||||
|
||||
if (texture) {
|
||||
texture->updateSource(ETS_FROM_CACHE);
|
||||
if (texture)
|
||||
return texture;
|
||||
}
|
||||
|
||||
texture = loadTextureFromFile(file);
|
||||
|
||||
if (texture) {
|
||||
texture->updateSource(ETS_FROM_FILE);
|
||||
addTexture(texture);
|
||||
texture->drop(); // drop it because we created it, one grab too much
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
_IRR_DEBUG_BREAK_IF(srcImages.empty())
|
||||
|
||||
DriverType = Driver->getDriverType();
|
||||
_IRR_DEBUG_BREAK_IF(Type == ETT_2D_MS); // not supported by this constructor
|
||||
_IRR_DEBUG_BREAK_IF(Type == ETT_2D_MS) // not supported by this constructor
|
||||
TextureType = TextureTypeIrrToGL(Type);
|
||||
HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
|
||||
KeepImage = Driver->getTextureCreationFlag(ETCF_ALLOW_MEMORY_COPY);
|
||||
|
@ -60,7 +60,6 @@ public:
|
|||
if (!InternalFormat)
|
||||
return;
|
||||
|
||||
#ifdef _DEBUG
|
||||
char lbuf[128];
|
||||
snprintf_irr(lbuf, sizeof(lbuf),
|
||||
"COpenGLCoreTexture: Type = %d Size = %dx%d (%dx%d) ColorFormat = %d (%d)%s -> %#06x %#06x %#06x%s",
|
||||
|
@ -70,7 +69,6 @@ public:
|
|||
InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : ""
|
||||
);
|
||||
os::Printer::log(lbuf, ELL_DEBUG);
|
||||
#endif
|
||||
|
||||
const auto *tmpImages = &srcImages;
|
||||
|
||||
|
@ -111,7 +109,6 @@ public:
|
|||
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 (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
|
||||
GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
|
||||
|
@ -120,8 +117,6 @@ public:
|
|||
else
|
||||
GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_GL_ERROR(Driver);
|
||||
|
||||
for (size_t i = 0; i < tmpImages->size(); ++i)
|
||||
|
@ -189,7 +184,6 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
char lbuf[100];
|
||||
snprintf_irr(lbuf, sizeof(lbuf),
|
||||
"COpenGLCoreTexture: RTT Type = %d Size = %dx%d ColorFormat = %d -> %#06x %#06x %#06x%s",
|
||||
|
@ -197,7 +191,6 @@ public:
|
|||
InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : ""
|
||||
);
|
||||
os::Printer::log(lbuf, ELL_DEBUG);
|
||||
#endif
|
||||
|
||||
GL.GenTextures(1, &TextureName);
|
||||
TEST_GL_ERROR(Driver);
|
||||
|
@ -218,10 +211,7 @@ public:
|
|||
GL.TexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
#if defined(GL_VERSION_1_2)
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
#endif
|
||||
|
||||
StatesCache.WrapU = ETC_CLAMP_TO_EDGE;
|
||||
StatesCache.WrapV = ETC_CLAMP_TO_EDGE;
|
||||
|
@ -258,6 +248,9 @@ public:
|
|||
GL.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
GL.TexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
break;
|
||||
default:
|
||||
_IRR_DEBUG_BREAK_IF(1)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!name.empty())
|
||||
|
@ -306,6 +299,7 @@ public:
|
|||
|
||||
if (!LockImage) {
|
||||
core::dimension2d<u32> lockImageSize(IImage::getMipMapsSize(Size, MipLevelStored));
|
||||
_IRR_DEBUG_BREAK_IF(lockImageSize.Width == 0 || lockImageSize.Height == 0)
|
||||
|
||||
// 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);
|
||||
|
@ -321,7 +315,7 @@ public:
|
|||
|
||||
if (use_gl_impl) {
|
||||
|
||||
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;
|
||||
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, this);
|
||||
TEST_GL_ERROR(Driver);
|
||||
|
@ -620,6 +614,7 @@ protected:
|
|||
TEST_GL_ERROR(Driver);
|
||||
break;
|
||||
default:
|
||||
_IRR_DEBUG_BREAK_IF(1)
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -637,6 +632,7 @@ protected:
|
|||
TEST_GL_ERROR(Driver);
|
||||
break;
|
||||
default:
|
||||
_IRR_DEBUG_BREAK_IF(1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,8 +50,7 @@ void COpenGL3Driver::initFeatures()
|
|||
TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}; // WARNING: may not be renderable
|
||||
TextureFormats[ECF_R5G6B5] = {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; // GL_RGB565 is an extension until 4.1
|
||||
TextureFormats[ECF_R8G8B8] = {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}; // WARNING: may not be renderable
|
||||
// FIXME: shouldn't this simply be GL_UNSIGNED_BYTE?
|
||||
TextureFormats[ECF_A8R8G8B8] = {GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV};
|
||||
TextureFormats[ECF_A8R8G8B8] = {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE};
|
||||
TextureFormats[ECF_R16F] = {GL_R16F, GL_RED, GL_HALF_FLOAT};
|
||||
TextureFormats[ECF_G16R16F] = {GL_RG16F, GL_RG, GL_HALF_FLOAT};
|
||||
TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT};
|
||||
|
|
|
@ -146,7 +146,7 @@ void COpenGLES2Driver::initFeatures()
|
|||
MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE);
|
||||
if (LODBiasSupported)
|
||||
GL.GetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias);
|
||||
GL.GetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec...
|
||||
GL.GetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine);
|
||||
GL.GetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue