AnsweredAssumed Answered

glGetTexImage strangeness

Question asked by dutta on Dec 10, 2015
Latest reply on Dec 11, 2015 by dutta

I am having issues with glGetTexImage. I am using it to retrieve pixels from render targets, and as far as I have been able to test it out, every pixel format works properly except for GL_R16F. This is the code:

 

  GLenum pixelType = OGL4Types::AsOGL4PixelFormat(this->pixelFormat);
  GLint components, type;
  glGetInternalformativ(GL_TEXTURE_2D, pixelType, GL_GET_TEXTURE_IMAGE_FORMAT, 4, &components);
  glGetInternalformativ(GL_TEXTURE_2D, pixelType, GL_GET_TEXTURE_IMAGE_TYPE, 4, &type);


  GLint mipWidth;
  GLint mipHeight;
  glGetTexLevelParameteriv(GL_TEXTURE_2D, mipLevel, GL_TEXTURE_WIDTH, &mipWidth);
  glGetTexLevelParameteriv(GL_TEXTURE_2D, mipLevel, GL_TEXTURE_HEIGHT, &mipHeight);


  GLint size;
  size = PixelFormat::ToSize(this->pixelFormat);


  // for some reason, the GL driver produces an additional pixel if the format is R16F
  if (this->pixelFormat == PixelFormat::R16F)
  {
  mipWidth += 1;
  mipHeight += 1;
  }


  // the row pitch must be the size of one pixel times the number of pixels in width
  outMapInfo.mipWidth = mipWidth;
  outMapInfo.mipHeight = mipHeight;
  outMapInfo.rowPitch = size * mipWidth;
  outMapInfo.depthPitch = 0;

  this->mappedData = Memory::Alloc(Memory::ObjectArrayHeap, mipWidth * mipHeight * size);
  glGetTexImage(this->target, mipLevel, components, type, this->mappedData);

 

The statement where I check if the format is R16F, and if so, add 1 extra pixel in both dimensions is required for glGetTexImage to not crash. Some of the other formats I have tested (and they work) are:

 

RGBA8

R32F

RGBA16F

RG16F

SRGBA8

R8

BC2

BC1

 

And the results occur on both the 7970 and my R9 Nano with GL driver version 6.14.10.13416.

 

Has anyone else encountered this issue?

Outcomes