From a9ba92f16c3ca325de870892615747ea48aa490a Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 6 Sep 2016 13:22:27 -0700 Subject: [PATCH] Fix alignment of small pages --- libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 3b512b3278..ce359ad6c2 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -118,11 +118,17 @@ bool TransferState::increment() { return false; } +#define DEFAULT_GL_PIXEL_ALIGNMENT 4 void TransferState::populatePage(uint8_t* dst) { uvec3 pageSize = currentPageSize(); + auto bytesPerPageLine = _bytesPerPixel * pageSize.x; + if (0 != (bytesPerPageLine % DEFAULT_GL_PIXEL_ALIGNMENT)) { + bytesPerPageLine += DEFAULT_GL_PIXEL_ALIGNMENT - (bytesPerPageLine % DEFAULT_GL_PIXEL_ALIGNMENT); + assert(0 == (bytesPerPageLine % DEFAULT_GL_PIXEL_ALIGNMENT)); + } for (uint32_t y = 0; y < pageSize.y; ++y) { uint32_t srcOffset = (_bytesPerLine * (_mipOffset.y + y)) + (_bytesPerPixel * _mipOffset.x); - uint32_t dstOffset = (_bytesPerPixel * pageSize.x) * y; + uint32_t dstOffset = bytesPerPageLine * y; memcpy(dst + dstOffset, _srcPointer + srcOffset, pageSize.x * _bytesPerPixel); } }