This commit is contained in:
Ray 2024-07-25 11:44:59 +02:00
commit efce4d69ce
5 changed files with 2239 additions and 1245 deletions

View file

@ -70,7 +70,8 @@ endif()
if (${PLATFORM} MATCHES "Web") if (${PLATFORM} MATCHES "Web")
target_link_options(raylib PUBLIC "-sUSE_GLFW=3") target_link_options(raylib PUBLIC "-sUSE_GLFW=3")
if(${GRAPHICS} MATCHES "GRAPHICS_API_OPENGL_ES3") if(${GRAPHICS} MATCHES "GRAPHICS_API_OPENGL_ES3")
target_link_options(raylib PUBLIC "-sFULL_ES3") target_link_options(raylib PUBLIC "-sMIN_WEBGL_VERSION=2")
target_link_options(raylib PUBLIC "-sMAX_WEBGL_VERSION=2")
endif() endif()
endif() endif()

2667
src/external/RGFW.h vendored

File diff suppressed because it is too large Load diff

View file

@ -46,7 +46,7 @@
* *
**********************************************************************************************/ **********************************************************************************************/
#ifdef GRAPHICS_API_OPENGL_ES2 #if defined(GRAPHICS_API_OPENGL_ES2)
#define RGFW_OPENGL_ES2 #define RGFW_OPENGL_ES2
#endif #endif
@ -182,7 +182,7 @@ static const unsigned short keyMappingRGFW[] = {
[RGFW_u] = KEY_U, [RGFW_u] = KEY_U,
[RGFW_v] = KEY_V, [RGFW_v] = KEY_V,
[RGFW_w] = KEY_W, [RGFW_w] = KEY_W,
[RGFW_x] KEY_X, [RGFW_x] = KEY_X,
[RGFW_y] = KEY_Y, [RGFW_y] = KEY_Y,
[RGFW_z] = KEY_Z, [RGFW_z] = KEY_Z,
[RGFW_Bracket] = KEY_LEFT_BRACKET, [RGFW_Bracket] = KEY_LEFT_BRACKET,
@ -483,14 +483,14 @@ void SetWindowIcons(Image *images, int count)
// Set title for window // Set title for window
void SetWindowTitle(const char *title) void SetWindowTitle(const char *title)
{ {
RGFW_window_setName(platform.window, title); RGFW_window_setName(platform.window, (char*)title);
CORE.Window.title = title; CORE.Window.title = title;
} }
// Set window position on screen (windowed mode) // Set window position on screen (windowed mode)
void SetWindowPosition(int x, int y) void SetWindowPosition(int x, int y)
{ {
RGFW_window_move(platform.window, RGFW_VECTOR(x, y)); RGFW_window_move(platform.window, RGFW_POINT(x, y));
} }
// Set monitor for the current window // Set monitor for the current window
@ -536,7 +536,9 @@ void SetWindowFocused(void)
// Get native window handle // Get native window handle
void *GetWindowHandle(void) void *GetWindowHandle(void)
{ {
#ifndef RGFW_WINDOWS #ifdef RGFW_WEBASM
return (void*)platform.window->src.ctx;
#elif !defined(RGFW_WINDOWS)
return (void *)platform.window->src.window; return (void *)platform.window->src.window;
#else #else
return platform.window->src.hwnd; return platform.window->src.hwnd;
@ -643,7 +645,7 @@ Vector2 GetWindowScaleDPI(void)
{ {
RGFW_monitor monitor = RGFW_window_getMonitor(platform.window); RGFW_monitor monitor = RGFW_window_getMonitor(platform.window);
return (Vector2){((u32)monitor.scaleX)*platform.window->r.w, ((u32) monitor.scaleX)*platform.window->r.h}; return (Vector2){monitor.scaleX, monitor.scaleX};
} }
// Set clipboard text content // Set clipboard text content
@ -690,8 +692,7 @@ void DisableCursor(void)
{ {
RGFW_disableCursor = true; RGFW_disableCursor = true;
// Set cursor position in the middle RGFW_window_mouseHold(platform.window, RGFW_AREA(CORE.Window.screen.width / 2, CORE.Window.screen.height / 2));
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
HideCursor(); HideCursor();
} }
@ -745,7 +746,7 @@ int SetGamepadMappings(const char *mappings)
// Set mouse position XY // Set mouse position XY
void SetMousePosition(int x, int y) void SetMousePosition(int x, int y)
{ {
RGFW_window_moveMouse(platform.window, RGFW_VECTOR(x, y)); RGFW_window_moveMouse(platform.window, RGFW_POINT(x, y));
CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y }; CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y };
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
} }
@ -875,10 +876,10 @@ void PollInputEvents(void)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CORE.Window.resizedLastFrame = false; CORE.Window.resizedLastFrame = false;
#define RGFW_HOLD_MOUSE (1L<<2)
#if defined(RGFW_X11) //|| defined(RGFW_MACOS) #define RGFW_HOLD_MOUSE (1L<<2)
if (platform.window->src.winArgs & RGFW_HOLD_MOUSE) #if defined(RGFW_X11) //|| defined(RGFW_MACOS)
if (platform.window->_winArgs & RGFW_HOLD_MOUSE)
{ {
CORE.Input.Mouse.previousPosition = (Vector2){ 0.0f, 0.0f }; CORE.Input.Mouse.previousPosition = (Vector2){ 0.0f, 0.0f };
CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f }; CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f };
@ -1031,17 +1032,17 @@ void PollInputEvents(void)
} break; } break;
case RGFW_mousePosChanged: case RGFW_mousePosChanged:
{ {
if (platform.window->src.winArgs & RGFW_HOLD_MOUSE) if (platform.window->_winArgs & RGFW_HOLD_MOUSE)
{ {
CORE.Input.Mouse.previousPosition = (Vector2){ 0.0f, 0.0f }; CORE.Input.Mouse.previousPosition = (Vector2){ 0.0f, 0.0f };
if ((event->point.x - (platform.window->r.w/2))*2) if (event->point.x)
CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.currentPosition.x; CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.currentPosition.x;
if ((event->point.y - (platform.window->r.h/2))*2) if (event->point.y)
CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.currentPosition.y; CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.currentPosition.y;
CORE.Input.Mouse.currentPosition.x = (event->point.x - (platform.window->r.w/2))*2; CORE.Input.Mouse.currentPosition.x = (float)event->point.x;
CORE.Input.Mouse.currentPosition.y = (event->point.y - (platform.window->r.h/2))*2; CORE.Input.Mouse.currentPosition.y = (float)event->point.y;
} }
else else
{ {
@ -1205,8 +1206,6 @@ void PollInputEvents(void)
} }
#endif #endif
} }
if (RGFW_disableCursor && platform.window->event.inFocus) RGFW_window_mouseHold(platform.window, RGFW_AREA(0, 0));
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
} }
@ -1258,6 +1257,16 @@ int InitPlatform(void)
platform.window = RGFW_createWindow(CORE.Window.title, RGFW_RECT(0, 0, CORE.Window.screen.width, CORE.Window.screen.height), flags); platform.window = RGFW_createWindow(CORE.Window.title, RGFW_RECT(0, 0, CORE.Window.screen.width, CORE.Window.screen.height), flags);
RGFW_area screenSize = RGFW_getScreenSize();
CORE.Window.display.width = screenSize.w;
CORE.Window.display.height = screenSize.h;
/*
I think this is needed by Raylib now ?
If so, rcore_destkop_sdl should be updated too
*/
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height);
if (CORE.Window.flags & FLAG_VSYNC_HINT) RGFW_window_swapInterval(platform.window, 1); if (CORE.Window.flags & FLAG_VSYNC_HINT) RGFW_window_swapInterval(platform.window, 1);
RGFW_window_makeCurrent(platform.window); RGFW_window_makeCurrent(platform.window);

