[Mesa-dev] [PATCH] mesa: fix GL_LUMINANCE handling in glGetTexImage
Anuj Phogat
anuj.phogat at gmail.com
Tue Sep 11 11:43:00 PDT 2012
On Mon, Sep 10, 2012 at 6:35 PM, Brian Paul <brian.e.paul at gmail.com> wrote:
> On Mon, Sep 10, 2012 at 3:16 PM, Anuj Phogat <anuj.phogat at gmail.com> wrote:
>> On Thu, Mar 8, 2012 at 7:19 PM, Brian Paul <brianp at vmware.com> wrote:
>>> There are several cases in which we need to explicity "rebase" colors
>>> (ex: set G=B=0) when getting GL_LUMINANCE textures:
>>> 1. If the luminance texture is actually stored as rgba
>>> 2. If getting a luminance texture, but returning rgba
>>> 3. If getting an rgba texture, but returning luminance
>>>
>>> Fixes https://bugs.freedesktop.org/show_bug.cgi?id=46679
>>>
>>> Also fixes the new piglit getteximage-luminance test.
>>> ---
>>> src/mesa/main/texgetimage.c | 30 ++++++++++++++++++++++++++++--
>>> 1 files changed, 28 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
>>> index 44a828a..05b052a 100644
>>> --- a/src/mesa/main/texgetimage.c
>>> +++ b/src/mesa/main/texgetimage.c
>>> @@ -298,6 +298,8 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
>>> const gl_format texFormat =
>>> _mesa_get_srgb_format_linear(texImage->TexFormat);
>>> const GLuint width = texImage->Width;
>>> + const GLenum destBaseFormat = _mesa_base_tex_format(ctx, format);
>>> + GLenum rebaseFormat = GL_NONE;
>>> GLuint height = texImage->Height;
>>> GLuint depth = texImage->Depth;
>>> GLuint img, row;
>>> @@ -318,6 +320,28 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
>>> height = 1;
>>> }
>>>
>>> + if (texImage->_BaseFormat == GL_LUMINANCE ||
>>> + texImage->_BaseFormat == GL_INTENSITY ||
>>> + texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
>>> + /* If a luminance (or intensity) texture is read back as RGB(A), the
>>> + * returned value should be (L,0,0,1), not (L,L,L,1). Set rebaseFormat
>>> + * here to get G=B=0.
>>> + */
>>> + rebaseFormat = texImage->_BaseFormat;
>>> + }
>>> + else if ((texImage->_BaseFormat == GL_RGBA ||
>>> + texImage->_BaseFormat == GL_RGB) &&
>>> + (destBaseFormat == GL_LUMINANCE ||
>>> + destBaseFormat == GL_LUMINANCE_ALPHA ||
>>> + destBaseFormat == GL_LUMINANCE_INTEGER_EXT ||
>>> + destBaseFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT)) {
>>> + /* If we're reading back an RGB(A) texture as luminance then we need
>>> + * to return L=tex(R). Note, that's different from glReadPixels which
>>> + * returns L=R+G+B.
>>> + */
>> Brian, don't we need do handle the similar case for compressed textures?
>> i.e. _mesa_meta_GetTexImage()->decompress_texture_image() currently
>> uses _mesa_ReadPixels() to get the compressed texture data, which
>> returns L=R+G+B. I haven't yet tested how NVIDIA/AMD handle compressed
>> textures in glGetTexImage().
>
> That's probably correct. Can you take care of that?
>
> -Brian
Yeah, I verified this on NVIDIA and AMD's proprietary linux drivers.
I'll soon post
a patch to fix this.
More information about the mesa-dev
mailing list