Commit 55d42e89 by Philipp Adolf

Render regular patches without subdivision

Splits original mesh into regular and irregular meshes and renders them separately.
parent 0e9ef934
...@@ -149,7 +149,7 @@ void MainWidget::loadNewMesh(QString path){ ...@@ -149,7 +149,7 @@ void MainWidget::loadNewMesh(QString path){
qDebug()<<"Opening File:"<<path; qDebug()<<"Opening File:"<<path;
mesh = new Mesh(this,path); mesh = new Mesh(this,path);
subdivision->splitRegular(mesh);
} }
void MainWidget::subdivide(int level){ void MainWidget::subdivide(int level){
...@@ -222,7 +222,6 @@ void MainWidget::paintGL(){ ...@@ -222,7 +222,6 @@ void MainWidget::paintGL(){
rot.rotate(time/100.0*36/5,QVector3D(0,1,0)); rot.rotate(time/100.0*36/5,QVector3D(0,1,0));
} }
if(subdivLevel>0){
regularShader->bind(); regularShader->bind();
regularShader->setUniformValue("wireframe",wireframe); regularShader->setUniformValue("wireframe",wireframe);
regularShader->setUniformValue("colorTexture",0); regularShader->setUniformValue("colorTexture",0);
...@@ -233,9 +232,6 @@ void MainWidget::paintGL(){ ...@@ -233,9 +232,6 @@ void MainWidget::paintGL(){
regularShader->release(); regularShader->release();
}
subdivisionShader->bind(); subdivisionShader->bind();
subdivisionShader->setUniformValue("wireframe",wireframe); subdivisionShader->setUniformValue("wireframe",wireframe);
subdivisionShader->setUniformValue("colorTexture",0); subdivisionShader->setUniformValue("colorTexture",0);
......
...@@ -37,6 +37,18 @@ void Mesh::SubdivEntry::addRegular(QVector<unsigned int>& Indices){ ...@@ -37,6 +37,18 @@ void Mesh::SubdivEntry::addRegular(QVector<unsigned int>& Indices){
} }
void Mesh::SubdivEntry::updateIndices() {
f->glDeleteBuffers(1, &IB_handle);
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->glDeleteBuffers(1, &IB_Regular);
f->glGenBuffers(1, &IB_Regular);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_Regular);
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indicesRegular.size(), &indicesRegular[0], GL_STATIC_DRAW);
}
void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices, void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices){ QVector<unsigned int>& Indices){
...@@ -462,15 +474,16 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, ...@@ -462,15 +474,16 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
// qDebug()<<"Render"<<subdivision<<entry->indices; // qDebug()<<"Render"<<subdivision<<entry->indices;
if(regular){ if(regular){
f->glBindBuffer(GL_ARRAY_BUFFER, entries[index].buffers[subdivision-1]->VB_handle); if (!entry->indicesRegular.isEmpty()) {
f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle);
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_Regular); f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_Regular);
f->glPatchParameteri(GL_PATCH_VERTICES, 12); f->glPatchParameteri(GL_PATCH_VERTICES, 12);
f->glDrawElements(GL_PATCHES, entry->indicesRegular.size(), GL_UNSIGNED_INT, 0); f->glDrawElements(GL_PATCHES, entry->indicesRegular.size(), GL_UNSIGNED_INT, 0);
}
} else {
} else{ if (!entry->indices.isEmpty()) {
f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle); f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle);
f->glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); f->glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
...@@ -478,10 +491,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, ...@@ -478,10 +491,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
f->glPatchParameteri(GL_PATCH_VERTICES, 3); f->glPatchParameteri(GL_PATCH_VERTICES, 3);
f->glDrawElements(GL_PATCHES, entry->indices.size(), GL_UNSIGNED_INT, 0); f->glDrawElements(GL_PATCHES, entry->indices.size(), GL_UNSIGNED_INT, 0);
} }
}
} }
void Mesh::findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, QVector3D &max){ void Mesh::findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, QVector3D &max){
......
...@@ -74,7 +74,7 @@ public: ...@@ -74,7 +74,7 @@ public:
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<unsigned int>& Indices); QVector<unsigned int>& Indices);
void addRegular(QVector<unsigned int>& Indices); void addRegular(QVector<unsigned int>& Indices);
void updateIndices();
}; };
struct MeshEntry{ struct MeshEntry{
......
...@@ -12,7 +12,7 @@ void main() ...@@ -12,7 +12,7 @@ void main()
tcPosition[gl_InvocationID] = vPosition[gl_InvocationID]; tcPosition[gl_InvocationID] = vPosition[gl_InvocationID];
float tesselation = subdiv+15; float tesselation = subdiv+1;
gl_TessLevelOuter[0] = tesselation; gl_TessLevelOuter[0] = tesselation;
gl_TessLevelOuter[1] = tesselation; gl_TessLevelOuter[1] = tesselation;
......
...@@ -363,6 +363,31 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -363,6 +363,31 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
return tables; return tables;
} }
void Subdivision::splitRegular(Mesh *mesh) {
Mesh::Node root = mesh->getRootNode();
int first_mesh_index = -1;
if (!root.getFirstMeshIndex(first_mesh_index)) {
qCritical()<<"No mesh found, aborting subdivision";
return;
}
Mesh::MeshEntry *current_mesh = mesh->getMeshEntry(first_mesh_index);
QVector<unsigned int> regular;
QVector<unsigned int> irregular;
findRegular(current_mesh->buffers[0]->indices, current_mesh->buffers[0]->vertices, regular, irregular);
findRegular(current_mesh->buffers[0]->indicesRegular, current_mesh->buffers[0]->vertices, regular, irregular);
QVector<unsigned int> patches = getPatchIndexBuffer(regular);
current_mesh->buffers[0]->indicesRegular = patches;
current_mesh->buffers[0]->indices = irregular;
current_mesh->buffers[0]->updateIndices();
qDebug() << "regular: " << regular.length();
qDebug() << "irregular: " << irregular.length();
}
/** /**
* @brief Subdivision::getPatchIndexBuffer * @brief Subdivision::getPatchIndexBuffer
* Computes an index buffer for the patches. patches are in order from figure 6(a) from the paper: * Computes an index buffer for the patches. patches are in order from figure 6(a) from the paper:
......
...@@ -13,6 +13,7 @@ public: ...@@ -13,6 +13,7 @@ public:
~Subdivision(); ~Subdivision();
void init(); void init();
void splitRegular(Mesh *mesh);
void subdivide(Mesh *mesh, int level); void subdivide(Mesh *mesh, int level);
void setDebugOutbut(bool debug); void setDebugOutbut(bool debug);
......
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