Erwin Coumans wrote:It's a good idea to provide a user-friendly high-level 'MultimaterialTriangleMeshShape' class that manages all the complexity. Can you help with such class, or do you want me to provide an example?
Yeah, I would like to help you with that, this would allow me to integrate it easier. Just give me some guidelines on where to catch the thread and I'll look something. The idea would be to do something in the lines of the sample in my first post.
Bullet is a general purpose physics engine, so it leaves the decision up to the developer. He can share graphics or duplicate. Notice that Bullet can directly re-use many small vertex/index buffers, each indicated by partId/triangleId. Internally there is a lock/unock mechanism that can be overridden to call the graphics API's unlock to get data back to main memory.
Well, from my experience on graphics engines, specially DirectX, locking/unlocking a buffer is a very big No-No. once a buffer is filled and locked, nobody garantees you that the graphics API does not do "things" to the buffer, like, compressing with some weird algo, or simply delete it after uploading it to graphics card VRAM.
When you do a "lock" into a vertex/index buffer to read from it, what happens is not only that the API gives you a pointer to the raw data, it can also take its time decompressing the buffer to a "readable" mode, or worse, downloading it from graphics vram. The worst case scenario is that if you lock a buffer that the graphics card is currently using for rendering, the whole system will stall, waiting for the current primitive batch to finish rendering, before returning a valid pointer (and before downloading from vram, or decompressing, etc)
I'm not sure about OpenGL, but DirectX specifically requests that, at render time, Lock/Unlock operations over a vertex/index for reading data should be kept to a bare minimum, but, given that this is a driver issue, I bet OpenGL also suffers from this.
As of today, when you create a vertex/index buffer in Managed Mode (aka, safe mode) in DirectX, DirectX keeps a copy of the buffer in system Ram, and then uploads it to graphics VRAM, only when there's more buffers than VRAM availiable, the driver uploads the buffer to VRAM and deletes old buffers on demand (and at that time, the buffers should be in unlocked mode), but generally, the buffers are lockable quite fast, because it will just give you the pointer to the copy of the buffer in RAM, but only because this is the behavior of today APIs and Drivers. This has lead a lot of people to think that the buffers are there to lock and read data easily.
But, Nobody guarantees you that in the next version of DirectX, OpenGL, or on your next driver update, the location and performance of buffer lock/unlock changes dramatically.
Another really big reason not to use vertex/index buffers for reading data is that, for all next generation systems, it is expected to do projects using multithreading, that means, running the graphics engine in one thread, and the physics/AI in another thread. The problem here will be that, if the physics engine locks a buffer to read data and perform some collision detection, the graphics engine will stall, waiting for the buffer to be unlocked. Or, if the graphics engine is rendering using that buffer, and the physics engine needs its data, the physics engine will stall, waiting to be able to lock the buffer.
In other words: a good design should lock/unlock buffers at load time, the only lockable buffers at render time should be Dynamic, Write_Only buffers (particles, morphs, animatables, etc)
The only type of geometry that would be bad to store in the physics engine would be a terrain heightmap. For heightmaps, game engines usually provide an interface from which the graphics engine "sucks" triangles on demand, a Physics engine should provide something like that, so the large terrain heightmap can be shared with the graphics engine and the physics engine.
maybe a "TerrainShape" ?
Bullet allows for creating triangles "on demand", given an axis aligned bounding box. Someone already made some heightfield tutorial.
http://www.continuousphysics.com/mediaw ... ight_Field
Thanks for the feedback,
Erwin
Good to know, I'll take a look
Thanks in advance
Vic