def __setitem__(self, key, value): with self.bound: sz = len(self) if isinstance(key, slice): start = int(key.start) if key.start is not None else 0 stop = int(key.stop) if key.stop is not None else start + value.size else: start = int(key) stop = start + 1 if start < 0 or stop < 0 or start >= stop: raise IndexError if stop > sz: newsz = max(sz * 2, stop) a = numpy.empty((newsz,), dtype=self.dtype) GL.glGetBufferSubData(GL.GL_ARRAY_BUFFER, 0, sz * self.dtype.itemsize, a.ctypes.data) b = numpy.asarray(value).reshape(-1) a[start:stop] = b GL.glBufferData(GL.GL_ARRAY_BUFFER, newsz * self.dtype.itemsize, a.ctypes.data, self.usage) else: a = numpy.ascontiguousarray(value, self.dtype).reshape(-1) sz = min((stop - start), len(a)) GL.glBufferSubData(GL.GL_ARRAY_BUFFER, start * self.dtype.itemsize, sz * self.dtype.itemsize, a)
def set_rays(self, rays: Sequence[np.ndarray], colors: Iterable = None): assert all(ray.ndim == 2 and ray.shape[1] == 3 for ray in rays) num_points = sum(ray.shape[0] for ray in rays) if num_points > self.max_num_points: raise ValueError( f'Number of points {num_points} is greater than max. number of points {self.max_num_points}.' ) if colors is None: colors = itertools.repeat((1, 0, 0)) buffer_data = np.empty((num_points, 3), dtype=np.float32) first = 0 indices = [] for ray in rays: count = ray.shape[0] buffer_data[first:first + count, :] = ray indices.append((first, count)) first += count GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.point_buffer) GL.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, buffer_data.nbytes, buffer_data.ravel().view(np.ubyte)) self.indices = indices self.colors = colors
def update_data(self, offset, data=None): # type: (int, Optional[Union[bytes, bytearray]]) -> None GL.glBindVertexArray(self.vao) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.vbo) if data is None: data = self.array GL.glBufferSubData(GL.GL_ARRAY_BUFFER, offset, len(data), data) GL.glBindVertexArray(0) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, 0)
def _update(self): """ Upload all pending data to GPU. """ if self.base is not None: return if self._need_resize: self._resize() self._need_resize = False log("GPU: Updating buffer (%d pending operation(s))" % len(self._pending_data)) while self._pending_data: data, nbytes, offset = self._pending_data.pop(0) gl.glBufferSubData(self._target, offset, nbytes, data)
def update_buffer(buf_id, data, offset=0, target=gl.GL_ARRAY_BUFFER): global msg1282 try: gl.glBindBuffer(target, buf_id) gl.glBufferSubData(target, offset, data.nbytes, data) except Exception as err: if err.err == 1282: if not msg1282: print("update_buffer: Communication aborted (1282)") msg1282 = True else: print("update_buffer in glhelpers.py: Could not update buffer due to GLError code:",\ err.err)
def refresh_gcode_object(self,): if not self.gcode_done and time.time() - self._last_updateTime >= 4.0: gl.glBindVertexArray(self.gcode_vao) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.gcode_vbo) status, pos, col = self.npgcr.get_current() if status is "Complete": self.gcode_done = True posisitions = np.array(pos, dtype=np.float32) scale = 1.0 / np.amax(posisitions) scale = np.array([scale, scale, scale, 1.0], dtype=np.float32) posisitions = posisitions * scale colors = np.array(col, dtype=np.float32) gl.glBufferData(gl.GL_ARRAY_BUFFER, (posisitions.size + colors.size) * 4, None, gl.GL_STATIC_DRAW) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, posisitions) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, posisitions.size * 4, colors) self.gcode_size = posisitions.size self._last_updateTime = time.time()
def flush(self): if not self.objectIndex: return GL.glVertexAttribPointer( texCoordAttribute, 2, GL.GL_FLOAT, GL.GL_TRUE, 4 * self.vboData.itemsize, ctypes.c_void_p(2 * self.vboData.itemsize) ) GL.glVertexAttribPointer( positionAttribute, 2, GL.GL_FLOAT, GL.GL_FALSE, 4 * self.vboData.itemsize, ctypes.c_void_p(0) ) GL.glBufferSubData( GL.GL_ARRAY_BUFFER, 0, 16 * self.objectIndex * self.vboData.itemsize, self.vboData, ) GL.glDrawElements( GL.GL_TRIANGLES, 6 * self.objectIndex, GL.GL_UNSIGNED_SHORT, ctypes.c_void_p(0), ) self.objectIndex = 0
def vbo_arrow_draw(self): if self.buffers is None: self.buffers = self.create_vbo() else: gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffers[0]) try: gl.glBufferSubData( gl.GL_ARRAY_BUFFER, 0, len(self.structure_vbo[self.i]) * 12, np.array(self.structure_vbo[self.i], dtype='float32').flatten()) except ValueError as e: print( e ) # watch out for setting array element with a sequence erorr print(len(self.structure_vbo[self.i]), len(self.structure_vbo[self.i][0])) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffers[1]) # later move to set_i function so that reference changes # does not cause buffer rebinding gl.glBufferSubData( gl.GL_ARRAY_BUFFER, 0, self.color_buffer_len * 4, np.array(self.color_vectors[self.i], dtype='float32').flatten()) self.draw_vbo()
def update_buffer_data(self, name, buffer_data): vbo = self.buffers[name] gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbo) buffer_data = buffer_data.tobytes() gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, len(buffer_data), buffer_data) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
def updateBackground(self): """ Updates the Background image """ if self.str: GL.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, self.pbo) GL.glBufferSubData( GL.GL_PIXEL_UNPACK_BUFFER , 0 , self.str.current()) GL.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, 0) self.updateGL()
def update(self, data, offset=0, size=None): ''' Send new data to this GL buffer. ''' dbuf, dsize = GLBuffer._raw(data) size = size or dsize if size > self.buf_size: print('GLBuffer: Warning, trying to send more data to buffer than allocated size.') gl.glBindBuffer(self.target, self.buf_id) gl.glBufferSubData(self.target, offset, min(self.buf_size, size), dbuf)
def data(self, value): try: binding = next(iter(self.buffer.active_bindings)) except StopIteration: raise RuntimeError("Sub-buffer contents can only be set if the buffer is bound.") value.dtype = self.dtype.base value.shape = self.dtype.shape GL.glBufferSubData(binding, self.offset, value.nbytes, value)
def updateBackground(self): """ Updates the Background image """ if self.str: GL.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, self.pbo) GL.glBufferSubData(GL.GL_PIXEL_UNPACK_BUFFER, 0, self.str.current()) GL.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, 0) self.updateGL()
def set_sub_data(self, data): """ :type data: np.array :param data: :return: """ self.bind() gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, data.nbytes, data)
def init_grid(self,): self.grid_vao = gl.glGenVertexArrays(1) self.grid_vbo = gl.glGenBuffers(1) gl.glBindVertexArray(self.grid_vao) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.grid_vbo) posisitions = np.array([ 1.0, 0.0, -1.0, 1.0, 1.0, 0.0, 1.0, 1.0, -1.0, 0.0, 1.0, 1.0, -1.0, 0.0, 1.0, 1.0, -1.0, 0.0, -1.0, 1.0, 1.0, 0.0, -1.0, 1.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 0.0, 1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, -1.0, 1.0, ], dtype=np.float32) colors = np.array( [ 1.0, 0.0, 0.0, 0.2, 1.0, 0.0, 0.0, 0.2, 1.0, 0.0, 0.0, 0.2, 1.0, 0.0, 0.0, 0.2, 1.0, 0.0, 0.0, 0.2, 1.0, 0.0, 0.0, 0.2, 0.0, 0.0, 1.0, 0.2, 0.0, 0.0, 1.0, 0.2, 0.0, 0.0, 1.0, 0.2, 0.0, 0.0, 1.0, 0.2, 0.0, 0.0, 1.0, 0.2, 0.0, 0.0, 1.0, 0.2, 0.0, 1.0, 0.0, 0.2, 0.0, 1.0, 0.0, 0.2, 0.0, 1.0, 0.0, 0.2, 0.0, 1.0, 0.0, 0.2, 0.0, 1.0, 0.0, 0.2, 0.0, 1.0, 0.0, 0.2, ], dtype=np.float32) gl.glBufferData(gl.GL_ARRAY_BUFFER, (posisitions.size + colors.size) * 4, None, gl.GL_STATIC_DRAW) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, posisitions) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, posisitions.size * 4, colors) self.grid_size = posisitions.size
def adjust_vert_data(self): moveit = VERTICES[:] for i in range(0,len(VERTICES),4): moveit[i] += self.offset[0] moveit[i+1] += self.offset[1] GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.vbo) ArrayType = (GL.GLfloat*len(VERTICES)) Array = ArrayType(*moveit) GL.glBufferSubData(GL.GL_ARRAY_BUFFER,0,len(VERTICES)*SIZE_FLOAT,Array) GL.glBindBuffer(GL.GL_ARRAY_BUFFER,0)
def vbo_cubic_draw(self): if self.buffers is None: self.buffers = self.create_vbo() else: gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffers[1]) # later move to set_i function so that reference changes # does not cause buffer rebinding gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, self.buffer_len, np.array(self.color_vectors[self.i], dtype='float32').flatten()) self.draw_vbo()
def update_gl(self): if not self._initialized: self.init_gl() translate = self.primitive.attributes['translate'] values = translate.tobytes() try: gl.glNamedBufferSubData(self.primitive.buffers['translate'], 0, len(values), values) except OpenGL.error.NullFunctionError as e: gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.primitive.buffers['translate']) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, len(values), values)
def adjustVertexData(self, x_offset, y_offset): verts = self.vertexPositions[:] for i in xrange(0,len(verts),4): verts[i] += x_offset verts[i+1] += y_offset GL.glBindBuffer(GL.GL_ARRAY_BUFFER,self.positionBufferObject) ArrayType = (GL.GLfloat*len(self.vertexPositions)) array = ArrayType(*verts) GL.glBufferSubData( GL.GL_ARRAY_BUFFER, 0, len(self.vertexPositions)*self.vertex_size, array) GL.glBindBuffer(GL.GL_ARRAY_BUFFER,0)
def update_buffer(buf_id, data, offset=0, target=gl.GL_ARRAY_BUFFER): global msg1282 try: gl.glBindBuffer(target, buf_id) gl.glBufferSubData(target, offset, data.nbytes, data) except Exception as err: if err.err==1282: if not msg1282: print("update_buffer: Communication aborted (1282)") msg1282 = True else: print("update_buffer in glhelpers.py: Could not update buffer due to GLError code:",\ err.err)
def setMask(self, filter=None): # set the correct filter/mask if filter is None: if self.default_mask is None: data = self.data self.current_mask = np.ones(self.dataLen, dtype=bool) else: data = self.data[self.default_mask] self.current_mask = self.default_mask else: data = self.data[filter] self.current_mask = filter self.dataLen = data.shape[0] gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffer) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, data.nbytes, data) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
def set_data( self, data, offset = 0 ): """Populates the buffer with the specified data. The buffer must be allocated before data can be set. :raise ValueError: Raised if the buffer is not currently bound. :raise OverflowError: Raised if the data size exceeds the buffer's bounds. .. seealso:: `py:func:pygly.vertex_buffer.Buffer.allocate` """ if not self.bound: raise ValueError( "Buffer is not bound" ) if (offset + data.nbytes) > self.nbytes: raise OverflowError( "Data would overflow buffer" ) GL.glBufferSubData( self.target, offset, data.nbytes, data )
def update_model_color(self): line_c = [] profile_start = time.time() line_c = self.model_channel_buffer[self.channel] LOG.debug( f"update model color iterate {time.time() - profile_start:0.2f}") GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.line_buffer_color) profile_start = time.time() GL.glBufferSubData( GL.GL_ARRAY_BUFFER, self.model_layer_chunks[0][0] * POSITION_VECTOR_SIZE * VERTEX_SIZE_BYTES, np.array(line_c, dtype='float32'), ) LOG.debug( f"update model color GL.glBufferSubData {time.time() - profile_start:0.2f}" )
def _load_text(self, text, color): posisitions = [] colors = [] texture_coords = [] texture_spacing = 1.0 / 510.0 y_pos = self.window_height - (self.kern + self.text_height) x_pos = self.kern for char in text: if "\n" == char: y_pos -= self.text_height + self.kern x_pos = self.kern else: x1 = x_pos y1 = y_pos + self.text_height x2 = x1 + self.text_width y2 = y_pos posisitions += self.square([x1, y1], [x2, y2]) letter_start = (ord(char) * 2.0 * texture_spacing) colors += [color for i in range(0, 6)] texture_coords += self.square( [letter_start, 1], [letter_start + texture_spacing, 0]) x_pos += self.text_width + self.kern posisitions = np.array(posisitions, dtype=np.float32).flatten() colors = np.array(colors, dtype=np.float32).flatten() texture_coords = np.array(texture_coords, dtype=np.float32).flatten() gl.glBindVertexArray(self.text_vao) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.text_vbo) gl.glBufferData( gl.GL_ARRAY_BUFFER, (posisitions.size + colors.size + texture_coords.size) * 4, None, gl.GL_STATIC_DRAW) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, posisitions) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, posisitions.size * 4, colors) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, (posisitions.size + colors.size) * 4, texture_coords) self.text_size = posisitions.size self.color_size = colors.size
def _load_text(self, text, color): posisitions = [] colors = [] texture_coords = [] texture_spacing = 1.0 / 510.0 y_pos = self.window_height - (self.kern + self.text_height) x_pos = self.kern for char in text: if "\n" == char: y_pos -= self.text_height + self.kern x_pos = self.kern else: x1 = x_pos y1 = y_pos + self.text_height x2 = x1 + self.text_width y2 = y_pos posisitions += self.square([x1, y1], [x2, y2]) letter_start = (ord(char) * 2.0 * texture_spacing) colors += [color for i in range(0, 6)] texture_coords += self.square([letter_start, 1], [letter_start + texture_spacing, 0]) x_pos += self.text_width + self.kern posisitions = np.array(posisitions, dtype=np.float32).flatten() colors = np.array(colors, dtype=np.float32).flatten() texture_coords = np.array(texture_coords, dtype=np.float32).flatten() gl.glBindVertexArray(self.text_vao) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.text_vbo) gl.glBufferData(gl.GL_ARRAY_BUFFER, (posisitions.size + colors.size + texture_coords.size) * 4, None, gl.GL_STATIC_DRAW) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, posisitions) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, posisitions.size * 4, colors) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, (posisitions.size + colors.size) * 4, texture_coords) self.text_size = posisitions.size self.color_size = colors.size
def update_vao(self): gl.glBindVertexArray(self._vao) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, self._vertices.nbytes, self._vertices, gl.GL_DYNAMIC_DRAW)
def update(self): gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vertex_buffer) gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, self.data.nbytes, self.data) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
def update(self, offset=0, size=None): if size is None: size = self.nbytes gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, self.ubo) gl.glBufferSubData(gl.GL_UNIFORM_BUFFER, offset, size, self.pdata)
def update_buffer(buf_id, data, offset=0, target=gl.GL_ARRAY_BUFFER): gl.glBindBuffer(target, buf_id) gl.glBufferSubData(target, offset, data.nbytes, data)
def write(self, data: np.ndarray): assert self.is_currently_bound() assert data.nbytes == self.data_layout.itemsize gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, data.nbytes, data.data)
def setSlice(self, start, size, data): """ sets a slice of data. """ dataptr = ArrayDatatype.voidDataPointer( data ) gl.glBufferSubData( self.target, start, size, dataptr )
def sub_data(self, data_size, data): self.bind() GL.glBufferSubData(self.target, 0, data_size, data)
def sync(self): """Flushes the cached data to OpenGL. """ with self: GL.glBufferSubData(self._target, 0, self._data.nbytes, self._data)
def glBufferSubData(target, offset, data): size = data.nbytes GL.glBufferSubData(target, offset, size, data)
def set_data(self, data, offset=0): offset = offset + self._offset with self: GL.glBufferSubData(self._target, offset, data.nbytes, data)
def loadData(self): for i in self.sections: vao = GL.glGenVertexArrays(1) self.vaos.append(vao) GL.glBindVertexArray(vao) #Calculate how big the buffer needs to be totalSize = 0 totalSize += i.vertices.size * i.vertices.itemsize totalSize += i.normals.size * i.normals.itemsize totalSize += i.texPos.size * i.texPos.itemsize #generate the vertex attribute buffer (VBO) attribsId = GL.glGenBuffers(1) self.attribIds.append(attribsId) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, attribsId) #Allocate the requisite space GL.glBufferData(GL.GL_ARRAY_BUFFER, totalSize, None, GL.GL_STATIC_DRAW) #Put data in buffer offset = 0 size = i.vertices.size * i.vertices.itemsize GL.glBufferSubData( GL.GL_ARRAY_BUFFER, #Type offset, #Offset into the buffer to put our data size, #How much data (in bytes) are we putting in? i.vertices) #The data itself offset += size size = i.normals.size * i.normals.itemsize GL.glBufferSubData(GL.GL_ARRAY_BUFFER, offset, size, i.normals) offset += size size = i.texPos.size * i.texPos.itemsize GL.glBufferSubData(GL.GL_ARRAY_BUFFER, offset, size, i.texPos) offset += size #Index buffer creation indexBuffer = GL.glGenBuffers(1) self.iBuffers.append(indexBuffer) #Populate index buffer GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer) GL.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, i.indices.size * i.indices.itemsize, i.indices, GL.GL_STATIC_DRAW) #load textures tex = GL.glGenTextures(1) self.dTexIds.append(tex) GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, i.mtl.texSize[0], i.mtl.texSize[1], 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, i.mtl.diffuseTexture) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) tex = GL.glGenTextures(1) self.maskIds.append(tex) GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, i.mtl.maskSize[0], i.mtl.maskSize[1], 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, i.mtl.maskTexture) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)
def update(self, data, start=0): GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.buffer) GL.glBufferSubData(GL.GL_ARRAY_BUFFER, start * self.itemsize, data) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, 0)
def loadData(self): for i in self.sections: vao = GL.glGenVertexArrays(1) self.vaos.append(vao) GL.glBindVertexArray(vao) #Calculate how big the buffer needs to be totalSize = 0 totalSize += i.vertices.size * i.vertices.itemsize totalSize += i.normals.size * i.normals.itemsize totalSize += i.texPos.size * i.texPos.itemsize #generate the vertex attribute buffer (VBO) attribsId = GL.glGenBuffers(1) self.attribIds.append(attribsId) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, attribsId) #Allocate the requisite space GL.glBufferData(GL.GL_ARRAY_BUFFER, totalSize, None, GL.GL_STATIC_DRAW) #Put data in buffer offset = 0 size = i.vertices.size * i.vertices.itemsize GL.glBufferSubData(GL.GL_ARRAY_BUFFER, #Type offset, #Offset into the buffer to put our data size, #How much data (in bytes) are we putting in? i.vertices) #The data itself offset += size size = i.normals.size * i.normals.itemsize GL.glBufferSubData(GL.GL_ARRAY_BUFFER, offset, size, i.normals) offset += size size = i.texPos.size * i.texPos.itemsize GL.glBufferSubData(GL.GL_ARRAY_BUFFER, offset, size, i.texPos) offset += size #Index buffer creation indexBuffer = GL.glGenBuffers(1) self.iBuffers.append(indexBuffer) #Populate index buffer GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer) GL.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, i.indices.size * i.indices.itemsize, i.indices, GL.GL_STATIC_DRAW) #load textures tex = GL.glGenTextures(1) self.dTexIds.append(tex) GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, i.mtl.texSize[0], i.mtl.texSize[1], 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, i.mtl.diffuseTexture) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) tex = GL.glGenTextures(1) self.maskIds.append(tex) GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, i.mtl.maskSize[0], i.mtl.maskSize[1], 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, i.mtl.maskTexture) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)
def update(self, offset=0, size=None): if size is None: size = self.nbytes gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, self.ubo) gl.glBufferSubData(gl.GL_UNIFORM_BUFFER, offset, size, pointer(self.data))
def AdjustVertexData(fXOffset, fYOffset): global vertexPositions n = len(vertexPositions) fNewData = N.copy(vertexPositions) # do this with slices! for iVertex in N.arange(0,n,4): fNewData[iVertex] += fXOffset fNewData[iVertex+1] += fYOffset GL.glBindBuffer(GL.GL_ARRAY_BUFFER, positionBufferObject) GL.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, fNewData) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, 0)
def vbo_arrow_draw(self): if self.buffers is None: self.buffers = self.create_vbo() else: gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffers[0]) gl.glBufferSubData( gl.GL_ARRAY_BUFFER, 0, self.inter_buffer_len, np.array(self.interleaved[self.i], dtype='float32').flatten()) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffers[1]) gl.glBufferSubData( gl.GL_ARRAY_BUFFER, 0, self.color_buffer_len, np.array(self.color_vectors[self.i], dtype='float32').flatten()) self.standard_vbo_draw()