How to more efficiently redraw

I’m making a chess GUI.

Dragging a piece across the board works, but I’m afraid it isn’t fluid enough. The piece lags behind the cursor by a few frames when you are moving it around fast, and being the perfectionist I am, I don’t want that. I’m calling the redraw function in mouseDrag (I didn’t see any other choice) which I believe is the source of my troubles. So far, I’ve tried to just draw the board using OpenGl (hoping it would be faster), but either I’m not using it right or it makes no difference.

Here is my source code. I hope it builds fine in IDEs that arent visual studio.

Edit: Here are a few things I’ve tried, and some specifics of what I’m doing.
I’ve tried building in release. Slightly better, but no dice.
I am loading the images only once from the file into their separate pieces (literally) in BoardTabsComponent.
I am pretty sure the OpenGLContext isn’t working now. Maybe it could solve my problems?

Thanks very much for any help!

Things to try:

- openGL rendering

- JUCE_ENABLE_REPAINT_DEBUGGING to see whether you're repainting too much

- Profile it!

1) For OpenGL rendering all I am doing is after creating my MainContentComponent calling openGLContext.attachTo (*mainComponent); Is there anything else I have to do specific to the component for even more speed? I don't need shaders and the like -- just to draw images.

2) I declared that flag in my JuceHeader.h above the include files, but nothing seemed to have happened! Help!

3) I profiled it -- and here (,au76j7W#0) are the two images from the results that seemed relevant to me. I have no idea what they mean! :(

Thanks for your patience, I'm a JUCE noobie.

I'm still incredibly curious what exactly is the bottleneck and what I can do to get Jules' seal of approval.

What I did to fix it is instead of attaching an OpenGLContext to my MainContentComponent, just attaching one in the constructor of  my boards where all the images are being drawn.

I'm confused because the rest of my components that were being drawn under the one OpenGLContext attached to the MainContentComponent were basically non-factors. It's just a menubar and then a tabbedcomponent with two tabs that each include my board, a textbox, and a viewport with a few labels inside. The diagnostic even showed the most CPU usage being inside of the drawing my pieces, not the textbox, viewport, nor menubar.

The report I last linked showed the drawing eventually boiling down to toEdgeTable() and sanatiseLevels() being the biggest hogs. Now they are using about 1/3-1/4 less CPU than they were before. I don't understand at all.

If you want to test any of this out, [url=]this[/url] is the commit with one context attached to the MainContentComponent that lags, and [url=]this[/url] is the one that just attaches to the boards that doesn't lag. The second one has the reports included, and I'm picking up and spinning around the piece from about 3 seconds to 10 seconds in all of them.

Of course in most cases this isn't even significant, and I'm just being very picky because this is the component of my application that will be receiving the most use. Is using a background thread for the board by implementing OpenGLRenderer the best thing to do? I'll try that next and then update it in an edit.

Edit: Doing that didn't make a difference, so I reverted back to the way things were before with just attaching each board to its own OpenGLContext. It runs just fine for now! All that's left is the question of why attaching the context to the top-level component lagged so much.

Use SetOpaque(true) whenever possible.

Does this need to be done to all child components too or is it enough to apply it to the parent? 

I am trying to optimise some jittery viewport / listbox scrolling on an old iPhone 3 which I think may be to do with drawing each row component... 

On each component, but most of all on top most one.(z order speaking) so Juce do not redraw component behind those.