mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Prefer immutable texture storage when available
This commit is contained in:
parent
427a7e4998
commit
d5bf094f9a
7 changed files with 42 additions and 24 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -503,10 +503,22 @@ protected:
|
|||
return;
|
||||
}
|
||||
|
||||
u32 levels = 1;
|
||||
if (HasMipMaps) {
|
||||
levels = core::u32_log2(core::max_(Size.Width, Size.Height)) + 1;
|
||||
}
|
||||
|
||||
// reference: <https://www.khronos.org/opengl/wiki/Texture_Storage>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue