Use the correct pixel formats for OpenGL ES on big endian
parent
05e7dcf8f8
commit
5db781cc3d
|
@ -730,7 +730,7 @@ static int GLES2_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd
|
||||||
|
|
||||||
static int GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
|
static int GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
|
||||||
{
|
{
|
||||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || renderer->target->format == SDL_PIXELFORMAT_XRGB8888));
|
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32));
|
||||||
SDL_VertexSolid *verts = (SDL_VertexSolid *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first);
|
SDL_VertexSolid *verts = (SDL_VertexSolid *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first);
|
||||||
int i;
|
int i;
|
||||||
SDL_Color color;
|
SDL_Color color;
|
||||||
|
@ -762,7 +762,7 @@ static int GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
||||||
|
|
||||||
static int GLES2_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
|
static int GLES2_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
|
||||||
{
|
{
|
||||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || renderer->target->format == SDL_PIXELFORMAT_XRGB8888));
|
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32));
|
||||||
int i;
|
int i;
|
||||||
GLfloat prevx, prevy;
|
GLfloat prevx, prevy;
|
||||||
SDL_VertexSolid *verts = (SDL_VertexSolid *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first);
|
SDL_VertexSolid *verts = (SDL_VertexSolid *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first);
|
||||||
|
@ -822,7 +822,7 @@ static int GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S
|
||||||
float scale_x, float scale_y)
|
float scale_x, float scale_y)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || renderer->target->format == SDL_PIXELFORMAT_XRGB8888));
|
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32));
|
||||||
int count = indices ? num_indices : num_vertices;
|
int count = indices ? num_indices : num_vertices;
|
||||||
|
|
||||||
cmd->data.draw.count = count;
|
cmd->data.draw.count = count;
|
||||||
|
@ -1020,50 +1020,50 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
|
||||||
/* Check if we need to do color mapping between the source and render target textures */
|
/* Check if we need to do color mapping between the source and render target textures */
|
||||||
if (renderer->target->format != texture->format) {
|
if (renderer->target->format != texture->format) {
|
||||||
switch (texture->format) {
|
switch (texture->format) {
|
||||||
case SDL_PIXELFORMAT_ARGB8888:
|
case SDL_PIXELFORMAT_BGRA32:
|
||||||
switch (renderer->target->format) {
|
switch (renderer->target->format) {
|
||||||
case SDL_PIXELFORMAT_ABGR8888:
|
case SDL_PIXELFORMAT_RGBA32:
|
||||||
case SDL_PIXELFORMAT_XBGR8888:
|
case SDL_PIXELFORMAT_RGBX32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_XRGB8888:
|
case SDL_PIXELFORMAT_BGRX32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_ABGR8888:
|
case SDL_PIXELFORMAT_RGBA32:
|
||||||
switch (renderer->target->format) {
|
switch (renderer->target->format) {
|
||||||
case SDL_PIXELFORMAT_ARGB8888:
|
case SDL_PIXELFORMAT_BGRA32:
|
||||||
case SDL_PIXELFORMAT_XRGB8888:
|
case SDL_PIXELFORMAT_BGRX32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_XBGR8888:
|
case SDL_PIXELFORMAT_RGBX32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_XRGB8888:
|
case SDL_PIXELFORMAT_BGRX32:
|
||||||
switch (renderer->target->format) {
|
switch (renderer->target->format) {
|
||||||
case SDL_PIXELFORMAT_ABGR8888:
|
case SDL_PIXELFORMAT_RGBA32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_ARGB8888:
|
case SDL_PIXELFORMAT_BGRA32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_XBGR8888:
|
case SDL_PIXELFORMAT_RGBX32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_XBGR8888:
|
case SDL_PIXELFORMAT_RGBX32:
|
||||||
switch (renderer->target->format) {
|
switch (renderer->target->format) {
|
||||||
case SDL_PIXELFORMAT_ABGR8888:
|
case SDL_PIXELFORMAT_RGBA32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_ARGB8888:
|
case SDL_PIXELFORMAT_BGRA32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_XRGB8888:
|
case SDL_PIXELFORMAT_BGRX32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1091,16 +1091,16 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (texture->format) {
|
switch (texture->format) {
|
||||||
case SDL_PIXELFORMAT_ARGB8888:
|
case SDL_PIXELFORMAT_BGRA32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_ABGR8888:
|
case SDL_PIXELFORMAT_RGBA32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_XRGB8888:
|
case SDL_PIXELFORMAT_BGRX32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
|
||||||
break;
|
break;
|
||||||
case SDL_PIXELFORMAT_XBGR8888:
|
case SDL_PIXELFORMAT_RGBX32:
|
||||||
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
|
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
|
||||||
break;
|
break;
|
||||||
#if SDL_HAVE_YUV
|
#if SDL_HAVE_YUV
|
||||||
|
@ -1153,7 +1153,7 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
|
||||||
static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
||||||
{
|
{
|
||||||
GLES2_RenderData *data = (GLES2_RenderData *)renderer->driverdata;
|
GLES2_RenderData *data = (GLES2_RenderData *)renderer->driverdata;
|
||||||
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || renderer->target->format == SDL_PIXELFORMAT_XRGB8888));
|
const SDL_bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32));
|
||||||
|
|
||||||
#if USE_VERTEX_BUFFER_OBJECTS
|
#if USE_VERTEX_BUFFER_OBJECTS
|
||||||
const int vboidx = data->current_vertex_buffer;
|
const int vboidx = data->current_vertex_buffer;
|
||||||
|
@ -1413,10 +1413,10 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
|
||||||
|
|
||||||
/* Determine the corresponding GLES texture format params */
|
/* Determine the corresponding GLES texture format params */
|
||||||
switch (texture->format) {
|
switch (texture->format) {
|
||||||
case SDL_PIXELFORMAT_ARGB8888:
|
case SDL_PIXELFORMAT_BGRA32:
|
||||||
case SDL_PIXELFORMAT_ABGR8888:
|
case SDL_PIXELFORMAT_RGBA32:
|
||||||
case SDL_PIXELFORMAT_XRGB8888:
|
case SDL_PIXELFORMAT_BGRX32:
|
||||||
case SDL_PIXELFORMAT_XBGR8888:
|
case SDL_PIXELFORMAT_RGBX32:
|
||||||
format = GL_RGBA;
|
format = GL_RGBA;
|
||||||
type = GL_UNSIGNED_BYTE;
|
type = GL_UNSIGNED_BYTE;
|
||||||
break;
|
break;
|
||||||
|
@ -1590,9 +1590,6 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
|
||||||
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)
|
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;
|
Uint8 *blob = NULL;
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
||||||
Uint32 *blob2 = NULL;
|
|
||||||
#endif
|
|
||||||
Uint8 *src;
|
Uint8 *src;
|
||||||
size_t src_pitch;
|
size_t src_pitch;
|
||||||
int y;
|
int y;
|
||||||
|
@ -1618,33 +1615,10 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff
|
||||||
src = blob;
|
src = blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
||||||
if (format == GL_RGBA) {
|
|
||||||
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);
|
data->glTexSubImage2D(target, 0, xoffset, yoffset, width, height, format, type, src);
|
||||||
if (blob) {
|
if (blob) {
|
||||||
SDL_free(blob);
|
SDL_free(blob);
|
||||||
}
|
}
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
||||||
if (blob2) {
|
|
||||||
SDL_free(blob2);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1937,7 +1911,7 @@ static int GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
||||||
Uint32 pixel_format, void *pixels, int pitch)
|
Uint32 pixel_format, void *pixels, int pitch)
|
||||||
{
|
{
|
||||||
GLES2_RenderData *data = (GLES2_RenderData *)renderer->driverdata;
|
GLES2_RenderData *data = (GLES2_RenderData *)renderer->driverdata;
|
||||||
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
|
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
|
||||||
size_t buflen;
|
size_t buflen;
|
||||||
void *temp_pixels;
|
void *temp_pixels;
|
||||||
int temp_pitch;
|
int temp_pitch;
|
||||||
|
@ -2291,10 +2265,10 @@ SDL_RenderDriver GLES2_RenderDriver = {
|
||||||
{ "opengles2",
|
{ "opengles2",
|
||||||
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
|
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
|
||||||
4,
|
4,
|
||||||
{ SDL_PIXELFORMAT_ARGB8888,
|
{ SDL_PIXELFORMAT_RGBA32,
|
||||||
SDL_PIXELFORMAT_ABGR8888,
|
SDL_PIXELFORMAT_BGRA32,
|
||||||
SDL_PIXELFORMAT_XRGB8888,
|
SDL_PIXELFORMAT_BGRX32,
|
||||||
SDL_PIXELFORMAT_XBGR8888 },
|
SDL_PIXELFORMAT_RGBX32 },
|
||||||
0,
|
0,
|
||||||
0 }
|
0 }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue