Commit 85836b9d by Kai Westerkamp

temp

parent 4d9d60a3
...@@ -6,7 +6,7 @@ int main(int argc, char *argv[]) ...@@ -6,7 +6,7 @@ int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
QLoggingCategory::setFilterRules("timing.debug=true\n" QLoggingCategory::setFilterRules("timing.debug=true\n"
"mesh.debug=false\n" "mesh.debug=true\n"
"mesh.render.debug=false\n" "mesh.render.debug=false\n"
"subdiv.debug=true\n" "subdiv.debug=true\n"
"subdiv.trace.debug=false\n"); "subdiv.trace.debug=false\n");
......
...@@ -145,7 +145,8 @@ void MainWidget::initializeGL(){ ...@@ -145,7 +145,8 @@ void MainWidget::initializeGL(){
subdivision->init(); subdivision->init();
//loadNewMesh( "../Models/demon_head.3ds"); //loadNewMesh( "../Models/demon_head.3ds");
loadNewMesh( "../Models/torus.obj"); // loadNewMesh( "../Models/torus.obj");
loadNewMesh( "../Models/box.obj");
} }
void MainWidget::loadNewMesh(){ void MainWidget::loadNewMesh(){
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
Mesh::SubdivEntry::SubdivEntry() Mesh::SubdivEntry::SubdivEntry()
{ {
VB_handle = 0xFFFFFFFF; VB_handle = 0xFFFFFFFF;
VB_handle_irregular = 0xFFFFFFFF;
IB_irregular_handle = 0xFFFFFFFF; IB_irregular_handle = 0xFFFFFFFF;
IB_regular_handle = 0xFFFFFFFF; IB_regular_handle = 0xFFFFFFFF;
} }
...@@ -39,10 +40,10 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Verti ...@@ -39,10 +40,10 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Verti
f->glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * Vertices.size(), &Vertices[0], GL_STATIC_DRAW); f->glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * Vertices.size(), &Vertices[0], GL_STATIC_DRAW);
QVector<unsigned int> patches; QVector<unsigned int> patches;
this->init(f, VB_handle, Vertices, Indices_irregular, patches); this->init(f, VB_handle, Vertices, Vertices, Indices_irregular, patches);
} }
void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, QVector<Vertex>& Vertices_irregular,
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches){ QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches){
this->f = f; this->f = f;
this->VB_handle = VB_handle; this->VB_handle = VB_handle;
...@@ -52,9 +53,15 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVe ...@@ -52,9 +53,15 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVe
indices_regular = patches; indices_regular = patches;
qCDebug(log_mesh) << "Vertices" << vertices.length(); qCDebug(log_mesh) << "Vertices" << vertices.length();
qCDebug(log_mesh) << "Vertices Irregular" << Vertices_irregular.length();
qCDebug(log_mesh) << "Indices irregular" << indices_irregular.length(); qCDebug(log_mesh) << "Indices irregular" << indices_irregular.length();
qCDebug(log_mesh) << "Indices patches" << patches.length(); qCDebug(log_mesh) << "Indices patches" << patches.length();
f->glGenBuffers(1, &VB_handle_irregular);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VB_handle_irregular);
if(Vertices_irregular.size() != 0)
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Vertex) * Vertices_irregular.size(), &Vertices_irregular[0], GL_STATIC_DRAW);
f->glGenBuffers(1, &IB_irregular_handle); f->glGenBuffers(1, &IB_irregular_handle);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_irregular_handle); f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_irregular_handle);
if(indices_irregular.size() != 0) if(indices_irregular.size() != 0)
...@@ -96,10 +103,10 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice ...@@ -96,10 +103,10 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
} }
} }
void Mesh::MeshEntry::update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches) { void Mesh::MeshEntry::update(GLuint VB_handle, QVector<Vertex>& Vertices,QVector<Vertex>& Vertices_Irregular, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches) {
SubdivEntry *entry = new SubdivEntry; SubdivEntry *entry = new SubdivEntry;
buffers.push_back(std::shared_ptr<SubdivEntry>(entry)); buffers.push_back(std::shared_ptr<SubdivEntry>(entry));
entry->init(f, VB_handle, Vertices, Indices_irregular, patches); entry->init(f, VB_handle, Vertices, Vertices_Irregular,Indices_irregular, patches);
} }
Mesh::MeshEntry::~MeshEntry() Mesh::MeshEntry::~MeshEntry()
...@@ -481,7 +488,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, ...@@ -481,7 +488,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
} }
} else { } else {
if (!entry->indices_irregular.isEmpty()) { if (!entry->indices_irregular.isEmpty()) {
f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle); f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle_irregular);
f->glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); f->glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_irregular_handle); f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_irregular_handle);
......
...@@ -32,11 +32,13 @@ public: ...@@ -32,11 +32,13 @@ public:
SubdivEntry(); SubdivEntry();
~SubdivEntry(); ~SubdivEntry();
GLuint VB_handle; GLuint VB_handle;
GLuint VB_handle_irregular;
GLuint IB_irregular_handle; GLuint IB_irregular_handle;
GLuint IB_regular_handle; GLuint IB_regular_handle;
QVector<Vertex> vertices; QVector<Vertex> vertices;
QVector<Vertex> vertices_irregular;
QVector<unsigned int> indices_irregular; QVector<unsigned int> indices_irregular;
QVector<unsigned int> indices_regular; QVector<unsigned int> indices_regular;
...@@ -44,7 +46,7 @@ public: ...@@ -44,7 +46,7 @@ public:
void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices, void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices_irregular); QVector<unsigned int>& Indices_irregular);
void init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, void init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, QVector<Vertex>& Vertices_irregular,
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches); QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches);
void updateIndices(); void updateIndices();
}; };
...@@ -54,7 +56,7 @@ public: ...@@ -54,7 +56,7 @@ public:
~MeshEntry(); ~MeshEntry();
void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices); 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_irregular, QVector<unsigned int>& patches); void update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<Vertex>& Vertices_Irregular, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches);
QString name; QString name;
......
...@@ -109,13 +109,13 @@ void Subdivision::subdivide(Mesh *mesh, int level) { ...@@ -109,13 +109,13 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
QVector<unsigned int> irregular_ib; QVector<unsigned int> irregular_ib;
trianglesToIB(irregular, irregular_ib); trianglesToIB(irregular, irregular_ib);
updateIrregularForDraw(irregular, irregular_ib, result); updateIrregularForDraw(irregular, neighbors, result);
QVector<unsigned int> patches; QVector<unsigned int> patches;
getPatchIndexBuffer(regular, neighbors, patches); getPatchIndexBuffer(regular, neighbors, patches);
qCDebug(log_subdiv) << "patches" << patches.length(); qCDebug(log_subdiv) << "patches" << patches.length();
current_mesh->update(result.vb_handle, result.vertex_buffer, irregular_ib, patches); current_mesh->update(result.vb_handle, result.vertex_buffer, result.vertex_buffer_irregular, irregular_ib, patches);
} }
} }
...@@ -1040,13 +1040,77 @@ void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indic ...@@ -1040,13 +1040,77 @@ void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indic
edgeShader->release(); edgeShader->release();
} }
void Subdivision::updateIrregularForDraw(const QVector<Triangle> &triangles,const QVector<unsigned int> &ib, Result result){ void Subdivision::updateIrregularForDraw(const QVector<Triangle> &triangles,QMap<Triangle, Triangle::Neighbors> &neighbors, Result &result){
result.vertex_buffer_irregular_draw.resize(result.vertex_buffer); result.vertex_buffer_irregular.resize(result.vertex_buffer.size());
for (int i = 0; i < ib.length(); ++i) { QVectorIterator<Triangle> it(triangles);
while (it.hasNext()) {
Triangle triangle = it.next();
Triangle::Neighbors ns = neighbors.value(triangle);
QVector<Triangle> neighboring_triangles;
// u
Vertex currentCorner = triangle.u();
neighboring_triangles = vertexNeighbors(triangle, ns.uv, neighbors);
QVector<Vertex> surroundingVertex;
QVectorIterator<Triangle> extra(neighboring_triangles);
while (extra.hasNext()) {
Triangle extra_triangle = extra.next();
if(currentCorner.samePos(extra_triangle.u()) ){
bool found = false;
for (int i = 0; i < surroundingVertex.length() && !found; ++i) {
if(extra_triangle.u().samePos(surroundingVertex[i])){
found = true;
}
}
if(!found)
surroundingVertex.push_back(extra_triangle.u());
}
if(currentCorner.samePos(extra_triangle.v()) )
found = false;
for (int i = 0; i < surroundingVertex.length() && !found; ++i) {
if(extra_triangle.v().samePos(surroundingVertex[i])){
found = true;
}
}
if(!found)
surroundingVertex.push_back(extra_triangle.v());
Triangle extra_triangle = extra.next();
if(currentCorner.samePos(extra_triangle.w()) )
found = false;
for (int i = 0; i < surroundingVertex.length() && !found; ++i) {
if(extra_triangle.w().samePos(surroundingVertex[i])){
found = true;
}
}
if(!found)
surroundingVertex.push_back(extra_triangle.w());
}
//v
//w
neighboring_triangles += vertexNeighbors(triangle, ns.vw, neighbors);
neighboring_triangles += vertexNeighbors(triangle, ns.wu, neighbors);
result.vertex_buffer_irregular[triangle.u_idx()] = result.vertex_buffer.at(triangle.u_idx());
result.vertex_buffer_irregular[triangle.v_idx()] = result.vertex_buffer.at(triangle.v_idx());
result.vertex_buffer_irregular[triangle.w_idx()] = result.vertex_buffer.at(triangle.w_idx());
} }
} }
...@@ -41,6 +41,7 @@ private: ...@@ -41,6 +41,7 @@ private:
{ {
GLuint vb_handle; GLuint vb_handle;
QVector<Vertex> vertex_buffer; QVector<Vertex> vertex_buffer;
QVector<Vertex> vertex_buffer_irregular;
}; };
struct Patch struct Patch
...@@ -69,6 +70,9 @@ private: ...@@ -69,6 +70,9 @@ private:
void runCopyShader(GLuint size, GLuint vb_in, GLuint vb_out); void runCopyShader(GLuint size, GLuint vb_in, GLuint vb_out);
void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle, GLuint offset_handle); void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle, GLuint offset_handle);
void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset_handle); void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset_handle);
void updateIrregularForDraw(const QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors, Result &result);
QVector<unsigned int> patchIBToTriangleIB(QVector<unsigned int> ib); QVector<unsigned int> patchIBToTriangleIB(QVector<unsigned int> ib);
......
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