SDL Hardware Acceleration on Linux

Hi all,

I would like to be able to use SDL + OpenGL and get hardware rendering on
Linux.
I believe there have been previous posts about this topic, but I cant seem
to be able to find a satisfactory answer.

According to the following posts, hardware rendering is not supported by SDL
yet:
http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2006-September/058154.html
http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2002-January/022714.html
http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2002-January/022730.html

(I tried using dga, but that resulted in SDL_Init(SDL_INIT_VIDEO) failing.)

And according to the following tutorial, SDL would use OpenGL’s hardware
rendering, if I pass SDL_OPENGL as the flag in SDL_SetVideoMode:
http://lazyfoo.net/SDL_tutorials/lesson36/index.php

So which is it? Can I get hardware acceleration with SDL or not?

I am using a Dell Inspiron 1525 laptop with Intel 965 express chipset
running Fedora 10.

Here is the output of lspci | grep -i vga:
00:02.0 VGA compatible controller: Intel Corporation Mobile GM965/GL960
Integrated Graphics Controller (rev 0c)

And here is the output of glxinfo | grep -i render:
direct rendering: Yes
OpenGL renderer string: Mesa DRI Intel® 965GM GEM 20080716 x86/MMX/SSE2

When I try to run the Nehe’s SDL code (
http://nehe.gamedev.net/data/lessons/linuxsdl/lesson01.tar.gz), I get only a
software surface and hardware blits is (blit_hw) is not available.
The relevant portion of code is shown below (I added the printfs to see what
is happening):

videoInfo = SDL_GetVideoInfo( );

if ( !videoInfo )
{
    fprintf( stderr, "Video query failed: %s\n",
         SDL_GetError( ) );
    Quit( 1 );
}

/* the flags to pass to SDL_SetVideoMode */
videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */
videoFlags |= SDL_RESIZABLE;       /* Enable window resizing */

/* This checks to see if surfaces can be stored in memory */
if ( videoInfo->hw_available )
{
  printf("Hardware surface available\n");
videoFlags |= SDL_HWSURFACE;
}
else
{
  printf("Software surface available\n");
videoFlags |= SDL_SWSURFACE;
}

/* This checks if hardware blits can be done */
if ( videoInfo->blit_hw )
{
  printf("Hardware blits can be done\n");
videoFlags |= SDL_HWACCEL;
}

And the output I get is:
Software surface available
973 frames in 5.001 seconds = 194.561 FPS

If I use the GLX version of the same tutorial (
http://nehe.gamedev.net/data/lessons/linuxglx/lesson01.tar.gz), I do get
hardware rendering
Relevant portion of the code:
if (glXIsDirect(GLWin.dpy, GLWin.ctx))
printf(“Congrats, you have Direct Rendering!\n”);
else
printf(“Sorry, no Direct Rendering possible!\n”);
initGL();

I get the output “Congrats, you have Direct Rendering!\n” with this.

I would prefer to use SDL but I really want hardware acceleration.
Any help, pointers, tips are much appreciated.

Thanks and Regards,
Abhishek

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

You’re confusing two concepts. If you want hardware accelerated
rendering, opengl will almost always be hardware (it’s generally safe to
assume so). OpenGL does not use surfaces to render, so it doesn’t
matter whether or not your surfaces are hardware, you’ll need to use
opengl textures anyway.

If you want to use SDL surfaces with OpenGL acceleration, you’ll need to
use SDL 1.3 since SDL 1.2 doesn’t do that. SDL 1.3 is still a
developement version.

To sum it up:

  • Don’t worry about HWSURFACEs - I believe they are deprecated anyway.
  • If you still want to use surfaces use SDL 1.3
  • If you want to use OpenGL directly instead, you can use SDL 1.2, but
    you will have to use textures not surfaces.

Edgar

Abhishek Gupta wrote:

Hi all,

I would like to be able to use SDL + OpenGL and get hardware rendering on
Linux.
I believe there have been previous posts about this topic, but I cant seem
to be able to find a satisfactory answer.

According to the following posts, hardware rendering is not supported by SDL
yet:
http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2006-September/058154.html
http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2002-January/022714.html
http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2002-January/022730.html

(I tried using dga, but that resulted in SDL_Init(SDL_INIT_VIDEO) failing.)

And according to the following tutorial, SDL would use OpenGL’s hardware
rendering, if I pass SDL_OPENGL as the flag in SDL_SetVideoMode:
http://lazyfoo.net/SDL_tutorials/lesson36/index.php

So which is it? Can I get hardware acceleration with SDL or not?

I am using a Dell Inspiron 1525 laptop with Intel 965 express chipset
running Fedora 10.

Here is the output of lspci | grep -i vga:
00:02.0 VGA compatible controller: Intel Corporation Mobile GM965/GL960
Integrated Graphics Controller (rev 0c)

And here is the output of glxinfo | grep -i render:
direct rendering: Yes
OpenGL renderer string: Mesa DRI Intel® 965GM GEM 20080716 x86/MMX/SSE2

When I try to run the Nehe’s SDL code (
http://nehe.gamedev.net/data/lessons/linuxsdl/lesson01.tar.gz), I get only a
software surface and hardware blits is (blit_hw) is not available.
The relevant portion of code is shown below (I added the printfs to see what
is happening):

videoInfo = SDL_GetVideoInfo( );

if ( !videoInfo )
{
    fprintf( stderr, "Video query failed: %s\n",
         SDL_GetError( ) );
    Quit( 1 );
}

/* the flags to pass to SDL_SetVideoMode */
videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */
videoFlags |= SDL_RESIZABLE;       /* Enable window resizing */

/* This checks to see if surfaces can be stored in memory */
if ( videoInfo->hw_available )
{
  printf("Hardware surface available\n");
videoFlags |= SDL_HWSURFACE;
}
else
{
  printf("Software surface available\n");
videoFlags |= SDL_SWSURFACE;
}

/* This checks if hardware blits can be done */
if ( videoInfo->blit_hw )
{
  printf("Hardware blits can be done\n");
videoFlags |= SDL_HWACCEL;
}

And the output I get is:
Software surface available
973 frames in 5.001 seconds = 194.561 FPS

If I use the GLX version of the same tutorial (
http://nehe.gamedev.net/data/lessons/linuxglx/lesson01.tar.gz), I do get
hardware rendering
Relevant portion of the code:
if (glXIsDirect(GLWin.dpy, GLWin.ctx))
printf(“Congrats, you have Direct Rendering!\n”);
else
printf(“Sorry, no Direct Rendering possible!\n”);
initGL();

I get the output “Congrats, you have Direct Rendering!\n” with this.

I would prefer to use SDL but I really want hardware acceleration.
Any help, pointers, tips are much appreciated.

Thanks and Regards,
Abhishek



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAknceYkACgkQolm4VNX3QTx10QCZAXTxFug5KSY6QCq9BcCjOjAw
h/IAoLlNAmUoRMQtwLp7VurifqcT4oD0
=PipL
-----END PGP SIGNATURE-----