From 26bbfead4596cb776a2ffdb003f9a0ed62796897 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Sun, 26 Jan 2014 09:53:10 +0100 Subject: [PATCH] Add support for MSAA. MSAA was a long wanted and often requested feature. Just set set the desired number of samples with gl_msaa_samples and do a vid_restart. This code is based upon work done in Hecatomb. --- CHANGELOG | 2 ++ LICENSE | 5 +++-- src/backends/sdl/refresh.c | 19 ++++++++++++++++++- src/client/refresh/header/local.h | 1 + src/client/refresh/r_main.c | 2 ++ src/client/refresh/r_misc.c | 8 +++++++- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4782404f..bdcdbd9f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ Quake II 5.21 to 5.22: - Provide a fallback if SDL2s relative mouse mode cannot be activated. +- Add support for MSAA through the gl_msaa_samples + cvar. Quake II 5.20 to 5.21: - Fix a bug regaring mouse key handling (reported diff --git a/LICENSE b/LICENSE index f0a11f9d..a85eaf76 100644 --- a/LICENSE +++ b/LICENSE @@ -9,11 +9,12 @@ copys for each license: Parts of other Quake II Clients were included into the source. They covered by the same GPLv2 license as Quake II itself: +- Hecatomb - Icculus Quake 2 -- r1q2 -- QuDoS - KMQuake2 - Q2Pro +- QuDoS +- r1q2 - zeq2 The following code is used in library form and thus not part of Yamagi diff --git a/src/backends/sdl/refresh.c b/src/backends/sdl/refresh.c index d6bf8c04..3c87617c 100644 --- a/src/backends/sdl/refresh.c +++ b/src/backends/sdl/refresh.c @@ -505,10 +505,11 @@ GLimp_InitGraphics(qboolean fullscreen) { int counter = 0; int flags; + int msaa_samples; int stencil_bits; + int width, height; char title[24]; - int width, height; if (GetWindowSize(&width, &height) && (width == vid.width) && (height == vid.height)) { @@ -546,6 +547,22 @@ GLimp_InitGraphics(qboolean fullscreen) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + if (gl_msaa_samples->value) + { + msaa_samples = gl_msaa_samples->value; + + if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) == -1) + { + Com_Printf("MSAA is unsupported: %s\n", SDL_GetError()); + Cvar_SetValue ("gl_msaa_samples", 0); + } + else if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa_samples) == -1) + { + Com_Printf("%i MSAA are unsupported: %s\n", msaa_samples, SDL_GetError()); + Cvar_SetValue("gl_msaa_samples", 0); + } + } + /* Initiate the flags */ flags = SDL_OPENGL; diff --git a/src/client/refresh/header/local.h b/src/client/refresh/header/local.h index 07efa6c0..325fedfe 100644 --- a/src/client/refresh/header/local.h +++ b/src/client/refresh/header/local.h @@ -242,6 +242,7 @@ extern cvar_t *gl_texturealphamode; extern cvar_t *gl_texturesolidmode; extern cvar_t *gl_saturatelighting; extern cvar_t *gl_lockpvs; +extern cvar_t *gl_msaa_samples; extern cvar_t *vid_fullscreen; extern cvar_t *vid_gamma; diff --git a/src/client/refresh/r_main.c b/src/client/refresh/r_main.c index 92a5fbdc..07f56875 100644 --- a/src/client/refresh/r_main.c +++ b/src/client/refresh/r_main.c @@ -139,6 +139,7 @@ cvar_t *gl_texturesolidmode; cvar_t *gl_anisotropic; cvar_t *gl_anisotropic_avail; cvar_t *gl_lockpvs; +cvar_t *gl_msaa_samples; cvar_t *vid_fullscreen; cvar_t *vid_gamma; @@ -1015,6 +1016,7 @@ R_Register(void) gl_customwidth = Cvar_Get("gl_customwidth", "1024", CVAR_ARCHIVE); gl_customheight = Cvar_Get("gl_customheight", "768", CVAR_ARCHIVE); + gl_msaa_samples = Cvar_Get ( "gl_msaa_samples", "0", CVAR_ARCHIVE ); #ifdef RETEXTURE gl_retexturing = Cvar_Get("gl_retexturing", "1", CVAR_ARCHIVE); diff --git a/src/client/refresh/r_misc.c b/src/client/refresh/r_misc.c index c0de7e54..e9f93152 100644 --- a/src/client/refresh/r_misc.c +++ b/src/client/refresh/r_misc.c @@ -164,6 +164,7 @@ void R_SetDefaultState(void) { glClearColor(1, 0, 0.5, 0.5); + glDisable(GL_MULTISAMPLE); glCullFace(GL_FRONT); glEnable(GL_TEXTURE_2D); @@ -216,8 +217,13 @@ R_SetDefaultState(void) if (qglColorTableEXT && gl_ext_palettedtexture->value) { glEnable(GL_SHARED_TEXTURE_PALETTE_EXT); - R_SetTexturePalette(d_8to24table); } + + if (gl_msaa_samples->value) + { + glEnable(GL_MULTISAMPLE); + glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); + } }