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];
            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,


works with no issues. Again normalMapTexture holds a HTMLImageElement.

Thank you.

  • \$\begingroup\$ Searching a lot since 3-4 hours any help will be much appriciated. \$\endgroup\$ – Ali Somay Feb 6 '17 at 20:30
  • \$\begingroup\$ This question is answered in my other post in StackOverflow. stackoverflow.com/questions/42073596/… \$\endgroup\$ – Ali Somay Feb 7 '17 at 17:56

Actually it was my bad,

First form of the function gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,texture);

accepts these types https://developer.mozilla.org/en/docs/Web/API/WebGLRenderingContext/texImage2D but second form accepts only ArrayBufferView or null. https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl.RGB, 1024, 1024, 0, gl.RGB, gl.UNSIGNED_BYTE,texture);

So i used the first form with the cubemap, then it worked.

Also webgl2 context accepts other types in the both forms of these functions, you can check it from the first link again.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.