Skip to content

Commit

Permalink
We use MSAA for antialiasing, stop calling it FSAA.
Browse files Browse the repository at this point in the history
Also support higher than 8x MSAA, if supported by the GPU,
and remove MSAA options not supported by the GPU from the
options list (4x is mandatory by spec, but 8x is not).
  • Loading branch information
perim committed Mar 18, 2017
1 parent ff57dc5 commit 33057c2
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 96 deletions.
7 changes: 7 additions & 0 deletions lib/ivis_opengl/piestate.cpp
Expand Up @@ -676,3 +676,10 @@ bool _glerrors(const char *function, const char *file, int line)
}
return ret;
}

int pie_GetMaxAntialiasing()
{
GLint maxSamples = 0;
glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
return maxSamples;
}
2 changes: 2 additions & 0 deletions lib/ivis_opengl/piestate.h
Expand Up @@ -85,6 +85,8 @@ extern void pie_SetTexturePage(SDWORD num);
extern void pie_SetRendMode(REND_MODE rendMode);
RENDER_STATE getCurrentRenderState();

int pie_GetMaxAntialiasing();

bool pie_LoadShaders();
void pie_FreeShaders();
SHADER_MODE pie_LoadShader(const char *programName, const char *vertexPath, const char *fragmentPath,
Expand Down
1 change: 0 additions & 1 deletion lib/sdl/main_sdl.cpp
Expand Up @@ -1263,7 +1263,6 @@ bool wzMainScreenSetup(int antialiasing, bool fullscreen, bool vsync)
// Enable stencil buffer, needed for shadows to work.
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

// Enable FSAA anti-aliasing if and at the level requested by the user
if (antialiasing)
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/configuration.cpp
Expand Up @@ -142,9 +142,9 @@ bool loadConfig()
setTextureSize(ini.value("textureSize").toInt());
}
NetPlay.isUPNP = ini.value("UPnP", true).toBool();
if (ini.contains("FSAA"))
if (ini.contains("antialiasing"))
{
war_setFSAA(ini.value("FSAA").toInt());
war_setAntialiasing(ini.value("antialiasing").toInt());
}
// Leave this to false, some system will fail and they can't see the system popup dialog!
war_setFullscreen(ini.value("fullscreen", false).toBool());
Expand Down Expand Up @@ -220,7 +220,7 @@ bool saveConfig()
ini.setValue("trapCursor", war_GetTrapCursor());
ini.setValue("vsync", war_GetVsync());
ini.setValue("textureSize", getTextureSize());
ini.setValue("FSAA", war_getFSAA());
ini.setValue("antialiasing", war_getAntialiasing());
ini.setValue("UPnP", (SDWORD)NetPlay.isUPNP);
ini.setValue("rotateRadar", rotateRadar);
ini.setValue("PauseOnFocusLoss", war_GetPauseOnFocusLoss());
Expand Down
46 changes: 26 additions & 20 deletions src/frontend.cpp
Expand Up @@ -89,6 +89,13 @@ bool bLimiterLoaded = false;

#define TUTORIAL_LEVEL "TUTORIAL3"

// ////////////////////////////////////////////////////////////////////////////
// Forward definitions

static void addSmallTextButton(UDWORD id, UDWORD PosX, UDWORD PosY, const char *txt, unsigned int style);

// ////////////////////////////////////////////////////////////////////////////
// Helper functions

// Returns true if escape key pressed.
//
Expand Down Expand Up @@ -116,8 +123,8 @@ template <typename T>
static T pow2Cycle(T value, T min, T max)
{
return !mouseReleased(MOUSE_RMB) ?
value < max ? value * 2 : min : // Cycle forwards.
min < value ? value / 2 : max; // Cycle backwards.
value < max ? std::max<T>(1, value) * 2 : min : // Cycle forwards.
min < value ? (value / 2 > 1 ? value / 2 : 0) : max; // Cycle backwards.
}


Expand Down Expand Up @@ -903,16 +910,15 @@ static char const *videoOptionsWindowModeString()
return war_getFullscreen()? _("Fullscreen") : _("Windowed");
}

static char const *videoOptionsFsaaString()
static std::string videoOptionsAntialiasingString()
{
switch (war_getFSAA())
if (war_getAntialiasing() == 0)
{
case FSAA_OFF: return _("Off");
case FSAA_2X: return _("");
case FSAA_4X: return _("");
case FSAA_8X: return _("");
// Some cards can do 16x & 32x ...
default: return _("Unsupported");
return _("Off");
}
else
{
return std::to_string(war_getAntialiasing()) + "×";
}
}

Expand Down Expand Up @@ -958,19 +964,19 @@ static bool startVideoOptionsMenu(void)

