Skip to content

Commit

Permalink
Merge pull request #1897 from zenustech/fix-picker
Browse files Browse the repository at this point in the history
fix-picker
  • Loading branch information
ShuliangLu authored Apr 18, 2024
2 parents 7269ba5 + 3009aef commit 8211282
Showing 1 changed file with 57 additions and 9 deletions.
66 changes: 57 additions & 9 deletions zenovis/src/bate/FrameBufferPicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,25 @@ struct FrameBufferPicker : IPicker {
empty_and_offset_shader->set_uniform("offset", -0.00001f);
scene->camera->set_program_uniforms(empty_and_offset_shader);

auto tri_count = prim->tris.size();
ebo->bind_data(prim->tris.data(), tri_count * sizeof(prim->tris[0]));
CHECK_GL(glDrawElements(GL_TRIANGLES, tri_count * 3, GL_UNSIGNED_INT, 0));
// draw prim
if (prim->tris.size()) {
ebo->bind_data(prim->tris.data(), prim->tris.size() * sizeof(prim->tris[0]));
CHECK_GL(glDrawElements(GL_TRIANGLES, prim->tris.size() * 3, GL_UNSIGNED_INT, 0));
}
else if (prim->polys.size()) {
std::vector<vec3i> tris;
for (auto [start, len]: prim->polys) {
for (auto i = 2; i < len; i++) {
tris.emplace_back(
prim->loops[start],
prim->loops[start + i - 1],
prim->loops[start + i]
);
}
}
ebo->bind_data(tris.data(), tris.size() * sizeof(tris[0]));
CHECK_GL(glDrawElements(GL_TRIANGLES, tris.size() * 3, GL_UNSIGNED_INT, 0));
}
ebo->unbind();

// ----- disable depth test -----
Expand Down Expand Up @@ -414,9 +430,25 @@ struct FrameBufferPicker : IPicker {
// ----- draw object to cover invisible lines -----
empty_shader->use();
scene->camera->set_program_uniforms(empty_shader);
auto tri_count = prim->tris.size();
ebo->bind_data(prim->tris.data(), tri_count * sizeof(prim->tris[0]));
CHECK_GL(glDrawElements(GL_TRIANGLES, tri_count * 3, GL_UNSIGNED_INT, 0));
// draw prim
if (prim->tris.size()) {
ebo->bind_data(prim->tris.data(), prim->tris.size() * sizeof(prim->tris[0]));
CHECK_GL(glDrawElements(GL_TRIANGLES, prim->tris.size() * 3, GL_UNSIGNED_INT, 0));
}
else if (prim->polys.size()) {
std::vector<vec3i> tris;
for (auto [start, len]: prim->polys) {
for (auto i = 2; i < len; i++) {
tris.emplace_back(
prim->loops[start],
prim->loops[start + i - 1],
prim->loops[start + i]
);
}
}
ebo->bind_data(tris.data(), tris.size() * sizeof(tris[0]));
CHECK_GL(glDrawElements(GL_TRIANGLES, tris.size() * 3, GL_UNSIGNED_INT, 0));
}
ebo->unbind();
// ----- disable depth test -----
CHECK_GL(glDisable(GL_DEPTH_TEST));
Expand All @@ -433,9 +465,25 @@ struct FrameBufferPicker : IPicker {
prim_shader->use();
scene->camera->set_program_uniforms(prim_shader);
CHECK_GL(glUniform1ui(glGetUniformLocation(prim_shader->pro, "gObjectIndex"), id + 1));
auto tri_count = prim->tris.size();
ebo->bind_data(prim->tris.data(), tri_count * sizeof(prim->tris[0]));
CHECK_GL(glDrawElements(GL_TRIANGLES, tri_count * 3, GL_UNSIGNED_INT, 0));
// draw prim
if (prim->tris.size()) {
ebo->bind_data(prim->tris.data(), prim->tris.size() * sizeof(prim->tris[0]));
CHECK_GL(glDrawElements(GL_TRIANGLES, prim->tris.size() * 3, GL_UNSIGNED_INT, 0));
}
else if (prim->polys.size()) {
std::vector<vec3i> tris;
for (auto [start, len]: prim->polys) {
for (auto i = 2; i < len; i++) {
tris.emplace_back(
prim->loops[start],
prim->loops[start + i - 1],
prim->loops[start + i]
);
}
}
ebo->bind_data(tris.data(), tris.size() * sizeof(tris[0]));
CHECK_GL(glDrawElements(GL_TRIANGLES, tris.size() * 3, GL_UNSIGNED_INT, 0));
}
ebo->unbind();
// ----- disable depth test -----
CHECK_GL(glDisable(GL_DEPTH_TEST));
Expand Down

0 comments on commit 8211282

Please sign in to comment.