Skip to content

Instantly share code, notes, and snippets.

@SebastienLussier
Created November 5, 2013 04:24
Show Gist options
  • Save SebastienLussier/7313854 to your computer and use it in GitHub Desktop.
Save SebastienLussier/7313854 to your computer and use it in GitHub Desktop.
Works on my HD3000 now... Not sure we need both checks... either of them will do in my case. The second one might be problematic as some drivers might report a GDI Generic but accelerated device that could run arx... #1 - // Verify that the msaa setting matches what was requested and #2 - // Avoid "GDI Generic" devices...
bool SDL2Window::initialize(const std::string & title, Vec2i size, bool fullscreen,
unsigned depth) {
ARX_UNUSED(depth); // TODO
arx_assert(!displayModes.empty());
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
// We need an accelerated OpenGL context or we'll likely fail later
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
// TODO EGL and core profile are not supported yet
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 0);
size_ = Vec2i_ZERO;
depth_ = 0;
for(int msaa = config.video.antialiasing ? 8 : 1; msaa > 0; msaa--) {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, msaa > 1 ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa > 1 ? msaa : 0);
m_window = SDL_CreateWindow(
title.c_str(),
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
size.x, size.y,
getSDLFlagsForMode(size, fullscreen) | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN
);
// Verify that the msaa setting matches what was requested
if(m_window && msaa > 1) {
int msaaEnabled, msaaValue;
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &msaaEnabled);
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaaValue);
if(!msaaEnabled || msaaValue != msaa) {
SDL_DestroyWindow(m_window);
m_window = NULL;
continue;
}
}
if(!m_window) {
continue;
}
m_glcontext = SDL_GL_CreateContext(m_window);
if(m_glcontext) {
// Avoid "GDI Generic" devices...
if(strcmp((const char*)glGetString(GL_RENDERER), "GDI Generic") == 0) {
SDL_GL_DeleteContext(m_glcontext);
m_glcontext = NULL;
continue;
}
break;
}
}
if(!m_window) {
LogError << "Failed to initialize SDL Window - could not create window: " << SDL_GetError();
return false;
}
if(!m_glcontext) {
LogError << "Failed to initialize SDL Window - could not create GL context: " << SDL_GetError();
return false;
}
SDL_GL_SetSwapInterval(config.video.vsync ? 1 : 0); // TODO support -1, support changing at runtime
title_ = title;
isFullscreen_ = fullscreen;
SDL_ShowWindow(m_window);
SDL_ShowCursor(SDL_DISABLE);
renderer = new OpenGLRenderer;
renderer->Initialize();
onCreate();
updateSize();
onShow(true);
onFocus(true);
onRendererInit();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment