Why can't we do blit on an opengl surface?

Hello,

I make a 2D application with SDL and Opengl and I thought naively that I can
blit an hardware surface to the video surface (flags = OPENGL, not OPENGLBLIT)
using SDL_BlitSurface and avoiding by this way the opengl pipeline.
I’ve tried and it has not been working. I also read on the internet that it
can’t work (but no reason was given).

So my question is : why?? Why can’t we write directly the opengl frame buffer by
SDL_BlitSurface?

I also read that OPENGLBLIT should not be used. It seems that configured with
OPENGLBLIT, SDL wraps a call to a slow opengl routine. What is this routine? I
saw glDrawPixels and glWritePixel? Which one of this routine is wrapped? (I
don’t see any glWritePixel in the opengl reference).

And finally, OPENGLBLIT is recommended to not be used but on my QNX machine,
with Mesa, the testgl program is faster with OPENGLBLIT (19fpp) than with
texture (15fpp).
Could you explain me that? In my case, OPENGLBLIT is not so much bad, isn’t it?

Thanks in advance.
Fabien

— Fabien Mairesse <fabien.mairesse at barco.com> wrote:

Hello,

I make a 2D application with SDL and Opengl and I
thought naively that I can
blit an hardware surface to the video surface (flags
= OPENGL, not OPENGLBLIT)
using SDL_BlitSurface and avoiding by this way the
opengl pipeline.
I’ve tried and it has not been working. I also read
on the internet that it
can’t work (but no reason was given).

It can’t work because SDL was not programmed to have
it work using the OPENGL flag… the OPENGLBLIT flag
was provided for this functionality. Seperating the
two allows much better preformance (using 3d
acceleration anyways) if just using OpenGL rendering
functions.

So my question is : why?? Why can’t we write
directly the opengl frame buffer by
SDL_BlitSurface?

The problem is the way SDL has to deal with this…
basicly it breaks down into the fact that using SDL
functions directly in conjunction with OpenGL requires
sending lots of data over the graphics pipeline… and
that this could be implemented a lot faster/less
wastefully by using OpenGL for all of it, if you’re
using OpenGL in the first place.

I also read that OPENGLBLIT should not be used.

Reasons: Due to the preformance hit allready
mentioned, and also that it’s mainly meant for
backwards compatability rather than as a feature of
SDL.

It
seems that configured with
OPENGLBLIT, SDL wraps a call to a slow opengl
routine. What is this routine? I
saw glDrawPixels and glWritePixel? Which one of this
routine is wrapped? (I
don’t see any glWritePixel in the opengl reference).

Err, the “slow opengl routine” (I’m assuming you read
this somewhere?) probably refers to having to take the
OpenGL scene from the graphics card, load it into
system memory, add the SDL blits, then send it all
back to the graphics card.

And finally, OPENGLBLIT is recommended to not be
used but on my QNX machine,
with Mesa, the testgl program is faster with
OPENGLBLIT (19fpp) than with
texture (15fpp).

With Mesa, everything is allready in system memory, so
the major preformance hit to/from texture memory isn’t
being incured.

Instead, you have the larger problem of having to
render everything using the CPU instead of the
dedicated hardware of your graphics card (assuming you
have such a card).

I havn’t looked at testgl, so I don’t know why it’s
faster using OPENGLBLIT. I’m guessing it’ll be faster
using textures if you use 3d acceleration. (Again,
clarification: Mesa is completely software based… no
3d acceleration will occur using Mesa).

Could you explain me that? In my case, OPENGLBLIT is
not so much bad, isn’t it?

I don’t know the details of your case… but, for
reasons allready mentioned, you should stay away from
the SDL_OPENGLBLIT flag. Mesa will get slow real fast,
and you’ll take a major preformance hit using
OPENGLBLIT if you use 3d acceleration.

Thanks in advance.
Fabien

-Mike__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

initial thread : http://thread.gmane.org/gmane.comp.lib.sdl/16299

Thank you Mike for your quick and complete answer.
I make a test bench of blit for my needs (2D application on QNX with Mesa). I
will compare glDrawPixels, textures and SDL_Surface with OPENGLBLIT.
Perhaps it could be useful for others. If somebody have suggestions…tell me.

(I didn’t succeed in reply to the initial thread. I got the following error :
“You seem to be top-posting. Don’t do that.” What I did is selecting the
follow-up items in the action list. I read and re-read the faq but found
nothing. Can someone tell me how to reply to a thread? thanks)

Fabien

I asked the same question about a month ago. I wanted to draw 2d overlay /
underlay for my OpenGL demo. My first try was to use glDrawPixels, but this
is so utterly slow, you might as well not try it, I draw a 100x100 pixels
white square on top of my opengl scene, resulting in frame rate drop from 500
fps to 4 fps. The way I got it to work was to use a GL_QUAD and use
gluOrtho2d(), this works really well, and it also has the benefit of being
independant of your window size.

The code I use is:

<snip>
// Don't use depth test when writing overlay
glDisable(GL_DEPTH_TEST);

// Use precise pixel coordinates
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375, 0.375, 0.);

// Setup 1:1 pixel ration
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

/*
	Sets virtual size to 800x600 (so 0,0 is lower left cornor, and 
	800x600 is top right no matter what the size of the window is)
*/
gluOrtho2D(0, 800, 0, 600);

// Draw our background quad
glBegin(GL_QUADS);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(0, 0, 0);
	glVertex3f(800, 0, 0);
	glVertex3f(800, 300, 0);
	glVertex3f(0, 300, 0);
glEnd();
<snip>

This simply draws a blue quad filling half the screen. And the best part 

about it is that your frame rate wont suffer.On Friday 25 June 2004 13:54, Fabien Mairesse wrote:

initial thread : http://thread.gmane.org/gmane.comp.lib.sdl/16299

Thank you Mike for your quick and complete answer.
I make a test bench of blit for my needs (2D application on QNX with Mesa).
I will compare glDrawPixels, textures and SDL_Surface with OPENGLBLIT.
Perhaps it could be useful for others. If somebody have suggestions…tell
me.

(I didn’t succeed in reply to the initial thread. I got the following error
: “You seem to be top-posting. Don’t do that.” What I did is selecting the
follow-up items in the action list. I read and re-read the faq but found
nothing. Can someone tell me how to reply to a thread? thanks)


Simon Ejsing, Systemudvikler
esoft ApS, http://www.esoft.dk
Skibhusvej 52C, DK-5000 Odense C.
Tlf: 70 222 466, Fax: 63 122 466

— Fabien Mairesse <fabien.mairesse at barco.com> wrote:

initial thread :
http://thread.gmane.org/gmane.comp.lib.sdl/16299

Thank you Mike for your quick and complete answer.

No problem… although I wouldn’t exactly call it
complete myself :-).

(I didn’t succeed in reply to the initial thread. I
got the following error :
“You seem to be top-posting. Don’t do that.” What I
did is selecting the
follow-up items in the action list. I read and
re-read the faq but found
nothing. Can someone tell me how to reply to a
thread? thanks)

No experience here with gmane… you could try
subscribing instead to the list (aka, all new posts
are emailed to you, and you post by emailing to
sdl at libsdl.org).

Then it just works via email… reply with any decent
mail client should reply to sdl at libsdl.org (yahoo mail
does this too) and you can set up email filters so all
the mail marked [SDL] gets thrown into a seperate
folder, to keep things nice and organized.

Check out:
http://www.libsdl.org/mailman/listinfo/

For subscription info.__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com