# How demanding is SDL\_SetRenderTarget performance-wise?

**URL:** <https://discourse.libsdl.org/t/how-demanding-is-sdl-setrendertarget-performance-wise/28950>\
**Category:** Game Development\
**Created:** [February 24, 2021, 10:43pm UTC](https://discourse.libsdl.org/t/how-demanding-is-sdl-setrendertarget-performance-wise/28950 "2021-02-24T22:43:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ifstatement](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/i/cdc98d/32.png) [@ifstatement](https://discourse.libsdl.org/u/ifstatement)\
**Post date:** [February 24, 2021, 10:43pm UTC](https://discourse.libsdl.org/t/how-demanding-is-sdl-setrendertarget-performance-wise/28950/1 "2021-02-24T22:43:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mkalte](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/mkalte/32/3995_2.png) [@mkalte](https://discourse.libsdl.org/u/mkalte)\
**Post date:** [March 1, 2021, 6:59pm UTC](https://discourse.libsdl.org/t/how-demanding-is-sdl-setrendertarget-performance-wise/28950/2 "2021-03-01T18:59:30Z")

</div>

You should be fine calling `SDL_SetRenderTarget` a lot[1] as long as you are **calling it on the same texture target every time**.

`SetTextureBlendMode` is also fine [2] as it only sets a parameter.

`SDL_RenderSetLogicalSize` does a bit more work. I am not sure if its enough to cause a performance hit, but if you can avoid it i certainly would recommend you to.

[1] [SDL/SDL\_render.c at 84c44e01d3bcf693e80c624bc82e03e49d40144c · libsdl-org/SDL · GitHub](https://github.com/libsdl-org/SDL/blob/84c44e01d3bcf693e80c624bc82e03e49d40144c/src/render/SDL_render.c#L2013)  
[2] [SDL/SDL\_render.c at 84c44e01d3bcf693e80c624bc82e03e49d40144c · libsdl-org/SDL · GitHub](https://github.com/libsdl-org/SDL/blob/84c44e01d3bcf693e80c624bc82e03e49d40144c/src/render/SDL_render.c#L1395)

---

<div class="post-metadata">

**Author:** ![ifstatement](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/i/cdc98d/32.png) [@ifstatement](https://discourse.libsdl.org/u/ifstatement)\
**Post date:** [March 4, 2021, 12:53am UTC](https://discourse.libsdl.org/t/how-demanding-is-sdl-setrendertarget-performance-wise/28950/3 "2021-03-04T00:53:42Z")

</div>

I see. Well, I’ve been using my function and calling these each time on different textures and I see no impact on performance. But it might impact once I start processing a lot of textures as I develop the game more. So it might be wise for me to refactor now lol. Thank you!
