What OpenGL ES texture format should I use for bet

2019-04-14 01:09发布

I'm developing some software which uses a texture map to store geometry. Using GL_RGB for the internal format gives a lot of aliasing, I assume because the texture is being compressed down to GL_RGB4 by default.

On a desktop I can use GL_RGB16 or GL_RGB32F (etc.) to set the internal format, but under OpenGL ES 2.0 there doesn't seem to be any of these formats. Is there an alternative, or extension, that is available under IOS which I can use?

2条回答
可以哭但决不认输i
2楼-- · 2019-04-14 01:24

So, after a bit of research, you can get float textures (as mentioned by @Tommy). What you can't do is access them from a vertex shader under IOS, making it impossible to use them to store geometry.

查看更多
Anthone
3楼-- · 2019-04-14 01:44

According to Apple (and my own experience) GL_RGB and GL_UNSIGNED_BYTE uses 8:8:8 storage. To drop to lower colour precision you'd need to specify a type of GL_UNSIGNED_SHORT_5_6_5 or one of the other types that packs multiple channels into one short.

If precision problems are creeping in nevertheless then it might be wise to check out the GL_OES_texture_float and GL_OES_texture_half_float extensions. You're limited to GL_NEAREST filtering, but I expect that's what you're using anyway since this is an exercise in data storage, and you can upload your source channels with 16 or 32 bits per pixel.

EDIT: example usage ripped directly from a project (which is uploading a 1 channel/pixel image, but you get the idea):

GLfloat *integralImage;

/* <lots of stuff to allocate storage and fill integralImage here> */

glTexImage2D(
    GL_TEXTURE_2D, 0, GL_LUMINANCE,
    256, 256, 0,
    GL_LUMINANCE, GL_FLOAT, 
    integralImage);
查看更多
登录 后发表回答