I am trying to assign an image to the texture and sometimes it causes the next error reports:
WebGL: texImage2D: Failed to get data from DOM element. Implicit width and height for this upload will be zero
WebGL: drawElements: Active texture 0 for target 0x0de1 is 'incomplete', and will be rendered as RGBA(0,0,0,1), as per the GLES 2.0.24 $3.8.2: The dimensions of level_base
are not all positive
When I reload the page the texture appears normally.
I have realized that it occurs only in Firefox and it seems that the image is not processed completely. Is there any way to check is the image ready to be processed or a workaround for this issue.
Thank you in advance and sorry for my bad English.
UPDATE: I create a framework with a pretty complicated architecture so there is a very simplified version of the code:
1. I create a texture wrapper that contains an instance of WebGL texture object.
function Texture (gl) {
// Here the texture does not keep any data.
this.texture = gl.createTexture();
};
2. When it is needed the texture gets an instance of image and performs default initialization procedure:
function initializeTexture (image) {
gl.bindTexture(gl.TEXTURE_2D, this.texture);
// Set pixel storing mode.
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
// Pass image data into the texture.
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, image);
// Handle mipmapping option.
if (this.enableMipmap &&
Math.isPowerOfTwo(this.width) &&
Math.isPowerOfTwo(this.height)) {
gl.generateMipmap(gl.TEXTURE_2D);
}
// Set filtering modes.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.magFilter);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.minFilter);
// Set wrapping modes.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.wrapS);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.wrapT);
// Unbind the texture.
gl.bindTexture(gl.TEXTURE_2D, null);
}
3. In game loop there is another default set of actions:
function applyTexture (value) {
// Pass the texture into shader program.
gl.uniform1i(uniform.location, uniform.id);
// Activate the texture.
gl.activeTexture(gl.TEXTURE0 + uniform.id);
// Bind passed texture.
gl.bindTexture(gl.TEXTURE_2D, value.texture);
};