diff options
author | Sven Gothel <[email protected]> | 2023-04-08 20:23:09 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-04-08 20:23:09 +0200 |
commit | 003eb8ca1f296f287dc3d224fa19781705e10dd9 (patch) | |
tree | 22e15bd8f0a58fd3a807dcb67b416d4d13d7e2b4 /src | |
parent | fc93a9aca67d0c4a11f70601743f58723a7fddd3 (diff) |
PMVMatrix: Expose temporary storage (w/o side-effects) for efficiency; GraphUI.Shape: Efficiently reuse matPMv and temporary PMVMatrix storage
Reuse PMv in Shape.getSurfaceSize() and Shape.winToShapeCoord(),
for the latter we invert the reused PMv for mapWinToObj (i.e. UnProject).
Diffstat (limited to 'src')
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Shape.java | 16 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java | 43 |
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> |