[Solved] Loading custom mipmaps fails

Hi,

I want to load my manually created mimaps for a texture, not those generated by OpenGL.
My code:

Texture texture = TextureIO.newTexture(myInputStream, false, "png");
for (int i = 1; true; i++)
{
   TextureData mipmap = TextureIO.newTextureData(myMipMapStream[i], false, "png");
   texture.updateSubImage(mipmap, i, 0, 0);
   if (mipmap.getWidth() <= 1) break;
}

There is no error, but the texture is only displayed black ( - at least without alpha, as it should have).

The input streams are ok, loading each texture works.

Also automatic generating works:

Texture texture = TextureIO.newTexture(myInputStream, true, "png");

Any idea?
Thanks :slight_smile:

push
Any idea?

If this is calling TexSubImage2D, try replacing it with TexImage2D.

Thanks!! This was the solution.

I think this is a bug in JOGL.

Detailed explanation:

I want to create a texture with manually loaded mipmaps. So I create a texture with auto-mipmap off. Now I want to add the mipmaps. This fails, because glTexSubImage2D is only allowed, if the corresponding image already exists. But it doesn’t, because I disabled auto-mipmap and so there is only level 0 available!

OK, you could say, that I may not call updateSubImage when there are no mipmap images. But I have no choice: There is neither a method to set mipmap images (updateImage has no parameter for the mipmap level), nor can I first enable auto-mipmap and then overwrite the mipmaps (JOGL doesn’t allow to change the mipmap images in this case).

Suggestion: Add a parameter for the mipmap level to Texture.updateImage and the problem is solved.

Can you fix that, please?

In short no, http://opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texsubimage2d.html

I refer you to the 2nd error condition…

[quote]GL_INVALID_OPERATION is generated if the texture array has
not been defined by a previous glTexImage2D operation.
[/quote]
I could go into the uglinesses of OpenGL’s textures and mipmap pyramids and the bizarre things you can legally do with them that no sane person would ever have reason to do in a real app. But the short and sweet of it is a glTexImage call defines the allocation’s size for each mip level, otherwise glTexSubImage is attempting to operate on undefined data over an undefined range.

This is exactly what I meant when I said:

[quote]OK, you could say, that I may not call updateSubImage when there are no mipmap images. But I have no choice: There is neither a method to set mipmap images (updateImage has no parameter for the mipmap level), nor can I first enable auto-mipmap and then overwrite the mipmaps (JOGL doesn’t allow to change the mipmap images in this case).
[/quote]
The “bug” is, that JOGL does not allow me to define custom mipmaps (if so, please tell me, how), although this would be trivial to do by adding a mipmap level parameter to the setTexImage2D method.

I think I see what you mean, there’s no level argument to Texture.updateImage(), sorry about that. I’ve not looked at that code but I would imaging that call in particular is probably a fairly simple wrapper around glTexImage. The fastest way to get the changes into the project would be to make them yourself and submit them. Hopefully Ken Russell can chime in a bit here on how to do that.

The way to do this with the current code would be to first load your mipmaps into an array of TextureData objects, and then allocate one TextureData with an array of Buffers, where the Buffers come from the original TextureDatas. Then create the Texture from the TextureData containing the mipmaps.

Does that solution work for you?

Agreed that there is functionality missing from the current code, but the JOGL 1.1.x branch is not being actively maintained right now, and the JOGL 2 branch (JOGL_2_SANDBOX branch in the source tree) is not ready for broad consumption yet. If you would like to submit a patch against the JOGL_2_SANDBOX branch that would be very welcome.

JOGL_2 ? this sounds interesting! :slight_smile:
i quickly looked into the CVS but could not find any branch like this. is it publicly available yet?

what is new in JOGL 2?

thanks!

The branch name is JOGL_2_SANDBOX. The branch exists on the gluegen, jogl and jogl-demos workspaces. cvs co -r JOGL_2_SANDBOX gluegen jogl jogl-demos

The major features of JOGL 2 are elimination of AWT dependencies from the core JOGL API (although the GLCanvas and GLJPanel still exist in a sub-package) and support for multiple OpenGL profiles, like GL2 for the desktop, GLES1 for OpenGL ES 1.x and GLES2 for OpenGL ES 2.0, as well as common subsets. With the common subsets you can develop on the desktop and deploy onto mobile devices.

The work is still in early stages and some stuff is broken. We’ll post more once it’s in better shape for public consumption and broader feedback.

Thanks for this idea, works perfectly! I will submit a patch for JOGL2 as soon as it is available and I use it.

Here is the working code now:


//load all mipmaps levels
LinkedList<TextureData> mipmapLevels = new LinkedList<TextureData>();
for (int i = 0; true; i++)
{
	TextureData mipmapLevel = TextureIO.newTextureData(openDataFile(i), false, "png");
	mipmapLevels.add(mipmapLevel);
	if (mipmapLevel.getWidth() <= 1)
		break;
}
//collect buffers
Buffer[] buffers = new Buffer[mipmapLevels.size()];
int level = 0;
for (TextureData mipmapLevel : mipmapLevels)
{
	buffers[level] = mipmapLevel.getBuffer();
	level++;
}
//create the texture
TextureData top = mipmapLevels.getFirst();
TextureData textureData = new TextureData(top.getInternalFormat(), top.getWidth(), top.getHeight(),
	0, top.getPixelFormat(), top.getPixelType(), false, false, buffers, null);
Texture texture = TextureIO.newTexture(textureData);