Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commit f164e380e3eb63e974485759a51e5e60612d13a4
- Author: gabriel pettier <dev@tangibledisplay.com>
- Date: Wed Jan 18 03:45:23 2017 +0100
- revert matham-mesh merge
- diff --git a/kivy/graphics/common.pxi b/kivy/graphics/common.pxi
- index f4d098cc6..224115971 100644
- --- a/kivy/graphics/common.pxi
- +++ b/kivy/graphics/common.pxi
- @@ -29,4 +29,3 @@ cdef extern from "stdlib.h":
- cdef extern from "string.h":
- void *memcpy(void *dest, void *src, size_t n) nogil
- void *memset(void *dest, int c, size_t len)
- -
- diff --git a/kivy/graphics/memory.pxi b/kivy/graphics/memory.pxi
- deleted file mode 100644
- index ac3dd2de8..000000000
- --- a/kivy/graphics/memory.pxi
- +++ /dev/null
- @@ -1,74 +0,0 @@
- -from cpython.array cimport array, clone
- -
- -
- -'''
- -These functions below, take a data element; if the data implements the
- -buffer interface, the data is returned unchanged, otherwise, a python
- -array is created from the data and returned.
- -
- -in both cases, the second parameter is initialized with a pointer to the
- -starting address of the returned buffer
- -
- -The return value is a tuple, of (original data, array), where in the first
- -case, array is None.
- -
- -The method used below (a untyped python array + array.data.as_floats pointer)
- -results in the fastest list to array creation and usage. Even malloc isn't
- -faster. Note, using memoryview (which we avoided for this case) is relatively
- -slow in cython.
- -
- -When the user passes in a memoryview type, we have no choice but to use the
- -memoryview passed in, though.
- -'''
- -cdef inline _ensure_float_view(data, float **f):
- - cdef array arr
- - cdef list src
- - cdef int i
- - cdef float [::1] memview
- - # do if/else instead of straight try/except because its faster for list
- - if not isinstance(data, (tuple, list)):
- - try:
- - memview = data
- - f[0] = &memview[0]
- - return data, None
- - except Exception as e:
- - import traceback; traceback.print_exc()
- - src = list(data)
- - arr = clone(array('f'), len(src), False)
- - f[0] = arr.data.as_floats
- - for i in range(len(src)):
- - f[0][i] = src[i]
- - else:
- - src = list(data)
- - arr = clone(array('f'), len(src), False)
- - f[0] = arr.data.as_floats
- - for i in range(len(src)):
- - f[0][i] = src[i]
- - return src, arr
- -
- -
- -cdef inline _ensure_ushort_view(data, unsigned short **f):
- - cdef array arr
- - cdef list src
- - cdef int i
- - cdef unsigned short [::1] memview
- - # do if/else instead of straight try/except because its faster for list
- - if not isinstance(data, (tuple, list)):
- - try:
- - memview = data
- - f[0] = &memview[0]
- - return data, None
- - except:
- - src = list(data)
- - arr = clone(array('H'), len(src), False)
- - f[0] = arr.data.as_ushorts
- - for i in range(len(src)):
- - f[0][i] = src[i]
- - else:
- - src = list(data)
- - arr = clone(array('H'), len(src), False)
- - f[0] = arr.data.as_ushorts
- - for i in range(len(src)):
- - f[0][i] = src[i]
- - return src, arr
- -
- diff --git a/kivy/graphics/vertex_instructions.pxd b/kivy/graphics/vertex_instructions.pxd
- index 81ac343ac..6bd272ad7 100644
- --- a/kivy/graphics/vertex_instructions.pxd
- +++ b/kivy/graphics/vertex_instructions.pxd
- @@ -19,16 +19,10 @@ cdef class StripMesh(VertexInstruction):
- cdef class Mesh(VertexInstruction):
- - cdef int is_built
- - cdef object _vertices # the object the user passed in
- - cdef object _indices
- - cdef object _fvertices # a buffer interface passed by user, or created
- - cdef object _lindices
- - cdef float *_pvertices # the pointer to the start of buffer interface data
- - cdef unsigned short *_pindices
- + cdef list _vertices
- + cdef list _indices
- cdef VertexFormat vertex_format
- - cdef long vcount # the length of last set _vertices
- - cdef long icount # the length of last set _indices
- + cdef int is_built
- cdef void build_triangle_fan(self, float *vertices, int vcount, int icount)
- cdef void build(self)
- diff --git a/kivy/graphics/vertex_instructions.pyx b/kivy/graphics/vertex_instructions.pyx
- index f06a8fb14..67448fcc3 100644
- --- a/kivy/graphics/vertex_instructions.pyx
- +++ b/kivy/graphics/vertex_instructions.pyx
- @@ -57,7 +57,6 @@ __all__ = ('Triangle', 'Quad', 'Rectangle', 'RoundedRectangle', 'BorderImage', '
- include "config.pxi"
- include "common.pxi"
- -include "memory.pxi"
- from os import environ
- from kivy.graphics.vbo cimport *
- @@ -347,9 +346,9 @@ cdef class Mesh(VertexInstruction):
- .. versionadded:: 1.1.0
- :Parameters:
- - `vertices`: iterable
- + `vertices`: list
- List of vertices in the format (x1, y1, u1, v1, x2, y2, u2, v2...).
- - `indices`: iterable
- + `indices`: list
- List of indices in the format (i1, i2, i3...).
- `mode`: str
- Mode of the vbo. Check :attr:`mode` for more information. Defaults to
- @@ -371,21 +370,6 @@ cdef class Mesh(VertexInstruction):
- attribute vec2 v_tc;
- in glsl's vertex shader.
- -
- - .. versionchanged:: 1.8.1
- - Before, `vertices` and `indices` would always be converted to a list,
- - now, they are only converted to a list if they do not implement the
- - buffer interface. So e.g. numpy arrays, python arrays etc. are used
- - in place, without creating any additional copies. However, the
- - buffers cannot be readonly (even though they are not changed, due to
- - a cython limitation) and must be contiguous in memory.
- -
- - .. note::
- - When passing a memoryview or a instance that implements the buffer
- - interface, `vertices` should be a buffer of floats (`'f'` code in
- - python array) and `indices` should be a buffer of unsigned short (`'H'`
- - code in python array). Arrays in other formats will still have to be
- - converted internally, negating any potential gain.
- '''
- def __init__(self, **kwargs):
- @@ -432,37 +416,37 @@ cdef class Mesh(VertexInstruction):
- cdef void build(self):
- if self.is_built:
- return
- + cdef int i
- + cdef long vcount = len(self._vertices)
- + cdef long icount = len(self._indices)
- + cdef float *vertices = NULL
- + cdef unsigned short *indices = NULL
- + cdef list lvertices = self._vertices
- + cdef list lindices = self._indices
- cdef vsize = self.batch.vbo.vertex_format.vsize
- - # if user updated the list, but didn't do self.indices = ... then
- - # we'd not know about it, so ensure _indices/_indices is up to date
- - if len(self._vertices) != self.vcount:
- - self._vertices, self._fvertices = _ensure_float_view(self._vertices,
- - &self._pvertices)
- - self.vcount = len(self._vertices)
- -
- - if len(self._indices) != self.icount:
- - if len(self._indices) > 65535:
- - raise GraphicException('Cannot upload more than 65535 indices'
- - '(OpenGL ES 2 limitation)')
- - self._indices, self._lindices = _ensure_ushort_view(self._indices,
- - &self._pindices)
- - self.icount = len(self._indices)
- -
- - if any([x > self.vcount for x in self._indices]):
- - raise GraphicException('indice superior to vcount! {}: {}' % (
- - self.vcount, self._indices))
- -
- - if self.vcount == 0 or self.icount == 0:
- + if vcount == 0 or icount == 0:
- self.batch.clear_data()
- return
- - if any([x > self.vcount for x in self._indices]):
- - print("error")
- - raise GraphicException('invalid indices in Mesh, superior to vertice count')
- + vertices = <float *>malloc(vcount * sizeof(float))
- + if vertices == NULL:
- + raise MemoryError('vertices')
- - self.batch.set_data(&self._pvertices[0], <int>(self.vcount / vsize),
- - &self._pindices[0], <int>self.icount)
- + indices = <unsigned short *>malloc(icount * sizeof(unsigned short))
- + if indices == NULL:
- + free(vertices)
- + raise MemoryError('indices')
- +
- + for i in xrange(vcount):
- + vertices[i] = lvertices[i]
- + for i in xrange(icount):
- + indices[i] = lindices[i]
- +
- + self.batch.set_data(vertices, <int>(vcount / vsize), indices, <int>icount)
- +
- + free(vertices)
- + free(indices)
- property vertices:
- '''List of x, y, u, v coordinates used to construct the Mesh. Right now,
- @@ -472,9 +456,7 @@ cdef class Mesh(VertexInstruction):
- def __get__(self):
- return self._vertices
- def __set__(self, value):
- - self._vertices, self._fvertices = _ensure_float_view(value,
- - &self._pvertices)
- - self.vcount = len(self._vertices)
- + self._vertices = list(value)
- self.flag_update()
- property indices:
- @@ -488,9 +470,7 @@ cdef class Mesh(VertexInstruction):
- raise GraphicException(
- 'Cannot upload more than 65535 indices (OpenGL ES 2'
- ' limitation - consider setting KIVY_GLES_LIMITS)')
- - self._indices, self._lindices = _ensure_ushort_view(value,
- - &self._pindices)
- - self.icount = len(self._indices)
- + self._indices = list(value)
- self.flag_update()
- property mode:
Add Comment
Please, Sign In to add comment