Is it possible to use SDL2 with 2D hardware accelerated rendering on Raspberry Pi?
If 2D hardware accelerated rendering is possible on the device, how do you check to see that your application is using hardware acceleration? i.e. How do you ensure that SDL2 and the application are set up correctly to use OpenGL ES 2.0?
I have built SDL2 from source configured with as described in this post: https://solarianprogrammer.com/2015/01/22/raspberry-pi-raspbian-getting-started-sdl-2/
- Copy Fresh Raspbian Wheezy image to SD card
- Boot to command prompt - no X
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile-dev libudev-dev libasound2-dev libjpeg8-dev libtiff5-dev libwebp-dev automake
- Use raspi-config to increase the GPU memory to 128MB
tar zxvf SDL2-2.0.3.tar.gz
cd SDL2-2.0.3 && mkdir build && cd build
../configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-opengl
make -j 4
sudo make install
I believe the configure step should prevent SDL from using a software implementation of OpenGL, and force it to use an OpenGL ES backend, which is supported by the hardware. I hope this implies that any 2D render calls (e.g.
SDL_DrawRect) call through to the OpenGL ES API so access the GPU and are therefore hardware accelerated.
When configure runs it states that it has found the OpenGL ES v1 and v2 headers, and lists
Video drivers : dummy, opengl_es1, opengl_es2
I'm using a very simple Tetris clone as a test case. It is initialised like so:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); window = SDL_CreateWindow(window_name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); renderer = SDL_CreateRenderer( &window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
The application's naive render function consists of drawing each of the 200 32x32 pixel squares that make up the board in turn to a 1280x720 buffer. Each square requires 2 calls to
SDL_SetRenderDrawColor a call to
The executable is built with
-L /opt/vc/lib -lEGL -lGLESv2 -I /opt/vc/include/
The problem is that the application runs at about 15 FPS, which strikes me as extremely slow and makes me think that software rendering is in use.
Is there anyway to check at runtime that the renderer is using hardware acceleration?
Is there any other set-up/initialisation required in the application to ensure that the GLES backend is used?
To be clear: I don't actually want to use the GL API at all, I just want to use the SDL 2D Render API, ensuring that the rendering happens in hardware and not software.
Incidentally, I have also tried using the Jessie sdl packages and builtbot binaries and seen the same results.