Error Log vs Shader Info Log


#1

glGetError() - ‘error log’
glGetShaderInfoLog () - ‘shader info log’

When there is a bug in the shader, the error message appears in the shader info log instead of the error log. why is this?

In my shader, I made a deliberate syntactical error by missing out the semicolon at the end of a line; gl_Position = u_MVP * position After compiling the shader, glGetError() returns 0, but then when the compile status is checked via glGetShaderiv(), GL_FALSE is returned with this message:

“ERROR: 0:11: ‘}’ : syntax error syntax error”

Is there a particular reason why this error appears in the shader info log as opposed to the error log?

    while(glGetError != 0); // clear any pre-existing errors

	glCompileShader(VertexShader);

	unsigned int error = glGetError();
	if(error != 0)
		std::cout << "OpenGL Error: " << error << std::endl;
	else
	{
		int succeeded;
		glGetShaderiv(VertexShader, GL_COMPILE_STATUS, &succeeded)
		if(!succeeded)
		{
			std::cout << "Failed to compile vertex shader\n";
			int buf_size;
			GLCall(glGetShaderiv(VertexShader, GL_INFO_LOG_LENGTH, &buf_size));
			std::vector<char> vec(buf_size);
			GLCall(glGetShaderInfoLog(VertexShader, buf_size, nullptr, &vec[0]));
			for (auto v : vec)
				std::cout << v;
		}
	}

#2

Shader and compilation errors are far too complex to be a mere error code. All the error code could possibly be is GL_COMPILE_LINK_ERROR, which tells you nothing of value. You’re going to have to get a textual info-log to be able to do anything about the error, so the compile/link error mechanism is built into the shader/program objects.

Put it another way: would you prefer your compiler to give you an “Error code 21” error, or an “ERROR: 0:11: ‘}’ : syntax error syntax error” error? Which is more informative?


#3

Put it another way: would you prefer your compiler to give you an “Error code 21” error, or an “ERROR: 0:11: ‘}’ : syntax error syntax error” error? Which is more informative?

Yes definitely the latter. Thanks for that information Alfonso