glCompressedTexImage2D

I was wondering if someone could help me with the use of compressed textures using JNI.

I try to use a *.pkm file without header, I got from converting a 2048x2048 png using the etc1tool from the adt.

Loading works fine, creating the texture fails though.

GLuint uiSize = 8 * ((width + 3) >> 2) * ((height + 3) >> 2);

	glCompressedTexImage2D(
			GL_TEXTURE_2D,
			0,
			GL_ETC1_RGB8_OES,
			img.width,
			img.height,
			0,
			uiSize,
			img.pixels);

Doing so causes error 0x501.

Handing 0 data works in the way, that I have a texture of arbitrary (undefined) stuff, resulting in funny colors and stripes on my model, as would be expected.

Help and hints are highly appreciated.

Christoph

notice that width and height here:

GLuint uiSize = 8 * ((width + 3) >> 2) * ((height + 3) >> 2);

Aren’t necessarily the same as img.width and img.height here:

glCompressedTexImage2D(
GL_TEXTURE_2D,
0,
GL_ETC1_RGB8_OES,
img.width,
img.height,

Assuming that they really are the same… Then 0x501 is GL_INVALID_VALUE.

Docs for glCompressedTexImage2D say:

GL_INVALID_VALUE may be generated if internalformat is not
one of the paletted formats and level is greater than 0 or the
absolute value of level is greater than log2 max, where
max is the returned value of GL_MAX_TEXTURE_SIZE.

Not this case.

GL_INVALID_VALUE may be generated if internalformat is
not one of the paletted formats and level is less than
0 or greater than log2 max, where max is the returned
value of GL_MAX_TEXTURE_SIZE.

Not this case.

GL_INVALID_VALUE is generated if width or height is less
than 0 or greater than GL_MAX_TEXTURE_SIZE, or if either
cannot be represented as 2^k for some integer k.

Possibly; try querying GL_MAX_TEXTURE_SIZE and confirm 2k x 2k is ok on his platform.

GL_INVALID_VALUE is generated if border is not 0.

Not this case.

GL_INVALID_VALUE is generated if imageSize is not consistent
with format, dimensions, and contents of the compressed image.

Most likely; not skipping some header data correctly, or code to calculate the image size is bugged.