basisunus

3D texture stride problem

Discussion created by basisunus on Dec 7, 2010
Latest reply on Oct 19, 2013 by basisunus

I'm creating a 3D texture from memory data. Since the data might be very large, I divide the memory block into bricks. The code for creating the texture is like this:

 glGenTextures(1, &m_tex);

 glEnable(GL_TEXTURE_3D);

 glBindTexture(GL_TEXTURE_3D, m_tex);

 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

 glPixelStorei(GL_UNPACK_ROW_LENGTH, m_nx);
 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, m_ny);
 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

 glTexImage3D(GL_TEXTURE_3D, 0, GL_ALPHA, 256, 256, m_nz, 0, GL_ALPHA, GL_UNSIGNED_BYTE, (unsigned char*)data->GetData());

In the example, the data block in memory has size m_nx*m_ny*m_nz, and I want to read only a portion of the data, which has size 256*256*m_nz, where 256 is smaller than the actual m_nx and m_ny.

On my Radeon HD4870, this doesn't work. Furthermore, no matter what number I put for the GL_UNPACK_IMAGE_HEIGHT parameter, the result stays incorrectly the same. This is apparently a stride problem. I'm wondering if anyone had the same problem and could help.

Outcomes