Kocsis Dávid
Kocsis Dávid

Reputation: 549

OpenGL texture array initialization

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.

Upvotes: 1

Views: 2029

Answers (2)

pyopyopyo
pyopyopyo

Reputation: 1

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.

Upvotes: 0

derhass
derhass

Reputation: 45322

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)...

Upvotes: 4

Related Questions