erkkah / tigr

TIGR - the TIny GRaphics library for Windows, macOS, Linux, iOS and Android.
Other
745 stars 44 forks source link

wglMakeCurrent Very Slow #56

Open nsmryan opened 1 year ago

nsmryan commented 1 year ago

Thank you for tigr! I've been having a lot of fun with it.

One thing I'm having trouble with though is that I have been finding that the call to wglMakeCurrent on Windows is very slow, ~10-15 ms.

I would really like to use tigr for some GUIs at work (small, no dependencies, and responsive!), but I would like the application to not take so much time just to draw.

I have not been able to figure out the root cause here: there are forum threads discussing similar problems, even similar slow downs, but it is not at all clear what is wrong. I tried to avoid the call to wglMakeCurrent by comparing wglGetCurrentContext and the hglrc field of GLStuff, but I'm not clear enough on the design to know which calls might be omitted if we are already in the current context.

Do you have any thoughts about this? The lines I'm looking at are: https://github.com/erkkah/tigr/blob/ff7307a534082b903446ddcda3aa6f42c7eb4328/src/tigr_win.c#L210

and especially

https://github.com/erkkah/tigr/blob/ff7307a534082b903446ddcda3aa6f42c7eb4328/src/tigr_win.c#L215

which seems to be what is causing the slow down.

Thank you!

erkkah commented 1 year ago

Hi there. Thanks for the report.

Theoretically, we should not need the NULL call, and I guess doing a check like you suggest could be a good idea. I don't have my windows dev env accessible right now, so I can't test atm.

nsmryan commented 1 year ago

At the time I was trying 64x64, with TIGR_2X, and only one window.

I'm not sure what to make of my performance tests. TIGR_AUTO did not make a difference if the drawing code is fast (just drawing a simple circle with tigrCircle), but when I added in the 'blur' effect from the examples, tigrUpdate takes 0 ms and the drawing (a simple circle, blurred) takes 25 ms.