opengl es - Loading PNG images but using them as COMPRESSED_RGBA_S3TC_DXT5_EXT in WebGL? -
i'm trying load images in webgl, , uploading them gpu. i'd use compressed texture format, though original images uncompressed/lossless.
to upload, i'm doing:
gl.teximage2d(gl.texture_2d, 0, gl.rgba, gl.rgba, gl.unsigned_byte, texturesource);
in above code, texturesource
loaded (say, "texture.png").
it works well, i'd load webgl_compressed_texture_s3tc
formats (compressed_rgb_s3tc_dxt1_ext
) store image in compressed fashion.
i make sure extension available , enabled...
var ext = gl.getextension("webgl_compressed_texture_s3tc"); var fmt = ext.compressed_rgba_s3tc_dxt5_ext; console.log(fmt); // 33779
but can't use format. using teximage2d()
doesn't work:
gl.teximage2d(gl.texture_2d, 0, fmt, fmt, gl.unsigned_byte, texturesource); // webgl: invalid_enum: teximage2d: invalid texture format // [.webglrenderingcontext]render warning: texture bound texture unit 0 not renderable. maybe non-power-of-2 , have incompatible texture filtering or not 'texture complete'
the expected method compressedteximage2d()
, that's not helpful either:
gl.compressedteximage2d(gl.texture_2d, 0, fmt, 256, 256, 0, texture.source); // uncaught typeerror: failed execute 'compressedteximage2d' on 'webglrenderingcontext': parameter 7 not of type 'arraybufferview'.
this because compressedteximage2d()
expects uint8array
actual dds/dxt data, not javascript image i'm passing.
the obvious solution uploading files in native dds format - files have been compressed somewhere else. that's i'm trying avoid: in current workflow, it'd make sense have image in original format rather pre-compress them (or having duplicates).
my question such: can still use original png images, loading them, , having them upload gpu on compressed format? in other words, can compress textures dxt1/5 formats on fly?
i'm little bit constrained video memory in i'm doing, saving great. managed minimize space used textures using unsigned_short_4_4_4_4
, other data types, start, i'd try using native compression too.
i haven't found documentation on topic, nor found relevant code on other popular libraries (three.js, pixi, etc), leads me believe request super stupid, i'd understand why. this page hints @ licensing issues, might why webgl doesn't feature way compress file, nor allow browser support of image objects.
can still use original png images, loading them, , having them upload gpu on compressed format? in other words, can compress textures dxt1/5 formats on fly?
as far informed: no.
i work on desktop , embedded gl, there no chance compress textures on fly without dedicated code or library.
(and, well, dxt formats not good, either, if textures detailed or have lots of different colors within small buckets. you're better off using smaller textures, dxt1 compresses 1/8th , dxt5 1/4 of original size (which halving resolution of texture).)
Comments
Post a Comment