Skip to content

Instantly share code, notes, and snippets.

@io7m
Created March 31, 2016 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save io7m/9f715be9440eb020362b66928413735e to your computer and use it in GitHub Desktop.
Save io7m/9f715be9440eb020362b66928413735e to your computer and use it in GitHub Desktop.
Timer queries and clearing
import com.jogamp.common.nio.Buffers;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.DebugGL3;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL3;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLContext;
import com.jogamp.opengl.GLProfile;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
public final class TimerQueries
{
private TimerQueries()
{
}
public static void main(final String[] args)
{
boolean done = false;
final GLProfile pro = GLProfile.get(GLProfile.GL3);
final GLCapabilities caps = new GLCapabilities(pro);
final GLWindow win = GLWindow.create(caps);
win.setVisible(true);
final GLContext ctx = win.getContext();
ctx.makeCurrent();
final IntBuffer timers = Buffers.newDirectIntBuffer(2);
final IntBuffer dbuf = Buffers.newDirectIntBuffer(1);
final LongBuffer lbuf = Buffers.newDirectLongBuffer(1);
final GL3 gl = new DebugGL3((GL3) win.getGL());
gl.glGenQueries(2, timers);
gl.glQueryCounter(timers.get(0), GL3.GL_TIMESTAMP);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glQueryCounter(timers.get(1), GL3.GL_TIMESTAMP);
while (!done) {
done = true;
for (int index = 0; index < timers.capacity(); ++index) {
gl.glGetQueryObjectiv(
timers.get(0), GL3.GL_QUERY_RESULT_AVAILABLE, dbuf);
done = done && dbuf.get(0) == 1;
gl.glGetQueryObjectiv(
timers.get(1), GL3.GL_QUERY_RESULT_AVAILABLE, dbuf);
done = done && dbuf.get(0) == 1;
}
}
final long time_start;
final long time_end;
final long time;
gl.glGetQueryObjecti64v(timers.get(0), GL3.GL_QUERY_RESULT, lbuf);
time_start = lbuf.get(0);
gl.glGetQueryObjecti64v(timers.get(1), GL3.GL_QUERY_RESULT, lbuf);
time_end = lbuf.get(0);
time = time_end - time_start;
System.out.printf("timer: %fms\n", Double.valueOf(time / 1000000.0));
ctx.release();
win.destroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment