@@ -863,14 +863,25 @@ void GLTexture::CopyImageFromBuffer(
863863 GLStateManager::Get ().BindBuffer (GLBufferTarget::PixelUnpackBuffer, 0 );
864864}
865865
866+ static GLuint GetGLRowLengthOrZero (const ImageView& imageView)
867+ {
868+ if (imageView.rowStride > 0 )
869+ {
870+ /* Divide row stride by bytes-per-pixel; This will be zero for compressed formats! */
871+ const std::uint32_t bytesPerPixel = static_cast <std::uint32_t >(GetMemoryFootprint (imageView.format , imageView.dataType , 1 ));
872+ if (bytesPerPixel > 0 )
873+ return static_cast <GLuint>(imageView.rowStride / bytesPerPixel);
874+ }
875+ return 0 ;
876+ }
877+
866878void GLTexture::TextureSubImage (const TextureRegion& region, const ImageView& srcImageView, bool restoreBoundTexture)
867879{
868880 if (!IsRenderbuffer ())
869881 {
870- const std::uint32_t bytesPerPixel = GetMemoryFootprint (srcImageView.format , srcImageView.dataType , 1 );
871- const std::uint32_t srcRowStride = bytesPerPixel > 0 ? srcImageView.rowStride / bytesPerPixel : 0 ;
882+ const GLuint srcRowLength = GetGLRowLengthOrZero (srcImageView);
872883
873- GLStateManager::Get ().SetPixelStoreUnpack (srcRowStride , region.extent .height , 1 );
884+ GLStateManager::Get ().SetPixelStoreUnpack (srcRowLength , region.extent .height , 1 );
874885 {
875886 #if LLGL_GLEXT_DIRECT_STATE_ACCESS
876887 if (HasExtension (GLExt::ARB_direct_state_access))
@@ -1277,9 +1288,8 @@ void GLTexture::AllocTextureStorage(const TextureDescriptor& textureDesc, const
12771288 intermediateImageView.format = MapSwizzleImageFormat (initialImage->format );
12781289 initialImage = &intermediateImageView;
12791290
1280- const std::uint32_t bytesPerPixel = GetMemoryFootprint (initialImage->format , initialImage->dataType , 1 );
1281- const std::uint32_t srcRowStride = bytesPerPixel > 0 ? initialImage->rowStride / bytesPerPixel : 0 ;
1282- GLStateManager::Get ().SetPixelStoreUnpack (srcRowStride, textureDesc.extent .height , 1 );
1291+ const GLuint srcRowLength = GetGLRowLengthOrZero (*initialImage);
1292+ GLStateManager::Get ().SetPixelStoreUnpack (srcRowLength, textureDesc.extent .height , 1 );
12831293 }
12841294
12851295 /* Build texture storage and upload image dataa */
@@ -1306,7 +1316,8 @@ void GLTexture::AllocTextureStorage(const TextureDescriptor& textureDesc, const
13061316 InitializeGLTextureSwizzleWithFormat (GetType (), swizzleFormat_, {}, true );
13071317 #endif
13081318
1309- if (initialImage != nullptr ) {
1319+ if (initialImage != nullptr )
1320+ {
13101321 GLStateManager::Get ().SetPixelStoreUnpack (0 , 0 , 1 );
13111322
13121323 /* Generate MIP-maps if enabled */
0 commit comments