diff --git a/tests/apps/gal-webgl/gal_webgl_test.html b/tests/apps/gal-webgl/gal_webgl_test.html
index 49488c5..a0d3013 100644
--- a/tests/apps/gal-webgl/gal_webgl_test.html
+++ b/tests/apps/gal-webgl/gal_webgl_test.html
@@ -1,60 +1,84 @@
-
+
+
+
-
-
-
-
-
-
Loading WASM module...
+
+
+
Loading WASM...
-
+
diff --git a/tests/e2e/gal-webgl.spec.ts b/tests/e2e/gal-webgl.spec.ts
index 9956033..23d0174 100644
--- a/tests/e2e/gal-webgl.spec.ts
+++ b/tests/e2e/gal-webgl.spec.ts
@@ -96,9 +96,38 @@ test.describe('GAL WebGL Regression Tests', () => {
// Wait for rendering to complete
await page.waitForTimeout(100);
- // Get the canvas element and take a screenshot of just the canvas
- const canvas = await page.locator('#canvas');
- await expect(canvas).toBeVisible();
+ // Debug: list all canvases on the page
+ const canvasInfo = await page.evaluate(() => {
+ const canvases = document.querySelectorAll('canvas');
+ const windowContainer = document.getElementById('window-container');
+ return {
+ canvases: Array.from(canvases).map(c => ({
+ id: c.id,
+ className: c.className,
+ width: c.width,
+ height: c.height,
+ display: window.getComputedStyle(c).display,
+ parentId: c.parentElement?.id
+ })),
+ windowContainerChildren: windowContainer?.children.length || 0,
+ allElements: document.querySelectorAll('#window-container *').length
+ };
+ });
+ console.log('Canvas debug:', JSON.stringify(canvasInfo, null, 2));
+
+ // Get the canvas element
+ // First try GL canvas, fall back to main canvas
+ let canvas = page.locator('.gl-canvas').first();
+ if (!(await canvas.count())) {
+ canvas = page.locator('#canvas');
+ }
+
+ // If still no canvas, use first available
+ if (!(await canvas.count())) {
+ canvas = page.locator('canvas').first();
+ }
+
+ await expect(canvas).toBeVisible({ timeout: 5000 });
// Screenshot the canvas (matching native 800x600 output)
const screenshotPath = path.join(OUTPUT_DIR, `gal-${scenarioName}.png`);
diff --git a/tests/gal-regression/wasm/Makefile b/tests/gal-regression/wasm/Makefile
index 2d0bb81..e98bb8e 100644
--- a/tests/gal-regression/wasm/Makefile
+++ b/tests/gal-regression/wasm/Makefile
@@ -29,7 +29,9 @@ SYSROOT = $(PROJECT_ROOT)/build-wasm/sysroot
# KiCad include paths
# Note: -I../native provides stub files (config.h, kicad_stubs.h, etc.)
+# Note: -I../scenarios provides shared test scenarios (gal_test_scenarios.h)
KICAD_INCLUDES = -I../native \
+ -I../scenarios \
-Igenerated \
-I$(KICAD_ROOT)/include \
-I$(KICAD_ROOT)/include/gal \
@@ -76,7 +78,18 @@ JS = $(TOOLS_ROOT)/wx.js
HTML_TEMPLATE = $(TOOLS_ROOT)/template.html
# Source files
-MAIN_SRCS = gal_webgl_test.cpp
+MAIN_SRCS = gal_webgl_test.cpp wasm_stubs.cpp
+
+# KiCad sources needed for linking (not in WEBGL_SRCS)
+KICAD_SRCS = $(KICAD_ROOT)/common/gal/hidpi_gl_canvas.cpp \
+ $(KICAD_ROOT)/common/gal/graphics_abstraction_layer.cpp \
+ $(KICAD_ROOT)/common/gal/gal_display_options.cpp
+
+# Test scenario sources (shared with native test)
+SCENARIO_SRCS = ../scenarios/gal_test_scenarios.cpp
+
+# GLU tesselator - stub (no actual implementation needed for basic shapes)
+GLU_SRCS =
# Generated shader sources (from generate_shaders.py)
SHADER_SRCS = generated/glsl_kicad_frag.cpp \
@@ -107,7 +120,7 @@ WEBGL_SRCS = webgl/webgl_gal.cpp \
webgl/gl_resources.cpp \
webgl/webgl_antialiasing.cpp
-SRCS = $(MAIN_SRCS) $(SHADER_SRCS) $(WEBGL_SRCS)
+SRCS = $(MAIN_SRCS) $(KICAD_SRCS) $(SCENARIO_SRCS) $(GLU_SRCS) $(SHADER_SRCS) $(WEBGL_SRCS)
OBJS = $(SRCS:.cpp=.o)
# Target
diff --git a/tests/gal-regression/wasm/gal_webgl_test.cpp b/tests/gal-regression/wasm/gal_webgl_test.cpp
index 91f4969..5396c19 100644
--- a/tests/gal-regression/wasm/gal_webgl_test.cpp
+++ b/tests/gal-regression/wasm/gal_webgl_test.cpp
@@ -1,87 +1,70 @@
/**
* GAL WebGL Test - WASM Entry Point
*
- * This is a test harness that renders GAL test scenarios using WEBGL_GAL
+ * This test harness renders GAL test scenarios using WEBGL_GAL
* and allows Playwright to capture screenshots for comparison against native.
- *
- * Phase 1: Stub that initializes WebGL and renders a test pattern
- * Phase 2: Full WEBGL_GAL implementation with all scenarios
*/
+// Include kiglew.h first to set GLEW guard before anything includes
+#include "webgl/kiglew.h"
+
+#include
+#include
+
#include
#include
-#include
+
+// KiCad GAL headers
+#include
+#include