Fix a couple of bugs in the buffer map API

This commit is contained in:
Kovid Goyal 2017-09-08 17:42:29 +05:30
parent 2089d2bfdf
commit f324d8ec4f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 5 deletions

View File

@ -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);

View File

@ -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)