/* Generated by Cython 0.12 on Sun Aug  1 13:01:10 2010 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#else
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
#endif
#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
       void *buf;
       PyObject *obj;
       Py_ssize_t len;
       Py_ssize_t itemsize;
       int readonly;
       int ndim;
       char *format;
       Py_ssize_t *shape;
       Py_ssize_t *strides;
       Py_ssize_t *suboffsets;
       void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyString_Type                PyUnicode_Type
  #define PyString_CheckExact          PyUnicode_CheckExact
#else
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_CheckExact           PyString_CheckExact
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#else
  #define _USE_MATH_DEFINES
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#define __PYX_HAVE_API___renpy_pysdlgl
#include "pygame/pygame.h"
#include "GL/glew.h"

#ifdef __GNUC__
#define INLINE __inline__
#elif _WIN32
#define INLINE __inline
#else
#define INLINE 
#endif

typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#if PY_MAJOR_VERSION < 3
#define __Pyx_PyBytes_FromString          PyString_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyString_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyString_AsString
#else
#define __Pyx_PyBytes_FromString          PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyBytes_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyBytes_AsString
#endif

#define __Pyx_PyBytes_FromUString(s)      __Pyx_PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)        ((unsigned char*) __Pyx_PyBytes_AsString(s))

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

#if !defined(T_PYSSIZET)
#if PY_VERSION_HEX < 0x02050000
#define T_PYSSIZET T_INT
#elif !defined(T_LONGLONG)
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))  ? T_INT  : \
        ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1))
#else
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))          ? T_INT      : \
        ((sizeof(Py_ssize_t) == sizeof(long))         ? T_LONG     : \
        ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1)))
#endif
#endif


#if !defined(T_ULONGLONG)
#define __Pyx_T_UNSIGNED_INT(x) \
        ((sizeof(x) == sizeof(unsigned char))  ? T_UBYTE : \
        ((sizeof(x) == sizeof(unsigned short)) ? T_USHORT : \
        ((sizeof(x) == sizeof(unsigned int))   ? T_UINT : \
        ((sizeof(x) == sizeof(unsigned long))  ? T_ULONG : -1))))
#else
#define __Pyx_T_UNSIGNED_INT(x) \
        ((sizeof(x) == sizeof(unsigned char))  ? T_UBYTE : \
        ((sizeof(x) == sizeof(unsigned short)) ? T_USHORT : \
        ((sizeof(x) == sizeof(unsigned int))   ? T_UINT : \
        ((sizeof(x) == sizeof(unsigned long))  ? T_ULONG : \
        ((sizeof(x) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))))
#endif
#if !defined(T_LONGLONG)
#define __Pyx_T_SIGNED_INT(x) \
        ((sizeof(x) == sizeof(char))  ? T_BYTE : \
        ((sizeof(x) == sizeof(short)) ? T_SHORT : \
        ((sizeof(x) == sizeof(int))   ? T_INT : \
        ((sizeof(x) == sizeof(long))  ? T_LONG : -1))))
#else
#define __Pyx_T_SIGNED_INT(x) \
        ((sizeof(x) == sizeof(char))  ? T_BYTE : \
        ((sizeof(x) == sizeof(short)) ? T_SHORT : \
        ((sizeof(x) == sizeof(int))   ? T_INT : \
        ((sizeof(x) == sizeof(long))  ? T_LONG : \
        ((sizeof(x) == sizeof(PY_LONG_LONG))   ? T_LONGLONG : -1)))))
#endif

#define __Pyx_T_FLOATING(x) \
        ((sizeof(x) == sizeof(float)) ? T_FLOAT : \
        ((sizeof(x) == sizeof(double)) ? T_DOUBLE : -1))

#if !defined(T_SIZET)
#if !defined(T_ULONGLONG)
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))  ? T_UINT  : \
        ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1))
#else
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))          ? T_UINT      : \
        ((sizeof(size_t) == sizeof(unsigned long))         ? T_ULONG     : \
        ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))
#endif
#endif

static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 ||               (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
static const char **__pyx_f;


/* Type declarations */

#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif

#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
  end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
  }
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  #define __Pyx_RefNannyFinishContext()           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
  #define __Pyx_RefNannySetupContext(name)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name, PyObject* kw_name); /*proto*/

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/


static INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}


#define __Pyx_GetItemInt_List(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}

#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}


#define __Pyx_GetItemInt(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    PyObject *r;
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
        r = PySequence_GetItem(o, i);
    }
    else {
        r = __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
    }
    return r;
}

static INLINE long __Pyx_div_long(long, long); /* proto */

static INLINE PyObject *__Pyx_PyInt_to_py_GLenum(GLenum);

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static INLINE GLenum __Pyx_PyInt_from_py_GLenum(PyObject *);

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static INLINE GLsizei __Pyx_PyInt_from_py_GLsizei(PyObject *);

static INLINE GLuint __Pyx_PyInt_from_py_GLuint(PyObject *);

static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static INLINE char __Pyx_PyInt_AsChar(PyObject *);

static INLINE short __Pyx_PyInt_AsShort(PyObject *);

static INLINE int __Pyx_PyInt_AsInt(PyObject *);

static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static INLINE long __Pyx_PyInt_AsLong(PyObject *);

static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from _renpy_pysdlgl */

#define __Pyx_MODULE_NAME "_renpy_pysdlgl"
int __pyx_module_is_main__renpy_pysdlgl = 0;

/* Implementation of _renpy_pysdlgl */
static PyObject *__pyx_builtin_Exception;
static char __pyx_k_1[] = "Glew init failed: %s";
static char __pyx_k_2[] = "premultiply (line 103)";
static char __pyx_k_3[] = "store_framebuffer (line 247)";
static char __pyx_k_4[] = "draw_rectangle (line 276)";
static char __pyx_k__h[] = "h";
static char __pyx_k__w[] = "w";
static char __pyx_k__x[] = "x";
static char __pyx_k__y[] = "y";
static char __pyx_k__sx[] = "sx";
static char __pyx_k__sy[] = "sy";
static char __pyx_k__xdx[] = "xdx";
static char __pyx_k__xdy[] = "xdy";
static char __pyx_k__ydx[] = "ydx";
static char __pyx_k__ydy[] = "ydy";
static char __pyx_k__data[] = "data";
static char __pyx_k__tex0[] = "tex0";
static char __pyx_k__tex1[] = "tex1";
static char __pyx_k__tex2[] = "tex2";
static char __pyx_k__xadd[] = "xadd";
static char __pyx_k__xmul[] = "xmul";
static char __pyx_k__yadd[] = "yadd";
static char __pyx_k__ymul[] = "ymul";
static char __pyx_k__pitch[] = "pitch";
static char __pyx_k__tex0x[] = "tex0x";
static char __pyx_k__tex0y[] = "tex0y";
static char __pyx_k__tex1x[] = "tex1x";
static char __pyx_k__tex1y[] = "tex1y";
static char __pyx_k__tex2x[] = "tex2x";
static char __pyx_k__tex2y[] = "tex2y";
static char __pyx_k__width[] = "width";
static char __pyx_k__format[] = "format";
static char __pyx_k__height[] = "height";
static char __pyx_k__number[] = "number";
static char __pyx_k__pixels[] = "pixels";
static char __pyx_k__pysurf[] = "pysurf";
static char __pyx_k__update[] = "update";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__Exception[] = "Exception";
static char __pyx_k__get_masks[] = "get_masks";
static char __pyx_k__transform[] = "transform";
static char __pyx_k__border_top[] = "border_top";
static char __pyx_k__border_left[] = "border_left";
static char __pyx_k__premultiply[] = "premultiply";
static char __pyx_k__border_right[] = "border_right";
static char __pyx_k__border_bottom[] = "border_bottom";
static char __pyx_k__draw_rectangle[] = "draw_rectangle";
static char __pyx_k__store_framebuffer[] = "store_framebuffer";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_u_2;
static PyObject *__pyx_kp_u_3;
static PyObject *__pyx_kp_u_4;
static PyObject *__pyx_n_s__Exception;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s__border_bottom;
static PyObject *__pyx_n_s__border_left;
static PyObject *__pyx_n_s__border_right;
static PyObject *__pyx_n_s__border_top;
static PyObject *__pyx_n_s__data;
static PyObject *__pyx_n_s__draw_rectangle;
static PyObject *__pyx_n_s__format;
static PyObject *__pyx_n_s__get_masks;
static PyObject *__pyx_n_s__h;
static PyObject *__pyx_n_s__height;
static PyObject *__pyx_n_s__number;
static PyObject *__pyx_n_s__pitch;
static PyObject *__pyx_n_s__pixels;
static PyObject *__pyx_n_s__premultiply;
static PyObject *__pyx_n_s__pysurf;
static PyObject *__pyx_n_s__store_framebuffer;
static PyObject *__pyx_n_s__sx;
static PyObject *__pyx_n_s__sy;
static PyObject *__pyx_n_s__tex0;
static PyObject *__pyx_n_s__tex0x;
static PyObject *__pyx_n_s__tex0y;
static PyObject *__pyx_n_s__tex1;
static PyObject *__pyx_n_s__tex1x;
static PyObject *__pyx_n_s__tex1y;
static PyObject *__pyx_n_s__tex2;
static PyObject *__pyx_n_s__tex2x;
static PyObject *__pyx_n_s__tex2y;
static PyObject *__pyx_n_s__transform;
static PyObject *__pyx_n_s__update;
static PyObject *__pyx_n_s__w;
static PyObject *__pyx_n_s__width;
static PyObject *__pyx_n_s__x;
static PyObject *__pyx_n_s__xadd;
static PyObject *__pyx_n_s__xdx;
static PyObject *__pyx_n_s__xdy;
static PyObject *__pyx_n_s__xmul;
static PyObject *__pyx_n_s__y;
static PyObject *__pyx_n_s__yadd;
static PyObject *__pyx_n_s__ydx;
static PyObject *__pyx_n_s__ydy;
static PyObject *__pyx_n_s__ymul;

/* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":96
 * 
 * 
 * def init_glew():             # <<<<<<<<<<<<<<
 *     err = glewInit()
 * 
 */

