1

I want to use texture arrays to reduce the high texture binding cost, but I can't upload the data to the texture array. I use Tao framework. Here's my code:

Gl.glEnable(Gl.GL_TEXTURE_2D_ARRAY_EXT);
Gl.glGenTextures(1, out textureArray);
Gl.glBindTexture(Gl.GL_TEXTURE_2D_ARRAY_EXT, textureArray);

var data = new uint[textureWidth, textureHeight, textureCount];
for (var x = 0; x < textureWidth; x++)
{
    for (var y = 0; y < textureHeight; y++)
    {
        for (var z = 0; z < textureCount; z++)
            data[x, y, z] = GetRGBAColor(1, 1, 1, 1);
    }
}

Gl.glTexImage3D(Gl.GL_TEXTURE_2D_ARRAY_EXT, 0, Gl.GL_RGBA, textureWidth, 
    textureHeight, textureCount, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, data);

Console.WriteLine(Glu.gluErrorString(Gl.glGetError()));

The glTexImage3D function says there is an invalid enumerant.

2
  • Are you sure that glTexImage3D() actually generates the error? The above code just schecks if any GL call before that generates an error. Also, have you checked that your implementation actually supports the GL_EXT_texture_array extension? Commented Jun 9, 2013 at 11:52
  • sorry for the late reply, I checked GL_EXT_texture_array, it is supported. As I see the invalid enumerant error was generated by the Gl.glEnable(Gl.GL_TEXTURE_2D_ARRAY_EXT); I thought it writes out the error of the last command. Commented Jun 10, 2013 at 16:29

2 Answers 2

4

The most likely cause for a GL_INVALID_ENUM in the above code is the

Gl.glEnable(Gl.GL_TEXTURE_2D_ARRAY_EXT);

call.

This is simply not allowed. Array textures cannot be used with the fixed-function pipeline, but only with shaders (which do not need those texture enables at all). The GL_EXT_texture_array spec makes this quite clear:

This extension does not provide for the use of array textures with fixed-function fragment processing. Such support could be added by providing an additional extension allowing pplications to pass the new target enumerants (TEXTURE_1D_ARRAY_EXT and TEXTURE_2D_ARRAY_EXT) to Enable and Disable.

There never was any further extension allowing array textures for fixed-function processing (AFAIK)...

Sign up to request clarification or add additional context in comments.

2 Comments

I use shaders, but there is only black color, when I get the color from the texture, but it seems now it's not related to the invalid enumerant error
@KocsisDávid: I think you should post another question, showing your shaders and shader/uniform setup code. There is no chance to guess what the problem might be without that information.
0

Change the 2nd parameter of glTexImage3d into 1.

I don't know why, however, nvidia's opengl driver seems to need at least 1 level for texture 2d array object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.