gravit
gravit copied to clipboard
skybox: check for maximum texture size before loading
I just had a crash on ubuntu linux with Intel graphics.
OpenGL video driver: vendor=Tungsten Graphics, Inc; renderer=Mesa DRI Intel(R) Ironlake Mobile ; version=2.1 Mesa 7.11
Seems that the intel driver does not like large textures; so we must first check the max. texture dimension before proceeding to upload it; see
http://www.opengl.org/archives/resources/faq/technical/texture.htm#text0120
Program received signal SIGSEGV, Segmentation fault. 0x00007fffab20b2b0 in ?? () from /usr/lib/x86_64-linux-gnu/dri/libdricore.so (gdb) where 0 0x00007fffab20b2b0 in ?? () from /usr/lib/x86_64-linux-gnu/dri/libdricore.so 1 0x00007fffab5a6992 in ?? () from /usr/lib/x86_64-linux-gnu/dri//i965_dri.so 2 0x00007fffab5a7503 in ?? () from /usr/lib/x86_64-linux-gnu/dri//i965_dri.so 3 0x00007fffab1f9624 in ?? () from /usr/lib/x86_64-linux-gnu/dri/libdricore.so 4 0x00007fffab1f9d4f in _mesa_TexImage2D () from /usr/lib/x86_64-linux-gnu/dri/libdricore.so 5 0x00007ffff701639d in ?? () from /usr/lib/x86_64-linux-gnu/libGLU.so.1 6 0x00007ffff701adb7 in gluBuild2DMipmaps () from /usr/lib/x86_64-linux-gnu/libGLU.so.1 7 0x0000000000416eed in loadTexture (fileName=0x625800 "/usr/local/share/gravit/data/skybox/simple.png", isSkybox=1) at src/texture.c:60 8 0x000000000040e8a6 in loadSkyBoxTexture (fileName=0x4199b0 "simple.png", textureID=0x620994) at src/gfx.c:86 9 0x000000000040ea86 in loadSkyBox () at src/gfx.c:123 10 0x000000000040ebda in gfxSetResolution () at src/gfx.c:169 11 0x000000000040edc7 in gfxInit () at src/gfx.c:231 12 0x00000000004135dc in init (argc=1, argv=0x7fffffffd978) at src/main.c:232 13 0x0000000000413acc in main (argc=1, argv=0x7fffffffd978) at src/main.c:433
must be something different; MAX_TEXTURE_SIZE returns 8192. @gak: any idea ?
frank@TigerLinux:~/WORK/gravit_develop$ glxinfo -l | grep -i texture | grep -i max GL_MAX_TEXTURE_STACK_DEPTH = 10 GL_MAX_TEXTURE_SIZE = 8192 GL_MAX_3D_TEXTURE_SIZE = 256 GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB = 2048 GL_MAX_RECTANGLE_TEXTURE_SIZE_NV = 4096 GL_MAX_TEXTURE_UNITS_ARB = 8 GL_MAX_TEXTURE_LOD_BIAS_EXT = 14 GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 16
What is the maximum for your video card? Maybe for 0.5.0 we can just reduce the size of simple.png to that?
2048x2048 is excessive anyway :)
purplenebula is 512x512, which is a reasonably sized OpenGL texture. How does that sound, assuming your video card can do that?
Ah I just realised:
if (surface->format->BytesPerPixel)
should be
if (surface->format->BytesPerPixel == 4)
I'm not sure what else it can be. The segfault is probably OpenGL trying to access memory past the allocated buffer (surface->pixels), so it seems that the BPP/colortype is wrong, or something similar.
this may be a way to avaoid the crash:
http://web.archiveorange.com/archive/v/TXjIiM3Iju3JAE31q13p
Apps should use the proxy texture mechanism to determine the actual max texture size.
from http://www.opengl.org/archives/resources/faq/technical/texture.htm#text0120
glTexImage2D(GL_PROXY_TEXTURE_2D, level, internalFormat, width, height, border, format, type, NULL);
Note the pixels parameter is NULL, because OpenGL doesn't load texel data when the target parameter is GL_PROXY_TEXTURE_2D. Instead, OpenGL merely considers whether it can accommodate a texture of the specified size and description. If the specified texture can't be accommodated, the width and height texture values will be set to zero. After making a texture proxy call, you'll want to query these values as follows:
GLint width;
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
if (width==0)
{ /* Can't use that texture */ }
We should probably put this functionality into 0.5.1 and try to fix the crashing problem for 0.5.0.
Did my latest commit 5c79ae2 help?
yes !! Now it works(tm).
good job :-))
The size check via "proxy texture" is still a good idea, but i agree it could go into 0,5.1
re-opened as feature for 0.5.1