GLRenderer.modifyTexture on GLES fix (#1235)

* Update GLImageFormats.java

* First implementation to solve the glTexSubImage issue

* Setting proper format to the image

* Removed the Image.convertToFormat method and its usage from GLRenderer.modifyTexture. Added a warning instead for the potential failing cases
Fixing the issue in JmeBatchRenderBackend.loadImage transforming it to RGBA8 if required
fix-openal-soft-deadlink
joliver82 5 years ago committed by Stephen Gold
parent b2ae269ede
commit 68fb1afe5d
  1. 6
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
  2. 28
      jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java

@ -2549,6 +2549,9 @@ public final class GLRenderer implements Renderer {
@Deprecated @Deprecated
public void modifyTexture(Texture tex, Image pixels, int x, int y) { public void modifyTexture(Texture tex, Image pixels, int x, int y) {
setTexture(0, tex); setTexture(0, tex);
if(caps.contains(Caps.OpenGLES20) && pixels.getFormat()!=tex.getImage().getFormat() ) {
logger.log(Level.WARNING, "Incompatible texture subimage");
}
int target = convertTextureType(tex.getType(), pixels.getMultiSamples(), -1); int target = convertTextureType(tex.getType(), pixels.getMultiSamples(), -1);
texUtil.uploadSubTexture(target,pixels, 0, x, y,0,0,pixels.getWidth(),pixels.getHeight(), linearizeSrgbImages); texUtil.uploadSubTexture(target,pixels, 0, x, y,0,0,pixels.getWidth(),pixels.getHeight(), linearizeSrgbImages);
} }
@ -2566,6 +2569,9 @@ public final class GLRenderer implements Renderer {
*/ */
public void modifyTexture(Texture2D dest, Image src, int destX, int destY, int srcX, int srcY, int areaW, int areaH) { public void modifyTexture(Texture2D dest, Image src, int destX, int destY, int srcX, int srcY, int areaW, int areaH) {
setTexture(0, dest); setTexture(0, dest);
if(caps.contains(Caps.OpenGLES20) && src.getFormat()!=dest.getImage().getFormat() ) {
logger.log(Level.WARNING, "Incompatible texture subimage");
}
int target = convertTextureType(dest.getType(), src.getMultiSamples(), -1); int target = convertTextureType(dest.getType(), src.getMultiSamples(), -1);
texUtil.uploadSubTexture(target, src, 0, destX, destY, srcX, srcY, areaW, areaH, linearizeSrgbImages); texUtil.uploadSubTexture(target, src, 0, destX, destY, srcX, srcY, areaW, areaH, linearizeSrgbImages);
} }

@ -43,7 +43,9 @@ import java.util.logging.Logger;
import com.jme3.asset.TextureKey; import com.jme3.asset.TextureKey;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.material.RenderState; import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
import com.jme3.renderer.Caps;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
@ -52,6 +54,7 @@ import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.VertexBuffer.Usage; import com.jme3.scene.VertexBuffer.Usage;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
import com.jme3.texture.image.ImageRaster;
import com.jme3.texture.Texture.MagFilter; import com.jme3.texture.Texture.MagFilter;
import com.jme3.texture.Texture.MinFilter; import com.jme3.texture.Texture.MinFilter;
import com.jme3.texture.Texture2D; import com.jme3.texture.Texture2D;
@ -214,6 +217,31 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
key.setGenerateMips(false); key.setGenerateMips(false);
Texture2D texture = (Texture2D) display.getAssetManager().loadTexture(key); Texture2D texture = (Texture2D) display.getAssetManager().loadTexture(key);
// Fix GLES format incompatibility issue with glTexSubImage
Renderer renderer = display.getRenderer();
if(renderer==null || renderer.getCaps().contains(Caps.OpenGLES20)) {
if(texture.getImage().getFormat()!=Format.RGBA8) {
com.jme3.texture.Image sourceImage = texture.getImage();
int size = sourceImage.getWidth() * sourceImage.getHeight() * 4;
ByteBuffer buffer = BufferUtils.createByteBuffer(size);
com.jme3.texture.Image rgba8Image = new com.jme3.texture.Image(Format.RGBA8,
sourceImage.getWidth(),
sourceImage.getHeight(),
buffer,
sourceImage.getColorSpace());
ImageRaster input = ImageRaster.create(sourceImage, 0, 0, false);
ImageRaster output = ImageRaster.create(rgba8Image, 0, 0, false);
ColorRGBA color = new ColorRGBA();
for (int y = 0; y < sourceImage.getHeight(); y++) {
for (int x = 0; x < sourceImage.getWidth(); x++) {
output.setPixel(x, y, input.getPixel(x, y, color));
}
}
return new ImageImpl(rgba8Image);
}
}
return new ImageImpl(texture.getImage()); return new ImageImpl(texture.getImage());
} }

Loading…
Cancel
Save