Skip to content

Commit

Permalink
Add shader toggle UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Safety0ff committed Jun 18, 2012
1 parent 2e72860 commit 691df6a
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/ivis_opengl/piedraw.cpp
Expand Up @@ -145,7 +145,7 @@ static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELI
{
iIMDPoly *pPolys;
bool light = true;
bool shaders = pie_GetShaderAvailability();
bool shaders = pie_GetShaderUsage();

pie_SetAlphaTest((pieFlag & pie_PREMULTIPLIED) == 0);

Expand Down
11 changes: 11 additions & 0 deletions lib/ivis_opengl/piestate.cpp
Expand Up @@ -37,6 +37,7 @@
*/

static bool shadersAvailable = false;
static bool shaderUsage = false;
static GLuint shaderProgram[SHADER_MAX];
static GLfloat shaderStretch = 0;
static GLint locTeam, locStretch, locTCMask, locFog, locNormalMap, locEcm, locTime;
Expand Down Expand Up @@ -139,6 +140,16 @@ void pie_SetShaderAvailability(bool availability)
shadersAvailable = availability;
}

bool pie_GetShaderUsage(void)
{
return shaderUsage;
}

void pie_SetShaderUsage(bool usage)
{
shaderUsage = pie_GetShaderAvailability() && usage;
}

// Read shader into text buffer
static char *readShaderBuf(const char *name)
{
Expand Down
3 changes: 3 additions & 0 deletions lib/ivis_opengl/piestate.h
Expand Up @@ -85,6 +85,9 @@ extern void pie_SetRendMode(REND_MODE rendMode);
// Shaders control center
extern bool pie_GetShaderAvailability(void);
extern void pie_SetShaderAvailability(bool);
extern bool pie_GetShaderUsage(void);
extern void pie_SetShaderUsage(bool);

bool pie_LoadShaders(void);
// Actual shaders (we do not want to export these calls)
void pie_DeactivateShader(void);
Expand Down
3 changes: 1 addition & 2 deletions lib/ivis_opengl/screen.cpp
Expand Up @@ -47,7 +47,6 @@
/* global used to indicate preferred internal OpenGL format */
int wz_texture_compression = 0;

bool opengl_fallback_mode = false;

static bool bBackDrop = false;
static char screendump_filename[PATH_MAX];
Expand Down Expand Up @@ -170,7 +169,7 @@ bool screenInitialise()
bool canRunAtAll = GLEW_VERSION_1_2 && GLEW_ARB_vertex_buffer_object && GLEW_ARB_texture_env_crossbar;
bool canRunShaders = canRunAtAll && glslVersion >= std::make_pair(1, 20); // glGetString(GL_SHADING_LANGUAGE_VERSION) >= "1.20"

if (canRunShaders && !opengl_fallback_mode)
if (canRunShaders)
{
screen_EnableMissingFunctions(); // We need to do this before pie_LoadShaders(), but the effect of this call will be undone later by iV_TextInit(), so we will need to call it again.
if (pie_LoadShaders())
Expand Down
1 change: 0 additions & 1 deletion lib/ivis_opengl/screen.h
Expand Up @@ -56,7 +56,6 @@ extern void screenDumpToDisk(const char* path);

extern int wz_texture_compression;

extern bool opengl_fallback_mode;

extern void screenDoDumpToDiskIfRequired(void);

Expand Down
2 changes: 1 addition & 1 deletion src/clparse.cpp
Expand Up @@ -599,7 +599,7 @@ bool ParseCommandLine(int argc, const char** argv)
break;

case CLI_FALLBACKMODE:
opengl_fallback_mode = true;
war_SetShaders(SHADERS_OFF);
break;
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/configuration.cpp
Expand Up @@ -121,6 +121,7 @@ bool loadConfig()
if (ini.contains("textureSize")) setTextureSize(ini.value("textureSize").toInt());
NetPlay.isUPNP = ini.value("UPnP", true).toBool();
if (ini.contains("FSAA")) war_setFSAA(ini.value("FSAA").toInt());
if (ini.contains("shaders")) war_SetShaders(ini.value("shaders").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());
war_SetTrapCursor(ini.value("trapCursor", false).toBool());
Expand Down Expand Up @@ -187,6 +188,7 @@ bool saveConfig()
ini.setValue("radarTerrainMode",(SDWORD)radarDrawMode);
ini.setValue("trapCursor", war_GetTrapCursor());
ini.setValue("vsync", war_GetVsync());
ini.setValue("shaders", war_GetShaders());
ini.setValue("textureSize", getTextureSize());
ini.setValue("FSAA", war_getFSAA());
ini.setValue("UPnP", (SDWORD)NetPlay.isUPNP);
Expand Down
33 changes: 33 additions & 0 deletions src/frontend.cpp
Expand Up @@ -33,6 +33,7 @@
#include "lib/framework/input.h"
#include "lib/ivis_opengl/bitimage.h"
#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/ivis_opengl/piestate.h"
#include "lib/sound/mixer.h"
#include "lib/widget/button.h"
#include "lib/widget/label.h"
Expand Down Expand Up @@ -883,6 +884,18 @@ static bool startVideoOptionsMenu(void)
break;
}

// Shaders
addTextButton(FRONTEND_SHADERS, FRONTEND_POS6X-35, FRONTEND_POS7Y, _("Shaders"), 0);

if (war_GetShaders() == SHADERS_ON)
{
addTextButton(FRONTEND_SHADERS_R, FRONTEND_POS6M-55, FRONTEND_POS7Y, _("On"), 0);
}
else
{
addTextButton(FRONTEND_SHADERS_R, FRONTEND_POS6M-55, FRONTEND_POS7Y, _("Off"), 0);
}

// Add some text down the side of the form
addSideText(FRONTEND_SIDETEXT, FRONTEND_SIDEX, FRONTEND_SIDEY, _("VIDEO OPTIONS"));

Expand Down Expand Up @@ -1043,6 +1056,26 @@ bool runVideoOptionsMenu(void)
break;
}

