views:

53

answers:

2

I create a VBO in a function and I only want to return the VBO id.

I use glDrawArrays in another function and I want it to draw all the vertices in the VBO without needing to also pass the number of vertices. The VBO also contains texture coordinate data.

Thank you.

+3  A: 

You need to return it, sorry. Data about the VBO might live somewhere far away from your CPU and be slow to access, so you need to keep locally whatever data you need.

Matt Curtis
Okay, thank you. The reason it is a problem is because I'm using C++ and python together with ctypes. Ctypes doesn't like structures when I've tried which I would use to return the two things needed.I could use global variables but that just seems like a ridiculous solution so I will try structures again.Thank you for the answer.
Matthew Mitchell
Can you pass by reference, from Python to C? That's another way you can "return" data from a function; it might help.
Matt Curtis
Ctypes doesn't mind me using pointers so I allocated some memory for an array and stored the data I needed in this array. The data is all GLUint so an array is perfect. I used the new and delete operator to do this. It's almost completely working now. At least the screen is not blank. :DOh dear. I have a memory leak. I suppose my deletion function isn't being called...
Matthew Mitchell
+1  A: 

Maybe it could be not useful for you application, you can use glGetBufferParameteriv with argument GL_BUFFER_SIZE: it returns the number of bytes of the buffer object.

It's difficoult to say that this is the solution, since you should know the internal format of the buffer element (and indeed, its size in bytes), in order to have the number of elements composing the buffer object.

For sure, the best solution is to keep most information in a class representing the buffer object, but as I can understand from your question this is hard to implement.

Luca
Thank you for your answer. ;)I did managed to get it working by storing the information myself.
Matthew Mitchell