3

I was wondering how to make my application interact with a 3D model that has to change a lot. For instance, I would like to be able to freely modify color, texture id, position or even normals from the application itself. I thought re-uploading the model (glBufferData) every time the model changes, or every frame, but that seems to be kind of memory intensive to me.

Also, I'm not quite sure how I'm supposed to let a class access a part of the buffer in the host memory. Example: a class "Shape" that has attributes and can modify them at any time, modifying what the buffer contains. For this, I have no idea where to start. I have to point out that I need to have many more attributes in these classes that can't be sent to the GPU. Any hints / techniques I could look into?

Edit: I found this article on Buffer Object Streaming, and feel pretty confortable about streaming data to the GPU using glBufferData and glBufferSubData. I still have trouble finding a good way to define my objects in the buffer though.

I looked into creating my own class "SubArray" which contains the array in CPU memory, an offset and a length. It has an indexer that validates the indices and throws an exception if not in the correct range, but I don't feel quite comfortable using this method as I can't change the block size of a simple object (add vertices).

Philippe Paré
  • 4,279
  • 5
  • 36
  • 56
  • Could you add some pseudo-code related to this "SubArray" class? By changing the block size, it's not actually clear what you are referring to. Be aware that to change the size of a buffer object is non-trivial, you cannot change its size without losing the old data. The strategy that comes up most often is allocate some slack space at the end of any buffer object that is expected to grow. Once the slack space fills up, you'll have to make a new buffer object (also with some slack space), do a GPU-side copy from the old to the new and then add the new data to the end. – Andon M. Coleman Aug 27 '15 at 12:48
  • _(and of course delete the old buffer object, so you don't leak CPU and GPU memory.)_ – Andon M. Coleman Aug 27 '15 at 12:50
  • @AndonM.Coleman when I'm talking about the SubArray class, it's just a class containing a reference to the array in CPU memory, an offset, and a length. it's nothing fancy, basically a copy of `ArraySegment` with basic checks upon the offset and length... About the resizing, I was talking more about redefining the vertices data of a shape. I ended up reuploading new data to the GPU... – Philippe Paré Aug 27 '15 at 15:07
  • So... is this question still valid? I was looking for things you needed help with, and about the only thing left in the question is the last sentence. Where you talk about "change the block size." I'd like to help you if I can, but I don't know exactly what you are talking about (if the problem is with GL or with your class design, or?). – Andon M. Coleman Aug 27 '15 at 15:20
  • Well the problem is with both class design and the interaction of that class with OpenGL. I'm having trouble figuring how to manage this interaction between the CPU and GPU memory for objects that tend to change a lot (change the number of vertices and their data). For instance, if I where to store data about a `Map` in a game, I would segment it in chunks. These chunks would have their own buffer on the GPU, but the chunk data might change and the number of vertices might change as well... That's where I'm struggling to figure out the memory management... – Philippe Paré Aug 27 '15 at 15:52

0 Answers0