| 45 | ConcurrentDictionary<VertexBufferLayouts, GPUVertexLayout*> VertexBufferCache; |
| 46 | |
| 47 | GPUVertexLayout* GetCache(const VertexBufferLayouts& key, int32 count) |
| 48 | { |
| 49 | GPUVertexLayout* result; |
| 50 | if (!VertexBufferCache.TryGet(key, result)) |
| 51 | { |
| 52 | GPUVertexLayout::Elements elements; |
| 53 | bool anyValid = false; |
| 54 | for (int32 slot = 0; slot < count; slot++) |
| 55 | { |
| 56 | if (key.Layouts[slot]) |
| 57 | { |
| 58 | anyValid = true; |
| 59 | int32 start = elements.Count(); |
| 60 | elements.Add(key.Layouts[slot]->GetElements()); |
| 61 | for (int32 j = start; j < elements.Count(); j++) |
| 62 | elements.Get()[j].Slot = (byte)slot; |
| 63 | } |
| 64 | } |
| 65 | result = anyValid ? GPUVertexLayout::Get(elements, true) : nullptr; |
| 66 | if (!VertexBufferCache.Add(key, result)) |
| 67 | { |
| 68 | // Other thread added the value |
| 69 | Delete(result); |
| 70 | bool found = VertexBufferCache.TryGet(key, result); |
| 71 | ASSERT(found); |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | return result; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | String VertexElement::ToString() const |