fxmaker
Posts: 43
Joined: Fri Dec 07, 2012 6:37 pm

Shader compilation not reporting syntax error

Wed Dec 19, 2012 5:28 pm

Hi,

I'm a little baffled at the moment.

Given the (bad) vertex shader:

Code: Select all

attribute vec3 vertex_position;
attribute vec3 color_in;

uniform mat4 mvp_matrix;

varying vec3 color_out;

void main()
{
	gl_Position = mvp_matrix * vec4(vertex_position, 1.0);
	color_out = color_in OKDEOKEDOKEDOK; // Note blatant syntax error
}
And the compilation code including:

Code: Select all

	this->vertex_shader_id = glCreateShader(GL_VERTEX_SHADER);
	
	if (!this->LoadShader(vertex_shader_file, this->vertex_shader_id))
		return false;

	glCompileShader(this->vertex_shader_id);
	glGetShaderiv(this->vertex_shader_id, GL_COMPILE_STATUS, &check_value);

	if (check_value != GL_TRUE)
	{
		cerr << "GLSL compilation failed - vertex shader: " << vertex_shader_file << endl;
		this->GetShaderLog(vertex_shader_id);
		return false;
	}
GL_COMPILE_STATUS is returning GL_TRUE - that the purposefully bad shader compiled correctly.

Granted this is my first GLES work, but oughtn't the shader fail to compile?

Of course it doesn't actually work - mvp_matrix cannot be located.

LoadShader() is defined as:

Code: Select all

bool Shader::LoadShader(string file_name, GLuint shader_id)
{
	// This function is adapted from OpenGL 4.0 Shading Language Cookbook by David Wolff.

	assert(file_name.length() > 0);

	if (GLReturnedError("Shader::LoadShader() - on entrance"))
		return false;

	ifstream file(file_name.c_str(), ifstream::in);

	if (!file.is_open())
	{
		cerr <<  "Cannot open shader: " << file_name << endl;
		return false;
	}

	file.seekg (0, ios::end);
	streamsize length = file.tellg();
	file.seekg (0, ios::beg);

	GLubyte * buffer = new GLubyte[length + 1];
	file.read((char *) buffer, length);
	file.close();

	buffer[length] = 0;
	glShaderSource(shader_id, 1, (const char **) &buffer, NULL);

#ifdef DEBUG_SHADER
	cerr << "Shader::LoadShader(" << file_name.c_str() << ")" << endl;
	cerr << string((const char *) buffer).c_str() << endl;
	cerr << endl;
#endif // DEBUG_SHADER

	delete [] buffer;
	return !GLReturnedError("Shader::LoadShader() - on exit");
}


fxmaker
Posts: 43
Joined: Fri Dec 07, 2012 6:37 pm

Re: Shader compilation not reporting syntax error

Wed Dec 19, 2012 8:17 pm

Try as I might, including checking that the correct context was indeed current, I am not getting reports of shader compilation failures.

The only sign I am getting of an error is the inability to find uniforms (which is to be expected).

Does anyone know if the PI GLES stack reports shader compilation errors?

Thanks

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: Shader compilation not reporting syntax error

Thu Dec 20, 2012 10:04 am

I've been using the examples from the openGL ES 2.0 programming guide, and the wrapper they use certainly does report errors (I've seen a few :D )

https://github.com/benosteen/opengles-b ... esShader.c

HTH
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

fxmaker
Posts: 43
Joined: Fri Dec 07, 2012 6:37 pm

Re: Shader compilation not reporting syntax error

Thu Dec 20, 2012 2:37 pm

PeterO wrote:I've been using the examples from the openGL ES 2.0 programming guide, and the wrapper they use certainly does report errors (I've seen a few :D )

https://github.com/benosteen/opengles-b ... esShader.c

HTH
PeterO
Thank you Peter - I found the problem. OpenGL (or at least nVidia drivers) report errors during the compilation step. The PI GLES driver reports shader compilation errors during the link step.

Ported from OpenGL, my library code wasn't checking the linker for errors. I see them now too :P

Return to “OpenGLES”