|
|
@ -57,40 +57,41 @@ 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 { |
|
|
|
|
|
|
|
|
|
|
|
BitmapFont font; |
|
|
|
BitmapFont font; |
|
|
|
String text; |
|
|
|
String text; |
|
|
|
// ColorRGBA color;
|
|
|
|
// ColorRGBA color;
|
|
|
|
|
|
|
|
|
|
|
|
public CachedTextKey(BitmapFont font, String text/*, ColorRGBA color*/) { |
|
|
|
public CachedTextKey(BitmapFont font, String text/*, ColorRGBA color*/) { |
|
|
|
this.font = font; |
|
|
|
this.font = font; |
|
|
|
this.text = text; |
|
|
|
this.text = text; |
|
|
|
// this.color = color;
|
|
|
|
// this.color = color;
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean equals(Object other) { |
|
|
|
public boolean equals(Object other) { |
|
|
|
CachedTextKey otherKey = (CachedTextKey) other; |
|
|
|
CachedTextKey otherKey = (CachedTextKey) other; |
|
|
@ -108,47 +109,51 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
return hash; |
|
|
|
return hash; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public RenderDeviceJme(NiftyJmeDisplay display) { |
|
|
|
public RenderDeviceJme(NiftyJmeDisplay display) { |
|
|
|
this.display = display; |
|
|
|
this.display = display; |
|
|
|
|
|
|
|
|
|
|
|
quadColor = new VertexBuffer(Type.Color); |
|
|
|
quadColor = new VertexBuffer(Type.Color); |
|
|
|
quadColor.setNormalized(true); |
|
|
|
quadColor.setNormalized(true); |
|
|
|
ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4); |
|
|
|
ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4); |
|
|
|
quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb); |
|
|
|
quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb); |
|
|
|
quad.setBuffer(quadColor); |
|
|
|
quad.setBuffer(quadColor); |
|
|
|
|
|
|
|
|
|
|
|
quadModTC.setUsage(Usage.Stream); |
|
|
|
quadModTC.setUsage(Usage.Stream); |
|
|
|
|
|
|
|
|
|
|
|
// Load the 3 material types separately to avoid
|
|
|
|
// Load the 3 material types separately to avoid
|
|
|
|
// reloading the shader when the defines change.
|
|
|
|
// reloading the shader when the defines change.
|
|
|
|
|
|
|
|
|
|
|
|
// Material with a single color (no texture or vertex color)
|
|
|
|
// Material with a single color (no texture or vertex color)
|
|
|
|
colorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); |
|
|
|
colorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); |
|
|
|
|
|
|
|
|
|
|
|
// Material with a texture and a color (no vertex color)
|
|
|
|
// Material with a texture and a color (no vertex color)
|
|
|
|
textureColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); |
|
|
|
textureColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); |
|
|
|
|
|
|
|
|
|
|
|
// Material with vertex color, used for gradients (no texture)
|
|
|
|
// Material with vertex color, used for gradients (no texture)
|
|
|
|
vertexColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); |
|
|
|
vertexColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); |
|
|
|
vertexColorMaterial.setBoolean("VertexColor", true); |
|
|
|
vertexColorMaterial.setBoolean("VertexColor", true); |
|
|
|
|
|
|
|
|
|
|
|
// Shared render state for all materials
|
|
|
|
// Shared render state for all materials
|
|
|
|
renderState.setDepthTest(false); |
|
|
|
renderState.setDepthTest(false); |
|
|
|
renderState.setDepthWrite(false); |
|
|
|
renderState.setDepthWrite(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) { |
|
|
|
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setRenderManager(RenderManager rm) { |
|
|
|
public void setRenderManager(RenderManager rm) { |
|
|
|
this.rm = rm; |
|
|
|
this.rm = rm; |
|
|
|
this.r = rm.getRenderer(); |
|
|
|
this.r = rm.getRenderer(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -161,60 +166,72 @@ 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)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int convertColor(Color color) { |
|
|
|
private int convertColor(Color color) { |
|
|
|
int color2 = 0; |
|
|
|
int color2 = 0; |
|
|
|
color2 |= ((int) (255.0 * color.getAlpha())) << 24; |
|
|
|
color2 |= ((int) (255.0 * color.getAlpha())) << 24; |
|
|
@ -223,19 +240,19 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
color2 |= ((int) (255.0 * color.getRed())); |
|
|
|
color2 |= ((int) (255.0 * color.getRed())); |
|
|
|
return color2; |
|
|
|
return color2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ColorRGBA convertColor(Color inColor, ColorRGBA outColor) { |
|
|
|
private ColorRGBA convertColor(Color inColor, ColorRGBA outColor) { |
|
|
|
return outColor.set(inColor.getRed(), inColor.getGreen(), inColor.getBlue(), inColor.getAlpha()); |
|
|
|
return outColor.set(inColor.getRed(), inColor.getGreen(), inColor.getBlue(), inColor.getAlpha()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) { |
|
|
|
public void renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) { |
|
|
|
if (str.length() == 0) { |
|
|
|
if (str.length() == 0) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RenderFontJme jmeFont = (RenderFontJme) font; |
|
|
|
RenderFontJme jmeFont = (RenderFontJme) font; |
|
|
|
|
|
|
|
|
|
|
|
ColorRGBA colorRgba = convertColor(color, tempColor); |
|
|
|
ColorRGBA colorRgba = convertColor(color, tempColor); |
|
|
|
CachedTextKey key = new CachedTextKey(jmeFont.getFont(), str/*, colorRgba*/); |
|
|
|
CachedTextKey key = new CachedTextKey(jmeFont.getFont(), str/*, colorRgba*/); |
|
|
|
BitmapText text = textCacheLastFrame.get(key); |
|
|
|
BitmapText text = textCacheLastFrame.get(key); |
|
|
@ -245,12 +262,12 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
text.updateLogicalState(0); |
|
|
|
text.updateLogicalState(0); |
|
|
|
} |
|
|
|
} |
|
|
|
textCacheCurrentFrame.put(key, text); |
|
|
|
textCacheCurrentFrame.put(key, text); |
|
|
|
|
|
|
|
|
|
|
|
// float width = text.getLineWidth();
|
|
|
|
// float width = text.getLineWidth();
|
|
|
|
// float height = text.getLineHeight();
|
|
|
|
// float height = text.getLineHeight();
|
|
|
|
float x0 = x; //+ 0.5f * width * (1f - sizeX);
|
|
|
|
float x0 = x; //+ 0.5f * width * (1f - sizeX);
|
|
|
|
float y0 = y; // + 0.5f * height * (1f - sizeY);
|
|
|
|
float y0 = y; // + 0.5f * height * (1f - sizeY);
|
|
|
|
|
|
|
|
|
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.setTranslation(x0, getHeight() - y0, 0); |
|
|
|
tempMat.setTranslation(x0, getHeight() - y0, 0); |
|
|
|
tempMat.setScale(sizeX, sizeY, 0); |
|
|
|
tempMat.setScale(sizeX, sizeY, 0); |
|
|
@ -260,33 +277,34 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
text.setColor(colorRgba); |
|
|
|
text.setColor(colorRgba); |
|
|
|
text.updateLogicalState(0); |
|
|
|
text.updateLogicalState(0); |
|
|
|
text.render(rm, colorRgba); |
|
|
|
text.render(rm, colorRgba); |
|
|
|
|
|
|
|
|
|
|
|
// 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, |
|
|
|
int centerX, int centerY) { |
|
|
|
int centerX, int centerY) { |
|
|
|
|
|
|
|
|
|
|
|
RenderImageJme jmeImage = (RenderImageJme) image; |
|
|
|
RenderImageJme jmeImage = (RenderImageJme) image; |
|
|
|
Texture2D texture = jmeImage.getTexture(); |
|
|
|
Texture2D texture = jmeImage.getTexture(); |
|
|
|
|
|
|
|
|
|
|
|
textureColorMaterial.setColor("Color", convertColor(color, tempColor)); |
|
|
|
textureColorMaterial.setColor("Color", convertColor(color, tempColor)); |
|
|
|
textureColorMaterial.setTexture("ColorMap", texture); |
|
|
|
textureColorMaterial.setTexture("ColorMap", texture); |
|
|
|
|
|
|
|
|
|
|
|
float imageWidth = jmeImage.getWidth(); |
|
|
|
float imageWidth = jmeImage.getWidth(); |
|
|
|
float imageHeight = jmeImage.getHeight(); |
|
|
|
float imageHeight = jmeImage.getHeight(); |
|
|
|
FloatBuffer texCoords = (FloatBuffer) quadModTC.getData(); |
|
|
|
FloatBuffer texCoords = (FloatBuffer) quadModTC.getData(); |
|
|
|
|
|
|
|
|
|
|
|
float startX = srcX / imageWidth; |
|
|
|
float startX = srcX / imageWidth; |
|
|
|
float startY = srcY / imageHeight; |
|
|
|
float startY = srcY / imageHeight; |
|
|
|
float endX = startX + (srcW / imageWidth); |
|
|
|
float endX = startX + (srcW / imageWidth); |
|
|
|
float endY = startY + (srcH / imageHeight); |
|
|
|
float endY = startY + (srcH / imageHeight); |
|
|
|
|
|
|
|
|
|
|
|
startY = 1f - startY; |
|
|
|
startY = 1f - startY; |
|
|
|
endY = 1f - endY; |
|
|
|
endY = 1f - endY; |
|
|
|
|
|
|
|
|
|
|
|
texCoords.rewind(); |
|
|
|
texCoords.rewind(); |
|
|
|
texCoords.put(startX).put(startY); |
|
|
|
texCoords.put(startX).put(startY); |
|
|
|
texCoords.put(endX).put(startY); |
|
|
|
texCoords.put(endX).put(startY); |
|
|
@ -294,51 +312,53 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
texCoords.put(startX).put(endY); |
|
|
|
texCoords.put(startX).put(endY); |
|
|
|
texCoords.flip(); |
|
|
|
texCoords.flip(); |
|
|
|
quadModTC.updateData(texCoords); |
|
|
|
quadModTC.updateData(texCoords); |
|
|
|
|
|
|
|
|
|
|
|
quad.clearBuffer(Type.TexCoord); |
|
|
|
quad.clearBuffer(Type.TexCoord); |
|
|
|
quad.setBuffer(quadModTC); |
|
|
|
quad.setBuffer(quadModTC); |
|
|
|
|
|
|
|
|
|
|
|
float x0 = centerX + (x - centerX) * scale; |
|
|
|
float x0 = centerX + (x - centerX) * scale; |
|
|
|
float y0 = centerY + (y - centerY) * scale; |
|
|
|
float y0 = centerY + (y - centerY) * scale; |
|
|
|
|
|
|
|
|
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.setTranslation(x0, getHeight() - y0, 0); |
|
|
|
tempMat.setTranslation(x0, getHeight() - y0, 0); |
|
|
|
tempMat.setScale(w * scale, h * scale, 0); |
|
|
|
tempMat.setScale(w * scale, h * scale, 0); |
|
|
|
|
|
|
|
|
|
|
|
rm.setWorldMatrix(tempMat); |
|
|
|
rm.setWorldMatrix(tempMat); |
|
|
|
rm.setForcedRenderState(renderState); |
|
|
|
rm.setForcedRenderState(renderState); |
|
|
|
textureColorMaterial.render(quadGeom, rm); |
|
|
|
textureColorMaterial.render(quadGeom, rm); |
|
|
|
|
|
|
|
|
|
|
|
//System.out.format("renderImage2(%s, %d, %d, %d, %d, %d, %d, %d, %d, %s, %f, %d, %d)\n", texture.getKey().toString(),
|
|
|
|
//System.out.format("renderImage2(%s, %d, %d, %d, %d, %d, %d, %d, %d, %s, %f, %d, %d)\n", texture.getKey().toString(),
|
|
|
|
// x, y, w, h, srcX, srcY, srcW, srcH,
|
|
|
|
// x, y, w, h, srcX, srcY, srcW, srcH,
|
|
|
|
// 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) { |
|
|
|
|
|
|
|
|
|
|
|
RenderImageJme jmeImage = (RenderImageJme) image; |
|
|
|
RenderImageJme jmeImage = (RenderImageJme) image; |
|
|
|
|
|
|
|
|
|
|
|
textureColorMaterial.setColor("Color", convertColor(color, tempColor)); |
|
|
|
textureColorMaterial.setColor("Color", convertColor(color, tempColor)); |
|
|
|
textureColorMaterial.setTexture("ColorMap", jmeImage.getTexture()); |
|
|
|
textureColorMaterial.setTexture("ColorMap", jmeImage.getTexture()); |
|
|
|
|
|
|
|
|
|
|
|
quad.clearBuffer(Type.TexCoord); |
|
|
|
quad.clearBuffer(Type.TexCoord); |
|
|
|
quad.setBuffer(quadDefaultTC); |
|
|
|
quad.setBuffer(quadDefaultTC); |
|
|
|
|
|
|
|
|
|
|
|
float x0 = x + 0.5f * width * (1f - imageScale); |
|
|
|
float x0 = x + 0.5f * width * (1f - imageScale); |
|
|
|
float y0 = y + 0.5f * height * (1f - imageScale); |
|
|
|
float y0 = y + 0.5f * height * (1f - imageScale); |
|
|
|
|
|
|
|
|
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.setTranslation(x0, getHeight() - y0, 0); |
|
|
|
tempMat.setTranslation(x0, getHeight() - y0, 0); |
|
|
|
tempMat.setScale(width * imageScale, height * imageScale, 0); |
|
|
|
tempMat.setScale(width * imageScale, height * imageScale, 0); |
|
|
|
|
|
|
|
|
|
|
|
rm.setWorldMatrix(tempMat); |
|
|
|
rm.setWorldMatrix(tempMat); |
|
|
|
rm.setForcedRenderState(renderState); |
|
|
|
rm.setForcedRenderState(renderState); |
|
|
|
textureColorMaterial.render(quadGeom, rm); |
|
|
|
textureColorMaterial.render(quadGeom, rm); |
|
|
|
|
|
|
|
|
|
|
|
//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.
|
|
|
@ -346,7 +366,7 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
//Since we disable depth write, there is absolutely no point in rendering those quads
|
|
|
|
//Since we disable depth write, there is absolutely no point in rendering those quads
|
|
|
|
//This optimization can result in a huge increase of perfs on complex Nifty UIs.
|
|
|
|
//This optimization can result in a huge increase of perfs on complex Nifty UIs.
|
|
|
|
if(color.getAlpha() >0){ |
|
|
|
if(color.getAlpha() >0){ |
|
|
|
colorMaterial.setColor("Color", convertColor(color, tempColor)); |
|
|
|
colorMaterial.setColor("Color", convertColor(color, tempColor)); |
|
|
|
|
|
|
|
|
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.setTranslation(x, getHeight() - y, 0); |
|
|
|
tempMat.setTranslation(x, getHeight() - y, 0); |
|
|
@ -356,44 +376,47 @@ public class RenderDeviceJme implements RenderDevice { |
|
|
|
rm.setForcedRenderState(renderState); |
|
|
|
rm.setForcedRenderState(renderState); |
|
|
|
colorMaterial.render(quadGeom, rm); |
|
|
|
colorMaterial.render(quadGeom, rm); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//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) { |
|
|
|
|
|
|
|
|
|
|
|
ByteBuffer buf = (ByteBuffer) quadColor.getData(); |
|
|
|
ByteBuffer buf = (ByteBuffer) quadColor.getData(); |
|
|
|
buf.rewind(); |
|
|
|
buf.rewind(); |
|
|
|
|
|
|
|
|
|
|
|
buf.putInt(convertColor(topRight)); |
|
|
|
buf.putInt(convertColor(topRight)); |
|
|
|
buf.putInt(convertColor(topLeft)); |
|
|
|
buf.putInt(convertColor(topLeft)); |
|
|
|
|
|
|
|
|
|
|
|
buf.putInt(convertColor(bottomLeft)); |
|
|
|
buf.putInt(convertColor(bottomLeft)); |
|
|
|
buf.putInt(convertColor(bottomRight)); |
|
|
|
buf.putInt(convertColor(bottomRight)); |
|
|
|
|
|
|
|
|
|
|
|
buf.flip(); |
|
|
|
buf.flip(); |
|
|
|
quadColor.updateData(buf); |
|
|
|
quadColor.updateData(buf); |
|
|
|
|
|
|
|
|
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.loadIdentity(); |
|
|
|
tempMat.setTranslation(x, getHeight() - y, 0); |
|
|
|
tempMat.setTranslation(x, getHeight() - y, 0); |
|
|
|
tempMat.setScale(width, height, 0); |
|
|
|
tempMat.setScale(width, height, 0); |
|
|
|
|
|
|
|
|
|
|
|
rm.setWorldMatrix(tempMat); |
|
|
|
rm.setWorldMatrix(tempMat); |
|
|
|
rm.setForcedRenderState(renderState); |
|
|
|
rm.setForcedRenderState(renderState); |
|
|
|
vertexColorMaterial.render(quadGeom, rm); |
|
|
|
vertexColorMaterial.render(quadGeom, rm); |
|
|
|
|
|
|
|
|
|
|
|
//System.out.format("renderQuad2(%d, %d, %d, %d, %s, %s, %s, %s)\n", x, y, width, height, topLeft.toString(),
|
|
|
|
//System.out.format("renderQuad2(%d, %d, %d, %d, %s, %s, %s, %s)\n", x, y, width, height, topLeft.toString(),
|
|
|
|
// topRight.toString(),
|
|
|
|
// topRight.toString(),
|
|
|
|
// bottomRight.toString(),
|
|
|
|
// bottomRight.toString(),
|
|
|
|
// 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(); |
|
|
|