Skip to content

Commit 552ef49

Browse files
committed
feat: add WebGLShader component with adaptive rendering, hardware feature detection, and real-time performance diagnostics.
1 parent 1ab8f95 commit 552ef49

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

components/ui/web-gl-shader.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function WebGLShader() {
4848
colorDepth: 24,
4949
hdrSupported: false,
5050
colorGamut: "sRGB",
51+
renderingGamut: "sRGB",
5152
// -- WebGL --
5253
webglVersion: "WebGL 1.0",
5354
maxTextureSize: 0,
@@ -144,6 +145,23 @@ export function WebGLShader() {
144145
return;
145146
}
146147

148+
// --- Auto-upgrade color gamut ---
149+
// Attempt to render in the widest gamut the display supports
150+
let renderingGamut = "sRGB";
151+
if (webglVersion === "WebGL 2.0") {
152+
const gl2 = gl as WebGL2RenderingContext;
153+
try {
154+
// Try P3 first (widest commonly supported)
155+
if (typeof window !== "undefined" && window.matchMedia("(color-gamut: p3)").matches) {
156+
gl2.drawingBufferColorSpace = "display-p3";
157+
renderingGamut = "Display P3";
158+
}
159+
} catch {
160+
// drawingBufferColorSpace not supported in this browser, stay sRGB
161+
renderingGamut = "sRGB";
162+
}
163+
}
164+
147165
// --- Collect GPU & WebGL stats ---
148166
const rendererDebugInfo = gl.getExtension("WEBGL_debug_renderer_info");
149167
const renderer = rendererDebugInfo ? gl.getParameter(rendererDebugInfo.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER);
@@ -315,6 +333,7 @@ export function WebGLShader() {
315333
colorDepth,
316334
hdrSupported,
317335
colorGamut,
336+
renderingGamut,
318337
nativeDpr,
319338
dprMultiplier,
320339
actualDpr: currentPixelRatio,
@@ -530,6 +549,7 @@ export function WebGLShader() {
530549
<div className="flex justify-between gap-4"><span>Color Depth</span><span className="text-white font-medium">{stats.colorDepth}-bit</span></div>
531550
<div className="flex justify-between gap-4"><span>Color Gamut</span><span className={`font-medium ${stats.colorGamut !== "sRGB" ? "text-emerald-400" : "text-white"}`}>{stats.colorGamut}</span></div>
532551
<div className="flex justify-between gap-4"><span>HDR Display</span><span className={`font-medium ${stats.hdrSupported ? "text-emerald-400" : "text-white/50"}`}>{stats.hdrSupported ? "Supported" : "Standard (SDR)"}</span></div>
552+
<div className="flex justify-between gap-4"><span>Rendering In</span><span className={`font-medium ${stats.renderingGamut !== "sRGB" ? "text-emerald-400" : "text-white"}`}>{stats.renderingGamut}</span></div>
533553
</div>
534554
</section>
535555

0 commit comments

Comments
 (0)