From f324d8ec4f4cb8627a957adf8c5ba394522ed3bd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 8 Sep 2017 17:42:29 +0530 Subject: [PATCH] Fix a couple of bugs in the buffer map API --- kitty/gl.h | 5 +---- kitty/shaders.py | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kitty/gl.h b/kitty/gl.h index b10459d6c..15951166b 100644 --- a/kitty/gl.h +++ b/kitty/gl.h @@ -610,10 +610,7 @@ replace_or_create_buffer(PyObject UNUSED *self, PyObject *args) { void *data = NULL; PyObject *address; if (!PyArg_ParseTuple(args, "kkkO!ii", &target, &size, &prev_sz, &PyLong_Type, &address, &usage, &buftype)) return NULL; - if (size) { - data = PyLong_AsVoidPtr(address); - if (data == NULL) { PyErr_SetString(PyExc_TypeError, "Not a valid data pointer"); return NULL; } - } + data = PyLong_AsVoidPtr(address); glBindBuffer(buftype, target); if (prev_sz == 0 || prev_sz != size) glBufferData(buftype, size, data, usage); else glBufferSubData(buftype, 0, size, data); diff --git a/kitty/shaders.py b/kitty/shaders.py index b476deaa8..54f09bd04 100644 --- a/kitty/shaders.py +++ b/kitty/shaders.py @@ -100,7 +100,7 @@ class BufferManager: # {{{ self.unbind(buf_id) @contextmanager - def mapped_buffer(self, buf_sz, buf_id, usage=GL_STREAM_DRAW, access=GL_WRITE_ONLY): + def mapped_buffer(self, buf_id, buf_sz, usage=GL_STREAM_DRAW, access=GL_WRITE_ONLY): prev_sz = self.sizes.get(buf_id, 0) buf_type = self.types[buf_id] if prev_sz != buf_sz: @@ -315,6 +315,10 @@ class ShaderProgram: # {{{ bufid = self.vertex_arrays[vao_id][bufnum] buffer_manager.set_data(bufid, data, usage=usage) + def mapped_vertex_data(self, vao_id, buf_sz, usage=GL_STREAM_DRAW, bufnum=0, access=GL_WRITE_ONLY): + bufid = self.vertex_arrays[vao_id][bufnum] + return buffer_manager.mapped_buffer(bufid, buf_sz, usage=usage, access=access) + def get_vertex_data(self, vao_id, bufnum=0): bufid = self.vertex_arrays[vao_id][bufnum] return buffer_manager.get_data(bufid)