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 2973

Summary: SDL_LockTexture() & SDL_RENDER_PRESENTVSYNC causes tearing
Product: SDL Reporter: 15gixh+64kt8tozpu6p0
Component: renderAssignee: Ryan C. Gordon <icculus>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.3   
Hardware: x86_64   
OS: Mac OS X (All)   
Attachments: Test probelm

Description 15gixh+64kt8tozpu6p0 2015-05-01 20:09:16 UTC
Created attachment 2145 [details]
Test probelm

In the documentation, it's recommended to use SDL_LockTexture() over SDL_UpdateTexture() (https://wiki.libsdl.org/SDL_UpdateTexture) for streaming textures (contradicting the advice given in the migration guide, https://wiki.libsdl.org/MigrationGuide#If_your_game_just_wants_to_get_fully-rendered_frames_to_the_screen).

The problem is that under the OpenGL render driver on Mac OS X, using SDL_LockTexture() causes tearing when SDL_RENDER_PRESENTVSYNC is set.

I've attached a sample program that demonstrates the behavior.

I'm guessing it's because SDL_LockTexture() retrieves a pointer to memory shared with the GPU. That's fine, but it should be the memory for the texture buffer not currently being displayed on the screen.

The workaround is to use SDL_UpdateTexture(). This workaround isn't ideal because it generates an extra buffer copy when the software renderer is used. It would be better to fix the OpenGL renderer so that each SDL texture references two different OpenGL textures if memory-sharing is being used.