I have created a function that renders a texture:
void renderTexture(WHStruct logicalSize, SDL_Texture* sTexture, SDL_Texture* dTexture, areaStruct sRect, areaStruct dRect, int transparencyPercentage) {
SDL_SetRenderTarget(renderer, dTexture);
SDL_RenderSetLogicalSize(renderer, logicalSize.w, logicalSize.h);
SDL_Rect sourceRect = { sRect.x, sRect.y, sRect.w, sRect.h };
SDL_Rect destinationRect = { dRect.x, dRect.y, dRect.w, dRect.h };
SDL_SetTextureBlendMode(sTexture, SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(sTexture, (255 * transparencyPercentage) / 100);
if (sRect.w > -1 && dRect.w > -1) {
SDL_RenderCopy(renderer, sTexture, &sourceRect, &destinationRect);
}
else if (sRect.w == -1 && dRect.w > -1) {
SDL_RenderCopy(renderer, sTexture, NULL, &destinationRect);
printInt(2);
}
else if (sRect.w > -1 && dRect.w == -1) {
SDL_RenderCopy(renderer, sTexture, &sourceRect, NULL);
}
}
This allows me to render a texture in one call rather than calling SDL_SetRenderTarget, SDL_RenderSetLogicalSize, SDL_SetTextureBlendMode, etc. each time. Which makes development faster.
However, I was concerned about SDL_SetRenderTarget (and the other SDL functions like SDL_RenderSetLogicalSize, SDL_SetTextureBlendMode, etc.) in terms of performance.
Is calling SDL_SetRenderTarget each time one texture is rendered slower than calling it once outside a loop and just calling SDL_RenderCopy inside a loop to render multiple textures?