diff --git a/zenovis/src/bate/FrameBufferPicker.cpp b/zenovis/src/bate/FrameBufferPicker.cpp index 5bdd801bdd..c414589810 100644 --- a/zenovis/src/bate/FrameBufferPicker.cpp +++ b/zenovis/src/bate/FrameBufferPicker.cpp @@ -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 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 ----- @@ -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 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)); @@ -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 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));