SDL-on-OpenGL priority?

As you might have noticed, Kobo Deluxe 0.3 contains a half finished hack
that makes it possible to transparently make the SDL 2D calls use
"native" OpenGL for rendering. There are some problems that I’ll fix
sooner or later, but as the game is quite playable with SDL 2D even on a
Win95/P-133 machine (in 320x240 mode, of course…), it’s not top priority.

Anyway, the major reason for using an OpenGL rendering layer or backend
for 2D is performance. Many SDL targets are incapable of using busmaster
DMA for system memory to VRAM blits, and some can’t even accelerate
VRAM->VRAM blits. AFAIK, no alpha blending acceleration is supported.
This makes SDL 2D rendering very slow on those targets, compared to what
you get with for example SDL on DirectX/Win32.

Just to make things even worse, you’re practically forced to use at
least 640x480 these days, as resolutions like 320x240 are considered
exotic and/or obsolete by many users and distro packagers. Getting
320x240 to run full screen on XFree86 usually requires manual hacking of
XF86Config.

Meanwhile, many of the targets with those problems do support
accelerated OpenGL. Using OpenGL for rendering not only means you get
much faster rendering, but also gives you accelerated alpha blending at
little extra cost.

Performance example: SDL ‘testsprite’ runs at 60 fps with 2000 sprites in
640x480x16 on my P-III 933 + Matrox G400 MAX; Linux with XFree86 4.1.x.
On average, OpenGL rendering is about 3 times faster than SDL software
rendering on that machine.

Now, those of you who believe this is more interesting than nicer menues,
scrolling radar screen and a real highscore table in Kobo Deluxe, tell
me, and I might reorder the TODO file a little. :slight_smile:

Or just go fix the bugs…! The code is in Kobo Deluxe - just
’./configure --enable-opengl’, and you have an addictive test suite. :wink:

Info for hackers follows.
—8<-------------------------------------------------------------------

1) Rip the files glSDL.h and glSDL.c from Kobo Deluxe 0.3.

2) Include glSDL.h instead of SDL.h.

3) Make sure that glSDL.c is compiled and linked, and that
   you link with OpenGL. Of course, your SDL library needs
   to have OpenGL support compiled in!

4) Add SDL_GLSDL to the flags argument of SDL_SetVideoMode(),
   to enable 2D-on-OpenGL mode.

5) If you get SDL_Surfaces from *any* code that isn't compiled
   with glSDL.h instead of SDL.h, you *must* "fix" those with
   the GLSDL_FIX_SURFACE() macro!

Note that blitting from the screen is not implemented (which does not
mean that alpha blending is disabled - it’s done in h/w instead), and
that the current version of the hack won’t work on platforms with 64 bit
pointers. Also note that blitting from sub-rectangles of surfaces to the
screen is broken (silly math bug, I think), and that something weird is
going on when manipulating off-screen surfaces (might have to do with
surface locking).

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -’

Now, those of you who believe this is more interesting than nicer menues,
scrolling radar screen and a real highscore table in Kobo Deluxe, tell
me, and I might reorder the TODO file a little. :slight_smile:

I’m not talking about Kobo especially - but this hack seems to be most
usefull. I’ll have a very interested look this weekend in order to use
it for Adonthell (it’s not dead! ;)). We’re switching to 640x480, and
without hw acceleration and the loads of sprites that has to be drawn
(plus the mandatory of drawing the entire screen every time) we
absolutely need hw acceleration in order to keep a correct frame rate.
So I’d say: why not integrating this into the main SDL as a complete
target? I’m sure it’ll be helpfull for lots and lots of people.

Alex.–
http://www.gnurou.org

Now, those of you who believe this is more interesting than nicer
menues, scrolling radar screen and a real highscore table in Kobo
Deluxe, tell me, and I might reorder the TODO file a little. :slight_smile:

I’m not talking about Kobo especially - but this hack seems to be most
usefull.

