From f079b04a5daafc1def25bb26c1111c4b02039666 Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 7 Feb 2013 12:47:41 +0100 Subject: [PATCH] also check for glsl errors on linking, activation GLSL_DEBUG again (slowdown on shader compilation) --- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp | 3 -- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h | 3 ++ .../Plugin_VideoOGL/Src/PixelShaderCache.cpp | 1 + .../Src/ProgramShaderCache.cpp | 42 +++++++++++++++++++ .../Plugin_VideoOGL/Src/VertexShaderCache.cpp | 1 + 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index 3598f55f3e..55b1d6e52a 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -28,9 +28,6 @@ #include "GLUtil.h" -// this should be removed in future, but as long as glsl is unstable, we should really read this messages -#define DEBUG_GLSL - GLWindow GLWin; cInterfaceBase *GLInterface; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h index 2b7858ee63..f5fe795575 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h @@ -69,6 +69,9 @@ bool OpenGL_ReportFBOError(const char *function, const char *file, int line); #define GL_REPORT_PROGRAM_ERROR() (void)0 #endif +// this should be removed in future, but as long as glsl is unstable, we should really read this messages +#define DEBUG_GLSL + // Isn't defined if we aren't using GLEW 1.6 #ifndef GL_ONE_MINUS_SRC1_ALPHA #define GL_ONE_MINUS_SRC1_ALPHA 0x88FB diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index 1545f9960f..eaf3562986 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -145,6 +145,7 @@ bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrpr char szTemp[MAX_PATH]; sprintf(szTemp, "ps_%d.txt", result); FILE *fp = fopen(szTemp, "wb"); + fwrite(infoLog, strlen(infoLog), 1, fp); fwrite(pstrprogram, strlen(pstrprogram), 1, fp); fclose(fp); delete[] infoLog; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index b56bb8919d..5481f26541 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -184,6 +184,48 @@ void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS) SetProgramBindings(entry); glLinkProgram(entry.prog_id); + +#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL) + GLsizei length = 0; + glGetProgramiv(entry.prog_id, GL_INFO_LOG_LENGTH, &length); + if (length > 1) + { + GLsizei charsWritten; + GLchar* infoLog = new GLchar[length]; + glGetProgramInfoLog(entry.prog_id, length, &charsWritten, infoLog); + ERROR_LOG(VIDEO, "Program info log:\n%s", infoLog); + char szTemp[MAX_PATH]; + sprintf(szTemp, "p_%d.txt", entry.prog_id); + FILE *fp = fopen(szTemp, "wb"); + fwrite(infoLog, length, 1, fp); + delete[] infoLog; + + glGetShaderiv(VS, GL_SHADER_SOURCE_LENGTH, &length); + GLchar* src = new GLchar[length]; + glGetShaderSource(VS, length, &charsWritten, src); + fwrite(src, strlen(src), 1, fp); + delete [] src; + + glGetShaderiv(PS, GL_SHADER_SOURCE_LENGTH, &length); + src = new GLchar[length]; + glGetShaderSource(PS, length, &charsWritten, src); + fwrite(src, strlen(src), 1, fp); + delete [] src; + fclose(fp); + } + + GLint linkStatus; + glGetProgramiv(entry.prog_id, GL_LINK_STATUS, &linkStatus); + if (linkStatus != GL_TRUE) + { + // Compile failed + ERROR_LOG(VIDEO, "Program linking failed; see info log"); + + // Don't try to use this shader + glDeleteProgram(entry.prog_id); + return; + } +#endif glUseProgram(entry.prog_id); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp index acba24a3b7..37a7b82485 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp @@ -131,6 +131,7 @@ bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrpr char szTemp[MAX_PATH]; sprintf(szTemp, "vs_%d.txt", result); FILE *fp = fopen(szTemp, "wb"); + fwrite(infoLog, strlen(infoLog), 1, fp); fwrite(pstrprogram, strlen(pstrprogram), 1, fp); fclose(fp); delete[] infoLog;