add wasigl

This commit is contained in:
David Konsumer 2026-05-09 08:31:46 -07:00
parent b2ea5eae5e
commit 5367c60328
No known key found for this signature in database
5 changed files with 26 additions and 16 deletions

View File

@ -205,8 +205,9 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
if (options.rmodels) {
try c_source_files.append("src/rmodels.c");
}
raylib_mod.addCMacro("SUPPORT_MODULE_RAUDIO", &.{@as(u8, @intFromBool(options.raudio)) + 0x30});
if (options.raudio) {
const raudio_enabled = options.raudio and options.platform != .wasigl;
raylib_mod.addCMacro("SUPPORT_MODULE_RAUDIO", &.{@as(u8, @intFromBool(raudio_enabled)) + 0x30});
if (raudio_enabled) {
try c_source_files.append("src/raudio.c");
}
@ -361,6 +362,12 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
raylib_mod.addCMacro(OpenglVersion.gl_soft.toCMacroStr(), "");
raylib_mod.addCMacro("PLATFORM_MEMORY", "");
},
.wasigl => {
raylib_mod.addCMacro("PLATFORM_WASIGL", "");
raylib_mod.addCMacro("GRAPHICS_API_OPENGL_ES2", "");
raylib_mod.addIncludePath(b.path("src/external/glfw/include"));
raylib.import_symbols = true;
},
.win32 => {
if (target.result.os.tag != .windows) {
@panic("Target is not supported with this platform");
@ -573,17 +580,7 @@ pub const LinuxDisplayBackend = enum {
Both,
};
pub const PlatformBackend = enum {
glfw,
rgfw,
sdl,
sdl2,
sdl3,
memory,
win32,
drm,
android,
};
pub const PlatformBackend = enum { glfw, rgfw, sdl, sdl2, sdl3, memory, win32, drm, android, wasigl };
fn translateCMod(
comptime header: []const u8,
@ -687,6 +684,7 @@ fn addExamples(
}
if (std.mem.eql(u8, filename, "raylib_opengl_interop")) {
if (platform == .drm) continue;
if (platform == .wasigl) continue;
if (target.result.os.tag == .macos) continue;
exe_mod.addIncludePath(b.path("src/external"));
}
@ -794,4 +792,3 @@ fn waylandGenerate(
}
}
}

View File

@ -578,6 +578,14 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
endif
endif
ifeq ($(PLATFORM),PLATFORM_WASIGL)
WASI_SDK ?= /opt/wasi-sdk
CC = $(WASI_SDK)/bin/clang
AR = $(WASI_SDK)/bin/llvm-ar
LDFLAGS += -Wl,--allow-undefined
CFLAGS += -DPLATFORM_WASIGL -DGRAPHICS_API_OPENGL_ES2
endif
# Define library paths containing required libs: LDFLAGS
# NOTE: This is only required for dynamic library generation
#------------------------------------------------------------------------------------------------

View File

@ -0,0 +1 @@
#include "./rcore_desktop_glfw.c"

View File

@ -33,6 +33,8 @@
* - Android (ARM, ARM64)
* > PLATFORM_MEMORY
* - Memory framebuffer output, using software renderer, no OS required
* > PLATFORM_WASIGL
* - WASM that imports GL/GLFW from host
*
* CONFIGURATION:
* #define SUPPORT_CAMERA_SYSTEM 1
@ -528,6 +530,8 @@ const char *TextFormat(const char *text, ...); // Formatting of text with variab
#include "platforms/rcore_android.c"
#elif defined(PLATFORM_MEMORY)
#include "platforms/rcore_memory.c"
#elif defined(PLATFORM_WASIGL)
#include "platforms/rcore_wasigl.c"
#else
// TODO: Include your custom platform backend!
// i.e software rendering backend or console backend!

View File

@ -883,7 +883,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
// NOTE: OpenGL ES 2.0 can be enabled on Desktop platforms,
// in that case, functions are loaded from a custom glad for OpenGL ES 2.0
// TODO: OpenGL ES 2.0 support shouldn't be platform-dependent, neither require GLAD
#if defined(PLATFORM_DESKTOP_GLFW) || defined(PLATFORM_DESKTOP_SDL)
#if defined(PLATFORM_DESKTOP_GLFW) || defined(PLATFORM_DESKTOP_SDL) || defined(PLATFORM_WASIGL)
#define GLAD_GLES2_IMPLEMENTATION
#include "external/glad_gles2.h"
#else
@ -2484,7 +2484,7 @@ void rlLoadExtensions(void *loader)
#elif defined(GRAPHICS_API_OPENGL_ES2)
#if defined(PLATFORM_DESKTOP_GLFW) || defined(PLATFORM_DESKTOP_SDL)
#if defined(PLATFORM_DESKTOP_GLFW) || defined(PLATFORM_DESKTOP_SDL) || defined(PLATFORM_WASIGL)
// TODO: Support GLAD loader for OpenGL ES 3.0
if (gladLoadGLES2((GLADloadfunc)loader) == 0) TRACELOG(RL_LOG_WARNING, "GLAD: Cannot load OpenGL ES2.0 functions");
else TRACELOG(RL_LOG_INFO, "GLAD: OpenGL ES 2.0 loaded successfully");