Exemplo n.º 1
0
#! /usr/bin/env python3.6
from __future__ import print_function, division, absolute_import

import posix, posixpath, sys, re

if sys.version_info.major > 2:
    basestring = str

from PyQt5.QtCore import QCoreApplication, Qt
from PyQt5.QtGui import QSurfaceFormat

fmt = QSurfaceFormat.defaultFormat()
fmt.setProfile(QSurfaceFormat.CoreProfile)
fmt.setRedBufferSize(8)
fmt.setGreenBufferSize(8)
fmt.setBlueBufferSize(8)
fmt.setAlphaBufferSize(8)
fmt.setDepthBufferSize(24)
fmt.setStencilBufferSize(8)

version_str = posix.environ.get(b'AV_PLAYER_OGL_VERSION', None)
version = None
if version_str:
    try:
        match = version_re.match(version_str)
        if match:
            version = (int(match.group(1)), int(match.group(2)))
    except:
        pass

if version is None:
Exemplo n.º 2
0
def init_glcontext(ctx):
    ''' Correct OpenGL functions can only be obtained from a valid GL context. '''
    if getattr(gl, '__name__', '') != 'OpenGL.GL':
        # The OpenGL functions are provided by the Qt library. Update them from the current context
        fmt = QSurfaceFormat.defaultFormat()
        glprofile = QOpenGLVersionProfile(fmt)
        globals()['gl'] = ctx.versionFunctions(glprofile)

    # QtOpenGL doesn't wrap all necessary functions. We can do this manually

    # void glGetActiveUniformBlockName(	GLuint program,
    #                                   GLuint uniformBlockIndex,
    #                                   GLsizei bufSize,
    #                                   GLsizei * length,
    #                                   GLchar * uniformBlockName)

    funtype = ctypes.CFUNCTYPE(None, ctypes.c_uint32,
                               ctypes.c_uint32, ctypes.c_uint32,
                               ctypes.POINTER(ctypes.c_uint32),
                               ctypes.POINTER(ctypes.c_char * 20))
    funcptr = ctx.getProcAddress(b'glGetActiveUniformBlockName')
    c_getuboname = funtype(funcptr.__int__())

    def p_getuboname(programid, uboid):
        name = (ctypes.c_char * 20)()
        c_getuboname(programid, uboid, 20, None, ctypes.pointer(name))
        return name.value.decode('utf-8')

    gl.glGetActiveUniformBlockName = p_getuboname

    # void glGetActiveUniformBlockiv( GLuint program,
    #                                 GLuint uniformBlockIndex,
    #                                 GLenum pname,
    #                                 GLint * params)
    funtype = ctypes.CFUNCTYPE(None, ctypes.c_uint32, ctypes.c_uint32,
                               ctypes.c_uint32, ctypes.POINTER(ctypes.c_int32))
    funcptr = ctx.getProcAddress(b'glGetActiveUniformBlockiv')
    c_getuboiv = funtype(funcptr.__int__())

    def p_getuboiv(programid, uboid, pname):
        if pname == gl.GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
            # Special case: array with specific size is expected
            n_indices = ctypes.c_int32()
            c_getuboiv(programid, uboid, gl.GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS,
                       ctypes.pointer(n_indices))
            indices = (ctypes.c_int32 * n_indices.value)()
            # Apparently we need to specifically wrap depending on array size
            funtype = ctypes.CFUNCTYPE(
                None, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32,
                ctypes.POINTER(ctypes.c_int32 * n_indices.value))
            funcptr = ctx.getProcAddress(b'glGetActiveUniformBlockiv')
            c_getuboindices = funtype(funcptr.__int__())
            c_getuboindices(programid, uboid, pname, ctypes.pointer(indices))
            return list(indices)

        param = ctypes.c_int32()
        c_getuboiv(programid, uboid, pname, ctypes.pointer(param))
        return param.value

    gl.glGetActiveUniformBlockiv = p_getuboiv

    # void glVertexAttrib4Nub( GLuint index,
    #                          GLubyte v0,
    #                          GLubyte v1,
    #                          GLubyte v2,
    #                          GLubyte v3)
    funtype = ctypes.CFUNCTYPE(None, ctypes.c_uint32, ctypes.c_uint8,
                               ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint8)
    funcptr = ctx.getProcAddress(b'glVertexAttrib4Nub')
    gl.glVertexAttrib4Nub = funtype(funcptr.__int__())

    # void glTexImage2D( GLenum target,
    #                    GLint level,
    #                    GLint internalFormat,
    #                    GLsizei width,
    #                    GLsizei height,
    #                    GLint border,
    #                    GLenum format,
    #                    GLenum type,
    #                    const void * data)
    funtype = ctypes.CFUNCTYPE(None, ctypes.c_uint32, ctypes.c_int32,
                               ctypes.c_int32, ctypes.c_uint32,
                               ctypes.c_uint32, ctypes.c_int32,
                               ctypes.c_uint32, ctypes.c_uint32,
                               ctypes.c_void_p)
    funcptr = ctx.getProcAddress(b'glTexImage2D')
    gl.glTexImage2D_alt = funtype(funcptr.__int__())

    # void glTexSubImage2D(	GLenum target,
    #                       GLint level,
    #                       GLint xoffset,
    #                       GLint yoffset,
    #                       GLsizei width,
    #                       GLsizei height,
    #                       GLenum format,
    #                       GLenum type,
    #                       const void * pixels)
    funtype = ctypes.CFUNCTYPE(None, ctypes.c_uint32, ctypes.c_int32,
                               ctypes.c_int32, ctypes.c_int32, ctypes.c_uint32,
                               ctypes.c_uint32, ctypes.c_uint32,
                               ctypes.c_uint32, ctypes.c_void_p)
    funcptr = ctx.getProcAddress(b'glTexSubImage2D')
    gl.glTexSubImage2D_alt = funtype(funcptr.__int__())

    if getattr(gl, '__name__', '') == 'OpenGL.GL':
        # In case we are using PyOpenGL, get some of the functions to behave in the
        # same way as their counterparts in Qt
        glGetProgramiv_wrap = gl.glGetProgramiv

        def glGetProgramiv(program, pname):
            params = ctypes.c_int32()
            glGetProgramiv_wrap(program, pname, params)
            return params.value

        gl.glGetProgramiv = glGetProgramiv

        glGetActiveAttrib_wrap = gl.glGetActiveAttrib

        def glGetActiveAttrib(program, index):
            length = ctypes.c_int32()
            size = ctypes.c_int32()
            atype = ctypes.c_uint32()
            name = (ctypes.c_char * 20)()
            glGetActiveAttrib_wrap(program, index, 20, length, size, atype,
                                   ctypes.pointer(name))
            return name.value.decode('utf-8'), size.value, atype.value

        gl.glGetActiveAttrib = glGetActiveAttrib

        glGetActiveUniform_wrap = gl.glGetActiveUniform

        def glGetActiveUniform(program, index):
            length = ctypes.c_int32()
            size = ctypes.c_int32()
            atype = ctypes.c_uint32()
            name = (ctypes.c_char * 20)()
            glGetActiveUniform_wrap(program, index, 20, length, size, atype,
                                    ctypes.pointer(name))
            return name.value.decode('utf-8'), size.value, atype.value

        gl.glGetActiveUniform = glGetActiveUniform

        glTexSubImage3D_wrap = gl.glTexSubImage3D

        def glTexSubImage3D(target, level, xOffset, yOffset, zOffset, width,
                            height, depth, sourceFormat, sourceType, data):
            glTexSubImage3D_wrap(target, level, xOffset, yOffset, zOffset,
                                 width, height, depth, sourceFormat,
                                 sourceType, ctypes.c_void_p(int(data)))

        gl.glTexSubImage3D = glTexSubImage3D

        # The extended initialisation of the remaining GL functions in this function
        # is only required for Qt-provided GL functions
        return

    # GLuint glGetUniformBlockIndex( GLuint program,
    #                                const GLchar * uniformBlockName)
    funtype = ctypes.CFUNCTYPE(ctypes.c_uint32, ctypes.c_uint32,
                               ctypes.POINTER(ctypes.c_char))
    funcptr = ctx.getProcAddress(b'glGetUniformBlockIndex')
    c_getuboindex = funtype(funcptr.__int__())

    def p_getuboindex(programid, uboname):
        ret = c_getuboindex(programid,
                            ctypes.c_char_p(uboname.encode('utf-8')))
        return ret

    gl.glGetUniformBlockIndex = p_getuboindex

    # void glVertexAttribIPointer(GLuint index,
    #                             GLint size,
    #                             GLenum type,
    #                             GLsizei stride,
    #                             const void * pointer)

    funtype = ctypes.CFUNCTYPE(None, ctypes.c_uint32, ctypes.c_int32,
                               ctypes.c_uint32, ctypes.c_uint32,
                               ctypes.c_void_p)
    funcptr = ctx.getProcAddress(b'glVertexAttribIPointer')
    # c_getvapointer = funtype(funcptr.__int__())
    # def p_getvapointer(index, size, atype, normalized, stride, offset):
    #     norm = ctypes.c_bool(0)
    #     c_getvapointer(index, size, atype, norm, stride, offset)
    gl.glVertexAttribIPointer = funtype(funcptr.__int__())
Exemplo n.º 3
0
#! /usr/bin/env python3.6
from __future__ import print_function, division,  absolute_import

import posix,posixpath,sys, re

if sys.version_info.major > 2:
    basestring = str

from PyQt5.QtCore import QCoreApplication, Qt
from PyQt5.QtGui  import QSurfaceFormat

fmt = QSurfaceFormat.defaultFormat()
fmt.setProfile(QSurfaceFormat.CoreProfile)
fmt.setRedBufferSize(8);
fmt.setGreenBufferSize(8);
fmt.setBlueBufferSize(8);
fmt.setAlphaBufferSize(8);
fmt.setDepthBufferSize(24);
fmt.setStencilBufferSize(8);

version_str = posix.environ.get(b'AV_PLAYER_OGL_VERSION',None)
version = None
if version_str:
    try:
        match = version_re.match(version_str)
        if match:
            version = (int(match.group(1)),int(match.group(2)))
    except:
        pass

if version is None: