Thread: [PyOpenGL-Users] Checking Shader Errors
Brought to you by:
mcfletch
From: Ian M. <geo...@gm...> - 2009-04-19 00:44:24
|
Hi, I've got a great shader library, and it's nearly done. Unfortunately, certain custom functions have problems on ATI cards. I'm trying to add error reporting to get useful errors about it. Unfortunately, glGetShaderInfoLog() seems to fail. It works for me, with NVidia. This function: def CompileShader(source,shaderType): shader = glCreateShaderObjectARB(shaderType) glShaderSourceARB(shader,[source]) glCompileShaderARB(shader) return shader provides the "shader" that is passed as the argument to glGetShaderInfoLog(). I have no idea what's wrong, and I really need to have error reporting to debug this. Curiously, glGetInfoLogARB() seems to work fine, but it does not give useful errors (fragment shader failed to compile successfully before linking or some such). I tried using ctypes in ways like here<http://www.pygame.org/wiki/GLSLExample?parent=CookBook>or here <http://www.pygame.org/wiki/GLSL_ARB_Example?parent=CookBook>, but they don't work for either of us. I need errors. Help. Thanks, Ian |
From: Gijs <in...@bs...> - 2009-04-19 22:24:41
|
Ian Mallett wrote: > Hi, > > I've got a great shader library, and it's nearly done. Unfortunately, > certain custom functions have problems on ATI cards. I'm trying to > add error reporting to get useful errors about it. Unfortunately, > glGetShaderInfoLog() seems to fail. It works for me, with NVidia. > > This function: > > def CompileShader(source,shaderType): > shader = glCreateShaderObjectARB(shaderType) > glShaderSourceARB(shader,[source]) > glCompileShaderARB(shader) > return shader > > provides the "shader" that is passed as the argument to > glGetShaderInfoLog(). I have no idea what's wrong, and I really need > to have error reporting to debug this. > > Curiously, glGetInfoLogARB() seems to work fine, but it does not give > useful errors (fragment shader failed to compile successfully before > linking or some such). I tried using ctypes in ways like here > <http://www.pygame.org/wiki/GLSLExample?parent=CookBook> or here > <http://www.pygame.org/wiki/GLSL_ARB_Example?parent=CookBook>, but > they don't work for either of us. > > I need errors. Help. > > Thanks, > Ian Hey Ian, I made some error reporting code for my own stuff a while back. Maybe you can use some of it to see what is going wrong with your code. Regards, Gijs def compileShader(source, shader_type, shader_name): shader = glCreateShaderObjectARB(shader_type) glShaderSourceARB(shader, source) glCompileShaderARB(shader) status = glGetObjectParameterivARB(shader, GL_COMPILE_STATUS) if not status: printShaderLog(shader, shader_name) glDeleteObjectARB(shader) raise ValueError, 'Shader compilation failed' return shader def compileProgram(vertex_source, fragment_source, shader_name): vertex_shader = None fragment_shader = None program = glCreateProgramObjectARB() if (type(vertex_source) == str): vertex_source = [vertex_source] if (type(fragment_source) == str): fragment_source = [fragment_source] if vertex_source: vertex_shader = compileShader(vertex_source, GL_VERTEX_SHADER, shader_name) glAttachObjectARB(program, vertex_shader) if fragment_source: fragment_shader = compileShader(fragment_source, GL_FRAGMENT_SHADER, shader_name) glAttachObjectARB(program, fragment_shader) glLinkProgramARB(program) status = glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB) if not status: print >> sys.stderr, glGetInfoLogARB(program) raise ValueError, 'Failed to link shader ('+str(shader_name)+')' glValidateProgramARB(program) status = glGetObjectParameterivARB(program, GL_OBJECT_VALIDATE_STATUS_ARB) if not status: print >> sys.stderr, glGetInfoLogARB(program) raise ValueError, 'Failed to validate shader ('+str(shader_name)+')' if vertex_shader: glDeleteObjectARB(vertex_shader) if fragment_shader: glDeleteObjectARB(fragment_shader) if glGetObjectParameterivARB(program, GL_INFO_LOG_LENGTH) > 0: print ("Info log for shader '" + str(shader_name) + "':\n" + glGetInfoLogARB(program)) return program def printShaderLog(shader, shader_name): if glGetObjectParameterivARB(shader, GL_INFO_LOG_LENGTH) > 0: log = glGetInfoLogARB(shader) print >> sys.stderr, "Problem with shader '" + shader_name + "'" print >> sys.stderr, log else: print >> sys.stderr, "Problem with shader '" + shader_name + "', but no log is available" |
From: Ian M. <geo...@gm...> - 2009-04-20 17:10:22
|
Yes, this was basically what I came up with. The problem turns out to be that for gl_LightSource[n], n must be a literal int or const int. I'm not sure why this could be. Ideas? I solved the problem by passing the light source itself to the function. There's a few more other problems, but it's mostly done. Ian |
From: Gijs <in...@bs...> - 2009-04-20 17:58:52
|
Ian Mallett wrote: > Yes, this was basically what I came up with. > > The problem turns out to be that for gl_LightSource[n], n must be a > literal int or const int. I'm not sure why this could be. Ideas? > > I solved the problem by passing the light source itself to the function. > > There's a few more other problems, but it's mostly done. > > Ian I have run into a similar problem regarding indexes of arrays like these. I tried to index gl_FragColor using a variable. Something which the Mac OS X driver doesn't like at all. So I unrolled the for-loop and used const integers instead of variables. However, I only saw this problem when I was using my mac. In Windows and Linux it worked like a charm, both using the ATI 9.3 drivers. In Linux the 9.2 driver actually crashed when I used arrays like this. So I don't really know what your problem is, but it could be driver or videocard related. See if updating your drivers fixes any problems. Regards, Gijs |
From: Ian M. <geo...@gm...> - 2009-04-20 23:12:44
|
The driver is: 8.552.0.0 (10/28/08). I have gl_FragData[*n*] just for MRT purposes. Good to know about these issues though. Why *is* it an issue? Just to be annoying? Ian |
From: Gijs <in...@bs...> - 2009-04-21 08:01:43
|
Ian Mallett wrote: > The driver is: 8.552.0.0 (10/28/08). > I have gl_FragData[/n/] just for MRT purposes. Good to know about > these issues though. Why /is/ it an issue? Just to be annoying? > > Ian My guess it is a bug in the driver since other drivers have no issues with it at all (that I know of). And it wouldn't make sense either, to restrict the programmer to only use const integers to index language-specific arrays. Gijs |