Skip to content

Commit

Permalink
[GL] Provide rowStride for SetPixelStoreUnpack in pixels instead of b…
Browse files Browse the repository at this point in the history
…ytes (#154)

* Provide rowStride for SetPixelStoreUnpack in pixels instead of bytes

* Handle the case when GetMemoryFootprint returns 0
  • Loading branch information
st0rmbtw authored Jan 29, 2025
1 parent c0a91e9 commit 542a01d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sources/Renderer/OpenGL/Texture/GLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../../TextureUtils.h"
#include "../../../Core/Exception.h"
#include "../../../Core/CoreUtils.h"
#include <LLGL/Format.h>
#include <LLGL/Utils/ForRange.h>
#include <LLGL/Backend/OpenGL/NativeHandle.h>

Expand Down Expand Up @@ -866,7 +867,10 @@ void GLTexture::TextureSubImage(const TextureRegion& region, const ImageView& sr
{
if (!IsRenderbuffer())
{
GLStateManager::Get().SetPixelStoreUnpack(srcImageView.rowStride, region.extent.height, 1);
const std::uint32_t bytesPerPixel = GetMemoryFootprint(srcImageView.format, srcImageView.dataType, 1);
const std::uint32_t srcRowStride = bytesPerPixel > 0 ? srcImageView.rowStride / bytesPerPixel : 0;

GLStateManager::Get().SetPixelStoreUnpack(srcRowStride, region.extent.height, 1);
{
#if LLGL_GLEXT_DIRECT_STATE_ACCESS
if (HasExtension(GLExt::ARB_direct_state_access))
Expand Down Expand Up @@ -1272,7 +1276,10 @@ void GLTexture::AllocTextureStorage(const TextureDescriptor& textureDesc, const
intermediateImageView = *initialImage;
intermediateImageView.format = MapSwizzleImageFormat(initialImage->format);
initialImage = &intermediateImageView;
GLStateManager::Get().SetPixelStoreUnpack(initialImage->rowStride, textureDesc.extent.height, 1);

const std::uint32_t bytesPerPixel = GetMemoryFootprint(initialImage->format, initialImage->dataType, 1);
const std::uint32_t srcRowStride = bytesPerPixel > 0 ? initialImage->rowStride / bytesPerPixel : 0;
GLStateManager::Get().SetPixelStoreUnpack(srcRowStride, textureDesc.extent.height, 1);
}

/* Build texture storage and upload image dataa */
Expand Down

0 comments on commit 542a01d

Please sign in to comment.