Hello,
I installed SDL2 and SDL_image packages and made the test below to just display a png and take some times.
The results are really disappointing.
Running in X11.
First the info are:
renderer name : opengl
flags = SDL_RENDERER_ACCELERATED SDL_RENDERER_TARGETTEXTURE
nb textures max : 5
texture size max : 8192 x 8192
current driver : x11
RenderCopy 200x200 : 2 336 201 microseconds
RenderPresent : 92 759 microseconds
RenderCopy 800x600 1 254 microseconds
RenderPresent 423 180 microseconds.
I hope there is something wrong in my test because with these results, it’s unuseable.
My code is:
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
SDL_Window* window = NULL;
SDL_Renderer *renderer;
SDL_Texture* texture;
SDL_Texture *WID_loadTexture( SDL_Renderer *renderer, char *name);
uint64_t getTimeStamp() {
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
}
int main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0 )
{
fprintf(stderr,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError());
return -1;
}
window = SDL_CreateWindow("test SDL2",SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
800,
600,
SDL_WINDOW_SHOWN);
if( window )
{
renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);
if ( renderer )
{
SDL_RendererInfo info;
SDL_GetRendererInfo(renderer, &info);
fprintf(stderr, "name : %s\n", info.name);
fprintf(stderr, "flags : ");
if (info.flags & SDL_RENDERER_SOFTWARE) fprintf(stderr, "SDL_RENDERER_SOFTWARE");
if (info.flags & SDL_RENDERER_ACCELERATED) fprintf(stderr, "SDL_RENDERER_ACCELERATED ");
if (info.flags & SDL_RENDERER_PRESENTVSYNC) fprintf(stderr, "SDL_RENDERER_PRESENTVSYNC ");
if (info.flags & SDL_RENDERER_TARGETTEXTURE) fprintf(stderr, "SDL_RENDERER_TARGETTEXTURE ");
fprintf(stderr, "\nnb textures max : %d\n", info.num_texture_formats);
fprintf(stderr, "texture size max : %d x %d \n", info.max_texture_width, info.max_texture_height);
fprintf(stderr, "current driver : %s\n", SDL_GetCurrentVideoDriver());
if (SDL_SetRenderTarget(renderer, NULL) != 0) {
fprintf(stderr, "SDL_SetRenderTarget error %s\n", SDL_GetError());
}
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer,0,0,0,255);
SDL_RenderClear(renderer);
texture = WID_loadTexture(renderer, "800_600.png");
SDL_Rect clip = {0,0,200,200};
int t1, t2;
t1 = getTimeStamp();
SDL_RenderCopy(renderer, texture, NULL, &clip);
t2 = getTimeStamp();
printf("RenderCopy 200x100 : %ld\n", (t2-t1));
t1 = getTimeStamp();
SDL_RenderPresent(renderer);
t2 = getTimeStamp();
printf("RenderPresent : %ld\n", (t2 - t1));
t1 = getTimeStamp();
SDL_RenderCopy(renderer, texture, NULL, NULL);
t2 = getTimeStamp();
printf("RenderCopy 800x600 : %ld\n", (t2-t1));
t1 = getTimeStamp();
SDL_RenderPresent(renderer);
t2 = getTimeStamp();
printf("RenderPresent : %ld\n", (t2 - t1));
bool loop = true;
while ( loop )
{
SDL_Event event;
SDL_WaitEvent( &event );
if ( event.type == SDL_QUIT )
{
fprintf(stderr, "received SDL_QUIT\n");
loop = false;
}
}
if (texture != NULL) SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
}
else
{
fprintf(stderr,"Fail to create renderer (%s)\n",SDL_GetError());
}
SDL_DestroyWindow(window);
}
else
{
fprintf(stderr,"Fail to create window: %s\n",SDL_GetError());
}
SDL_Quit();
return 0;
}
SDL_Texture *WID_loadTexture( SDL_Renderer *renderer, char *name)
{
SDL_Texture *texture = NULL;
if(name == NULL || renderer == NULL)
return NULL;
SDL_Surface* surface = IMG_Load( name );
if (surface == NULL)
{
fprintf(stderr, "error loading : %s", name);
}
else
{
texture = SDL_CreateTextureFromSurface( renderer, surface );
SDL_FreeSurface( surface );
}
return texture;
}