Commit 1e6ec30f by Alisa Jung

patch index buffer for regular meshes

parent 1c1d13b3
......@@ -358,9 +358,221 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
}
}
qDebug()<<"Precompute Tables Done";
getPatchIndexBuffer(ib);
return tables;
}
QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib){
QVector<unsigned int> pib;
for (int i = 0; i < ib.length() - 2; i+=3){
unsigned int i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11;
//alles gegen den uzs
i3 = ib[i];
i6 = ib[i+1];
i7 = ib[i+2];
int count3 = 0; //counts other triangles with this vertex
int count6 = 0;
int count7 = 0;
for (int j = 0; j < ib.length(); j++){
if (j != i && j != i+1 && j != i+2){
//for debugging // checking if patch is regular.
if (ib[j] == i3) count3++;
if (ib[j] == i6) count6++;
if (ib[j] == i7) count7++;
}
}
if (count3 != 5 || count6 != 5 || count7 != 5){
qWarning()<<"Counts wrong! 3: "<< count3 <<", 6: "<<count6<<", 7: "<<count7;
}
//find triangles with shared edge. Fills i2, i4, i10.
{
bool found36 = false;
bool found67 = false;
bool found73 = false;
for (int j = 0; j < ib.length() - 2; j+=3){
unsigned int j0 = ib[j];
unsigned int j1 = ib[j+1];
unsigned int j2 = ib[j+2];
//Dreieck angrenzend an Kante i3 i6
if (j0 == i3 && j2 == i6){
i2 = j1;
found36 = true;
}
if (j1 == i3 && j0 == i6){
i2 = j2;
found36 = true;
}
if (j2 == i3 && j1 == i6){
i2 == j0;
found36 = true;
}
//Dreieck angrenzend an Kante i6 i7
if (j0 == i6 && j2 == i7){
i10 = j1;
found67 = true;
}
if (j1 == i6 && j0 == i7){
i10 = j2;
found67 = true;
}
if (j2 == i6 && j1 == i7){
i10 = j0;
found67 = true;
}
//Dreieck angrenzend an Kante i7 i3
if (j0 == i7 && j2 == i3){
i4 = j1;
found73 = true;
}
if (j1 == i7 && j0 == i3){
i4 == j2;
found73 = true;
}
if (j2 == i7 && j1 == i3){
i4 = j0;
found73 = true;
}
}
if (!(found36 && found67 && found73)){
qWarning()<<"Didnt find neighbour. duplicate vertex? Abort.";
return pib;
}
}
//find last missing triangles.
{
bool found0,found1,found5,found9,found8,found11;
for (int j = 0; j < ib.length() - 2; j+=3){
unsigned int j0 = ib[j];
unsigned int j1 = ib[j+1];
unsigned int j2 = ib[j+2];
//find i0. //TODO assert triangle 031 \exists somewhere
if (j0 == i2 && j1 == i3){
i0 == j2;
found0 = true;
}
if (j1 == i2 && j2 == i3){
i0 = j0;
found0 = true;
}
if (j2 == i2 && j0 == i3){
i0 = j1;
found0 = true;
}
//find i1
if (j0 == i3 && j1 == i4){
i1 = j2;
found1 = true;
}
if (j1 == i3 && j2 == i4){
i1 = j0;
found1 = true;
}
if (j2 == i3 && j0 == i4){
i1 = j1;
found1 = true;
}
//TODO maybe assert that triangle i0 i3 i1 actually \exists.
//find i5.
if(j0 == i6 && j1 == i2){
i5 = j2;
found5 = true;
}
if (j1 == i6 && j2 == i2){
i5 = j0;
found5 = true;
}
if (j2 == i6 && j0 == i2){
i5 = j1;
found5 = true;
}
//find i9.
if (j0 == i10 && j1 == i6){
i9 = j2;
found9 = true;
}
if (j1 == i10 && j2 == i6){
i9 = j0;
found9 = true;
}
if (j2 == i10 && j0 == i6){
i9 = j1;
found9 = true;
}
//todo assert that triangle i5 i9 i6
//find i8
if (j0 == i4 && j1 == i7){
i8 = j2;
found8 = true;
}
if (j1 == i4 && j2 == i7){
i8 = j0;
found8 = true;
}
if (j2 == i4 && j0 == i7){
i8 = j1;
found8 = true;
}
//find i11
if (j0 == i7 && j1 == i10){
i11 = j2;
found11 = true;
}
if (j1 == i7 && j2 == i10){
i11 = j0;
found11 = true;
}
if (j2 == i7 && j0 == i10){
i11 = j1;
found11 = true;
}
}
if (!(found0 && found1 && found5 && found9 && found8 && found11)){
qWarning()<<"Couldnt find some neighbour at i= "<<i;
qWarning()<<found0<<found1<<found5<<found9<<found8<<found11;
qWarning()<<"Abort computing patch index buffer.";
return pib;
}
//else qWarning()<<"found all neighbours for patch.";
pib.push_back(i0);
pib.push_back(i1);
pib.push_back(i2);
pib.push_back(i3);
pib.push_back(i4);
pib.push_back(i5);
pib.push_back(i6);
pib.push_back(i7);
pib.push_back(i8);
pib.push_back(i9);
pib.push_back(i10);
pib.push_back(i11);
}
}
return pib;
}
Subdivision::Result Subdivision::runShader(Input input, Tables &tables) {
qDebug()<<"Running compute shader";
......
......@@ -50,6 +50,9 @@ private:
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);
//Geht davon aus, dass jeder 3D-Punkt nur einmal im Vertex-Buffer vorkommt!
QVector<unsigned int> getPatchIndexBuffer(QVector<unsigned int> ib);
};
#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