Struggling with rendering performance in C for mobile game on SDL2
I've tried everything I can think of but Building a mobile game using SDL2, I've noticed that rendering performance drastically drops when too many sprites are on the screen. My current approach involves using texture atlases to minimize texture binding, but I'm still facing frame rate issues when multiple animated sprites are displayed. Hereβs a snippet of how Iβm currently managing my sprite rendering: ```c void render_sprites(SDL_Renderer *renderer, Sprite *sprites, int count) { for (int i = 0; i < count; i++) { SDL_Rect destRect = { sprites[i].x, sprites[i].y, sprites[i].width, sprites[i].height }; SDL_RenderCopy(renderer, sprites[i].texture, NULL, &destRect); } } ``` For optimization, I've implemented sprite batching as follows: ```c void batch_render_sprites(SDL_Renderer *renderer, SpriteBatch *batch) { SDL_SetTextureBlendMode(batch->texture, SDL_BLENDMODE_BLEND); SDL_RenderCopy(renderer, batch->texture, &batch->srcRect, &batch->destRect); } ``` The bottleneck seems to arise when calling `SDL_RenderCopy`, especially with large numbers of sprites. I tried reducing the number of draw calls by grouping sprites into a single texture atlas, but the performance improvement wasn't as significant as expected. Additionally, Iβm leveraging SDL2βs hardware acceleration, which should theoretically enhance performance. However, profiling with `gprof` indicated that the rendering function is still the main bottleneck, suggesting that perhaps the draw call optimization isn't enough for the number of sprites being rendered. Has anyone tackled similar performance issues with SDL2 on mobile platforms? Any tips for further optimization or alternate strategies that could help improve rendering speeds would be greatly appreciated! I'm working on a REST API that needs to handle this. What are your experiences with this? I recently upgraded to C LTS. Any help would be greatly appreciated!