def glGetActiveAttribARB(program, index): """ Retrieve the name, size and type of the uniform of the index in the program """ max_index = int(glGetObjectParameterivARB( program, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB )) length = int(glGetObjectParameterivARB( program, GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB)) if index < max_index and index >= 0 and length > 0: name = ctypes.create_string_buffer(length) size = arrays.GLintArray.zeros( (1,)) gl_type = arrays.GLuintArray.zeros( (1,)) base_glGetActiveAttribARB(program, index, length, None, size, gl_type, name) return name.value, size[0], gl_type[0] raise IndexError, 'index out of range from zero to %i' % (max_index - 1, )
def glGetActiveAttribARB(program, index): """ Retrieve the name, size and type of the uniform of the index in the program """ max_index = int( glGetObjectParameterivARB(program, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB)) length = int( glGetObjectParameterivARB(program, GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB)) if index < max_index and index >= 0 and length > 0: name = ctypes.create_string_buffer(length) size = arrays.GLintArray.zeros((1, )) gl_type = arrays.GLuintArray.zeros((1, )) base_glGetActiveAttribARB(program, index, length, None, size, gl_type, name) return name.value, size[0], gl_type[0] raise IndexError, 'index out of range from zero to %i' % (max_index - 1, )
def __init__(self, shaderName, shaderVertSrc, shaderFragSrc): # note: on any error, we set self.error, print a message, and return. # exceptions will be caught by caller and also set self.error, # but result in less specific printed error messages. # Configure the max constant RAM used for a "uniform" transforms block. if UNIFORM_XFORMS: global N_CONST_XFORMS oldNCX = N_CONST_XFORMS maxComponents = glGetInteger(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB) N_CONST_XFORMS = min( N_CONST_XFORMS, # Each matrix has 16 components. Leave slack for other vars too. (maxComponents - _VERTEX_SHADER_GPU_VAR_SLACK) / 16) if N_CONST_XFORMS <= 0: print ( "N_CONST_XFORMS not positive, is %d. %d max components." % (N_CONST_XFORMS, maxComponents)) # Now, we think this means we should use display lists instead. print "error: not enough shader constant memory" self.error = True return elif N_CONST_XFORMS == oldNCX: print ("N_CONST_XFORMS unchanged at %d. %d max components." % (N_CONST_XFORMS, maxComponents)) else: print ( "N_CONST_XFORMS changed to %d, was %d. %d max components." % (N_CONST_XFORMS, oldNCX, maxComponents)) pass pass # Version statement has to come first in GLSL source. prefix = """// requires GLSL version 1.20 #version 120 """ # Insert preprocessor constants before both shader source code strings # (using a constant number of lines, to preserve GLSL line numbers) if UNIFORM_XFORMS: prefix += "#define UNIFORM_XFORMS\n" prefix += "#define N_CONST_XFORMS %d\n" % N_CONST_XFORMS elif TEXTURE_XFORMS: prefix += "#define TEXTURE_XFORMS\n" prefix += "\n" else: prefix += "\n\n" pass # GLSL on the nVidia GeForce 7000 only supports constant array # subscripts, and subscripting by a loop index variable. if not debug_pref("GLPane: shaders with only constant subscripts?", Choice_boolean_True, prefs_key = True): prefix += "#define FULL_SUBSCRIPTING\n" else: prefix += "\n" # To keep the shader line numbers unchanged. pass if debug_pref("GLPane: simulate GLSL syntax error (next session)", Choice_boolean_False, prefs_key = True): prefix += "}\n" # remove whitespace before and after each prefix line [bruce 090306] prefix = '\n'.join( [line.strip() for line in prefix.split('\n')] ) assert prefix[-1] == '\n' # Pass the source strings to the shader compiler. self.vertShader = self.createShader(shaderName, GL_VERTEX_SHADER, prefix + shaderVertSrc) self.fragShader = self.createShader(shaderName, GL_FRAGMENT_SHADER, prefix + shaderFragSrc) if self.error: # May be set by createShader. return # Can't do anything good after an error. # Link the compiled shaders into a shader program. self.progObj = glCreateProgramObjectARB() glAttachObjectARB(self.progObj, self.vertShader) glAttachObjectARB(self.progObj, self.fragShader) try: glLinkProgramARB(self.progObj) # Checks status, raises error if bad. except: self.error = True print shaderName, "shader program link error" print glGetInfoLogARB(self.progObj) return # Can't do anything good after an error. # Optional, may be useful for debugging. glValidateProgramARB(self.progObj) status = glGetObjectParameterivARB(self.progObj, GL_VALIDATE_STATUS) if (not status): self.error = True print "Shader program validation error" print glGetInfoLogARB(self.progObj) return # Can't do anything good after an error. return