Commit c2d8d532 by Kai Westerkamp

test

parent 40d7dd3a
......@@ -213,10 +213,24 @@ void MainWidget::paintGL(){
rot.rotate(time/100.0*36/5,QVector3D(0,1,0));
}
regularShader->bind();
regularShader->setUniformValue("wireframe",wireframe);
regularShader->setUniformValue("colorTexture",0);
regularShader->setUniformValue("LightPos",QVector3D(0,100,100));
regularShader->setUniformValue("subdiv",subdivLevel);
mesh->render(regularShader,cam->getMatrix()*rot, m_projection,subdivLevel,true);
regularShader->release();
subdevisionShader->bind();
subdevisionShader->setUniformValue("wireframe",wireframe);
subdevisionShader->setUniformValue("colorTexture",0);
subdevisionShader->setUniformValue("LightPos",QVector3D(0,100,100));
subdevisionShader->setUniformValue("subdiv",1);
mesh->render(subdevisionShader,cam->getMatrix()*rot, m_projection,subdivLevel,false);
......
......@@ -24,26 +24,10 @@ Mesh::SubdivEntry::~SubdivEntry()
void Mesh::SubdivEntry::addRegular(QVector<unsigned int>& Indices){
//TODO fixme
for(int i = 0; i < Indices.length(); i+=3){
// qDebug()<<"T:"<<Indices[i]<<Indices[i+1]<<Indices[i+2];
indicesRegular.push_back(0);//0
indicesRegular.push_back(0);//1
indicesRegular.push_back(0);//2
indicesRegular.push_back(Indices[i]);//3
indicesRegular.push_back(0);//4
indicesRegular.push_back(0);//5
indicesRegular.push_back(Indices[i+1]);//6
indicesRegular.push_back(Indices[i+2]);//7
indicesRegular.push_back(0);//8
indicesRegular.push_back(0);//9
indicesRegular.push_back(0);//10
indicesRegular.push_back(0);//11
}
f->glGenBuffers(1, &IB_handle);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_handle);
indicesRegular = Indices;
indices.clear();
f->glGenBuffers(1, &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);
}
......@@ -477,6 +461,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
if(regular){
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entry->IB_Regular);
f->glPatchParameteri(GL_PATCH_VERTICES, 12);
f->glDrawElements(GL_PATCHES, entry->indicesRegular.size(), GL_UNSIGNED_INT, 0);
} else{
......
......@@ -5,6 +5,8 @@ layout(vertices = 3) out;
in vec3 vPosition[];
out vec3 tcPosition[];
uniform float subdiv;
void main()
{
tcPosition[gl_InvocationID] = vPosition[gl_InvocationID];
......
......@@ -5,12 +5,14 @@ layout(vertices = 12) out;
in vec3 vPosition[];
out vec3 tcPosition[];
uniform float subdiv;
void main()
{
tcPosition[gl_InvocationID] = vPosition[gl_InvocationID];
float tesselation = 1.0;
float tesselation = subdiv;
gl_TessLevelOuter[0] = tesselation;
gl_TessLevelOuter[1] = tesselation;
......
......@@ -56,11 +56,15 @@ void main()
vec3 p10 = tcPosition[10];
vec3 p11 = tcPosition[11];
vec3 newPos= a0*p0+a1*p1+a2*p2+a3*p3+a4*p4+a5*p5+a6*p6+a7*p7+a8*p8+a9*p9+a10*p10+a11*p11;
vec4 pos = vec4(newPos/12,1);
vec3 d0 = gl_TessCoord.x * p3;
vec3 d1 = gl_TessCoord.y * p6;
vec3 d2 = gl_TessCoord.z * p7;
pos = vec4((d0 + d1 + d2),1);
tePatchDistance = gl_TessCoord.xyz;
teCamPosition = vec4(MV*pos).xyz;
gl_Position = MVP * pos;
......
......@@ -75,6 +75,8 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
Result result = runShader(input, tables);
current_mesh->update(result.vb_handle,result.vertex_buffer, tables.index_buffer);
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);
}
......@@ -358,7 +360,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
}
}
qDebug()<<"Precompute Tables Done";
getPatchIndexBuffer(ib);
tables.index_regular = getPatchIndexBuffer(ib);
return tables;
}
......
......@@ -32,6 +32,7 @@ private:
QVector<GLuint> vertex_indices;
QVector<GLuint> vertex_offsets;
QVector<GLuint> index_buffer;
QVector<GLuint> index_regular;
};
struct Result
......
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