issue #2790: GLProgram::getXXXLog return `std::string` to prevent using CCString which was deprecated.

This commit is contained in:
James Chen 2013-12-11 22:35:37 +08:00
parent c2bccbaf98
commit 9e637a3a3b
2 changed files with 16 additions and 28 deletions

View File

@ -202,11 +202,11 @@ bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source
if (type == GL_VERTEX_SHADER)
{
CCLOG("cocos2d: %s", getVertexShaderLog());
CCLOG("cocos2d: %s", getVertexShaderLog().c_str());
}
else
{
CCLOG("cocos2d: %s", getFragmentShaderLog());
CCLOG("cocos2d: %s", getFragmentShaderLog().c_str());
}
free(src);
@ -288,34 +288,35 @@ void GLProgram::use()
GL::useProgram(_program);
}
const char* GLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const
std::string GLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const
{
std::string ret;
GLint logLength = 0, charsWritten = 0;
infoFunc(object, GL_INFO_LOG_LENGTH, &logLength);
if (logLength < 1)
return 0;
return "";
char *logBytes = (char*)malloc(logLength);
logFunc(object, logLength, &charsWritten, logBytes);
String* log = String::create(logBytes);
ret = logBytes;
free(logBytes);
return log->getCString();
return ret;
}
const char* GLProgram::getVertexShaderLog() const
std::string GLProgram::getVertexShaderLog() const
{
return this->logForOpenGLObject(_vertShader, (GLInfoFunction)&glGetShaderiv, (GLLogFunction)&glGetShaderInfoLog);
}
const char* GLProgram::getFragmentShaderLog() const
std::string GLProgram::getFragmentShaderLog() const
{
return this->logForOpenGLObject(_fragShader, (GLInfoFunction)&glGetShaderiv, (GLLogFunction)&glGetShaderInfoLog);
}
const char* GLProgram::getProgramLog() const
std::string GLProgram::getProgramLog() const
{
return this->logForOpenGLObject(_program, (GLInfoFunction)&glGetProgramiv, (GLLogFunction)&glGetProgramInfoLog);
}

View File

@ -211,26 +211,13 @@ public:
void setUniformsForBuiltins();
/** returns the vertexShader error log */
const char* getVertexShaderLog() const;
/** @deprecated. Use getVertexShaderLog() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE const char* vertexShaderLog() const { return getVertexShaderLog(); }
std::string getVertexShaderLog() const;
/** returns the fragmentShader error log */
const char* getFragmentShaderLog() const;
/** @deprecated. Use getFragmentShaderLog() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE const char* fragmentShaderLog() const{ return getFragmentShaderLog();}
std::string getFragmentShaderLog() const;
/** returns the program error log */
const char* getProgramLog() const;
/** @deprecated. Use getProgramLog() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE const char* programLog() const { return getProgramLog(); }
std::string getProgramLog() const;
// reload all shaders, this function is designed for android
// when opengl context lost, so don't call it.
@ -242,7 +229,7 @@ private:
bool updateUniformLocation(GLint location, GLvoid* data, unsigned int bytes);
const char* description() const;
bool compileShader(GLuint * shader, GLenum type, const GLchar* source);
const char* logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const;
std::string logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const;
private:
GLuint _program;