Skip to content

PyGLM types do not support PyBUF_SIMPLE #61

Closed
@einarf

Description

@einarf

Example from mat_getbuffer

if ((flags & PyBUF_RECORDS_RO) != PyBUF_RECORDS_RO || (flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS || (flags & PyBUF_ANY_CONTIGUOUS) == PyBUF_ANY_CONTIGUOUS) {
	PyErr_SetString(PyExc_BufferError, "This type of buffer is not supported.");
	view->obj = NULL;
	return -1;
}

Most types (if not all) do pass the PyBuffer_IsContiguous() tests, so I assume all types have contiguous buffer data. Still, the various *_getbuffer methods do not accept this flag.

We discovered this issue when trying to set uniform or buffer data in moderngl.

program['uniform'].value = (1, 1, 1)    # working
program['uniform'].write(np.array([1,1,1]))    # working

v = glm.fvec3(1,1,1)
program['uniform'].write(memoryview(v))    # working
program['uniform'].write(bytes(v))    # working
program['uniform'].write(np.array(v))    # working

program['uniform'].write(v)    #  <--------- error

Error output:

BufferError: This type of buffer is not supported.

We obtain the buffer using:

PyObject_GetBuffer(value, &buffer_view, PyBUF_SIMPLE);

This is acceptable when you just want to write contiguous to an opengl buffer and have no plans to keep the buffer reference or modify it.

More details here:
moderngl/moderngl#379

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions