Commit e56887c7 by Kai Westerkamp

subdivide

parent c2d8d532
...@@ -26,6 +26,11 @@ Mesh::SubdivEntry::~SubdivEntry() ...@@ -26,6 +26,11 @@ Mesh::SubdivEntry::~SubdivEntry()
void Mesh::SubdivEntry::addRegular(QVector<unsigned int>& Indices){ void Mesh::SubdivEntry::addRegular(QVector<unsigned int>& Indices){
indicesRegular = Indices; indicesRegular = Indices;
indices.clear(); indices.clear();
for (int var = 0; var < 12; ++var) {
qDebug()<<indicesRegular[var];
}
f->glGenBuffers(1, &IB_Regular); f->glGenBuffers(1, &IB_Regular);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_Regular); f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_Regular);
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indicesRegular.size(), &indicesRegular[0], GL_STATIC_DRAW); f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indicesRegular.size(), &indicesRegular[0], GL_STATIC_DRAW);
...@@ -460,13 +465,12 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, ...@@ -460,13 +465,12 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
if(regular){ if(regular){
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_Regular); f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_Regular);
f->glPatchParameteri(GL_PATCH_VERTICES, 12); f->glPatchParameteri(GL_PATCH_VERTICES, 12);
f->glDrawElements(GL_PATCHES, entry->indicesRegular.size(), GL_UNSIGNED_INT, 0); f->glDrawElements(GL_PATCHES, entry->indicesRegular.size(), GL_UNSIGNED_INT, 0);
} else{ } else{
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_handle); f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_handle);
f->glPatchParameteri(GL_PATCH_VERTICES, 3); f->glPatchParameteri(GL_PATCH_VERTICES, 3);
f->glDrawElements(GL_PATCHES, entry->indices.size(), GL_UNSIGNED_INT, 0); f->glDrawElements(GL_PATCHES, entry->indices.size(), GL_UNSIGNED_INT, 0);
} }
......
...@@ -5,14 +5,14 @@ layout(vertices = 12) out; ...@@ -5,14 +5,14 @@ layout(vertices = 12) out;
in vec3 vPosition[]; in vec3 vPosition[];
out vec3 tcPosition[]; out vec3 tcPosition[];
uniform float subdiv; uniform int subdiv;
void main() void main()
{ {
tcPosition[gl_InvocationID] = vPosition[gl_InvocationID]; tcPosition[gl_InvocationID] = vPosition[gl_InvocationID];
float tesselation = subdiv; float tesselation = subdiv+6;
gl_TessLevelOuter[0] = tesselation; gl_TessLevelOuter[0] = tesselation;
gl_TessLevelOuter[1] = tesselation; gl_TessLevelOuter[1] = tesselation;
......
...@@ -36,7 +36,7 @@ void main() ...@@ -36,7 +36,7 @@ void main()
float a3 = 6*u4+24*u3*w+24*u2*w2+8*u*w3+w4+24*u3*v+60*u2*v*w+36*u*v*w2+6*v*w3+24*u2*v2+36*u*v2*w+12*v2*w2+8*u*v3+6*v3*w+v4; float a3 = 6*u4+24*u3*w+24*u2*w2+8*u*w3+w4+24*u3*v+60*u2*v*w+36*u*v*w2+6*v*w3+24*u2*v2+36*u*v2*w+12*v2*w2+8*u*v3+6*v3*w+v4;
float a4 = u4+6*u3*w+12*u2*w2+6*u*w3+w4+2*u3*v+6*u2*v*w+6*u*v*w2+2*v*w3; float a4 = u4+6*u3*w+12*u2*w2+6*u*w3+w4+2*u3*v+6*u2*v*w+6*u*v*w2+2*v*w3;
float a5 = 2*u*v3+v4; float a5 = 2*u*v3+v4;
float a6 = u4+6*u3*w+12*u2*w2+6*u*w3+w4+8*u3*v+36*u2*v*w+36*u*v*w2+8*v*w3+24*u2*v2+60*u*v2*w+24*v2*w2+24*u*w3+24*v3*w+6*v4; float a6 = u4+6*u3*w+12*u2*w2+6*u*w3+w4+8*u3*v+36*u2*v*w+36*u*v*w2+8*v*w3+24*u2*v2+60*u*v2*w+24*v2*w2+24*u*v3+24*v3*w+6*v4;
float a7 = u4+8*u3*w+24*u2*w2+24*u*w3+6*w4+6*u3*v+36*u2*v*w+60*u*v*w2+24*v*w3+12*u2*v2+36*u*v2*w+24*v2*w2+6*u*v3+8*v3*w+v4; float a7 = u4+8*u3*w+24*u2*w2+24*u*w3+6*w4+6*u3*v+36*u2*v*w+60*u*v*w2+24*v*w3+12*u2*v2+36*u*v2*w+24*v2*w2+6*u*v3+8*v3*w+v4;
float a8 = 2*u*w3+w4; float a8 = 2*u*w3+w4;
float a9 = 2*v3*w+v4; float a9 = 2*v3*w+v4;
...@@ -60,10 +60,10 @@ void main() ...@@ -60,10 +60,10 @@ void main()
vec4 pos = vec4(newPos/12,1); vec4 pos = vec4(newPos/12,1);
vec3 d0 = gl_TessCoord.x * p3; // vec3 d0 = gl_TessCoord.x * p3;
vec3 d1 = gl_TessCoord.y * p6; // vec3 d1 = gl_TessCoord.y * p6;
vec3 d2 = gl_TessCoord.z * p7; // vec3 d2 = gl_TessCoord.z * p7;
pos = vec4((d0 + d1 + d2),1); // pos = vec4((d0 + d1 + d2),1);
tePatchDistance = gl_TessCoord.xyz; tePatchDistance = gl_TessCoord.xyz;
teCamPosition = vec4(MV*pos).xyz; teCamPosition = vec4(MV*pos).xyz;
......
...@@ -76,7 +76,6 @@ void Subdivision::subdivide(Mesh *mesh, int level) { ...@@ -76,7 +76,6 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
current_mesh->update(result.vb_handle,result.vertex_buffer, tables.index_buffer); current_mesh->update(result.vb_handle,result.vertex_buffer, tables.index_buffer);
current_mesh->buffers[currentMax+1]->addRegular(tables.index_regular); current_mesh->buffers[currentMax+1]->addRegular(tables.index_regular);
qDebug()<<tables.index_regular.size();
//return new Mesh(f, mesh, result.vertex_buffer, tables.index_buffer); //return new Mesh(f, mesh, result.vertex_buffer, tables.index_buffer);
} }
......
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