Hi I hava jpeg compressed data stored in Uin8Array . I read about texture in Webgl . All Link what i saw initialize texture after loading image ( created by jpeg data , image.src = “some data” image.onload ( load texture ) ) . But this is asynchronus process . This process works fine . But can i use function compressedTexImage2D(target, level, internalFormat, width, height, border, data) internel format should be related to jpeg and data will be in form of compressed jpeg format ( width or height is not in form of pow of 2 ) so that whole process should be synchronous ? Or any other method in webgl that take jpeg compressed data directly without loading an image ?
Share
So here is the bad news currently as of September 2012 WebGL does not actually support
compressedTexImage2D. If you try calling the function it will always return anINVALID_ENUMerror. If you are curious here is the section of the specification that explains it.Now the some what good news is that you can create a texture from a
Uint8Arrayof jpeg data. I’m not sure how to do this synchronously, but maybe this code will help anyways.Basically we have to convert the original
Uint8Arraydata into a base64 string, so we can create a new image with the base64 string as the image source.So here is the code:
I have a demo of the function here. To keep the file small I’m only using a 24×24 pixel jpeg. Just in case you are wondering, the function also works for jpeg’s with non power of 2 heights/widths.
If you want to see the full source code of the demo look here.