OpenGL for 2D surfaces

I noticed lots of games are using OGL hardware acceleration for 2D
games (for obvious benefits). I was wondering if it would be a good
idea to have SDL transparently use OGL for 2D surfaces if it is present
on the current system, and then fallback to software if OGL isn’t
available. I can’t think of many non-transparent issues except maybe some
systems that don’t support OGL in a window.

I was going to write up something like this in a separate library but
then I thought about writing it directly into the SDL library itself. Are
there any reasons against this?

http://www.mongeese.org

idea to have SDL transparently use OGL for 2D surfaces if it is present

Uh, SDL_OPENGLBLIT?

m.On Thu, Nov 16, 2000 at 12:06:27PM -0500, Garrett Banuk wrote:


Programmer “Ha ha.” “Ha ha.” "What are you laughing at?"
Loki Software "Just the horror of being alive."
http://lokigames.com/~briareos/ - Tony Millionaire

I noticed lots of games are using OGL hardware acceleration for 2D
games (for obvious benefits). I was wondering if it would be a good
idea to have SDL transparently use OGL for 2D surfaces if it is present
on the current system, and then fallback to software if OGL isn’t
available.

I proposed using opengl for 2d rendering on #sdl, and the response was
mixed. It would probably not be useful as a generic 2d rendering
target since direct pixel access is likely to be very slow, but many
alpha operations could be nicely accelerated. No doubt the devil is in
the details (surfaces have to be split up in texture-sized chunks and
tiled, and many other problems), but it could be useful as a target
for games written with its limitations in mind.

But the only proof is in implementation, so as long as nobody has done
it (or tried really hard and failed), there’s no way to be know for
sure whether it’s feasible or not

At 12:06 PM 11/16/00 -0500, Garrett Banuk wrote:

I noticed lots of games are using OGL hardware acceleration for 2D
games (for obvious benefits). I was wondering if it would be a good
idea to have SDL transparently use OGL for 2D surfaces if it is present
on the current system, and then fallback to software if OGL isn’t
available. I can’t think of many non-transparent issues except maybe some
systems that don’t support OGL in a window.

Don’t video cards provide specific acceleration for 2D drawing? If this is
the case, then what would be the advantage of passing all of the 2D
elements through OpenGL’s pipeline?

Its a driver problem. Under X11 the only (i know of) methods of exploiting 2D
acceleration are DGA and X11 Pixmaps. X11 Pixmaps are commonly accelerated but
extremely limited. DGA was broken in X3.x and is even more broken in X4.
However, OpenGL benefits from being a “buzzword enhanced” API and so hardware
vendors and software developers are a lot less reluctant to waste precious
resources on developing drivers for it.On Thu, Nov 16, 2000 at 12:39:04PM -0800, Darren Grant wrote:

Don’t video cards provide specific acceleration for 2D drawing? If this is
the case, then what would be the advantage of passing all of the 2D
elements through OpenGL’s pipeline?


Martin

Bother said the Moderator, &$&^%NO CARRIER

Hmm… that’s no good. Is there a possibility for pixmaps to improve
without substantial video driver changes?

At 10:03 PM 11/16/00 +0000, Martin Donlon wrote:>Its a driver problem. Under X11 the only (i know of) methods of exploiting 2D

acceleration are DGA and X11 Pixmaps. X11 Pixmaps are commonly accelerated but
extremely limited. DGA was broken in X3.x and is even more broken in X4.
However, OpenGL benefits from being a “buzzword enhanced” API and so hardware
vendors and software developers are a lot less reluctant to waste precious
resources on developing drivers for it.

On Thu, Nov 16, 2000 at 12:39:04PM -0800, Darren Grant wrote:

Don’t video cards provide specific acceleration for 2D drawing? If
this is
the case, then what would be the advantage of passing all of the 2D
elements through OpenGL’s pipeline?


Martin

Bother said the Moderator, &$&^%NO CARRIER

At 12:06 PM 11/16/00 -0500, Garrett Banuk wrote:

I noticed lots of games are using OGL hardware acceleration for 2D
games (for obvious benefits). I was wondering if it would be a good
idea to have SDL transparently use OGL for 2D surfaces if it is present
on the current system, and then fallback to software if OGL isn’t
available. I can’t think of many non-transparent issues except maybe some
systems that don’t support OGL in a window.