Well, at least it’s useful to others, as well as the Koboholics. :wink:

I’ll have a very interested look this weekend in order to use
it for Adonthell (it’s not dead! ;)).

Hopefully, glSDL isn’t too broken to give you an idea of the
performance… There shouldn’t be any major problems as long as you stick
to blitting full sprite/tile surfaces - and that’s the way to go for RLE
accelerated software blitting as well.

We’re switching to 640x480, and
without hw acceleration and the loads of sprites that has to be drawn
(plus the mandatory of drawing the entire screen every time) we
absolutely need hw acceleration in order to keep a correct frame rate.

Yeah. Same thing with Project Spitfire, and to some extent, Kobo Deluxe.
Even though the former (currently) doesn’t use an awful lot of sprites,
it does full screen scrolling. Kobo Deluxe doesn’t even scroll the whole
screen, but is still not achieving more than some 60-70 fps in 640x480 on
600+ MHz machines…

So I’d say: why not integrating this into the main SDL as a complete
target?

That’s the primary idea. If you look at the proof-of-concept hack, you’ll
probably realize that it’s either that, or making it a separate library,
using a custom surface struct, incompatible with SDL_Surface. The current
method just becomes too flaky as soon as you start mixing code using
SDL.h with code using glSDL.h…

I’m sure it’ll be helpfull for lots and lots of people.

That’s the idea, and the reason why it’s important to really make it 100%
SDL 2D compatible. So far, I haven’t seen any really serious problems
with that. Tiling of large textures and grouping of small and
non-quadratic textures seems to be the most complicated parts.

BTW, I just tried the OpenGL hack on Win2k for the first time. Not worse
than on Linux, except for the double buffering support. (Same problem as
with SDL 2D in normal double buffer mode; some parts of Kobo Deluxe just
aren’t written to handle h/w pageflipping, and SemiTriple isn’t available
in “full” OpenGL mode.)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Friday 07 December 2001 08:51, Alexandre Courbot wrote:

[… bla bla bla evrythin is slow and badly designed … ;-)]

Now, those of you who believe this is more interesting than nicer menues,
scrolling radar screen and a real highscore table in Kobo Deluxe, tell
me, and I might reorder the TODO file a little. :slight_smile:
Yes it’s really interesting but, personally (and I guess I’m not the only
one)
I don’t like to dig into other’s game code to find some usefull procs. If
you could
write a small seperate package with a small and neat example, I’d surely use
your stuff.
Or even better if you could add this transparently to the SDL main
distribution
(with something like a flag SDL_OPENGL passed somewhere) it would be great.
I guess that in this case, you might need a compile time switch too…

See ya,
Gaetan.

[… bla bla bla evrythin is slow and badly designed … ;-)]

Now, those of you who believe this is more interesting than nicer
menues, scrolling radar screen and a real highscore table in Kobo
Deluxe, tell me, and I might reorder the TODO file a little. :slight_smile:

Yes it’s really interesting but, personally (and I guess I’m not the
only one)
I don’t like to dig into other’s game code to find some usefull procs.
If you could
write a small seperate package with a small and neat example, I’d
surely use your stuff.

Of course, I’m probably going to wrap some minimal package up, with
autoconf/automake and stuff.

OTOH, you’re not really supposed to use this stuff in it’s current
form… Too ugly and too flaky.

Then again, if it works for you, so will any future versions. The API is
supposed to be 100% SDL compatible, so it won’t “infect” your code with
some nasty half finished API or anything like that.

Or even better if you could add this transparently to the SDL main
distribution
(with something like a flag SDL_OPENGL passed somewhere) it would be
great.

Apart from the requirement of using glSDL.h instead of SDL.h, and this
GLSDL_FIX_SURFACE() kludge, it already is transparent on the source
level. (You should still use the normal SDL function call names in your
code - the glSDL calls are not intended for direct use by applications!)

