diff --git a/examples/50-shadertoy/main.cpp b/examples/50-shadertoy/main.cpp index 37169a0ff8728a912c113dcfc78e64a2201c6b11..dd5a519c44a03e0072a63cb05450f1750cb85642 100644 --- a/examples/50-shadertoy/main.cpp +++ b/examples/50-shadertoy/main.cpp @@ -397,8 +397,6 @@ int render(GLFWwindow* window, << "ns fps: " << (1e9 / renderTime) << " mpx/s: " << (contextConfig.width * contextConfig.height / (renderTime / 1e3)) << std::endl; - - state.V<shadertoy::iTimeDelta>() = renderTime / 1e9; } // Buffer swapping diff --git a/src/RenderContext.cpp b/src/RenderContext.cpp index 99d92bc5f061afd9d726b0928310d925e3ac2206..a637f7316c2fb1dff005c6c860f5c735cc629fd8 100644 --- a/src/RenderContext.cpp +++ b/src/RenderContext.cpp @@ -101,6 +101,7 @@ void RenderContext::Initialize() { // Initialize constant uniforms state.V<iResolution>() = glm::vec3(config.width, config.height, 1.0f); + // Note that this will be overriden once query measurements are available state.V<iTimeDelta>() = 1.0f / (float) config.targetFramerate; state.V<iFrameRate>() = (float) config.targetFramerate; diff --git a/src/ToyBuffer.cpp b/src/ToyBuffer.cpp index 935d9db120f20184bd063eadd0187e4db8d7826e..eac6e9d4a84d004458c4966e90e3f64e3d810906 100644 --- a/src/ToyBuffer.cpp +++ b/src/ToyBuffer.cpp @@ -144,6 +144,18 @@ void ToyBuffer::Render() resolutions[i][2] = 1.0f; } + // Try to set iTimeDelta + GLint available = 0; + timeDeltaQuery.GetObjectiv(GL_QUERY_RESULT_AVAILABLE, &available); + if (available) + { + // Result available, set uniform value + GLuint64 timeDelta; + timeDeltaQuery.GetObjectui64v(GL_QUERY_RESULT, &timeDelta); + static_pointer_cast<ShaderInputsType::BoundInputs>(boundInputs[0]) + ->State.V<iTimeDelta>() = timeDelta / 1e9; + } + // Set all uniforms for (auto &inputs : boundInputs) inputs->Apply();