Archived

This topic is now archived and is closed to further replies.

Architekt

Display mouse cursor in separate thread?

Recommended Posts

I''m writing some simple GUI widgets for myself, as well as a mouse class. It uses DirectInput for polling, but OpenGL for drawing the cursor. Anyways, I was debating whether or not to do the drawing of the cursor part of my polling thread. Currently, I have a thread running just to handle the mouse. In case my game gets bogged down, hopefully the cursor should still be responsive and not give the illusion of everything gonig slower than normal. But, should I put the drawing code for the cursor in this thread as well? I thought yes, so that the cursor would still appear to be always responsive...but then I thought no, because of a few issues: 1. Alpha blending is used for transparent cursors 2. It could possibly draw the cursor at the wrong time (i.e. right before the screen is cleared). I suppose a solution to #2 is that I could just have a variable set by the main loop of when it''s acceptable to draw the cursor...but I''m not sure if I''d still run into the same sluggish mouse problem. And as for #1, it seems inefficient to constantly be calling the functions to turn on/off alpha blending. It seems a better idea to have the cursor drawn manually, so that I can embed it in a block of code that''s already doing alpha blending, to avoid unnecessary overhead. What''s the general method used for this kind of situation? Thanks for your help.

Share this post


Link to post
Share on other sites
It is generally a bad idea to draw from more than one thread, as OpenGL is likely to spit the dummy at you (it is not threadsafe).

What I would suggest is having your input thread continually update information about the mouse (position and button states), and the rendering thread can simply grab that info when it is time to draw the cursor (as you said, you can leave it until it is time to draw overlays with transparency, and batch it all together).

Having a separate input and rendering thread will help your game stay responsive, but using the approah I outlined, your cursor may ''lag'' a little if the sh!t really hits the fan (ie framerate nosedives)... not exactly life-threatening stuff though

Share this post


Link to post
Share on other sites
under linux with nvidia drivers, i believe opengl is threadsafe
but thats irrelevant, what you want is fast input, the input will be received by the system, why would you need to update a graphical mouse when the system is bogged down anyway? it would be no use to the interface what so ever, your still getting high frequency input but you have no use for it until the system has acceptable performance

Share this post


Link to post
Share on other sites