I am learning JOGL on my own. I have just switched from GL2 to GL3. I found that there are very few tutorials on the GL3. Also, I found that GL3 is completely different from GL2. As far as I know, many ppl used buffer to hold all the vertices and bind them to OpenGL. But, when they were initialising the buffers, they used arrays, which are fixed in length. How am I going to work on varying number of vertices or objects, if the number of vertices was fixed from the beginning? Are there any simple examples? In general, how can I make my program more "dynamic"? (i.e. render a user-defined 3D world)
Asked
Active
Viewed 88 times
1
-
It depends by the average size and life of your objects – elect May 02 '16 at 06:54
-
So, are there any more specific examples? Let's say, if I were to make a mini Blender(the 3D modelling program), let the user to generate and modify a small amount of objects? What approach should I take? Or, If I had to handle large amount of objects?(Maybe a mini minecraft world) What approach should I take? – FunnyFunkyBuggy May 09 '16 at 14:08
-
If we talk about things getting modified by the user, that means long life in computer terms, you should just destroy the old buffer and create the new one when the number of vertices changes. Same approach for a mini minecraft world. To give you some numbers, a cad program I work on, with over 4k objects and over 27 milions triangles in total, takes roughly 1 seconds to transfer all the geometry (position, normal and indices) on the gpu (mid-perf pc, gtx 770) – elect May 09 '16 at 14:17
-
You may want to follow [this tutorial](https://github.com/elect86/modern-jogl-examples) – elect May 09 '16 at 14:21
-
That's really quick in deed. So, if the life time is short(maybe for a game or animation or simulator?), would you prefer me to create a huge buffer at first and modify the buffer in time? Also, you just mentioned about destroying and creating, I am concerned about the garbage collecting process? Should I call it constantly to ensure the garbage won't accumulate?(I know java will do it from time to time, but sometimes I found it quite slow) – FunnyFunkyBuggy May 09 '16 at 14:26
-
Short life means a single or few frames, I doubt is your case. Destroying/creating means glDeleteBuffers/glBufferData gl3 - glStorageData gl4. And you can do everything using the same direct buffer. So nothing would require the garbage collector – elect May 09 '16 at 18:20
1 Answers
1
The best i can think of is creating a large buffer at the initializing stage and modify the data with glBufferSubData()
. Other way is recreate the buffer with glBufferData()
though this one is not preferable because of how expensive it is to recreate the buffer every time a new entity/object is created to/removed from the world (Probably fine once in a while).

Greffin28
- 257
- 1
- 6
- 15
-
Thanks for your suggestion. It seems that GL3/GL4 sacrifice the flexibility of GL2 to gain speed. Surely recreating the buffer will cost a lot of computation and I don't think it is a good idea(but still workable). – FunnyFunkyBuggy May 01 '16 at 05:50
-
@FunnyFunkyBuggy Well, you can of course store those entities in an `ArrayList` which you can add or remove entities as you wish and render them one by one with the same buffer (a simple quad buffer). But this approach will cost on your performance too, as calling many draw calls without batching is also bad. – Greffin28 May 01 '16 at 09:54
-
@FunnyFunkyBuggy I know this is very very late, lol. But after further research i ran to [this](http://stackoverflow.com/questions/1728026/how-do-i-use-opengl-3-x-vbos-to-render-a-dynamic-world) which might answer. If you already figure this out then just ignore this comment. – Greffin28 May 24 '16 at 09:31