Skip to content

Commit c93f3ff

Browse files
committed
Try more fallback contexts for GL
1 parent 5677d5c commit c93f3ff

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

backends/backend-sdl/src/arc/backend/sdl/SdlApplication.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,27 @@ private void init(){
153153
if(context == 0) throw new SdlError();
154154
}catch(SdlError error){
155155
if(config.gl30){
156-
//try creating a GL 2.0 context instead as fallback.
157-
config.gl30 = false;
156+
try{
157+
//try a 3.0 context
158+
Log.info("Failed to initialize with OpenGL @.@, attempting fallback compatibility context: @", config.gl30Major, config.gl30Minor, Strings.getSimpleMessage(error));
159+
160+
check(SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY));
161+
check(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3));
162+
check(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0));
158163

159-
check(SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY));
160-
check(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2));
161-
check(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0));
164+
context = SDL_GL_CreateContext(window);
165+
if(context == 0) throw new SdlError();
166+
}catch(SdlError error2){
167+
//finally, try a 2.0 context
168+
Log.info("Failed to initialize with fallback OpenGL 3.0 context, attempting 2.0 context: @", Strings.getSimpleMessage(error2));
169+
config.gl30 = false;
162170

163-
context = SDL_GL_CreateContext(window);
164-
if(context == 0) throw new SdlError();
171+
check(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2));
172+
check(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0));
173+
174+
context = SDL_GL_CreateContext(window);
175+
if(context == 0) throw new SdlError();
176+
}
165177
}else{
166178
throw error;
167179
}

0 commit comments

Comments
 (0)