1

I'm working through the openGL ES 2.0 guide, and I just stumbled on this note for the GenerateMipmap(target) command:

If the level zero array is stored in a compressed internal format, the error INVALID_OPERATION is generated.

The way I understand that is that there is no function to automatically generate mipmaps for compressed textures in openGL ES 2.0 - and everything else I've looked at seems to indicate that, even though I've never seen it concretely confirmed anywhere. I've seen that the Mali texture compression tool can automatically generate mipmaps - but that only works on Windows, Linux and OS X - and not on Android. I need my app to compress the textures and mipmap them (the idea is that a user can take an image and apply it as a texture - I've already taken care of the aspect that the texture has to have a widths and heights of 2^n and 2^m respectively). The ETC1Util takes care of compressing textures (although it only takes care of the ETC1 format, and I'm still looking for a solution for textures with an alpha channel - but that's a different question for a different day, if Google doesn't help me there).

My question is: how do you compress and mipmap textures - most importantly ETC1, but ideally also PVRTC, ATITC, S3TC and ETC2 - at runtime on Android?

trainman261
  • 123
  • 6
  • Using `glTexImage2D`, image data can be uploaded for a specific MIP-map level. But I suspect, your question is more about how to create the smaller textures for the higher MIP-map levels in compressed format? – j00hi Dec 01 '17 at 06:55
  • Yes, that's correct. – trainman261 Dec 02 '17 at 03:57

1 Answers1

1

There's nothing in OpenGL or OpenGLES for generating compressed textures.

Generally, creating compressed textures is slow, and people almost always generate them offline. For runtime generated textures, people usually keep them in basic formats like 8888, 565 or 4444 because the trade-off of compression-time vs rendering efficiency is just not worth it.

That said, it's possible to find open source code for generating most compressed formats, and there's nothing stopping you from plugging that code into your game code. For ETC1 there's this (github version). For S3TC (aka DXT) there's squish (or many others).

Columbo
  • 6,648
  • 4
  • 19
  • 30
  • For this case, it doesn't matter if it's slow. The idea is to create an object editor where the user can create objects for use in-game - and there, it doesn't matter if it takes a moment - I can display a loading message. I've looked through the tools you mention, but they don't seem to be able to automatically mipmap textures... or do they? Thanks for the links to those tools, though - how did you find them? That's the first time I saw any of them (I'll also have to learn how to implement them, but again - that's for another question if I can't figure that out). – trainman261 Dec 02 '17 at 04:08
  • 2
    Probably easiest to do the mipmapping yourself, a box filter is good enough (get the pixel colour by averaging 4 pixels from the mipmap above). There are other mipmapping fancy methods, but the quality increase is marginal, and the complexity is much higher. I found them by googling (include 'open source' in your searches) and searching on github. – Columbo Dec 02 '17 at 08:13
  • OK, thanks. implementing other code, box filter, ... I've got a lot to learn ;D – trainman261 Dec 02 '17 at 17:33