This commit is contained in:
halx99 2021-05-27 14:39:17 +08:00
parent 5a9fe68c35
commit 7d0395ee26
2 changed files with 12 additions and 11 deletions

View File

@ -56,21 +56,23 @@ void ShaderModuleGL::compileShader(ShaderStage stage, const std::string &source)
glGetShaderiv(_shader, GL_COMPILE_STATUS, &status);
if (!status)
{
cocos2d::log("cocos2d: ERROR: Failed to compile shader, detail: %s\n%s", getErrorLog(_shader), source.c_str());
GLint logLength = 0;
glGetShaderiv(_shader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 1) {
cocos2d::Data errorLog{};
glGetShaderInfoLog(_shader, logLength, nullptr, (char*) errorLog.resize(logLength));
cocos2d::log("cocos2d: ERROR: Failed to compile shader, detail: %s\n%s", errorLog.getBytes(), source.c_str());
}
else {
cocos2d::log("cocos2d: ERROR: Failed to compile shader without errors.");
}
deleteShader();
CCASSERT(false, "Shader compile failed!");
}
}
char* ShaderModuleGL::getErrorLog(GLuint shader) const
{
GLint logLength = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
char* log = (char*)malloc(sizeof(char) * logLength);
glGetShaderInfoLog(shader, logLength, nullptr, log);
return log;
}
void ShaderModuleGL::deleteShader()
{
if (_shader)

View File

@ -55,7 +55,6 @@ public:
private:
void compileShader(ShaderStage stage, const std::string& source);
char* getErrorLog(GLuint shader) const;
void deleteShader();
GLuint _shader = 0;