Commit 1de39cde by Kai Westerkamp

rendering all patches from all Levels

parent 87d5c28e
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
Q_LOGGING_CATEGORY(log_subdiv, "subdiv") Q_LOGGING_CATEGORY(log_subdiv, "subdiv")
Q_LOGGING_CATEGORY(log_subdiv_trace, "subdiv.trace") Q_LOGGING_CATEGORY(log_subdiv_trace, "subdiv.trace")
Q_LOGGING_CATEGORY(log_mesh, "mesh") Q_LOGGING_CATEGORY(log_mesh, "mesh")
Q_LOGGING_CATEGORY(log_mesh_render, "mesh.render")
...@@ -7,5 +7,6 @@ ...@@ -7,5 +7,6 @@
Q_DECLARE_LOGGING_CATEGORY(log_subdiv) Q_DECLARE_LOGGING_CATEGORY(log_subdiv)
Q_DECLARE_LOGGING_CATEGORY(log_subdiv_trace) Q_DECLARE_LOGGING_CATEGORY(log_subdiv_trace)
Q_DECLARE_LOGGING_CATEGORY(log_mesh) Q_DECLARE_LOGGING_CATEGORY(log_mesh)
Q_DECLARE_LOGGING_CATEGORY(log_mesh_render)
#endif #endif
...@@ -437,9 +437,9 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, ...@@ -437,9 +437,9 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
// qCDebug(log_mesh) << materials[MaterialIndex].Diffuse << materials[MaterialIndex].Specular << materials[MaterialIndex].Shininess << materials[MaterialIndex].hasTexture; // qCDebug(log_mesh) << materials[MaterialIndex].Diffuse << materials[MaterialIndex].Specular << materials[MaterialIndex].Shininess << materials[MaterialIndex].hasTexture;
if (regular ) { if (regular ) {
// shader->setUniformValue("materialInfo.Diffuse", QVector3D(0.0f, 0.0f, 1.0f)); // shader->setUniformValue("materialInfo.Diffuse", QVector3D(0.0f, 0.0f, 1.0f));
shader->setUniformValue("materialInfo.Diffuse", QVector3D(243.0, 156.0, 18.0)/255.0); shader->setUniformValue("materialInfo.Diffuse", QVector3D(243.0, 156.0, 18.0)/255.0);
// shader->setUniformValue("materialInfo.Diffuse", QVector/3D(1.0f, 1.0f, 1.0f)); // shader->setUniformValue("materialInfo.Diffuse", QVector/3D(1.0f, 1.0f, 1.0f));
} else { } else {
shader->setUniformValue("materialInfo.Diffuse", materials[MaterialIndex].Diffuse); shader->setUniformValue("materialInfo.Diffuse", materials[MaterialIndex].Diffuse);
} }
...@@ -459,14 +459,25 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, ...@@ -459,14 +459,25 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
// Draw Vertex Array // Draw Vertex Array
if(regular){ if(regular){
if (!entry->indices_regular.isEmpty()) { for (int depth = 0; depth < subdivision+1; ++depth) {
f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle); std::shared_ptr<SubdivEntry> depthEntry = entries[index].buffers[depth];
f->glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); if (!depthEntry->indices_regular.isEmpty()) {
std::shared_ptr<SubdivEntry> depthEntryMinusOne = entries[index].buffers[depth];
if(depth > 0){
depthEntryMinusOne = entries[index].buffers[depth-1];
}
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_regular_handle); shader->setUniformValue("depth",depth);
f->glPatchParameteri(GL_PATCH_VERTICES, 12);
f->glDrawElements(GL_PATCHES, entry->indices_regular.size(), GL_UNSIGNED_INT, 0); f->glBindBuffer(GL_ARRAY_BUFFER, depthEntryMinusOne->VB_handle);
//qCDebug(log_mesh)<<"Patches "<<entry->indices_regular.size()/12<<" Subdivision Level: "<< subdivision; f->glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
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;
}
} }
} else { } else {
if (!entry->indices_irregular.isEmpty()) { if (!entry->indices_irregular.isEmpty()) {
......
...@@ -5,7 +5,6 @@ layout(vertices = 3) out; ...@@ -5,7 +5,6 @@ layout(vertices = 3) out;
in vec3 vPosition[]; in vec3 vPosition[];
out vec3 tcPosition[]; out vec3 tcPosition[];
uniform float subdiv;
void main() void main()
{ {
......
...@@ -6,17 +6,19 @@ in vec3 vPosition[]; ...@@ -6,17 +6,19 @@ in vec3 vPosition[];
out vec3 tcPosition[]; out vec3 tcPosition[];
uniform int subdiv; uniform int subdiv;
uniform int depth;
void main() void main()
{ {
tcPosition[gl_InvocationID] = vPosition[gl_InvocationID]; tcPosition[gl_InvocationID] = vPosition[gl_InvocationID];
float tesselation = subdiv; float tesselation = subdiv-depth;
gl_TessLevelOuter[0] = exp2(tesselation); gl_TessLevelOuter[0] = exp2(tesselation);
gl_TessLevelOuter[1] = exp2(tesselation); gl_TessLevelOuter[1] = exp2(tesselation);
gl_TessLevelOuter[2] = exp2(tesselation); gl_TessLevelOuter[2] = exp2(tesselation);
gl_TessLevelInner[0] = exp2(tesselation+1); gl_TessLevelInner[0] = exp2(tesselation);
} }
...@@ -68,7 +68,7 @@ void Subdivision::subdivide(Mesh *mesh, int level) { ...@@ -68,7 +68,7 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
input.index_buffer = entry->indices_irregular; input.index_buffer = entry->indices_irregular;
if (input.index_buffer.isEmpty()) { if (input.index_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);
Result result = runShader(input, tables); Result result = runShader(input, tables);
......
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