gameprogcpp / code

Game Programming in C++ Code
Other
1.01k stars 354 forks source link

Sprite Batching enabled? #56

Closed LedLoaf closed 7 months ago

LedLoaf commented 1 year ago

I had a question regarding the 2D example using OpenGL.

Because the draw components happen all at once as it loops through the sprite components, is this considered sprite batching? Or do I still need to find a way to implement that so it all happens at one draw call? If so, any ideas using the same structure as this code?

Thanks

chalonverse commented 1 year ago

It's not sprite batching since each sprite still gets drawn separately. So, if there are 10 instances of the asteroid it will set the uWorldTransformuniform and texture per each instance and issue a separate glDrawElements.

One way to do sprite batching in OpenGL is that instead of having a single world transform matrix in the uniform you instead have an array of the world transform matrices, each index corresponding to an instance, and then you can use glDrawElementsInstanced to draw the instances.

LedLoaf commented 1 year ago

Hey! Thanks for the response. That seems easy enough, I'll give it a shot.

Thanks