-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebgl-test.html
More file actions
348 lines (305 loc) · 10 KB
/
webgl-test.html
File metadata and controls
348 lines (305 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WebGL Video Test</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
.container {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.debug-panel {
flex: 1;
min-width: 300px;
background: #f5f5f5;
padding: 15px;
border-radius: 8px;
}
.webgl-container {
flex: 1;
min-width: 300px;
}
canvas {
border: 1px solid #ccc;
max-width: 100%;
}
video {
max-width: 100%;
margin-bottom: 10px;
}
.error {
color: red;
background: #ffe6e6;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
.success {
color: green;
background: #e6ffe6;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
pre {
background: #000;
color: #0f0;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
font-size: 12px;
}
</style>
</head>
<body>
<h1>WebGL Video Compatibility Test</h1>
<p>This page helps debug WebGL video texture issues between different browsers.</p>
<div class="container">
<div class="debug-panel">
<h2>Debug Information</h2>
<div id="debug-info"></div>
<h3>Console Output</h3>
<pre id="console-output"></pre>
</div>
<div class="webgl-container">
<h2>WebGL Canvas</h2>
<video id="test-video" controls crossorigin="anonymous" loop muted>
<source
src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
type="video/mp4"
/>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>
<br />
<canvas id="webgl-canvas" width="640" height="360"></canvas>
<br />
<button onclick="startTest()">Start WebGL Test</button>
<button onclick="clearConsole()">Clear Console</button>
</div>
</div>
<script>
// Capture console output
const consoleOutput = document.getElementById('console-output');
const originalLog = console.log;
const originalError = console.error;
const originalWarn = console.warn;
function addToConsole(type, args) {
const timestamp = new Date().toLocaleTimeString();
const message = Array.from(args)
.map((arg) =>
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)
)
.join(' ');
consoleOutput.textContent += `[${timestamp}] ${type.toUpperCase()}: ${message}\n`;
consoleOutput.scrollTop = consoleOutput.scrollHeight;
}
console.log = (...args) => {
originalLog.apply(console, args);
addToConsole('log', args);
};
console.error = (...args) => {
originalError.apply(console, args);
addToConsole('error', args);
};
console.warn = (...args) => {
originalWarn.apply(console, args);
addToConsole('warn', args);
};
function clearConsole() {
consoleOutput.textContent = '';
}
function displayDebugInfo() {
const debugInfo = document.getElementById('debug-info');
let html = '';
// Browser info
html += `<div class="success"><strong>Browser:</strong> ${navigator.userAgent}</div>`;
html += `<div><strong>Platform:</strong> ${navigator.platform}</div>`;
// WebGL support check
const canvas = document.createElement('canvas');
const webgl2 = canvas.getContext('webgl2');
const webgl1 = canvas.getContext('webgl');
if (webgl2) {
html += `<div class="success">✓ WebGL2 supported</div>`;
} else if (webgl1) {
html += `<div class="success">✓ WebGL1 supported (WebGL2 not available)</div>`;
} else {
html += `<div class="error">✗ WebGL not supported</div>`;
debugInfo.innerHTML = html;
return;
}
const gl = webgl2 || webgl1;
html += `<div><strong>Vendor:</strong> ${gl.getParameter(gl.VENDOR)}</div>`;
html += `<div><strong>Renderer:</strong> ${gl.getParameter(gl.RENDERER)}</div>`;
html += `<div><strong>Version:</strong> ${gl.getParameter(gl.VERSION)}</div>`;
html += `<div><strong>Shading Language:</strong> ${gl.getParameter(
gl.SHADING_LANGUAGE_VERSION
)}</div>`;
html += `<div><strong>Max Texture Size:</strong> ${gl.getParameter(
gl.MAX_TEXTURE_SIZE
)}</div>`;
// Check extensions
const extensions = gl.getSupportedExtensions();
const importantExtensions = [
'OES_texture_float',
'OES_texture_float_linear',
'WEBGL_lose_context',
'EXT_texture_filter_anisotropic',
];
html += '<div><strong>Important Extensions:</strong><ul>';
importantExtensions.forEach((ext) => {
const supported = extensions.includes(ext);
html += `<li style="color: ${supported ? 'green' : 'red'}">${ext}: ${
supported ? '✓' : '✗'
}</li>`;
});
html += '</ul></div>';
debugInfo.innerHTML = html;
}
// Simple WebGL test
function startTest() {
console.log('Starting WebGL video texture test...');
const canvas = document.getElementById('webgl-canvas');
const video = document.getElementById('test-video');
// Try to get WebGL context
const gl = canvas.getContext('webgl2') || canvas.getContext('webgl');
if (!gl) {
console.error('Failed to get WebGL context');
return;
}
console.log('WebGL context obtained successfully');
// Simple vertex shader
const vertexShaderSource =
gl instanceof WebGL2RenderingContext
? `#version 300 es
in vec2 a_position;
in vec2 a_texCoord;
out vec2 v_texCoord;
void main() {
gl_Position = vec4(a_position, 0.0, 1.0);
v_texCoord = a_texCoord;
}`
: `attribute vec2 a_position;
attribute vec2 a_texCoord;
varying vec2 v_texCoord;
void main() {
gl_Position = vec4(a_position, 0.0, 1.0);
v_texCoord = a_texCoord;
}`;
// Simple fragment shader
const fragmentShaderSource =
gl instanceof WebGL2RenderingContext
? `#version 300 es
precision mediump float;
uniform sampler2D u_texture;
in vec2 v_texCoord;
out vec4 outColor;
void main() {
outColor = texture(u_texture, v_texCoord);
}`
: `precision mediump float;
uniform sampler2D u_texture;
varying vec2 v_texCoord;
void main() {
gl_FragColor = texture2D(u_texture, v_texCoord);
}`;
// Compile shader
function compileShader(source, type) {
const shader = gl.createShader(type);
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
const error = gl.getShaderInfoLog(shader);
console.error('Shader compilation error:', error);
gl.deleteShader(shader);
return null;
}
return shader;
}
const vertexShader = compileShader(vertexShaderSource, gl.VERTEX_SHADER);
const fragmentShader = compileShader(fragmentShaderSource, gl.FRAGMENT_SHADER);
if (!vertexShader || !fragmentShader) {
console.error('Shader compilation failed');
return;
}
// Create program
const program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
console.error('Program linking error:', gl.getProgramInfoLog(program));
return;
}
console.log('Shaders compiled and linked successfully');
// Set up geometry
const positions = new Float32Array([
-1, -1, 0, 1, 1, -1, 1, 1, -1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 1, 1, 1, 1, 1, 0,
]);
const buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
// Set up attributes
const positionLocation = gl.getAttribLocation(program, 'a_position');
const texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
gl.enableVertexAttribArray(positionLocation);
gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 16, 0);
gl.enableVertexAttribArray(texCoordLocation);
gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 16, 8);
// Create texture
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
console.log('WebGL setup complete, starting render loop...');
// Render function
function render() {
requestAnimationFrame(render);
if (video.readyState < 2) return;
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video);
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(0, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.useProgram(program);
gl.drawArrays(gl.TRIANGLES, 0, 6);
// Check for errors
const error = gl.getError();
if (error !== gl.NO_ERROR) {
console.error('WebGL error:', error);
}
}
// Wait for video to be ready
if (video.readyState >= 2) {
console.log('Video already ready, starting render');
render();
} else {
console.log('Waiting for video to be ready...');
video.addEventListener(
'canplay',
() => {
console.log('Video ready, starting render');
render();
},
{ once: true }
);
video.play().catch((e) => {
console.error('Video play failed:', e);
});
}
}
// Initialize on load
window.addEventListener('load', () => {
displayDebugInfo();
console.log('Page loaded, ready for testing');
});
</script>
</body>
</html>