Skip to content

Commit

Permalink
Refactor|Client|libappfw|libgui: Replaced 'vid-fsaa' and 'vid-vsync' …
Browse files Browse the repository at this point in the history
…with Config variables

Console variables are game-specific, however the user most likely
prefers to use the same FSAA/vsync settings for all games as their
appropriate values depend on the available hardware.

Now the FSAA and vsync settings are configured persistently using
Config.window.main.fsaa and Config.window.main.vsync. The old cvars
were removed, however they can still be accessed via the console
command line using a mapping.

IssueID #1832
  • Loading branch information
skyjake committed Nov 16, 2014
1 parent bfd885c commit bc765f7
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 57 deletions.
11 changes: 5 additions & 6 deletions doomsday/client/include/gl/gl_main.h
Expand Up @@ -180,18 +180,17 @@ void GL_ShutdownRefresh();
void GL_ModulateTexture(int mode);

/**
* Enables or disables vsync. Changes the value of the vid-vsync variable.
* May cause the OpenGL surface to be recreated.
* Enables or disables vsync. May cause the OpenGL surface to be recreated.
*
* @param on @c true to enable vsync, @c false to disable.
*/
void GL_SetVSync(dd_bool on);

/**
* Enables or disables multisampling when FSAA is available (vid-fsaa 1). You
* cannot enable multisampling if vid-fsaa is 0. Never causes the GL surface or
* pixel format to be modified; can be called at any time during the rendering
* of a frame.
* Enables or disables multisampling when FSAA is available. You cannot enable
* multisampling if FSAA has not been enabled in the Canvas. Never causes the GL surface
* or pixel format to be modified; can be called at any time during the rendering of a
* frame.
*
* @param on @c true to enable multisampling, @c false to disable.
*/
Expand Down
30 changes: 4 additions & 26 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -88,33 +88,10 @@ static float oldgamma, oldcontrast, oldbright;

static int fogModeDefault = 0;

static byte fsaaEnabled = true; // default value also specified in CanvasWindow
static byte vsyncEnabled = true;

static viewport_t currentView;

static void videoFSAAChanged()
{
if(novideo || !WindowSystem::mainExists()) return;
ClientWindow::main().updateCanvasFormat();
}

static void videoVsyncChanged()
{
if(novideo || !WindowSystem::mainExists()) return;

#ifdef WIN32
ClientWindow::main().updateCanvasFormat();
#else
GL_SetVSync(Con_GetByte("vid-vsync") != 0);
#endif
}

void GL_Register()
{
// Update values from saved Config.
fsaaEnabled = App::config().getb("window.fsaa", true);

// Cvars
C_VAR_INT ("rend-dev-wireframe", &renderWireframe, CVF_NO_ARCHIVE, 0, 2);
C_VAR_INT ("rend-fog-default", &fogModeDefault, 0, 0, 2);
Expand All @@ -129,12 +106,13 @@ void GL_Register()
C_VAR_INT ("rend-mobj-smooth-turn", &useSRVOAngle, 0, 0, 1);

// * video
C_VAR_BYTE2("vid-vsync", &vsyncEnabled, 0, 0, 1, videoVsyncChanged);
C_VAR_BYTE2("vid-fsaa", &fsaaEnabled, 0, 0, 1, videoFSAAChanged);
C_VAR_FLOAT("vid-gamma", &vid_gamma, 0, 0.1f, 4);
C_VAR_FLOAT("vid-contrast", &vid_contrast, 0, 0, 2.5f);
C_VAR_FLOAT("vid-bright", &vid_bright, 0, -1, 1);

Con_AddMappedConfigVariable("vid-vsync", "i", "window.main.vsync");
Con_AddMappedConfigVariable("vid-fsaa", "i", "window.main.fsaa");

// Ccmds
C_CMD_FLAGS("fog", NULL, Fog, CMDF_NO_NULLGAME|CMDF_NO_DEDICATED);
C_CMD ("displaymode", "", DisplayModeInfo);
Expand Down Expand Up @@ -337,7 +315,7 @@ dd_bool GL_EarlyInit()
// Initialize the renderer into a 2D state.
GL_Init2DState();

GL_SetVSync(true); // will be overridden from vid-vsync
GL_SetVSync(App::config().getb("window.main.vsync"));

initGLOk = true;
return true;
Expand Down
49 changes: 39 additions & 10 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -70,9 +70,10 @@ static ClientWindow *mainWindow = nullptr; // The main window, set after fully c

DENG2_PIMPL(ClientWindow)
, DENG2_OBSERVES(MouseEventSource, MouseStateChange)
, DENG2_OBSERVES(Canvas, FocusChange)
, DENG2_OBSERVES(App, GameChange)
, DENG2_OBSERVES(App, StartupComplete)
, DENG2_OBSERVES(Canvas, FocusChange)
, DENG2_OBSERVES(App, GameChange)
, DENG2_OBSERVES(App, StartupComplete)
, DENG2_OBSERVES(Variable, Change)
{
bool needMainInit;
bool needRecreateCanvas;
Expand Down Expand Up @@ -141,10 +142,20 @@ DENG2_PIMPL(ClientWindow)

// Listen to input.
self.canvas().audienceForMouseStateChange() += this;

foreach(String s, configVariableNames())
{
App::config(s).audienceForChange() += this;
}
}

~Instance()
{
foreach(String s, configVariableNames())
{
App::config(s).audienceForChange() -= this;
}

App::app().audienceForGameChange() -= this;
App::app().audienceForStartupComplete() -= this;

Expand All @@ -160,6 +171,13 @@ DENG2_PIMPL(ClientWindow)
}
}

