Irbis
Irbis

Reputation: 1491

glGetTexImage/glGetCompressedTexImage and sRGB colorspace

When I use sRGB internal format, for example GL_SRGB8_EXT or GL_COMPRESSED_SRGB_S3TC_DXT1_EXT as glTexImage2D argument I get an automatic sRGB to lRGB conversion when reading a texture in the shader. Does glGetTexImage/glGetCompressedTexImage also perform such conversion ?

Upvotes: 1

Views: 214

Answers (1)

Yakov Galka
Yakov Galka

Reputation: 72469

No, glGetTexImage/glGetCompressedTexImage do not perform sRGB conversion. Neither does glTexImage2D. If you set a texture image with glTexImage2D and later retrieve it with glGetTexImage (using same format and type), you'll read back the same data that you passed to glTexImage2D at the start. It doesn't matter if texture's internal format was GL_SRGB8 or GL_RGB8.

sRGB ↔ linear conversion is a server-side operation, i.e. performed by operations on the GPU. sRGB to linear conversion happens only when the GPU reads from the texture (from shaders, glBlitFramebuffer, etc). Linear to sRGB conversion happens only when the GPU writes to a texture (through imageStore, FBO, glBlitFramebuffer, etc). Consequently if you render linear data to an sRGB texture, then glGetTexImage will return sRGB data. However the conversion is done when your render to the texture, not in the glGetTexImage call.

Upvotes: 2

Related Questions