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 1026

Summary: changing gl state is not a good thing
Product: SDL Reporter: Vittorio Giovara <vitto.giova>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: Other   
OS: All   
Attachments: patch that implements this feature

Description Vittorio Giovara 2010-07-16 19:09:28 UTC
i was reading SDL_renderer_gles and i noticed that every time we there
is some gl call the gl state is modified with a couple of
glEnableClientState()/glDisableClientState.
While this is completely fine for desktops systems, this is a major
performace kill on mobile devices, right where opengles is
implemented.
Normal practice in this case is to update the glstate once, keep it
always the same and disable/enable other states only in very special
occasions.

On the web there's plenty of documentation (on the top of my head
http://developer.apple.com/iphone/library/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Performance/Performance.html#//apple_ref/doc/uid/TP40008793-CH105-SW5
) and i personally tried this.
I modified my code and got a 10 fps boost, then modified SDL_render_gles and shifted from 40 fps to 50 fps alone -- considering that i started from ~30fps i got an 80% performance increase with this technique.

I have attached a dif of my changes, hope that it will be included in mainstream.
Comment 1 Vittorio Giovara 2010-07-16 19:39:14 UTC
Created attachment 520 [details]
patch that implements this feature
Comment 2 Sam Lantinga 2010-07-16 19:40:08 UTC
Thank you very much for your patch for SDL 1.3!

Do you give me permission to release your code with SDL 1.3 and future
versions of SDL under both the LGPL and a closed-source commercial
license?
Comment 3 Vittorio Giovara 2010-07-16 19:43:38 UTC
sure, no problem.
Comment 4 Sam Lantinga 2010-07-16 19:53:06 UTC
Thanks! :)
Comment 5 Sam Lantinga 2010-07-21 00:27:07 UTC
There was some question about whether we should enable/disable GL_TEXTURE_COORD_ARRAY.  Were you able to determine whether your patch was safe in that regard?
Comment 6 Vittorio Giovara 2010-07-21 01:27:44 UTC
(In reply to comment #5)
> There was some question about whether we should enable/disable
> GL_TEXTURE_COORD_ARRAY.  Were you able to determine whether your patch was safe
> in that regard?

well by testing against the sdl demos, only the fireworks caused glitches (where by glitch i mean crash) and enabling or disabling othe gl states didn't change the result.
In our app we use opengles directly so this worked well as we have more control. Perhaps you leave this frequent gl switch on by default (for compatibility) and then add an api that freezes the state,
Comment 7 Sam Lantinga 2011-01-19 23:56:46 UTC
This is fixed, thanks!
http://hg.libsdl.org/SDL/rev/b5b42be9333c