StringList configVariableNames() const
{
return StringList()
<< self.configName("fsaa")
<< self.configName("vsync");
}

Widget &container()
{
if(compositor)
Expand Down Expand Up @@ -500,6 +518,22 @@ DENG2_PIMPL(ClientWindow)
}
}

void variableValueChanged(Variable &variable, Value const &newValue)
{
if(variable.name() == "fsaa")
{
self.updateCanvasFormat();
}
else if(variable.name() == "vsync")
{
#ifdef WIN32
self.updateCanvasFormat();
#else
GL_SetVSync(newValue.isTrue());
#endif
}
}

void installSidebar(SidebarLocation location, GuiWidget *widget)
{
// Get rid of the old sidebar.
Expand Down Expand Up @@ -937,7 +971,7 @@ bool ClientWindow::setDefaultGLFormat() // static
}

#ifdef WIN32
if(CommandLine_Exists("-novsync") || !Con_GetByte("vid-vsync"))
if(CommandLine_Exists("-novsync") || !App::config().getb(configName("vsync")))
{
fmt.setSwapInterval(0);
}
Expand All @@ -947,10 +981,8 @@ bool ClientWindow::setDefaultGLFormat() // static
}
#endif

// The value of the "vid-fsaa" variable is written to this settings
// key when the value of the variable changes.
int sampleCount = 1;
bool configured = de::App::config().getb("window.fsaa");
bool configured = de::App::config().getb("window.main.fsaa");
if(CommandLine_Exists("-nofsaa") || !configured)
{
LOG_GL_VERBOSE("Multisampling off");
Expand Down Expand Up @@ -1036,9 +1068,6 @@ void ClientWindow::drawGameContent()
void ClientWindow::updateCanvasFormat()
{
d->needRecreateCanvas = true;

// Save the relevant format settings.
App::config().set("window.fsaa", Con_GetByte("vid-fsaa") != 0);
}

void ClientWindow::updateRootSize()
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/clientwindowsystem.cpp
Expand Up @@ -41,8 +41,8 @@ DENG2_PIMPL(ClientWindowSystem)
self.style().load(App::packageLoader().load("net.dengine.client.defaultstyle"));

settings.define(SettingsRegister::ConfigVariable, "window.main.showFps")
.define(SettingsRegister::IntCVar, "vid-fsaa", 0)
.define(SettingsRegister::IntCVar, "vid-vsync", 1)
.define(SettingsRegister::ConfigVariable, "window.main.fsaa")
.define(SettingsRegister::ConfigVariable, "window.main.vsync")
.define(SettingsRegister::ConfigVariable, "render.pixelDensity");
}
};
Expand Down
12 changes: 4 additions & 8 deletions doomsday/client/src/ui/dialogs/videosettingsdialog.cpp
Expand Up @@ -17,7 +17,6 @@
*/

