Commit bf238c0c by Kai Westerkamp

added UI

some changes to Mesh entry handle
parent 25a99649
...@@ -128,10 +128,20 @@ void MainWidget::loadNewMesh(QString path){ ...@@ -128,10 +128,20 @@ void MainWidget::loadNewMesh(QString path){
return; return;
qDebug()<<"Opening File:"<<path; qDebug()<<"Opening File:"<<path;
Mesh* temp = new Mesh(this,path); mesh = new Mesh(this,path);
mesh = subdivision->subdivide(temp);
}
void MainWidget::subdivide(int level){
subdivision->subdivide(mesh);
} }
void MainWidget::setdebugOutput(bool output){
subdivision->setDebugOutbut(output);
}
void MainWidget::setRotation(bool started){ void MainWidget::setRotation(bool started){
qDebug()<<"rotation"<<started; qDebug()<<"rotation"<<started;
this->rotation = started; this->rotation = started;
......
...@@ -31,6 +31,8 @@ public slots: ...@@ -31,6 +31,8 @@ public slots:
void loadNewMesh(QString path); void loadNewMesh(QString path);
void setRotation(bool started); void setRotation(bool started);
void setWireframe(bool active); void setWireframe(bool active);
void subdivide(int level);
void setdebugOutput(bool output);
......
...@@ -34,6 +34,21 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -34,6 +34,21 @@ MainWindow::MainWindow(QWidget *parent) :
connect(CamHome, SIGNAL(triggered()), cam, SLOT(home())); connect(CamHome, SIGNAL(triggered()), cam, SLOT(home()));
toolBar->addAction(CamHome); toolBar->addAction(CamHome);
debugOutput = new QAction("DebugOutput",this);
debugOutput->setCheckable(true);
debugOutput->setChecked(false);
connect(debugOutput, SIGNAL(triggered(bool)), m_centralWidget, SLOT(setdebugOutput(bool)));
toolBar->addAction(debugOutput);
subdivSlider = new QSlider(Qt::Horizontal);
subdivSlider->setMinimum(0);
subdivSlider->setMaximum(10);
subdivSlider->setSliderPosition(0);
connect(subdivSlider, SIGNAL(valueChanged(int)),
m_centralWidget, SLOT(subdivide(int)));
toolBar->addWidget(subdivSlider);
this->setCentralWidget(m_centralWidget); this->setCentralWidget(m_centralWidget);
......
...@@ -26,7 +26,8 @@ private: ...@@ -26,7 +26,8 @@ private:
QAction *switchRotation; QAction *switchRotation;
QAction *switchWireframe; QAction *switchWireframe;
QAction *CamHome; QAction *CamHome;
QAction *debugOutput;
QSlider *subdivSlider;
}; };
......
...@@ -47,6 +47,25 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice ...@@ -47,6 +47,25 @@ 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){
numIndex = Indices.size();
indices = Indices;
vertices = Vertices;
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) * numIndex, &Indices[0], GL_STATIC_DRAW);
f->glDeleteBuffers(1, &VB_handle);
VB_handle = VB;
}
Mesh::MeshEntry::~MeshEntry() Mesh::MeshEntry::~MeshEntry()
{ {
f->glDeleteBuffers(1, &VB_handle); f->glDeleteBuffers(1, &VB_handle);
......
...@@ -65,6 +65,8 @@ public: ...@@ -65,6 +65,8 @@ 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); QVector<unsigned int>& Indices);
void update(GLuint VB_handle,QVector<Vertex>& Vertices, QVector<unsigned int>& Indices);
QString name; QString name;
GLuint VB_handle; GLuint VB_handle;
GLuint IB_handle; GLuint IB_handle;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f) Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f)
{ {
this->f =f; this->f =f;
debugOutput = false;
} }
Subdivision::~Subdivision() Subdivision::~Subdivision()
...@@ -10,6 +11,10 @@ Subdivision::~Subdivision() ...@@ -10,6 +11,10 @@ Subdivision::~Subdivision()
delete edgeShader; delete edgeShader;
} }
void Subdivision::setDebugOutbut(boolean debug){
this->debugOutput = debug;
}
void Subdivision::init() { void Subdivision::init() {
QString source = QLatin1String(":/subdivision-edge.compute"); QString source = QLatin1String(":/subdivision-edge.compute");
edgeShader = initComputeShaderProgram(source); edgeShader = initComputeShaderProgram(source);
...@@ -58,7 +63,9 @@ Mesh *Subdivision::subdivide(Mesh *mesh) { ...@@ -58,7 +63,9 @@ Mesh *Subdivision::subdivide(Mesh *mesh) {
Tables tables = precomputeTables(input); Tables tables = precomputeTables(input);
Result result = runShader(input, tables); Result result = runShader(input, tables);
return new Mesh(f, mesh, result.vertex_buffer, tables.index_buffer); current_mesh->update(result.vb_handle,result.vertex_buffer, tables.index_buffer);
//return new Mesh(f, mesh, result.vertex_buffer, tables.index_buffer);
} }
/** /**
...@@ -76,12 +83,14 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -76,12 +83,14 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
Tables tables; Tables tables;
QVector<unsigned int> ib = input.index_buffer; QVector<unsigned int> ib = input.index_buffer;
if(debugOutput)
qDebug()<<"Index Buffer: "<<ib; qDebug()<<"Index Buffer: "<<ib;
QVector<Vertex> vb = input.vertex_buffer; QVector<Vertex> vb = input.vertex_buffer;
//qDebug()<<"Vertex Buffer: "<<vb; if(debugOutput)
qDebug()<<"Vertex Buffer: "<<vb;
//compute edge table //compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices. //Format: first two entries: edge vertices. last two entries: distant vertices.
unsigned int nib_offset = vb.length(); unsigned int nib_offset = vb.length();
...@@ -238,15 +247,16 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -238,15 +247,16 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
//Wichtig: Wir gehen davon aus, dass wir geschlossene Oberflächen haben, dh für jede Kante von einem Dreieck wird eine passende Kante bei einem anderen Dreieck gefunden. //Wichtig: Wir gehen davon aus, dass wir geschlossene Oberflächen haben, dh für jede Kante von einem Dreieck wird eine passende Kante bei einem anderen Dreieck gefunden.
}//for each index in indexbuffer }//for each index in indexbuffer
qDebug()<<"Done with edge table. "<<tables.edge_indices.length()<<" edges found. Table: "<<tables.edge_indices; qDebug()<<"Done with edge table. "<<tables.edge_indices.length();
if (true){ if (debugOutput){
qDebug()<<"Eedges found. Table: "<<tables.edge_indices;
qDebug()<<"Table (long version):"; qDebug()<<"Table (long version):";
for (int i = 0; i < tables.edge_indices.length(); i++){ for (int i = 0; i < tables.edge_indices.length(); i++){
qDebug()<<"blub:"<<tables.edge_indices[i]; qDebug()<<"blub:"<<tables.edge_indices[i];
} }
} }
//compute vertex table //compute vertex table
//Format: First entry: original vertex. Other entries: adjacent vertices. //Format: First entry: original vertex. Other entries: adjacent vertices.
QVector<QVector<unsigned int> > duplicates;//for debugging QVector<QVector<unsigned int> > duplicates;//for debugging
unsigned int offset = 0; unsigned int offset = 0;
...@@ -306,15 +316,18 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -306,15 +316,18 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
if (!duplicates.contains(d)) duplicates.push_back(d); if (!duplicates.contains(d)) duplicates.push_back(d);
} }
qDebug()<<"Done with vertex index table. ";
tables.vertex_offsets.push_back(offset); tables.vertex_offsets.push_back(offset);
qDebug()<<"Done with vertex index table. ";
if(debugOutput){
qDebug()<<"Duplicates: "; qDebug()<<"Duplicates: ";
for (int i = 0; i < duplicates.length(); i++){ for (int i = 0; i < duplicates.length(); i++){
qDebug()<<duplicates[i]; qDebug()<<duplicates[i];
} }
}
qDebug()<<"Precompute Tables Done";
return tables; return tables;
} }
...@@ -358,16 +371,24 @@ Subdivision::Result Subdivision::runShader(Input input, Tables &tables) { ...@@ -358,16 +371,24 @@ Subdivision::Result Subdivision::runShader(Input input, Tables &tables) {
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, output_handle); f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, output_handle);
Vertex *ptr; Vertex *ptr;
ptr = (Vertex *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY); ptr = (Vertex *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
if(debugOutput)
qDebug() << "New vertices:"; qDebug() << "New vertices:";
for (int i = 0; i < input.vertex_buffer.size(); i++) { for (int i = 0; i < input.vertex_buffer.size(); i++) {
if(debugOutput)
qDebug() << ptr[i].pos; qDebug() << ptr[i].pos;
result.vertex_buffer.push_back(ptr[i]); result.vertex_buffer.push_back(ptr[i]);
} }
if(debugOutput)
qDebug() << "New edge points:"; qDebug() << "New edge points:";
for (int i = 0; i < tables.edge_indices.size() / 4; i++) { for (int i = 0; i < tables.edge_indices.size() / 4; i++) {
if(debugOutput)
qDebug() << ptr[edgeOffset + i].pos; qDebug() << ptr[edgeOffset + i].pos;
result.vertex_buffer.push_back(ptr[edgeOffset + i]); result.vertex_buffer.push_back(ptr[edgeOffset + i]);
} }
f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
// Delete the buffers the free the resources // Delete the buffers the free the resources
......
...@@ -14,8 +14,11 @@ public: ...@@ -14,8 +14,11 @@ public:
void init(); void init();
Mesh *subdivide(Mesh *mesh); Mesh *subdivide(Mesh *mesh);
void setDebugOutbut(boolean debug);
private: private:
boolean debugOutput;
struct Input struct Input
{ {
GLuint vb_handle; GLuint vb_handle;
...@@ -46,6 +49,7 @@ private: ...@@ -46,6 +49,7 @@ private:
Result runShader(Input input, Tables &tables); Result runShader(Input input, Tables &tables);
void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle); void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle);
void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset); void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset);
}; };
#endif #endif
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