Skip to content

Commit

Permalink
[GL] Fixed initial texture min/mag filters for integer types.
Browse files Browse the repository at this point in the history
- Replaced IsIntegralFormat() with IsIntegerFormat() which is exclusively referring to signed/unsigned integer formats (not normalized formats).
- Deprecated IsIntegralFormat() function to strictly distinguish between integer, float, and normalized formats.

Breaking change: GetFormatAttribs().flags now strictly distinguishes FormatFlags::IsNormalized and FormatFlags::IsInteger.
  • Loading branch information
LukasBanana committed Aug 28, 2024
1 parent 91c708b commit eae155e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
12 changes: 12 additions & 0 deletions include/LLGL/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


#include <LLGL/Export.h>
#include <LLGL/Deprecated.h>
#include <cstdint>
#include <cstddef>

Expand Down Expand Up @@ -534,11 +535,22 @@ LLGL_EXPORT bool IsNormalizedFormat(const Format format);
/**
\brief Returns true if the specified hardware format is an integral format (like Format::RGBA8UInt, Format::RGBA8UNorm, Format::R8SInt etc.).
\remarks This also includes all normalized formats.
\deprecated Since 0.04b; Use a combination of IsIntegerFormat(), IsFloatFormat(), and IsNormalizedFormat() instead!
\see IsNormalizedFormat
\see Format
*/
LLGL_DEPRECATED("IsIntegralFormat() is deprecated since 0.04b; Use a combination of IsIntegerFormat(), IsFloatFormat(), and IsNormalizedFormat() instead!")
LLGL_EXPORT bool IsIntegralFormat(const Format format);

/**
\brief Returns true if the specified hardware format is an integer format (like Format::RGBA8UInt, Format::R8SInt etc.).
\remarks This does not include normalized formats such as Format::RGBA8UNorm.
While these types use an integer type as input, they are normalized to a fractional number in the closed range [0, 1].
\see IsNormalizedFormat
\see Format
*/
LLGL_EXPORT bool IsIntegerFormat(const Format format);

/**
\brief Returns true if the specified hardware format is a floating-point format (like Format::RGBA32Float, Format::R32Float etc.).
\remarks This does not include depth-stencil formats or compressed formats.
Expand Down
42 changes: 16 additions & 26 deletions sources/Renderer/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ static constexpr long Vertex = FormatFlags::SupportsVertex;
static constexpr long Dim1D_2D = Dim1D | Dim2D;
static constexpr long Dim2D_3D = Dim2D | Dim3D;
static constexpr long Dim1D_2D_3D = Dim1D | Dim2D | Dim3D;
static constexpr long UInt = Integer | Unsigned;
static constexpr long SInt = Integer;
static constexpr long UNorm = UInt | Norm;
static constexpr long SNorm = SInt | Norm;
static constexpr long UInt = Integer | Unsigned;
static constexpr long SNorm = Norm;
static constexpr long UNorm = Unsigned | Norm;
static constexpr long SFloat = 0;
static constexpr long UFloat = Unsigned;

Expand Down Expand Up @@ -284,35 +284,25 @@ LLGL_EXPORT bool IsNormalizedFormat(const Format format)
return ((GetFormatAttribs(format).flags & FormatFlags::IsNormalized) != 0);
}

//deprecated
LLGL_EXPORT bool IsIntegralFormat(const Format format)
{
if (format >= Format::R8UNorm && format <= Format::BGRA8SInt)
return !IsFloatFormat(format);
else
return false;
const auto& formatAttribs = GetFormatAttribs(format);
return
(
(formatAttribs.flags & (FormatFlags::IsInteger | FormatFlags::IsNormalized)) != 0 &&
(formatAttribs.flags & (FormatFlags::HasDepthStencil | FormatFlags::IsCompressed)) == 0
);
}

LLGL_EXPORT bool IsIntegerFormat(const Format format)
{
return ((GetFormatAttribs(format).flags & FormatFlags::IsInteger) != 0);
}

//TODO: needs update
LLGL_EXPORT bool IsFloatFormat(const Format format)
{
switch (format)
{
case Format::R16Float:
case Format::R64Float:
case Format::R32Float:
case Format::RG16Float:
case Format::RG32Float:
case Format::RG64Float:
case Format::RGB16Float:
case Format::RGB32Float:
case Format::RGB64Float:
case Format::RGBA16Float:
case Format::RGBA32Float:
case Format::RGBA64Float:
return true;
default:
return false;
}
return ((GetFormatAttribs(format).flags & FormatFlags::IsInteger) == 0);
}

LLGL_EXPORT std::uint32_t DataTypeSize(const DataType dataType)
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/OpenGL/Buffer/GLVertexArrayObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void GLConvertVertexAttrib(GLVertexAttribute& dst, const VertexAttribute& src, G
dst.stride = static_cast<GLsizei>(src.stride);
dst.offsetPtrSized = static_cast<GLsizeiptr>(src.offset);
dst.divisor = static_cast<GLuint>(src.instanceDivisor);
dst.isInteger = (formatAttribs.flags & FormatFlags::IsNormalized) == 0 && !IsFloatFormat(src.format);
dst.isInteger = IsIntegerFormat(src.format);
}

void GLVertexArrayObject::Release()
Expand Down
4 changes: 2 additions & 2 deletions sources/Renderer/OpenGL/Texture/GLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ void GLTexture::BindTexParameters(const GL2XSampler& sampler)
static GLint GetInitialGlTextureMinFilter(const TextureDescriptor& textureDesc)
{
/* Integral texture formats cannot use linear samplers */
if (IsIntegralFormat(textureDesc.format))
if (IsIntegerFormat(textureDesc.format))
return (IsMipMappedTexture(textureDesc) ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
else
return (IsMipMappedTexture(textureDesc) ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
Expand All @@ -992,7 +992,7 @@ static GLint GetInitialGlTextureMinFilter(const TextureDescriptor& textureDesc)
static GLint GetInitialGlTextureMagFilter(const TextureDescriptor& textureDesc)
{
/* Integral texture formats cannot use linear samplers */
return (IsIntegralFormat(textureDesc.format) ? GL_NEAREST : GL_LINEAR);
return (IsIntegerFormat(textureDesc.format) ? GL_NEAREST : GL_LINEAR);
}

static ImageFormat MapSwizzleImageFormat(const ImageFormat format)
Expand Down

0 comments on commit eae155e

Please sign in to comment.