openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.94k stars 2.55k forks source link

ofTexture : allow uploading DXT pre-compressed data #6269

Open armadillu opened 5 years ago

armadillu commented 5 years ago

I've been working on an addon to compress pixel data with DXT (ofxDXT) to upload already compressed texture data into ofTextures (vs uploading raw RGBA data and making the GPU compress it). This is very useful to be able to preload more textures in GPU memory (think image sequences / sprite sheets), but also to stream them from disk. DXT gives you a 4:1 compression ratio with a quite acceptable quality loss on RGBA texture data, and a 8:1 ratio on RGB data.

This currently works on my branch of OF (close to 0.10.1) in GL2, GL3 and GL4, but it requires some changes to ofTexture.

The changes are quite small (see here, sorry for tab vs space mess), and would only affect anything when a texture glInternalType is DXT. Basically when the internal type is of the GL_COMPRESSED_RGB_S3TC_DXT*_EXT family, instead of calling glTexImage2D() you need to call glCompressedTexImage2D() for both alloc() and load(). After this, the ofTexture just works as normal.

But I wonder if this is a chance to revisit what's up with with the compression options im ofTexture. There's an ofTextureCompression type in ofTextureData that you can seet, but its not being used anywhere in the implementation.

There's two ways you can use texture compression as far as I can tell:

  1. You upload raw RGBA data as usual, but specify you want it store compressed (and the GPU does the compression at upload time)
  2. You upload already compressed data, the GPU just stores what you send and treats it as compressed.

I feel 2 is probably more common, but 1 can also be very useful because of the upload bandwith savings.

arturoc commented 5 years ago

yes i think both cases can be useful if you want to send a PR adding the two options that would be great

armadillu commented 5 years ago

ok will do soon!