Fix for screenshot crash at 1366 x 768 resolution (Intel Graphics)
by Geom · in Torque Game Engine · 12/08/2010 (7:46 pm) · 4 replies
Got a shiny new laptop. Native screen resolution is 1366 x 768. But sadly, I discovered that TGE corrupts memory data whenever I take a screenshot at this resolution.
The fix seems to be as simple as adding a call to glPixelStorei(GL_PACK_ALIGNMENT,1) in the console function "screenShot":
Adding that call to glPixelStorei() prevents glReadPixels() from overwriting memory. Apparently, the default value of GL_PACK_ALIGNMENT is 4 (or at least it is for my laptop's Intel HD Graphics OpenGL driver). The added call simply sets it to 1.
Hope that helps somebody else. I'm surprised I didn't find any existing forum posts about this issue.
The fix seems to be as simple as adding a call to glPixelStorei(GL_PACK_ALIGNMENT,1) in the console function "screenShot":
ConsoleFunction(screenShot, void, 3, 3, "(string file, string format)"
"Take a screenshot.\n\n"
"@param format One of JPEG or PNG.")
{
FileStream fStream;
if(!fStream.open(argv[1], FileStream::Write))
{
Con::printf("Failed to open file '%s'.", argv[1]);
return;
}
glReadBuffer(GL_FRONT);
glPixelStorei(GL_PACK_ALIGNMENT,1); // <<---- Here's the call to fix the crash @ 1366 x 768
// ...rest of function unchanged...
}Adding that call to glPixelStorei() prevents glReadPixels() from overwriting memory. Apparently, the default value of GL_PACK_ALIGNMENT is 4 (or at least it is for my laptop's Intel HD Graphics OpenGL driver). The added call simply sets it to 1.
Hope that helps somebody else. I'm surprised I didn't find any existing forum posts about this issue.
About the author
My email address is my GG handle, at redbrickgames.com.
#2
12/09/2010 (10:46 am)
GL_PACK_ALIGNMENT defaults to 4 for all GPUs. Interestingly, GL_UNPACK_ALIGNMENT is already being set to 1 in the video code (winOGLVideo.cc, etc) but GL_PACK_ALIGNMENT is not. Might be a better fix to add the code there. However, I do not know what, if any, the performance drop would be.
#3
12/10/2010 (12:43 am)
If there's a chance that changing GL_PACK_ALIGNMENT to 1 causes a performance drop, then maybe a better fix would be to save & restore GL_PACK_ALIGNMENT in the screenShot function.
#4
12/10/2010 (1:36 pm)
Reading up on it, and considering GL_UNPACK_ALIGNMENT is already set to 1, I don't think there would be a performance hit. You may even end up using less memory, since you are not adding the extra byte padding to the malloc.
Torque Owner Geom