Handmade Hero » Forums » Code » PushBuffer question
Fred
20 posts
1 project

None

#3178 PushBuffer question
2 years, 1 month ago Edited by Fred on April 2, 2015, 4:16 p.m.

(I'm one or two videos behind)
Casey just introduced a PushBuffer structure to act as a command buffer for the renderer.

He mentioned that this can be used to store objects of various size.
But once you stop using objects of uniform size, it then becomes very hard to search the structure, no? You can't do random access anymore, it's more like a linked list.
How can we do sorting efficiently on this structure? (I'm mentioning sorting because one of the goals of the buffer is to handle correct z sorting).

thanks!

None
C0D3
popcorn
71 posts

#3196 PushBuffer question
2 years, 1 month ago Edited by popcorn on April 2, 2015, 10:20 p.m.

It's easy to make this kind of like an array since we pre allocated space? Not sure but if all of the structure size are all the same you can access X by doing

startoflinkedlist + sizeof(struct buffer) + index

I might be wrong tho, if more then one structure type pushed into the linkedlist or it gets push some where else in the memory which means the addresses won't be in order, then it won't work.

"The important thing is not to stop questioning. Curiosity has its own reason for existing. One can't help but be in awe when he contemplates the mysteries of structure of reality. Never lose a holy curiosity." -Albert Einstein
cmuratori
Casey Muratori
799 posts
1 project

Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.

#3207 PushBuffer question
2 years, 1 month ago

As long as we store something that allows us to get back to the start of an individual structure, we can easily sort it. So, for example, instead of storing an index as if it were an array of same-size structs, we can just store a byte index that says where the struct starts, and that handles everything. It's basically the same as just using pointers, only we don't need 64-bits to store it, we just use 32 because we know everything is based of the same base pointer in memory.

- Casey