mirror of https://github.com/axmolengine/axmol.git
Merge pull request #9786 from dabingnn/v3_fixGLProgramLogCrash
fix GLProgram log crash on windows
This commit is contained in:
commit
1f271a3668
|
@ -595,18 +595,36 @@ void GLProgram::use()
|
||||||
GL::useProgram(_program);
|
GL::useProgram(_program);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const
|
static std::string logForOpenGLShader(GLuint shader)
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
GLint logLength = 0, charsWritten = 0;
|
GLint logLength = 0, charsWritten = 0;
|
||||||
|
|
||||||
infoFunc(object, GL_INFO_LOG_LENGTH, &logLength);
|
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
|
||||||
if (logLength < 1)
|
if (logLength < 1)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
char *logBytes = (char*)malloc(logLength);
|
char *logBytes = (char*)malloc(logLength + 1);
|
||||||
logFunc(object, logLength, &charsWritten, logBytes);
|
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;
|
ret = logBytes;
|
||||||
|
|
||||||
free(logBytes);
|
free(logBytes);
|
||||||
|
@ -615,17 +633,17 @@ std::string GLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFunc
|
||||||
|
|
||||||
std::string GLProgram::getVertexShaderLog() const
|
std::string GLProgram::getVertexShaderLog() const
|
||||||
{
|
{
|
||||||
return this->logForOpenGLObject(_vertShader, (GLInfoFunction)&glGetShaderiv, (GLLogFunction)&glGetShaderInfoLog);
|
return cocos2d::logForOpenGLShader(_vertShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GLProgram::getFragmentShaderLog() const
|
std::string GLProgram::getFragmentShaderLog() const
|
||||||
{
|
{
|
||||||
return this->logForOpenGLObject(_fragShader, (GLInfoFunction)&glGetShaderiv, (GLLogFunction)&glGetShaderInfoLog);
|
return cocos2d::logForOpenGLShader(_fragShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GLProgram::getProgramLog() const
|
std::string GLProgram::getProgramLog() const
|
||||||
{
|
{
|
||||||
return this->logForOpenGLObject(_program, (GLInfoFunction)&glGetProgramiv, (GLLogFunction)&glGetProgramInfoLog);
|
return logForOpenGLProgram(_program);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uniform cache
|
// Uniform cache
|
||||||
|
|
|
@ -47,10 +47,10 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
class GLProgram;
|
class GLProgram;
|
||||||
class Director;
|
class Director;
|
||||||
|
//FIXME: these two typedefs would be deprecated or removed in version 4.0
|
||||||
typedef void (*GLInfoFunction)(GLuint program, GLenum pname, GLint* params);
|
typedef void (*GLInfoFunction)(GLuint program, GLenum pname, GLint* params);
|
||||||
typedef void (*GLLogFunction) (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog);
|
typedef void (*GLLogFunction) (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog);
|
||||||
|
|
||||||
|
|
||||||
struct VertexAttrib
|
struct VertexAttrib
|
||||||
{
|
{
|
||||||
GLuint index;
|
GLuint index;
|
||||||
|
@ -333,8 +333,7 @@ protected:
|
||||||
void parseUniforms();
|
void parseUniforms();
|
||||||
|
|
||||||
bool compileShader(GLuint * shader, GLenum type, const GLchar* source);
|
bool compileShader(GLuint * shader, GLenum type, const GLchar* source);
|
||||||
std::string logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const;
|
|
||||||
|
|
||||||
GLuint _program;
|
GLuint _program;
|
||||||
GLuint _vertShader;
|
GLuint _vertShader;
|
||||||
GLuint _fragShader;
|
GLuint _fragShader;
|
||||||
|
|
Loading…
Reference in New Issue