Jme nifty render device optimization :

- Banished color buffer updating at render time (except for gradient quads that uses vertex color)
- fully transparent quads are not rendered anymore (that avoid rendering transparent layers allowing complex layout for free).

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9232 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent 6087a930df
commit 654c44abdd
  1. 4
      engine/src/niftygui/Common/MatDefs/Nifty/NiftyQuad.frag
  2. 6
      engine/src/niftygui/Common/MatDefs/Nifty/NiftyQuad.vert
  3. 6
      engine/src/niftygui/Common/MatDefs/Nifty/NiftyQuadGrad.frag
  4. 18
      engine/src/niftygui/Common/MatDefs/Nifty/NiftyQuadGrad.j3md
  5. 14
      engine/src/niftygui/Common/MatDefs/Nifty/NiftyQuadGrad.vert
  6. 4
      engine/src/niftygui/Common/MatDefs/Nifty/NiftyTex.frag
  7. 4
      engine/src/niftygui/Common/MatDefs/Nifty/NiftyTex.vert
  8. 53
      engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java

@ -1,6 +1,6 @@
varying vec4 color;
uniform vec4 m_Color;
void main() {
gl_FragColor = color;
gl_FragColor = m_Color;
}

@ -1,15 +1,9 @@
uniform mat4 g_WorldViewProjectionMatrix;
uniform vec4 m_Color;
attribute vec4 inPosition;
attribute vec4 inColor;
varying vec2 texCoord;
varying vec4 color;
void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
gl_Position = vec4(pos, 0.0, 1.0);
color = inColor * m_Color;
}

@ -0,0 +1,6 @@
varying vec4 color;
void main() {
gl_FragColor = color;
}

@ -0,0 +1,18 @@
MaterialDef Default GUI {
MaterialParameters {
}
Technique {
VertexShader GLSL100: Common/MatDefs/Nifty/NiftyQuadGrad.vert
FragmentShader GLSL100: Common/MatDefs/Nifty/NiftyQuadGrad.frag
WorldParameters {
WorldViewProjectionMatrix
}
}
Technique FixedFunc {
}
}

@ -0,0 +1,14 @@
uniform mat4 g_WorldViewProjectionMatrix;
attribute vec4 inPosition;
attribute vec4 inColor;
attribute vec4 inIndex;
varying vec4 color;
void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
gl_Position = vec4(pos, 0.0, 1.0);
color = inIndex;
}

@ -2,11 +2,9 @@ uniform sampler2D m_Texture;
uniform vec4 m_Color;
varying vec2 texCoord;
varying vec4 color;
void main() {
vec4 texVal = texture2D(m_Texture, texCoord);
// texVal = m_UseTex ? texVal : vec4(1.0);
gl_FragColor = texVal * color ;
gl_FragColor = texVal * m_Color ;
}

@ -1,17 +1,13 @@
uniform mat4 g_WorldViewProjectionMatrix;
uniform vec4 m_Color;
attribute vec4 inPosition;
attribute vec4 inColor;
attribute vec2 inTexCoord;
varying vec2 texCoord;
varying vec4 color;
void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
gl_Position = vec4(pos, 0.0, 1.0);
texCoord = inTexCoord;
color = inColor * m_Color;
}

@ -69,6 +69,7 @@ public class RenderDeviceJme implements RenderDevice {
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);
@ -88,10 +89,17 @@ public class RenderDeviceJme implements RenderDevice {
quadModTC.setUsage(Usage.Stream);
//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) {
@ -179,19 +187,19 @@ public class RenderDeviceJme implements RenderDevice {
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);
// }
/**
*
@ -252,9 +260,9 @@ public class RenderDeviceJme implements RenderDevice {
Texture2D texture = jmeImage.getTexture();
niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
niftyMat.setColor("Color", ColorRGBA.White);
niftyMat.setColor("Color", convertColor(color, tempColor));
niftyMat.setTexture("Texture", texture);
setColor(color);
//setColor(color);
float imageWidth = jmeImage.getWidth();
float imageHeight = jmeImage.getHeight();
@ -298,9 +306,9 @@ public class RenderDeviceJme implements RenderDevice {
RenderImageJme jmeImage = (RenderImageJme) image;
niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
niftyMat.setColor("Color", ColorRGBA.White);
niftyMat.setColor("Color", convertColor(color, tempColor));
niftyMat.setTexture("Texture", jmeImage.getTexture());
setColor(color);
//setColor(color);
quad.clearBuffer(Type.TexCoord);
quad.setBuffer(quadDefaultTC);
@ -319,9 +327,9 @@ public class RenderDeviceJme implements RenderDevice {
}
public void renderQuad(int x, int y, int width, int height, Color color) {
if (color.getAlpha() > 0) {
niftyQuadMat.getAdditionalRenderState().setBlendMode(convertBlend());
niftyQuadMat.setColor("Color", ColorRGBA.White);
setColor(color);
niftyQuadMat.setColor("Color", convertColor(color, tempColor));
tempMat.loadIdentity();
tempMat.setTranslation(x, getHeight() - y, 0);
@ -329,7 +337,7 @@ public class RenderDeviceJme implements RenderDevice {
rm.setWorldMatrix(tempMat);
niftyQuadMat.render(quadGeom, rm);
}
// System.out.println("renderQuad (Solid)");
}
@ -348,15 +356,14 @@ public class RenderDeviceJme implements RenderDevice {
buf.flip();
quadColor.updateData(buf);
niftyQuadMat.getAdditionalRenderState().setBlendMode(convertBlend());
niftyQuadMat.setColor("Color", ColorRGBA.White);
niftyQuadGradMat.getAdditionalRenderState().setBlendMode(convertBlend());
tempMat.loadIdentity();
tempMat.setTranslation(x, getHeight() - y, 0);
tempMat.setScale(width, height, 0);
rm.setWorldMatrix(tempMat);
niftyQuadMat.render(quadGeom, rm);
niftyQuadGradMat.render(quadGeom, rm);
//
// System.out.println("renderQuad (Grad)");
}

Loading…
Cancel
Save