// Resolution
addTextButton(FRONTEND_RESOLUTION, FRONTEND_POS3X - 35, FRONTEND_POS3Y, _("Resolution*"), WBUT_SECONDARY);
addTextButton(FRONTEND_RESOLUTION_R, FRONTEND_POS3M - 55, FRONTEND_POS3Y, videoOptionsResolutionString().c_str(), WBUT_SECONDARY);
addTextButton(FRONTEND_RESOLUTION_R, FRONTEND_POS3M - 55, FRONTEND_POS3Y, videoOptionsResolutionString(), WBUT_SECONDARY);

// Texture size
addTextButton(FRONTEND_TEXTURESZ, FRONTEND_POS4X - 35, FRONTEND_POS4Y, _("Texture size"), WBUT_SECONDARY);
addTextButton(FRONTEND_TEXTURESZ_R, FRONTEND_POS4M - 55, FRONTEND_POS4Y, videoOptionsTextureSizeString().c_str(), WBUT_SECONDARY);
addTextButton(FRONTEND_TEXTURESZ_R, FRONTEND_POS4M - 55, FRONTEND_POS4Y, videoOptionsTextureSizeString(), WBUT_SECONDARY);

// Vsync
addTextButton(FRONTEND_VSYNC, FRONTEND_POS5X - 35, FRONTEND_POS5Y, _("Vertical sync"), WBUT_SECONDARY);
addTextButton(FRONTEND_VSYNC_R, FRONTEND_POS5M - 55, FRONTEND_POS5Y, videoOptionsVsyncString(), WBUT_SECONDARY);

// FSAA
addTextButton(FRONTEND_FSAA, FRONTEND_POS5X - 35, FRONTEND_POS6Y, "FSAA*", WBUT_SECONDARY);
addTextButton(FRONTEND_FSAA_R, FRONTEND_POS5M - 55, FRONTEND_POS6Y, videoOptionsFsaaString(), WBUT_SECONDARY);
// Antialiasing
addTextButton(FRONTEND_FSAA, FRONTEND_POS5X - 35, FRONTEND_POS6Y, "Antialiasing*", WBUT_SECONDARY);
addTextButton(FRONTEND_FSAA_R, FRONTEND_POS5M - 55, FRONTEND_POS6Y, videoOptionsAntialiasingString(), WBUT_SECONDARY);

// Add some text down the side of the form
addSideText(FRONTEND_SIDETEXT, FRONTEND_SIDEX, FRONTEND_SIDEY, _("VIDEO OPTIONS"));
Expand All @@ -997,8 +1003,8 @@ bool runVideoOptionsMenu(void)
case FRONTEND_FSAA:
case FRONTEND_FSAA_R:
{
war_setFSAA(stepCycle(war_getFSAA(), FSAA_OFF, FSAA_LEVEL(FSAA_MAX - 1)));
widgSetString(psWScreen, FRONTEND_FSAA_R, videoOptionsFsaaString());
war_setAntialiasing(pow2Cycle(war_getAntialiasing(), 0, pie_GetMaxAntialiasing()));
widgSetString(psWScreen, FRONTEND_FSAA_R, videoOptionsAntialiasingString().c_str());
break;
}

Expand Down Expand Up @@ -1624,7 +1630,7 @@ void addSideText(UDWORD id, UDWORD PosX, UDWORD PosY, const char *txt)
}

