I'm having a problem building a 2D mipmap on JOGL 1.1b10 on OSX 10.3.9 (Powerbook G4 ATI Radeon 9700 card). No matter what image I send to the function, it keeps giving me a GL_INVALID_VALUE exception inside of an internal call to glTexImage2D. Here's the code:

where, texture.target is GL_TEXTURE_2D, dstPixelFormat is GL_RGBA, srcPixelFormat is GL_RGBA, width and height are 256 and byteBuffer points to image data loaded from a PNG file (which looks ok with Preview).

The error I get is this:

Initializing new texture 22 - /Users/abegel/Developer/eandl/starlogo-tng/build/models/hulk/blue.pngbuilding mipmap for image width: 256 height: 256net.java.games.jogl.GLException: glGetError() returned the following error codes after a call to glTexImage2D(): GL_INVALID_VALUE at net.java.games.jogl.DebugGL.checkGLGetError(DebugGL.java:13901) at net.java.games.jogl.DebugGL.glTexImage2D(DebugGL.java:10554) at net.java.games.jogl.impl.mipmap.Mipmap.closestFit(Mipmap.java:259) at net.java.games.jogl.impl.mipmap.Mipmap.gluBuild2DMipmaps(Mipmap.java:676) at net.java.games.jogl.impl.GLUImpl.gluBuild2DMipmapsJava(GLUImpl.java:587) at net.java.games.jogl.impl.GLUImpl.gluBuild2DMipmaps(GLUImpl.java:823) at torusworld.TextureManager.initTexture(TextureManager.java:186) at torusworld.TextureManager.initNewTextures(TextureManager.java:137) at torusworld.TorusWorld.drawTurtle(TorusWorld.java:2076) at torusworld.TorusWorld.renderMobileObject(TorusWorld.java:2024) at torusworld.TorusWorld.renderMobileObjects(TorusWorld.java:1957) at torusworld.TorusWorld.drawIt(TorusWorld.java:1874) at torusworld.TorusWorld.display(TorusWorld.java:1249) at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74) at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:241) at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:292) at net.java.games.jogl.impl.macosx.MacOSXOnscreenGLContext.invokeGL(MacOSXOnscreenGLContext.java:84)

Using Apple's OpenGL Profiler, I found the arguments for the offending glTexImage2D() call at the end of this sequence (the calls above it are definitely my own that happen before the gluBuild2DMipmap code):

Does it work if you specify the system property -Djogl.glu.nojava on the command line? That would indicate a bug in the Java port of the mipmap routines and in that case I'd appreciate it if you could file a bug with the Issue Tracker on the JOGL home page and attach your example texture and a small test program.

Does the behavior change if you run with -Xint?

Is that output from exactly the source image you're specifying? It looks like it's at level 1 but the image size is 64x64; if you have a 256x256 base image then mipmap level 1 should be 128x128. Maybe that's the problem. The log and image size computation routines are really simple, so it's surprising if they're producing incorrect results.

I noticed the Apple OpenGL profiler seems to be reporting strange arguments like GL_PROXY_TEXTURE_2D instead of GL_TEXTURE_2D; I assume this is due to how the profiler works. Does JOGL's TraceGL report similar arguments?

Please do file the bug. However it looks like this is the intended behavior of the GLU code, both the original C and the Java port. If proxy textures aren't supported by the hardware (and it looks like they aren't on ATI cards) then the code is supposed to go to a fallback path which doesn't attempt to figure out whether the subsampled texture will fit in texture memory. If you take out the DebugGL does your program work with the Java port of the GLU routines? We might need to add an API to disable the DebugGL's error checking around calls like this, or try to rewrite this part of the GLU routines to not generate GL errors.

I just tried my code with JOGL 1.1b12 and there's been progress! With the java version of the glu library, some of my mipmaps are built correctly!

The ones that fail are mipmaps made from 1x1 textures. There's a bug in the algorithm in BuildMipmap.java:gluBuild2DMipmapLevelsCore() when width, height, widthPowerOf2 and heightPowerOf2 are equal to 1. We enter the if statement (if (width == newwidth && height == newheight)) and get down to the switch(type) statement where I'm passing in GL.GL_UNSIGNED_BYTE, so we call HalveImage.halveImage_ubyte() with width and height = 1. But halveImage_ubyte() has an assertion that width and height can't both be 1 so we fail.

There's obviously a bug in the control flow here. Here's a stack trace of the error:

Caused by: java.lang.AssertionError at net.java.games.jogl.impl.mipmap.HalveImage.halveImage_ubyte(HalveImage.java:95) at net.java.games.jogl.impl.mipmap.BuildMipmap.gluBuild2DMipmapLevelsCore(BuildMipmap.java:365) at net.java.games.jogl.impl.mipmap.Mipmap.gluBuild2DMipmaps(Mipmap.java:719) at net.java.games.jogl.impl.GLUImpl.gluBuild2DMipmapsJava(GLUImpl.java:587) at net.java.games.jogl.impl.GLUImpl.gluBuild2DMipmaps(GLUImpl.java:823) at torusworld.TextureManager.initTexture(TextureManager.java:196) at torusworld.TextureManager.initNewTextures(TextureManager.java:146) at torusworld.TorusWorld.drawTurtle(TorusWorld.java:2111) at torusworld.TorusWorld.renderMobileObject(TorusWorld.java:2059) at torusworld.TorusWorld.renderMobileObjects(TorusWorld.java:1990) at torusworld.TorusWorld.drawIt(TorusWorld.java:1907) at torusworld.TorusWorld.display(TorusWorld.java:1275) at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74) at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:249) at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:292) at net.java.games.jogl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:266)

I'm pretty sure I found the bug (a missing return statement in BuildMipmap.gluBuild2DMipmapLevelsCore() and just checked in a fix - untested, however. If you have the time to write up a small test case that would be helpful. Regardless, the fix will be in the next JOGL release.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org