17 gl->glGenVertexArrays(1, &vao);
18 gl->glGenBuffers(1, &vbo);
20 gl->glBindVertexArray(vao);
21 gl->glBindBuffer(GL_ARRAY_BUFFER, vbo);
22 gl->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
sizeof(glm::vec3), (
void*)0);
23 gl->glEnableVertexAttribArray(0);
24 gl->glBindVertexArray(0);
28 traceShader =
ResourceManager::loadShader(
"assets/shaders/debug/pathtrace.vert",
"assets/shaders/debug/pathtrace.frag",
"pathtrace");
38 if (!traceShader)
return;
41 const auto& objects = sceneManager->
getObjects();
45 gl->glBindVertexArray(vao);
47 const GLboolean depthWasEnabled = gl->glIsEnabled(GL_DEPTH_TEST);
48 if (depthWasEnabled) {
49 gl->glDisable(GL_DEPTH_TEST);
53 gl->glGetFloatv(GL_LINE_WIDTH, &oldLineWidth);
55 gl->glLineWidth(kTraceLineWidth);
57 std::vector<glm::vec3> points;
58 for (
const auto& objPtr : objects) {
65 if (snapshots.size() < kMinTrailPointCount)
return;
67 const float latestTime = snapshots.back().time;
68 const float startTime = latestTime - this->timeWindow;
72 const auto startIt = std::lower_bound(snapshots.begin(), snapshots.end(), startTime,
74 return snapshot.time < time;
76 int startIdx =
static_cast<int>(std::distance(snapshots.begin(), startIt));
77 int totalCount =
static_cast<int>(snapshots.size()) - startIdx;
78 if (totalCount < kMinTrailPointCount) {
79 startIdx = std::max(0,
static_cast<int>(snapshots.size()) - kMinTrailPointCount);
80 totalCount =
static_cast<int>(snapshots.size()) - startIdx;
82 const int stride = std::max(1, totalCount / kMaxTrailPointsPerObject);
83 points.reserve(
static_cast<size_t>(std::min(totalCount, kMaxTrailPointsPerObject + 1)));
85 int lastDrawnIndex = -1;
86 for (
int i = startIdx; i < static_cast<int>(snapshots.size()); i += stride) {
87 points.push_back(snapshots[
static_cast<size_t>(i)].position - renderOrigin);
90 if (lastDrawnIndex !=
static_cast<int>(snapshots.size()) - 1) {
91 points.push_back(snapshots.back().position - renderOrigin);
94 if (points.size() < kMinTrailPointCount)
return;
96 this->gl->glBindBuffer(GL_ARRAY_BUFFER, this->vbo);
97 this->gl->glBufferData(GL_ARRAY_BUFFER, points.size() *
sizeof(glm::vec3), points.data(), GL_DYNAMIC_DRAW);
99 this->gl->glDrawArrays(GL_LINE_STRIP, 0,
static_cast<GLsizei
>(points.size()));
103 gl->glBindVertexArray(0);
104 gl->glLineWidth(oldLineWidth);
105 if (depthWasEnabled) {
106 gl->glEnable(GL_DEPTH_TEST);
void withFrames(BodyLock lock, F &&fn) const