Reputation: 3077
My interest in this question is mostly theoretical at this point.
I'd like to store images (for webgl textures) locally such as with indexedDB which I'm already using to store meshes.
Is this possible? if so then how? and is it a good idea?
Upvotes: 1
Views: 1013
Reputation: 34498
You certainly could use indexedDB to store a texture. You'd need to store the width and height, wether or not is has an alpha channel, and an array of RGB(A) values. You can then create a texture directly from that, as is shown in the answer to this question.
As for it being a good idea, that's a trickier question. Why would you be doing it? Speed? Uniformity of resource access? There's some limits typically in place on indexedDB storage that would make it difficult to store large resources in, and frankly loading from an image may well be faster, since the browser developers will have optimized that route. Also, the image will actually be larger in the DB than the JPEG or PNG equivalent, since you'll probably want to store it uncompressed. It's worth benchmarking, but I doubt there's much in the way of performance wins here.
Upvotes: 1
Reputation: 2830
You should be able to store an image in indexedDb by converting or having it as a base64 image.
Remember there is only a 5Mb limit on the database per site unless you specify unlimited in the Manifest but then it requires user authorization.
Upvotes: 1