diff --git a/irr/include/irrMath.h b/irr/include/irrMath.h index e9c86156d..e11d47360 100644 --- a/irr/include/irrMath.h +++ b/irr/include/irrMath.h @@ -283,6 +283,17 @@ inline s32 s32_clamp(s32 value, s32 low, s32 high) return clamp(value, low, high); } +// integer log2 of an integer. returning 0 if denormal +inline s32 u32_log2(u32 in) +{ + s32 ret = 0; + while (in > 1) { + in >>= 1; + ret++; + } + return ret; +} + /* float IEEE-754 bit representation diff --git a/irr/src/CImage.cpp b/irr/src/CImage.cpp index de4df0c0f..29c115c8a 100644 --- a/irr/src/CImage.cpp +++ b/irr/src/CImage.cpp @@ -363,7 +363,7 @@ inline SColor CImage::getPixelBox(s32 x, s32 y, s32 fx, s32 fy, s32 bias) const } } - s32 sdiv = s32_log2_s32(fx * fy); + s32 sdiv = core::u32_log2(fx * fy); a = core::s32_clamp((a >> sdiv) + bias, 0, 255); r = core::s32_clamp((r >> sdiv) + bias, 0, 255); diff --git a/irr/src/COpenGLCoreFeature.h b/irr/src/COpenGLCoreFeature.h index dc3d40e04..629bec2a1 100644 --- a/irr/src/COpenGLCoreFeature.h +++ b/irr/src/COpenGLCoreFeature.h @@ -14,20 +14,18 @@ namespace video class COpenGLCoreFeature { public: - COpenGLCoreFeature() : - BlendOperation(false), ColorAttachment(0), MultipleRenderTarget(0), MaxTextureUnits(1) - { - } + COpenGLCoreFeature() = default; virtual ~COpenGLCoreFeature() { } - bool BlendOperation; + bool BlendOperation = false; + bool TexStorage = false; - u8 ColorAttachment; - u8 MultipleRenderTarget; - u8 MaxTextureUnits; + u8 ColorAttachment = 0; + u8 MultipleRenderTarget = 0; + u8 MaxTextureUnits = 0; }; } diff --git a/irr/src/COpenGLCoreTexture.h b/irr/src/COpenGLCoreTexture.h index 28394886c..439f786c6 100644 --- a/irr/src/COpenGLCoreTexture.h +++ b/irr/src/COpenGLCoreTexture.h @@ -503,10 +503,22 @@ protected: return; } + u32 levels = 1; + if (HasMipMaps) { + levels = core::u32_log2(core::max_(Size.Width, Size.Height)) + 1; + } + + // reference: + switch (Type) { case ETT_2D: - GL.TexImage2D(TextureType, 0, InternalFormat, - Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + if (Driver->getFeature().TexStorage) { + GL.TexStorage2D(TextureType, levels, InternalFormat, + Size.Width, Size.Height); + } else { + GL.TexImage2D(TextureType, 0, InternalFormat, + Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + } TEST_GL_ERROR(Driver); break; case ETT_2D_MS: { @@ -531,8 +543,14 @@ protected: } case ETT_CUBEMAP: for (u32 i = 0; i < 6; i++) { - GL.TexImage2D(getTextureTarget(i), 0, InternalFormat, - Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GLenum target = getTextureTarget(i); + if (Driver->getFeature().TexStorage) { + GL.TexStorage2D(target, levels, InternalFormat, + Size.Width, Size.Height); + } else { + GL.TexImage2D(target, 0, InternalFormat, + Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + } TEST_GL_ERROR(Driver); } break; diff --git a/irr/src/OpenGL3/Driver.cpp b/irr/src/OpenGL3/Driver.cpp index 43ee9ba45..8339068a6 100644 --- a/irr/src/OpenGL3/Driver.cpp +++ b/irr/src/OpenGL3/Driver.cpp @@ -78,6 +78,7 @@ void COpenGL3Driver::initFeatures() // COGLESCoreExtensionHandler::Feature static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed"); Feature.BlendOperation = true; + Feature.TexStorage = isVersionAtLeast(4, 2) || queryExtension("GL_ARB_texture_storage"); Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); diff --git a/irr/src/OpenGLES2/Driver.cpp b/irr/src/OpenGLES2/Driver.cpp index 7c98fca8d..6000059ed 100644 --- a/irr/src/OpenGLES2/Driver.cpp +++ b/irr/src/OpenGLES2/Driver.cpp @@ -131,6 +131,7 @@ void COpenGLES2Driver::initFeatures() // COGLESCoreExtensionHandler::Feature static_assert(MATERIAL_MAX_TEXTURES <= 8, "Only up to 8 textures are guaranteed"); Feature.BlendOperation = true; + Feature.TexStorage = Version.Major >= 3 || queryExtension("GL_ARB_texture_storage"); Feature.ColorAttachment = 1; if (MRTSupported) Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); diff --git a/irr/src/SoftwareDriver2_helper.h b/irr/src/SoftwareDriver2_helper.h index 602f9e295..76ea249ea 100644 --- a/irr/src/SoftwareDriver2_helper.h +++ b/irr/src/SoftwareDriver2_helper.h @@ -93,17 +93,6 @@ inline void memset16(void *dest, const u16 value, size_t bytesize) } } -// integer log2 of an integer. returning 0 as denormal -static inline s32 s32_log2_s32(u32 in) -{ - s32 ret = 0; - while (in > 1) { - in >>= 1; - ret++; - } - return ret; -} - // ------------------ Video--------------------------------------- /*! Pixel = dest * ( 1 - alpha ) + source * alpha