Hi,
SWAP_BYTES has no effects with the latest OGL driver on Windows.
[Step to reproduce]
Run the sample code;
GetTexImage should return data whose Component bytes order are swapped, just as the spec.
[HW/Driver:]
[OS]:
Windows 11
[Sample Code]: --------------------------------------------------------------------------------------------
typedef uint16_t ComponentType;
GLuint initTextureUnorm(size_t Width, size_t Height, GLenum format)
{
GLuint tex = -1;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
uint32_t channel = 4;
GLenum internalFmt = 0;
switch (format)
{
case GL_RED:
channel = 1;
internalFmt = GL_R16;
break;
case GL_RG:
channel = 2;
internalFmt = GL_RG16;
break;
case GL_RGB:
channel = 3;
internalFmt = GL_RGB16;
break;
case GL_RGBA:
channel = 4;
internalFmt = GL_RGBA16;
break;
default:
assert(0);
break;
}
std::vector<ComponentType> data;
data.resize(Width * Height * channel);
uint32_t divdor = (ComponentType)(-1);
for (size_t j = 0; j < Height; j++)
{
uint32_t R, G, B, A;
R = G = Height - j;
B = j;
A = divdor;
for (size_t i = 0; i < Width; i++)
{
R = (R + i * 12) % divdor;
G = (G + i * 12 + i * 12) % divdor;
B = (B + i * 12) % divdor;
if (channel == 1)
{
data[channel * (j * Width + i) + 0] = (ComponentType)R;
}
else if (channel == 2)
{
data[channel * (j * Width + i) + 0] = (ComponentType)R;
data[channel * (j * Width + i) + 1] = (ComponentType)G;
}
else if (channel == 3)
{
data[channel * (j * Width + i) + 0] = (ComponentType)R;
data[channel * (j * Width + i) + 1] = (ComponentType)G;
data[channel * (j * Width + i) + 2] = (ComponentType)B;
}
else if (channel == 4)
{
data[channel * (j * Width + i) + 0] = (ComponentType)R;
data[channel * (j * Width + i) + 1] = (ComponentType)G;
data[channel * (j * Width + i) + 2] = (ComponentType)B;
data[channel * (j * Width + i) + 3] = (ComponentType)A;
}
}
}
GLenum type = GL_UNSIGNED_BYTE;
internalFmt = GL_RGBA8;
type = GL_UNSIGNED_SHORT;
internalFmt = GL_RGBA16;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
// Unpack
//glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
//glPixelStorei(GL_UNPACK_SKIP_ROWS, 32);
//glPixelStorei(GL_UNPACK_SKIP_PIXELS, 64);
glTexImage2D(GL_TEXTURE_2D, GLint(0), internalFmt, GLsizei(Width), GLsizei(Height),
0, format, type, data.data());
std::vector<ComponentType> savedata;
savedata.resize(Width * Height * channel);
glGetTexImage(GL_TEXTURE_2D, GLint(0), format, type, savedata.data());
return tex;
}