Commit 2b4f6b1c by Philipp Adolf

Split precomputTables into smaller functions

parent 547955fa
......@@ -2,7 +2,6 @@
#include "logcategories.h"
#include "subdivision.h"
#include "triangle.h"
Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f)
{
......@@ -149,6 +148,15 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
triangles.push_back(Triangle(vb, ib[i], ib[i+1], ib[i+2]));
}
precomputeEdgeTable(tables, triangles, (unsigned int) vb.length());
precomputeVertexTable(tables, vb, ib);
tables.index_regular = getPatchIndexBuffer(ib);
qCInfo(log_subdiv) << "Precompute Tables Done";
return tables;
}
void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, unsigned int offset) {
//compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices.
......@@ -159,7 +167,6 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
// Maps edges to the index of the new vertex added on that edge. The keys are the indices of the two vertices defining the edge and must be in the order uv, vw or uw.
QMap<Edge, unsigned int> edge_indices;
unsigned int edge_index = vb.length();//offset in new index buffer for edge vertices
for (int i = 0; i < triangles.length(); i++){
//schaue alle dreiecke an
Triangle triangle = triangles[i];
......@@ -193,7 +200,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
if (edge_indices.contains(edge)) {
uv = edge_indices.value(edge);
} else {
uv = edge_index++;
uv = offset++;
edge_indices.insert(edge, uv);
edge = { opposite[0].a, opposite[0].b };
......@@ -209,7 +216,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
if (edge_indices.contains(edge)) {
vw = edge_indices.value(edge);
} else {
vw = edge_index++;
vw = offset++;
edge_indices.insert(edge, vw);
edge = { opposite[1].a, opposite[1].b };
......@@ -225,7 +232,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
if (edge_indices.contains(edge)) {
wu = edge_indices.value(edge);
} else {
wu = edge_index++;
wu = offset++;
edge_indices.insert(edge, wu);
edge = { opposite[2].a, opposite[2].b };
......@@ -263,7 +270,9 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
qCDebug(log_subdiv) << "blub:" << tables.edge_indices[i];
}
}
}
void Subdivision::precomputeVertexTable(Subdivision::Tables &tables, QVector<Vertex> &vb, QVector<unsigned int> &ib) {
//compute vertex table
//Format: First entry: original vertex. Other entries: adjacent vertices.
QVector<QVector<unsigned int> > duplicates;//for debugging
......@@ -273,6 +282,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
QVector<Vertex> adj_v;//helfer
tables.vertex_offsets.push_back(offset);
qCDebug(log_subdiv) << offset;
tables.vertex_indices.push_back(i);
offset++;
......@@ -324,8 +334,6 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
if (!duplicates.contains(d)) duplicates.push_back(d);
}
tables.vertex_offsets.push_back(offset);
qCDebug(log_subdiv) << "Done with vertex index table. ";
......@@ -333,9 +341,6 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
for (int i = 0; i < duplicates.length(); i++){
qCDebug(log_subdiv) << duplicates[i];
}
tables.index_regular = getPatchIndexBuffer(ib);
qCInfo(log_subdiv) << "Precompute Tables Done";
return tables;
}
void Subdivision::splitRegular(Mesh *mesh) {
......
......@@ -6,6 +6,7 @@
#include <QOpenGLFunctions_4_3_Core>
#include "mesh.h"
#include "triangle.h"
class Subdivision
{
......@@ -52,6 +53,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 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