diff --git a/cocos/renderer/CCGLProgram.cpp b/cocos/renderer/CCGLProgram.cpp index b776a8958a..b80e40d6ae 100644 --- a/cocos/renderer/CCGLProgram.cpp +++ b/cocos/renderer/CCGLProgram.cpp @@ -595,18 +595,36 @@ void GLProgram::use() GL::useProgram(_program); } -std::string GLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const +static std::string logForOpenGLShader(GLuint shader) { std::string ret; GLint logLength = 0, charsWritten = 0; - infoFunc(object, GL_INFO_LOG_LENGTH, &logLength); + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); if (logLength < 1) return ""; - char *logBytes = (char*)malloc(logLength); - logFunc(object, logLength, &charsWritten, logBytes); + char *logBytes = (char*)malloc(logLength + 1); + glGetShaderInfoLog(shader, logLength, &charsWritten, logBytes); + logBytes[logLength] = '\0'; + ret = logBytes; + free(logBytes); + return ret; +} + +static std::string logForOpenGLProgram(GLuint program) +{ + std::string ret; + GLint logLength = 0, charsWritten = 0; + + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); + if (logLength < 1) + return ""; + + char *logBytes = (char*)malloc(logLength + 1); + glGetProgramInfoLog(program, logLength, &charsWritten, logBytes); + logBytes[logLength] = '\0'; ret = logBytes; free(logBytes); @@ -615,17 +633,17 @@ std::string GLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFunc std::string GLProgram::getVertexShaderLog() const { - return this->logForOpenGLObject(_vertShader, (GLInfoFunction)&glGetShaderiv, (GLLogFunction)&glGetShaderInfoLog); + return cocos2d::logForOpenGLShader(_vertShader); } std::string GLProgram::getFragmentShaderLog() const { - return this->logForOpenGLObject(_fragShader, (GLInfoFunction)&glGetShaderiv, (GLLogFunction)&glGetShaderInfoLog); + return cocos2d::logForOpenGLShader(_fragShader); } std::string GLProgram::getProgramLog() const { - return this->logForOpenGLObject(_program, (GLInfoFunction)&glGetProgramiv, (GLLogFunction)&glGetProgramInfoLog); + return logForOpenGLProgram(_program); } // Uniform cache diff --git a/cocos/renderer/CCGLProgram.h b/cocos/renderer/CCGLProgram.h index f7323eb66d..eb79880b6a 100644 --- a/cocos/renderer/CCGLProgram.h +++ b/cocos/renderer/CCGLProgram.h @@ -47,9 +47,8 @@ NS_CC_BEGIN class GLProgram; class Director; -typedef void (*GLInfoFunction)(GLuint program, GLenum pname, GLint* params); -typedef void (*GLLogFunction) (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); - +CC_DEPRECATED_ATTRIBUTE typedef void (*GLInfoFunction)(GLuint program, GLenum pname, GLint* params); +CC_DEPRECATED_ATTRIBUTE typedef void (*GLLogFunction) (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); struct VertexAttrib { @@ -333,8 +332,7 @@ protected: void parseUniforms(); bool compileShader(GLuint * shader, GLenum type, const GLchar* source); - std::string logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const; - + GLuint _program; GLuint _vertShader; GLuint _fragShader;