be more conservative and use pure SDL when shader 0 ("none") is selected
This commit is contained in:
parent
aca107c4cb
commit
2a6677fd46
3 changed files with 20 additions and 36 deletions
src
|
@ -5,8 +5,7 @@
|
|||
|
||||
#ifndef __APPLE__
|
||||
extern bool LoadShaderExtensions();
|
||||
extern void RenderWithShader(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* backBuffer);
|
||||
extern const char* NextShader();
|
||||
extern bool RenderWithShader(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* backBuffer);
|
||||
#else
|
||||
#include "stratagus.h"
|
||||
|
||||
|
@ -14,13 +13,8 @@ inline bool LoadShaderExtensions() {
|
|||
return false;
|
||||
}
|
||||
|
||||
inline void RenderWithShader(SDL_Renderer*, SDL_Window*, SDL_Texture*) {
|
||||
fprintf(stderr, "shaders not supported on macOS\n");
|
||||
ExitFatal(-1);
|
||||
}
|
||||
|
||||
inline const char* NextShader() {
|
||||
return "shaders not supported on macOS";
|
||||
inline bool RenderWithShader(SDL_Renderer*, SDL_Window*, SDL_Texture*) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -103,8 +103,6 @@ double FrameTicks; /// Frame length in ms
|
|||
|
||||
const EventCallback *Callbacks;
|
||||
|
||||
static bool CanUseShaders = false;
|
||||
|
||||
bool IsSDLWindowVisible = true;
|
||||
|
||||
uint32_t SDL_CUSTOM_KEY_UP;
|
||||
|
@ -378,15 +376,7 @@ void InitVideoSdl()
|
|||
SDL_GetRendererInfo(TheRenderer, &rendererInfo);
|
||||
printf("[Renderer] %s\n", rendererInfo.name);
|
||||
if(!strncmp(rendererInfo.name, "opengl", 6)) {
|
||||
CanUseShaders = LoadShaderExtensions();
|
||||
}
|
||||
if (!CanUseShaders) {
|
||||
puts("[Renderer] Cannot use shaders");
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
|
||||
SDL_DestroyRenderer(TheRenderer);
|
||||
TheRenderer = SDL_CreateRenderer(TheWindow, -1, SDL_RENDERER_SOFTWARE);
|
||||
SDL_GetRendererInfo(TheRenderer, &rendererInfo);
|
||||
printf("[Renderer] %s\n", rendererInfo.name);
|
||||
LoadShaderExtensions();
|
||||
}
|
||||
SDL_SetRenderDrawColor(TheRenderer, 0, 0, 0, 255);
|
||||
Video.ResizeScreen(Video.Width, Video.Height);
|
||||
|
@ -747,9 +737,7 @@ void RealizeVideoMemory()
|
|||
if (NumRects) {
|
||||
//SDL_UpdateWindowSurfaceRects(TheWindow, Rects, NumRects);
|
||||
SDL_UpdateTexture(TheTexture, NULL, TheScreen->pixels, TheScreen->pitch);
|
||||
if (CanUseShaders) {
|
||||
RenderWithShader(TheRenderer, TheWindow, TheTexture);
|
||||
} else {
|
||||
if (!RenderWithShader(TheRenderer, TheWindow, TheTexture)) {
|
||||
SDL_RenderClear(TheRenderer);
|
||||
//for (int i = 0; i < NumRects; i++)
|
||||
// SDL_UpdateTexture(TheTexture, &Rects[i], TheScreen->pixels, TheScreen->pitch);
|
||||
|
|
|
@ -88,6 +88,9 @@ static const int MAX_SHADERS = 128;
|
|||
static GLuint shaderPrograms[MAX_SHADERS + 1] = { (GLuint) 0 };
|
||||
static const char* shaderNames[MAX_SHADERS + 1] = { NULL };
|
||||
static char shadersLoaded = -1;
|
||||
#define canUseShaders (shadersLoaded == 1)
|
||||
#define shadersAreInitialized (shadersLoaded != -1)
|
||||
#define setCanUseShaders(x) (shadersLoaded = (x ? 1 : 0))
|
||||
static int currentShaderIdx = 0;
|
||||
|
||||
static std::regex invalidQuoteReplaceRegex("\"([a-zA-Z0-9 -\\.]+)\"");
|
||||
|
@ -239,7 +242,11 @@ static int loadShaders() {
|
|||
return numShdr;
|
||||
}
|
||||
|
||||
void RenderWithShader(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* backBuffer) {
|
||||
bool RenderWithShader(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* backBuffer) {
|
||||
if (!canUseShaders || currentShaderIdx == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GLint oldProgramId;
|
||||
// Detach the texture
|
||||
SDL_SetRenderTarget(renderer, NULL);
|
||||
|
@ -343,14 +350,8 @@ void RenderWithShader(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* back
|
|||
if (shaderProgram != 0) {
|
||||
glUseProgram(oldProgramId);
|
||||
}
|
||||
}
|
||||
|
||||
const char* NextShader() {
|
||||
if (shaderPrograms[++currentShaderIdx] == 0) {
|
||||
currentShaderIdx = 0;
|
||||
}
|
||||
std::cout << "NextShader: " << shaderNames[currentShaderIdx] << std::endl;
|
||||
return shaderNames[currentShaderIdx];
|
||||
return true;
|
||||
}
|
||||
|
||||
static int CclGetShader(lua_State *l) {
|
||||
|
@ -380,6 +381,7 @@ static int CclSetShader(lua_State *l) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
currentShaderIdx = 0;
|
||||
lua_pushboolean(l, 0);
|
||||
return 1;
|
||||
}
|
||||
|
@ -395,8 +397,8 @@ static int CclGetShaderNames(lua_State *l) {
|
|||
}
|
||||
|
||||
bool LoadShaderExtensions() {
|
||||
if (shadersLoaded != -1) {
|
||||
return shadersLoaded == 1;
|
||||
if (shadersAreInitialized) {
|
||||
return canUseShaders;
|
||||
}
|
||||
|
||||
*(void **) (&lazyGlBegin) = SDL_GL_GetProcAddress("glBegin");
|
||||
|
@ -437,16 +439,16 @@ bool LoadShaderExtensions() {
|
|||
glLinkProgram && glValidateProgram && glGetProgramiv && glGetProgramInfoLog &&
|
||||
glUseProgram && glGetUniformLocation && glUniform1i && glUniform1f && glUniform2f &&
|
||||
glUniformMatrix4fv && glGetAttribLocation && glVertexAttrib4f) {
|
||||
shadersLoaded = loadShaders() > 0 ? 1 : 0;
|
||||
setCanUseShaders(loadShaders() > 0);
|
||||
} else {
|
||||
shadersLoaded = 0;
|
||||
setCanUseShaders(false);
|
||||
}
|
||||
|
||||
lua_register(Lua, "GetShaderNames", CclGetShaderNames);
|
||||
lua_register(Lua, "GetShader", CclGetShader);
|
||||
lua_register(Lua, "SetShader", CclSetShader);
|
||||
|
||||
return shadersLoaded == 1;
|
||||
return canUseShaders;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue