Commit bf238c0c by Kai Westerkamp

added UI

some changes to Mesh entry handle
parent 25a99649
......@@ -128,10 +128,20 @@ void MainWidget::loadNewMesh(QString path){
return;
qDebug()<<"Opening File:"<<path;
Mesh* temp = new Mesh(this,path);
mesh = subdivision->subdivide(temp);
mesh = new Mesh(this,path);
}
void MainWidget::subdivide(int level){
subdivision->subdivide(mesh);
}
void MainWidget::setdebugOutput(bool output){
subdivision->setDebugOutbut(output);
}
void MainWidget::setRotation(bool started){
qDebug()<<"rotation"<<started;
this->rotation = started;
......
......@@ -31,6 +31,8 @@ public slots:
void loadNewMesh(QString path);
void setRotation(bool started);
void setWireframe(bool active);
void subdivide(int level);
void setdebugOutput(bool output);
......
......@@ -34,10 +34,25 @@ MainWindow::MainWindow(QWidget *parent) :
connect(CamHome, SIGNAL(triggered()), cam, SLOT(home()));
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);
this->setCentralWidget(m_centralWidget);
subdivSlider = new QSlider(Qt::Horizontal);
subdivSlider->setMinimum(0);
subdivSlider->setMaximum(10);
subdivSlider->setSliderPosition(0);
// showMaximized();
connect(subdivSlider, SIGNAL(valueChanged(int)),
m_centralWidget, SLOT(subdivide(int)));
toolBar->addWidget(subdivSlider);
this->setCentralWidget(m_centralWidget);
// showMaximized();
}
MainWindow::~MainWindow()
......
......@@ -26,7 +26,8 @@ private:
QAction *switchRotation;
QAction *switchWireframe;
QAction *CamHome;
QAction *debugOutput;
QSlider *subdivSlider;
};
......
......@@ -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()
{
f->glDeleteBuffers(1, &VB_handle);
......
......@@ -65,6 +65,8 @@ 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);
QString name;
GLuint VB_handle;
GLuint IB_handle;
......
......@@ -3,6 +3,7 @@
Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f)
{
this->f =f;
debugOutput = false;
}
Subdivision::~Subdivision()
......@@ -10,6 +11,10 @@ Subdivision::~Subdivision()
delete edgeShader;
}
void Subdivision::setDebugOutbut(boolean debug){
this->debugOutput = debug;
}
void Subdivision::init() {
QString source = QLatin1String(":/subdivision-edge.compute");
edgeShader = initComputeShaderProgram(source);
......@@ -58,7 +63,9 @@ Mesh *Subdivision::subdivide(Mesh *mesh) {
Tables tables = precomputeTables(input);
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) {
Tables tables;
QVector<unsigned int> ib = input.index_buffer;
qDebug()<<"Index Buffer: "<<ib;
if(debugOutput)
qDebug()<<"Index Buffer: "<<ib;
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.
unsigned int nib_offset = vb.length();
......@@ -220,33 +229,34 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
}//quadratische Laufzeit ftw
//add indices to new index buffer
tables.index_buffer.push_back(ib[i]);
tables.index_buffer.push_back(nib_offset + i);
tables.index_buffer.push_back(nib_offset + i + 2);
tables.index_buffer.push_back(ib[i+1]);
tables.index_buffer.push_back(nib_offset + i + 1);
tables.index_buffer.push_back(nib_offset + i);
tables.index_buffer.push_back(ib[i+2]);
tables.index_buffer.push_back(nib_offset + i + 2);
tables.index_buffer.push_back(nib_offset + i + 1);
tables.index_buffer.push_back(nib_offset + i);
tables.index_buffer.push_back(nib_offset + i + 1);
tables.index_buffer.push_back(nib_offset + i + 2);
//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.
tables.index_buffer.push_back(ib[i]);
tables.index_buffer.push_back(nib_offset + i);
tables.index_buffer.push_back(nib_offset + i + 2);
tables.index_buffer.push_back(ib[i+1]);
tables.index_buffer.push_back(nib_offset + i + 1);
tables.index_buffer.push_back(nib_offset + i);
tables.index_buffer.push_back(ib[i+2]);
tables.index_buffer.push_back(nib_offset + i + 2);
tables.index_buffer.push_back(nib_offset + i + 1);
tables.index_buffer.push_back(nib_offset + i);
tables.index_buffer.push_back(nib_offset + i + 1);
tables.index_buffer.push_back(nib_offset + i + 2);
//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
qDebug()<<"Done with edge table. "<<tables.edge_indices.length()<<" edges found. Table: "<<tables.edge_indices;
if (true){
qDebug()<<"Done with edge table. "<<tables.edge_indices.length();
if (debugOutput){
qDebug()<<"Eedges found. Table: "<<tables.edge_indices;
qDebug()<<"Table (long version):";
for (int i = 0; i < tables.edge_indices.length(); i++){
qDebug()<<"blub:"<<tables.edge_indices[i];
}
}
//compute vertex table
//compute vertex table
//Format: First entry: original vertex. Other entries: adjacent vertices.
QVector<QVector<unsigned int> > duplicates;//for debugging
unsigned int offset = 0;
......@@ -306,15 +316,18 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
if (!duplicates.contains(d)) duplicates.push_back(d);
}
qDebug()<<"Done with vertex index table. ";
tables.vertex_offsets.push_back(offset);
qDebug()<<"Duplicates: ";
for (int i = 0; i < duplicates.length(); i++){
qDebug()<<duplicates[i];
qDebug()<<"Done with vertex index table. ";
if(debugOutput){
qDebug()<<"Duplicates: ";
for (int i = 0; i < duplicates.length(); i++){
qDebug()<<duplicates[i];
}
}
qDebug()<<"Precompute Tables Done";
return tables;
}
......@@ -358,16 +371,24 @@ Subdivision::Result Subdivision::runShader(Input input, Tables &tables) {
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, output_handle);
Vertex *ptr;
ptr = (Vertex *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
qDebug() << "New vertices:";
if(debugOutput)
qDebug() << "New vertices:";
for (int i = 0; i < input.vertex_buffer.size(); i++) {
qDebug() << ptr[i].pos;
result.vertex_buffer.push_back(ptr[i]);
if(debugOutput)
qDebug() << ptr[i].pos;
result.vertex_buffer.push_back(ptr[i]);
}
qDebug() << "New edge points:";
if(debugOutput)
qDebug() << "New edge points:";
for (int i = 0; i < tables.edge_indices.size() / 4; i++) {
qDebug() << ptr[edgeOffset + i].pos;
result.vertex_buffer.push_back(ptr[edgeOffset + i]);
if(debugOutput)
qDebug() << ptr[edgeOffset + i].pos;
result.vertex_buffer.push_back(ptr[edgeOffset + i]);
}
f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
// Delete the buffers the free the resources
......
......@@ -14,8 +14,11 @@ public:
void init();
Mesh *subdivide(Mesh *mesh);
void setDebugOutbut(boolean debug);
private:
boolean debugOutput;
struct Input
{
GLuint vb_handle;
......@@ -46,6 +49,7 @@ private:
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 runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset);
};
#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