Skip to content

Commit

Permalink
[GL] Fixed initialization of textures with unsigned integer format.
Browse files Browse the repository at this point in the history
- Fixed mixup between GL_R32I and GL_R32UI in GLTypes::UnmapFormat().
- Check for both signed and unsigned integer data types when initializing GL textures.
- Deprecated IsIntDataType() and renamed new one to IsSIntDataType() as counterpart to IsUIntDataType().

NOTE: IsIntDataType() should be not be removed in the next release version,
      but instead use both IsSIntDataType() and IsUIntDataType() to cover all integer types.
      Since this is a breaking change, it needs to be deprecated first.
  • Loading branch information
LukasBanana committed Jan 25, 2025
1 parent 671c74e commit e7eeb99
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
9 changes: 8 additions & 1 deletion include/LLGL/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,21 @@ LLGL_EXPORT std::uint32_t DataTypeSize(const DataType dataType);
\brief Determines if the argument refers to a signed integer data type.
\return True if the specified data type equals one of the following enumeration entries: DataType::Int8, DataType::Int16, DataType::Int32.
*/
LLGL_EXPORT bool IsIntDataType(const DataType dataType);
LLGL_EXPORT bool IsSIntDataType(const DataType dataType);

/**
\brief Determines if the argument refers to an unsigned integer data type.
\return True if the specified data type equals one of the following enumeration entries: DataType::UInt8, DataType::UInt16, DataType::UInt32.
*/
LLGL_EXPORT bool IsUIntDataType(const DataType dataType);

//! \deprecated Since 0.04b; Use IsSIntDataType() instead.
LLGL_DEPRECATED("LLGL::IsIntDataType() is deprecated since 0.04b; Use IsSIntDataType() instead.", "IsSIntDataType")
inline bool IsIntDataType(const DataType dataType)
{
return IsSIntDataType(dataType);
}

/**
\brief Determines if the argument refers to a floating-pointer data type.
\return True if the specified data type equals one of the following enumeration entries: DataType::Float16, DataType::Float32, DataType::Float64.
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ LLGL_EXPORT std::uint32_t DataTypeSize(const DataType dataType)
return 0;
}

LLGL_EXPORT bool IsIntDataType(const DataType dataType)
LLGL_EXPORT bool IsSIntDataType(const DataType dataType)
{
return (dataType == DataType::Int8 || dataType == DataType::Int16 || dataType == DataType::Int32);
}
Expand Down
4 changes: 2 additions & 2 deletions sources/Renderer/OpenGL/GLTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ Format UnmapFormat(const GLenum internalFormat)
case GL_R16I: return Format::R16SInt;
case GL_R16F: return Format::R16Float;

case GL_R32I: return Format::R32UInt;
case GL_R32UI: return Format::R32SInt;
case GL_R32UI: return Format::R32UInt;
case GL_R32I: return Format::R32SInt;
case GL_R32F: return Format::R32Float;

/* --- RG color formats --- */
Expand Down
16 changes: 11 additions & 5 deletions sources/Renderer/OpenGL/Texture/GLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ namespace LLGL
{


//TODO: replace this with a public 'IsIntDataType()' function once the deprecated version has been removed in the next release version.
static bool IsSIntOrUIntDataType(DataType dataType)
{
return (IsSIntDataType(dataType) || IsUIntDataType(dataType));
}

// Returns true if a GL renderbuffer is sufficient for a texture with the specified bind flags
static bool IsRenderbufferSufficient(const TextureDescriptor& desc)
{
Expand Down Expand Up @@ -919,7 +925,7 @@ static void GLGetTextureSubImage(
static_cast<GLsizei>(extent.width),
static_cast<GLsizei>(extent.height),
static_cast<GLsizei>(extent.depth),
GLTypes::Map(dstImageView.format, IsIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.format, IsSIntOrUIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.dataType),
static_cast<GLsizei>(dstImageView.dataSize),
dstImageView.data
Expand Down Expand Up @@ -1003,7 +1009,7 @@ static void GLGetTexImage(
glGetTexImage(
cubeFaceTargetGL,
mipLevel,
GLTypes::Map(dstImageView.format, IsIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.format, IsSIntOrUIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.dataType),
dstImageData
);
Expand All @@ -1015,7 +1021,7 @@ static void GLGetTexImage(
glGetTexImage(
targetGL,
mipLevel,
GLTypes::Map(dstImageView.format, IsIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.format, IsSIntOrUIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.dataType),
dstImageView.data
);
Expand Down Expand Up @@ -1095,7 +1101,7 @@ static void GLGetTextureImage(
glGetTextureImage(
stagingTextureID,
0,
GLTypes::Map(dstImageView.format, IsIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.format, IsSIntOrUIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.dataType),
static_cast<GLsizei>(dstImageView.dataSize),
dstImageView.data
Expand All @@ -1122,7 +1128,7 @@ static void GLGetTextureImage(
glGetTextureImage(
srcTextureID,
mipLevel,
GLTypes::Map(dstImageView.format, IsIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.format, IsSIntOrUIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.dataType),
static_cast<GLsizei>(dstImageView.dataSize),
dstImageView.data
Expand Down

0 comments on commit e7eeb99

Please sign in to comment.