use and expose ShaderIndex on the Video global
This commit is contained in:
parent
c28db9ae59
commit
b38c5bb926
6 changed files with 26 additions and 14 deletions
|
@ -9,7 +9,6 @@ extern PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebuffer;
|
|||
#define glBindFramebuffer glBindFramebufferEXT
|
||||
#endif
|
||||
extern GLuint fullscreenFramebuffer;
|
||||
extern unsigned ShaderIndex;
|
||||
extern bool LoadShaders(int direction, char* shadernameOut);
|
||||
extern bool LoadShaderExtensions();
|
||||
extern void SetupFramebuffer();
|
||||
|
|
|
@ -267,7 +267,7 @@ struct EventCallback {
|
|||
class CVideo
|
||||
{
|
||||
public:
|
||||
CVideo() : Width(0), Height(0), Depth(0), FullScreen(false) {}
|
||||
CVideo() : Width(0), Height(0), Depth(0), ShaderIndex(0), FullScreen(false) {}
|
||||
|
||||
void LockScreen();
|
||||
void UnlockScreen();
|
||||
|
@ -381,6 +381,7 @@ public:
|
|||
SDL_Cursor *blankCursor;
|
||||
#endif
|
||||
int Depth;
|
||||
int ShaderIndex;
|
||||
bool FullScreen;
|
||||
};
|
||||
|
||||
|
@ -498,6 +499,9 @@ extern void WaitEventsOneFrame();
|
|||
/// Toggle full screen mode
|
||||
extern void ToggleFullScreen();
|
||||
|
||||
/// Switch to the shader currently stored in Video.ShaderIndex
|
||||
extern void SwitchToShader();
|
||||
|
||||
/// Push current clipping.
|
||||
extern void PushClipping();
|
||||
|
||||
|
|
|
@ -634,7 +634,7 @@ void ParseCommandLine(int argc, char **argv, Parameters ¶meters)
|
|||
continue;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
case 'x':
|
||||
ShaderIndex = atoi(optarg);
|
||||
Video.ShaderIndex = atoi(optarg);
|
||||
if (atoi(optarg) == -1) {
|
||||
GLShaderPipelineSupported = false;
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ public:
|
|||
int Width;
|
||||
int Height;
|
||||
int Depth;
|
||||
int ShaderIndex;
|
||||
bool FullScreen;
|
||||
bool ResizeScreen(int width, int height);
|
||||
};
|
||||
|
||||
CVideo Video;
|
||||
void ToggleFullScreen(void);
|
||||
void SwitchToShader(void);
|
||||
|
||||
class CGraphic
|
||||
{
|
||||
|
|
|
@ -779,6 +779,15 @@ void Invalidate()
|
|||
}
|
||||
}
|
||||
|
||||
// Switch to the shader currently stored in Video.ShaderIndex without changing it
|
||||
void SwitchToShader() {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
LoadShaders(0, NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
** Handle interactive input event.
|
||||
**
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "stratagus.h"
|
||||
#include "parameters.h"
|
||||
#include "video.h"
|
||||
#include "iolib.h"
|
||||
#include <iostream>
|
||||
|
@ -81,16 +82,13 @@ void printProgramInfoLog(GLuint obj, const char* prefix)
|
|||
}
|
||||
}
|
||||
|
||||
unsigned ShaderIndex = -1;
|
||||
|
||||
/* This does not have to be very efficient, it is only called when the shader
|
||||
is changed by the user.
|
||||
*/
|
||||
extern bool LoadShaders(int direction, char* shadernameOut) {
|
||||
ShaderIndex += direction;
|
||||
if (direction == 0 && ShaderIndex == -1) {
|
||||
// TODO: load from preferences
|
||||
ShaderIndex = 0;
|
||||
Video.ShaderIndex += direction;
|
||||
if (direction == 0 && Video.ShaderIndex == -1) {
|
||||
Video.ShaderIndex = 0;
|
||||
}
|
||||
|
||||
GLuint vs, fs;
|
||||
|
@ -101,7 +99,7 @@ extern bool LoadShaders(int direction, char* shadernameOut) {
|
|||
}
|
||||
|
||||
std::vector<FileList> flp;
|
||||
std::string shaderPath(StratagusLibPath);
|
||||
std::string shaderPath(Parameters::Instance.GetUserDirectory());
|
||||
#ifdef _WIN32
|
||||
shaderPath.append("\\shaders\\");
|
||||
#else
|
||||
|
@ -118,14 +116,14 @@ extern bool LoadShaders(int direction, char* shadernameOut) {
|
|||
}
|
||||
}
|
||||
if (numShaderFiles <= 0) return false;
|
||||
if (numShaderFiles <= ShaderIndex || ShaderIndex < 0) {
|
||||
ShaderIndex = ShaderIndex % numShaderFiles;
|
||||
if (numShaderFiles <= Video.ShaderIndex || Video.ShaderIndex < 0) {
|
||||
Video.ShaderIndex = Video.ShaderIndex % numShaderFiles;
|
||||
}
|
||||
|
||||
if (shadernameOut) {
|
||||
strncpy(shadernameOut, flp[shaderFileToIdx[ShaderIndex]].name.c_str(), 1023);
|
||||
strncpy(shadernameOut, flp[shaderFileToIdx[Video.ShaderIndex]].name.c_str(), 1023);
|
||||
}
|
||||
shaderPath.append(flp[shaderFileToIdx[ShaderIndex]].name);
|
||||
shaderPath.append(flp[shaderFileToIdx[Video.ShaderIndex]].name);
|
||||
std::ifstream myfile(shaderPath.c_str());
|
||||
std::string contents((std::istreambuf_iterator<char>(myfile)),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
|
Loading…
Reference in a new issue