Skip to content

Commit

Permalink
[GL] Fixed retrieving integer format texture data.
Browse files Browse the repository at this point in the history
- Add glMemoryBarrier() to ReadBuffer() and ReadTexture() functions when resources were created with BindFlags::Storage flag.
- Map GL image format to integer specific type when integer format is requested, e.g. GL_RGBA_INTEGER instead of GL_RGBA.
  • Loading branch information
LukasBanana committed May 12, 2024
1 parent 9ffbed5 commit e20f1fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 20 additions & 0 deletions sources/Renderer/OpenGL/GLRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ void GLRenderSystem::WriteBuffer(Buffer& buffer, std::uint64_t offset, const voi
void GLRenderSystem::ReadBuffer(Buffer& buffer, std::uint64_t offset, void* data, std::uint64_t dataSize)
{
auto& bufferGL = LLGL_CAST(GLBuffer&, buffer);

#ifdef GL_ARB_shader_image_load_store
if ((bufferGL.GetBindFlags() & BindFlags::Storage) != 0)
{
/* Ensure all shader writes to the buffer completed */
if (HasExtension(GLExt::ARB_shader_image_load_store))
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
}
#endif

bufferGL.GetBufferSubData(static_cast<GLintptr>(offset), static_cast<GLsizeiptr>(dataSize), data);
}

Expand Down Expand Up @@ -336,6 +346,16 @@ void GLRenderSystem::ReadTexture(Texture& texture, const TextureRegion& textureR
/* Bind texture and write texture sub data */
LLGL_ASSERT_PTR(dstImageView.data);
auto& textureGL = LLGL_CAST(GLTexture&, texture);

#ifdef GL_ARB_shader_image_load_store
if ((textureGL.GetBindFlags() & BindFlags::Storage) != 0)
{
/* Ensure all shader writes to the texture completed */
if (HasExtension(GLExt::ARB_shader_image_load_store))
glMemoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT);
}
#endif

textureGL.GetTextureSubImage(textureRegion, dstImageView, false);
}

Expand Down
8 changes: 4 additions & 4 deletions sources/Renderer/OpenGL/Texture/GLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ static void GLGetTextureSubImage(
static_cast<GLsizei>(extent.width),
static_cast<GLsizei>(extent.height),
static_cast<GLsizei>(extent.depth),
GLTypes::Map(dstImageView.format),
GLTypes::Map(dstImageView.format, IsIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.dataType),
static_cast<GLsizei>(dstImageView.dataSize),
dstImageView.data
Expand Down Expand Up @@ -804,7 +804,7 @@ static void GLGetTexImage(
glGetTexImage(
GLTypes::Map(type),
mipLevel,
GLTypes::Map(format),
GLTypes::Map(format, IsIntDataType(dataType)),
GLTypes::Map(dataType),
data
);
Expand Down Expand Up @@ -880,7 +880,7 @@ static void GLGetTextureImage(
glGetTextureImage(
stagingTextureID,
0,
GLTypes::Map(dstImageView.format),
GLTypes::Map(dstImageView.format, IsIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.dataType),
static_cast<GLsizei>(dstImageView.dataSize),
dstImageView.data
Expand Down Expand Up @@ -908,7 +908,7 @@ static void GLGetTextureImage(
glGetTextureImage(
srcTextureID,
mipLevel,
GLTypes::Map(dstImageView.format),
GLTypes::Map(dstImageView.format, IsIntDataType(dstImageView.dataType)),
GLTypes::Map(dstImageView.dataType),
static_cast<GLsizei>(dstImageView.dataSize),
dstImageView.data
Expand Down

0 comments on commit e20f1fa

Please sign in to comment.