Replacement for GL_LUMINANCE, GL_LUMINANCE_ALPHA​
Asked Answered
A

1

15

For memory-efficient realtime embedded graphics I have traditionally used DDS images encoded using GL_LUMINANCE when I need lossless grayscale images (or GL_LUMINANCE_ALPHA when there is alpha needed). However, I have just discovered that these file formats were deprecated in OpenGL 3 and removed from 3.1.

Is there a replacement image format for lossless grayscale-only data that is 8 bits per pixel or less (or 16bpp when alpha is involved)?

Allot answered 19/11, 2013 at 16:27 Comment(0)
G
12

If you scroll up a bit on that wiki page you'll see GL_RED/GL_R* and GL_RG* for 1- and 2-channel images.

glTexImage2D():

GL_RED: Each element is a single red component. The GL converts it to floating point and assembles it into an RGBA element by attaching 0 for green and blue, and 1 for alpha...

GL_RG: Each element is a red/green double. The GL converts it to floating point and assembles it into an RGBA element by attaching 0 for blue, and 1 for alpha...

As GuyRT pointed out if you have EXT_texture_swizzle/ARB_texture_swizzle and/or OpenGL version >= 3.3 you can use swizzle mask to expand out/rearrange your texture color components.

Groomsman answered 19/11, 2013 at 16:34 Comment(7)
Are these semantically equivalent, such that a GL_RED should always be interpreted by a shader to replicate the values across RGB, and RG should always use the green/second channel for alpha?Allot
No, you'll have to expand them out yourself in the shader.Groomsman
Sorry, I meant: is it considered official (or at least commonplace) that a shader reading from GL_RED should always expand the values across green and blue? Or is this basically shoe-horning the explicit meaning of GL_LUMINANCE into the implementation of GL_RED?Allot
I don't think there's a convention, official or otherwise.Groomsman
You can also use swizzling, so that your shader sees the values as luminance/alpha - have a look at: opengl.org/wiki/Texture#Swizzle_maskNomarchy
Are GL_RED and GL_RG available for older OpenGLs too?Acquittance
@yairchu: GL_RED is, but not GL_RG.Groomsman

© 2022 - 2024 — McMap. All rights reserved.