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 2244

Summary: Unsupported Multisampling breaks context/window creation
Product: SDL Reporter: Mike Kasprzak <mike>
Component: videoAssignee: Gabriel Jacobo <gabomdq>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.1   
Hardware: All   
OS: Android (All)   

Description Mike Kasprzak 2013-11-16 07:18:04 UTC
On Android, if I enable multisampling like so:

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);

This works fine on GPUs where it is supported (PowerVR SGX, Adreno 320, etc), but fails to create a context on others (NVidia Tegra 3).

The problem is after failing to create a legal "window" (not even context, window), doing this:

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);

and trying to create the window again still fails. You can't make legal windows or contexts anymore.


There's not really a way (AFAIK) to poll if Multisampling is supported (as it's an EGL thing, not GL).
Comment 1 Gabriel Jacobo 2013-12-02 13:16:16 UTC
When you create the "window" on Android (which actually already exists), SDL creates the EGL surface for it, which uses the GL config parameters. If you request unsupported parameters for it, it's the expected behaviour that it'll fail.

A fix to let you change the EGL config every time you create a window (theoretically, there may be other factors preventing you from actually recreating the window) is here: https://hg.libsdl.org/SDL/rev/afd62b3fda31

Regarding querying SDL_GL_MULTISAMPLEBUFFERS, SDL_GL_GetAttribute needs to evolve to take into consideration what type of context is active (see: https://bugzilla.libsdl.org/show_bug.cgi?id=2060 for a similar case where it also fails depending on the context version).

In the meantime, I guess you can use EGL in your app directly to poll for that value.
Comment 2 Mike Kasprzak 2013-12-02 22:18:57 UTC
Thanks Gabriel. I have tested the changes and they work.

Like you suggested, I had to recreate the "Window" using SDL_CreateWindow for changes to take effect (SDL_GL_SetAttribute before SDL_GL_CreateContext doesn't work). 

Of note, on an failing device (1st gen Nexus 7) the Window creation succeeds, and the "automatic" EGL context creation fails. When you delete the Window, it attempts to destroy the bad EGL context. Here's what's popping up in my logcat:

E/libEGL  ( 4105): eglDestroySurface:570 error 300d (EGL_BAD_SURFACE)

I did some checking myself, and it looks like the SDL_EGL_CreateSurface is returning -1 when it should be returning EGL_NO_SURFACE (0). The check in SDL_EGL_DestroySurface expects EGL_NO_SURFACE.

Simple fix:


@@ -452,7 +452,7 @@
 SDL_EGL_CreateSurface(_THIS, NativeWindowType nw) 
 {
     if (SDL_EGL_ChooseConfig(_this) != 0) {
-        return -1;
+        return EGL_NO_SURFACE;
     }
     
     return _this->egl_data->eglCreateWindowSurface(
Comment 3 Mike Kasprzak 2013-12-02 22:21:20 UTC
Oh whoops, that in src/video/SDL_egl.c
Comment 4 Sam Lantinga 2013-12-03 07:55:05 UTC
Simple fix pushed, thanks!
https://hg.libsdl.org/SDL/rev/3c2694255705