From 63e6557165d97f72dec98f26b5d009aebc93cdec Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Sun, 4 Jan 2015 21:51:22 +0800 Subject: [PATCH 1/2] fix GLProgram log crash on windows --- cocos/renderer/CCGLProgram.cpp | 32 +++++++++++++++++++++++++------- cocos/renderer/CCGLProgram.h | 8 +++----- 2 files changed, 28 insertions(+), 12 deletions(-) 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; From 8dde42b66a4de8b924a95878d5033f6c8992b01a Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 5 Jan 2015 13:52:22 +0800 Subject: [PATCH 2/2] code adjust, delay deprecated flag specification --- cocos/renderer/CCGLProgram.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos/renderer/CCGLProgram.h b/cocos/renderer/CCGLProgram.h index eb79880b6a..4577311262 100644 --- a/cocos/renderer/CCGLProgram.h +++ b/cocos/renderer/CCGLProgram.h @@ -47,8 +47,9 @@ NS_CC_BEGIN class GLProgram; class Director; -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); +//FIXME: these two typedefs would be deprecated or removed in version 4.0 +typedef void (*GLInfoFunction)(GLuint program, GLenum pname, GLint* params); +typedef void (*GLLogFunction) (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); struct VertexAttrib {