diff --git a/build.zig.zon b/build.zig.zon index 3bf82afe5..571550860 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,8 +12,8 @@ .lazy = true, }, .emsdk = .{ - .url = "git+https://github.com/emscripten-core/emsdk#3.1.50", - .hash = "N-V-__8AALRTBQDo_pUJ8IQ-XiIyYwDKQVwnr7-7o5kvPDGE", + .url = "git+https://github.com/emscripten-core/emsdk#4.0.9", + .hash = "N-V-__8AAJl1DwBezhYo_VE6f53mPVm00R-Fk28NPW7P14EQ", .lazy = true, }, }, @@ -23,6 +23,6 @@ "build.zig.zon", "src", "examples", - "LICENSE", + "LICENSE", }, } diff --git a/src/config.h b/src/config.h index dc6cc5893..ef01013b3 100644 --- a/src/config.h +++ b/src/config.h @@ -189,7 +189,7 @@ //------------------------------------------------------------------------------------ // Module: rtextures - Configuration Flags //------------------------------------------------------------------------------------ -// Selecte desired fileformats to be supported for image data loading +// Selected desired fileformats to be supported for image data loading #define SUPPORT_FILEFORMAT_PNG 1 //#define SUPPORT_FILEFORMAT_BMP 1 //#define SUPPORT_FILEFORMAT_TGA 1 diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 6af1cb6c7..60753caf4 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -424,6 +424,8 @@ void ClosePlatform(void); // Close platform static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode); // Help convert SDL scancodes to raylib key +static int GetCodepointNextSDL(const char *text, int *codepointSize); // Get next codepoint in a byte sequence and bytes processed + //---------------------------------------------------------------------------------- // Module Functions Declaration //---------------------------------------------------------------------------------- @@ -1601,13 +1603,18 @@ void PollInputEvents(void) { // NOTE: event.text.text data comes an UTF-8 text sequence but we register codepoints (int) - int codepointSize = 0; - // Check if there is space available in the queue if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) { // Add character (codepoint) to the queue - CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = GetCodepointNext(event.text.text, &codepointSize); + #if defined(PLATFORM_DESKTOP_SDL3) + unsigned int textLen = strlen(event.text.text); + unsigned int codepoint = (unsigned int)SDL_StepUTF8(&event.text.text, textLen); + #else + int codepointSize = 0; + codepoint = GetCodepointNextSDL(event.text.text, &codepointSize); + #endif + CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = codepoint; CORE.Input.Keyboard.charPressedQueueCount++; } } break; @@ -2093,4 +2100,42 @@ static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode) return KEY_NULL; // No equivalent key in Raylib } -// EOF + +// Get next codepoint in a byte sequence and bytes processed +static int GetCodepointNextSDL(const char *text, int *codepointSize) +{ + const char *ptr = text; + int codepoint = 0x3f; // Codepoint (defaults to '?') + *codepointSize = 1; + + // Get current codepoint and bytes processed + if (0xf0 == (0xf8 & ptr[0])) + { + // 4 byte UTF-8 codepoint + if (((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80) || ((ptr[3] & 0xC0) ^ 0x80)) { return codepoint; } // 10xxxxxx checks + codepoint = ((0x07 & ptr[0]) << 18) | ((0x3f & ptr[1]) << 12) | ((0x3f & ptr[2]) << 6) | (0x3f & ptr[3]); + *codepointSize = 4; + } + else if (0xe0 == (0xf0 & ptr[0])) + { + // 3 byte UTF-8 codepoint */ + if (((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80)) { return codepoint; } // 10xxxxxx checks + codepoint = ((0x0f & ptr[0]) << 12) | ((0x3f & ptr[1]) << 6) | (0x3f & ptr[2]); + *codepointSize = 3; + } + else if (0xc0 == (0xe0 & ptr[0])) + { + // 2 byte UTF-8 codepoint + if ((ptr[1] & 0xC0) ^ 0x80) { return codepoint; } // 10xxxxxx checks + codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]); + *codepointSize = 2; + } + else if (0x00 == (0x80 & ptr[0])) + { + // 1 byte UTF-8 codepoint + codepoint = ptr[0]; + *codepointSize = 1; + } + + return codepoint; +} diff --git a/src/rlgl.h b/src/rlgl.h index c39d096fb..2562ad45d 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -4178,6 +4178,9 @@ unsigned int rlCompileShader(const char *shaderCode, int type) RL_FREE(log); } + // Unload object allocated by glCreateShader(), + // despite failing in the compilation process + glDeleteShader(shader); shader = 0; } else