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
|
@ -283,6 +283,17 @@ inline s32 s32_clamp(s32 value, s32 low, s32 high)
|
||||||
return clamp(value, low, 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
|
float IEEE-754 bit representation
|
||||||
|
|
||||||
|
|
|
@ -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);
|
a = core::s32_clamp((a >> sdiv) + bias, 0, 255);
|
||||||
r = core::s32_clamp((r >> sdiv) + bias, 0, 255);
|
r = core::s32_clamp((r >> sdiv) + bias, 0, 255);
|
||||||
|
|
|
@ -14,20 +14,18 @@ namespace video
|
||||||
class COpenGLCoreFeature
|
class COpenGLCoreFeature
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
COpenGLCoreFeature() :
|
COpenGLCoreFeature() = default;
|
||||||
BlendOperation(false), ColorAttachment(0), MultipleRenderTarget(0), MaxTextureUnits(1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~COpenGLCoreFeature()
|
virtual ~COpenGLCoreFeature()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlendOperation;
|
bool BlendOperation = false;
|
||||||
|
bool TexStorage = false;
|
||||||
|
|
||||||
u8 ColorAttachment;
|
u8 ColorAttachment = 0;
|
||||||
u8 MultipleRenderTarget;
|
u8 MultipleRenderTarget = 0;
|
||||||
u8 MaxTextureUnits;
|
u8 MaxTextureUnits = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -503,10 +503,22 @@ protected:
|
||||||
return;
|
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) {
|
switch (Type) {
|
||||||
case ETT_2D:
|
case ETT_2D:
|
||||||
GL.TexImage2D(TextureType, 0, InternalFormat,
|
if (Driver->getFeature().TexStorage) {
|
||||||
Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
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);
|
TEST_GL_ERROR(Driver);
|
||||||
break;
|
break;
|
||||||
case ETT_2D_MS: {
|
case ETT_2D_MS: {
|
||||||
|
@ -531,8 +543,14 @@ protected:
|
||||||
}
|
}
|
||||||
case ETT_CUBEMAP:
|
case ETT_CUBEMAP:
|
||||||
for (u32 i = 0; i < 6; i++) {
|
for (u32 i = 0; i < 6; i++) {
|
||||||
GL.TexImage2D(getTextureTarget(i), 0, InternalFormat,
|
GLenum target = getTextureTarget(i);
|
||||||
Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
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);
|
TEST_GL_ERROR(Driver);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -78,6 +78,7 @@ void COpenGL3Driver::initFeatures()
|
||||||
// COGLESCoreExtensionHandler::Feature
|
// COGLESCoreExtensionHandler::Feature
|
||||||
static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed");
|
static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed");
|
||||||
Feature.BlendOperation = true;
|
Feature.BlendOperation = true;
|
||||||
|
Feature.TexStorage = isVersionAtLeast(4, 2) || queryExtension("GL_ARB_texture_storage");
|
||||||
Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS);
|
Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS);
|
||||||
Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES;
|
Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES;
|
||||||
Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS);
|
Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS);
|
||||||
|
|
|
@ -131,6 +131,7 @@ void COpenGLES2Driver::initFeatures()
|
||||||
// COGLESCoreExtensionHandler::Feature
|
// COGLESCoreExtensionHandler::Feature
|
||||||
static_assert(MATERIAL_MAX_TEXTURES <= 8, "Only up to 8 textures are guaranteed");
|
static_assert(MATERIAL_MAX_TEXTURES <= 8, "Only up to 8 textures are guaranteed");
|
||||||
Feature.BlendOperation = true;
|
Feature.BlendOperation = true;
|
||||||
|
Feature.TexStorage = Version.Major >= 3 || queryExtension("GL_ARB_texture_storage");
|
||||||
Feature.ColorAttachment = 1;
|
Feature.ColorAttachment = 1;
|
||||||
if (MRTSupported)
|
if (MRTSupported)
|
||||||
Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS);
|
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---------------------------------------
|
// ------------------ Video---------------------------------------
|
||||||
/*!
|
/*!
|
||||||
Pixel = dest * ( 1 - alpha ) + source * alpha
|
Pixel = dest * ( 1 - alpha ) + source * alpha
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue