Sign in to follow this  
akerlund

Allocation for 3D texture

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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[i]);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this