Discussion:
SDL 2 2D hardware acceleration on Raspberry Pi
(too old to reply)
Hop
2015-10-09 12:47:44 UTC
Permalink
I managed to get a little further with this (I already posted this response over on http://raspberrypi.stackexchange.com/questions/37096/sdl2-performance/37120#37120
Is it possible to use SDL2 with 2D hardware accelerated rendering on Raspberry Pi?
Is there anyway to check at runtime that the renderer is using hardware acceleration?
Yes and yes. It seems that this method is actually producing an executable that uses SDL2 with an OpenGLES 2 backend. This can be confirmed by adding some code:


Code:

#include <GLES2/gl2.h>
...
static void SetGLAttribute(SDL_GLattr attr, int value)
{
if( SDL_GL_SetAttribute(attr, value) != 0 )
fprintf( stderr, "SDL_GL_SetAttr failed: %s\n", SDL_GetError() );
}
static void PrintGLString(GLenum name)
{
const GLubyte* ret = glGetString(name);
if( ret == 0 )
fprintf( stderr, "Failed to get GL string: %d\n", name );
else
printf( "%s\n", ret );
}
#endif // GL_ES_VERSION_2_0
...
// Let's see if we can use OpenGL ES 2 on Raspberry Pi
SDL_GLContext gl_context = SDL_GL_CreateContext(m_pWindow);
printf("GL_VERSION: ");
PrintGLString(GL_VERSION);
printf("GL_RENDERER: ");
PrintGLString(GL_RENDERER);
printf("GL_SHADING_LANGUAGE_VERSION: ");
PrintGLString(GL_SHADING_LANGUAGE_VERSION);
printf("GL_EXTENSIONS: ");
PrintGLString(GL_EXTENSIONS);
SDL_GL_DeleteContext(gl_context);
...
static void PrintRendererInfo(SDL_RendererInfo& rendererInfo)
{
printf( "Renderer: %s software=%d accelerated=%d, presentvsync=%d targettexture=%d\n",
rendererInfo.name,
(rendererInfo.flags & SDL_RENDERER_SOFTWARE) != 0,
(rendererInfo.flags & SDL_RENDERER_ACCELERATED) != 0,
(rendererInfo.flags & SDL_RENDERER_PRESENTVSYNC) != 0,
(rendererInfo.flags & SDL_RENDERER_TARGETTEXTURE) != 0 );
}
...
int numRenderDrivers = SDL_GetNumRenderDrivers();
printf( "%d render drivers:\n", numRenderDrivers );
for( int i = 0; i < numRenderDrivers; ++i )
{
SDL_RendererInfo rendererInfo;
SDL_GetRenderDriverInfo(i, &rendererInfo);
printf( "%d ", i );
PrintRendererInfo(rendererInfo);
}

Uint32 rendererFlags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
m_pSdlRenderer = SDL_CreateRenderer( &window, -1, rendererFlags );
if(!m_pSdlRenderer)
{
fprintf( stderr, "SDL_CreateRenderer failed: %s\n", SDL_GetError() );
}

SDL_RendererInfo rendererInfo;
if( SDL_GetRendererInfo(m_pSdlRenderer, &rendererInfo) != 0 )
{
fprintf( stderr, "SDL_GetRendererInfo failed: %s\n", SDL_GetError() );
}
printf( "Created renderer:\n" );
PrintRendererInfo(rendererInfo);




This produces the following output:

Code:

GL_VERSION: OpenGL ES 2.0
GL_RENDERER: VideoCore IV HW
GL_SHADING_LANGUAGE_VERSION: OpenGL ES GLSL ES 1.00
GL_EXTENSIONS: GL_OES_compressed_ETC1_RGB8_texture GL_OES_compressed_paletted_texture GL_OES_texture_npot GL_OES_depth24 GL_OES_vertex_half_float GL_OES_EGL_image GL_OES_EGL_image_external GL_EXT_discard_framebuffer GL_OES_rgb8_rgba8 GL_OES_depth32 GL_OES_mapbuffer GL_EXT_texture_format_BGRA8888 GL_APPLE_rgb_422 GL_EXT_debug_marker
3 render drivers:
0 Renderer: opengles2 software=0 accelerated=1, presentvsync=1 targettexture=1
1 Renderer: opengles software=0 accelerated=1, presentvsync=1 targettexture=0
2 Renderer: software software=1 accelerated=0, presentvsync=0 targettexture=1
Created renderer:
Renderer: opengles2 software=0 accelerated=1, presentvsync=1 targettexture=1



It seems that the performance of the application is limited by the number of SDL_RenderDraw*Rect calls. This is a little disappointing.

The application in question is at https://github.com/howprice/sdl2-tetris
Continue reading on narkive:
Loading...