From 6882e00d5e39b2cfa92975a51f717a19bc9319c9 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 2 Dec 2011 18:31:06 -0600 Subject: [PATCH] Compile --- .../Plugin_VideoOGL/Src/PixelShaderCache.cpp | 31 ++++++++++++++++++- .../Plugin_VideoOGL/Src/VertexShaderCache.cpp | 31 ++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index c4162b54a0..36a8f054f5 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -296,7 +296,36 @@ void PixelShaderCache::SetCurrentShader(GLuint Shader) // GLSL Specific bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) { - return false; + GLuint result = glCreateShader(GL_FRAGMENT_SHADER); + + glShaderSource(result, 1, &pstrprogram, NULL); + glCompileShader(result); + GLsizei length = 0; + + glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length); + if (length > 0) + { + GLsizei charsWritten; + GLchar* infoLog = new GLchar[length]; + glGetShaderInfoLog(result, length, &charsWritten, infoLog); + WARN_LOG(VIDEO, "Shader info log:\n%s", infoLog); + delete[] infoLog; + } + + GLint compileStatus; + glGetShaderiv(result, GL_COMPILE_STATUS, &compileStatus); + if (compileStatus != GL_TRUE) + { + // Compile failed + ERROR_LOG(VIDEO, "Shader compilation failed; see info log"); + // Don't try to use this shader + glDeleteShader(result); + return false; + } + + (void)GL_REPORT_ERROR(); + ps.glprogid = result; + return true; } void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex) { diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp index eb4f56522e..f58e9eb786 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp @@ -180,7 +180,36 @@ void VertexShaderCache::SetCurrentShader(GLuint Shader) // GLSL Specific bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram) { - return false; + GLuint result = glCreateShader(GL_VERTEX_SHADER); + + glShaderSource(result, 1, &pstrprogram, NULL); + glCompileShader(result); + GLsizei length = 0; + + glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length); + if (length > 0) + { + GLsizei charsWritten; + GLchar* infoLog = new GLchar[length]; + glGetShaderInfoLog(result, length, &charsWritten, infoLog); + WARN_LOG(VIDEO, "Shader info log:\n%s", infoLog); + delete[] infoLog; + } + + GLint compileStatus; + glGetShaderiv(result, GL_COMPILE_STATUS, &compileStatus); + if (compileStatus != GL_TRUE) + { + // Compile failed + ERROR_LOG(VIDEO, "Shader compilation failed; see info log"); + // Don't try to use this shader + glDeleteShader(result); + return false; + } + + (void)GL_REPORT_ERROR(); + vs.glprogid = result; + return true; } void SetVSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1) {