@@ -1798,11 +1798,6 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
17981798 }
17991799
18001800 // populate the vertex/index buffers
1801- struct simple_vertex_t
1802- {
1803- qvec3f pos;
1804- };
1805-
18061801 {
18071802 QOpenGLVertexArrayObject::Binder vaoBinder (&m_frustumVao);
18081803
@@ -1886,20 +1881,13 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
18861881 fs::path portalFile = fs::path (file.toStdString ()).replace_extension (" .prt" );
18871882
18881883 if (fs::exists (portalFile)) {
1889- QOpenGLVertexArrayObject::Binder portalVaoBinder (&m_portalVao);
1890-
18911884 auto prt = LoadPrtFile (portalFile, bsp.loadversion );
18921885 std::vector<GLuint> indices;
18931886 std::vector<simple_vertex_t > points;
18941887
1895- [[maybe_unused]] size_t total_points = 0 ;
1896- [[maybe_unused]] size_t total_indices = 0 ;
18971888 size_t current_index = 0 ;
18981889
18991890 for (auto &portal : prt.portals ) {
1900- total_points += portal.winding .size ();
1901- total_indices += portal.winding .size () + 1 ;
1902-
19031891 for (auto &pt : portal.winding ) {
19041892 indices.push_back (current_index++);
19051893 points.push_back (simple_vertex_t {qvec3f{pt}});
@@ -1908,22 +1896,7 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
19081896 indices.push_back ((GLuint)-1 );
19091897 }
19101898
1911- // upload index buffer
1912- m_portalIndexBuffer.create ();
1913- m_portalIndexBuffer.bind ();
1914- m_portalIndexBuffer.allocate (indices.data (), indices.size () * sizeof (indices[0 ]));
1915-
1916- num_portal_indices = indices.size ();
1917-
1918- // upload vertex buffer
1919- m_portalVbo.create ();
1920- m_portalVbo.bind ();
1921- m_portalVbo.allocate (points.data (), points.size () * sizeof (points[0 ]));
1922-
1923- // positions
1924- glEnableVertexAttribArray (0 /* attrib */ );
1925- glVertexAttribPointer (
1926- 0 /* attrib */ , 3 , GL_FLOAT, GL_FALSE, sizeof (simple_vertex_t ), (void *)offsetof (simple_vertex_t , pos));
1899+ uploadPortalVAO (points, indices);
19271900 }
19281901
19291902 // load decompiled hulls
@@ -2168,6 +2141,28 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
21682141 update ();
21692142}
21702143
2144+ void GLView::uploadPortalVAO (const std::vector<simple_vertex_t > &points, const std::vector<GLuint> &indices)
2145+ {
2146+ QOpenGLVertexArrayObject::Binder portalVaoBinder (&m_portalVao);
2147+
2148+ // upload index buffer
2149+ m_portalIndexBuffer.create ();
2150+ m_portalIndexBuffer.bind ();
2151+ m_portalIndexBuffer.allocate (indices.data (), indices.size () * sizeof (indices[0 ]));
2152+
2153+ num_portal_indices = indices.size ();
2154+
2155+ // upload vertex buffer
2156+ m_portalVbo.create ();
2157+ m_portalVbo.bind ();
2158+ m_portalVbo.allocate (points.data (), points.size () * sizeof (points[0 ]));
2159+
2160+ // positions
2161+ glEnableVertexAttribArray (0 /* attrib */ );
2162+ glVertexAttribPointer (
2163+ 0 /* attrib */ , 3 , GL_FLOAT, GL_FALSE, sizeof (simple_vertex_t ), (void *)offsetof (simple_vertex_t , pos));
2164+ }
2165+
21712166void GLView::uploadFaceVAO (const std::vector<vertex_t > &verts, const std::vector<uint32_t > &indexBuffer)
21722167{
21732168 QOpenGLVertexArrayObject::Binder vaoBinder (&m_vao);
0 commit comments