Commit 182c5e2e by Philipp Adolf

Split triangles after subdivision

parent 0f5dfb05
......@@ -50,25 +50,36 @@ void Mesh::SubdivEntry::updateIndices() {
}
void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices){
QVector<unsigned int>& Indices_irregular){
f->glGenBuffers(1, &VB_handle);
f->glBindBuffer(GL_ARRAY_BUFFER, VB_handle);
f->glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * Vertices.size(), &Vertices[0], GL_STATIC_DRAW);
this->init(f,VB_handle,Vertices,Indices);
QVector<unsigned int> patches;
this->init(f, VB_handle, Vertices, Indices_irregular, patches);
}
void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,GLuint VB_handle, QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices){
void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches){
this->f = f;
this->VB_handle = VB_handle;
vertices = Vertices;
indices = Indices;
indices = Indices_irregular;
indicesRegular = patches;
qDebug() << "Vertices" << vertices.length();
qDebug() << "Indices irregular" << indices.length();
qDebug() << "Indices patches" << patches.length();
f->glGenBuffers(1, &IB_handle);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_handle);
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * Indices.size(), &Indices[0], GL_STATIC_DRAW);
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indices.size(), &indices[0], GL_STATIC_DRAW);
f->glGenBuffers(1, &IB_Regular);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_Regular);
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * patches.size(), &patches[0], GL_STATIC_DRAW);
}
......@@ -103,10 +114,10 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
}
}
void Mesh::MeshEntry::update(GLuint VB, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices){
void Mesh::MeshEntry::update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches) {
SubdivEntry *entry = new SubdivEntry;
buffers.push_back(std::shared_ptr<SubdivEntry>(entry));
entry->init(f,VB,Vertices,Indices);
entry->init(f, VB_handle, Vertices, Indices_irregular, patches);
}
Mesh::MeshEntry::~MeshEntry()
......
......@@ -70,9 +70,9 @@ public:
QOpenGLFunctions_4_3_Core *f;
void init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices);
QVector<unsigned int>& Indices_irregular);
void init(QOpenGLFunctions_4_3_Core *f,GLuint VB_handle,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices);
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches);
void addRegular(QVector<unsigned int>& Indices);
void updateIndices();
};
......@@ -84,7 +84,7 @@ public:
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);
void update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches);
QString name;
......
......@@ -74,8 +74,18 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
Tables tables = precomputeTables(input);
Result result = runShader(input, tables);
current_mesh->update(result.vb_handle,result.vertex_buffer, tables.index_buffer);
current_mesh->buffers[currentMax+1]->addRegular(tables.index_regular);
QVector<unsigned int> regular;
QVector<unsigned int> irregular;
findRegular(tables.index_buffer, result.vertex_buffer, regular, irregular);
qDebug() << "Indices" << tables.index_buffer.length();
qDebug() << "regular" << regular.length();
qDebug() << "irregular" << irregular.length();
QVector<unsigned int> patches = getPatchIndexBuffer(regular);
qDebug() << "patches" << patches.length();
current_mesh->update(result.vb_handle, result.vertex_buffer, irregular, patches);
//return new Mesh(f, mesh, result.vertex_buffer, tables.index_buffer);
}
......
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