Closed erikmchut closed 3 years ago
Hey @erikmchut.
Yeah, a PR would be great!
In terms of tests, I'd keep this out of the gl-conformance package (unless you believe it's in the scope of GL spec compliance), and simply add a test file/ suite in the tests
directory.
I'll start there. But, yes โ it is part of the spec:
From the WebGL1 Spec: https://www.khronos.org/registry/webgl/specs/latest/1.0/#TEXIMAGE2D
void texImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, [AllowShared] ArrayBufferView? pixels)
(OpenGL ES 2.0 ยง3.7.1, man page)If pixels is null, a buffer of sufficient size initialized to 0 is passed.
If pixels is non-null, the type of pixels must match the type of the data to be read. If it is UNSIGNED_BYTE, a Uint8Array or Uint8ClampedArray must be supplied; if it is UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_4_4_4_4, or UNSIGNED_SHORT_5_5_5_1, a Uint16Array must be supplied. If the types do not match, an INVALID_OPERATION error is generated.
If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is generated.
See Pixel Storage Parameters for WebGL-specific pixel storage parameters that affect the behavior of this function.
If pixels is non-null but its size is less than what is required by the specified width, height, format, type, and pixel storage parameters, generates an INVALID_OPERATION error.
My apologies โ this source that needs fixing is actually in the node-canvas-webgl repo. https://github.com/akira-cn/node-canvas-webgl.
Moving this issue there.
The OpenGL and WebGL process for allocating texture memory without actually uploading data is to call texImage2D with a null for the final parameter. The current code in headless-gl tries to dereference the null and throws an exception.
@dhritzkiv โ the fix is easy (just null check and don't dereference
pixels
). I'd be happy to send a PR, but I'm curious about how to go about updating thegl-conformance
package that tests this functionality. It seems the unit tests for WebGL support are not in the headless-gl package. Do you want the fix first or the conformance test first?