clojure-gamedev

euccastro 2020-07-24T23:30:33.035600Z

I'm trying to measure the frame time, for the purposes of getting a sense of how close I'm getting to using up my time budget, in a clojure LWJGL project (based upon https://github.com/rogerallen/hello_lwjgl, but updated to LWJGL version 3.2.3). This is my main loop:

(defn main-loop [^Histogram histogram]
  (loop [frame-t0 nil]
    (update-globals)
    (draw)
    (when frame-t0
      (.recordValue histogram (- (get-time) frame-t0)))
    (GLFW/glfwSwapBuffers (:window @globals))
    ;;(GL11/glClear (bit-or GL11/GL_COLOR_BUFFER_BIT  GL11/GL_DEPTH_BUFFER_BIT GL11/GL_STENCIL_BUFFER_BIT))
    (GLFW/glfwPollEvents)
    (when-not (GLFW/glfwWindowShouldClose (:window @globals))
      (recur (get-time))))
  (.outputPercentileDistribution histogram System/out 1000000.0))
where Histogram is this class: https://github.com/HdrHistogram/HdrHistogram, tl;dr: something that keeps track of the recorded times and can summarize them for me at the end, and for (get-time) I tried (System/nanoTime) and (GLFW/glfwGetTime) with the same results as far as this question is concerned. Also, the fact that I'm excluding the GLFW/glfwPollEvents call from my measurements is a temporary experiment that doesn't matter for this purpose either. My problem was that the time spent waiting for vsync was included in these measurements despite my attempts to exclude it. The only thing that worked for me is the line that is commented above (i.e., do some drawing op before getting the start time. i.e., it would seem like GLFW/glfwSwapBuffers returns before the vsync wait, but any further OpenGL drawing call will block until vsync is done. Is this expected behavior? Am I missing anything? In any event, I thought I'd leave this hint here should anyone stumble into the same problem.

euccastro 2020-07-24T23:38:27.037300Z

BTW, I figured out that the vsync wait was getting included in my measurements by changing the glfwSwapInterval from 1 to 10 and checking that measured times would indeed grow 10x as well