Fixed bug 4025 - SDL_Renderer OpenGL : add support for textures ABGR, RGB, BGR

Sylvain

OpenGLES2 SDL renderer has support for textures ARGB, ABGR, RGB and BGR, whereas OpenGL SDL renderer only had ARGB.

If you think it's worth adding it, here's a patch. I quickly tried and it worked, but there may be missing things or corner case.
This commit is contained in:
Sam Lantinga 2019-05-19 11:01:36 -07:00
parent 8dea23c705
commit 2ee9b1ddce
3 changed files with 39 additions and 3 deletions

View File

@ -405,10 +405,17 @@ convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
{
switch (pixel_format) {
case SDL_PIXELFORMAT_ARGB8888:
case SDL_PIXELFORMAT_RGB888:
*internalFormat = GL_RGBA8;
*format = GL_BGRA;
*type = GL_UNSIGNED_INT_8_8_8_8_REV;
break;
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_BGR888:
*internalFormat = GL_RGBA8;
*format = GL_RGBA;
*type = GL_UNSIGNED_INT_8_8_8_8_REV;
break;
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_NV12:
@ -1019,7 +1026,13 @@ SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd)
{
SDL_Texture *texture = cmd->data.draw.texture;
const GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
GL_Shader shader = SHADER_RGB;
GL_Shader shader;
if (texture->format == SDL_PIXELFORMAT_ABGR8888 || texture->format == SDL_PIXELFORMAT_ARGB8888) {
shader = SHADER_RGBA;
} else {
shader = SHADER_RGB;
}
if (data->shaders) {
if (texturedata->yuv || texturedata->nv12) {
@ -1733,8 +1746,13 @@ SDL_RenderDriver GL_RenderDriver = {
{
"opengl",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
1,
{SDL_PIXELFORMAT_ARGB8888},
4,
{
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_RGB888,
SDL_PIXELFORMAT_BGR888
},
0,
0}
};

View File

@ -240,6 +240,23 @@ static const char *shader_source[NUM_SHADERS][2] =
"\n"
"void main()\n"
"{\n"
" gl_FragColor = texture2D(tex0, v_texCoord);\n"
" gl_FragColor.a = 1.0;\n"
" gl_FragColor *= v_color;\n"
"}"
},
/* SHADER_RGBA */
{
/* vertex shader */
TEXTURE_VERTEX_SHADER,
/* fragment shader */
"varying vec4 v_color;\n"
"varying vec2 v_texCoord;\n"
"uniform sampler2D tex0;\n"
"\n"
"void main()\n"
"{\n"
" gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
"}"
},

View File

@ -31,6 +31,7 @@ typedef enum {
SHADER_NONE,
SHADER_SOLID,
SHADER_RGB,
SHADER_RGBA,
SHADER_YUV_JPEG,
SHADER_YUV_BT601,
SHADER_YUV_BT709,