|
|
@ -57,27 +57,28 @@ import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.nio.FloatBuffer; |
|
|
|
import java.nio.FloatBuffer; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
public class RenderDeviceJme implements RenderDevice { |
|
|
|
public class RenderDeviceJme implements RenderDevice { |
|
|
|
|
|
|
|
|
|
|
|
private NiftyJmeDisplay display; |
|
|
|
private final NiftyJmeDisplay display; |
|
|
|
private RenderManager rm; |
|
|
|
private RenderManager rm; |
|
|
|
private Renderer r; |
|
|
|
private Renderer r; |
|
|
|
private HashMap<CachedTextKey, BitmapText> textCacheLastFrame = new HashMap<CachedTextKey, BitmapText>(); |
|
|
|
private Map<CachedTextKey, BitmapText> textCacheLastFrame = new HashMap<>(); |
|
|
|
private HashMap<CachedTextKey, BitmapText> textCacheCurrentFrame = new HashMap<CachedTextKey, BitmapText>(); |
|
|
|
private Map<CachedTextKey, BitmapText> textCacheCurrentFrame = new HashMap<>(); |
|
|
|
private final Quad quad = new Quad(1, -1, true); |
|
|
|
private final Quad quad = new Quad(1, -1, true); |
|
|
|
private final Geometry quadGeom = new Geometry("nifty-quad", quad); |
|
|
|
private final Geometry quadGeom = new Geometry("nifty-quad", quad); |
|
|
|
private boolean clipWasSet = false; |
|
|
|
private boolean clipWasSet = false; |
|
|
|
private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord); |
|
|
|
private final VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord); |
|
|
|
private VertexBuffer quadModTC = quadDefaultTC.clone(); |
|
|
|
private final VertexBuffer quadModTC = quadDefaultTC.clone(); |
|
|
|
private VertexBuffer quadColor; |
|
|
|
private final VertexBuffer quadColor; |
|
|
|
private Matrix4f tempMat = new Matrix4f(); |
|
|
|
private final Matrix4f tempMat = new Matrix4f(); |
|
|
|
private ColorRGBA tempColor = new ColorRGBA(); |
|
|
|
private final ColorRGBA tempColor = new ColorRGBA(); |
|
|
|
private RenderState renderState = new RenderState(); |
|
|
|
private final RenderState renderState = new RenderState(); |
|
|
|
|
|
|
|
|
|
|
|
private Material colorMaterial; |
|
|
|
private final Material colorMaterial; |
|
|
|
private Material textureColorMaterial; |
|
|
|
private final Material textureColorMaterial; |
|
|
|
private Material vertexColorMaterial; |
|
|
|
private final Material vertexColorMaterial; |
|
|
|
|
|
|
|
|
|
|
|
private static class CachedTextKey { |
|
|
|
private static class CachedTextKey { |
|
|
|
|
|
|
|
|
|
|
@ -138,6 +139,7 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
renderState.setDepthWrite(false); |
|
|
|
renderState.setDepthWrite(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) { |
|
|
|
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -147,8 +149,11 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Cursor support
|
|
|
|
// TODO: Cursor support
|
|
|
|
|
|
|
|
@Override |
|
|
|
public MouseCursor createMouseCursor(String str, int x, int y) { |
|
|
|
public MouseCursor createMouseCursor(String str, int x, int y) { |
|
|
|
return new MouseCursor() { |
|
|
|
return new MouseCursor() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void dispose() { |
|
|
|
public void dispose() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -162,43 +167,53 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void enableMouseCursor(MouseCursor cursor) { |
|
|
|
public void enableMouseCursor(MouseCursor cursor) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void disableMouseCursor() { |
|
|
|
public void disableMouseCursor() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public RenderImage createImage(String filename, boolean linear) { |
|
|
|
public RenderImage createImage(String filename, boolean linear) { |
|
|
|
//System.out.println("createImage(" + filename + ", " + linear + ")");
|
|
|
|
//System.out.println("createImage(" + filename + ", " + linear + ")");
|
|
|
|
return new RenderImageJme(filename, linear, display); |
|
|
|
return new RenderImageJme(filename, linear, display); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public RenderFont createFont(String filename) { |
|
|
|
public RenderFont createFont(String filename) { |
|
|
|
return new RenderFontJme(filename, display); |
|
|
|
return new RenderFontJme(filename, display); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void beginFrame() { |
|
|
|
public void beginFrame() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void endFrame() { |
|
|
|
public void endFrame() { |
|
|
|
HashMap<CachedTextKey, BitmapText> temp = textCacheLastFrame; |
|
|
|
Map<CachedTextKey, BitmapText> temp = textCacheLastFrame; |
|
|
|
textCacheLastFrame = textCacheCurrentFrame; |
|
|
|
textCacheLastFrame = textCacheCurrentFrame; |
|
|
|
textCacheCurrentFrame = temp; |
|
|
|
textCacheCurrentFrame = temp; |
|
|
|
textCacheCurrentFrame.clear(); |
|
|
|
textCacheCurrentFrame.clear(); |
|
|
|
rm.setForcedRenderState(null); |
|
|
|
rm.setForcedRenderState(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public int getWidth() { |
|
|
|
public int getWidth() { |
|
|
|
return display.getWidth(); |
|
|
|
return display.getWidth(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public int getHeight() { |
|
|
|
public int getHeight() { |
|
|
|
return display.getHeight(); |
|
|
|
return display.getHeight(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void clear() { |
|
|
|
public void clear() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void setBlendMode(BlendMode blendMode) { |
|
|
|
public void setBlendMode(BlendMode blendMode) { |
|
|
|
renderState.setBlendMode(convertBlend(blendMode)); |
|
|
|
renderState.setBlendMode(convertBlend(blendMode)); |
|
|
|
} |
|
|
|
} |
|
|
@ -206,12 +221,14 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
private RenderState.BlendMode convertBlend(BlendMode blendMode) { |
|
|
|
private RenderState.BlendMode convertBlend(BlendMode blendMode) { |
|
|
|
if (blendMode == null) { |
|
|
|
if (blendMode == null) { |
|
|
|
return RenderState.BlendMode.Off; |
|
|
|
return RenderState.BlendMode.Off; |
|
|
|
} else if (blendMode == BlendMode.BLEND) { |
|
|
|
} else |
|
|
|
return RenderState.BlendMode.Alpha; |
|
|
|
switch (blendMode) { |
|
|
|
} else if (blendMode == BlendMode.MULIPLY) { |
|
|
|
case BLEND: |
|
|
|
return RenderState.BlendMode.Alpha; |
|
|
|
return RenderState.BlendMode.Alpha; |
|
|
|
} else { |
|
|
|
case MULIPLY: |
|
|
|
throw new UnsupportedOperationException(); |
|
|
|
return RenderState.BlendMode.Alpha; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new UnsupportedOperationException(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -264,6 +281,7 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
// System.out.format("renderFont(%s, %s, %d, %d, %s, %f, %f)\n", jmeFont.getFont(), str, x, y, color.toString(), sizeX, sizeY);
|
|
|
|
// System.out.format("renderFont(%s, %s, %d, %d, %s, %f, %f)\n", jmeFont.getFont(), str, x, y, color.toString(), sizeX, sizeY);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void renderImage(RenderImage image, int x, int y, int w, int h, |
|
|
|
public void renderImage(RenderImage image, int x, int y, int w, int h, |
|
|
|
int srcX, int srcY, int srcW, int srcH, |
|
|
|
int srcX, int srcY, int srcW, int srcH, |
|
|
|
Color color, float scale, |
|
|
|
Color color, float scale, |
|
|
@ -314,6 +332,7 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
// color.toString(), scale, centerX, centerY);
|
|
|
|
// color.toString(), scale, centerX, centerY);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void renderImage(RenderImage image, int x, int y, int width, int height, |
|
|
|
public void renderImage(RenderImage image, int x, int y, int width, int height, |
|
|
|
Color color, float imageScale) { |
|
|
|
Color color, float imageScale) { |
|
|
|
|
|
|
|
|
|
|
@ -339,6 +358,7 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
//System.out.format("renderImage1(%s, %d, %d, %d, %d, %s, %f)\n", jmeImage.getTexture().getKey().toString(), x, y, width, height, color.toString(), imageScale);
|
|
|
|
//System.out.format("renderImage1(%s, %d, %d, %d, %d, %s, %f)\n", jmeImage.getTexture().getKey().toString(), x, y, width, height, color.toString(), imageScale);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void renderQuad(int x, int y, int width, int height, Color color) { |
|
|
|
public void renderQuad(int x, int y, int width, int height, Color color) { |
|
|
|
//We test for alpha >0 as an optimization to prevent the render of completely transparent quads.
|
|
|
|
//We test for alpha >0 as an optimization to prevent the render of completely transparent quads.
|
|
|
|
//Nifty use layers that are often used for logical positionning and not rendering.
|
|
|
|
//Nifty use layers that are often used for logical positionning and not rendering.
|
|
|
@ -360,6 +380,7 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
//System.out.format("renderQuad1(%d, %d, %d, %d, %s)\n", x, y, width, height, color.toString());
|
|
|
|
//System.out.format("renderQuad1(%d, %d, %d, %d, %s)\n", x, y, width, height, color.toString());
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void renderQuad(int x, int y, int width, int height, |
|
|
|
public void renderQuad(int x, int y, int width, int height, |
|
|
|
Color topLeft, Color topRight, Color bottomRight, Color bottomLeft) { |
|
|
|
Color topLeft, Color topRight, Color bottomRight, Color bottomLeft) { |
|
|
|
|
|
|
|
|
|
|
@ -389,11 +410,13 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
// bottomLeft.toString());
|
|
|
|
// bottomLeft.toString());
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void enableClip(int x0, int y0, int x1, int y1) { |
|
|
|
public void enableClip(int x0, int y0, int x1, int y1) { |
|
|
|
clipWasSet = true; |
|
|
|
clipWasSet = true; |
|
|
|
r.setClipRect(x0, getHeight() - y1, x1 - x0, y1 - y0); |
|
|
|
r.setClipRect(x0, getHeight() - y1, x1 - x0, y1 - y0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void disableClip() { |
|
|
|
public void disableClip() { |
|
|
|
if (clipWasSet) { |
|
|
|
if (clipWasSet) { |
|
|
|
r.clearClipRect(); |
|
|
|
r.clearClipRect(); |
|
|
|