Commit 4ae392f5 by Philipp Adolf

Use separate buffer for rendering irregular triangles in mesh

parent 2d5d8f0f
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
Mesh::SubdivEntry::SubdivEntry() Mesh::SubdivEntry::SubdivEntry()
{ {
VB_handle = 0xFFFFFFFF; VB_handle = 0xFFFFFFFF;
VB_handle_irregular = 0xFFFFFFFF;
IB_irregular_handle = 0xFFFFFFFF; IB_irregular_handle = 0xFFFFFFFF;
IB_regular_handle = 0xFFFFFFFF; IB_regular_handle = 0xFFFFFFFF;
} }
...@@ -39,10 +40,10 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Verti ...@@ -39,10 +40,10 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Verti
f->glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * Vertices.size(), &Vertices[0], GL_STATIC_DRAW); f->glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * Vertices.size(), &Vertices[0], GL_STATIC_DRAW);
QVector<unsigned int> patches; QVector<unsigned int> patches;
this->init(f, VB_handle, Vertices, Indices_irregular, patches); this->init(f, VB_handle, Vertices, Vertices, Indices_irregular, patches);
} }
void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, QVector<Vertex>& Vertices_irregular,
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches){ QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches){
this->f = f; this->f = f;
this->VB_handle = VB_handle; this->VB_handle = VB_handle;
...@@ -52,9 +53,15 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVe ...@@ -52,9 +53,15 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVe
indices_regular = patches; indices_regular = patches;
qCDebug(log_mesh) << "Vertices" << vertices.length(); qCDebug(log_mesh) << "Vertices" << vertices.length();
qCDebug(log_mesh) << "Vertices Irregular" << Vertices_irregular.length();
qCDebug(log_mesh) << "Indices irregular" << indices_irregular.length(); qCDebug(log_mesh) << "Indices irregular" << indices_irregular.length();
qCDebug(log_mesh) << "Indices patches" << patches.length(); qCDebug(log_mesh) << "Indices patches" << patches.length();
f->glGenBuffers(1, &VB_handle_irregular);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VB_handle_irregular);
if(Vertices_irregular.size() != 0)
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Vertex) * Vertices_irregular.size(), &Vertices_irregular[0], GL_STATIC_DRAW);
f->glGenBuffers(1, &IB_irregular_handle); f->glGenBuffers(1, &IB_irregular_handle);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_irregular_handle); f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_irregular_handle);
if(indices_irregular.size() != 0) if(indices_irregular.size() != 0)
...@@ -96,10 +103,10 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice ...@@ -96,10 +103,10 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
} }
} }
void Mesh::MeshEntry::update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches) { void Mesh::MeshEntry::update(GLuint VB_handle, QVector<Vertex>& Vertices,QVector<Vertex>& Vertices_Irregular, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches) {
SubdivEntry *entry = new SubdivEntry; SubdivEntry *entry = new SubdivEntry;
buffers.push_back(std::shared_ptr<SubdivEntry>(entry)); buffers.push_back(std::shared_ptr<SubdivEntry>(entry));
entry->init(f, VB_handle, Vertices, Indices_irregular, patches); entry->init(f, VB_handle, Vertices, Vertices_Irregular,Indices_irregular, patches);
} }
Mesh::MeshEntry::~MeshEntry() Mesh::MeshEntry::~MeshEntry()
...@@ -481,7 +488,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, ...@@ -481,7 +488,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
} }
} else { } else {
if (!entry->indices_irregular.isEmpty()) { if (!entry->indices_irregular.isEmpty()) {
f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle); f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle_irregular);
f->glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); f->glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_irregular_handle); f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_irregular_handle);
......
...@@ -32,11 +32,13 @@ public: ...@@ -32,11 +32,13 @@ public:
SubdivEntry(); SubdivEntry();
~SubdivEntry(); ~SubdivEntry();
GLuint VB_handle; GLuint VB_handle;
GLuint VB_handle_irregular;
GLuint IB_irregular_handle; GLuint IB_irregular_handle;
GLuint IB_regular_handle; GLuint IB_regular_handle;
QVector<Vertex> vertices; QVector<Vertex> vertices;
QVector<Vertex> vertices_irregular;
QVector<unsigned int> indices_irregular; QVector<unsigned int> indices_irregular;
QVector<unsigned int> indices_regular; QVector<unsigned int> indices_regular;
...@@ -44,7 +46,7 @@ public: ...@@ -44,7 +46,7 @@ public:
void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices, void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices_irregular); QVector<unsigned int>& Indices_irregular);
void init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, void init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, QVector<Vertex>& Vertices_irregular,
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches); QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches);
void updateIndices(); void updateIndices();
}; };
...@@ -54,7 +56,7 @@ public: ...@@ -54,7 +56,7 @@ public:
~MeshEntry(); ~MeshEntry();
void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices); void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices);
void update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches); void update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<Vertex>& Vertices_Irregular, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches);
QString name; QString name;
......
...@@ -113,7 +113,7 @@ void Subdivision::subdivide(Mesh *mesh, int level) { ...@@ -113,7 +113,7 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
getPatchIndexBuffer(regular, neighbors, patches); getPatchIndexBuffer(regular, neighbors, patches);
qCDebug(log_subdiv) << "patches" << patches.length(); qCDebug(log_subdiv) << "patches" << patches.length();
current_mesh->update(result.vb_handle, result.vertex_buffer, irregular_ib, patches); current_mesh->update(result.vb_handle, result.vertex_buffer, result.vertex_buffer, irregular_ib, patches);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment