-
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy patharray.py
More file actions
85 lines (59 loc) · 2.28 KB
/
array.py
File metadata and controls
85 lines (59 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -----------------------------------------------------------------------------
# Copyright (c) 2009-2016 Nicolas P. Rougier. All rights reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
"""
Vertex Array objects are OpenGL objects that store all of the state needed
to supply vertex data. Only available from GL > 3.2.
Read more on buffer objects on `OpenGL Wiki
<https://www.opengl.org/wiki/Vertex_Specification>`_
**Example usage**:
.. code:: python
dtype = [("position", np.float32, 3),
("color", np.float32, 4)]
V = np.zeros(4,dtype).view(gloo.VertexArray)
"""
import numpy as np
from glumpy import gl
from glumpy.log import log
from glumpy.gloo.gpudata import GPUData
from glumpy.gloo.globject import GLObject
from glumpy.gloo.buffer import VertexBuffer
class VertexArray(GPUData,GLObject):
"""
Vertex array.
A vertex array is an interface used to specify vertex data structure.
"""
def __init__(self, usage=gl.GL_DYNAMIC_DRAW):
GLObject.__init__(self)
self._target = gl.GL_ARRAY_BUFFER
self._buffer = self.view(VertexBuffer)
self._buffer.__init__(usage)
@property
def need_update(self):
""" Whether object needs to be updated """
return self._buffer.need_update
def _update(self):
""" Upload all pending data to GPU. """
self._buffer._update()
def _create(self):
""" Create vertex array on GPU """
self._handle = gl.glGenVertexArrays(1)
log.debug("GPU: Creating vertex array (id=%d)" % self._id)
self._deactivate()
self._buffer._create()
def _delete(self):
""" Delete vertex array from GPU """
if self._handle > -1:
self._buffer._delete()
gl.glDeleteVertexArrays(1, np.array([self._handle]))
def _activate(self):
""" Bind the array """
log.debug("GPU: Activating array (id=%d)" % self._id)
gl.glBindVertexArray(self._handle)
self._buffer._activate()
def _deactivate(self):
""" Unbind the current bound array """
self._buffer._deactivate()
log.debug("GPU: Deactivating array (id=%d)" % self._id)
gl.glBindVertexArray(0)