Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore][win32] Adding native win32 backend #4869

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

marler8997
Copy link
Contributor

A native Win32 backend for your consideration. The main benefits are a smaller disk/memory footprint for raylib applications and less unexpected behavior. Here's some numbers to compare:

Executable File Size of core_basic_window

      |     ReleaseFast    |   ReleaseSmall   |      Debug       |
------|--------------------|------------------|------------------|
GLFW  |  1,138 KB  (1.00x) |   794 KB (1.00x) | 1,479 KB (1.00x) | 
RGFW  |    981 KB  (0.86x) |   633 KB (0.78x) | 1,282 KB (0.86x) |
WIN32 |    951 KB  (0.83x) |   611 KB (0.77x) | 1,254 KB (0.85x) |

Memory Footprint (process memory size) of core_basic_window

      |   ReleaseFast   | ReleaseSmall  |     Debug     |
------|-----------------|---------------|---------------|
GLFW  |     53.4 MB     |    53.5 MB    |     53.4 MB   |
RGFW  |     53.6 MB     |    53.5 MB    |     53.5 MB   |
WIN32 |     53.2 MB     |    53.1 MB    |     53.1 MB   |

The implementation attempts to keep the actual state of the window and the raylib flags in sync. This is enforced before/after every window message which is overly paranoid but probably good for a first pass. The Win32 platform is full of gotchas and the benefit of using an abstraction like GLFW/RGFW are they have had a long time to fix all of them. However, I've made an effort to handle alot of them here.

The backend is not complete but it currently works with most examples.

@raysan5 raysan5 changed the title native win32 backend [rcore][win32] Adding native win32 backend Mar 31, 2025
zet23t pushed a commit to zet23t/raylib that referenced this pull request Apr 1, 2025
I believe it makes sense to only do this when there are no known
touch points. I am not even sure if this should be done at all.

See raysan5#4869 for more information.
@raysan5
Copy link
Owner

raysan5 commented Apr 2, 2025

@marler8997 Thanks for this new backend! Looks great! I want to test and review more carefully before merging.

I don't understand OpenGL well enough to know the difference between
SwapBuffers and wglSwapLayerBuffers but the former seems to double
my FPS (from 2000 to about 4000 in core_vr_simulator).
Instead of calling BeginPaint/EndPaint in WM_PAINT which signals to the
OS that our window content is updated, now when we encounter the WM_PAINT
message instead we return back to the raylib application which will
trigger it to render a new frame. We've replaced the call to BeginPaint
and EndPaint with a call to ValidateRect in SwapBuffers, which, means
we're now correctly telling the OS when our window content is actually
up-to-date.

Note that this doesn't fix the window content not being updated during
a window resize/move beacuse thos have their own message loop which
doesn't return early when it's time to paint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants