1

I want to try updating a VBO in PyOpenGL using glMapBuffer, which returns a ctypes pointer to the mapped memory. Now, almost all the examples for this function are in C and use memcpy, which does apparently not exist in Python as such.

So, how can I update the data using this pointer?

2
  • Does this answer your question? Pointers and arrays in Python ctypes Commented Aug 26, 2020 at 9:53
  • @vallentin Not really, since I have virtually no experience with ctypes , and I understand neither the question nor the answer. Commented Aug 26, 2020 at 10:30

1 Answer 1

1

Use from_address from the ctypes to get a ctypes type instance using the memory returned by glMapBuffer.

The following example maps the buffer to an array of numberOfFloats floats:

map_data = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY)
map_array = (GLfloat * numberOfFloats).from_address(map_data)

// copy new data
// [...]

glUnmapBuffer(GL_ARRAY_BUFFER)

The elements of map_array can be accessed by subscription:

map_array[i] = value

Data can be copied form one ctypes array to another by ctypes.memmove(dst, src, count).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.