SDL: Enable multisampling

Unfortunately, there doesn't seem to be an easy way to apply
multisampling changes in SDL. As a workaround, a message requesting the
player to restart the game is shown.
directional-lights
Lukas Werling 2016-05-07 12:25:11 +02:00
parent 1919d81f9d
commit 9fa16c5e14
3 changed files with 32 additions and 5 deletions

View File

@ -94,6 +94,8 @@ IDS_CON_HELP=Hilfe
IDS_CON_HOME=Zurück zur Basis
IDS_CTL_ACTIVE=Aktivieren
IDS_CTL_ANTIALIASING=Antialiasing:
IDS_CTL_ANTIALIASING_RESTART_TITLE=Neustart notwendig
IDS_CTL_ANTIALIASING_RESTART_MSG=Die neuen Antialiasing-Einstellungen werden nach einem Neustart aktiv.
IDS_CTL_AUTHOR=Autor: %s
IDS_CTL_AUTOMATICUPDATES=automatische Updates aktivieren
IDS_CTL_BACKGROUND=Hintergrund:

View File

@ -94,6 +94,8 @@ IDS_CON_HELP=Help
IDS_CON_HOME=Back to base
IDS_CTL_ACTIVE=Active
IDS_CTL_ANTIALIASING=Antialiasing:
IDS_CTL_ANTIALIASING_RESTART_TITLE=Restart required
IDS_CTL_ANTIALIASING_RESTART_MSG=Antialiasing settings will be applied after a restart.
IDS_CTL_AUTHOR=Author: %s
IDS_CTL_AUTOMATICUPDATES=Enable automatic updates
IDS_CTL_PACKETLOGGING=Packet logging

View File

@ -21,6 +21,7 @@
#include "game/C4Application.h"
#include "graphics/C4DrawGL.h"
#include "gui/C4Gui.h"
#include "platform/StdFile.h"
#include "lib/StdBuf.h"
@ -46,10 +47,14 @@ C4Window::~C4Window ()
Clear();
}
static void SetMultisamplingAttributes(int samples)
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, samples > 0 ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples);
}
C4Window * C4Window::Init(WindowKind windowKind, C4AbstractApp * pApp, const char * Title, const C4Rect * size)
{
/* SDL_GL_MULTISAMPLEBUFFERS,
SDL_GL_MULTISAMPLESAMPLES,*/
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
@ -58,6 +63,7 @@ C4Window * C4Window::Init(WindowKind windowKind, C4AbstractApp * pApp, const cha
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, /*REQUESTED_GL_CTX_MINOR*/ 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, (Config.Graphics.DebugOpenGL ? SDL_GL_CONTEXT_DEBUG_FLAG : 0));
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SetMultisamplingAttributes(Config.Graphics.MultiSampling);
uint32_t flags = SDL_WINDOW_OPENGL;
if (windowKind == W_Fullscreen && size->Wdt == -1)
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
@ -77,9 +83,10 @@ C4Window * C4Window::Init(WindowKind windowKind, C4AbstractApp * pApp, const cha
bool C4Window::ReInit(C4AbstractApp* pApp)
{
// TODO: How do we enable multisampling with SDL?
// TODO: Is there some way to do this without requiring a restart?
// Maybe re-call SDL_SetVideoMode?
return false;
C4GUI::TheScreen.ShowMessage(LoadResStr("IDS_CTL_ANTIALIASING_RESTART_MSG"), LoadResStr("IDS_CTL_ANTIALIASING_RESTART_TITLE"), C4GUI::Ico_Notify);
return true;
}
void C4Window::Clear()
@ -90,7 +97,23 @@ void C4Window::Clear()
void C4Window::EnumerateMultiSamples(std::vector<int>& samples) const
{
// TODO: Enumerate multi samples
int max_samples;
glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
samples.clear();
for (int s = 2; s <= max_samples; s *= 2)
{
// Not all multisampling options seem to work. Verify by creating a hidden window.
SetMultisamplingAttributes(s);
SDL_Window *wnd = SDL_CreateWindow("OpenClonk Test Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 100, 100, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
if (wnd)
{
SDL_DestroyWindow(wnd);
samples.push_back(s);
}
else
break;
}
SetMultisamplingAttributes(Config.Graphics.MultiSampling);
}
bool C4Window::StorePosition(const char *, const char *, bool) { return true; }