Mouse/keyboard input problems

for my game engine i ran intro troubles using accelerated opengl on my linux machine. if i have high fill-rate (rendering shadow volumes) the mouse and keyboard starts to lag. hence if i move the mouse it takes a second before the motion is done. if i take out the heavy shadow shaders the lagging does not happen.

i use plain Xlib to using a simple message queue. how comes it that using heavy shaders lags out the x-window-server? or rather… how can i get past this problem? do i need to poll somehow the keyboard and mouse? is there something like ‘direct-input’ which bypasses the x-server and goes directly into the underlaying hardware like accelerated opengl does?

infos:
os - linux (gentoo)
graphic - ati radeon 9700 and 9600 (two machines)

try

XQueryKeymap(display, keys_return)
Display *display;
char keys_return[32];

to get the actual state of the keyboard.
keys_return has a size of 32 byte, which is 256
bit. each key is represented by one bit.

for the pointer, use

Bool XQueryPointer(display, w, root_return, child_return, root_x_return, root_y_return, win_x_return, win_y_return, mask_return)
Display *display;
Window w;
Window *root_return, *child_return;
int *root_x_return, *root_y_return;
int *win_x_return, *win_y_return;
unsigned int *mask_return;

Originally posted by RigidBody:
[b]try

XQueryKeymap(display, keys_return)
Display *display;
char keys_return[32];

to get the actual state of the keyboard.
keys_return has a size of 32 byte, which is 256
bit. each key is represented by one bit.

for the pointer, use

Bool XQueryPointer(display, w, root_return, child_return, root_x_return, root_y_return, win_x_return, win_y_return, mask_return)
Display *display;
Window w;
Window *root_return, *child_return;
int *root_x_return, *root_y_return;
int *win_x_return, *win_y_return;
unsigned int *mask_return;[/b]
XQueryPointer i’m already using to avoid laginess of my mouse (an optical one if this is important).

the keyboard i did not poll like this yet, may try it.

still leaves the question why with XQueryPointer my mouse lags if i have heavy shaders. i wonder if the opengl-shader usage somehow blocks the x-server. can’t think of something else. or is my setup bad?

that’s my message loop

	// sync to get all messages processed
//	XSync(p_Display, False);
	XFlush(p_Display);
	// check messages
	while(XPending(p_Display)){
		XNextEvent(p_Display, &event);
		// process event on your own
                 // ... ... ...
		}
	}

that’s how my window event mask is setup

int deAppDisplay::linGetEventMask(){
	return StructureNotifyMask
		| ExposureMask
		| ButtonPressMask | ButtonReleaseMask
//		| ButtonMotionMask | MotionNotify | PointerMotionMask | PointerMotionHintMask
		| KeyPressMask | KeyReleaseMask
		| EnterWindowMask | LeaveWindowMask
		| FocusChangeMask;
}

something wrong there? i fiddled around a lot with those settings trying to find one which does not lag.

afaik you do not need XNextEvent if you use
XQueryPointer/XQueryKeyboard; you should get the
current mouse and keyboard state,
regardless of what events are queued.

have you tried something like

 while(true) {
 XQueryKeymap(...);
 XQueryPointer(...);
 // what else has to be done 
 }

i do need the XNextEvent as i need to keep track of when my window changes shape or is unfocused.

the reason for this is that i needed to get rid or things like auto-key-repeat and mouse-acceleration as they completly upset my engine. for that i do have to restore the settings upon loosing the focus.

for the auto-repeat i can get it away using the query-keyboard thingy, but somehow getting away the acceleration from the mouse with the query-mouse-pointer did not work.

if i can find a way to get rid of these two additional problems i could perhaps get rid of the XNextEvent.

EDIT: if i take out the XFlush i have a lagging mouse, meaning, if i pull up my view the engine reacts with a timed lag before doing the motion. i don’t know why but i can’t for some reason get past the x-server which seems to horribly lag.

EDIT EDIT: another reason for the XNextEvent to stay. i need it with the focusing of my game window to capture and release the mouse/keyboard. hence i can not let it slip unless i can safely detect this situation without watching the event queue.

the problem with XNextEvent is that it blocks if
there is no event. XCheckWindowEvent might work
better.

i think if you insert an XGetWindowAttributes
and a glViewport at the beginning of your display
function, you do not need to care about any expose
or resize events.

the thing with the window attributes i could try out. about the XNextEvent blocking this can not happen as i check first with XPending if there is a message in the queue and then call XNextEvent as i am sure it will not block for this message. i could be wrong though.

about that mouse acceleration thingy. does it also apply to XQueryPointer? or am i safe of this thingy there. after my knowledge of X this should also have influence there.

A standard way of handling events is to use the combination of XPending and XNextEvent followed by a switch statement. XPending tells you if there are any pending events in the event queue. It never blocks. Depending on how you have set things up you may also want to look into XCheckMaskEvent.

This has always been fast enough for me. If the mouse handling is still too slow you may look into the XFRee86-DGA extensions (assuming you are using XFree86). Look for the function XF86DGADirectVideo. This comes with its own bag of problems such as portability and the fact that it only works well for fullscreen applications. There are also deprecation issues. I believe you can find an example of this in the SDL code base. The Doom 3 linux version seems to claim that it initializes “DGA-Mouse” at startup.

  • SFRuckus

PS Check out the xlib manuals - they are available online. man-pages are your friend.

i’m currently doing the trick with the simple event loop and it works well for even fps rates below 10 but as soon as i have heavy fill-rate shaders like shadow-volume shaders it starts to lag. that’s in principle the main problem i have and that i can not get my head around.

the dga extension is a no-go as i use XOrg as i am on GenToo systems here.

about the xlib manuals… this is one of the few things i just can not find on google and co. for some reason i stumble only over subset-docs of it of 404 links. if you have a working link i would be glad to have it. man is nice but only if you know the function you are looking for O_O

These links seem to be okay.

http://www.ac3.edu.au/SGI_Developer/books/XLib_PG/sgi_html/
http://www.the-labs.com/X11/XLib-Manual/

How often do you process events? Is it tied to the rendering or do you do it independently, say every 1/10 of a second?

  • SFRuckus

the links are wonderfull, thanks.

about the events, each frame-update i do first a run for the events if there are any pending, then i render my stuff.

i somehow fiddled a bit around with the engine and noticed that this phenomena happens at certain ‘places’. i can produce this problem even at 35 fps. it seems to be the case whener there is a lot of shadow casting, hence, a lot of fill-rate usage when the lag occurs. looks like the rendering over the AGP bus somehow ‘stalls’ the x-server. i just have no idea how this can happen as the AGP access should be done by the x-driver, not the x-server itself :confused:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.