2

I'm working on a WebGL project and all my textures render fine. When i wanted to implement a cubemap i started getting this type error. Argument 9 of WebGLRenderingContext.texImage2D does not implement interface ArrayBufferViewOrNull. in all browsers. A fragment of my code i use to load the textures is,

    var cubeMap = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_CUBE_MAP, cubeMap);

    for(var i = 0; i < 6; i++)
    {   
        var img = cubeMapArr[i];
        console.log(img);
        gl.texImage2D(
            gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 
            0, gl.RGB, 1024, 1024, 0, gl.RGB, gl.UNSIGNED_BYTE,img);
    }

the cubeMapArr holds HTMLImageElements. Any ideas or experiences about this issue? Using gl.texImage2D() like for example this,

gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,normalMapTexture);

works with no issues. Again normalMapTexture holds a HTMLImageElement.

Thank you.

2
  • Thank you for the edit genpfault this question should be tagged opengl-es. Commented Feb 6, 2017 at 17:25
  • 2
    no it should not be tagged opengl-es because the error as nothing to do with opengl-es. OpenGL ES has no concept of ArrayBufferViews or HTMLImageElements Commented Feb 7, 2017 at 12:56

1 Answer 1

4

In WebGL there are 2 forms of texImage2D

gl.texImage2D(bindPoint, mipLevel, internalFormat, format, type, HTMLElement);

where HTMLElement is either HTMLImageElement, HTMLVideoElement or HTMLCanvasElement

and then there's

gl.texImage2D(bindPoint, mipLevel, internalFormat, width, height, border, 
              format, type, ArrayBufferViewOrNull);

Your code is passing an HTMLImageElement to the second form of the function which is why it's complaining it's not an ArrayBufferViewOrNull

In other words remove 1024, 1024, 0, from your call to gl.texImage2D

In WebGL2 the form you used exists but be aware WebGL2 just shipped in September 2021 on Safari 15.

Sign up to request clarification or add additional context in comments.

2 Comments

I updated firefox and used webgl2 context, i think it is only available in firefox. The second version(with more arguments) of gl.texImage2d function works with a HTMLImageElement there. Thanks for the answer the first version with less arguments works in webgl1 context.
WebGL2 has shipped in both Firefox and Chrome

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.