From 926f7cf115b5599e510219e28493dc8962ed0094 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 22 Mar 2016 23:27:54 +1300 Subject: [PATCH] Possible fix for #738 Explicitly set byte alignment in pixel transfer operations --- src/graphics/opengl/gl21device.cpp | 6 ++++++ src/graphics/opengl/gl33device.cpp | 6 ++++++ src/graphics/opengl/gldevice.cpp | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index e4f6145b..fe5d3b69 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -823,6 +823,9 @@ Texture CGL21Device::CreateTexture(ImageData *data, const TextureCreateParams &p PreparedTextureData texData = PrepareTextureData(data, params.format); result.alpha = texData.alpha; + glPixelStorei(GL_UNPACK_ROW_LENGTH, texData.actualSurface->pitch / texData.actualSurface->format->BytesPerPixel); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texData.actualSurface->w, texData.actualSurface->h, 0, texData.sourceFormat, GL_UNSIGNED_BYTE, texData.actualSurface->pixels); @@ -894,6 +897,9 @@ void CGL21Device::UpdateTexture(const Texture& texture, Math::IntPoint offset, I PreparedTextureData texData = PrepareTextureData(data, format); + glPixelStorei(GL_UNPACK_ROW_LENGTH, texData.actualSurface->pitch / texData.actualSurface->format->BytesPerPixel); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexSubImage2D(GL_TEXTURE_2D, 0, offset.x, offset.y, texData.actualSurface->w, texData.actualSurface->h, texData.sourceFormat, GL_UNSIGNED_BYTE, texData.actualSurface->pixels); diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index f355aff1..781ed053 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -852,6 +852,9 @@ Texture CGL33Device::CreateTexture(ImageData *data, const TextureCreateParams &p PreparedTextureData texData = PrepareTextureData(data, params.format); result.alpha = texData.alpha; + glPixelStorei(GL_UNPACK_ROW_LENGTH, texData.actualSurface->pitch / texData.actualSurface->format->BytesPerPixel); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texData.actualSurface->w, texData.actualSurface->h, 0, texData.sourceFormat, GL_UNSIGNED_BYTE, texData.actualSurface->pixels); @@ -921,6 +924,9 @@ void CGL33Device::UpdateTexture(const Texture& texture, Math::IntPoint offset, I PreparedTextureData texData = PrepareTextureData(data, format); + glPixelStorei(GL_UNPACK_ROW_LENGTH, texData.actualSurface->pitch / texData.actualSurface->format->BytesPerPixel); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexSubImage2D(GL_TEXTURE_2D, 0, offset.x, offset.y, texData.actualSurface->w, texData.actualSurface->h, texData.sourceFormat, GL_UNSIGNED_BYTE, texData.actualSurface->pixels); diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index fcaf7d0e..85c16578 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -725,6 +725,9 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par PreparedTextureData texData = PrepareTextureData(data, params.format); result.alpha = texData.alpha; + glPixelStorei(GL_UNPACK_ROW_LENGTH, texData.actualSurface->pitch / texData.actualSurface->format->BytesPerPixel); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texData.actualSurface->w, texData.actualSurface->h, 0, texData.sourceFormat, GL_UNSIGNED_BYTE, texData.actualSurface->pixels); @@ -826,6 +829,9 @@ void CGLDevice::UpdateTexture(const Texture& texture, Math::IntPoint offset, Ima PreparedTextureData texData = PrepareTextureData(data, format); + glPixelStorei(GL_UNPACK_ROW_LENGTH, texData.actualSurface->pitch / texData.actualSurface->format->BytesPerPixel); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexSubImage2D(GL_TEXTURE_2D, 0, offset.x, offset.y, texData.actualSurface->w, texData.actualSurface->h, texData.sourceFormat, GL_UNSIGNED_BYTE, texData.actualSurface->pixels);