0
\$\begingroup\$

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.

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

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .