Allocation for 3D texture

Started by
6 comments, last by akerlund 16 years ago
I am rendering the screen in four parts, because there is a lot of data I need to pass to the shader. So I divide the height by four. I initialize a 3D texture with GL_ALPHA16UI_EXT, GL_ALPHA_INTEGER_EXT and GL_UNSIGNED_SHORT. I use a NULL pointer in glTexImage3D to allocate the space needed (W * H/4 * D) and there is no GL error after that. Then I create my data structure which is divided into 4 parts:

data = new unsigned short*[4];
data[0] = new unsigned short[size];
data[1] = new unsigned short[size];
data[2] = new unsigned short[size];
data[3] = new unsigned short[size];
std::fill_n(data[0], size, 0);
std::fill_n(data[1], size, 0);
std::fill_n(data[2], size, 0);
std::fill_n(data[3], size, 0);



Here, size is verified to be W * H/4 * D. And yes, H is definitely dividable with 4. After this, I can loop though each element and verify that everything is 0. I have tried using malloc, memset and loops with the same result. However, when I upload the data to the GPU, I get a memory error and the application crashes. The same error that occur when there is not enough data to be read into the texture. Is there not enough space left on the card? There should be - since I pre-allocated it without errors. Is there really not enough data allocated on the CPU side? Well if I allocate a little bit more (size = W * H/4 * (D+1)) then it runs fine! How can that happen? There are no glErrors involved anywhere. I use a nvidia G80 card, windows xp.
Advertisement
This may seem stupid but is data a unsigned short**? or unsigned short*? Also is GL_ALPHA16UI_EXT even a supported format for 3D textures?
Yes, data is unsigned short **. I don't know if GL_ALPHA16UI_EXT is supported for 3D textures. But there is no problem if I just allocate some more space on the CPU-side... which is wrong, of course.
how do you upload the data?
W = selectedLeafs.sizePerPixel
H = dimWin.x
D = dimWin.y / 4

glTexImage3D(GL_TEXTURE_3D, 0, GL_ALPHA16UI_EXT, selectedLeafs.sizePerPixel, dimWin.x, dimWin.y / 4, 0, GL_ALPHA_INTEGER_EXT, GL_UNSIGNED_SHORT, selectedLeafs.data);
The problem is solved - my texture width was 563. It does not have to be power of two, but it DOES have to be an even number! So 564 and 562 works.
Are you sure it wasn`t a data alignement problem?
By default, glPixelStorei(GL_UNPACK_ALIGMNENT, 4)
but you can change to 1
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Ah, thank you. That is a better solution!! I set it to 2 and it worked.

This topic is closed to new replies.

Advertisement