SDL 2.0.4
Hi all, I’ve been trying to gauge expectations of performance with SDL and RenderCopy. I’ve been working on a few engine systems that manipulate screen sized textures using RenderCopy and SDL_TEXTUREACCESS_TARGET. This was working extremely well, but as I scaled up (in texture dimensions and count) the performance tanked. The following code simply creates a red SDL_Texture and copies it to the screen 100 times per logic loop. This results in under 60 fps, which seems extremely low. I would have thought these operations were relatively cheap, as the texture is stored on the GPU, and drawing is a quad per texture?
I am a bit new to SDL 2.X, but am having a tough time finding similar threads or benchmarks to push me towards a better implementation. Any info would be greatly appreciated.
#include <SDL.h>
#include <stdio.h>
const int SCREEN_WIDTH = 1920 * .6;
const int SCREEN_HEIGHT = 1080 * .6;
SDL_Window* gWindow = NULL;
SDL_Renderer* gRenderer = NULL;
int main( int argc, char* args[] )
{
SDL_Init(SDL_INIT_VIDEO);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
gWindow = SDL_CreateWindow("Demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0x0, 0x0, 0xFF);
SDL_Texture* example_texture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
SDL_SetRenderTarget(gRenderer, example_texture);
SDL_RenderClear(gRenderer);
Uint32 startTick = SDL_GetTicks();
Uint32 countedFrames = 0;
while (true) {
Uint32 ticks = SDL_GetTicks();
countedFrames++;
if (countedFrames % 30 == 0) {
float avgFPS = (int)countedFrames / ((ticks - startTick) / 1000.f);
printf("fps %f\n", avgFPS);
}
if (countedFrames % 150 == 0) {
printf("resetting fps counter\n");
startTick = ticks;
countedFrames = 0;
}
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_SetRenderTarget(gRenderer, 0);
SDL_RenderClear(gRenderer);
for (int i = 0; i < 100; i++) {
SDL_RenderCopy(gRenderer, example_texture, 0, 0);
}
SDL_RenderPresent(gRenderer);
}
return 0;
}