// ////////////////////////////////////////////////////////////////////////////
void addTextButton(UDWORD id, UDWORD PosX, UDWORD PosY, const char *txt, unsigned int style)
void addTextButton(UDWORD id, UDWORD PosX, UDWORD PosY, const std::string &txt, unsigned int style)
{
W_BUTINIT sButInit;

Expand All @@ -1636,7 +1642,7 @@ void addTextButton(UDWORD id, UDWORD PosX, UDWORD PosY, const char *txt, unsign
// Align
if (!(style & WBUT_TXTCENTRE))
{
sButInit.width = (short)(iV_GetTextWidth(txt) + 10);
sButInit.width = (short)(iV_GetTextWidth(txt.c_str()) + 10);
sButInit.x += 35;
}
else
Expand All @@ -1656,7 +1662,7 @@ void addTextButton(UDWORD id, UDWORD PosX, UDWORD PosY, const char *txt, unsign
sButInit.height = FRONTEND_BUTHEIGHT;
sButInit.pDisplay = displayTextOption;
sButInit.FontID = font_large;
sButInit.pText = txt;
sButInit.pText = txt.c_str();
widgAddButton(psWScreen, &sButInit);

// Disable button
Expand Down
3 changes: 1 addition & 2 deletions src/frontend.h
Expand Up @@ -76,8 +76,7 @@ bool runTutorialMenu(void);
void addTopForm(void);
void addBottomForm(void);
void addBackdrop(void);
void addTextButton(UDWORD id, UDWORD PosX, UDWORD PosY, const char *txt, unsigned int style);
void addSmallTextButton(UDWORD id, UDWORD PosX, UDWORD PosY, const char *txt, unsigned int style);
void addTextButton(UDWORD id, UDWORD PosX, UDWORD PosY, const std::string &txt, unsigned int style);
void addSideText(UDWORD id, UDWORD PosX, UDWORD PosY, const char *txt);
void addFESlider(UDWORD id, UDWORD parent, UDWORD x, UDWORD y, UDWORD stops, UDWORD pos);

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -1022,7 +1022,7 @@ int realmain(int argc, char *argv[])
}
}

if (!wzMainScreenSetup(war_getFSAA(), war_getFullscreen(), war_GetVsync()))
if (!wzMainScreenSetup(war_getAntialiasing(), war_getFullscreen(), war_GetVsync()))
{
return EXIT_FAILURE;
}
Expand Down
79 changes: 21 additions & 58 deletions src/warzoneconfig.cpp
Expand Up @@ -31,67 +31,32 @@
#include "component.h"

/***************************************************************************/
/*
* Global Variables
*/
/***************************************************************************/


/***************************************************************************/
/*
* Local Definitions
*/
/***************************************************************************/

struct WARZONE_GLOBALS
{
FMV_MODE FMVmode;
SWORD effectsLevel;
UDWORD width;
UDWORD height;
int screen;
int8_t SPcolor;
int MPcolour;
FSAA_LEVEL fsaa;
bool Fullscreen;
bool soundEnabled;
bool trapCursor;
bool vsync;
bool pauseOnFocusLoss;
bool ColouredCursor;
bool MusicEnabled;
FMV_MODE FMVmode = FMV_FULLSCREEN;
UDWORD width = 1024;
UDWORD height = 720;
int screen = 0;
int8_t SPcolor = 0;
int MPcolour = -1;
int antialiasing = 0;
bool Fullscreen = false;
bool soundEnabled = true;
bool trapCursor = false;
bool vsync = true;
bool pauseOnFocusLoss = true;
bool ColouredCursor = true;
bool MusicEnabled = true;
};

/***************************************************************************/
/*
* Local Variables
*/
/***************************************************************************/

static WARZONE_GLOBALS warGlobs;//STATIC use or write an access function if you need any of this
static WARZONE_GLOBALS warGlobs;

/***************************************************************************/
/*
* Local ProtoTypes
*/
/***************************************************************************/

/***************************************************************************/
/*
* Source
*/
/***************************************************************************/
void war_SetDefaultStates(void)//Sets all states
void war_SetDefaultStates()
{
//set those here and reset in clParse or loadConfig
war_setFSAA(0);
war_SetVsync(true);
war_setSoundEnabled(true);
war_SetPauseOnFocusLoss(false);
war_SetColouredCursor(true);
war_SetMusicEnabled(true);
war_SetSPcolor(0); //default color is green
war_setMPcolour(-1); // Default color is random.
warGlobs = WARZONE_GLOBALS();
}

void war_SetSPcolor(int color)
Expand Down Expand Up @@ -129,14 +94,14 @@ bool war_getFullscreen(void)
return warGlobs.Fullscreen;
}

void war_setFSAA(unsigned int fsaa)
void war_setAntialiasing(int antialiasing)
{
warGlobs.fsaa = (FSAA_LEVEL)(fsaa % FSAA_MAX);
warGlobs.antialiasing = antialiasing;
}

FSAA_LEVEL war_getFSAA()
int war_getAntialiasing()
{
return warGlobs.fsaa;
return warGlobs.antialiasing;
}

void war_SetTrapCursor(bool b)
Expand Down Expand Up @@ -189,8 +154,6 @@ int war_GetScreen()
return warGlobs.screen;
}

/***************************************************************************/
/***************************************************************************/
void war_SetFMVmode(FMV_MODE mode)
{
warGlobs.FMVmode = (FMV_MODE)(mode % FMV_MAX);
Expand Down
13 changes: 2 additions & 11 deletions src/warzoneconfig.h
Expand Up @@ -40,15 +40,6 @@ enum FMV_MODE
FMV_MAX
};

enum FSAA_LEVEL
{
FSAA_OFF,
FSAA_2X,
FSAA_4X,
FSAA_8X,
FSAA_MAX
};

/***************************************************************************/
/*
* Global ProtoTypes
Expand All @@ -61,8 +52,8 @@ extern void war_SetAllowSubtitles(bool);
extern bool war_GetAllowSubtitles(void);
extern void war_setFullscreen(bool);
extern bool war_getFullscreen(void);
extern void war_setFSAA(unsigned int);
FSAA_LEVEL war_getFSAA();
void war_setAntialiasing(int);
int war_getAntialiasing();
extern void war_SetTrapCursor(bool b);
extern bool war_GetTrapCursor(void);
extern bool war_GetColouredCursor(void);
Expand Down

0 comments on commit 33057c2

Please sign in to comment.