ref: b8ceefcefd5dadf3c360347629ed4c472d4f5f94
parent: 86d084f750c175787ac81fc4133065e4450c42a7
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Sep 17 14:05:38 EDT 2020
Flexible OpenGL unpack alignment
--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -294,6 +294,13 @@
}
*/
+static void SetTextureUploadAlignment(size_t pitch)
+{
+ const GLint alignments[8] = {8, 1, 2, 1, 4, 1, 2, 1};
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, alignments[pitch & 7]);
+}
+
////////////////////////
// Shader compilation //
////////////////////////
@@ -709,6 +716,7 @@
if (surface->texture_id == last_source_texture || surface->texture_id == last_destination_texture)
FlushVertexBuffer();
+ SetTextureUploadAlignment(width * 3);
glBindTexture(GL_TEXTURE_2D, surface->texture_id);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
glBindTexture(GL_TEXTURE_2D, last_source_texture);
@@ -932,7 +940,7 @@
for (size_t y = 0; y < height; ++y)
memcpy (&buffer[y * width], &pixels[y * pitch], width);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ SetTextureUploadAlignment(width);
glBindTexture(GL_TEXTURE_2D, atlas->texture_id);
#ifdef USE_OPENGLES2
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, buffer);