View file

@ -4756,7 +4756,16 @@ static void rlLoadShaderDefault(void)
"out vec2 fragTexCoord; \n" "out vec2 fragTexCoord; \n"
"out vec4 fragColor; \n" "out vec4 fragColor; \n"
#endif #endif
#if defined(GRAPHICS_API_OPENGL_ES2)
#if defined(GRAPHICS_API_OPENGL_ES3)
"#version 300 es \n"
"precision mediump float; \n" // Precision required for OpenGL ES3 (WebGL 2) (on some browsers)
"in vec3 vertexPosition; \n"
"in vec2 vertexTexCoord; \n"
"in vec4 vertexColor; \n"
"out vec2 fragTexCoord; \n"
"out vec4 fragColor; \n"
#elif defined(GRAPHICS_API_OPENGL_ES2)
"#version 100 \n" "#version 100 \n"
"precision mediump float; \n" // Precision required for OpenGL ES2 (WebGL) (on some browsers) "precision mediump float; \n" // Precision required for OpenGL ES2 (WebGL) (on some browsers)
"attribute vec3 vertexPosition; \n" "attribute vec3 vertexPosition; \n"
@ -4765,6 +4774,7 @@ static void rlLoadShaderDefault(void)
"varying vec2 fragTexCoord; \n" "varying vec2 fragTexCoord; \n"
"varying vec4 fragColor; \n" "varying vec4 fragColor; \n"
#endif #endif
"uniform mat4 mvp; \n" "uniform mat4 mvp; \n"
"void main() \n" "void main() \n"
"{ \n" "{ \n"
@ -4799,7 +4809,21 @@ static void rlLoadShaderDefault(void)
" finalColor = texelColor*colDiffuse*fragColor; \n" " finalColor = texelColor*colDiffuse*fragColor; \n"
"} \n"; "} \n";
#endif #endif
#if defined(GRAPHICS_API_OPENGL_ES2)
#if defined(GRAPHICS_API_OPENGL_ES3)
"#version 300 es \n"
"precision mediump float; \n" // Precision required for OpenGL ES3 (WebGL 2)
"in vec2 fragTexCoord; \n"
"in vec4 fragColor; \n"
"out vec4 finalColor; \n"
"uniform sampler2D texture0; \n"
"uniform vec4 colDiffuse; \n"
"void main() \n"
"{ \n"
" vec4 texelColor = texture(texture0, fragTexCoord); \n"
" finalColor = texelColor*colDiffuse*fragColor; \n"
"} \n";
#elif defined(GRAPHICS_API_OPENGL_ES2)
"#version 100 \n" "#version 100 \n"
"precision mediump float; \n" // Precision required for OpenGL ES2 (WebGL) "precision mediump float; \n" // Precision required for OpenGL ES2 (WebGL)
"varying vec2 fragTexCoord; \n" "varying vec2 fragTexCoord; \n"

View file

@ -503,7 +503,16 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
Image image = { 0 }; Image image = { 0 };
// Security check for input data // Security check for input data
if ((fileType == NULL) || (fileData == NULL) || (dataSize == 0)) return image; if ((fileData == NULL) || (dataSize == 0))
{
TRACELOG(LOG_WARNING, "IMAGE: Invalid file data");
return image;
}
if (fileType == NULL)
{
TRACELOG(LOG_WARNING, "IMAGE: Missing file extension");
return image;
}
if ((false) if ((false)
#if defined(SUPPORT_FILEFORMAT_PNG) #if defined(SUPPORT_FILEFORMAT_PNG)