Sign in to follow this  

How do you get rid of "drag lag" in 2D graphics with Cairo.

This topic is 678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I am creating a quite-complex app using GtkD and the D programming language.

 

When you are moving a 2D graphics item with the mouse, there's a noticeable lag between the intermediately-rendered 2D graphics and the current mouse position.

 

I have an onMouseMove event handler that does something like:

onMouseMove {
     delta = currMousePos - lastMousePos;
     foreach (obj; freeObjs) {
         obj.translate(delta)
     }
     queueRedraw(boxList /*calculated above*/);
}

I queue the redraws (only effected boxes during a move) using:

queuRedraw(boxList) { 
   // calls gtk.DrawingArea.queueDrawArea
}

The draw callback looks like:

drawCallback() {
     // Draw effected geometry in AABBTree
     // Draw freeObjs
}

The problem is occuring because too many redraws are accumulating.    How do I limit the redraws or somehow only redraw the free objects at the current mouse pos?   I've tried many things and all have worse performance than the current set up or are buggy.

 

I've tried incrementing a redrawQCounter variable upon queuing and decrementing upon redraw, but it seems to grow and not converge back to zero.

 

I've tried playing with the time derivative of the mouse position as well, and failed.

 

Any ideas?  My next guess is my own queueing function that queues a redraw only when (WHAT? Idk...).

 

Thank you, Graphics Programming Gods!

 

If you have VisualD running and GtkD installed I can send you the source code.

 

-EM

Edited by EnjoysMath

Share this post


Link to post
Share on other sites

This little snippet seems to have reduced the number of draws when moving many objects:

 

I have my own queueDrawRect() function with a Rect[] drawQueue;   Whenever the queue gets full really quickly, I set its size back to zero and only draw the first and last.  Seems to work, though there's not an improvement when moving single objects.

 

Perhaps I should've used a list over my own AABBTree structure biggrin.png

 

(See attached photo)

Share this post


Link to post
Share on other sites

This topic is 678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this