Commit 23085e12 by Philipp Adolf

Add Input struct

This will make it easier to iterate over all meshes in subdivide when we want to add that feature.
parent 97ea391e
...@@ -46,33 +46,33 @@ QOpenGLShaderProgram *Subdivision::initComputeShaderProgram(QString &source){ ...@@ -46,33 +46,33 @@ QOpenGLShaderProgram *Subdivision::initComputeShaderProgram(QString &source){
} }
Mesh *Subdivision::subdivide(Mesh *mesh) { Mesh *Subdivision::subdivide(Mesh *mesh) {
// For now we only look at the first mesh entry
Mesh::Node root = mesh->getRootNode();
int first_mesh_index = -1;
if (!root.getFirstMeshIndex(first_mesh_index)) {
qCritical()<<"No mesh found, aborting subdivision";
return NULL;
}
Mesh::MeshEntry *current_mesh = mesh->getMeshEntry(first_mesh_index);
Input input;
input.vb_handle = current_mesh->VB_handle;
input.vertex_buffer = current_mesh->getVertexBuffer();
input.index_buffer = current_mesh->getIndexBuffer();
QVector<QVector<unsigned int> > edgeIndices; QVector<QVector<unsigned int> > edgeIndices;
QVector<unsigned int> vertexIndices; QVector<unsigned int> vertexIndices;
QVector<unsigned int> vertexIndicesOffsets; QVector<unsigned int> vertexIndicesOffsets;
precomputeTables(mesh, edgeIndices, vertexIndices, vertexIndicesOffsets); precomputeTables(input, edgeIndices, vertexIndices, vertexIndicesOffsets);
runShader(mesh, edgeIndices); runShader(input, edgeIndices);
return NULL; return NULL;
} }
void Subdivision::precomputeTables(Mesh *mesh, QVector<QVector<unsigned int> > &edgeIndices_base, void Subdivision::precomputeTables(Input input, QVector<QVector<unsigned int> > &edgeIndices_base,
QVector<unsigned int> &vertexIndices, QVector<unsigned int> &vertexIndicesOffsets) { QVector<unsigned int> &vertexIndices, QVector<unsigned int> &vertexIndicesOffsets) {
Mesh::Node root = mesh->getRootNode(); QVector<unsigned int> ib = input.index_buffer;
QVector<Vertex> vb = input.vertex_buffer;
int firstMeshEntryIndex = -1;
bool meshExists = root.getFirstMeshIndex(firstMeshEntryIndex);
if (!meshExists){
qDebug()<<"No Mesh found. Abort subdiv table precomputation.";
return;
}
qDebug()<<"Mesh found. Index:"<<firstMeshEntryIndex;
//die drei zeilen machen das bild schwarz. wenn man davor returnt tuts.
Mesh::MeshEntry *firstMeshEntry = mesh->getMeshEntry(firstMeshEntryIndex);
QVector<unsigned int> ib = firstMeshEntry->getIndexBuffer();
qDebug()<<"Index Buffer: "<<ib;
QVector<Vertex> vb = firstMeshEntry->getVertexBuffer();
//qDebug()<<"Vertex Buffer: "<<vb;
//compute edge table //compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices. //Format: first two entries: edge vertices. last two entries: distant vertices.
...@@ -264,25 +264,11 @@ void Subdivision::precomputeTables(Mesh *mesh, QVector<QVector<unsigned int> > & ...@@ -264,25 +264,11 @@ void Subdivision::precomputeTables(Mesh *mesh, QVector<QVector<unsigned int> > &
} }
void Subdivision::runShader(Mesh *mesh, QVector<QVector<unsigned int> > &edgeIndices) { void Subdivision::runShader(Input input, QVector<QVector<unsigned int> > &edgeIndices) {
qDebug()<<"Running compute shader"; qDebug()<<"Running compute shader";
Mesh::Node root = mesh->getRootNode();
int firstMeshEntryIndex = -1;
bool meshExists = root.getFirstMeshIndex(firstMeshEntryIndex);
if (!meshExists){
qDebug()<<"No Mesh found. Abort shader execution.";
return;
}
qDebug()<<"Mesh found. Index:"<<firstMeshEntryIndex;
Mesh::MeshEntry *firstMeshEntry = mesh->getMeshEntry(firstMeshEntryIndex);
GLuint vb_handle = firstMeshEntry->VB_handle;
QVector<Vertex> vb = firstMeshEntry->getVertexBuffer();
edgeShader->bind(); edgeShader->bind();
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, vb_handle); f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, input.vb_handle);
GLuint *edgeIDs = new GLuint[edgeIndices.size() * 4]; GLuint *edgeIDs = new GLuint[edgeIndices.size() * 4];
for (uint i = 0; i < edgeIndices.size(); i++) { for (uint i = 0; i < edgeIndices.size(); i++) {
......
...@@ -16,13 +16,20 @@ public: ...@@ -16,13 +16,20 @@ public:
Mesh *subdivide(Mesh *mesh); Mesh *subdivide(Mesh *mesh);
private: private:
struct Input
{
GLuint vb_handle;
QVector<unsigned int> index_buffer;
QVector<Vertex> vertex_buffer;
};
QOpenGLFunctions_4_3_Core *f; QOpenGLFunctions_4_3_Core *f;
QOpenGLShaderProgram *edgeShader; QOpenGLShaderProgram *edgeShader;
QOpenGLShaderProgram *initComputeShaderProgram(QString &source); QOpenGLShaderProgram *initComputeShaderProgram(QString &source);
void precomputeTables(Mesh *mesh, QVector<QVector<unsigned int> > &edgeIndices_base, void precomputeTables(Input input, QVector<QVector<unsigned int> > &edgeIndices_base,
QVector<unsigned int> &vertexIndices, QVector<unsigned int> &vertexIndicesOffsets); QVector<unsigned int> &vertexIndices, QVector<unsigned int> &vertexIndicesOffsets);
void runShader(Mesh *mesh, QVector<QVector<unsigned int> > &edgeIndices); void runShader(Input input, QVector<QVector<unsigned int> > &edgeIndices);
QVector<unsigned int> fillVector(unsigned int a, unsigned int b, unsigned int c,unsigned int d); QVector<unsigned int> fillVector(unsigned int a, unsigned int b, unsigned int c,unsigned int d);
}; };
......
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