[FIXED] problem with glTexStorage3D

I found a strange behavior of glTexStorage3D

I use glTexStrage3D to create a texture 2d array object.
Up to 255 layers, glTexStorage3D works fine.
But with 256+ layers, the number of allocated layers seems to be masked with 0xff.
For example, with 256 layers, glGetTextureParamter(GL_TEXTURE_VIEW_NUM_LAYERS) says
the number of layers is zero.
Because of this behavior, I’m troubled with creating texture view for texture_2d_array.

I wrote a testcase and tested with GTX 650 Ti with 325.15 driver on linux-3.10.

Would you please check the attached testcase?
Is this correct behavior?

---------------------------
#include <stdio.h>

#include<GL/glew.h>

#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>

#define CHECK_GL() do { GLenum e; while ( (e = glGetError()) != GL_NO_ERROR ) { fprintf(stderr, __FILE__ ":%d glGetError() returns '%d'\n", __LINE__, e ); } } while(0)

void test_texturestorage()
{
     for (int num_layers = 250; num_layers<=260; ++num_layers) {

	  // Creates GL_TEXTURE_2D_ARRAY with num_layers
	  GLuint texture;
	  glGenTextures(1, &texture);
	  glBindTexture( GL_TEXTURE_2D_ARRAY, texture );
	  glTexStorage3D( GL_TEXTURE_2D_ARRAY, 
			  1,
			  GL_RGB8,
			  64, 64, num_layers);
	  CHECK_GL();

	  // Retrieves number of layers
	  GLint value;
	  glGetTexParameterIiv(GL_TEXTURE_2D_ARRAY,
			       GL_TEXTURE_VIEW_NUM_LAYERS,
			       &value);
	  printf("GL_TEXTURE_VIEW_NUM_LAYERS: %d  num_layers: %d\n", 
		 value, num_layers);

	  glBindTexture( GL_TEXTURE_2D_ARRAY,0);
	  glDeleteTextures(1, &texture);
     }
}

void test_textureview(int num_layers)
{
     // Creates texture 2d array
     GLuint originaltexture;
     glGenTextures(1, &originaltexture);
     glBindTexture( GL_TEXTURE_2D_ARRAY, originaltexture );
     glTexStorage3D( GL_TEXTURE_2D_ARRAY, 
		     1,
		     GL_RGB8,
		     64, 64, num_layers);
     CHECK_GL();

     // Creates an texture view for the last slice of originaltexture
     GLuint textureview;
     glGenTextures(1, &textureview);
     glTextureView(textureview, GL_TEXTURE_2D,
		   originaltexture,
		   GL_RGB8,
		   0,1,
		   (num_layers-1),1);
     CHECK_GL();

     glDeleteTextures(1, &originaltexture);
     glDeleteTextures(1, &textureview);
}

int
main(int argc, char *argv[])
{
     // Initialize GLUT stuff
     glutInit(&argc, argv);
     glutInitDisplayMode( GLUT_RGBA );
     glutInitWindowSize( 100,100 );
     glutCreateWindow( argv[ 0 ] );

     // Initialize glew stuff
     glewInit();

     glActiveTexture(GL_TEXTURE1);

     test_texturestorage();

     // This works fine.
     test_textureview(255);

     // This doesn't work in my environment.
     test_textureview(256);

     return 0;
}

testcase.cpp (2.03 KB)

This bug had been fixed already.
I don’t check when it was fixed. However, at least version 334.16 works fine for me.

Thank you