However, it can’t be transparent on the binary level without being part
of SDL.

I guess that in this case, you might need a compile time switch
too…

Well, it would just become another rendering backend… Of course, it
should be possible to disable, and obviously, it shouldn’t build if
there’s no OpenGL support.

Anyway, there’s some work left to do before glSDL goes anywhere:

1) Fix the remaining bugs:
	* Texture coords are bad when not blitting fill surface.
	* Something burns *huge* amounts of memory initially...

2) Implement the missing compatibility features:
	* Blit from screen surface.
	* Proper locking/unlocking of screen surface.
	* Transparent stretching to nearest or best higher
	  resolution for fullscreen modes.

3) Transform glSDL from a wrapper into a rendering backend:
	* Extract "core" code and remove API emulation crap.
	* Kill the "unused1" kludge.
	* Turn the "core" code into a real backend.
	* Maintain this as a patch against current SDL releases.

4) Testing and optimization:
	* Try all sorts of SDL apps, forcing SDL to use the
	  glSDL driver.
	* Fix anything that doesn't work! glSDL *must* be
	  100% compatible - even if some more or less feasible
	  SDL 2D operations may result in brutal abuse of
	  OpenGL, results must be correct.
	* Benchmark and fix any serious preformance killers.

When all that is done, then maybe the SDL maintainers would consider
making it a part of mainstream SDL. :wink:

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Friday 07 December 2001 13:48, Gaetan de Menten wrote:

(Just some corrections… heh)

[…]

Anyway, there’s some work left to do before glSDL goes anywhere:

  1. Fix the remaining bugs:
    • Texture coords are bad when not blitting fill surface.
      ^^^^
      Should read “full”, of course. The problem is that
      when you pass a source rect, textcoord calculations are
      done - but not correctly.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Friday 07 December 2001 17:52, David Olofson wrote:

An embedded and charset-unspecified text was scrubbed…
Name: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011207/de379b9e/attachment.txt

le ven 07-12-2001 ? 21:26, pjira at siwa.solar.com.br a ?crit :> On Fri, 7 Dec 2001 17:52:09 +0100 David Olofson <david.olofson at reologica.se> wrote:

Then again, if it works for you, so will any future versions. The API is
supposed to be 100% SDL compatible, so it won’t “infect” your code with
some nasty half finished API or anything like that.

[…]

Well, it would just become another rendering backend… Of course, it
should be possible to disable, and obviously, it shouldn’t build if
there’s no OpenGL support.

But rotozoom and other nice effects OpenGL provides
are not part of the SDL API, so maybe a glSDL-extra
library with all those features would be the next step.
And if it’s fast, some games will use this rendering
backend exclusively to get reasonable gameplay… so
it won’t be just optional anymore.

But in this case those who just want to use the glSDL backend for
performance issues would be obliged to get another library and modify
their source… I’d say, glSDL should be included as a classic SDL
backend, and others effects that are not part of SDL (like rotozoom, as
you said) could then easily go into a separate library. That way,
everybody’ll be happy :wink:

Alex.


http://www.gnurou.org

Then again, if it works for you, so will any future versions. The API
is supposed to be 100% SDL compatible, so it won’t “infect” your code
with some nasty half finished API or anything like that.

[…]

Well, it would just become another rendering backend… Of course, it
should be possible to disable, and obviously, it shouldn’t build if
there’s no OpenGL support.

But rotozoom and other nice effects OpenGL provides
are not part of the SDL API, so maybe a glSDL-extra
library with all those features would be the next step.

The problems with that is that

1) Applications will have to be written explicitly for this
   "external" glSDL API - in which case I'd rather recommend
   that people write their code directly against OpenGL. That
   way, you get a faster game, and you also get to use more
   powerful blending, transformations and texture
   interpolation, which glSDL does not provide.

