diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 0bf658c..22aae40 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -50,6 +50,22 @@ Window::Window(glm::vec2 virtual_size, Mode mode, RenderChain* render_chain, int create(); sp::initOpenGL(); + // Enable multisampling after OpenGL is initialized. + switch (fsaa) + { + case 0: + // Expected input for no FSAA. + break; + case 2: + case 4: + case 8: + // Expected inputs for FSAA. + glEnable(GL_MULTISAMPLE); + break; + default: + LOG(Warning, "FSAA must be off (0), 2x, 4x, or 8x, but ", fsaa , "x was passed and ignored."); + } + all_windows.push_back(this); } @@ -113,10 +129,25 @@ void Window::setMode(Mode new_mode) void Window::setFSAA(int new_fsaa) { - if (fsaa == new_fsaa) - return; - fsaa = new_fsaa; - create(); + if (fsaa == new_fsaa) return; + + switch (new_fsaa) + { + case 0: + case 2: + case 4: + case 8: + fsaa = new_fsaa; + break; + default: + LOG(Warning, "FSAA must be off (0), 2x, 4x, or 8x, but ", new_fsaa , "x was passed. Treating as fsaa=0."); + if (fsaa == 0) return; + fsaa = 0; + } + + // Can't apply this without recreating the OpenGL context. + // Log that a restart is required. + LOG(Warning, "FSAA changed to ", fsaa, "x. Restart required for this change to take effect."); } void Window::setTitle(string title) @@ -184,6 +215,27 @@ void Window::create() SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + // Configure multisampling for FSAA. + switch (fsaa) + { + case 0: + // Expected value for no FSAA. + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); + break; + case 2: + case 4: + case 8: + // Expected value for FSAA. + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa); + break; + default: + LOG(Warning, "FSAA must be off (0), 2x, 4x, or 8x, but ", fsaa , "x was passed. Treating as fsaa=0."); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); + } + int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; switch(mode) { @@ -221,6 +273,22 @@ void Window::create() SDL_GL_MakeCurrent(static_cast(window), gl_context); if (SDL_GL_SetSwapInterval(-1)) SDL_GL_SetSwapInterval(1); + + // Log FSAA status. + if (fsaa > 0) + { + int actual_buffers, actual_samples; + SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &actual_buffers); + SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &actual_samples); + + if (actual_buffers == 0 || actual_samples == 0) + LOG(Warning, "FSAA ", fsaa, "x requested but not available on this system."); + else if (actual_samples != fsaa) + LOG(Warning, "FSAA ", fsaa, "x requested, but ", actual_samples, "x provided."); + else + LOG(Info, "FSAA ", fsaa, "x enabled."); + } + setupView(); }