|
1 | 1 | import * as React from 'react' |
2 | 2 | import type { GLViewProps } from 'expo-gl' |
3 | | -import { WebGL2RenderingContext } from '@react-three/test-renderer/src/WebGL2RenderingContext' |
| 3 | + |
| 4 | +//* WebGL2 Mock Context ============================== |
| 5 | + |
| 6 | +// Minimal WebGL2RenderingContext mock for testing |
| 7 | +// Based on @react-three/test-renderer's implementation |
| 8 | +class MockWebGL2RenderingContext { |
| 9 | + canvas: HTMLCanvasElement |
| 10 | + drawingBufferWidth: number |
| 11 | + drawingBufferHeight: number |
| 12 | + |
| 13 | + constructor(canvas: HTMLCanvasElement) { |
| 14 | + this.canvas = canvas |
| 15 | + this.drawingBufferWidth = canvas.width || 1280 |
| 16 | + this.drawingBufferHeight = canvas.height || 800 |
| 17 | + } |
| 18 | + |
| 19 | + // WebGL methods (no-ops for testing) |
| 20 | + getParameter = () => null |
| 21 | + getExtension = () => null |
| 22 | + createShader = () => ({}) |
| 23 | + createProgram = () => ({}) |
| 24 | + createBuffer = () => ({}) |
| 25 | + createTexture = () => ({}) |
| 26 | + createFramebuffer = () => ({}) |
| 27 | + createRenderbuffer = () => ({}) |
| 28 | + bindBuffer = () => {} |
| 29 | + bindTexture = () => {} |
| 30 | + bindFramebuffer = () => {} |
| 31 | + bindRenderbuffer = () => {} |
| 32 | + bufferData = () => {} |
| 33 | + shaderSource = () => {} |
| 34 | + compileShader = () => {} |
| 35 | + attachShader = () => {} |
| 36 | + linkProgram = () => {} |
| 37 | + useProgram = () => {} |
| 38 | + enable = () => {} |
| 39 | + disable = () => {} |
| 40 | + clear = () => {} |
| 41 | + clearColor = () => {} |
| 42 | + clearDepth = () => {} |
| 43 | + viewport = () => {} |
| 44 | + scissor = () => {} |
| 45 | + drawArrays = () => {} |
| 46 | + drawElements = () => {} |
| 47 | + getShaderParameter = () => true |
| 48 | + getProgramParameter = () => true |
| 49 | + getShaderInfoLog = () => '' |
| 50 | + getProgramInfoLog = () => '' |
| 51 | + getUniformLocation = () => ({}) |
| 52 | + getAttribLocation = () => 0 |
| 53 | + enableVertexAttribArray = () => {} |
| 54 | + vertexAttribPointer = () => {} |
| 55 | + uniform1i = () => {} |
| 56 | + uniform1f = () => {} |
| 57 | + uniform2f = () => {} |
| 58 | + uniform3f = () => {} |
| 59 | + uniform4f = () => {} |
| 60 | + uniformMatrix4fv = () => {} |
| 61 | + texImage2D = () => {} |
| 62 | + texParameteri = () => {} |
| 63 | + pixelStorei = () => {} |
| 64 | + generateMipmap = () => {} |
| 65 | + deleteShader = () => {} |
| 66 | + deleteProgram = () => {} |
| 67 | + deleteBuffer = () => {} |
| 68 | + deleteTexture = () => {} |
| 69 | + deleteFramebuffer = () => {} |
| 70 | + deleteRenderbuffer = () => {} |
| 71 | + blendFunc = () => {} |
| 72 | + blendEquation = () => {} |
| 73 | + depthFunc = () => {} |
| 74 | + depthMask = () => {} |
| 75 | + cullFace = () => {} |
| 76 | + frontFace = () => {} |
| 77 | + activeTexture = () => {} |
| 78 | + flush = () => {} |
| 79 | + finish = () => {} |
| 80 | + getContextAttributes = () => ({}) |
| 81 | + isContextLost = () => false |
| 82 | + getSupportedExtensions = () => [] |
| 83 | + readPixels = () => {} |
| 84 | + renderbufferStorage = () => {} |
| 85 | + framebufferTexture2D = () => {} |
| 86 | + framebufferRenderbuffer = () => {} |
| 87 | + checkFramebufferStatus = () => 36053 // GL_FRAMEBUFFER_COMPLETE |
| 88 | + |
| 89 | + // Expo-specific extension |
| 90 | + endFrameEXP = () => {} |
| 91 | +} |
| 92 | + |
| 93 | +//* GLView Mock Component ============================== |
4 | 94 |
|
5 | 95 | export function GLView({ onContextCreate, ref, ...props }: GLViewProps & any) { |
6 | 96 | React.useLayoutEffect(() => { |
7 | | - const gl = new WebGL2RenderingContext({ width: 1280, height: 800 } as HTMLCanvasElement) |
8 | | - gl.endFrameEXP = () => {} |
| 97 | + const canvas = { width: 1280, height: 800 } as HTMLCanvasElement |
| 98 | + const gl = new MockWebGL2RenderingContext(canvas) |
9 | 99 | onContextCreate(gl as any) |
10 | 100 | }, [onContextCreate]) |
11 | 101 |
|
12 | 102 | return React.createElement('glview', props) |
13 | 103 | } |
| 104 | + |
| 105 | +export { MockWebGL2RenderingContext as ExpoWebGLRenderingContext } |
0 commit comments