Commit 11b65874 by Alisa Jung

Merge branch 'patchRender' of…

Merge branch 'patchRender' of ssh://git.breab.org:2223/kai/Unterteilungsalgorithmen into patchRender
parents c19a9d28 fc9a48c7
......@@ -5,7 +5,10 @@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLoggingCategory::setFilterRules("subdiv.trace.debug=false\n");
QLoggingCategory::setFilterRules("mesh.debug=false\n"
"mesh.render.debug=false\n"
"subdiv.debug=true\n"
"subdiv.trace.debug=false\n");
// If you want to enable debug output for some categories use something like this:
//QLoggingCategory::setFilterRules("*.debug=false\n"
......
......@@ -47,7 +47,7 @@ MainWindow::MainWindow(QWidget *parent) :
subdivSlider->setSingleStep(1);
connect(subdivSlider, SIGNAL(valueChanged(int)),
m_centralWidget, SLOT(subdivide(int)));
this, SLOT(sliderfix(int)));
toolBar->addWidget(subdivSlider);
......@@ -57,6 +57,16 @@ MainWindow::MainWindow(QWidget *parent) :
// showMaximized();
}
void MainWindow::sliderfix(int pos){
int move = pos -oldSliderpos;
move >0 ? move = 1 : move = -1;
int newPos = oldSliderpos+move;
// qDebug()<<"SliderPos"<<oldSliderpos<<move<<newPos;
m_centralWidget->subdivide(newPos);
subdivSlider->setSliderPosition(newPos);
oldSliderpos = newPos;
}
MainWindow::~MainWindow()
{
}
......@@ -19,7 +19,11 @@ public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void sliderfix(int pos);
private:
int oldSliderpos = 0;
MainWidget *m_centralWidget;
QToolBar *toolBar;
......
......@@ -476,7 +476,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, depthEntry->IB_regular_handle);
f->glPatchParameteri(GL_PATCH_VERTICES, 12);
f->glDrawElements(GL_PATCHES, depthEntry->indices_regular.size(), GL_UNSIGNED_INT, 0);
qCDebug(log_mesh)<<"Patches "<<entry->indices_regular.size()/12<<" Subdivision Level: "<< subdivision;
// qCDebug(log_mesh_render)<<"Patches "<<entry->indices_regular.size()/12<<" Subdivision Level: "<< subdivision;
}
}
} else {
......
......@@ -65,9 +65,10 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
input.vb_handle = entry->VB_handle;
input.vertex_buffer = entry->vertices;
input.index_buffer = entry->indices_irregular;
input.index_irregular_buffer = entry->indices_irregular;
input.index_regular_buffer = getTriangles(entry->indices_regular);
if (input.index_buffer.isEmpty()) {
if (input.index_irregular_buffer.isEmpty()) {
// current_mesh->update(input.vb_handle, input.vertex_buffer, input.index_buffer, entry->indices_regular);
} else {
Tables tables = precomputeTables(input);
......@@ -137,8 +138,11 @@ struct Edge {
Subdivision::Tables Subdivision::precomputeTables(Input input) {
Tables tables;
QVector<unsigned int> ib = input.index_buffer;
qCDebug(log_subdiv_trace) << "Index Buffer: " << ib;
QVector<unsigned int> ib = input.index_irregular_buffer;
qCDebug(log_subdiv_trace) << "Index Buffer Irregular: " << ib;
QVector<unsigned int> ib_regular = input.index_regular_buffer;
qCDebug(log_subdiv_trace) << "Index Buffer Regular: " << ib_regular;
QVector<Vertex> vb = input.vertex_buffer;
qCDebug(log_subdiv_trace) << "Vertex Buffer: " << vb;
......@@ -147,16 +151,20 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
for (int i = 0; i < ib.length(); i+=3) {
triangles.push_back(Triangle(vb, ib[i], ib[i+1], ib[i+2]));
}
QVector<Triangle> triangles_regular;
for (int i = 0; i < ib_regular.length(); i+=3) {
triangles.push_back(Triangle(vb, ib_regular[i], ib_regular[i+1], ib_regular[i+2]));
}
precomputeEdgeTable(tables, triangles, (unsigned int) vb.length());
precomputeVertexTable(tables, vb, ib);
precomputeEdgeTable(tables, triangles, triangles_regular, (unsigned int) vb.length());
precomputeVertexTable(tables, vb, ib, ib_regular);
//tables.patch_index_regular = getPatchIndexBuffer(ib, QVector<unsigned int>());//TODO pass regular and irregular index buffer?
qCDebug(log_subdiv) << "Precompute Tables Done";
return tables;
}
void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, unsigned int offset) {
void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, QVector<Triangle> &triangles_regular, unsigned int offset) {
//compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices.
......@@ -188,6 +196,12 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
insert_edge(opposite_edges, triangles[j], edge_b, edge_a);
}
}
for (int j = 0; j < triangles_regular.length(); j++){
if (triangle.get_shared_edge(triangles_regular[j], edge_a, edge_b)) {
insert_edge(opposite_edges, triangle, edge_a, edge_b);
// no need to insert the opposite edge of a regular triangle - it won't be processed by the outer loop
}
}
QVector<Triangle::Edge> opposite = opposite_edges.value(triangle);
......@@ -272,10 +286,11 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
}
}
void Subdivision::precomputeVertexTable(Subdivision::Tables &tables, QVector<Vertex> &vb, QVector<unsigned int> &ib) {
void Subdivision::precomputeVertexTable(Subdivision::Tables &tables, QVector<Vertex> &vb, QVector<unsigned int> &ib, QVector<unsigned int> &ib_regular) {
//compute vertex table
//Format: First entry: original vertex. Other entries: adjacent vertices.
QVector<QVector<unsigned int> > duplicates;//for debugging
QVector<unsigned int> ib_combined = ib + ib_regular;
unsigned int offset = 0;
for (int i = 0; i < vb.length(); i++){
//hat evtl viel redundanz
......@@ -289,21 +304,21 @@ void Subdivision::precomputeVertexTable(Subdivision::Tables &tables, QVector<Ver
QVector<unsigned int> d;
for (int j = 0; j < ib.length(); j++){
for (int j = 0; j < ib_combined.length(); j++){
//suche verweise auf vertex im indexbuffer
if (vb[ib[j]].samePos(originalVertex)){
if (vb[ib_combined[j]].samePos(originalVertex)){
d.push_back(j);
unsigned int i1, i2; //indices for neighbour vertices
if(j%3==0){
i1 = ib[j+1];
i2 = ib[j+2];
i1 = ib_combined[j+1];
i2 = ib_combined[j+2];
} else if(j%3==1){
i1 = ib[j-1];
i2 = ib[j+1];
i1 = ib_combined[j-1];
i2 = ib_combined[j+1];
} else{
i1 = ib[j-2];
i2 = ib[j-1];
i1 = ib_combined[j-2];
i2 = ib_combined[j-1];
}
Vertex v1,v2; //neighbour vertices;
......
......@@ -22,7 +22,8 @@ private:
struct Input
{
GLuint vb_handle;
QVector<unsigned int> index_buffer;
QVector<unsigned int> index_irregular_buffer;
QVector<unsigned int> index_regular_buffer;
QVector<Vertex> vertex_buffer;
};
......@@ -53,8 +54,8 @@ private:
QOpenGLShaderProgram *initComputeShaderProgram(QString &source);
Tables precomputeTables(Input input);
void precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, unsigned int offset);
void precomputeVertexTable(Subdivision::Tables &tables, QVector<Vertex> &vb, QVector<unsigned int> &ib);
void precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, QVector<Triangle> &triangles_regular, unsigned int offset);
void precomputeVertexTable(Subdivision::Tables &tables, QVector<Vertex> &vb, QVector<unsigned int> &ib, QVector<unsigned int> &ib_regular);
void findRegular(QVector<unsigned int> index_buffer, QVector<Vertex> vertex_buffer, QVector<unsigned int> &regular, QVector<unsigned int> &irregular);
Result runShader(Input input, Tables &tables);
void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle);
......
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