glTexSubImage3D produces GL_INVALID_VALUE

Hello. I render a cube, and load its textures from png files. When I load the first png texture, it is rendered good, but for the rest of them I get a GL_INVALID_VALUE error in glTexSubImage3D line.


        //Now generate the OpenGL texture object
	GLuint texture;
	GLsizei mipLevelCount = 8;

	glGenTextures(1, &texture);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D_ARRAY, texture);

	int width, height;
        for (int j = 0; j < texture_names.size(); ++j)
       {
             // here a png[j] is read to * array.
            ....
            // update width and height, always 256x256
            ....

            if (j == 0)
	    {
	         glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, texture_names.size());
	    }
	    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, j, 0, 0, 0, width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)image_data);
            
            //  release resources
            ...
       }

.....

[QUOTE=wenhaug;1291399]Hello. I render a cube, and load its textures from png files. When I load the first png texture, it is rendered good, but for the rest of them I get a GL_INVALID_VALUE error in glTexSubImage3D line.


        for (int j = 0; j < texture_names.size(); ++j)
...
	    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, j, 0, 0, 0, width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)image_data);

[/QUOTE]
The second parameter to glTexSubImage3D() is the mipmap level. You probably want to be uploading to array layer j, not mipmap level j, i.e.:


glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, j, width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)image_data);

Thank you.