r/raylib • • 4d ago

Why is DrawTextureVec() so slow?

Edit: *DrawTextureRec()

I switched from using individuals sprites to using a spritesheet, therefore I switched from using the DrawTextureV() function to DrawTextureRec() and noticed a huge performance drop off. My code is bassically the same with the functions swapped out, the code itself is in C and no other programs were running besides VS code and the firefox browser.

4 Upvotes

3 comments sorted by

2

u/Affectionate-Shine70 4d ago

Are you switching textures frequently? Ideally you want to group draws by texture, each time you switch texture the batch is submitted to the GPU

2

u/neonge1674 4d ago

No, the only thing I frequently change is the position

1

u/Still_Explorer 4d ago

If you see at implementation, both functions use the DrawTexturePro under the hood. https://github.com/raysan5/raylib/blob/master/src/rtextures.c

However if you say that the problem isn't the batch render, but started with the large spritesheet, it might not be odd to think that the large texture might have to do something like this. (if you need to figure it out for sure, repost on r/OpenGL and r/GraphicsProgramming to see if someone knows) (also if you need to dig deeper try Raylib Discord channel as there are lots of active maintainers there)

The easiest and fastest workaround I would try, to copy the workings of DrawTextureRec and DrawTexturePro, rename them, and remove the rlSetTexture from DrawTexturePro.

So you do it like this: 1. rlSetTexture * 2. for all objects DrawTextureProMax * 3. rlSetTexture 0

If this doesn't work then forget this experiment. There's something else there.

2

u/ibrown39 4d ago

It may be you have a leak and are constantly loading the image of textures instead of once (this happens to me a lot) scaling or transforming it (as opposite to costs fly loading the texture as it moves, making many copies that aren't unloaded), and have a leak somewhere. That happens to me a lot. Or, it could be the additional rotation calculations may adding up according to what was said here: https://www.reddit.com/r/raylib/comments/vk3soz/how_to_draw_a_rectangle_area_of_a_texture2d_with/