Guest User

Untitled

a guest
Oct 24th, 2017
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.38 KB | None | 0 0
  1. commit f164e380e3eb63e974485759a51e5e60612d13a4
  2. Author: gabriel pettier <dev@tangibledisplay.com>
  3. Date: Wed Jan 18 03:45:23 2017 +0100
  4.  
  5. revert matham-mesh merge
  6.  
  7. diff --git a/kivy/graphics/common.pxi b/kivy/graphics/common.pxi
  8. index f4d098cc6..224115971 100644
  9. --- a/kivy/graphics/common.pxi
  10. +++ b/kivy/graphics/common.pxi
  11. @@ -29,4 +29,3 @@ cdef extern from "stdlib.h":
  12. cdef extern from "string.h":
  13. void *memcpy(void *dest, void *src, size_t n) nogil
  14. void *memset(void *dest, int c, size_t len)
  15. -
  16. diff --git a/kivy/graphics/memory.pxi b/kivy/graphics/memory.pxi
  17. deleted file mode 100644
  18. index ac3dd2de8..000000000
  19. --- a/kivy/graphics/memory.pxi
  20. +++ /dev/null
  21. @@ -1,74 +0,0 @@
  22. -from cpython.array cimport array, clone
  23. -
  24. -
  25. -'''
  26. -These functions below, take a data element; if the data implements the
  27. -buffer interface, the data is returned unchanged, otherwise, a python
  28. -array is created from the data and returned.
  29. -
  30. -in both cases, the second parameter is initialized with a pointer to the
  31. -starting address of the returned buffer
  32. -
  33. -The return value is a tuple, of (original data, array), where in the first
  34. -case, array is None.
  35. -
  36. -The method used below (a untyped python array + array.data.as_floats pointer)
  37. -results in the fastest list to array creation and usage. Even malloc isn't
  38. -faster. Note, using memoryview (which we avoided for this case) is relatively
  39. -slow in cython.
  40. -
  41. -When the user passes in a memoryview type, we have no choice but to use the
  42. -memoryview passed in, though.
  43. -'''
  44. -cdef inline _ensure_float_view(data, float **f):
  45. - cdef array arr
  46. - cdef list src
  47. - cdef int i
  48. - cdef float [::1] memview
  49. - # do if/else instead of straight try/except because its faster for list
  50. - if not isinstance(data, (tuple, list)):
  51. - try:
  52. - memview = data
  53. - f[0] = &memview[0]
  54. - return data, None
  55. - except Exception as e:
  56. - import traceback; traceback.print_exc()
  57. - src = list(data)
  58. - arr = clone(array('f'), len(src), False)
  59. - f[0] = arr.data.as_floats
  60. - for i in range(len(src)):
  61. - f[0][i] = src[i]
  62. - else:
  63. - src = list(data)
  64. - arr = clone(array('f'), len(src), False)
  65. - f[0] = arr.data.as_floats
  66. - for i in range(len(src)):
  67. - f[0][i] = src[i]
  68. - return src, arr
  69. -
  70. -
  71. -cdef inline _ensure_ushort_view(data, unsigned short **f):
  72. - cdef array arr
  73. - cdef list src
  74. - cdef int i
  75. - cdef unsigned short [::1] memview
  76. - # do if/else instead of straight try/except because its faster for list
  77. - if not isinstance(data, (tuple, list)):
  78. - try:
  79. - memview = data
  80. - f[0] = &memview[0]
  81. - return data, None
  82. - except:
  83. - src = list(data)
  84. - arr = clone(array('H'), len(src), False)
  85. - f[0] = arr.data.as_ushorts
  86. - for i in range(len(src)):
  87. - f[0][i] = src[i]
  88. - else:
  89. - src = list(data)
  90. - arr = clone(array('H'), len(src), False)
  91. - f[0] = arr.data.as_ushorts
  92. - for i in range(len(src)):
  93. - f[0][i] = src[i]
  94. - return src, arr
  95. -
  96. diff --git a/kivy/graphics/vertex_instructions.pxd b/kivy/graphics/vertex_instructions.pxd
  97. index 81ac343ac..6bd272ad7 100644
  98. --- a/kivy/graphics/vertex_instructions.pxd
  99. +++ b/kivy/graphics/vertex_instructions.pxd
  100. @@ -19,16 +19,10 @@ cdef class StripMesh(VertexInstruction):
  101.  
  102.  
  103. cdef class Mesh(VertexInstruction):
  104. - cdef int is_built
  105. - cdef object _vertices # the object the user passed in
  106. - cdef object _indices
  107. - cdef object _fvertices # a buffer interface passed by user, or created
  108. - cdef object _lindices
  109. - cdef float *_pvertices # the pointer to the start of buffer interface data
  110. - cdef unsigned short *_pindices
  111. + cdef list _vertices
  112. + cdef list _indices
  113. cdef VertexFormat vertex_format
  114. - cdef long vcount # the length of last set _vertices
  115. - cdef long icount # the length of last set _indices
  116. + cdef int is_built
  117.  
  118. cdef void build_triangle_fan(self, float *vertices, int vcount, int icount)
  119. cdef void build(self)
  120. diff --git a/kivy/graphics/vertex_instructions.pyx b/kivy/graphics/vertex_instructions.pyx
  121. index f06a8fb14..67448fcc3 100644
  122. --- a/kivy/graphics/vertex_instructions.pyx
  123. +++ b/kivy/graphics/vertex_instructions.pyx
  124. @@ -57,7 +57,6 @@ __all__ = ('Triangle', 'Quad', 'Rectangle', 'RoundedRectangle', 'BorderImage', '
  125.  
  126. include "config.pxi"
  127. include "common.pxi"
  128. -include "memory.pxi"
  129.  
  130. from os import environ
  131. from kivy.graphics.vbo cimport *
  132. @@ -347,9 +346,9 @@ cdef class Mesh(VertexInstruction):
  133. .. versionadded:: 1.1.0
  134.  
  135. :Parameters:
  136. - `vertices`: iterable
  137. + `vertices`: list
  138. List of vertices in the format (x1, y1, u1, v1, x2, y2, u2, v2...).
  139. - `indices`: iterable
  140. + `indices`: list
  141. List of indices in the format (i1, i2, i3...).
  142. `mode`: str
  143. Mode of the vbo. Check :attr:`mode` for more information. Defaults to
  144. @@ -371,21 +370,6 @@ cdef class Mesh(VertexInstruction):
  145. attribute vec2 v_tc;
  146.  
  147. in glsl's vertex shader.
  148. -
  149. - .. versionchanged:: 1.8.1
  150. - Before, `vertices` and `indices` would always be converted to a list,
  151. - now, they are only converted to a list if they do not implement the
  152. - buffer interface. So e.g. numpy arrays, python arrays etc. are used
  153. - in place, without creating any additional copies. However, the
  154. - buffers cannot be readonly (even though they are not changed, due to
  155. - a cython limitation) and must be contiguous in memory.
  156. -
  157. - .. note::
  158. - When passing a memoryview or a instance that implements the buffer
  159. - interface, `vertices` should be a buffer of floats (`'f'` code in
  160. - python array) and `indices` should be a buffer of unsigned short (`'H'`
  161. - code in python array). Arrays in other formats will still have to be
  162. - converted internally, negating any potential gain.
  163. '''
  164.  
  165. def __init__(self, **kwargs):
  166. @@ -432,37 +416,37 @@ cdef class Mesh(VertexInstruction):
  167. cdef void build(self):
  168. if self.is_built:
  169. return
  170. + cdef int i
  171. + cdef long vcount = len(self._vertices)
  172. + cdef long icount = len(self._indices)
  173. + cdef float *vertices = NULL
  174. + cdef unsigned short *indices = NULL
  175. + cdef list lvertices = self._vertices
  176. + cdef list lindices = self._indices
  177. cdef vsize = self.batch.vbo.vertex_format.vsize
  178.  
  179. - # if user updated the list, but didn't do self.indices = ... then
  180. - # we'd not know about it, so ensure _indices/_indices is up to date
  181. - if len(self._vertices) != self.vcount:
  182. - self._vertices, self._fvertices = _ensure_float_view(self._vertices,
  183. - &self._pvertices)
  184. - self.vcount = len(self._vertices)
  185. -
  186. - if len(self._indices) != self.icount:
  187. - if len(self._indices) > 65535:
  188. - raise GraphicException('Cannot upload more than 65535 indices'
  189. - '(OpenGL ES 2 limitation)')
  190. - self._indices, self._lindices = _ensure_ushort_view(self._indices,
  191. - &self._pindices)
  192. - self.icount = len(self._indices)
  193. -
  194. - if any([x > self.vcount for x in self._indices]):
  195. - raise GraphicException('indice superior to vcount! {}: {}' % (
  196. - self.vcount, self._indices))
  197. -
  198. - if self.vcount == 0 or self.icount == 0:
  199. + if vcount == 0 or icount == 0:
  200. self.batch.clear_data()
  201. return
  202.  
  203. - if any([x > self.vcount for x in self._indices]):
  204. - print("error")
  205. - raise GraphicException('invalid indices in Mesh, superior to vertice count')
  206. + vertices = <float *>malloc(vcount * sizeof(float))
  207. + if vertices == NULL:
  208. + raise MemoryError('vertices')
  209.  
  210. - self.batch.set_data(&self._pvertices[0], <int>(self.vcount / vsize),
  211. - &self._pindices[0], <int>self.icount)
  212. + indices = <unsigned short *>malloc(icount * sizeof(unsigned short))
  213. + if indices == NULL:
  214. + free(vertices)
  215. + raise MemoryError('indices')
  216. +
  217. + for i in xrange(vcount):
  218. + vertices[i] = lvertices[i]
  219. + for i in xrange(icount):
  220. + indices[i] = lindices[i]
  221. +
  222. + self.batch.set_data(vertices, <int>(vcount / vsize), indices, <int>icount)
  223. +
  224. + free(vertices)
  225. + free(indices)
  226.  
  227. property vertices:
  228. '''List of x, y, u, v coordinates used to construct the Mesh. Right now,
  229. @@ -472,9 +456,7 @@ cdef class Mesh(VertexInstruction):
  230. def __get__(self):
  231. return self._vertices
  232. def __set__(self, value):
  233. - self._vertices, self._fvertices = _ensure_float_view(value,
  234. - &self._pvertices)
  235. - self.vcount = len(self._vertices)
  236. + self._vertices = list(value)
  237. self.flag_update()
  238.  
  239. property indices:
  240. @@ -488,9 +470,7 @@ cdef class Mesh(VertexInstruction):
  241. raise GraphicException(
  242. 'Cannot upload more than 65535 indices (OpenGL ES 2'
  243. ' limitation - consider setting KIVY_GLES_LIMITS)')
  244. - self._indices, self._lindices = _ensure_ushort_view(value,
  245. - &self._pindices)
  246. - self.icount = len(self._indices)
  247. + self._indices = list(value)
  248. self.flag_update()
  249.  
  250. property mode:
Add Comment
Please, Sign In to add comment