Ejemplo n.º 1
0
def createProgram(vertexShader, fragmentShader):
    program = bgl.glCreateProgram()
    bgl.glAttachShader(program, vertexShader)
    bgl.glAttachShader(program, fragmentShader)
    bgl.glLinkProgram(program)
    success = bgl.Buffer(bgl.GL_INT, [1])
    bgl.glGetProgramiv(program, bgl.GL_LINK_STATUS, success)
    #var success = gl.getProgramParameter(program, gl.LINK_STATUS);
    if (success[0] == bgl.GL_TRUE):
        print("shader link success")
        return program

    print("shader program linking failed")
    
    bgl.glGetProgramiv(program, bgl.GL_INFO_LOG_LENGTH, success)
    start = bgl.Buffer(bgl.GL_INT, [1])
    start[0] =0
    log = bgl.Buffer(bgl.GL_BYTE, [success[0]])
    bgl.glGetProgramInfoLog(program, success[0], start, log)
    py_log = log[:]
    py_log_str = ""
    for c in py_log:
        py_log_str += str(chr(c))
    print(str(py_log_str))
    bgl.glDeleteProgram(program)
Ejemplo n.º 2
0
def check_shaderError(shader, flag, isProgram, errorMessage):
    success = bgl.Buffer(bgl.GL_INT, 1)
    slen = 1024
    if isProgram:
        bgl.glGetProgramiv(shader, flag, success)
        check_error("glGetProgramiv")

    else:
        bgl.glGetShaderiv(shader, flag, success)
        check_error("glGetShaderiv")

    import numpy as np
    from .bgl_ext import VoidBufValue

    offset = VoidBufValue(None)
    error = bgl.Buffer(bgl.GL_BYTE, slen)

    if isProgram:
        bgl.glGetProgramInfoLog(shader, slen, offset.buf, error)
        check_error("glGetProgramInfoLog")
    else:
        bgl.glGetShaderInfoLog(shader, slen, offset.buf, error)
        check_error("glGetShaderInfoLog")

    print(np.bytes_(error).decode("utf-8"))

    del offset
    if success[0] != bgl.GL_TRUE:
        print(errorMessage, np.bytes_(error).decode("utf-8"))
        raise RuntimeError(errorMessage, error)
Ejemplo n.º 3
0
def create_program(*shaders):
    program = bgl.glCreateProgram()
    for shader in shaders:
        bgl.glAttachShader(program, shader)
    bgl.glLinkProgram(program)
    status = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGetProgramiv(program, bgl.GL_LINK_STATUS, status)
    if status[0] != bgl.GL_TRUE:
        infoLog = bgl.Buffer(bgl.GL_BYTE, 1024)
        length = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGetProgramInfoLog(program, 1024, length, infoLog)
        raise RuntimeError(''.join(chr(infoLog[i]) for i in range(length[0])))
    return program
Ejemplo n.º 4
0
def gl_link_error(msg, program):
    """
    Print OpenGL link errors, if any, for a given program.
    
    msg is an rbitrary human readable string
    program is an int (an OpenGL program name)
    """
    buf = bgl.Buffer(bgl.GL_INT,1)
    bgl.glGetProgramiv(program, bgl.GL_LINK_STATUS,buf)
    if buf[0] == bgl.GL_TRUE:
        return False
    err = buf[0]
    charbuf = bgl.Buffer(bgl.GL_BYTE,4000)
    lenbuf = bgl.Buffer(bgl.GL_INT,1)
    bgl.glGetProgramInfoLog(program,4000,lenbuf,charbuf)
    print('GL Error: %d (%s)\n%s'%(err, msg, "".join(map( chr, charbuf[:lenbuf[0]]))))
    return True
Ejemplo n.º 5
0
def check_shaderError(shader, flag, isProgram, errorMessage):
    success = bgl.Buffer(bgl.GL_INT, 1)

    if isProgram:
        bgl.glGetProgramiv(shader, flag, success)
    else:
        bgl.glGetShaderiv(shader, flag, success)

    if success[0] == bgl.GL_FALSE:
        import numpy as np
        import ctypes

        offset = bgl.Buffer(bgl.GL_INT, 1, (ctypes.c_int * 1).from_address(0))
        error = bgl.Buffer(bgl.GL_BYTE, 1024)
        if isProgram:
            bgl.glGetProgramInfoLog(shader, 1024, offset, error)
            print(errorMessage, np.bytes_(error).decode("utf-8"))
        else:
            bgl.glGetShaderInfoLog(shader, 1024, offset, error)
            print(errorMessage, np.bytes_(error).decode("utf-8"))

        del offset
        raise #RuntimeError(errorMessage, bgl.glGetShaderInfoLog(shader))
Ejemplo n.º 6
0
def check_shaderError(shader, flag, isProgram, errorMessage):
    success = bgl.Buffer(bgl.GL_INT, 1)

    if isProgram:
        bgl.glGetProgramiv(shader, flag, success)
    else:
        bgl.glGetShaderiv(shader, flag, success)

    if success[0] == bgl.GL_FALSE:
        import numpy as np
        from .bgl_ext import VoidBufValue

        offset = VoidBufValue(None)
        error = bgl.Buffer(bgl.GL_BYTE, 1024)
        if isProgram:
            bgl.glGetProgramInfoLog(shader, 1024, offset.buf, error)
            print(errorMessage, np.bytes_(error).decode("utf-8"))
        else:
            bgl.glGetShaderInfoLog(shader, 1024, offset.buf, error)
            print(errorMessage, np.bytes_(error).decode("utf-8"))

        del offset
        raise #RuntimeError(errorMessage, bgl.glGetShaderInfoLog(shader))
Ejemplo n.º 7
0
def check_shaderError(shader, flag, isProgram, errorMessage):
    success = bgl.Buffer(bgl.GL_INT, 1)

    if isProgram:
        bgl.glGetProgramiv(shader, flag, success)
    else:
        bgl.glGetShaderiv(shader, flag, success)

    if success[0] == bgl.GL_FALSE:
        import numpy as np
        import ctypes

        offset = bgl.Buffer(bgl.GL_INT, 1, (ctypes.c_int32 * 1).from_address(0))
        error = bgl.Buffer(bgl.GL_BYTE, 1024)
        if isProgram:
            bgl.glGetProgramInfoLog(shader, 1024, offset, error)
            print(errorMessage, np.bytes_(error).decode("utf-8"))
        else:
            bgl.glGetShaderInfoLog(shader, 1024, offset, error)
            print(errorMessage, np.bytes_(error).decode("utf-8"))

        del offset
        raise #RuntimeError(errorMessage, bgl.glGetShaderInfoLog(shader))