aboutsummaryrefslogtreecommitdiffstats
path: root/src/demos
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-01-22 05:53:34 +0100
committerSven Göthel <[email protected]>2024-01-22 05:53:34 +0100
commita883f3e2e1563736df32573141fd5119f0678c92 (patch)
tree647dd5b5ec8fcd236406a27ed38d68eda0de5c7a /src/demos
parentffe4e670c9d35121934c6f3c95067d9c18aee386 (diff)
Bug 1490 - GraphUI Group: Resolve Performance Issues with Shape Mv Transform -> PMVMatrix4f
Shape.setTransformMv() is called for each renderer frame and for each shape, involving 6 Matrix4f.mul() and set*() operations. Since mutation of shape's position, rotation or scale is less frequent than rendering one frame (for all shapes), it is more efficient to maintain a local Matrix4f and update it on such single mutations. Rendering then only needs to perform one Matrix4f.mul() operation using this internal matrix. +++ Also changes name from setTransformMv(PMVMatrix4f) to applyMatToMv(PMVMatrix4f), as its name might be misleading.
Diffstat (limited to 'src/demos')
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UIGraphDemoU01a.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java12
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java11
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java6
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java6
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo01.java6
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java6
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java4
11 files changed, 33 insertions, 26 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java
index c010c4f07..fa2ae7f3b 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java
@@ -371,7 +371,7 @@ public class FontView01 {
final Vec3f rot = new Vec3f(e.getRotation()).scale( FloatUtil.PI / 180.0f );
// swap axis for onscreen rotation matching natural feel
final float tmp = rot.x(); rot.setX( rot.y() ); rot.setY( tmp );
- mainView.getRotation().rotateByEuler( rot.scale( 2f ) );
+ mainView.setRotation( mainView.getRotation().rotateByEuler( rot.scale( 2f ) ) );
e.setConsumed(true);
}
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIGraphDemoU01a.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIGraphDemoU01a.java
index 0788ab69e..297827aac 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIGraphDemoU01a.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIGraphDemoU01a.java
@@ -307,7 +307,7 @@ public class UIGraphDemoU01a {
}
if( !textOnly ) {
pmv.pushMv();
- shape.setTransformMv(pmv);
+ shape.applyMatToMv(pmv);
shape.draw(gl, renderer);
if( onceAtDisplay ) {
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java
index 43f403e8b..daea00d4f 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java
@@ -137,7 +137,7 @@ public class UILayoutBox01 {
final Vec3f rot = new Vec3f(e.getRotation()).scale( FloatUtil.PI / 180.0f );
// swap axis for onscreen rotation matching natural feel
final float tmp = rot.x(); rot.setX( rot.y() ); rot.setY( tmp );
- shape.getRotation().rotateByEuler( rot.scale( 2f ) );
+ shape.setRotation( shape.getRotation().rotateByEuler( rot.scale( 2f ) ) );
}
};
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java
index e1558e7b3..c1b041b42 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java
@@ -136,7 +136,7 @@ public class UILayoutGrid01 {
final Vec3f rot = new Vec3f(e.getRotation()).scale( FloatUtil.PI / 180.0f );
// swap axis for onscreen rotation matching natural feel
final float tmp = rot.x(); rot.setX( rot.y() ); rot.setY( tmp );
- shape.getRotation().rotateByEuler( rot.scale( 2f ) );
+ shape.setRotation( shape.getRotation().rotateByEuler( rot.scale( 2f ) ) );
}
};
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java
index a66f5af56..f527226c3 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java
@@ -39,6 +39,7 @@ import com.jogamp.graph.ui.Shape;
import com.jogamp.graph.ui.shapes.Button;
import com.jogamp.graph.ui.shapes.GLButton;
import com.jogamp.math.FloatUtil;
+import com.jogamp.math.Quaternion;
import com.jogamp.math.geom.AABBox;
import com.jogamp.math.util.PMVMatrix4f;
import com.jogamp.newt.event.MouseEvent;
@@ -77,8 +78,12 @@ public class UISceneDemo01b {
System.err.println("Font: "+font.getFullFamilyName());
final Shape shape = new Button(options.renderModes, font, "L", 1/8f, 1/8f/2.5f).setPerp(); // normalized: 1 is 100% surface size (width and/or height)
- shape.getRotation().rotateByAngleX(FloatUtil.PI);
- shape.getRotation().rotateByAngleY(FloatUtil.PI);
+ {
+ final Quaternion q = shape.getRotation().copy();
+ q.rotateByAngleX(FloatUtil.PI);
+ q.rotateByAngleY(FloatUtil.PI);
+ shape.setRotation(q);
+ }
System.err.println("Shape bounds "+shape.getBounds(reqCaps.getGLProfile()));
System.err.println("Shape "+shape);
@@ -168,9 +173,10 @@ public class UISceneDemo01b {
} else {
shape.getRotation().rotateByAngleY(rad);
}
+ shape.updateMat();
System.err.println("Shape "+shape);
final PMVMatrix4f pmv = new PMVMatrix4f();
- shape.setTransformMv(pmv);
+ shape.applyMatToMv(pmv);
System.err.println("Shape "+pmv);
}
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java
index 10ddf8c78..fdec041d1 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java
@@ -244,7 +244,7 @@ public class UISceneDemo03 {
if( showAnimBox ) {
animGroup.scale(0.85f, 0.85f, 1f);
animGroup.move(-sceneBox.getWidth()/2f*0.075f, 0f, 0f);
- animGroup.getRotation().rotateByAngleY(0.1325f);
+ animGroup.setRotation( animGroup.getRotation().rotateByAngleY(0.1325f) );
} else {
animGroup.scale(1.0f, 1.0f, 1f);
}
@@ -428,7 +428,7 @@ public class UISceneDemo03 {
sd.shape.moveTo( sd.startPos );
};
refShape.setColor(1.0f, 0.0f, 0.0f, 0.9f);
- refShape.getRotation().rotateByAngleZ(FloatUtil.QUARTER_PI);
+ refShape.setRotation( refShape.getRotation().rotateByAngleZ(FloatUtil.QUARTER_PI) );
dynAnimSet[2].addShape(animGroup, refShape, shapeSetup);
{
final Shape s = new Rectangle(options.renderModes, size2, size2*yscale, sceneBox.getWidth() * 0.0025f ).validate(hasGLP);
@@ -571,7 +571,8 @@ public class UISceneDemo03 {
} else if( euler.y() <= -FloatUtil.HALF_PI ) {
dir = 1f;
}
- animGroup.getRotation().rotateByAngleY( frame_velocity * dir );
+ rot.rotateByAngleY( frame_velocity * dir );
+ animGroup.setRotation(rot);
}
final String text = String.format("%s, v %.1f mm/s, r %.3f rad/s",
scene.getStatusText(drawable, options.renderModes, dpiV), velocity * 1e3f, ang_velo);
@@ -732,7 +733,7 @@ public class UISceneDemo03 {
* @param axis 0 for X-, 1 for Y- and 2 for Z-axis
*/
public static void rotateShape(final Shape shape, float angle, final int axis) {
- final Quaternion rot = shape.getRotation();
+ final Quaternion rot = shape.getRotation().copy();
final Vec3f euler = rot.toEuler(new Vec3f());
final Vec3f eulerOld = euler.copy();
@@ -756,7 +757,7 @@ public class UISceneDemo03 {
case 2: euler.add(0, 0, angle); break;
}
System.err.println("Rot: angleDelta "+angle+" (eps "+eps+"): "+eulerOld+" -> "+euler);
- rot.setFromEuler(euler);
+ shape.setRotation( rot.setFromEuler(euler) );
}
static class MyGLMediaEventListener implements GLMediaEventListener {
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java
index 5551d4701..7292b05f9 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java
@@ -316,7 +316,7 @@ public class UISceneDemo20 implements GLEventListener {
sl.addAll(buttonsLeft.getShapes());
sl.addAll(buttonsRight.getShapes());
for(final Shape s : sl) {
- s.getRotation().rotateByEuler( angdeg );
+ s.setRotation( s.getRotation().rotateByEuler( angdeg ) );
}
}
@@ -355,7 +355,7 @@ public class UISceneDemo20 implements GLEventListener {
for(final Shape s : sl) {
if( s instanceof BaseButton ) {
final BaseButton b = (BaseButton)s;
- b.getRotation().setIdentity();
+ b.setRotation( b.getRotation().setIdentity() );
b.setCorner(BaseButton.ROUND_CORNER);
if( b instanceof Button ) {
((Button)b).setSpacing(Button.DEFAULT_SPACING_X, Button.DEFAULT_SPACING_Y);
@@ -1177,7 +1177,7 @@ public class UISceneDemo20 implements GLEventListener {
final Vec3f rot = new Vec3f(e.getRotation()).scale( FloatUtil.PI / 180.0f );
// swap axis for onscreen rotation matching natural feel
final float tmp = rot.x(); rot.setX( rot.y() ); rot.setY( tmp );
- shapeEvent.shape.getRotation().rotateByEuler( rot.scale( 2f ) );
+ shapeEvent.shape.setRotation( shapeEvent.shape.getRotation().rotateByEuler( rot.scale( 2f ) ) );
}
};
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java
index c0d8babe1..591d57e97 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java
@@ -256,7 +256,7 @@ public class UIShapeClippingDemo00 implements GLEventListener {
final Vec3f rot = new Vec3f(e.getRotation()).scale( FloatUtil.PI / 180.0f );
// swap axis for onscreen rotation matching natural feel
final float tmp = rot.x(); rot.setX( rot.y() ); rot.setY( tmp );
- clipRect.getRotation().rotateByEuler( rot.scale( 2f ) );
+ clipRect.setRotation( clipRect.getRotation().rotateByEuler( rot.scale( 2f ) ) );
}
});
}
@@ -292,13 +292,13 @@ public class UIShapeClippingDemo00 implements GLEventListener {
final PMVMatrix4f pmv = renderer.getMatrix();
pmv.pushMv();
{
- clipRect.setTransformMv(pmv);
+ clipRect.applyMatToMv(pmv);
final Frustum clipFrustumMv = new Cube( clipRect.getBounds() ).transform( pmv.getMv() ).updateFrustumPlanes(new Frustum());
renderer.setClipFrustum( clipFrustumMv );
// System.err.println("Clipping "+renderer.getClipBBox());
if( null != shape && shape.isVisible() ) {
pmv.pushMv();
- shape.setTransformMv(pmv);
+ shape.applyMatToMv(pmv);
shape.draw(gl, renderer);
pmv.popMv();
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo01.java
index 35de00965..bcf9dfe63 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo01.java
@@ -140,7 +140,7 @@ public class UIShapeClippingDemo01 {
final Vec3f rot = new Vec3f(e.getRotation()).scale( FloatUtil.PI / 180.0f );
// swap axis for onscreen rotation matching natural feel
final float tmp = rot.x(); rot.setX( rot.y() ); rot.setY( tmp );
- shapeEvent.shape.getRotation().rotateByEuler( rot.scale( 2f ) );
+ shapeEvent.shape.setRotation( shapeEvent.shape.getRotation().rotateByEuler( rot.scale( 2f ) ) );
}
});
scene.addShape(contentBox);
@@ -154,14 +154,14 @@ public class UIShapeClippingDemo01 {
final PMVMatrix4f pmv = renderer.getMatrix();
pmv.pushMv();
- contentBox.setTransformMv(pmv);
+ contentBox.applyMatToMv(pmv);
{
final AABBox box = contentBox.getBounds();
final Cube cube = tempC00.set(box);
final Frustum frustumCbMv = tempC01.set(cube).transform(pmv.getMv()).updateFrustumPlanes(new Frustum());
pmv.pushMv();
- shape.setTransformMv(pmv);
+ shape.applyMatToMv(pmv);
{
final AABBox shapeBox = shape.getBounds();
final Cube shapedMv = tempC10.set(shapeBox).transform(pmv.getMv());
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java
index cca86df68..834686bc2 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java
@@ -236,7 +236,7 @@ public class UIShapeDemo01 implements GLEventListener {
private void drawShape(final GL2ES2 gl, final RegionRenderer renderer, final Shape shape) {
final PMVMatrix4f pmv = renderer.getMatrix();
pmv.pushMv();
- shape.setTransformMv(pmv);
+ shape.applyMatToMv(pmv);
shape.draw(gl, renderer);
if( once ) {
System.err.println("draw.0: "+shape);
@@ -392,7 +392,7 @@ public class UIShapeDemo01 implements GLEventListener {
{
pmv.pushMv();
- button.setTransformMv(pmv);
+ button.applyMatToMv(pmv);
System.err.println("\n\nButton: "+button);
final Vec3f objPos = button.winToShapeCoord(pmv, viewport, glWinX, glWinY, new Vec3f());
@@ -409,7 +409,7 @@ public class UIShapeDemo01 implements GLEventListener {
}
{
pmv.pushMv();
- crossHair.setTransformMv(pmv);
+ crossHair.applyMatToMv(pmv);
final Vec3f objPosC = crossHair.getBounds().getCenter();
System.err.println("\n\nCrossHair: "+crossHair);
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java
index a131c0fd5..bd36b7509 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java
@@ -261,7 +261,7 @@ public class UITypeDemo01 implements GLEventListener {
private void drawShape(final GL2ES2 gl, final PMVMatrix4f pmv, final RegionRenderer renderer, final Shape shape) {
pmv.pushMv();
- shape.setTransformMv(pmv);
+ shape.applyMatToMv(pmv);
shape.draw(gl, renderer);
pmv.popMv();
}
@@ -466,7 +466,7 @@ public class UITypeDemo01 implements GLEventListener {
{
pmv.pushMv();
- crossHair.setTransformMv(pmv);
+ crossHair.applyMatToMv(pmv);
final Vec3f objPosC = crossHair.getBounds().getCenter();
System.err.println("\n\nCrossHair: "+crossHair);