We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4433

Summary: SDL_Renderer is sometimes replacing a texture by another
Product: SDL Reporter: Sylvain <sylvain.becker>
Component: renderAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: amaranth72
Version: don't know   
Hardware: x86_64   
OS: Linux   
Attachments: test-case
test-case opengles 1

Description Sylvain 2018-12-20 15:25:37 UTC
SDL_Renderer is sometimes drawing the wrong texture.

Here's a test-case tested with latest hg.

It should renders texture Green and Blue, but draws twice the blue.

Appears with opengles2 and batching, on linux, also on android.

I think it also appears with software and opengl renderers.
Comment 1 Sylvain 2018-12-20 15:26:55 UTC
Created attachment 3554 [details]
test-case

test case.

(but no patch ..)
Comment 2 Alex Szpakowski 2018-12-22 00:55:25 UTC
Thanks for the easy repro. I believe it's fixed as of https://hg.libsdl.org/SDL/rev/fbce19db4e53 , but post again if it still happens on a particular platform.
Comment 3 Sylvain 2018-12-28 21:41:46 UTC
Hi, thanks a lot as it indeed fixes the issue on GL and GLES2 !


I looked at the opengles 1 renderer, and it suffers the same issue so I re-opened.
Probably the same fix, but I believe there is also some strangeness

On my side, I don't even get anything renders (all remains black on Linux and Android), unless I add (on Linux): 
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);  
(https://hg.libsdl.org/SDL/rev/48b40c223503 )
What is strange is SDL 2.0.8 doesn't have this call, but it displays correctly.
Comment 4 Sylvain 2018-12-28 21:53:21 UTC
On opengles 1. 
I am not sure what needs to be fixed,
but I also need to call "glEnable(GL_TEXTURE_2D)" before "glBindTexture()" in SetCopyState()
Comment 5 Sylvain 2018-12-29 15:43:55 UTC
Opengles 1: 

Black texture issue (which would be also solved glTexEnvf) is fixed with using the correct colour:
https://hg.libsdl.org/SDL/rev/06031bc24165

I also apply the same fix as in opengl and opengles2 (it solves this issue too):
https://hg.libsdl.org/SDL/rev/c3bc7d1f4179


Still have a glitch with opengles 1. Solved (workaround?) by calling "glEnable(GL_TEXTURE_2D)" before "glBindTexture()" in SetCopyState()
Comment 6 Sylvain 2018-12-29 21:02:29 UTC
Created attachment 3556 [details]
test-case opengles 1

Test-case for opengles 1. At first, it draws correctly, then textures turn white.

A patch would be:

--- a/src/render/opengles/SDL_render_gles.c	Sat Dec 29 17:59:34 2018 +0100
+++ b/src/render/opengles/SDL_render_gles.c	Sat Dec 29 21:56:27 2018 +0100
@@ -795,6 +795,7 @@
 
     if (texture != data->drawstate.texture) {
         GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
+        data->glEnable(GL_TEXTURE_2D);
         data->glBindTexture(GL_TEXTURE_2D, texturedata->texture);
         data->drawstate.texture = texture;
     }

What do you think ?
Comment 7 Sam Lantinga 2019-01-05 06:07:23 UTC
This fix looks reasonable to me.. Ryan?