Don’t video cards provide specific acceleration for 2D drawing? If this is
the case, then what would be the advantage of passing all of the 2D
elements through OpenGL’s pipeline?

There’s a lack of portable hardware acceleration that’s SDL-compatible.
OpenGL is pretty much it.
I’m now getting quite interested in this idea though I’m working entirely
with OpenGL only, I can see a value to it.
The only problem I’ve encountered as yet is having some idea of what
accelerations to support :slight_smile:
GGI has a good set for hardware (although slim).
X and Windows have different sets. MacOS is probably different yet again.

hrm. complicated problem. 3D is lots easier as OpenGL is more or less
a common standard.

Note that I’m NOT interested in writing this - just in seeing what
happens…On Thu, 16 Nov 2000, Darren Grant wrote:


Trying to bring truth from beauty is Winterlion.
find at this winterlions’ page

Just thinkin’ sum’…

I can see a few problems with OpenGL and a “transparent” 2D
rendering API, that would directly lend itself to non-accelerated
rendering.

* Texture size constraints

* Cannot blit from anywhere to anywhere even in VRAM

* Alpha blending, color keying etc - different methods

* Pixel effects - sync + access overhead problems

* CPU cannot read from VRAM w/o serious performance impact

As to blitting, cards with colorkeying problems (I’ve heard some
"cards" are broken - but then it could be a Direct3D driver issue -
can’t remember exactly what that was about), different ways to do
alpha (some cards not being able to use a single alpha value for an
entire RGB surface?) and so on; this could all be solved by simply
requiring applications to “uppload” or “convert” the data into an
internal format that suits the current implementations - somewhat like
automatically convertion to the screen pixel format, and then not
dealing with pixels directly.

Texture sizes are worse, but as long as we stick to always blitting
entire sprites, tiles etc, this is no problem - uploading the data to
the engine will take care of this.

The last two issues, pixel effects and CPU reads, can probably be
seen as closely related in most cases - you have to read some data to
blend the pixels in, one way or another. (Either because you need to
do some kind of blending, or just because the bus word size doesn’t
match the size of the single pixel you’re writing, thus causing the
CPU or bus logic to automatically do a read-modify-write operation.)

What I have in mind for this isn’t exactly compatible with software
rendering methods, but could perhaps be nicer than no consensus at
all: Implement pixel renderers as callbacks (instead of textures),
somewhat similar to sprites. The callbacks should expect two raw
surface pointers (screen pixel format); one for reading and one for
writing.

In software mode, the read pointer would usually be in system RAM,
and the write pointer in VRAM (if possible), while in OpenGL mode,
both would (probably) be in the AGP aperture. This will vary between
hardware and drivers, but the general idea is that SDL gets to decide.

Procedural tiles and sprites would be like procedural textures,
although it might be a good idea for games to be able to disable RGBA
data with software rendering. There should be a sufficient buffering
system, so that the GPU and CPU don’t have to actively sync a few
times per frame, as that’s usually a serious performance killer.

I wish I had the time to just hack away on all that… :slight_smile:

//David

.- M u C o S -------------------------. .- David Olofson --------.
| A Free/Open Source | | Audio Hacker |
| Plugin and Integration Standard | | Linux Advocate |
| for | | Open Source Advocate |
| Professional and Consumer | | Singer |
| Multimedia | | Songwriter |
-----> http://www.linuxdj.com/mucos -'—> david at linuxdj.com -'On Thu, 16 Nov 2000, Mattias Engdeg?rd wrote:

I noticed lots of games are using OGL hardware acceleration for 2D
games (for obvious benefits). I was wondering if it would be a good
idea to have SDL transparently use OGL for 2D surfaces if it is present
on the current system, and then fallback to software if OGL isn’t
available.

I proposed using opengl for 2d rendering on #sdl, and the response was
mixed. It would probably not be useful as a generic 2d rendering
target since direct pixel access is likely to be very slow, but many
alpha operations could be nicely accelerated. No doubt the devil is in
the details (surfaces have to be split up in texture-sized chunks and
tiled, and many other problems), but it could be useful as a target
for games written with its limitations in mind.

David Olofson wrote:

Just thinkin’ sum’…

I can see a few problems with OpenGL and a “transparent” 2D
rendering API, that would directly lend itself to non-accelerated
rendering.

    * Texture size constraints

    * Cannot blit from anywhere to anywhere even in VRAM

    * Alpha blending, color keying etc - different methods

    * Pixel effects - sync + access overhead problems

    * CPU cannot read from VRAM w/o serious performance impact

Ok, right now I am speaking outside my knowledge because I don’t use OpenGL,
but this is what I think. I see SDL as one way of dealing with a computers
graphical hardware and OpenGL as another. Wouldn’t it be more appropriate to
write a seperate layer on top of SDL and OpenGL that performs the required
operations for each? In C++ for example (although I know a lot of people use
C, the same sort of thing applies with a little different logic), you could
write an abstract “Surface” class and have too seperate child classes, one
whose underlying implementation is SDL and the other OpenGL. This way only
the information required for the SDL is in its version and all the extra
information needed for OpenGL is allocated with that class. Integrating
OpenGL inside of SDL seems like we’d be removing the ‘Simple’ in Simple
DirectMedia Layer…

(Hopefully this isn;t filled with TOO mush erroneus thought)

-- David Snopek

This is not really about incorporating the OpenGL API or anything,
but rather using OpenGL as an alternative target for 2D sprite
blitting and similar stuff.

That is, as a user of such an extension, you wouldn’t be able to
tell that it’s actually OpenGL. It would just blit your sprites and
backgrounds nicely - and very quickly.

(Well, that’s the basic idea anyway. However, it turns out that
it’s hard to do it totally transparently, as OpenGL adds some
restrictions that are not relevant to 2D blitting in general -
that’s what the above is basically about.)

//David

.- M u C o S -------------------------. .- David Olofson --------.
| A Free/Open Source | | Audio Hacker |
| Plugin and Integration Standard | | Linux Advocate |
| for | | Open Source Advocate |
| Professional and Consumer | | Singer |
| Multimedia | | Songwriter |
-----> http://www.linuxdj.com/mucos -'—> david at linuxdj.com -'On Sun, 19 Nov 2000, David Snopek wrote:

David Olofson wrote:

Just thinkin’ sum’…

I can see a few problems with OpenGL and a “transparent” 2D
rendering API, that would directly lend itself to non-accelerated
rendering.

    * Texture size constraints

    * Cannot blit from anywhere to anywhere even in VRAM

    * Alpha blending, color keying etc - different methods

    * Pixel effects - sync + access overhead problems

    * CPU cannot read from VRAM w/o serious performance impact

Ok, right now I am speaking outside my knowledge because I don’t use OpenGL,
but this is what I think. I see SDL as one way of dealing with a computers
graphical hardware and OpenGL as another. Wouldn’t it be more appropriate to
write a seperate layer on top of SDL and OpenGL that performs the required
operations for each? In C++ for example (although I know a lot of people use
C, the same sort of thing applies with a little different logic), you could
write an abstract “Surface” class and have too seperate child classes, one
whose underlying implementation is SDL and the other OpenGL. This way only
the information required for the SDL is in its version and all the extra
information needed for OpenGL is allocated with that class. Integrating
OpenGL inside of SDL seems like we’d be removing the ‘Simple’ in Simple
DirectMedia Layer…

Yes, from what I’m seeing it wouldn’t be transparent and thus would
have to be something done outside of SDL. Direct memory access to the
surfaces seems like something that would really screw things up in OGL.
Having the user manage all OGL functions would probably be alot
faster and more efficient. After looking around, SDL and OGL have very
different bottom layers and SDL would need alot of hacks and workarounds.

http://www.mongeese.orgOn Sun, 19 Nov 2000, David Olofson wrote:

This is not really about incorporating the OpenGL API or anything,
but rather using OpenGL as an alternative target for 2D sprite
blitting and similar stuff.

That is, as a user of such an extension, you wouldn’t be able to
tell that it’s actually OpenGL. It would just blit your sprites and
backgrounds nicely - and very quickly.

(Well, that’s the basic idea anyway. However, it turns out that
it’s hard to do it totally transparently, as OpenGL adds some
restrictions that are not relevant to 2D blitting in general -
that’s what the above is basically about.)