Commit fc9a48c7 by Kai Westerkamp

Merge branch 'patchRender' of…

Merge branch 'patchRender' of ssh://git.breab.org:2223/kai/Unterteilungsalgorithmen into patchRender
parents d4fae3f2 9ead25f6
...@@ -65,9 +65,10 @@ void Subdivision::subdivide(Mesh *mesh, int level) { ...@@ -65,9 +65,10 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
input.vb_handle = entry->VB_handle; input.vb_handle = entry->VB_handle;
input.vertex_buffer = entry->vertices; 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); // current_mesh->update(input.vb_handle, input.vertex_buffer, input.index_buffer, entry->indices_regular);
} else { } else {
Tables tables = precomputeTables(input); Tables tables = precomputeTables(input);
...@@ -137,8 +138,11 @@ struct Edge { ...@@ -137,8 +138,11 @@ struct Edge {
Subdivision::Tables Subdivision::precomputeTables(Input input) { Subdivision::Tables Subdivision::precomputeTables(Input input) {
Tables tables; Tables tables;
QVector<unsigned int> ib = input.index_buffer; QVector<unsigned int> ib = input.index_irregular_buffer;
qCDebug(log_subdiv_trace) << "Index Buffer: " << ib; 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; QVector<Vertex> vb = input.vertex_buffer;
qCDebug(log_subdiv_trace) << "Vertex Buffer: " << vb; qCDebug(log_subdiv_trace) << "Vertex Buffer: " << vb;
...@@ -147,16 +151,20 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -147,16 +151,20 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
for (int i = 0; i < ib.length(); i+=3) { for (int i = 0; i < ib.length(); i+=3) {
triangles.push_back(Triangle(vb, ib[i], ib[i+1], ib[i+2])); 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()); precomputeEdgeTable(tables, triangles, triangles_regular, (unsigned int) vb.length());
precomputeVertexTable(tables, vb, ib); precomputeVertexTable(tables, vb, ib, ib_regular);
//tables.patch_index_regular = getPatchIndexBuffer(ib, QVector<unsigned int>());//TODO pass regular and irregular index buffer? //tables.patch_index_regular = getPatchIndexBuffer(ib, QVector<unsigned int>());//TODO pass regular and irregular index buffer?
qCDebug(log_subdiv) << "Precompute Tables Done"; qCDebug(log_subdiv) << "Precompute Tables Done";
return tables; 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 //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.
...@@ -188,6 +196,12 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian ...@@ -188,6 +196,12 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
insert_edge(opposite_edges, triangles[j], edge_b, edge_a); 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); QVector<Triangle::Edge> opposite = opposite_edges.value(triangle);
...@@ -272,10 +286,11 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian ...@@ -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 //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
QVector<unsigned int> ib_combined = ib + ib_regular;
unsigned int offset = 0; unsigned int offset = 0;
for (int i = 0; i < vb.length(); i++){ for (int i = 0; i < vb.length(); i++){
//hat evtl viel redundanz //hat evtl viel redundanz
...@@ -289,21 +304,21 @@ void Subdivision::precomputeVertexTable(Subdivision::Tables &tables, QVector<Ver ...@@ -289,21 +304,21 @@ void Subdivision::precomputeVertexTable(Subdivision::Tables &tables, QVector<Ver
QVector<unsigned int> d; 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 //suche verweise auf vertex im indexbuffer
if (vb[ib[j]].samePos(originalVertex)){ if (vb[ib_combined[j]].samePos(originalVertex)){
d.push_back(j); d.push_back(j);
unsigned int i1, i2; //indices for neighbour vertices unsigned int i1, i2; //indices for neighbour vertices
if(j%3==0){ if(j%3==0){
i1 = ib[j+1]; i1 = ib_combined[j+1];
i2 = ib[j+2]; i2 = ib_combined[j+2];
} else if(j%3==1){ } else if(j%3==1){
i1 = ib[j-1]; i1 = ib_combined[j-1];
i2 = ib[j+1]; i2 = ib_combined[j+1];
} else{ } else{
i1 = ib[j-2]; i1 = ib_combined[j-2];
i2 = ib[j-1]; i2 = ib_combined[j-1];
} }
Vertex v1,v2; //neighbour vertices; Vertex v1,v2; //neighbour vertices;
......
...@@ -22,7 +22,8 @@ private: ...@@ -22,7 +22,8 @@ private:
struct Input struct Input
{ {
GLuint vb_handle; GLuint vb_handle;
QVector<unsigned int> index_buffer; QVector<unsigned int> index_irregular_buffer;
QVector<unsigned int> index_regular_buffer;
QVector<Vertex> vertex_buffer; QVector<Vertex> vertex_buffer;
}; };
...@@ -53,8 +54,8 @@ private: ...@@ -53,8 +54,8 @@ private:
QOpenGLShaderProgram *initComputeShaderProgram(QString &source); QOpenGLShaderProgram *initComputeShaderProgram(QString &source);
Tables precomputeTables(Input input); Tables precomputeTables(Input input);
void precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, unsigned int offset); 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); 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); 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); 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);
......
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