Fix MSVC errors for PLATFORM_DESKTOP_RGFW (#4441)

* (rcore_desktop_rgfw.c) fix errors when compiling with mingw

* define WideCharToMultiByte

* update RGFW

* move stdcall def to windows only

* fix raw cursor input

* Fix warnings, update RGFW, fix msvc errors (make sure windows macro _WIN32 is correct)
This commit is contained in:
Colleague Riley 2024-10-26 16:59:10 -04:00 committed by GitHub
parent 38cf9f3224
commit 7fe5f7126b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 21 deletions

50
src/external/RGFW.h vendored
View File

@ -38,6 +38,7 @@
#define RGFW_OPENGL_ES2 - (optional) use OpenGL ES (version 2)
#define RGFW_OPENGL_ES3 - (optional) use OpenGL ES (version 3)
#define RGFW_DIRECTX - (optional) use directX for the rendering backend (rather than opengl) (windows only, defaults to opengl for unix)
#define RGFW_WEBGPU - (optional) use webGPU for rendering (Web ONLY)
#define RGFW_NO_API - (optional) don't use any rendering API (no opengl, no vulkan, no directX)
#define RGFW_LINK_EGL (optional) (windows only) if EGL is being used, if EGL functions should be defined dymanically (using GetProcAddress)
@ -84,6 +85,9 @@
Rob Rohan -> X11 bugs and missing features, MacOS/Cocoa fixing memory issues/bugs
AICDG (@THISISAGOODNAME) -> vulkan support (example)
@Easymode -> support, testing/debugging, bug fixes and reviews
Joshua Rowe (omnisci3nce) - bug fix, review (macOS)
@lesleyrs -> bug fix, review (OpenGL)
Nick Porcino (meshula) - testing, organization, review (MacOS, examples)
*/
#if _MSC_VER
@ -201,7 +205,7 @@
#ifdef __EMSCRIPTEN__
#define RGFW_WEBASM
#ifndef RGFW_NO_API
#if !defined(RGFW_NO_API) && !defined(RGFW_WEBGPU)
#define RGFW_OPENGL
#endif
@ -211,6 +215,10 @@
#include <emscripten/html5.h>
#include <emscripten/key_codes.h>
#ifdef RGFW_WEBGPU
#include <emscripten/html5_webgpu.h>
#endif
#endif
#if defined(RGFW_X11) && defined(__APPLE__)
@ -573,7 +581,13 @@ typedef struct RGFW_window_src {
void* image;
#endif
#elif defined(RGFW_WEBASM)
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx;
#ifdef RGFW_WEBGPU
WGPUInstance ctx;
WGPUDevice device;
WGPUQueue queue;
#else
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx;
#endif
#endif
} RGFW_window_src;
@ -1180,9 +1194,9 @@ int main() {
static : ar rcs RGFW.a RGFW.o
shared :
windows:
gcc -shared RGFW.o -lopengl32 -lshell32 -lgdi32 -o RGFW.dll
gcc -shared RGFW.o -lwinmm -lopengl32 -lshell32 -lgdi32 -o RGFW.dll
linux:
gcc -shared RGFW.o -lX11 -lXcursor -lGL -o RGFW.so
gcc -shared RGFW.o -lX11 -lXcursor -lGL -lXrandr -o RGFW.so
macos:
gcc -shared RGFW.o -framework Foundation -framework AppKit -framework OpenGL -framework CoreVideo
*/
@ -1406,7 +1420,7 @@ char RGFW_keyCodeToChar(u32 keycode, b8 shift) {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '`', '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', '-', '=', 0, '\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '.', ',', '/', '[', ']', ';', '\n', '\'', '\\',
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '/', '*', '-', '1', '2', '3', '3', '5', '6', '7', '8', '9', '0', '\n'
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '/', '*', '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\n'
};
static const char mapCaps[] = {
@ -1969,7 +1983,7 @@ void RGFW_updateLockState(RGFW_window* win, b8 capital, b8 numlock) {
size_t index = (sizeof(attribs) / sizeof(attribs[0])) - 13;
#define RGFW_GL_ADD_ATTRIB(attrib, attVal) \
#define RGFW_GL_ADD_ATTRIB(attrib, attVal) \
if (attVal) { \
attribs[index] = attrib;\
attribs[index + 1] = attVal;\
@ -2522,7 +2536,8 @@ Start of Linux / Unix defines
glXGetFBConfigAttrib((Display*) win->src.display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
glXGetFBConfigAttrib((Display*) win->src.display, fbc[i], GLX_SAMPLES, &samples);
if ((best_fbc < 0 || samp_buf) && (samples == RGFW_SAMPLES || best_fbc == -1)) {
if ((!(args & RGFW_TRANSPARENT_WINDOW) || vi->depth == 32) &&
(best_fbc < 0 || samp_buf) && (samples == RGFW_SAMPLES || best_fbc == -1)) {
best_fbc = i;
}
}
@ -2538,11 +2553,6 @@ Start of Linux / Unix defines
XVisualInfo* vi = glXGetVisualFromFBConfig((Display*) win->src.display, bestFbc);
XFree(fbc);
if (args & RGFW_TRANSPARENT_WINDOW) {
XMatchVisualInfo((Display*) win->src.display, DefaultScreen((Display*) win->src.display), 32, TrueColor, vi); /*!< for RGBA backgrounds*/
}
#else
XVisualInfo viNorm;
@ -8547,7 +8557,8 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) {
RGFW_UNUSED(RGFW_initFormatAttribs);
RGFW_window* win = RGFW_window_basic_init(rect, args);
#ifndef RGFW_WEBGPU
EmscriptenWebGLContextAttributes attrs;
attrs.alpha = EM_TRUE;
attrs.depth = EM_TRUE;
@ -8576,6 +8587,11 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) {
#ifdef LEGACY_GL_EMULATION
EM_ASM("Module.useWebGL = true; GLImmediate.init();");
#endif
#else
win->src.ctx = wgpuCreateInstance(NULL);
win->src.device = emscripten_webgpu_get_device();
win->src.queue = wgpuDeviceGetQueue(win->src.device);
#endif
emscripten_set_canvas_element_size("#canvas", rect.w, rect.h);
emscripten_set_window_title(name);
@ -8871,16 +8887,20 @@ void RGFW_window_swapBuffers(RGFW_window* win) {
}
#endif
#ifndef RGFW_WEBGPU
emscripten_webgl_commit_frame();
#endif
emscripten_sleep(0);
}
void RGFW_window_makeCurrent_OpenGL(RGFW_window* win) {
#ifndef RGFW_WEBGPU
if (win == NULL)
emscripten_webgl_make_context_current(0);
else
emscripten_webgl_make_context_current(win->src.ctx);
#endif
}
#ifndef RGFW_EGL
@ -8888,7 +8908,9 @@ void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) { RGFW_UNUSED(
#endif
void RGFW_window_close(RGFW_window* win) {
emscripten_webgl_destroy_context(win->src.ctx);
#ifndef RGFW_WEBGPU
emscripten_webgl_destroy_context(win->src.ctx);
#endif
free(win);
}

View File

@ -63,13 +63,16 @@ void CloseWindow(void);
#define RGFW_IMPLEMENTATION
#if defined(__WIN32) || defined(__WIN64)
#if defined(_WIN32) || defined(_WIN64)
#define WIN32_LEAN_AND_MEAN
#define Rectangle rectangle_win32
#define Rectangle rectangle_win32
#define CloseWindow CloseWindow_win32
#define ShowCursor __imp_ShowCursor
#define _APISETSTRING_
__declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar);
#define _APISETSTRING_
#undef MAX_PATH
__declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar);
#endif
#if defined(__APPLE__)
@ -79,11 +82,14 @@ void CloseWindow(void);
#include "../external/RGFW.h"
#if defined(__WIN32) || defined(__WIN64)
#if defined(_WIN32) || defined(_WIN64)
#undef DrawText
#undef ShowCursor
#undef CloseWindow
#undef Rectangle
#undef MAX_PATH
#define MAX_PATH 1025
#endif
#if defined(__APPLE__)

View File

@ -161,8 +161,8 @@
__declspec(dllimport) unsigned long __stdcall GetModuleFileNameA(void *hModule, void *lpFilename, unsigned long nSize);
__declspec(dllimport) unsigned long __stdcall GetModuleFileNameW(void *hModule, void *lpFilename, unsigned long nSize);
__declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, void *widestr, int cchwide, void *str, int cbmb, void *defchar, int *used_default);
unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
__declspec(dllimport) unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
__declspec(dllimport) unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
#elif defined(__linux__)
#include <unistd.h>
#elif defined(__FreeBSD__)