Out of memory with glTexImage3D

Hi everyone,
I have the following code which calls glTexImage3D with different texture size until 1285 error.

GLint maxSize = 0;
glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &maxSize);
GLuint texId;
glGenTextures(1, &texId);
glBindTexture(GL_TEXTURE_3D, texId);

printf("******************* glTexImage3D test *******************
printf("GL_MAX_3D_TEXTURE_SIZE: %d
", maxSize);
GLint xDim = maxSize;
GLint yDim = maxSize;
GLint zDim = maxSize;
int memory;
GLenum error = 1;
memory = int(((double)xDim * (double)yDim * (double)zDim * 1.)/(1024*1024));
printf("Trying %d %d %d, Memory: %dM
", xDim, yDim, zDim, memory);
glTexImage3D(GL_TEXTURE_3D, 0, GL_ALPHA, xDim, yDim, zDim, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
error = glGetError();
if (error)
printf("error %d
", error);
zDim -= 1;

Results on winXP64 4Go and geForce GTX 580(1.5Go)
32bit exe:

Trying 2048 2048 1261, Memory: 5044M => error 1285
Trying 2048 2048 1260, Memory: 5040M => no error

64bit exe:

Trying 2048 2048 1518, Memory: 6072M => error 1285
Trying 2048 2048 1517, Memory: 6068M => no error

Results on winSeven64 12Go and Quadro FX 4000 (2Go)
32bit exe:

Trying 2048 2048 1420, Memory: 5680M => error 1285
Trying 2048 2048 1419, Memory: 5676M => no error

64bit exe:
Trying 2048 2048 2048, Memory: 8192M => no error

I don’t understand the results. Can someone explain the results to me please ?

A 1024x1024x1024 3d texture would require 4gig of ram. Something tells me even if a card claims it supports this, it won’t work.

Are you sure ? I’m thinking a 1024x1024x1024 3d texture (GL_ALPHA) requires 1gig.

It might also be looking for contiguous space. If you’re asking for 1Gb, there might be 1Gb of free space, but with a 20kb VBO smack bang in the middle.

I was thinking RGBA, but still 1gig is a pretty hilarious amount of memory to be asking for. Windows etc is going to eat up some of the graphics memory.

You might be puzzled by the results due to misunderstanding the meaning of the advertised maximum texture size.

If I understand correctly, the maximum texture size represents the largest allowed dimension, and is related to the texture sampling hardware capabilities, and doesn’t really relate to the amount of graphics memory available to the GL. I.e., just because it GL_MAX_3D_TEXTURE_SIZE reports 4096 (or more!), doesn’t mean you can create an 4096^3 texture.

There used to be a proxy texture target you could use to ask “If I tried to create this texture, would I succeed?” I don’t know if this has been deprecated in recent OpenGL releases.

Your results don’t seem that strange to me. 32-bit mode runs out of memory before 64-bit mode, and XP before Windows 7.

just because it GL_MAX_3D_TEXTURE_SIZE reports 4096 (or more!), doesn’t mean you can create an 4096^3 texture.

You 're right, that’s why I don’t understand why glTexImage3D doesn’t return an “out of memory” for a 2048x2048x1517 (6go) texture.

Maybe you have the same problem as
According to this link, the maximum allocation is limited by the OS not the hardware. Does somebody can confirm this?

What does it do?
Anyway, it would be a driver issue if it just crashes instead of returning an error message.

Also, I don’t know if it has been stated but if the max size is reported as 4096 pixels, then you can probably make a 4096 x 1 pixel x 1 pixel x GL_ALPHA8 3D texture (4 KB). Perhaps you can even make 4096 x 8 x 8 X GL_ALPHA8 pixel 3D texture (262 KB).