aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-30 05:25:55 +0200
committerSven Gothel <[email protected]>2023-03-30 05:25:55 +0200
commit655993caf745fc31e1d389b660b650b8f8c7d4f5 (patch)
tree02909bb84f1b05676fd7af0e2098deeb930cf44c /src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
parentd959e28119a5a973968d47a988d3dd4b6320db87 (diff)
GraphUI Scene: Add screenshot(..) method for convenience
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
index 5008acd6e..46e75acd5 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
@@ -27,11 +27,13 @@
*/
package com.jogamp.graph.ui.gl;
+import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
+import java.util.Locale;
import com.jogamp.opengl.FPSCounter;
import com.jogamp.opengl.GL;
@@ -57,6 +59,7 @@ import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.Ray;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.util.GLPixelStorageModes;
+import com.jogamp.opengl.util.GLReadBufferUtil;
import com.jogamp.opengl.util.PMVMatrix;
/**
@@ -114,6 +117,8 @@ public final class Scene implements GLEventListener {
private SBCGestureListener sbcGestureListener = null;
private PinchToZoomGesture pinchToZoomGesture = null;
+ final GLReadBufferUtil screenshot;
+
private GLAutoDrawable cDrawable = null;
private static RegionRenderer createRenderer() {
@@ -138,6 +143,7 @@ public final class Scene implements GLEventListener {
}
this.renderer = renderer;
this.sampleCount[0] = 4;
+ this.screenshot = new GLReadBufferUtil(false, false);
}
/** Returns the associated RegionRenderer */
@@ -417,6 +423,7 @@ public final class Scene implements GLEventListener {
shapes.clear();
cDrawable = null;
renderer.destroy(gl);
+ screenshot.dispose(gl);
}
/**
@@ -926,7 +933,7 @@ public final class Scene implements GLEventListener {
* Return a formatted status string containing avg fps and avg frame duration.
* @param glad GLAutoDrawable instance for FPSCounter, its chosen GLCapabilities and its GL's swap-interval
* @param renderModes render modes for {@link Region#getRenderModeString(int)}
- * @param quality the Graph-Curve quality setting
+ * @param quality the Graph-Curve quality setting or -1 to be ignored
* @param dpi the monitor's DPI (vertical preferred)
* @return formatted status string
*/
@@ -944,7 +951,7 @@ public final class Scene implements GLEventListener {
}
final String modeS = Region.getRenderModeString(renderModes);
final GLCapabilitiesImmutable caps = glad.getChosenGLCapabilities();
- final String sampleCountStr1, sampleCountStr2, blendStr;
+ final String sampleCountStr1, sampleCountStr2, qualityStr, blendStr;
if( Region.isVBAA(renderModes) || Region.isMSAA(renderModes) ) {
sampleCountStr1 = "-samples "+getSampleCount();
} else {
@@ -955,14 +962,19 @@ public final class Scene implements GLEventListener {
} else {
sampleCountStr2 = "";
}
+ if( 0 <= quality ) {
+ qualityStr = ", q "+quality;
+ } else {
+ qualityStr = "";
+ }
if( getRenderState().isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED) ) {
blendStr = ", blend";
} else {
blendStr = "";
}
- return String.format("%03.1f/%03.1f fps, %.1f ms/f, vsync %d, dpi %.1f, %s%s%s, q %d%s, a %d",
+ return String.format("%03.1f/%03.1f fps, %.1f ms/f, vsync %d, dpi %.1f, %s%s%s%s%s, a %d",
lfps, tfps, td, glad.getGL().getSwapInterval(), dpi, modeS, sampleCountStr1, sampleCountStr2,
- quality, blendStr, caps.getAlphaBits());
+ qualityStr, blendStr, caps.getAlphaBits());
}
/**
@@ -977,6 +989,27 @@ public final class Scene implements GLEventListener {
return String.format("%03.1f/%03.1f fps, %.1f ms/f", lfps, tfps, td);
}
+ /**
+ * Write current read drawable (screen) to a PNG file.
+ * @see #getScreenshotCount()
+ */
+ public void screenshot(final GL gl, final int renderModes, final String prefix) {
+ final RegionRenderer renderer = getRenderer();
+ final String modeS = Region.getRenderModeString(renderModes);
+ final String filename = String.format((Locale)null, "%s-shot%03d-%03dx%03d-S_%s_%02d.png",
+ prefix, shotCount++, renderer.getWidth(), renderer.getHeight(),
+ modeS, getSampleCount());
+ gl.glFinish(); // just make sure rendering finished ..
+ if(screenshot.readPixels(gl, false)) {
+ screenshot.write(new File(filename));
+ System.err.println("Wrote: "+filename);
+ }
+ }
+ private int shotCount = 0;
+
+ /** Return the number of {@link #screenshot(GL, int, String)}s being taken. */
+ public int getScreenshotCount() { return shotCount; }
+
private static final PMVMatrixSetup defaultPMVMatrixSetup = new PMVMatrixSetup() {
@Override
public void set(final PMVMatrix pmv, final int x, final int y, final int width, final int height) {