Fixed GLES2 back-end on Big Endian Platform (see #5093)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 167d8ee..ddd336e 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -1486,6 +1486,9 @@ static int
GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, GLint pitch, GLint bpp)
{
Uint8 *blob = NULL;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ Uint32 *blob2 = NULL;
+#endif
Uint8 *src;
int src_pitch;
int y;
@@ -1512,10 +1515,33 @@ GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoffset, GLint
src = blob;
}
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ {
+ int i;
+ Uint32 *src32 = (Uint32 *)src;
+ blob2 = (Uint32 *)SDL_malloc(src_pitch * height);
+ if (!blob2) {
+ if (blob) {
+ SDL_free(blob);
+ }
+ return SDL_OutOfMemory();
+ }
+ for (i = 0; i < (src_pitch * height) / 4; i++) {
+ blob2[i] = SDL_Swap32(src32[i]);
+ }
+ src = (Uint8 *) blob2;
+ }
+#endif
+
data->glTexSubImage2D(target, 0, xoffset, yoffset, width, height, format, type, src);
if (blob) {
SDL_free(blob);
}
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ if (blob2) {
+ SDL_free(blob2);
+ }
+#endif
return 0;
}