The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Hardware-accelerated memory-to-screen blitting in X11 / Open
Stephane Marchesin
Guest

Frank Mehnert wrote:
Quote:
Hi Ryan, Bob and Stephane,


Hi, and sorry for the delay

Quote:
thank you very much for your response.

On Monday 24 April 2006 15:20, Stephane Marchesin wrote:

Quote:
Frank Mehnert wrote:

Quote:
SDL supports hardware accelerated blitting of ``normal'' surfaces to the
screen surface. However, this mode is not supported for X11 (except for
some cards when using DGA). In fact, the only backend hardware
accelerated memory-to-screen blitting is well supported seems to be the
DirectX5 backend for Windows.

Is it possible to achive the same functionality using SDL together with
OpenGL? Note: I do _not_ want to use offscreen-rendering. Rather I want
to perform the complete rendering into a surface in the main memory and
then blit _parts_ of the surface to the graphics memory using DMA. Think
of a big frame buffer where some content is changed and only the changed
part of the framebuffer should be blitted to the graphics memory (to
prevent full screen updates).

I still had a look at the tests/testgl.c example but that example deals
with a static surface/texture.

If this is not possible, are there other ways to achieve the same
behaviour for X11? What about the Xrender extension for X11?

You should look at the glscale backend :
http://icps.u-strasbg.fr/~marchesin/sdl/sdl_glscale.patch


Thank you. I had a look on this. Since I don't want to patch the libSDL,
I took the code on how to create an OpenGL surface and how to upload an
OpenGL sub-surfaces to the screen.


Quote:
If the OpenGL implementation supports DMA for texture uploads (which
almost all drivers do) it will accelerate upload of screen portions, and
try to avoid format conversions when possible. Plus as a nice bonus, you
get free bilinear scaling :)


I did already know that OpenGL performance depends on a properly working
DRI (glxinfo, "direct rendering:" must say "Yes"). What I did _not_ know is
that blitting with SDL is much faster if DRI works well than if DRI is
disabled!


I didn't say that. What I said basically, is that hardware accelerated
OpenGL scaling can be about as fast as standard 2D. Also, if you don't
use OpenGL, direct rendering or not should not make any difference.

Quote:
My understanding is that on X11, the SDL screen surface is always a memory
buffer (therefore a software surface). You don't get direct access to the
window contents since this would allow you to draw outside the window.
Blitting from memory to memory is much faster that blitting from memory
to screen (graphics memory).

Yes.

Quote:
I normally do

/* set SDL video mode */
mScreen = SDL_SetVideoMode(width, height, 0, sdlFlags);
.
.
.

/* blit the virtual frame buffer of the application (mSurfVRAM) to the
* screen surface (mScreen) */
SDL_BlitSurface(mSurfVRAM, &rect, mScreen, &rect);


As you said, with the X11 backend, the screen is a software surface. So
you should draw directly to it, it's faster.
You still should call SDL_UpdateRect(s), though.

Quote:
/* notify X11 that something has changed */
SDL_UpdateRect(mScreen, rect.x, rect.y, rect.w, rect.h);

The SDL_UpdateRect action is necessary to get X11 informed that something
has changed in the screen surface. It seems that this function is able
to use DRI if enabled.

With a single buffer, you always have to use that function, and it often
provides a nice speed improvement if you send a rect as small as possible.

Stephane