static PyObject *__pyx_pf_14_renpy_pysdlgl_init_glew(PyObject *__pyx_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_14_renpy_pysdlgl_init_glew(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_v_err;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  GLenum __pyx_t_4;
  __Pyx_RefNannySetupContext("init_glew");
  __pyx_self = __pyx_self;
  __pyx_v_err = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":97
 * 
 * def init_glew():
 *     err = glewInit()             # <<<<<<<<<<<<<<
 * 
 *     if err != GLEW_OK:
 */
  __pyx_t_1 = __Pyx_PyInt_to_py_GLenum(glewInit()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_err);
  __pyx_v_err = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":99
 *     err = glewInit()
 * 
 *     if err != GLEW_OK:             # <<<<<<<<<<<<<<
 *         raise Exception("Glew init failed: %s" % <char *> glewGetErrorString(err))
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_to_py_GLenum(GLEW_OK); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_err, __pyx_t_1, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":100
 * 
 *     if err != GLEW_OK:
 *         raise Exception("Glew init failed: %s" % <char *> glewGetErrorString(err))             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_4 = __Pyx_PyInt_from_py_GLenum(__pyx_v_err); if (unlikely((__pyx_t_4 == (GLenum)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyBytes_FromString(((char *)glewGetErrorString(__pyx_t_4))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_builtin_Exception, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_renpy_pysdlgl.init_glew");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_err);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":103
 * 
 * 
 * def premultiply(             # <<<<<<<<<<<<<<
 *     object pysurf,
 *     int x,
 */

static PyObject *__pyx_pf_14_renpy_pysdlgl_premultiply(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14_renpy_pysdlgl_premultiply[] = "\n    Creates a string containing the premultiplied image data for\n    for the (x, y, w, h) box inside pysurf. The various border_\n    parameters control the addition of a border on the sides.\n    ";
static PyObject *__pyx_pf_14_renpy_pysdlgl_premultiply(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysurf = 0;
  int __pyx_v_x;
  int __pyx_v_y;
  int __pyx_v_w;
  int __pyx_v_h;
  PyObject *__pyx_v_border_left = 0;
  PyObject *__pyx_v_border_top = 0;
  PyObject *__pyx_v_border_right = 0;
  PyObject *__pyx_v_border_bottom = 0;
  unsigned char __pyx_v_alpha_and;
  unsigned char __pyx_v_alpha_or;
  unsigned char *__pyx_v_null;
  PyObject *__pyx_v_rv;
  unsigned char *__pyx_v_out;
  unsigned char *__pyx_v_pixels;
  struct SDL_Surface *__pyx_v_surf;
  unsigned char *__pyx_v_p;
  unsigned char *__pyx_v_op;
  unsigned char *__pyx_v_pend;
  unsigned int __pyx_v_a;
  unsigned int *__pyx_v_pp;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  unsigned char *__pyx_t_4;
  int __pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__pysurf,&__pyx_n_s__x,&__pyx_n_s__y,&__pyx_n_s__w,&__pyx_n_s__h,&__pyx_n_s__border_left,&__pyx_n_s__border_top,&__pyx_n_s__border_right,&__pyx_n_s__border_bottom,0};
  __Pyx_RefNannySetupContext("premultiply");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[9] = {0,0,0,0,0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
      case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
      case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pysurf);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("premultiply", 1, 9, 9, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("premultiply", 1, 9, 9, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__w);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("premultiply", 1, 9, 9, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__h);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("premultiply", 1, 9, 9, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  5:
      values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__border_left);
      if (likely(values[5])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("premultiply", 1, 9, 9, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  6:
      values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__border_top);
      if (likely(values[6])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("premultiply", 1, 9, 9, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  7:
      values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__border_right);
      if (likely(values[7])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("premultiply", 1, 9, 9, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  8:
      values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__border_bottom);
      if (likely(values[8])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("premultiply", 1, 9, 9, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "premultiply") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysurf = values[0];
    __pyx_v_x = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_x == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_y = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_y == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_w = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_w == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_h = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_h == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_border_left = values[5];
    __pyx_v_border_top = values[6];
    __pyx_v_border_right = values[7];
    __pyx_v_border_bottom = values[8];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 9) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysurf = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_x = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_x == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_y = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_y == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_w = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_w == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_h = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 4)); if (unlikely((__pyx_v_h == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_border_left = PyTuple_GET_ITEM(__pyx_args, 5);
    __pyx_v_border_top = PyTuple_GET_ITEM(__pyx_args, 6);
    __pyx_v_border_right = PyTuple_GET_ITEM(__pyx_args, 7);
    __pyx_v_border_bottom = PyTuple_GET_ITEM(__pyx_args, 8);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("premultiply", 1, 9, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy_pysdlgl.premultiply");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_pysurf);
  __Pyx_INCREF(__pyx_v_border_left);
  __Pyx_INCREF(__pyx_v_border_top);
  __Pyx_INCREF(__pyx_v_border_right);
  __Pyx_INCREF(__pyx_v_border_bottom);
  __pyx_v_rv = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":121
 *     cdef unsigned char alpha_or
 * 
 *     if pysurf.get_masks()[3]:             # <<<<<<<<<<<<<<
 *         alpha_and = 255
 *         alpha_or = 0
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_pysurf, __pyx_n_s__get_masks); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 3, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":122
 * 
 *     if pysurf.get_masks()[3]:
 *         alpha_and = 255             # <<<<<<<<<<<<<<
 *         alpha_or = 0
 *     else:
 */
    __pyx_v_alpha_and = 255;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":123
 *     if pysurf.get_masks()[3]:
 *         alpha_and = 255
 *         alpha_or = 0             # <<<<<<<<<<<<<<
 *     else:
 *         alpha_and = 0
 */
    __pyx_v_alpha_or = 0;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":125
 *         alpha_or = 0
 *     else:
 *         alpha_and = 0             # <<<<<<<<<<<<<<
 *         alpha_or = 255
 * 
 */
    __pyx_v_alpha_and = 0;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":126
 *     else:
 *         alpha_and = 0
 *         alpha_or = 255             # <<<<<<<<<<<<<<
 * 
 *     # Allocate an uninitialized string.
 */
    __pyx_v_alpha_or = 255;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":129
 * 
 *     # Allocate an uninitialized string.
 *     cdef unsigned char *null = NULL             # <<<<<<<<<<<<<<
 *     rv = null[:w*h*4]
 * 
 */
  __pyx_v_null = NULL;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":130
 *     # Allocate an uninitialized string.
 *     cdef unsigned char *null = NULL
 *     rv = null[:w*h*4]             # <<<<<<<<<<<<<<
 * 
 *     # Out is where we put the output.
 */
  __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_null + 0, ((__pyx_v_w * __pyx_v_h) * 4) - 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(__pyx_v_rv);
  __pyx_v_rv = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":133
 * 
 *     # Out is where we put the output.
 *     cdef unsigned char *out = rv             # <<<<<<<<<<<<<<
 * 
 *     # The pixels in the source image.
 */
  __pyx_t_4 = __Pyx_PyBytes_AsUString(__pyx_v_rv); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_out = __pyx_t_4;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":136
 * 
 *     # The pixels in the source image.
 *     cdef unsigned char *pixels = NULL             # <<<<<<<<<<<<<<
 *     cdef SDL_Surface *surf
 * 
 */
  __pyx_v_pixels = NULL;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":154
 *     cdef unsigned int *pp
 * 
 *     surf = PySurface_AsSurface(pysurf)             # <<<<<<<<<<<<<<
 *     pixels = <unsigned char *> surf.pixels
 * 
 */
  __pyx_v_surf = PySurface_AsSurface(__pyx_v_pysurf);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":155
 * 
 *     surf = PySurface_AsSurface(pysurf)
 *     pixels = <unsigned char *> surf.pixels             # <<<<<<<<<<<<<<
 * 
 *     pixels += y * surf.pitch
 */
  __pyx_v_pixels = ((unsigned char *)__pyx_v_surf->pixels);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":157
 *     pixels = <unsigned char *> surf.pixels
 * 
 *     pixels += y * surf.pitch             # <<<<<<<<<<<<<<
 *     pixels += x * 4
 * 
 */
  __pyx_v_pixels += (__pyx_v_y * __pyx_v_surf->pitch);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":158
 * 
 *     pixels += y * surf.pitch
 *     pixels += x * 4             # <<<<<<<<<<<<<<
 * 
 *     op = out
 */
  __pyx_v_pixels += (__pyx_v_x * 4);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":160
 *     pixels += x * 4
 * 
 *     op = out             # <<<<<<<<<<<<<<
 * 
 *     for y from 0 <= y < h:
 */
  __pyx_v_op = __pyx_v_out;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":162
 *     op = out
 * 
 *     for y from 0 <= y < h:             # <<<<<<<<<<<<<<
 *         p = pixels + y * surf.pitch
 *         pend = p + w * 4
 */
  __pyx_t_5 = __pyx_v_h;
  for (__pyx_v_y = 0; __pyx_v_y < __pyx_t_5; __pyx_v_y++) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":163
 * 
 *     for y from 0 <= y < h:
 *         p = pixels + y * surf.pitch             # <<<<<<<<<<<<<<
 *         pend = p + w * 4
 * 
 */
    __pyx_v_p = (__pyx_v_pixels + (__pyx_v_y * __pyx_v_surf->pitch));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":164
 *     for y from 0 <= y < h:
 *         p = pixels + y * surf.pitch
 *         pend = p + w * 4             # <<<<<<<<<<<<<<
 * 
 *         while p < pend:
 */
    __pyx_v_pend = (__pyx_v_p + (__pyx_v_w * 4));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":166
 *         pend = p + w * 4
 * 
 *         while p < pend:             # <<<<<<<<<<<<<<
 *             a = (p[3] & alpha_and) | alpha_or
 * 
 */
    while (1) {
      __pyx_t_3 = (__pyx_v_p < __pyx_v_pend);
      if (!__pyx_t_3) break;

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":167
 * 
 *         while p < pend:
 *             a = (p[3] & alpha_and) | alpha_or             # <<<<<<<<<<<<<<
 * 
 *             op[0] = p[0] * a / 255
 */
      __pyx_v_a = (((__pyx_v_p[3]) & __pyx_v_alpha_and) | __pyx_v_alpha_or);

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":169
 *             a = (p[3] & alpha_and) | alpha_or
 * 
 *             op[0] = p[0] * a / 255             # <<<<<<<<<<<<<<
 *             op[1] = p[1] * a / 255
 *             op[2] = p[2] * a / 255
 */
      (__pyx_v_op[0]) = (((__pyx_v_p[0]) * __pyx_v_a) / 255);

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":170
 * 
 *             op[0] = p[0] * a / 255
 *             op[1] = p[1] * a / 255             # <<<<<<<<<<<<<<
 *             op[2] = p[2] * a / 255
 *             op[3] = a
 */
      (__pyx_v_op[1]) = (((__pyx_v_p[1]) * __pyx_v_a) / 255);

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":171
 *             op[0] = p[0] * a / 255
 *             op[1] = p[1] * a / 255
 *             op[2] = p[2] * a / 255             # <<<<<<<<<<<<<<
 *             op[3] = a
 * 
 */
      (__pyx_v_op[2]) = (((__pyx_v_p[2]) * __pyx_v_a) / 255);

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":172
 *             op[1] = p[1] * a / 255
 *             op[2] = p[2] * a / 255
 *             op[3] = a             # <<<<<<<<<<<<<<
 * 
 *             p += 4
 */
      (__pyx_v_op[3]) = __pyx_v_a;

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":174
 *             op[3] = a
 * 
 *             p += 4             # <<<<<<<<<<<<<<
 *             op += 4
 * 
 */
      __pyx_v_p += 4;

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":175
 * 
 *             p += 4
 *             op += 4             # <<<<<<<<<<<<<<
 * 
 *     if border_left:
 */
      __pyx_v_op += 4;
    }
  }

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":177
 *             op += 4
 * 
 *     if border_left:             # <<<<<<<<<<<<<<
 *         pp = <unsigned int *> (out)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_border_left); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_3) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":178
 * 
 *     if border_left:
 *         pp = <unsigned int *> (out)             # <<<<<<<<<<<<<<
 * 
 *         for y from 0 <= y < h:
 */
    __pyx_v_pp = ((unsigned int *)__pyx_v_out);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":180
 *         pp = <unsigned int *> (out)
 * 
 *         for y from 0 <= y < h:             # <<<<<<<<<<<<<<
 *             pp[0] = pp[1]
 *             pp += w
 */
    __pyx_t_5 = __pyx_v_h;
    for (__pyx_v_y = 0; __pyx_v_y < __pyx_t_5; __pyx_v_y++) {

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":181
 * 
 *         for y from 0 <= y < h:
 *             pp[0] = pp[1]             # <<<<<<<<<<<<<<
 *             pp += w
 * 
 */
      (__pyx_v_pp[0]) = (__pyx_v_pp[1]);

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":182
 *         for y from 0 <= y < h:
 *             pp[0] = pp[1]
 *             pp += w             # <<<<<<<<<<<<<<
 * 
 *     if border_right:
 */
      __pyx_v_pp += __pyx_v_w;
    }
    goto __pyx_L11;
  }
  __pyx_L11:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":184
 *             pp += w
 * 
 *     if border_right:             # <<<<<<<<<<<<<<
 *         pp = <unsigned int *> (out)
 *         pp += w - 2
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_border_right); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_3) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":185
 * 
 *     if border_right:
 *         pp = <unsigned int *> (out)             # <<<<<<<<<<<<<<
 *         pp += w - 2
 * 
 */
    __pyx_v_pp = ((unsigned int *)__pyx_v_out);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":186
 *     if border_right:
 *         pp = <unsigned int *> (out)
 *         pp += w - 2             # <<<<<<<<<<<<<<
 * 
 *         for y from 0 <= y < h:
 */
    __pyx_v_pp += (__pyx_v_w - 2);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":188
 *         pp += w - 2
 * 
 *         for y from 0 <= y < h:             # <<<<<<<<<<<<<<
 *             pp[1] = pp[0]
 *             pp += w
 */
    __pyx_t_5 = __pyx_v_h;
    for (__pyx_v_y = 0; __pyx_v_y < __pyx_t_5; __pyx_v_y++) {

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":189
 * 
 *         for y from 0 <= y < h:
 *             pp[1] = pp[0]             # <<<<<<<<<<<<<<
 *             pp += w
 * 
 */
      (__pyx_v_pp[1]) = (__pyx_v_pp[0]);

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":190
 *         for y from 0 <= y < h:
 *             pp[1] = pp[0]
 *             pp += w             # <<<<<<<<<<<<<<
 * 
 *     if border_top:
 */
      __pyx_v_pp += __pyx_v_w;
    }
    goto __pyx_L14;
  }
  __pyx_L14:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":192
 *             pp += w
 * 
 *     if border_top:             # <<<<<<<<<<<<<<
 *         pp = <unsigned int *> (out)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_border_top); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_3) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":193
 * 
 *     if border_top:
 *         pp = <unsigned int *> (out)             # <<<<<<<<<<<<<<
 * 
 *         for x from 0 <= x < w:
 */
    __pyx_v_pp = ((unsigned int *)__pyx_v_out);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":195
 *         pp = <unsigned int *> (out)
 * 
 *         for x from 0 <= x < w:             # <<<<<<<<<<<<<<
 *             pp[0] = pp[w]
 *             pp += 1
 */
    __pyx_t_5 = __pyx_v_w;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":196
 * 
 *         for x from 0 <= x < w:
 *             pp[0] = pp[w]             # <<<<<<<<<<<<<<
 *             pp += 1
 * 
 */
      (__pyx_v_pp[0]) = (__pyx_v_pp[__pyx_v_w]);

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":197
 *         for x from 0 <= x < w:
 *             pp[0] = pp[w]
 *             pp += 1             # <<<<<<<<<<<<<<
 * 
 *     if border_top:
 */
      __pyx_v_pp += 1;
    }
    goto __pyx_L17;
  }
  __pyx_L17:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":199
 *             pp += 1
 * 
 *     if border_top:             # <<<<<<<<<<<<<<
 *         pp = <unsigned int *> (out)
 *         pp += (y - 2) * w
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_border_top); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_3) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":200
 * 
 *     if border_top:
 *         pp = <unsigned int *> (out)             # <<<<<<<<<<<<<<
 *         pp += (y - 2) * w
 * 
 */
    __pyx_v_pp = ((unsigned int *)__pyx_v_out);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":201
 *     if border_top:
 *         pp = <unsigned int *> (out)
 *         pp += (y - 2) * w             # <<<<<<<<<<<<<<
 * 
 *         for x from 0 <= x < w:
 */
    __pyx_v_pp += ((__pyx_v_y - 2) * __pyx_v_w);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":203
 *         pp += (y - 2) * w
 * 
 *         for x from 0 <= x < w:             # <<<<<<<<<<<<<<
 *             pp[w] = pp[0]
 *             pp += 1
 */
    __pyx_t_5 = __pyx_v_w;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":204
 * 
 *         for x from 0 <= x < w:
 *             pp[w] = pp[0]             # <<<<<<<<<<<<<<
 *             pp += 1
 * 
 */
      (__pyx_v_pp[__pyx_v_w]) = (__pyx_v_pp[0]);

      /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":205
 *         for x from 0 <= x < w:
 *             pp[w] = pp[0]
 *             pp += 1             # <<<<<<<<<<<<<<
 * 
 *     return rv
 */
      __pyx_v_pp += 1;
    }
    goto __pyx_L20;
  }
  __pyx_L20:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":207
 *             pp += 1
 * 
 *     return rv             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_rv);
  __pyx_r = __pyx_v_rv;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_renpy_pysdlgl.premultiply");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_rv);
  __Pyx_DECREF(__pyx_v_pysurf);
  __Pyx_DECREF(__pyx_v_border_left);
  __Pyx_DECREF(__pyx_v_border_top);
  __Pyx_DECREF(__pyx_v_border_right);
  __Pyx_DECREF(__pyx_v_border_bottom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":210
 * 
 * 
 * def load_premultiplied(             # <<<<<<<<<<<<<<
 *     data, width, height, update, format,
 *     ):
 */

static PyObject *__pyx_pf_14_renpy_pysdlgl_load_premultiplied(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_14_renpy_pysdlgl_load_premultiplied(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_data = 0;
  PyObject *__pyx_v_width = 0;
  PyObject *__pyx_v_height = 0;
  PyObject *__pyx_v_update = 0;
  PyObject *__pyx_v_format = 0;
  char *__pyx_v_pixels;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  char *__pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  GLsizei __pyx_t_6;
  GLsizei __pyx_t_7;
  GLenum __pyx_t_8;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__data,&__pyx_n_s__width,&__pyx_n_s__height,&__pyx_n_s__update,&__pyx_n_s__format,0};
  __Pyx_RefNannySetupContext("load_premultiplied");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[5] = {0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__data);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__width);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("load_premultiplied", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__height);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("load_premultiplied", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__update);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("load_premultiplied", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__format);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("load_premultiplied", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "load_premultiplied") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_data = values[0];
    __pyx_v_width = values[1];
    __pyx_v_height = values[2];
    __pyx_v_update = values[3];
    __pyx_v_format = values[4];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_data = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_width = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_height = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_update = PyTuple_GET_ITEM(__pyx_args, 3);
    __pyx_v_format = PyTuple_GET_ITEM(__pyx_args, 4);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("load_premultiplied", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy_pysdlgl.load_premultiplied");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_data);
  __Pyx_INCREF(__pyx_v_width);
  __Pyx_INCREF(__pyx_v_height);
  __Pyx_INCREF(__pyx_v_update);
  __Pyx_INCREF(__pyx_v_format);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":216
 *     cdef char *pixels
 * 
 *     if data:             # <<<<<<<<<<<<<<
 *         pixels = data
 *     else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_data); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":217
 * 
 *     if data:
 *         pixels = data             # <<<<<<<<<<<<<<
 *     else:
 *         pixels = NULL
 */
    __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_data); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_pixels = __pyx_t_2;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":219
 *         pixels = data
 *     else:
 *         pixels = NULL             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_v_pixels = NULL;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":222
 * 
 * 
 *     if update:             # <<<<<<<<<<<<<<
 *         glTexSubImage2D(
 *             GL_TEXTURE_2D,
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_update); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":228
 *             0,
 *             0,
 *             width,             # <<<<<<<<<<<<<<
 *             height,
 *             format,
 */
    __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_width); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":229
 *             0,
 *             width,
 *             height,             # <<<<<<<<<<<<<<
 *             format,
 *             GL_UNSIGNED_BYTE,
 */
    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_height); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":230
 *             width,
 *             height,
 *             format,             # <<<<<<<<<<<<<<
 *             GL_UNSIGNED_BYTE,
 *             pixels)
 */
    __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_v_format); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":232
 *             format,
 *             GL_UNSIGNED_BYTE,
 *             pixels)             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, __pyx_t_3, __pyx_t_4, __pyx_t_5, GL_UNSIGNED_BYTE, __pyx_v_pixels);
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":239
 *             0,
 *             GL_RGBA,
 *             width,             # <<<<<<<<<<<<<<
 *             height,
 *             0,
 */
    __pyx_t_6 = __Pyx_PyInt_from_py_GLsizei(__pyx_v_width); if (unlikely((__pyx_t_6 == (GLsizei)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":240
 *             GL_RGBA,
 *             width,
 *             height,             # <<<<<<<<<<<<<<
 *             0,
 *             format,
 */
    __pyx_t_7 = __Pyx_PyInt_from_py_GLsizei(__pyx_v_height); if (unlikely((__pyx_t_7 == (GLsizei)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":242
 *             height,
 *             0,
 *             format,             # <<<<<<<<<<<<<<
 *             GL_UNSIGNED_BYTE,
 *             pixels)
 */
    __pyx_t_8 = __Pyx_PyInt_from_py_GLenum(__pyx_v_format); if (unlikely((__pyx_t_8 == (GLenum)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":244
 *             format,
 *             GL_UNSIGNED_BYTE,
 *             pixels)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, __pyx_t_6, __pyx_t_7, 0, __pyx_t_8, GL_UNSIGNED_BYTE, __pyx_v_pixels);
  }
  __pyx_L7:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("_renpy_pysdlgl.load_premultiplied");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_data);
  __Pyx_DECREF(__pyx_v_width);
  __Pyx_DECREF(__pyx_v_height);
  __Pyx_DECREF(__pyx_v_update);
  __Pyx_DECREF(__pyx_v_format);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":247
 * 
 * 
 * def store_framebuffer(             # <<<<<<<<<<<<<<
 *     object pysurf,
 *     int format,
 */

static PyObject *__pyx_pf_14_renpy_pysdlgl_store_framebuffer(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14_renpy_pysdlgl_store_framebuffer[] = "\n    This loads the supplied pygame surface into the numbered\n    texture. The created texture will be of size (width, height),\n    and at position (xoffset, yoffset) relative to the containing\n    image. \n    ";
static PyObject *__pyx_pf_14_renpy_pysdlgl_store_framebuffer(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysurf = 0;
  int __pyx_v_format;
  unsigned char *__pyx_v_pixels;
  struct SDL_Surface *__pyx_v_surf;
  PyObject *__pyx_r = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__pysurf,&__pyx_n_s__format,0};
  __Pyx_RefNannySetupContext("store_framebuffer");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pysurf);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__format);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("store_framebuffer", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "store_framebuffer") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysurf = values[0];
    __pyx_v_format = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_format == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysurf = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_format = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_format == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("store_framebuffer", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy_pysdlgl.store_framebuffer");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":258
 *     image.
 *     """
 *     cdef unsigned char *pixels = NULL             # <<<<<<<<<<<<<<
 *     cdef SDL_Surface *surf
 * 
 */
  __pyx_v_pixels = NULL;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":261
 *     cdef SDL_Surface *surf
 * 
 *     surf = PySurface_AsSurface(pysurf)             # <<<<<<<<<<<<<<
 *     pixels = <unsigned char *> surf.pixels
 * 
 */
  __pyx_v_surf = PySurface_AsSurface(__pyx_v_pysurf);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":262
 * 
 *     surf = PySurface_AsSurface(pysurf)
 *     pixels = <unsigned char *> surf.pixels             # <<<<<<<<<<<<<<
 * 
 *     glPixelStorei(GL_PACK_ROW_LENGTH, surf.pitch / 4)
 */
  __pyx_v_pixels = ((unsigned char *)__pyx_v_surf->pixels);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":264
 *     pixels = <unsigned char *> surf.pixels
 * 
 *     glPixelStorei(GL_PACK_ROW_LENGTH, surf.pitch / 4)             # <<<<<<<<<<<<<<
 * 
 *     glReadPixels(
 */
  glPixelStorei(GL_PACK_ROW_LENGTH, __Pyx_div_long(__pyx_v_surf->pitch, 4));

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":273
 *         format,
 *         GL_UNSIGNED_BYTE,
 *         pixels)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  glReadPixels(0, 0, __pyx_v_surf->w, __pyx_v_surf->h, __pyx_v_format, GL_UNSIGNED_BYTE, __pyx_v_pixels);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":276
 * 
 * 
 * def draw_rectangle(             # <<<<<<<<<<<<<<
 *     float sx,
 *     float sy,
 */

static PyObject *__pyx_pf_14_renpy_pysdlgl_draw_rectangle(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14_renpy_pysdlgl_draw_rectangle[] = "\n    This draws a rectangle (textured with up to four textures) to the\n    screen.\n    ";
static PyObject *__pyx_pf_14_renpy_pysdlgl_draw_rectangle(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  float __pyx_v_sx;
  float __pyx_v_sy;
  float __pyx_v_x;
  float __pyx_v_y;
  float __pyx_v_w;
  float __pyx_v_h;
  PyObject *__pyx_v_transform = 0;
  PyObject *__pyx_v_tex0 = 0;
  int __pyx_v_tex0x;
  int __pyx_v_tex0y;
  PyObject *__pyx_v_tex1 = 0;
  int __pyx_v_tex1x;
  int __pyx_v_tex1y;
  PyObject *__pyx_v_tex2 = 0;
  int __pyx_v_tex2x;
  int __pyx_v_tex2y;
  int __pyx_v_has_tex0;
  int __pyx_v_has_tex1;
  int __pyx_v_has_tex2;
  float __pyx_v_t0u0;
  float __pyx_v_t0v0;
  float __pyx_v_t0u1;
  float __pyx_v_t0v1;
  float __pyx_v_t1u0;
  float __pyx_v_t1v0;
  float __pyx_v_t1u1;
  float __pyx_v_t1v1;
  float __pyx_v_t2u0;
  float __pyx_v_t2v0;
  float __pyx_v_t2u1;
  float __pyx_v_t2v1;
  float __pyx_v_xdx;
  float __pyx_v_xdy;
  float __pyx_v_ydx;
  float __pyx_v_ydy;
  float __pyx_v_x0;
  float __pyx_v_y0;
  float __pyx_v_x1;
  float __pyx_v_y1;
  float __pyx_v_x2;
  float __pyx_v_y2;
  float __pyx_v_x3;
  float __pyx_v_y3;
  float __pyx_v_xadd;
  float __pyx_v_yadd;
  float __pyx_v_xmul;
  float __pyx_v_ymul;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  float __pyx_t_2;
  int __pyx_t_3;
  GLuint __pyx_t_4;
  int __pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sx,&__pyx_n_s__sy,&__pyx_n_s__x,&__pyx_n_s__y,&__pyx_n_s__w,&__pyx_n_s__h,&__pyx_n_s__transform,&__pyx_n_s__tex0,&__pyx_n_s__tex0x,&__pyx_n_s__tex0y,&__pyx_n_s__tex1,&__pyx_n_s__tex1x,&__pyx_n_s__tex1y,&__pyx_n_s__tex2,&__pyx_n_s__tex2x,&__pyx_n_s__tex2y,0};
  __Pyx_RefNannySetupContext("draw_rectangle");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15);
      case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
      case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
      case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
      case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
      case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
      case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
      case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
      case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
      case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sx);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sy);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__w);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  5:
      values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__h);
      if (likely(values[5])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  6:
      values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__transform);
      if (likely(values[6])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  7:
      values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tex0);
      if (likely(values[7])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  8:
      values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tex0x);
      if (likely(values[8])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  9:
      values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tex0y);
      if (likely(values[9])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 9); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 10:
      values[10] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tex1);
      if (likely(values[10])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 10); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 11:
      values[11] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tex1x);
      if (likely(values[11])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 11); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 12:
      values[12] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tex1y);
      if (likely(values[12])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 12); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 13:
      values[13] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tex2);
      if (likely(values[13])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 13); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 14:
      values[14] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tex2x);
      if (likely(values[14])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 14); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 15:
      values[15] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tex2y);
      if (likely(values[15])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, 15); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "draw_rectangle") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_sx = __pyx_PyFloat_AsDouble(values[0]); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_sy = __pyx_PyFloat_AsDouble(values[1]); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_x = __pyx_PyFloat_AsDouble(values[2]); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_y = __pyx_PyFloat_AsDouble(values[3]); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_w = __pyx_PyFloat_AsDouble(values[4]); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_h = __pyx_PyFloat_AsDouble(values[5]); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_transform = values[6];
    __pyx_v_tex0 = values[7];
    __pyx_v_tex0x = __Pyx_PyInt_AsInt(values[8]); if (unlikely((__pyx_v_tex0x == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex0y = __Pyx_PyInt_AsInt(values[9]); if (unlikely((__pyx_v_tex0y == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex1 = values[10];
    __pyx_v_tex1x = __Pyx_PyInt_AsInt(values[11]); if (unlikely((__pyx_v_tex1x == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex1y = __Pyx_PyInt_AsInt(values[12]); if (unlikely((__pyx_v_tex1y == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex2 = values[13];
    __pyx_v_tex2x = __Pyx_PyInt_AsInt(values[14]); if (unlikely((__pyx_v_tex2x == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex2y = __Pyx_PyInt_AsInt(values[15]); if (unlikely((__pyx_v_tex2y == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  } else if (PyTuple_GET_SIZE(__pyx_args) != 16) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_sx = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_sy = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_x = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_y = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_w = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 4)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_h = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_transform = PyTuple_GET_ITEM(__pyx_args, 6);
    __pyx_v_tex0 = PyTuple_GET_ITEM(__pyx_args, 7);
    __pyx_v_tex0x = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 8)); if (unlikely((__pyx_v_tex0x == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex0y = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 9)); if (unlikely((__pyx_v_tex0y == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex1 = PyTuple_GET_ITEM(__pyx_args, 10);
    __pyx_v_tex1x = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 11)); if (unlikely((__pyx_v_tex1x == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex1y = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 12)); if (unlikely((__pyx_v_tex1y == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex2 = PyTuple_GET_ITEM(__pyx_args, 13);
    __pyx_v_tex2x = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 14)); if (unlikely((__pyx_v_tex2x == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_tex2y = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 15)); if (unlikely((__pyx_v_tex2y == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("draw_rectangle", 1, 16, 16, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy_pysdlgl.draw_rectangle");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_transform);
  __Pyx_INCREF(__pyx_v_tex0);
  __Pyx_INCREF(__pyx_v_tex1);
  __Pyx_INCREF(__pyx_v_tex2);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":303
 * 
 *     # Pull apart the transform.
 *     cdef float xdx = transform.xdx             # <<<<<<<<<<<<<<
 *     cdef float xdy = transform.xdy
 *     cdef float ydx = transform.ydx
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_transform, __pyx_n_s__xdx); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_xdx = __pyx_t_2;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":304
 *     # Pull apart the transform.
 *     cdef float xdx = transform.xdx
 *     cdef float xdy = transform.xdy             # <<<<<<<<<<<<<<
 *     cdef float ydx = transform.ydx
 *     cdef float ydy = transform.ydy
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_transform, __pyx_n_s__xdy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_xdy = __pyx_t_2;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":305
 *     cdef float xdx = transform.xdx
 *     cdef float xdy = transform.xdy
 *     cdef float ydx = transform.ydx             # <<<<<<<<<<<<<<
 *     cdef float ydy = transform.ydy
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_transform, __pyx_n_s__ydx); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ydx = __pyx_t_2;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":306
 *     cdef float xdy = transform.xdy
 *     cdef float ydx = transform.ydx
 *     cdef float ydy = transform.ydy             # <<<<<<<<<<<<<<
 * 
 *     # Transform the vertex coordinates to screen-space.
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_transform, __pyx_n_s__ydy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ydy = __pyx_t_2;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":309
 * 
 *     # Transform the vertex coordinates to screen-space.
 *     cdef float x0 = (x + 0) * xdx + (y + 0) * xdy + sx             # <<<<<<<<<<<<<<
 *     cdef float y0 = (x + 0) * ydx + (y + 0) * ydy + sy
 * 
 */
  __pyx_v_x0 = ((((__pyx_v_x + 0) * __pyx_v_xdx) + ((__pyx_v_y + 0) * __pyx_v_xdy)) + __pyx_v_sx);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":310
 *     # Transform the vertex coordinates to screen-space.
 *     cdef float x0 = (x + 0) * xdx + (y + 0) * xdy + sx
 *     cdef float y0 = (x + 0) * ydx + (y + 0) * ydy + sy             # <<<<<<<<<<<<<<
 * 
 *     cdef float x1 = (x + w) * xdx + (y + 0) * xdy + sx
 */
  __pyx_v_y0 = ((((__pyx_v_x + 0) * __pyx_v_ydx) + ((__pyx_v_y + 0) * __pyx_v_ydy)) + __pyx_v_sy);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":312
 *     cdef float y0 = (x + 0) * ydx + (y + 0) * ydy + sy
 * 
 *     cdef float x1 = (x + w) * xdx + (y + 0) * xdy + sx             # <<<<<<<<<<<<<<
 *     cdef float y1 = (x + w) * ydx + (y + 0) * ydy + sy
 * 
 */
  __pyx_v_x1 = ((((__pyx_v_x + __pyx_v_w) * __pyx_v_xdx) + ((__pyx_v_y + 0) * __pyx_v_xdy)) + __pyx_v_sx);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":313
 * 
 *     cdef float x1 = (x + w) * xdx + (y + 0) * xdy + sx
 *     cdef float y1 = (x + w) * ydx + (y + 0) * ydy + sy             # <<<<<<<<<<<<<<
 * 
 *     cdef float x2 = (x + 0) * xdx + (y + h) * xdy + sx
 */
  __pyx_v_y1 = ((((__pyx_v_x + __pyx_v_w) * __pyx_v_ydx) + ((__pyx_v_y + 0) * __pyx_v_ydy)) + __pyx_v_sy);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":315
 *     cdef float y1 = (x + w) * ydx + (y + 0) * ydy + sy
 * 
 *     cdef float x2 = (x + 0) * xdx + (y + h) * xdy + sx             # <<<<<<<<<<<<<<
 *     cdef float y2 = (x + 0) * ydx + (y + h) * ydy + sy
 * 
 */
  __pyx_v_x2 = ((((__pyx_v_x + 0) * __pyx_v_xdx) + ((__pyx_v_y + __pyx_v_h) * __pyx_v_xdy)) + __pyx_v_sx);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":316
 * 
 *     cdef float x2 = (x + 0) * xdx + (y + h) * xdy + sx
 *     cdef float y2 = (x + 0) * ydx + (y + h) * ydy + sy             # <<<<<<<<<<<<<<
 * 
 *     cdef float x3 = (x + w) * xdx + (y + h) * xdy + sx
 */
  __pyx_v_y2 = ((((__pyx_v_x + 0) * __pyx_v_ydx) + ((__pyx_v_y + __pyx_v_h) * __pyx_v_ydy)) + __pyx_v_sy);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":318
 *     cdef float y2 = (x + 0) * ydx + (y + h) * ydy + sy
 * 
 *     cdef float x3 = (x + w) * xdx + (y + h) * xdy + sx             # <<<<<<<<<<<<<<
 *     cdef float y3 = (x + w) * ydx + (y + h) * ydy + sy
 * 
 */
  __pyx_v_x3 = ((((__pyx_v_x + __pyx_v_w) * __pyx_v_xdx) + ((__pyx_v_y + __pyx_v_h) * __pyx_v_xdy)) + __pyx_v_sx);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":319
 * 
 *     cdef float x3 = (x + w) * xdx + (y + h) * xdy + sx
 *     cdef float y3 = (x + w) * ydx + (y + h) * ydy + sy             # <<<<<<<<<<<<<<
 * 
 *     # Compute the texture coordinates, and set up the textures.
 */
  __pyx_v_y3 = ((((__pyx_v_x + __pyx_v_w) * __pyx_v_ydx) + ((__pyx_v_y + __pyx_v_h) * __pyx_v_ydy)) + __pyx_v_sy);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":324
 *     cdef float xadd, yadd, xmul, ymul
 * 
 *     if tex0 is not None:             # <<<<<<<<<<<<<<
 * 
 *         has_tex0 = 1
 */
  __pyx_t_3 = (__pyx_v_tex0 != Py_None);
  if (__pyx_t_3) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":326
 *     if tex0 is not None:
 * 
 *         has_tex0 = 1             # <<<<<<<<<<<<<<
 * 
 *         glActiveTextureARB(GL_TEXTURE0_ARB)
 */
    __pyx_v_has_tex0 = 1;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":328
 *         has_tex0 = 1
 * 
 *         glActiveTextureARB(GL_TEXTURE0_ARB)             # <<<<<<<<<<<<<<
 *         glBindTexture(GL_TEXTURE_2D, tex0.number)
 * 
 */
    glActiveTextureARB(GL_TEXTURE0_ARB);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":329
 * 
 *         glActiveTextureARB(GL_TEXTURE0_ARB)
 *         glBindTexture(GL_TEXTURE_2D, tex0.number)             # <<<<<<<<<<<<<<
 * 
 *         xadd = tex0.xadd
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex0, __pyx_n_s__number); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_from_py_GLuint(__pyx_t_1); if (unlikely((__pyx_t_4 == (GLuint)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    glBindTexture(GL_TEXTURE_2D, __pyx_t_4);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":331
 *         glBindTexture(GL_TEXTURE_2D, tex0.number)
 * 
 *         xadd = tex0.xadd             # <<<<<<<<<<<<<<
 *         yadd = tex0.yadd
 *         xmul = tex0.xmul
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex0, __pyx_n_s__xadd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_xadd = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":332
 * 
 *         xadd = tex0.xadd
 *         yadd = tex0.yadd             # <<<<<<<<<<<<<<
 *         xmul = tex0.xmul
 *         ymul = tex0.ymul
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex0, __pyx_n_s__yadd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_yadd = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":333
 *         xadd = tex0.xadd
 *         yadd = tex0.yadd
 *         xmul = tex0.xmul             # <<<<<<<<<<<<<<
 *         ymul = tex0.ymul
 * 
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex0, __pyx_n_s__xmul); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_xmul = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":334
 *         yadd = tex0.yadd
 *         xmul = tex0.xmul
 *         ymul = tex0.ymul             # <<<<<<<<<<<<<<
 * 
 *         t0u0 = xadd + xmul * (tex0x + 0)
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex0, __pyx_n_s__ymul); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_ymul = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":336
 *         ymul = tex0.ymul
 * 
 *         t0u0 = xadd + xmul * (tex0x + 0)             # <<<<<<<<<<<<<<
 *         t0u1 = xadd + xmul * (tex0x + w)
 *         t0v0 = yadd + ymul * (tex0y + 0)
 */
    __pyx_v_t0u0 = (__pyx_v_xadd + (__pyx_v_xmul * (__pyx_v_tex0x + 0)));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":337
 * 
 *         t0u0 = xadd + xmul * (tex0x + 0)
 *         t0u1 = xadd + xmul * (tex0x + w)             # <<<<<<<<<<<<<<
 *         t0v0 = yadd + ymul * (tex0y + 0)
 *         t0v1 = yadd + ymul * (tex0y + h)
 */
    __pyx_v_t0u1 = (__pyx_v_xadd + (__pyx_v_xmul * (__pyx_v_tex0x + __pyx_v_w)));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":338
 *         t0u0 = xadd + xmul * (tex0x + 0)
 *         t0u1 = xadd + xmul * (tex0x + w)
 *         t0v0 = yadd + ymul * (tex0y + 0)             # <<<<<<<<<<<<<<
 *         t0v1 = yadd + ymul * (tex0y + h)
 * 
 */
    __pyx_v_t0v0 = (__pyx_v_yadd + (__pyx_v_ymul * (__pyx_v_tex0y + 0)));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":339
 *         t0u1 = xadd + xmul * (tex0x + w)
 *         t0v0 = yadd + ymul * (tex0y + 0)
 *         t0v1 = yadd + ymul * (tex0y + h)             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
    __pyx_v_t0v1 = (__pyx_v_yadd + (__pyx_v_ymul * (__pyx_v_tex0y + __pyx_v_h)));
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":342
 * 
 *     else:
 *         has_tex0 = 0             # <<<<<<<<<<<<<<
 * 
 *     if tex1 is not None:
 */
    __pyx_v_has_tex0 = 0;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":344
 *         has_tex0 = 0
 * 
 *     if tex1 is not None:             # <<<<<<<<<<<<<<
 * 
 *         has_tex1 = 1
 */
  __pyx_t_3 = (__pyx_v_tex1 != Py_None);
  if (__pyx_t_3) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":346
 *     if tex1 is not None:
 * 
 *         has_tex1 = 1             # <<<<<<<<<<<<<<
 * 
 *         glActiveTextureARB(GL_TEXTURE1_ARB)
 */
    __pyx_v_has_tex1 = 1;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":348
 *         has_tex1 = 1
 * 
 *         glActiveTextureARB(GL_TEXTURE1_ARB)             # <<<<<<<<<<<<<<
 *         glBindTexture(GL_TEXTURE_2D, tex1.number)
 * 
 */
    glActiveTextureARB(GL_TEXTURE1_ARB);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":349
 * 
 *         glActiveTextureARB(GL_TEXTURE1_ARB)
 *         glBindTexture(GL_TEXTURE_2D, tex1.number)             # <<<<<<<<<<<<<<
 * 
 *         xadd = tex1.xadd
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex1, __pyx_n_s__number); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_from_py_GLuint(__pyx_t_1); if (unlikely((__pyx_t_4 == (GLuint)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    glBindTexture(GL_TEXTURE_2D, __pyx_t_4);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":351
 *         glBindTexture(GL_TEXTURE_2D, tex1.number)
 * 
 *         xadd = tex1.xadd             # <<<<<<<<<<<<<<
 *         yadd = tex1.yadd
 *         xmul = tex1.xmul
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex1, __pyx_n_s__xadd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_xadd = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":352
 * 
 *         xadd = tex1.xadd
 *         yadd = tex1.yadd             # <<<<<<<<<<<<<<
 *         xmul = tex1.xmul
 *         ymul = tex1.ymul
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex1, __pyx_n_s__yadd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_yadd = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":353
 *         xadd = tex1.xadd
 *         yadd = tex1.yadd
 *         xmul = tex1.xmul             # <<<<<<<<<<<<<<
 *         ymul = tex1.ymul
 * 
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex1, __pyx_n_s__xmul); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_xmul = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":354
 *         yadd = tex1.yadd
 *         xmul = tex1.xmul
 *         ymul = tex1.ymul             # <<<<<<<<<<<<<<
 * 
 *         t1u0 = xadd + xmul * (tex1x + 0)
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex1, __pyx_n_s__ymul); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_ymul = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":356
 *         ymul = tex1.ymul
 * 
 *         t1u0 = xadd + xmul * (tex1x + 0)             # <<<<<<<<<<<<<<
 *         t1u1 = xadd + xmul * (tex1x + w)
 *         t1v0 = yadd + ymul * (tex1y + 0)
 */
    __pyx_v_t1u0 = (__pyx_v_xadd + (__pyx_v_xmul * (__pyx_v_tex1x + 0)));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":357
 * 
 *         t1u0 = xadd + xmul * (tex1x + 0)
 *         t1u1 = xadd + xmul * (tex1x + w)             # <<<<<<<<<<<<<<
 *         t1v0 = yadd + ymul * (tex1y + 0)
 *         t1v1 = yadd + ymul * (tex1y + h)
 */
    __pyx_v_t1u1 = (__pyx_v_xadd + (__pyx_v_xmul * (__pyx_v_tex1x + __pyx_v_w)));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":358
 *         t1u0 = xadd + xmul * (tex1x + 0)
 *         t1u1 = xadd + xmul * (tex1x + w)
 *         t1v0 = yadd + ymul * (tex1y + 0)             # <<<<<<<<<<<<<<
 *         t1v1 = yadd + ymul * (tex1y + h)
 * 
 */
    __pyx_v_t1v0 = (__pyx_v_yadd + (__pyx_v_ymul * (__pyx_v_tex1y + 0)));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":359
 *         t1u1 = xadd + xmul * (tex1x + w)
 *         t1v0 = yadd + ymul * (tex1y + 0)
 *         t1v1 = yadd + ymul * (tex1y + h)             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
    __pyx_v_t1v1 = (__pyx_v_yadd + (__pyx_v_ymul * (__pyx_v_tex1y + __pyx_v_h)));
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":362
 * 
 *     else:
 *         has_tex1 = 0             # <<<<<<<<<<<<<<
 * 
 *     if tex2 is not None:
 */
    __pyx_v_has_tex1 = 0;
  }
  __pyx_L7:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":364
 *         has_tex1 = 0
 * 
 *     if tex2 is not None:             # <<<<<<<<<<<<<<
 * 
 *         has_tex2 = 1
 */
  __pyx_t_3 = (__pyx_v_tex2 != Py_None);
  if (__pyx_t_3) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":366
 *     if tex2 is not None:
 * 
 *         has_tex2 = 1             # <<<<<<<<<<<<<<
 * 
 *         glActiveTextureARB(GL_TEXTURE2_ARB)
 */
    __pyx_v_has_tex2 = 1;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":368
 *         has_tex2 = 1
 * 
 *         glActiveTextureARB(GL_TEXTURE2_ARB)             # <<<<<<<<<<<<<<
 *         glBindTexture(GL_TEXTURE_2D, tex2.number)
 * 
 */
    glActiveTextureARB(GL_TEXTURE2_ARB);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":369
 * 
 *         glActiveTextureARB(GL_TEXTURE2_ARB)
 *         glBindTexture(GL_TEXTURE_2D, tex2.number)             # <<<<<<<<<<<<<<
 * 
 *         xadd = tex2.xadd
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex2, __pyx_n_s__number); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_from_py_GLuint(__pyx_t_1); if (unlikely((__pyx_t_4 == (GLuint)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    glBindTexture(GL_TEXTURE_2D, __pyx_t_4);

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":371
 *         glBindTexture(GL_TEXTURE_2D, tex2.number)
 * 
 *         xadd = tex2.xadd             # <<<<<<<<<<<<<<
 *         yadd = tex2.yadd
 *         xmul = tex2.xmul
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex2, __pyx_n_s__xadd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_xadd = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":372
 * 
 *         xadd = tex2.xadd
 *         yadd = tex2.yadd             # <<<<<<<<<<<<<<
 *         xmul = tex2.xmul
 *         ymul = tex2.ymul
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex2, __pyx_n_s__yadd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_yadd = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":373
 *         xadd = tex2.xadd
 *         yadd = tex2.yadd
 *         xmul = tex2.xmul             # <<<<<<<<<<<<<<
 *         ymul = tex2.ymul
 * 
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex2, __pyx_n_s__xmul); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_xmul = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":374
 *         yadd = tex2.yadd
 *         xmul = tex2.xmul
 *         ymul = tex2.ymul             # <<<<<<<<<<<<<<
 * 
 *         t2u0 = xadd + xmul * (tex2x + 0)
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_tex2, __pyx_n_s__ymul); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_ymul = __pyx_t_2;

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":376
 *         ymul = tex2.ymul
 * 
 *         t2u0 = xadd + xmul * (tex2x + 0)             # <<<<<<<<<<<<<<
 *         t2u1 = xadd + xmul * (tex2x + w)
 *         t2v0 = yadd + ymul * (tex2y + 0)
 */
    __pyx_v_t2u0 = (__pyx_v_xadd + (__pyx_v_xmul * (__pyx_v_tex2x + 0)));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":377
 * 
 *         t2u0 = xadd + xmul * (tex2x + 0)
 *         t2u1 = xadd + xmul * (tex2x + w)             # <<<<<<<<<<<<<<
 *         t2v0 = yadd + ymul * (tex2y + 0)
 *         t2v1 = yadd + ymul * (tex2y + h)
 */
    __pyx_v_t2u1 = (__pyx_v_xadd + (__pyx_v_xmul * (__pyx_v_tex2x + __pyx_v_w)));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":378
 *         t2u0 = xadd + xmul * (tex2x + 0)
 *         t2u1 = xadd + xmul * (tex2x + w)
 *         t2v0 = yadd + ymul * (tex2y + 0)             # <<<<<<<<<<<<<<
 *         t2v1 = yadd + ymul * (tex2y + h)
 * 
 */
    __pyx_v_t2v0 = (__pyx_v_yadd + (__pyx_v_ymul * (__pyx_v_tex2y + 0)));

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":379
 *         t2u1 = xadd + xmul * (tex2x + w)
 *         t2v0 = yadd + ymul * (tex2y + 0)
 *         t2v1 = yadd + ymul * (tex2y + h)             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
    __pyx_v_t2v1 = (__pyx_v_yadd + (__pyx_v_ymul * (__pyx_v_tex2y + __pyx_v_h)));
    goto __pyx_L8;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":382
 * 
 *     else:
 *         has_tex2 = 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_v_has_tex2 = 0;
  }
  __pyx_L8:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":387
 *     # Now, actually draw the textured rectangle.
 * 
 *     glBegin(GL_TRIANGLE_STRIP)             # <<<<<<<<<<<<<<
 * 
 *     if has_tex0:
 */
  glBegin(GL_TRIANGLE_STRIP);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":389
 *     glBegin(GL_TRIANGLE_STRIP)
 * 
 *     if has_tex0:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u0, t0v0)
 *     if has_tex1:
 */
  __pyx_t_5 = __pyx_v_has_tex0;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":390
 * 
 *     if has_tex0:
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u0, t0v0)             # <<<<<<<<<<<<<<
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v0)
 */
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, __pyx_v_t0u0, __pyx_v_t0v0);
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":391
 *     if has_tex0:
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u0, t0v0)
 *     if has_tex1:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v0)
 *     if has_tex2:
 */
  __pyx_t_5 = __pyx_v_has_tex1;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":392
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u0, t0v0)
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v0)             # <<<<<<<<<<<<<<
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u0, t2v0)
 */
    glMultiTexCoord2fARB(GL_TEXTURE1_ARB, __pyx_v_t1u0, __pyx_v_t1v0);
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":393
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v0)
 *     if has_tex2:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u0, t2v0)
 *     glVertex2f(x0, y0)
 */
  __pyx_t_5 = __pyx_v_has_tex2;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":394
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v0)
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u0, t2v0)             # <<<<<<<<<<<<<<
 *     glVertex2f(x0, y0)
 * 
 */
    glMultiTexCoord2fARB(GL_TEXTURE2_ARB, __pyx_v_t2u0, __pyx_v_t2v0);
    goto __pyx_L11;
  }
  __pyx_L11:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":395
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u0, t2v0)
 *     glVertex2f(x0, y0)             # <<<<<<<<<<<<<<
 * 
 *     if has_tex0:
 */
  glVertex2f(__pyx_v_x0, __pyx_v_y0);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":397
 *     glVertex2f(x0, y0)
 * 
 *     if has_tex0:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u1, t0v0)
 *     if has_tex1:
 */
  __pyx_t_5 = __pyx_v_has_tex0;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":398
 * 
 *     if has_tex0:
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u1, t0v0)             # <<<<<<<<<<<<<<
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v0)
 */
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, __pyx_v_t0u1, __pyx_v_t0v0);
    goto __pyx_L12;
  }
  __pyx_L12:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":399
 *     if has_tex0:
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u1, t0v0)
 *     if has_tex1:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v0)
 *     if has_tex2:
 */
  __pyx_t_5 = __pyx_v_has_tex1;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":400
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u1, t0v0)
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v0)             # <<<<<<<<<<<<<<
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u1, t2v0)
 */
    glMultiTexCoord2fARB(GL_TEXTURE1_ARB, __pyx_v_t1u1, __pyx_v_t1v0);
    goto __pyx_L13;
  }
  __pyx_L13:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":401
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v0)
 *     if has_tex2:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u1, t2v0)
 *     glVertex2f(x1, y1)
 */
  __pyx_t_5 = __pyx_v_has_tex2;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":402
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v0)
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u1, t2v0)             # <<<<<<<<<<<<<<
 *     glVertex2f(x1, y1)
 * 
 */
    glMultiTexCoord2fARB(GL_TEXTURE2_ARB, __pyx_v_t2u1, __pyx_v_t2v0);
    goto __pyx_L14;
  }
  __pyx_L14:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":403
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u1, t2v0)
 *     glVertex2f(x1, y1)             # <<<<<<<<<<<<<<
 * 
 *     if has_tex0:
 */
  glVertex2f(__pyx_v_x1, __pyx_v_y1);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":405
 *     glVertex2f(x1, y1)
 * 
 *     if has_tex0:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u0, t0v1)
 *     if has_tex1:
 */
  __pyx_t_5 = __pyx_v_has_tex0;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":406
 * 
 *     if has_tex0:
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u0, t0v1)             # <<<<<<<<<<<<<<
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v1)
 */
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, __pyx_v_t0u0, __pyx_v_t0v1);
    goto __pyx_L15;
  }
  __pyx_L15:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":407
 *     if has_tex0:
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u0, t0v1)
 *     if has_tex1:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v1)
 *     if has_tex2:
 */
  __pyx_t_5 = __pyx_v_has_tex1;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":408
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u0, t0v1)
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v1)             # <<<<<<<<<<<<<<
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u0, t2v1)
 */
    glMultiTexCoord2fARB(GL_TEXTURE1_ARB, __pyx_v_t1u0, __pyx_v_t1v1);
    goto __pyx_L16;
  }
  __pyx_L16:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":409
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v1)
 *     if has_tex2:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u0, t2v1)
 *     glVertex2f(x2, y2)
 */
  __pyx_t_5 = __pyx_v_has_tex2;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":410
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u0, t1v1)
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u0, t2v1)             # <<<<<<<<<<<<<<
 *     glVertex2f(x2, y2)
 * 
 */
    glMultiTexCoord2fARB(GL_TEXTURE2_ARB, __pyx_v_t2u0, __pyx_v_t2v1);
    goto __pyx_L17;
  }
  __pyx_L17:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":411
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u0, t2v1)
 *     glVertex2f(x2, y2)             # <<<<<<<<<<<<<<
 * 
 *     if has_tex0:
 */
  glVertex2f(__pyx_v_x2, __pyx_v_y2);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":413
 *     glVertex2f(x2, y2)
 * 
 *     if has_tex0:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u1, t0v1)
 *     if has_tex1:
 */
  __pyx_t_5 = __pyx_v_has_tex0;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":414
 * 
 *     if has_tex0:
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u1, t0v1)             # <<<<<<<<<<<<<<
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v1)
 */
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, __pyx_v_t0u1, __pyx_v_t0v1);
    goto __pyx_L18;
  }
  __pyx_L18:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":415
 *     if has_tex0:
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u1, t0v1)
 *     if has_tex1:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v1)
 *     if has_tex2:
 */
  __pyx_t_5 = __pyx_v_has_tex1;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":416
 *         glMultiTexCoord2fARB(GL_TEXTURE0_ARB, t0u1, t0v1)
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v1)             # <<<<<<<<<<<<<<
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u1, t2v1)
 */
    glMultiTexCoord2fARB(GL_TEXTURE1_ARB, __pyx_v_t1u1, __pyx_v_t1v1);
    goto __pyx_L19;
  }
  __pyx_L19:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":417
 *     if has_tex1:
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v1)
 *     if has_tex2:             # <<<<<<<<<<<<<<
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u1, t2v1)
 *     glVertex2f(x3, y3)
 */
  __pyx_t_5 = __pyx_v_has_tex2;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":418
 *         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t1u1, t1v1)
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u1, t2v1)             # <<<<<<<<<<<<<<
 *     glVertex2f(x3, y3)
 * 
 */
    glMultiTexCoord2fARB(GL_TEXTURE2_ARB, __pyx_v_t2u1, __pyx_v_t2v1);
    goto __pyx_L20;
  }
  __pyx_L20:;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":419
 *     if has_tex2:
 *         glMultiTexCoord2fARB(GL_TEXTURE2_ARB, t2u1, t2v1)
 *     glVertex2f(x3, y3)             # <<<<<<<<<<<<<<
 * 
 *     glEnd()
 */
  glVertex2f(__pyx_v_x3, __pyx_v_y3);

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":421
 *     glVertex2f(x3, y3)
 * 
 *     glEnd()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  glEnd();

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_renpy_pysdlgl.draw_rectangle");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_transform);
  __Pyx_DECREF(__pyx_v_tex0);
  __Pyx_DECREF(__pyx_v_tex1);
  __Pyx_DECREF(__pyx_v_tex2);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":424
 * 
 * 
 * def get_string(name):             # <<<<<<<<<<<<<<
 *     return <char *> glGetString(name)
 */

static PyObject *__pyx_pf_14_renpy_pysdlgl_get_string(PyObject *__pyx_self, PyObject *__pyx_v_name); /*proto*/
static PyObject *__pyx_pf_14_renpy_pysdlgl_get_string(PyObject *__pyx_self, PyObject *__pyx_v_name) {
  PyObject *__pyx_r = NULL;
  GLenum __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_string");
  __pyx_self = __pyx_self;

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":425
 * 
 * def get_string(name):
 *     return <char *> glGetString(name)             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_from_py_GLenum(__pyx_v_name); if (unlikely((__pyx_t_1 == (GLenum)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyBytes_FromString(((char *)glGetString(__pyx_t_1))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_renpy_pysdlgl.get_string");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static struct PyMethodDef __pyx_methods[] = {
  {__Pyx_NAMESTR("init_glew"), (PyCFunction)__pyx_pf_14_renpy_pysdlgl_init_glew, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("premultiply"), (PyCFunction)__pyx_pf_14_renpy_pysdlgl_premultiply, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14_renpy_pysdlgl_premultiply)},
  {__Pyx_NAMESTR("load_premultiplied"), (PyCFunction)__pyx_pf_14_renpy_pysdlgl_load_premultiplied, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("store_framebuffer"), (PyCFunction)__pyx_pf_14_renpy_pysdlgl_store_framebuffer, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14_renpy_pysdlgl_store_framebuffer)},
  {__Pyx_NAMESTR("draw_rectangle"), (PyCFunction)__pyx_pf_14_renpy_pysdlgl_draw_rectangle, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14_renpy_pysdlgl_draw_rectangle)},
  {__Pyx_NAMESTR("get_string"), (PyCFunction)__pyx_pf_14_renpy_pysdlgl_get_string, METH_O, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("_renpy_pysdlgl"),
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_u_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 1, 0, 0},
  {&__pyx_kp_u_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 1, 0, 0},
  {&__pyx_kp_u_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 1, 0, 0},
  {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s__border_bottom, __pyx_k__border_bottom, sizeof(__pyx_k__border_bottom), 0, 0, 1, 1},
  {&__pyx_n_s__border_left, __pyx_k__border_left, sizeof(__pyx_k__border_left), 0, 0, 1, 1},
  {&__pyx_n_s__border_right, __pyx_k__border_right, sizeof(__pyx_k__border_right), 0, 0, 1, 1},
  {&__pyx_n_s__border_top, __pyx_k__border_top, sizeof(__pyx_k__border_top), 0, 0, 1, 1},
  {&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1},
  {&__pyx_n_s__draw_rectangle, __pyx_k__draw_rectangle, sizeof(__pyx_k__draw_rectangle), 0, 0, 1, 1},
  {&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1},
  {&__pyx_n_s__get_masks, __pyx_k__get_masks, sizeof(__pyx_k__get_masks), 0, 0, 1, 1},
  {&__pyx_n_s__h, __pyx_k__h, sizeof(__pyx_k__h), 0, 0, 1, 1},
  {&__pyx_n_s__height, __pyx_k__height, sizeof(__pyx_k__height), 0, 0, 1, 1},
  {&__pyx_n_s__number, __pyx_k__number, sizeof(__pyx_k__number), 0, 0, 1, 1},
  {&__pyx_n_s__pitch, __pyx_k__pitch, sizeof(__pyx_k__pitch), 0, 0, 1, 1},
  {&__pyx_n_s__pixels, __pyx_k__pixels, sizeof(__pyx_k__pixels), 0, 0, 1, 1},
  {&__pyx_n_s__premultiply, __pyx_k__premultiply, sizeof(__pyx_k__premultiply), 0, 0, 1, 1},
  {&__pyx_n_s__pysurf, __pyx_k__pysurf, sizeof(__pyx_k__pysurf), 0, 0, 1, 1},
  {&__pyx_n_s__store_framebuffer, __pyx_k__store_framebuffer, sizeof(__pyx_k__store_framebuffer), 0, 0, 1, 1},
  {&__pyx_n_s__sx, __pyx_k__sx, sizeof(__pyx_k__sx), 0, 0, 1, 1},
  {&__pyx_n_s__sy, __pyx_k__sy, sizeof(__pyx_k__sy), 0, 0, 1, 1},
  {&__pyx_n_s__tex0, __pyx_k__tex0, sizeof(__pyx_k__tex0), 0, 0, 1, 1},
  {&__pyx_n_s__tex0x, __pyx_k__tex0x, sizeof(__pyx_k__tex0x), 0, 0, 1, 1},
  {&__pyx_n_s__tex0y, __pyx_k__tex0y, sizeof(__pyx_k__tex0y), 0, 0, 1, 1},
  {&__pyx_n_s__tex1, __pyx_k__tex1, sizeof(__pyx_k__tex1), 0, 0, 1, 1},
  {&__pyx_n_s__tex1x, __pyx_k__tex1x, sizeof(__pyx_k__tex1x), 0, 0, 1, 1},
  {&__pyx_n_s__tex1y, __pyx_k__tex1y, sizeof(__pyx_k__tex1y), 0, 0, 1, 1},
  {&__pyx_n_s__tex2, __pyx_k__tex2, sizeof(__pyx_k__tex2), 0, 0, 1, 1},
  {&__pyx_n_s__tex2x, __pyx_k__tex2x, sizeof(__pyx_k__tex2x), 0, 0, 1, 1},
  {&__pyx_n_s__tex2y, __pyx_k__tex2y, sizeof(__pyx_k__tex2y), 0, 0, 1, 1},
  {&__pyx_n_s__transform, __pyx_k__transform, sizeof(__pyx_k__transform), 0, 0, 1, 1},
  {&__pyx_n_s__update, __pyx_k__update, sizeof(__pyx_k__update), 0, 0, 1, 1},
  {&__pyx_n_s__w, __pyx_k__w, sizeof(__pyx_k__w), 0, 0, 1, 1},
  {&__pyx_n_s__width, __pyx_k__width, sizeof(__pyx_k__width), 0, 0, 1, 1},
  {&__pyx_n_s__x, __pyx_k__x, sizeof(__pyx_k__x), 0, 0, 1, 1},
  {&__pyx_n_s__xadd, __pyx_k__xadd, sizeof(__pyx_k__xadd), 0, 0, 1, 1},
  {&__pyx_n_s__xdx, __pyx_k__xdx, sizeof(__pyx_k__xdx), 0, 0, 1, 1},
  {&__pyx_n_s__xdy, __pyx_k__xdy, sizeof(__pyx_k__xdy), 0, 0, 1, 1},
  {&__pyx_n_s__xmul, __pyx_k__xmul, sizeof(__pyx_k__xmul), 0, 0, 1, 1},
  {&__pyx_n_s__y, __pyx_k__y, sizeof(__pyx_k__y), 0, 0, 1, 1},
  {&__pyx_n_s__yadd, __pyx_k__yadd, sizeof(__pyx_k__yadd), 0, 0, 1, 1},
  {&__pyx_n_s__ydx, __pyx_k__ydx, sizeof(__pyx_k__ydx), 0, 0, 1, 1},
  {&__pyx_n_s__ydy, __pyx_k__ydy, sizeof(__pyx_k__ydy), 0, 0, 1, 1},
  {&__pyx_n_s__ymul, __pyx_k__ymul, sizeof(__pyx_k__ymul), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_renpy_pysdlgl(void); /*proto*/
PyMODINIT_FUNC init_renpy_pysdlgl(void)
#else
PyMODINIT_FUNC PyInit__renpy_pysdlgl(void); /*proto*/
PyMODINIT_FUNC PyInit__renpy_pysdlgl(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  #if CYTHON_REFNANNY
  void* __pyx_refnanny = NULL;
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit__renpy_pysdlgl(void)", __LINE__, __FILE__);
  #endif
  __pyx_init_filenames();
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION < 3
  __pyx_empty_bytes = PyString_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #else
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_renpy_pysdlgl"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main__renpy_pysdlgl) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/home/tom/ab/renpy/module/_renpy_pysdlgl.pyx":1
 * # This file contains bindings to integrate pygame (SDL) and OpenGL.             # <<<<<<<<<<<<<<
 * 
 * cdef extern from "pygame/pygame.h":
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__premultiply); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__");
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_2), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__store_framebuffer); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_3), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__draw_rectangle); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__");
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_4), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    __Pyx_AddTraceback("init _renpy_pysdlgl");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init _renpy_pysdlgl");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

static const char *__pyx_filenames[] = {
  "_renpy_pysdlgl.pyx",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AS_STRING(kw_name));
        #endif
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *more_or_less;

    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}


static INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

static INLINE PyObject *__Pyx_PyInt_to_py_GLenum(GLenum val) {
    const GLenum neg_one = (GLenum)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(GLenum) <  sizeof(long)) {
        return PyInt_FromLong((long)val);
    } else if (sizeof(GLenum) == sizeof(long)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else { /* (sizeof(GLenum) > sizeof(long)) */
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    }
}

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

static INLINE GLenum __Pyx_PyInt_from_py_GLenum(PyObject* x) {
    const GLenum neg_one = (GLenum)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(GLenum) == sizeof(char)) {
        if (is_unsigned)
            return (GLenum)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (GLenum)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(GLenum) == sizeof(short)) {
        if (is_unsigned)
            return (GLenum)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (GLenum)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(GLenum) == sizeof(int)) {
        if (is_unsigned)
            return (GLenum)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (GLenum)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(GLenum) == sizeof(long)) {
        if (is_unsigned)
            return (GLenum)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (GLenum)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(GLenum) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (GLenum)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (GLenum)__Pyx_PyInt_AsSignedLongLong(x);
#if 0
    } else if (sizeof(GLenum) > sizeof(short) &&
               sizeof(GLenum) < sizeof(int)) { /*  __int32 ILP64 ? */
        if (is_unsigned)
            return (GLenum)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (GLenum)__Pyx_PyInt_AsSignedInt(x);
#endif
    }
    PyErr_SetString(PyExc_TypeError, "GLenum");
    return (GLenum)-1;
}

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(type);
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }

    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

#else /* Python 3+ */

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;

    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (!PyExceptionClass_Check(type)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }

    PyErr_SetObject(type, value);

    if (tb) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }

bad:
    return;
}
#endif

static INLINE GLsizei __Pyx_PyInt_from_py_GLsizei(PyObject* x) {
    const GLsizei neg_one = (GLsizei)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(GLsizei) == sizeof(char)) {
        if (is_unsigned)
            return (GLsizei)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (GLsizei)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(GLsizei) == sizeof(short)) {
        if (is_unsigned)
            return (GLsizei)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (GLsizei)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(GLsizei) == sizeof(int)) {
        if (is_unsigned)
            return (GLsizei)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (GLsizei)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(GLsizei) == sizeof(long)) {
        if (is_unsigned)
            return (GLsizei)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (GLsizei)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(GLsizei) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (GLsizei)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (GLsizei)__Pyx_PyInt_AsSignedLongLong(x);
#if 0
    } else if (sizeof(GLsizei) > sizeof(short) &&
               sizeof(GLsizei) < sizeof(int)) { /*  __int32 ILP64 ? */
        if (is_unsigned)
            return (GLsizei)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (GLsizei)__Pyx_PyInt_AsSignedInt(x);
#endif
    }
    PyErr_SetString(PyExc_TypeError, "GLsizei");
    return (GLsizei)-1;
}

static INLINE GLuint __Pyx_PyInt_from_py_GLuint(PyObject* x) {
    const GLuint neg_one = (GLuint)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(GLuint) == sizeof(char)) {
        if (is_unsigned)
            return (GLuint)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (GLuint)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(GLuint) == sizeof(short)) {
        if (is_unsigned)
            return (GLuint)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (GLuint)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(GLuint) == sizeof(int)) {
        if (is_unsigned)
            return (GLuint)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (GLuint)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(GLuint) == sizeof(long)) {
        if (is_unsigned)
            return (GLuint)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (GLuint)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(GLuint) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (GLuint)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (GLuint)__Pyx_PyInt_AsSignedLongLong(x);
#if 0
    } else if (sizeof(GLuint) > sizeof(short) &&
               sizeof(GLuint) < sizeof(int)) { /*  __int32 ILP64 ? */
        if (is_unsigned)
            return (GLuint)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (GLuint)__Pyx_PyInt_AsSignedInt(x);
#endif
    }
    PyErr_SetString(PyExc_TypeError, "GLuint");
    return (GLuint)-1;
}

static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   if (x == Py_True) return 1;
   else if ((x == Py_False) | (x == Py_None)) return 0;
   else return PyObject_IsTrue(x);
}

static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
