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() { void main() {
gl_FragColor = color; gl_FragColor = m_Color;
} }

@ -1,15 +1,9 @@
uniform mat4 g_WorldViewProjectionMatrix; uniform mat4 g_WorldViewProjectionMatrix;
uniform vec4 m_Color;
attribute vec4 inPosition; attribute vec4 inPosition;
attribute vec4 inColor;
varying vec2 texCoord;
varying vec4 color;
void main() { void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy; vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
gl_Position = vec4(pos, 0.0, 1.0); 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; uniform vec4 m_Color;
varying vec2 texCoord; varying vec2 texCoord;
varying vec4 color;
void main() { void main() {
vec4 texVal = texture2D(m_Texture, texCoord); vec4 texVal = texture2D(m_Texture, texCoord);
// texVal = m_UseTex ? texVal : vec4(1.0); gl_FragColor = texVal * m_Color ;
gl_FragColor = texVal * color ;
} }

@ -1,17 +1,13 @@
uniform mat4 g_WorldViewProjectionMatrix; uniform mat4 g_WorldViewProjectionMatrix;
uniform vec4 m_Color;
attribute vec4 inPosition; attribute vec4 inPosition;
attribute vec4 inColor;
attribute vec2 inTexCoord; attribute vec2 inTexCoord;
varying vec2 texCoord; varying vec2 texCoord;
varying vec4 color;
void main() { void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy; vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
gl_Position = vec4(pos, 0.0, 1.0); gl_Position = vec4(pos, 0.0, 1.0);
texCoord = inTexCoord; 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 Geometry quadGeom = new Geometry("nifty-quad", quad);
private final Material niftyMat; private final Material niftyMat;
private final Material niftyQuadMat; private final Material niftyQuadMat;
private final Material niftyQuadGradMat;
private boolean clipWasSet = false; private boolean clipWasSet = false;
private BlendMode blendMode = null; private BlendMode blendMode = null;
private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord); private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord);
@ -88,10 +89,17 @@ public class RenderDeviceJme implements RenderDevice {
quadModTC.setUsage(Usage.Stream); quadModTC.setUsage(Usage.Stream);
//Color + texture color material for text and images
niftyMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/NiftyTex.j3md"); niftyMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/NiftyTex.j3md");
niftyMat.getAdditionalRenderState().setDepthTest(false); niftyMat.getAdditionalRenderState().setDepthTest(false);
//Color material for uniform colored quads
niftyQuadMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/NiftyQuad.j3md"); niftyQuadMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/NiftyQuad.j3md");
niftyQuadMat.getAdditionalRenderState().setDepthTest(false); 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 setResourceLoader(NiftyResourceLoader niftyResourceLoader) {
@ -179,19 +187,19 @@ public class RenderDeviceJme implements RenderDevice {
return outColor.set(inColor.getRed(), inColor.getGreen(), inColor.getBlue(), inColor.getAlpha()); return outColor.set(inColor.getRed(), inColor.getGreen(), inColor.getBlue(), inColor.getAlpha());
} }
private void setColor(Color color) { // private void setColor(Color color) {
ByteBuffer buf = (ByteBuffer) quadColor.getData(); // ByteBuffer buf = (ByteBuffer) quadColor.getData();
buf.rewind(); // buf.rewind();
//
int color2 = convertColor(color); // int color2 = convertColor(color);
buf.putInt(color2); // buf.putInt(color2);
buf.putInt(color2); // buf.putInt(color2);
buf.putInt(color2); // buf.putInt(color2);
buf.putInt(color2); // buf.putInt(color2);
//
buf.flip(); // buf.flip();
quadColor.updateData(buf); // quadColor.updateData(buf);
} // }
/** /**
* *
@ -252,9 +260,9 @@ public class RenderDeviceJme implements RenderDevice {
Texture2D texture = jmeImage.getTexture(); Texture2D texture = jmeImage.getTexture();
niftyMat.getAdditionalRenderState().setBlendMode(convertBlend()); niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
niftyMat.setColor("Color", ColorRGBA.White); niftyMat.setColor("Color", convertColor(color, tempColor));
niftyMat.setTexture("Texture", texture); niftyMat.setTexture("Texture", texture);
setColor(color); //setColor(color);
float imageWidth = jmeImage.getWidth(); float imageWidth = jmeImage.getWidth();
float imageHeight = jmeImage.getHeight(); float imageHeight = jmeImage.getHeight();
@ -298,9 +306,9 @@ public class RenderDeviceJme implements RenderDevice {
RenderImageJme jmeImage = (RenderImageJme) image; RenderImageJme jmeImage = (RenderImageJme) image;
niftyMat.getAdditionalRenderState().setBlendMode(convertBlend()); niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
niftyMat.setColor("Color", ColorRGBA.White); niftyMat.setColor("Color", convertColor(color, tempColor));
niftyMat.setTexture("Texture", jmeImage.getTexture()); niftyMat.setTexture("Texture", jmeImage.getTexture());
setColor(color); //setColor(color);
quad.clearBuffer(Type.TexCoord); quad.clearBuffer(Type.TexCoord);
quad.setBuffer(quadDefaultTC); 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) { public void renderQuad(int x, int y, int width, int height, Color color) {
if (color.getAlpha() > 0) {
niftyQuadMat.getAdditionalRenderState().setBlendMode(convertBlend()); niftyQuadMat.getAdditionalRenderState().setBlendMode(convertBlend());
niftyQuadMat.setColor("Color", ColorRGBA.White); niftyQuadMat.setColor("Color", convertColor(color, tempColor));
setColor(color);
tempMat.loadIdentity(); tempMat.loadIdentity();
tempMat.setTranslation(x, getHeight() - y, 0); tempMat.setTranslation(x, getHeight() - y, 0);
@ -329,7 +337,7 @@ public class RenderDeviceJme implements RenderDevice {
rm.setWorldMatrix(tempMat); rm.setWorldMatrix(tempMat);
niftyQuadMat.render(quadGeom, rm); niftyQuadMat.render(quadGeom, rm);
}
// System.out.println("renderQuad (Solid)"); // System.out.println("renderQuad (Solid)");
} }
@ -348,15 +356,14 @@ public class RenderDeviceJme implements RenderDevice {
buf.flip(); buf.flip();
quadColor.updateData(buf); quadColor.updateData(buf);
niftyQuadMat.getAdditionalRenderState().setBlendMode(convertBlend()); niftyQuadGradMat.getAdditionalRenderState().setBlendMode(convertBlend());
niftyQuadMat.setColor("Color", ColorRGBA.White);
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);
niftyQuadMat.render(quadGeom, rm); niftyQuadGradMat.render(quadGeom, rm);
// //
// System.out.println("renderQuad (Grad)"); // System.out.println("renderQuad (Grad)");
} }

Loading…
Cancel
Save