SDL&OpenGL: fast mouse cursor

“Hello World\n”,

i’ve implemented my own mouse-cursor by painting a GL_QUAD with texture at the current mouse position
at the end of painting the scene.
Now i would like to detach the mouse-painting from the fps of the scene for more smoothness of the cursor.
Therefore i tried two ways, both with an additional thread:

  1. using the additional thread for handling the events and the mouse-cursor.
  • this failed, becouse i didn’t get mouse-events and i cannot paint to the screen from another thread.
  1. using the additional thread for painting my scene.
  • this also failed becouse of painting to the screen from another thread.

I thought about periodically calling an extra mouse-event-paint-function from my renderfunction,
but isn’t there another, nicer way?

Tnx,
Florian

[…]

I thought about periodically calling an extra
mouse-event-paint-function from my renderfunction,
but isn’t there another, nicer way?

I’m afraid there isn’t. You can probably get around the event handling
issues with SDL one way or another, but asynchronous rendering into
different pages of the same OpenGL context would probably require
platform and/or driver specific hacks, if it’s at all possible
without driver modifications.

If we disregard the fact that there is no support for rendering
directly into the front/display page in SDL or OpenGL, the next issue
is synchronization in the driver. Most serious OpenGL drivers should
be able to (sort of) handle this, if you do the pointer rendering
through a different OpenGL context. However, (older?) consumer cards
and any cards running game oriented drivers may have performance
issues, because they cannot switch GPU task at any time, like in the
middle of rasterizing a polygon. Keep in mind that it’s not
sufficient that the driver/GPU can handle multiple command queues;
the GPU also has to be able to switch target buffer as a separate
operation; not just as part of the page flip operation. Workstation
cards are designed to handle this (for asynchronous rendering in
multiple windows or contexts), but I wouldn’t be surprized if some
gamer setups work on frame granularity - which would of course render
your efforts completely meaningless.

Anyway, what kind of scenes are you rendering? There might be a
shortcut that’ll work everywhere - but be warned that this will cause
severe tearing and/or flickering if you try it with your average full
screen 3D game!

1. Tile the rendering! Keep track of the average frame rate,
   and render only as much of the screen at a time, that you
   can finish before the next retrace. (If you have multiple
   windows or similar, you can repaint one at a time, for
   example.)

2. Redraw the mouse cursor and flip pages for every tile.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Thursday 12 May 2005 14.53, Florian Liefers wrote:

Quoth David Olofson , on 2005-05-12 16:11:33 +0200:

If we disregard the fact that there is no support for rendering
directly into the front/display page in SDL or OpenGL […]

Is there a reason you can’t use glDrawBuffer(GL_FRONT)?

—> Drake Wilson
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050512/b3f06a5d/attachment.pgp

Should work where supported (everywhere?), I think - but probably only
if you stay in a single thread, which means you still have to check
for mouse events “every now and then” while rendering.

Definitely worth a try.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Thursday 12 May 2005 17.08, Drake Wilson wrote:

Quoth David Olofson <@David_Olofson>, on 2005-05-12 16:11:33
+0200:

If we disregard the fact that there is no support for rendering
directly into the front/display page in SDL or OpenGL […]

Is there a reason you can’t use glDrawBuffer(GL_FRONT)?

— Florian Liefers wrote:

“Hello World\n”,

i’ve implemented my own mouse-cursor by painting a
GL_QUAD with texture at the current mouse position
at the end of painting the scene.
Now i would like to detach the mouse-painting from
the fps of the scene for more smoothness of the
cursor.
Therefore i tried two ways, both with an additional
thread:

  1. using the additional thread for handling the
    events and the mouse-cursor.
  • this failed, becouse i didn’t get mouse-events and
    i cannot paint to the screen from another thread.
  1. using the additional thread for painting my
    scene.
  • this also failed becouse of painting to the screen
    from another thread.

I thought about periodically calling an extra
mouse-event-paint-function from my renderfunction,
but isn’t there another, nicer way?

Can you draw the mouse cursor in an overlay (YUV
usually) such that the rest of the overlay is
transparent and the OpenGL surface is below it?

I’ve never tried it; it was just a though.

Dennis Jenkins

Dennis Jenkins schrieb:

— Florian Liefers <@Florian_Liefers> wrote:

Can you draw the mouse cursor in an overlay (YUV
usually) such that the rest of the overlay is
transparent and the OpenGL surface is below it?

I’ve never worked with an overlay and don’t know how to draw in into it.
But a problem in this case would be, that i don’t get the mouse-events in
another thread.

Florian

Florian Liefers wrote:

“Hello World\n”,

i’ve implemented my own mouse-cursor by painting a GL_QUAD with texture at the current mouse position
at the end of painting the scene.
Now i would like to detach the mouse-painting from the fps of the scene for more smoothness of the cursor.
Therefore i tried two ways, both with an additional thread:

  1. using the additional thread for handling the events and the mouse-cursor.
  • this failed, becouse i didn’t get mouse-events and i cannot paint to the screen from another thread.
  1. using the additional thread for painting my scene.
  • this also failed becouse of painting to the screen from another thread.

I thought about periodically calling an extra mouse-event-paint-function from my renderfunction,
but isn’t there another, nicer way?

Why don’t you use the SDL cursor ? It’s a hardware cursor, and it is
refreshed independently from your paplication.

Stephane

Stephane Marchesin schrieb:

Florian Liefers wrote:

I thought about periodically calling an extra
mouse-event-paint-function from my renderfunction,
but isn’t there another, nicer way?

Why don’t you use the SDL cursor ? It’s a hardware cursor, and it is
refreshed independently from your paplication.

Because the SDL cursor only supports black and white :frowning:

Florian

I’ve never worked with an overlay and don’t know how to draw in into it.
But a problem in this case would be, that i don’t get the mouse-events in
another thread.

Mouse events are not the bottleneck. Moving them to another thread not
only doesn’t work, it’s really not necessary. I would look for somewhere
else to optimize framerate.

–ryan.