* Render off screen surfaces even if main screen isn't visible

* AWTLoader now supports 16-bit grayscale PNG loading as Luminance16
 * AWTLoader uses try/finally on stream
 * Fix exception in MaterialLoader (was it really that hard to fix, normen?)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8185 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 13 years ago
parent 2f41dcfd48
commit 062507e23e
  1. 4
      engine/src/core/com/jme3/app/SimpleApplication.java
  2. 17
      engine/src/core/com/jme3/renderer/RenderManager.java
  3. 71
      engine/src/desktop/com/jme3/texture/plugins/AWTLoader.java
  4. 2
      engine/src/ogre/com/jme3/scene/plugins/ogre/MaterialLoader.java

@ -260,9 +260,7 @@ public abstract class SimpleApplication extends Application {
// render states // render states
stateManager.render(renderManager); stateManager.render(renderManager);
if (context.isRenderable()){ renderManager.render(tpf, context.isRenderable());
renderManager.render(tpf);
}
simpleRender(renderManager); simpleRender(renderManager);
stateManager.postRender(); stateManager.postRender();
} }

@ -1148,7 +1148,7 @@ public class RenderManager {
* *
* @param tpf Time per frame value * @param tpf Time per frame value
*/ */
public void render(float tpf) { public void render(float tpf, boolean mainFrameBufferActive) {
if (renderer instanceof NullRenderer) { if (renderer instanceof NullRenderer) {
return; return;
} }
@ -1156,13 +1156,22 @@ public class RenderManager {
this.shader = renderer.getCaps().contains(Caps.GLSL100); this.shader = renderer.getCaps().contains(Caps.GLSL100);
for (int i = 0; i < preViewPorts.size(); i++) { for (int i = 0; i < preViewPorts.size(); i++) {
renderViewPort(preViewPorts.get(i), tpf); ViewPort vp = preViewPorts.get(i);
if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){
renderViewPort(vp, tpf);
}
} }
for (int i = 0; i < viewPorts.size(); i++) { for (int i = 0; i < viewPorts.size(); i++) {
renderViewPort(viewPorts.get(i), tpf); ViewPort vp = viewPorts.get(i);
if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){
renderViewPort(vp, tpf);
}
} }
for (int i = 0; i < postViewPorts.size(); i++) { for (int i = 0; i < postViewPorts.size(); i++) {
renderViewPort(postViewPorts.get(i), tpf); ViewPort vp = postViewPorts.get(i);
if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){
renderViewPort(vp, tpf);
}
} }
} }
} }

@ -43,6 +43,7 @@ import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel; import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer; import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte; import java.awt.image.DataBufferByte;
import java.awt.image.DataBufferUShort;
import java.awt.image.DirectColorModel; import java.awt.image.DirectColorModel;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -65,12 +66,15 @@ public class AWTLoader implements AssetLoader {
Transparency.BITMASK, Transparency.BITMASK,
DataBuffer.TYPE_BYTE); DataBuffer.TYPE_BYTE);
private byte[] extractImageData(BufferedImage img){ private Object extractImageData(BufferedImage img){
DataBuffer buf = img.getRaster().getDataBuffer(); DataBuffer buf = img.getRaster().getDataBuffer();
switch (buf.getDataType()){ switch (buf.getDataType()){
case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_BYTE:
DataBufferByte byteBuf = (DataBufferByte) buf; DataBufferByte byteBuf = (DataBufferByte) buf;
return byteBuf.getData(); return byteBuf.getData();
case DataBuffer.TYPE_USHORT:
DataBufferUShort shortBuf = (DataBufferUShort) buf;
return shortBuf.getData();
} }
return null; return null;
} }
@ -87,25 +91,55 @@ public class AWTLoader implements AssetLoader {
} }
} }
private void flipImage(short[] img, int width, int height, int bpp){
int scSz = (width * bpp) / 8;
scSz /= 2; // Because shorts are 2 bytes
byte[] sln = new byte[scSz];
int y2 = 0;
for (int y1 = 0; y1 < height / 2; y1++){
y2 = height - y1 - 1;
System.arraycopy(img, y1 * scSz, sln, 0, scSz);
System.arraycopy(img, y2 * scSz, img, y1 * scSz, scSz);
System.arraycopy(sln, 0, img, y2 * scSz, scSz);
}
}
public Image load(BufferedImage img, boolean flipY){ public Image load(BufferedImage img, boolean flipY){
int width = img.getWidth(); int width = img.getWidth();
int height = img.getHeight(); int height = img.getHeight();
switch (img.getType()){ switch (img.getType()){
case BufferedImage.TYPE_4BYTE_ABGR: // most common in PNG images w/ alpha
byte[] dataBuf1 = (byte[]) extractImageData(img);
if (flipY)
flipImage(dataBuf1, width, height, 32);
ByteBuffer data1 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*4);
data1.put(dataBuf1);
return new Image(Format.ABGR8, width, height, data1);
case BufferedImage.TYPE_3BYTE_BGR: // most common in JPEG images case BufferedImage.TYPE_3BYTE_BGR: // most common in JPEG images
byte[] dataBuf = extractImageData(img); byte[] dataBuf2 = (byte[]) extractImageData(img);
if (flipY) if (flipY)
flipImage(dataBuf, width, height, 24); flipImage(dataBuf2, width, height, 24);
ByteBuffer data = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*3);
data.put(dataBuf); ByteBuffer data2 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*3);
return new Image(Format.BGR8, width, height, data); data2.put(dataBuf2);
return new Image(Format.BGR8, width, height, data2);
case BufferedImage.TYPE_BYTE_GRAY: // grayscale fonts case BufferedImage.TYPE_BYTE_GRAY: // grayscale fonts
byte[] dataBuf2 = extractImageData(img); byte[] dataBuf3 = (byte[]) extractImageData(img);
if (flipY)
flipImage(dataBuf3, width, height, 8);
ByteBuffer data3 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight());
data3.put(dataBuf3);
return new Image(Format.Luminance8, width, height, data3);
case BufferedImage.TYPE_USHORT_GRAY: // grayscale heightmap
short[] dataBuf4 = (short[]) extractImageData(img);
if (flipY) if (flipY)
flipImage(dataBuf2, width, height, 8); flipImage(dataBuf4, width, height, 16);
ByteBuffer data2 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight());
data2.put(dataBuf2); ByteBuffer data4 = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*2);
return new Image(Format.Luminance8, width, height, data2); data4.asShortBuffer().put(dataBuf4);
return new Image(Format.Luminance16, width, height, data4);
default: default:
break; break;
} }
@ -163,11 +197,18 @@ public class AWTLoader implements AssetLoader {
public Object load(AssetInfo info) throws IOException { public Object load(AssetInfo info) throws IOException {
if (ImageIO.getImageWritersBySuffix(info.getKey().getExtension()) != null){ if (ImageIO.getImageWritersBySuffix(info.getKey().getExtension()) != null){
InputStream in = info.openStream();
boolean flip = ((TextureKey) info.getKey()).isFlipY(); boolean flip = ((TextureKey) info.getKey()).isFlipY();
Image img = load(in, flip); InputStream in = null;
in.close(); try {
return img; in = info.openStream();
Image img = load(in, flip);
return img;
} finally {
if (in != null){
in.close();
}
}
} }
return null; return null;
} }

@ -458,6 +458,8 @@ public class MaterialLoader implements AssetLoader {
list.put(matName, mat); list.put(matName, mat);
} }
} }
return list;
} }
public Object load(AssetInfo info) throws IOException { public Object load(AssetInfo info) throws IOException {

Loading…
Cancel
Save