#include "ui/dialogs/videosettingsdialog.h"
#include "ui/widgets/cvartogglewidget.h"
#include "ui/widgets/taskbarwidget.h"
#include "ui/clientwindow.h"
#include "CommandAction"
Expand Down Expand Up @@ -48,8 +47,8 @@ DENG2_OBSERVES(PersistentCanvasWindow, AttributeChange)
ToggleWidget *fullscreen;
ToggleWidget *maximized;
ToggleWidget *centered;
CVarToggleWidget *fsaa;
CVarToggleWidget *vsync;
VariableToggleWidget *fsaa;
VariableToggleWidget *vsync;
ChoiceWidget *modes;
ButtonWidget *windowButton;
#ifdef USE_COLOR_DEPTH_CHOICE
Expand All @@ -66,8 +65,8 @@ DENG2_OBSERVES(PersistentCanvasWindow, AttributeChange)
area.add(fullscreen = new ToggleWidget);
area.add(maximized = new ToggleWidget);
area.add(centered = new ToggleWidget);
area.add(fsaa = new CVarToggleWidget("vid-fsaa"));
area.add(vsync = new CVarToggleWidget("vid-vsync"));
area.add(fsaa = new VariableToggleWidget(App::config("window.main.fsaa")));
area.add(vsync = new VariableToggleWidget(App::config("window.main.vsync")));
area.add(modes = new ChoiceWidget);
area.add(windowButton = new ButtonWidget);
#ifdef USE_COLOR_DEPTH_CHOICE
Expand All @@ -92,9 +91,6 @@ DENG2_OBSERVES(PersistentCanvasWindow, AttributeChange)

windowButton->enable(!win.isFullScreen() && !win.isMaximized());

fsaa->updateFromCVar();
vsync->updateFromCVar();

// Select the current resolution/size in the mode list.
Canvas::Size current = win.fullscreenSize();

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/dialogs/vrsettingsdialog.cpp
Expand Up @@ -186,7 +186,7 @@ void VRSettingsDialog::autoConfigForOculusRift()
/// @todo This would be a good use case for cvar overriding. -jk

Con_SetInteger("rend-vr-mode", VRConfig::OculusRift);
Con_SetInteger("vid-fsaa", 0);
App::config().set("window.main.fsaa", false);
Con_SetFloat ("vid-gamma", 1.176f);
Con_SetFloat ("vid-contrast", 1.186f);
Con_SetFloat ("vid-bright", .034f);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libappfw/src/vrwindowtransform.cpp
Expand Up @@ -85,8 +85,8 @@ DENG2_PIMPL(VRWindowTransform)
vrCfg.enableFrustumShift(false);

// Use a little bit of multisampling to smooth out the magnified jagged edges.
// Note: Independent of the vid-fsaa setting because this is beneficial even when
// vid-fsaa is disabled.
// Note: Independent of the window FSAA setting because this is beneficial even
// when FSAA is disabled.
unwarpedFB.setSampleCount(1); //vrCfg.riftFramebufferSampleCount());

// Set render target to offscreen temporarily.
Expand Down
6 changes: 4 additions & 2 deletions doomsday/libgui/src/persistentcanvaswindow.cpp
Expand Up @@ -194,8 +194,10 @@ DENG2_PIMPL(PersistentCanvasWindow)
config.set(configName("maximize"), isMaximized());
config.set(configName("fullscreen"), isFullscreen());
config.set(configName("colorDepth"), colorDepthBits);
config.set(configName("fsaa"), isAntialiased());
config.set(configName("vsync"), isVSync());

// FSAA and vsync are saved as part of the Config.
//config.set(configName("fsaa"), isAntialiased());
//config.set(configName("vsync"), isVSync());
}

void restoreFromConfig()
Expand Down

0 comments on commit bc765f7

Please sign in to comment.