def parseOutput(output, lines) : ''' Parse error output lines from the GLSL reference compiler, map them to the original source code location and output an error message compatible with Xcode or VStudio ''' outLines = output.splitlines() for outLine in outLines : if outLine.startswith('ERROR: ') : # extract generated shader source column, line and message colStartIndex = 7 colEndIndex = outLine.find(':', colStartIndex) if colEndIndex == -1 : continue lineStartIndex = colEndIndex + 1 lineEndIndex = outLine.find(':', lineStartIndex) if lineEndIndex == -1 : continue msgStartIndex = lineEndIndex + 1 colNr = int(outLine[colStartIndex:colEndIndex]) lineNr = int(outLine[lineStartIndex:lineEndIndex]) msg = outLine[msgStartIndex:] # map to original location lineIndex = lineNr - 1 if lineIndex >= len(lines) : lineIndex = len(lines) - 1 srcPath = lines[lineIndex].path srcLineNr = lines[lineIndex].lineNumber # and output... util.setErrorLocation(srcPath, srcLineNr) util.fmtError(msg)
def resolveDeps(self, shd, dep): ''' Recursively resolve dependencies for a shader. ''' # just add new dependencies at the end of resolvedDeps, # and remove dups in a second pass after recursion if not dep.name in self.blocks: util.setErrorLocation(dep.path, dep.lineNumber) util.fmtError("unknown block dependency '{}'".format(dep.name)) shd.resolvedDeps.append(dep.name) for depdep in self.blocks[dep.name].dependencies: self.resolveDeps(shd, depdep)
def resolveDeps(self, shd, dep) : ''' Recursively resolve dependencies for a shader. ''' # just add new dependencies at the end of resolvedDeps, # and remove dups in a second pass after recursion if not dep.name in self.blocks : util.setErrorLocation(dep.path, dep.lineNumber) util.fmtError("unknown block dependency '{}'".format(dep.name)) shd.resolvedDeps.append(dep.name) for depdep in self.blocks[dep.name].dependencies : self.resolveDeps(shd, depdep)
def checkAddUniform(self, uniform, list): ''' Check if uniform already exists in list, if yes check if type and binding matches, if not write error. If uniform doesn't exist yet in list, add it. ''' listUniform = findByName(uniform.name, list) if listUniform is not None: # redundant uniform, check if type and binding name match if listUniform.type != uniform.type: util.setErrorLocation(uniform.filePath, uniform.lineNumber) util.fmtError( "uniform type mismatch '{}' vs '{}'".format( uniform.type, listUniform.type), False) util.setErrorLocation(listUniform.filePath, listUniform.lineNumber) util.fmtError("uniform type mismatch '{}' vs '{}'".format( listUniform.type, uniform.type)) if listUniform.bind != uniform.bind: util.setErrorLocation(uniform.filePath, uniform.lineNumber) util.fmtError( "uniform bind name mismatch '{}' vs '{}'".format( uniform.bind, listUniform.bind), False) util.setErrorLocation(listUniform.filePath, listUniform.lineNumber) util.fmtError("uniform bind name mismatch '{}' vs '{}'".format( listUniform.bind, uniform.bind)) else: # new uniform from block, add to list list.append(uniform)
def resolveBundleUniforms(self, bundle) : ''' Gathers all uniforms from all shaders in the bundle. ''' for program in bundle.programs : if program.vs not in self.vertexShaders : util.setErrorLocation(program.filePath, program.lineNumber) util.fmtError("unknown vertex shader '{}'".format(program.vs)) for uniform in self.vertexShaders[program.vs].uniforms : self.checkAddUniform(uniform, bundle.uniforms) if program.fs not in self.fragmentShaders : util.setErrorLocation(program.filePath, program.lineNumber) util.fmtError("unknown fragment shader '{}'".format(program.fs)) for uniform in self.fragmentShaders[program.fs].uniforms : self.checkAddUniform(uniform, bundle.uniforms)
def parseSource(self, fileName): ''' Parse a single file and populate shader lib ''' print '=> parsing {}'.format(fileName) f = open(fileName, 'r') self.fileName = fileName self.lineNumber = 0 for line in f: util.setErrorLocation(self.fileName, self.lineNumber) self.parseLine(line) self.lineNumber += 1 f.close() # all blocks must be closed if self.current is not None: util.fmtError('missing @end at end of file')
def parseSource(self, fileName) : ''' Parse a single file and populate shader lib ''' print '=> parsing {}'.format(fileName) f = open(fileName, 'r') self.fileName = fileName self.lineNumber = 0 for line in f : util.setErrorLocation(self.fileName, self.lineNumber) self.parseLine(line) self.lineNumber += 1 f.close() # all blocks must be closed if self.current is not None : util.fmtError('missing @end at end of file')
def checkAddUniform(self, uniform, list) : ''' Check if uniform already exists in list, if yes check if type and binding matches, if not write error. If uniform doesn't exist yet in list, add it. ''' listUniform = findByName(uniform.name, list) if listUniform is not None: # redundant uniform, check if type and binding name match if listUniform.type != uniform.type : util.setErrorLocation(uniform.filePath, uniform.lineNumber) util.fmtError("uniform type mismatch '{}' vs '{}'".format(uniform.type, listUniform.type), False) util.setErrorLocation(listUniform.filePath, listUniform.lineNumber) util.fmtError("uniform type mismatch '{}' vs '{}'".format(listUniform.type, uniform.type)) if listUniform.bind != uniform.bind : util.setErrorLocation(uniform.filePath, uniform.lineNumber) util.fmtError("uniform bind name mismatch '{}' vs '{}'".format(uniform.bind, listUniform.bind), False) util.setErrorLocation(listUniform.filePath, listUniform.lineNumber) util.fmtError("uniform bind name mismatch '{}' vs '{}'".format(listUniform.bind, uniform.bind)) else : # new uniform from block, add to list list.append(uniform)