예제 #1
0
def errcheck(result, func, arguments):
    if _debug_gl_trace:
        try:
            name = func.__name__
        except AttributeError:
            name = repr(func)
        if _debug_gl_trace_args:
            trace_args = ', '.join([repr(arg)[:20] for arg in arguments])
            print('%s(%s)' % (name, trace_args))
        else:
            print(name)

    from pyglet import gl
    context = gl.current_context
    if not context:
        raise GLException('No GL context; create a Window first')
    error = gl.glGetError()
    if error:
        # These are the 6 possible error codes we can get in opengl core 3.3+
        error_types = {
            gl.GL_INVALID_ENUM:
            "Invalid enum. An unacceptable value is specified for an enumerated argument.",
            gl.GL_INVALID_VALUE:
            "Invalid value. A numeric argument is out of range.",
            gl.GL_INVALID_OPERATION:
            "Invalid operation. The specified operation is not allowed in the current state.",
            gl.GL_INVALID_FRAMEBUFFER_OPERATION:
            "Invalid framebuffer operation. The framebuffer object is not complete.",
            gl.GL_OUT_OF_MEMORY:
            "Out of memory. There is not enough memory left to execute the command.",
        }
        msg = error_types.get(error, "Unknown error")
        raise GLException('(0x%x): %s' % (error, msg))
    return result
예제 #2
0
파일: lib.py 프로젝트: tkrym02/anaconda
def errcheck(result=None, func=None, arguments=None):
    if _debug_gl_trace:
        try:
            name = func.__name__
        except AttributeError:
            name = repr(func)
        if _debug_gl_trace_args:
            trace_args = ', '.join([repr(arg)[:20] for arg in arguments])
            print '%s(%s)' % (name, trace_args)
        else:
            print name

    from pyglet import gl
    context = gl.current_context
    if not context:
        raise GLException('No GL context; create a Window first')
    if not context._gl_begin:
        error = gl.glGetError()
        # special cases
        if error:
            msg = (ctypes.cast(gl.gluErrorString(error), ctypes.c_char_p).value
                   or ('Error %s' % error))
            try:
                msg += ' (%s %s)' % (func.name, arguments)
            except AttributeError:
                msg += ' (%s)' % (func)
            raise GLException(msg)
        return result
예제 #3
0
파일: lib.py 프로젝트: Matt-Esch/anaconda
def errcheck(result = None, func = None, arguments = None):
    if _debug_gl_trace:
        try:
            name = func.__name__
        except AttributeError:
            name = repr(func)
        if _debug_gl_trace_args:
            trace_args = ', '.join([repr(arg)[:20] for arg in arguments])
            print '%s(%s)' % (name, trace_args)
        else:
            print name

    from pyglet import gl
    context = gl.current_context
    if not context:
        raise GLException('No GL context; create a Window first')
    if not context._gl_begin:
        error = gl.glGetError()
        # special cases
        if error:
            msg = (ctypes.cast(gl.gluErrorString(error), ctypes.c_char_p).value
                   or ('Error %s' % error))
            try:
                msg += ' (%s %s)' % (func.name, arguments)
            except AttributeError:
                msg += ' (%s)' % (func)
            raise GLException(msg)
        return result
예제 #4
0
 def my_errcheck(result, func, arguments):
     from pyglet import gl
     error = gl.glGetError()
     if error and error != 1286:
         # HACK: The 1286(INVALID_FRAMEBUFFER_OPERATION) error again!
         # This time I DIDN'T EVEN USE FBO! ATI!!
         msg = ctypes.cast(gl.gluErrorString(error), ctypes.c_char_p).value
         raise gl.GLException((error, msg))
     return result
예제 #5
0
 def my_errcheck(result, func, arguments):
     from pyglet import gl
     error = gl.glGetError()
     if error and error != 1286:
         # HACK: The 1286(INVALID_FRAMEBUFFER_OPERATION) error again!
         # This time I DIDN'T EVEN USE FBO! ATI!!
         msg = ctypes.cast(gl.gluErrorString(error), ctypes.c_char_p).value
         raise gl.GLException((error, msg))
     return result
예제 #6
0
def errcheck(result, func, arguments):
    from pyglet.gl import get_current_context
    context = get_current_context()
    if not context:
        raise GLException('No GL context; create a Window first')
    if not context._gl_begin:
        from pyglet.gl import glGetError, gluErrorString
        error = glGetError()
        if error:
            message = ctypes.cast(gluErrorString(error), ctypes.c_char_p).value
            raise GLException(message)
        return result