case FRONTEND_SHADERS:
case FRONTEND_SHADERS_R:
{
switch (war_GetShaders())
{
case SHADERS_ON:
war_SetShaders(SHADERS_OFF);
widgSetString(psWScreen, FRONTEND_SHADERS_R, _("Off"));
break;
case SHADERS_OFF:
war_SetShaders(SHADERS_ON);
widgSetString(psWScreen, FRONTEND_SHADERS_R, _("On"));
break;
case FALLBACK:
break;
}
pie_SetShaderUsage(war_GetShaders()==SHADERS_ON);
break;
}

case FRONTEND_QUIT:
changeTitleMode(OPTIONS);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/frontend.h
Expand Up @@ -234,6 +234,8 @@ enum
FRONTEND_VSYNC_R,
FRONTEND_FSAA,
FRONTEND_FSAA_R,
FRONTEND_SHADERS,
FRONTEND_SHADERS_R,

FRONTEND_MOUSEOPTIONS = 25000, // Mouse Options Menu
FRONTEND_TRAP,
Expand Down
9 changes: 9 additions & 0 deletions src/main.cpp
Expand Up @@ -1266,6 +1266,15 @@ int realmain(int argc, char *argv[])
war_SetWidth(pie_GetVideoBufferWidth());
war_SetHeight(pie_GetVideoBufferHeight());

if (!pie_GetShaderAvailability())
{
war_SetShaders(FALLBACK);
}
else
{
pie_SetShaderUsage(war_GetShaders()==SHADERS_ON);
}

pie_SetFogStatus(false);
pie_ScreenFlip(CLEAR_BLACK);

Expand Down
23 changes: 18 additions & 5 deletions src/warzoneconfig.cpp
Expand Up @@ -47,18 +47,19 @@ struct WARZONE_GLOBALS
{
FMV_MODE FMVmode;
SWORD effectsLevel;
bool Fullscreen;
bool soundEnabled;
bool trapCursor;
UDWORD width;
UDWORD height;
int8_t SPcolor;
int MPcolour;
FSAA_LEVEL fsaa;
RENDER_MODE shaders;
bool Fullscreen;
bool soundEnabled;
bool trapCursor;
bool vsync;
bool pauseOnFocusLoss;
bool ColouredCursor;
bool MusicEnabled;
int8_t SPcolor;
int MPcolour;
};

/***************************************************************************/
Expand All @@ -84,11 +85,13 @@ void war_SetDefaultStates(void)//Sets all states
{
//set those here and reset in clParse or loadConfig
war_setFSAA(0);
war_SetVsync(true);
war_setSoundEnabled( true );
war_SetPauseOnFocusLoss(false);
war_SetMusicEnabled(true);
war_SetSPcolor(0); //default color is green
war_setMPcolour(-1); // Default color is random.
war_SetShaders(SHADERS_ON);
}

void war_SetSPcolor(int color)
Expand Down Expand Up @@ -136,6 +139,16 @@ unsigned int war_getFSAA()
return warGlobs.fsaa;
}

void war_SetShaders(unsigned shaders)
{
warGlobs.shaders = (RENDER_MODE)shaders;
}

unsigned war_GetShaders()
{
return warGlobs.shaders;
}

void war_SetTrapCursor(bool b)
{
warGlobs.trapCursor = b;
Expand Down
9 changes: 9 additions & 0 deletions src/warzoneconfig.h
Expand Up @@ -48,6 +48,13 @@ enum FSAA_LEVEL
FSAA_8X,
FSAA_MAX
};

enum RENDER_MODE
{
FALLBACK, /// Shaders not supported
SHADERS_OFF,/// Shaders supported but off
SHADERS_ON, /// Shaders supported and on
};
/***************************************************************************/
/*
* Global ProtoTypes
Expand All @@ -66,6 +73,8 @@ extern void war_SetTrapCursor(bool b);
extern bool war_GetTrapCursor(void);
extern void war_SetVsync(bool b);
extern bool war_GetVsync(void);
extern void war_SetShaders(unsigned);
extern unsigned war_GetShaders(void);
extern void war_SetWidth(UDWORD width);
extern UDWORD war_GetWidth(void);
extern void war_SetHeight(UDWORD height);
Expand Down

0 comments on commit 691df6a

Please sign in to comment.