Seems to be a problem with this method in TextureFactory.java in jagatoo library.
In the case where pixelSize == 1, there are other format choices that it could be.
I've got an image that has the format TextureImageFormat.LUMINANCE, but this method gets called when creating mip maps, and the wrong texture format (TextureImageFormat.DEPTH) is chosen.
/**
* Creates an instance of {@link AbstractTextureImage} with an initialized
* {@link ByteBuffer}, which is returned by the {@link AbstractTextureImage#getDataBuffer()} method.
*
* @param width
* @param height
* @param orgWidth
* @param orgHeight
* @param pixelSize
*
* @return the new AbstractTextureImage.
*/
public final AbstractTextureImage createTextureImage( int width, int height, int orgWidth, int orgHeight, int pixelSize )
{
if ( pixelSize >= 8 )
pixelSize /= 8;
final TextureImageFormat format;
switch ( pixelSize )
{
case 1:
format = TextureImageFormat.DEPTH;
break;
case 2:
format = TextureImageFormat.LUMINANCE_ALPHA;
break;
case 3:
format = TextureImageFormat.RGB;
break;
case 4:
format = TextureImageFormat.RGBA;
break;
default:
throw new Error( "Unsupported pixel-size: " + pixelSize );
}
return ( createTextureImage( width, height, orgWidth, orgHeight, pixelSize, format ) );
}
One thing I did to fix this was to change this line in PixelProcessor.java:
AbstractTextureImage trgImg = texFactory.createTextureImage( trgWidth, trgHeight, trgWidth, trgHeight, pixelSize );
to:
AbstractTextureImage trgImg = texFactory.createTextureImage( trgWidth, trgHeight, trgWidth, trgHeight, pixelSize, srcImg.getFormat() );
to avoid TextureImageFormat.DEPTH from being chosen, and instead passing the same format as the source image (TextureImageFormat.LUMINANCE). However, there is still a general problem, I assume, when other places call this method.
I also had to fix the PixelProcessorLUM.java to handle the grayscale texture properly consistent with the PixelProcessorRGB):
Index: src/org/jagatoo/loaders/textures/pixelprocessing/PixelProcessorLUM.java
===================================================================
--- src/org/jagatoo/loaders/textures/pixelprocessing/PixelProcessorLUM.java (revision 378)
+++ src/org/jagatoo/loaders/textures/pixelprocessing/PixelProcessorLUM.java (working copy)
@@ -64,6 +64,9 @@
Raster r = img.getRaster();
final int trgOffset0 = trgOffset;
+
+ final int trgLineSize = getLineSize( width );
+
trg.position( trgOffset0 );
trg.limit( trg.capacity() );
@@ -81,7 +84,7 @@
trg.position( trgOffset );
trg.put( data, 0, width );
- trgOffset += width;
+ trgOffset += trgLineSize;
}
break;
}
@@ -105,7 +108,7 @@
trg.put( trgOffsetX++, value );
}
- trgOffset += width;
+ trgOffset += trgLineSize;
}
break;
}
@@ -133,12 +136,12 @@
trg.put( trgOffsetX++, value );
}
- trgOffset += width;
+ trgOffset += trgLineSize;
}
}
}
- int dataSize = height * 1;
+ int dataSize = height * trgLineSize;
trg.position( 0 );
trg.limit( trgOffset0 + dataSize );