예제 #7
0
파일: lib.py 프로젝트: certik/sympy-oldcore
def errcheck(result, func, arguments):
    from pyglet.gl import get_current_context
    context = get_current_context()
    if not context:
        raise GLException('No GL context; create a Window first')
    if not context._gl_begin:
        from pyglet.gl import glGetError, gluErrorString
        error = glGetError()
        if error:
            message = ctypes.cast(gluErrorString(error), ctypes.c_char_p).value
            raise GLException(message)
        return result
예제 #8
0
    def error(self) -> Union[str, None]:
        """Check OpenGL error

        Returns a string representation of the occurring error
        or ``None`` of no errors has occurred.

        Example::

            err = ctx.error
            if err:
                raise RuntimeError("OpenGL error: {err}")

        :type: str
        """
        err = gl.glGetError()
        if err == gl.GL_NO_ERROR:
            return None

        return self._errors.get(err, "GL_UNKNOWN_ERROR")
예제 #9
0
def errcheck(result, func, arguments):
    if _debug_gl_trace:
        try:
            name = func.__name__
        except AttributeError:
            name = repr(func)
        if _debug_gl_trace_args:
            trace_args = ', '.join([repr(arg)[:20] for arg in arguments])
            print('%s(%s)' % (name, trace_args))
        else:
            print(name)

    from pyglet import gl
    context = gl.current_context
    if not context:
        raise GLException('No GL context; create a Window first')
    error = gl.glGetError()
    if error:
        msg = ctypes.cast(gl.gluErrorString(error), ctypes.c_char_p).value
        raise GLException(msg)
    return result
예제 #10
0
파일: lib.py 프로젝트: cajlarsson/village
def errcheck(result, func, arguments):
    if _debug_gl_trace:
        try:
            name = func.__name__
        except AttributeError:
            name = repr(func)
        if _debug_gl_trace_args:
            trace_args = ', '.join([repr(arg)[:20] for arg in arguments])
            print('%s(%s)' % (name, trace_args))
        else:
            print(name)

    from pyglet import gl
    context = gl.current_context
    if not context:
        raise GLException('No GL context; create a Window first')
    if not context._gl_begin:
        error = gl.glGetError()
        if error:
            msg = ctypes.cast(gl.gluErrorString(error), ctypes.c_char_p).value
            raise GLException(msg)
        return result
예제 #11
0
    def add_texture(self, shape, dtype=gl.GL_FLOAT):
        """Add texture image to the framebuffer object.

        Parameters
        ----------
        shape : tuple of ints
            Dimension of framebuffer.  Note that for earlier versions
            of OpenGL, height and width dimensions must be a power of
            two.  Valid shapes include (16,), (16, 17), (16, 16, 3).
        dtype : opengl data-type, e.g. GL_FLOAT, GL_UNSIGNED_BYTE

        Returns
        -------
        slot : int
            The slot number to which the texture was bound.  E.g., in the
            case of GL_COLOR_ATTACHMENT3_EXT, returns 3.

        """
        if dtype != gl.GL_FLOAT:
            warnings.warn("While OpenGL < 3.0 implementations allow the "
                          "storage of textures with data-types other "
                          "than FLOAT, gl_FragColor only accepts "
                          "assigned a floating point value.  In OpenGL 3.0 "
                          "this can be changed (see READING.txt).",
                          RuntimeWarning)

        if len(self._textures) >= MAX_COLOR_ATTACHMENTS:
            raise RuntimeError("Maximum number of textures reached.  This "
                               "platform supports %d attachments." % \
                               MAX_COLOR_ATTACHMENTS)

        slot = getattr(gl, "GL_COLOR_ATTACHMENT%d_EXT" % len(self._textures))

        width, height, bands = _shape_to_3d(shape)

        if bands > 4:
            raise ValueError("Texture cannot have more than 4 colour layers.")

        colour_bands = {1: gl.GL_LUMINANCE,
                        2: gl.GL_LUMINANCE_ALPHA,
                        3: gl.GL_RGB,
                        4: gl.GL_RGBA}

        # allocate a texture and add to the frame buffer
        tex = Texture(width, height,
                      format=colour_bands[bands],
                      dtype=dtype,
                      internalformat=gl.GL_RGB32F_ARB,
                      )

        gl.glBindTexture(tex.target, tex.id)
        gl.glFramebufferTexture2DEXT(gl.GL_FRAMEBUFFER_EXT,
                                     gl.GL_COLOR_ATTACHMENT0_EXT,
                                     tex.target, tex.id, 0)
        if (gl.glGetError() != gl.GL_NO_ERROR):
            raise RuntimeError("Could not create framebuffer texture.")

        status = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT)
        if not (status == gl.GL_FRAMEBUFFER_COMPLETE_EXT):
            raise RuntimeError("Could not set up framebuffer.")

        self._textures.append(tex)
        return len(self._textures) - 1