Fix jme constanly trying to upload image data every frame with mips

There is a little bug that causes caues jME to reupload image data on opengl every frame if we are using mipmaps slightly wrong.

Here is example of code that creates a bug:
[java]
// Load some texture
Texture tex = someAssetManager.loadTexture(“sometexture.png”);
// Ensure that mip mapping is disabled
tex.setMinFilter(MinFilter.NearestNoMipMaps);
// Generate mipmaps
MipMapGenerator.generateMipMaps(tex.getImage()); // You can find MipMapGenerator on jme3-desktop at jme3tools/converters
// MipMap generator will call images method Image.setMipMapSizes()
// Then we are enabling using of mipmaps
tex.setMinFilter(MinFilter.NearestNearestMipMap);
// Last call sets Image.needGeneratedMips to true, but Image.mipsWereGenerated is still false cause we are uploading mips, not generating them by OpenGL
[/java]
Next, in lwjgl renderer at com.jme3.renderer.LwjglRenderer.setTexture:1946
[java]
public void setTexture(int unit, Texture tex) {
Image image = tex.getImage();
if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) {
updateTexImageData(image, tex.getType(), unit);
}
[/java]
image.isGeneratedMipmapsRequired() is true. But we already have mipmaps in image, it causes that updateTexImageData() is using them, not using generated mipmaps therefore not setting mipsWereGenerated to true. So every time we are using texture, updateTexImageData() is called, reuploading image data to opengl every time. It causes enormous fps lowering.

Fix is not setting Image.needGeneratedMips to true when we already have mipmaps in image.

2 Likes

I’ve merged this PR thanks