2) Applications get to act as the glue between SDL_Surfaces
   and the required new type glSDL_Surface - which is not
   very nice at all. Another reason why you might as well
   use OpenGL directly.

And if it’s fast, some games will use this rendering
backend exclusively to get reasonable gameplay… so
it won’t be just optional anymore.

Well, those games in particular should definitely us carefully tuned
native OpenGL code - not something that’s specifically designed to be
compatible with the SDL API.

The bottom line is that glSDL is ultimately meant to run existing SDL
games on top of OpenGL, on systems where that gives several times the
frame rate, despite glSDL being an inefficient mess compared to any
native OpenGL game code.

Currently, this requires changing a few lines and recompiling. If it was
an SDL rendering backend, any SDL application could be made to use it by
setting an SDL system variable, or build time config switch.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Friday 07 December 2001 21:26, pjira at siwa.solar.com.br wrote:

On Fri, 7 Dec 2001 17:52:09 +0100 David Olofson <david.olofson at reologica.se> wrote:

le ven 07-12-2001 ? 21:26, pjira at siwa.solar.com.br a ?crit :

Then again, if it works for you, so will any future versions. The
API is supposed to be 100% SDL compatible, so it won’t "infect"
your code with some nasty half finished API or anything like that.

[…]

Well, it would just become another rendering backend… Of course,
it should be possible to disable, and obviously, it shouldn’t build
if there’s no OpenGL support.

But rotozoom and other nice effects OpenGL provides
are not part of the SDL API, so maybe a glSDL-extra
library with all those features would be the next step.
And if it’s fast, some games will use this rendering
backend exclusively to get reasonable gameplay… so
it won’t be just optional anymore.

But in this case those who just want to use the glSDL backend for
performance issues would be obliged to get another library and modify
their source… I’d say, glSDL should be included as a classic SDL
backend, and others effects that are not part of SDL (like rotozoom, as
you said) could then easily go into a separate library. That way,
everybody’ll be happy :wink:

Interesting idea… Indeed, glSDL has to be integrated with SDL to really
work reliably with it’s current API (the SDL API on source level) - but
that doesn’t rule out an external lib with higher level stuff. That lib
would to some extent depend on the inner workings of SDL, but it should
be possible to maintain a rather stable “private API” for that lib to use.

Of course, one could implement the external lib for software rendering
backends as well - would make it a lot more useful, I think. Why? Well,
remember that glSDL still is meant as a performance hack for standard
SDL applications - not as a [stupid and inefficient] OpenGL 2D wrapper.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Saturday 08 December 2001 10:11, Alexandre Courbot wrote:

On Fri, 7 Dec 2001 17:52:09 +0100 David Olofson <david.olofson at reologica.se> wrote:

David Olofson wrote:

Indeed, glSDL has to be integrated with SDL to really
work reliably with it’s current API (the SDL API on source level)

Have you considered maintaining a glSDL patch?? So people who want an
SDL that uses OpenGL as its backend can just apply it and compile away?
This seems like the easiest way to distribute a version of a library
that is not accepted into the main tree.

-- David Snopek

/-- libksd –
| The C++ Cross-Platform Game Framework
| Only want to write it once??
| http://libksd.sourceforge.net
------------

Yes, that’s how I plan to do it eventually.

It’s slightly faster and easier to test and debug the way it is now
(compiled with the application), but there are only a few features left
to implement before it’s time to turn it into real code. :slight_smile:

(And ‘make; make install’ on an SDL tree after modifying one or two files
doesn’t take many seconds on my system anyway…)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Tuesday 11 December 2001 20:33, David Snopek wrote:

David Olofson wrote:

Indeed, glSDL has to be integrated with SDL to really

work reliably with it’s current API (the SDL API on source level)

Have you considered maintaining a glSDL patch?? So people who want an
SDL that uses OpenGL as its backend can just apply it and compile away?
This seems like the easiest way to distribute a version of a
library that is not accepted into the main tree.