Пример #1
0
 def resize(self, size):
     if self.size == size:
         return
     self.size = size
     glBindFramebuffer(GL_FRAMEBUFFER, self.fb_name)
     glBindRenderbuffer(GL_RENDERBUFFER, self.rb_name)
     glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, size.w, size.h)
     glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, self.rb_name)
     x = glCheckFramebufferStatus(GL_FRAMEBUFFER)
     if x != GL_FRAMEBUFFER_COMPLETE:
         raise RuntimeError("framebuffer incomplete: {}".format(glname.get(x,x)))
     glBindFramebuffer(GL_FRAMEBUFFER, 0)
Пример #2
0
def gldumplog(header = '', logger = None):
    if not bool(glGetDebugMessageLogARB):
        return
    if logger is None:
        logger = logging.getLogger('OpenGL.debug_output')

    count = 256
    logSize = 1048576
    sources = arrays.GLuintArray.zeros((count, ))
    types = arrays.GLuintArray.zeros((count, ))
    ids = arrays.GLuintArray.zeros((count, ))
    severities = arrays.GLuintArray.zeros((count, ))
    lengths = arrays.GLsizeiArray.zeros((count, ))
    messageLog = arrays.GLcharArray.zeros((logSize, ))

    num = glGetDebugMessageLogARB(count, logSize, sources, types, ids, severities, lengths, messageLog)
    offs = 0
    ldict = {
        GL_DEBUG_SEVERITY_HIGH_ARB : logger.error,
        GL_DEBUG_SEVERITY_MEDIUM_ARB : logger.warn,
        GL_DEBUG_SEVERITY_LOW_ARB : logger.info,
    }

    first = True
    for n in range(num):
        msg = bytes(messageLog[offs:offs+lengths[n]]).decode('utf-8')
        if first:
            glcalltrace("gldump({})".format(header))
            logger.info("gldump({})".format(header))
            first = False
        ldict.get(severities[n],logger.error)(
            "{} {} {} {} {}".format(
                glname.get(sources[n], sources[n]),
                glname.get(types[n], types[n]),
                glname.get(ids[n], ids[n]),
                glname.get(severities[n], severities[n]),
                msg))
        offs += lengths[n]
Пример #3
0
def texparams(target, callable = print):
    w = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH)
    h = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT)
    d = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_DEPTH)
    ifmt = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT)
    rt = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_RED_TYPE)
    bt = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_GREEN_TYPE)
    gt = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_BLUE_TYPE)
    at = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_ALPHA_TYPE)
    rsz = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_RED_SIZE)
    gsz = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_GREEN_SIZE)
    bsz = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_BLUE_SIZE)
    asz = glGetTexLevelParameteriv(target, 0, GL_TEXTURE_ALPHA_SIZE)
    min_f = glGetTexParameteriv(target, GL_TEXTURE_MIN_FILTER)
    max_f = glGetTexParameteriv(target, GL_TEXTURE_MAG_FILTER)
    wrap_s = glGetTexParameteriv(target, GL_TEXTURE_WRAP_S)
    wrap_t = glGetTexParameteriv(target, GL_TEXTURE_WRAP_T)
    callable(w,h,d,glname.get(ifmt))
    callable(glname.get(rt),glname.get(bt),glname.get(gt),glname.get(at),rsz,gsz,bsz,asz)
    callable(glname.get(min_f), glname.get(max_f), glname.get(wrap_s), glname.get(wrap_t))
Пример #4
0
    def __init__(self, sname=None):
        log_locs = logging.getLogger('fgt.shader.locs').info
        
        self.uloc = collections.defaultdict(lambda:-1)
        if sname is None:
            sname = self.sname
        vsfn = os.path.join(fgt.config.shaderpath, sname) + '.vs'
        fsfn = os.path.join(fgt.config.shaderpath, sname) + '.fs'
        prepend = list(map(lambda x: x+"\n", self.prepend))
        vsp = self._compile(prepend + open(vsfn, encoding='utf-8').readlines(), GL_VERTEX_SHADER, vsfn)
        fsp = self._compile(prepend + open(fsfn, encoding='utf-8').readlines(), GL_FRAGMENT_SHADER, fsfn)
        if not (vsp and fsp):
            raise SystemExit
        
        program = glCreateProgram()

        for shader in (vsp, fsp):
            glAttachShader(program, shader)
            glDeleteShader(shader)
            
        for name, loc in self.aloc.items():
            glBindAttribLocation(program, loc, name)
            log_locs("  vao{0}: name={1}".format(loc, name))
        glBindFragDataLocation(program, 0, b'frag')

        glLinkProgram(program)
    
        link_status = glGetProgramiv( program, GL_LINK_STATUS )
        if link_status == GL_FALSE:
            raise RuntimeError(
                """Link failure (%s): %s"""%(
                link_status,
                glGetProgramInfoLog( program ),
            ))
    
        self.uloc = collections.defaultdict(lambda:-1)
        au = glGetProgramiv(program, GL_ACTIVE_UNIFORMS)
        for i in range(au):
            name, wtf, typ = glGetActiveUniform(program, i)
            loc = glGetUniformLocation(program, name)
            self.uloc[name] = loc
            log_locs("  uni{0}: name={1} type={2} loc={3}".format(i, name, glname.get(typ, typ), loc))
        
        self.program = program
Пример #5
0
    def resize(self, size):
        if self.size == size:
            return
        self.size = size
        self.bytesize = size.w*size.h*4

        # [re]-init texture storage
        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, self.bo_name)
        glBufferData(GL_PIXEL_UNPACK_BUFFER, self.bytesize, ctypes.c_void_p(0), GL_STREAM_DRAW)
        glBindTexture(GL_TEXTURE_2D, self.tex_name)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, size.w, size.h, 0,
            GL_RGBA, GL_UNSIGNED_BYTE, ctypes.c_void_p(0))

        # attach the texture
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, self.fb_name)
        glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
            GL_TEXTURE_2D, self.tex_name, 0)

        # check completeness
        x = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)
        if x != GL_FRAMEBUFFER_COMPLETE:
            raise RuntimeError("framebuffer incomplete: {}".format(glname.get(x,x)))
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)