aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Shape.java16
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java43
2 files changed, 54 insertions, 5 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
index befee55c3..0f6b0ec28 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
@@ -43,6 +43,7 @@ import com.jogamp.newt.event.PinchToZoomGesture;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.MouseListener;
import com.jogamp.opengl.math.FloatUtil;
+import com.jogamp.opengl.math.Matrix4f;
import com.jogamp.opengl.math.Quaternion;
import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.Vec2f;
@@ -526,8 +527,10 @@ public abstract class Shape {
final Vec3f high = box.getHigh();
final Vec3f low = box.getLow();
- if( pmv.gluProject(high, viewport, winCoordHigh) ) {
- if( pmv.gluProject(low, viewport, winCoordLow) ) {
+ // Efficiently reuse matPMv and temporary PMVMatrix storage
+ final Matrix4f matPMv = pmv.mulPMvMat(pmv.getTmp1Mat());
+ if( Matrix4f.mapObjToWin(high, matPMv, viewport, winCoordHigh) ) {
+ if( Matrix4f.mapObjToWin(low, matPMv, viewport, winCoordLow) ) {
surfaceSize[0] = (int)Math.abs(winCoordHigh.x() - winCoordLow.x());
surfaceSize[1] = (int)Math.abs(winCoordHigh.y() - winCoordLow.y());
return surfaceSize;
@@ -703,9 +706,14 @@ public abstract class Shape {
public Vec3f winToShapeCoord(final PMVMatrix pmv, final Recti viewport, final int glWinX, final int glWinY, final Vec3f objPos) {
final Vec3f ctr = box.getCenter();
- if( pmv.gluProject(ctr, viewport, objPos) ) {
+ // Efficiently reuse matPMv and temporary PMVMatrix storage
+ final Matrix4f matPMv = pmv.mulPMvMat(pmv.getTmp1Mat());
+ if( Matrix4f.mapObjToWin(ctr, matPMv, viewport, objPos) ) {
final float winZ = objPos.z();
- if( pmv.gluUnProject(glWinX, glWinY, winZ, viewport, objPos) ) {
+ if( !matPMv.invert() ) {
+ return null;
+ }
+ if( Matrix4f.mapWinToObj(glWinX, glWinY, winZ, matPMv, viewport, objPos, pmv.getTmp2Mat()) ) {
return objPos;
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
index 6c0a6c351..0cba41f65 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
@@ -271,8 +271,49 @@ public final class PMVMatrix implements GLMatrixFunc {
}
//
- // Matrix4f access as well as their SyncedBuffer counterpart SyncedMatrix and SyncedMatrices
+ // Temporary storage access for efficiency
//
+
+ /**
+ * Return the first temporary Matrix4f exposed to be reused for efficiency.
+ * <p>
+ * Temporary storage is only used by this class within single method calls,
+ * hence has no side-effects.
+ * </p>
+ */
+ public final Matrix4f getTmp1Mat() { return mat4Tmp1; }
+
+ /**
+ * Return the second temporary Matrix4f exposed to be reused for efficiency.
+ * <p>
+ * Temporary storage is only used by this class within single method calls,
+ * hence has no side-effects.
+ * </p>
+ */
+ public final Matrix4f getTmp2Mat() { return mat4Tmp2; }
+
+ /**
+ * Return the first temporary Vec3f exposed to be reused for efficiency.
+ * <p>
+ * Temporary storage is only used by this class within single method calls,
+ * hence has no side-effects.
+ * </p>
+ */
+ public final Vec3f getTmp1Vec3f() { return vec3Tmp1; }
+
+ /**
+ * Return the first temporary Vec4f exposed to be reused for efficiency.
+ * <p>
+ * Temporary storage is only used by this class within single method calls,
+ * hence has no side-effects.
+ * </p>
+ */
+ public final Vec4f getTmp1Vec4f() { return vec4Tmp1; }
+
+ //
+ // Regular Matrix4f access as well as their SyncedBuffer counterpart SyncedMatrix and SyncedMatrices
+ //
+
/**
* Returns the {@link GLMatrixFunc#GL_TEXTURE_MATRIX texture matrix} (T).
* <p>