How do I test if the WebGLTexture
object is 'complete' ?
Currently I get this message:
[WebGLRenderingContext]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering or is not 'texture complete'
I get this warning because the render-loop is trying to use the texture before its image has finished loading, so how to fix that?
I had this issue when attempting to deploy my HTML5/JS app to an Android phone using Cordova.
At first, I thought my issue was that my spritesheet/texture atlas was too large for the mobile GPU to load. So I batch shrank all the images using ImageMagick's
mogrify
(mogrify -resize 256x256 *.png
), but was still having issues. This step was still necessary tho (as my8000x8000 .png
was too much for phones).Then I used
console.log(
navigator.userAgent
)
to check my browser version and saw that the Chromium used was older than my browser. So I re-installed the Crosswalk plugin and everything is rendering fine.To fix that issue, use some boolean value to tell if the image has loaded.
The easiest way to fix that is to make a 1x1 texture at creation time.
Then when the image loads you can replace the 1x1 pixel texture with the image. No flags needed and your scene will render with the color of your choice until the image has loaded.
Just for the sake of saving people the trouble of running into the next problem they are most likely going to run into, WebGL requires mips or it requires filtering that doesn't require mips. On top of that it requires textures with dimensions that are a power of 2 (ie, 1, 2, 4, 8, ..., 256, 512, etc) to use mips. So, when loading an image you'll most likely want to setup the filtering to handle this correctly.