diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index 5110023ee3..574ca33a05 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -629,6 +629,70 @@ void OpenGL_Shutdown() #endif } +GLuint OpenGL_CompileProgram ( const char* vertexShader, const char* fragmentShader ) +{ + // generate objects + GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER); + GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); + GLuint programID = glCreateProgram(); + GLint Result = GL_FALSE; + char stringBuffer[1024]; + GLsizei stringBufferUsage = 0; + + // compile vertex shader + glShaderSource(vertexShaderID, 1, &vertexShader, NULL); + glCompileShader(vertexShaderID); +#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL) + glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &Result); + glGetShaderInfoLog(vertexShaderID, 1024, &stringBufferUsage, stringBuffer); + if(Result && stringBufferUsage) { + ERROR_LOG(VIDEO, "GLSL vertex shader warnings:\n%s%s", stringBuffer, vertexShader); + } else if(!Result) { + ERROR_LOG(VIDEO, "GLSL vertex shader error:\n%s%s", stringBuffer, vertexShader); + } else { + DEBUG_LOG(VIDEO, "GLSL vertex shader compiled:\n%s", vertexShader); + } + bool shader_errors = !Result; +#endif + + // compile fragment shader + glShaderSource(fragmentShaderID, 1, &fragmentShader, NULL); + glCompileShader(fragmentShaderID); +#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL) + glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &Result); + glGetShaderInfoLog(fragmentShaderID, 1024, &stringBufferUsage, stringBuffer); + if(Result && stringBufferUsage) { + ERROR_LOG(VIDEO, "GLSL fragment shader warnings:\n%s%s", stringBuffer, fragmentShader); + } else if(!Result) { + ERROR_LOG(VIDEO, "GLSL fragment shader error:\n%s%s", stringBuffer, fragmentShader); + } else { + DEBUG_LOG(VIDEO, "GLSL fragment shader compiled:\n%s", fragmentShader); + } + shader_errors |= !Result; +#endif + + // link them + glAttachShader(programID, vertexShaderID); + glAttachShader(programID, fragmentShaderID); + glLinkProgram(programID); +#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL) + glGetProgramiv(programID, GL_LINK_STATUS, &Result); + glGetProgramInfoLog(programID, 1024, &stringBufferUsage, stringBuffer); + if(Result && stringBufferUsage) { + ERROR_LOG(VIDEO, "GLSL linker warnings:\n%s%s%s", stringBuffer, vertexShader, fragmentShader); + } else if(!Result && !shader_errors) { + ERROR_LOG(VIDEO, "GLSL linker error:\n%s%s%s", stringBuffer, vertexShader, fragmentShader); + } +#endif + + // cleanup + glDeleteShader(vertexShaderID); + glDeleteShader(fragmentShaderID); + + return programID; +} + + GLuint OpenGL_ReportGLError(const char *function, const char *file, int line) { GLint err = glGetError(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h index 23c31a1bb7..61f3ef6085 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h @@ -96,6 +96,9 @@ u32 OpenGL_GetBackbufferHeight(); // Set things void OpenGL_SetWindowText(const char *text); +// Helpers +GLuint OpenGL_CompileProgram(const char *vertexShader, const char *fragmentShader); + // Error reporting - use the convenient macros. void OpenGL_ReportARBProgramError(); GLuint OpenGL_ReportGLError(const char *function, const char *file, int line); @@ -126,4 +129,7 @@ extern CGprofile g_cgvProf, g_cgfProf; // use GLSL shaders across the whole pipeline. Yikes! //#define USE_DUAL_SOURCE_BLEND +// TODO: should be removed if we use glsl a lot +#define DEBUG_GLSL + #endif // _GLINIT_H_ diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index 6c98824341..29166e4bc0 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -176,19 +176,7 @@ RasterFont::RasterFont() glVertexAttribPointer(1, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2); // generate shader - GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); - GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); - shader_program = glCreateProgram(); - - glShaderSource(vertex_shader, 1, &s_vertex_shader, NULL); - glCompileShader(vertex_shader); - glShaderSource(fragment_shader, 1, &s_fragment_shader, NULL); - glCompileShader(fragment_shader); - glAttachShader(shader_program, vertex_shader); - glAttachShader(shader_program, fragment_shader); - glLinkProgram(shader_program); - glDeleteShader(vertex_shader); - glDeleteShader(fragment_shader); + shader_program = OpenGL_CompileProgram(s_vertex_shader, s_fragment_shader); // bound uniforms glUseProgram(shader_program);