aboutsummaryrefslogtreecommitdiff
path: root/engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java
diff options
context:
space:
mode:
authorScott Barta <sbarta@google.com>2012-03-09 13:52:20 -0800
committerScott Barta <sbarta@google.com>2012-03-09 14:13:24 -0800
commita6b44658eb1c55295f132a36233a11aa2bd8f9cf (patch)
tree4006b29d319de8635ca7cc2384782618f6c80ee7 /engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java
parent59b2e6871c65f58fdad78cd7229c292f6a177578 (diff)
downloadjmonkeyengine-nougat-mr2-release.tar.gz
New drop of the jmonkeyengine libraryHEADandroid-wear-n-preview-3android-wear-n-preview-2android-wear-n-preview-1android-sdk-support_r11android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-n-preview-5android-n-preview-4android-n-preview-3android-n-preview-2android-n-preview-1android-n-mr2-preview-2android-n-mr2-preview-1android-n-mr1-preview-2android-n-mr1-preview-1android-n-iot-release-smart-display-r2android-n-iot-release-smart-displayandroid-n-iot-release-polk-at1android-n-iot-release-lg-thinq-wk7android-n-iot-release-ihome-igv1android-n-iot-preview-4android-l-preview_r2android-cts-6.0_r9android-cts-6.0_r8android-cts-6.0_r7android-cts-6.0_r6android-cts-6.0_r5android-cts-6.0_r4android-cts-6.0_r32android-cts-6.0_r31android-cts-6.0_r30android-cts-6.0_r3android-cts-6.0_r29android-cts-6.0_r28android-cts-6.0_r27android-cts-6.0_r26android-cts-6.0_r25android-cts-6.0_r24android-cts-6.0_r23android-cts-6.0_r22android-cts-6.0_r21android-cts-6.0_r20android-cts-6.0_r2android-cts-6.0_r19android-cts-6.0_r18android-cts-6.0_r17android-cts-6.0_r16android-cts-6.0_r15android-cts-6.0_r14android-cts-6.0_r13android-cts-6.0_r12android-cts-6.0_r1android-cts-4.4_r4android-cts-4.4_r1android-cts-4.2_r2android-cts-4.2_r1android-cts-4.1_r4android-cts-4.1_r2android-cts-4.1_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-6.0.1_r9android-6.0.1_r81android-6.0.1_r80android-6.0.1_r8android-6.0.1_r79android-6.0.1_r78android-6.0.1_r77android-6.0.1_r74android-6.0.1_r73android-6.0.1_r72android-6.0.1_r70android-6.0.1_r7android-6.0.1_r69android-6.0.1_r68android-6.0.1_r67android-6.0.1_r66android-6.0.1_r65android-6.0.1_r63android-6.0.1_r62android-6.0.1_r61android-6.0.1_r60android-6.0.1_r59android-6.0.1_r58android-6.0.1_r57android-6.0.1_r56android-6.0.1_r55android-6.0.1_r54android-6.0.1_r53android-6.0.1_r52android-6.0.1_r51android-6.0.1_r50android-6.0.1_r5android-6.0.1_r49android-6.0.1_r48android-6.0.1_r47android-6.0.1_r46android-6.0.1_r45android-6.0.1_r43android-6.0.1_r42android-6.0.1_r41android-6.0.1_r40android-6.0.1_r4android-6.0.1_r33android-6.0.1_r32android-6.0.1_r31android-6.0.1_r30android-6.0.1_r3android-6.0.1_r28android-6.0.1_r27android-6.0.1_r26android-6.0.1_r25android-6.0.1_r24android-6.0.1_r22android-6.0.1_r21android-6.0.1_r20android-6.0.1_r18android-6.0.1_r17android-6.0.1_r16android-6.0.1_r13android-6.0.1_r12android-6.0.1_r11android-6.0.1_r10android-6.0.1_r1android-6.0.0_r7android-6.0.0_r6android-6.0.0_r5android-6.0.0_r41android-6.0.0_r4android-6.0.0_r3android-6.0.0_r26android-6.0.0_r25android-6.0.0_r24android-6.0.0_r23android-6.0.0_r2android-6.0.0_r13android-6.0.0_r12android-6.0.0_r11android-6.0.0_r1android-4.4w_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1android-4.3_r3.1android-4.3_r3android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.3.1_r1android-4.2_r1android-4.2.2_r1.2android-4.2.2_r1.1android-4.2.2_r1android-4.2.1_r1.2android-4.2.1_r1.1android-4.2.1_r1android-4.1.2_r2.1android-4.1.2_r2android-4.1.2_r1android-4.1.1_r6.1android-4.1.1_r6android-4.1.1_r5android-4.1.1_r4android-4.1.1_r3android-4.1.1_r2android-4.1.1_r1.1android-4.1.1_r1tools_r22.2tools_r22tools_r21nougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-iot-releasen-iot-preview-4mastermarshmallow-releasemarshmallow-mr3-releasemarshmallow-mr2-releasemarshmallow-mr1-releasemarshmallow-mr1-devmarshmallow-dr1.6-releasemarshmallow-dr1.5-releasemarshmallow-dr1.5-devmarshmallow-dr-releasemarshmallow-dr-dragon-releasemarshmallow-dr-devmarshmallow-devmarshmallow-cts-releasemainl-previewkitkat-wearkitkat-releasekitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-releasekitkat-cts-devjb-releasejb-mr2.0.0-releasejb-mr2.0-releasejb-mr2-releasejb-mr2-devjb-mr1.1-releasejb-mr1.1-dev-plus-aospjb-mr1.1-devjb-mr1-releasejb-mr1-dev-plus-aospjb-mr1-devjb-mr0-releasejb-devidea133-weekly-releaseidea133
A new drop of the jmonkeyengine library sources, based on a 2012-03-05 snapshot. Fixes a few unnecessary memory allocations in the main rendering loop. Change-Id: I51ac0942fe87204df102cfdce746b59a5cb5ff85
Diffstat (limited to 'engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java')
-rw-r--r--engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java289
1 files changed, 140 insertions, 149 deletions
diff --git a/engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java b/engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java
index 8977ed6..1f36a97 100644
--- a/engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java
+++ b/engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.niftygui;
import com.jme3.font.BitmapText;
@@ -60,140 +59,148 @@ import java.nio.FloatBuffer;
import java.util.HashMap;
public class RenderDeviceJme implements RenderDevice {
-
+
private NiftyJmeDisplay display;
private RenderManager rm;
private Renderer r;
-
private HashMap<String, BitmapText> textCacheLastFrame = new HashMap<String, BitmapText>();
private HashMap<String, BitmapText> textCacheCurrentFrame = new HashMap<String, BitmapText>();
-
private final Quad quad = new Quad(1, -1, true);
private final Geometry quadGeom = new Geometry("nifty-quad", quad);
private final Material niftyMat;
-
+ private final Material niftyQuadMat;
+ private final Material niftyQuadGradMat;
private boolean clipWasSet = false;
private BlendMode blendMode = null;
-
private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord);
private VertexBuffer quadModTC = quadDefaultTC.clone();
private VertexBuffer quadColor;
-
private Matrix4f tempMat = new Matrix4f();
private ColorRGBA tempColor = new ColorRGBA();
-
- public RenderDeviceJme(NiftyJmeDisplay display){
+
+ public RenderDeviceJme(NiftyJmeDisplay display) {
this.display = display;
-
+
quadColor = new VertexBuffer(Type.Color);
quadColor.setNormalized(true);
ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4);
quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb);
quad.setBuffer(quadColor);
-
+
quadModTC.setUsage(Usage.Stream);
-
- niftyMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/Nifty.j3md");
+
+ //Color + texture color material for text and images
+ niftyMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/NiftyTex.j3md");
niftyMat.getAdditionalRenderState().setDepthTest(false);
+ //Color material for uniform colored quads
+ niftyQuadMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/NiftyQuad.j3md");
+ niftyQuadMat.getAdditionalRenderState().setDepthTest(false);
+
+ //vertex color only for gradient quads (although i didn't find a way in nifty to make a gradient using vertex color)
+ niftyQuadGradMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/NiftyQuadGrad.j3md");
+ niftyQuadGradMat.getAdditionalRenderState().setDepthTest(false);
+
}
-
+
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) {
}
-
- public void setRenderManager(RenderManager rm){
+
+ public void setRenderManager(RenderManager rm) {
this.rm = rm;
this.r = rm.getRenderer();
}
// TODO: Cursor support
- public MouseCursor createMouseCursor(String str, int x, int y){
+ public MouseCursor createMouseCursor(String str, int x, int y) {
return new MouseCursor() {
+
public void dispose() {
}
};
}
-
- public void enableMouseCursor(MouseCursor cursor){
+
+ public void enableMouseCursor(MouseCursor cursor) {
}
-
- public void disableMouseCursor(){
+
+ public void disableMouseCursor() {
}
-
+
public RenderImage createImage(String filename, boolean linear) {
return new RenderImageJme(filename, linear, display);
}
-
+
public RenderFont createFont(String filename) {
return new RenderFontJme(filename, display);
}
-
+
public void beginFrame() {
}
-
+
public void endFrame() {
HashMap<String, BitmapText> temp = textCacheLastFrame;
textCacheLastFrame = textCacheCurrentFrame;
textCacheCurrentFrame = temp;
textCacheCurrentFrame.clear();
-
+
// System.exit(1);
}
-
+
public int getWidth() {
return display.getWidth();
}
-
+
public int getHeight() {
return display.getHeight();
}
-
+
public void clear() {
}
-
+
public void setBlendMode(BlendMode blendMode) {
- if (this.blendMode != blendMode){
+ if (this.blendMode != blendMode) {
this.blendMode = blendMode;
}
}
-
- private RenderState.BlendMode convertBlend(){
- if (blendMode == null)
+
+ private RenderState.BlendMode convertBlend() {
+ if (blendMode == null) {
return RenderState.BlendMode.Off;
- else if (blendMode == BlendMode.BLEND)
+ } else if (blendMode == BlendMode.BLEND) {
return RenderState.BlendMode.Alpha;
- else if (blendMode == BlendMode.MULIPLY)
+ } else if (blendMode == BlendMode.MULIPLY) {
return RenderState.BlendMode.Modulate;
- else
+ } else {
throw new UnsupportedOperationException();
+ }
}
-
- private int convertColor(Color color){
+
+ private int convertColor(Color color) {
int color2 = 0;
- color2 |= ((int)(255.0 * color.getAlpha())) << 24;
- color2 |= ((int)(255.0 * color.getBlue())) << 16;
- color2 |= ((int)(255.0 * color.getGreen())) << 8;
- color2 |= ((int)(255.0 * color.getRed()));
+ color2 |= ((int) (255.0 * color.getAlpha())) << 24;
+ color2 |= ((int) (255.0 * color.getBlue())) << 16;
+ color2 |= ((int) (255.0 * color.getGreen())) << 8;
+ color2 |= ((int) (255.0 * color.getRed()));
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());
}
-
- private void setColor(Color color){
- ByteBuffer buf = (ByteBuffer) quadColor.getData();
- buf.rewind();
-
- int color2 = convertColor(color);
- buf.putInt(color2);
- buf.putInt(color2);
- buf.putInt(color2);
- buf.putInt(color2);
-
- buf.flip();
- quadColor.updateData(buf);
- }
+// private void setColor(Color color) {
+// ByteBuffer buf = (ByteBuffer) quadColor.getData();
+// buf.rewind();
+//
+// int color2 = convertColor(color);
+// buf.putInt(color2);
+// buf.putInt(color2);
+// buf.putInt(color2);
+// buf.putInt(color2);
+//
+// buf.flip();
+// quadColor.updateData(buf);
+// }
+
/**
*
* @param font
@@ -205,22 +212,23 @@ public class RenderDeviceJme implements RenderDevice {
* @deprecated use renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) instead
*/
@Deprecated
- public void renderFont(RenderFont font, String str, int x, int y, Color color, float size){
+ public void renderFont(RenderFont font, String str, int x, int y, Color color, float size) {
renderFont(font, str, x, y, color, size, size);
}
-
+
@Override
- public void renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY){
- //TODO find out what the f1 param is for
- if (str.length() == 0)
+ public void renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) {
+ if (str.length() == 0) {
return;
-
- if (font instanceof RenderFontNull)
+ }
+
+ if (font instanceof RenderFontNull) {
return;
-
+ }
+
RenderFontJme jmeFont = (RenderFontJme) font;
- String key = font+str+color.getColorString();
+ String key = font + str + color.getColorString();
BitmapText text = textCacheLastFrame.get(key);
if (text == null) {
text = jmeFont.createText();
@@ -228,166 +236,149 @@ public class RenderDeviceJme implements RenderDevice {
text.updateLogicalState(0);
}
textCacheCurrentFrame.put(key, text);
-
- niftyMat.setColor("Color", convertColor(color, tempColor));
- niftyMat.setBoolean("UseTex", true);
+
+ niftyMat.setColor("Color", convertColor(color, tempColor));
niftyMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
// niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
text.setMaterial(niftyMat);
-
- float width = text.getLineWidth();
- float height = text.getLineHeight();
-
- float x0 = x + 0.5f * width * (1f - sizeX);
- float y0 = y + 0.5f * height * (1f - sizeY);
-
+
tempMat.loadIdentity();
- tempMat.setTranslation(x0, getHeight() - y0, 0);
+ tempMat.setTranslation(x, getHeight() - y, 0);
tempMat.setScale(sizeX, sizeY, 0);
-
+
rm.setWorldMatrix(tempMat);
text.render(rm);
-
+
// System.out.println("renderFont");
}
-
+
public void renderImage(RenderImage image, int x, int y, int w, int h,
- int srcX, int srcY, int srcW, int srcH,
- Color color, float scale,
- int centerX, int centerY){
+ int srcX, int srcY, int srcW, int srcH,
+ Color color, float scale,
+ int centerX, int centerY) {
RenderImageJme jmeImage = (RenderImageJme) image;
Texture2D texture = jmeImage.getTexture();
-
+
niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
- niftyMat.setColor("Color", ColorRGBA.White);
- niftyMat.setTexture("Texture", texture);
- niftyMat.setBoolean("UseTex", true);
- setColor(color);
-
- float imageWidth = jmeImage.getWidth();
+ niftyMat.setColor("Color", convertColor(color, tempColor));
+ niftyMat.setTexture("Texture", texture);
+ //setColor(color);
+
+ float imageWidth = jmeImage.getWidth();
float imageHeight = jmeImage.getHeight();
FloatBuffer texCoords = (FloatBuffer) quadModTC.getData();
-
+
float startX = srcX / imageWidth;
float startY = srcY / imageHeight;
- float endX = startX + (srcW / imageWidth);
- float endY = startY + (srcH / imageHeight);
-
+ float endX = startX + (srcW / imageWidth);
+ float endY = startY + (srcH / imageHeight);
+
startY = 1f - startY;
- endY = 1f - endY;
-
+ endY = 1f - endY;
+
texCoords.rewind();
texCoords.put(startX).put(startY);
- texCoords.put(endX) .put(startY);
- texCoords.put(endX) .put(endY);
+ texCoords.put(endX).put(startY);
+ texCoords.put(endX).put(endY);
texCoords.put(startX).put(endY);
texCoords.flip();
quadModTC.updateData(texCoords);
-
+
quad.clearBuffer(Type.TexCoord);
quad.setBuffer(quadModTC);
-
+
float x0 = centerX + (x - centerX) * scale;
float y0 = centerY + (y - centerY) * scale;
-
+
tempMat.loadIdentity();
tempMat.setTranslation(x0, getHeight() - y0, 0);
tempMat.setScale(w * scale, h * scale, 0);
-
+
rm.setWorldMatrix(tempMat);
niftyMat.render(quadGeom, rm);
//
// System.out.println("renderImage (Sub)");
}
-
+
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;
-
+
niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
- niftyMat.setColor("Color", ColorRGBA.White);
- niftyMat.setTexture("Texture", jmeImage.getTexture());
- niftyMat.setBoolean("UseTex", true);
- setColor(color);
-
+ niftyMat.setColor("Color", convertColor(color, tempColor));
+ niftyMat.setTexture("Texture", jmeImage.getTexture());
+ //setColor(color);
+
quad.clearBuffer(Type.TexCoord);
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);
-
+
tempMat.loadIdentity();
tempMat.setTranslation(x0, getHeight() - y0, 0);
tempMat.setScale(width * imageScale, height * imageScale, 0);
-
+
rm.setWorldMatrix(tempMat);
niftyMat.render(quadGeom, rm);
//
// System.out.println("renderImage");
}
-
- public void renderQuad(int x, int y, int width, int height, Color color){
- niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
- niftyMat.setColor("Color", ColorRGBA.White);
- niftyMat.clearParam("Texture");
- niftyMat.setBoolean("UseTex", false);
- setColor(color);
-
- tempMat.loadIdentity();
- tempMat.setTranslation(x, getHeight() - y, 0);
- tempMat.setScale(width, height, 0);
-
- rm.setWorldMatrix(tempMat);
- niftyMat.render(quadGeom, rm);
-
+
+ public void renderQuad(int x, int y, int width, int height, Color color) {
+ if (color.getAlpha() > 0) {
+ niftyQuadMat.getAdditionalRenderState().setBlendMode(convertBlend());
+ niftyQuadMat.setColor("Color", convertColor(color, tempColor));
+
+ tempMat.loadIdentity();
+ tempMat.setTranslation(x, getHeight() - y, 0);
+ tempMat.setScale(width, height, 0);
+
+ rm.setWorldMatrix(tempMat);
+ niftyQuadMat.render(quadGeom, rm);
+ }
// System.out.println("renderQuad (Solid)");
}
-
+
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();
buf.rewind();
buf.putInt(convertColor(topRight));
buf.putInt(convertColor(topLeft));
-
+
buf.putInt(convertColor(bottomLeft));
buf.putInt(convertColor(bottomRight));
buf.flip();
quadColor.updateData(buf);
- niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
- niftyMat.setColor("Color", ColorRGBA.White);
- niftyMat.clearParam("Texture");
- niftyMat.setBoolean("UseTex", false);
-
+ niftyQuadGradMat.getAdditionalRenderState().setBlendMode(convertBlend());
+
tempMat.loadIdentity();
tempMat.setTranslation(x, getHeight() - y, 0);
tempMat.setScale(width, height, 0);
-
+
rm.setWorldMatrix(tempMat);
- niftyMat.render(quadGeom, rm);
+ niftyQuadGradMat.render(quadGeom, rm);
//
// System.out.println("renderQuad (Grad)");
}
-
- public void enableClip(int x0, int y0, int x1, int y1){
+
+ public void enableClip(int x0, int y0, int x1, int y1) {
// System.out.println("enableClip");
clipWasSet = true;
r.setClipRect(x0, getHeight() - y1, x1 - x0, y1 - y0);
}
-
+
public void disableClip() {
// System.out.println("disableClip");
- if (clipWasSet){
+ if (clipWasSet) {
r.clearClipRect();
clipWasSet = false;
}
}
-
-
-
}