john-chapman / im3d

Immediate mode rendering and 3d gizmos.
MIT License
1.21k stars 63 forks source link

VertexData Cache #30

Open john-chapman opened 6 years ago

john-chapman commented 6 years ago
ChemistAion commented 1 year ago

I was wondering if there have been any updates or progress made since?

john-chapman commented 1 year ago

I've not really looked into this since the issue was created, but I think it would be quite simple to implement an initial version. Updated thoughts:

The main goal here would be to provide an API allowing the user to avoid the overhead of making lots of Im3d calls. User code would look like this:

if (Im3d::BeginCache("BigScene")) // If false, we skip Im3d calls below and use the cached vertex data directly.
{
    // ... lots of Im3d calls here.

    Im3d::EndCache(); // Cache the vertex data we just created.
}

Internally, cached vertex data would follow the structure of m_vertexData (= one list per layer, per primitive * 2 for sorted/unsorted). This way, the cache can be copied into m_vertexData such that sorting/layering still works. There would also be an InvalidateCache(id) function.

The approach outlined above has a couple of caveats:

Transform modification:

Nested caches: