Commit 1c1d13b3 by Philipp Adolf

Use shared_ptr for SubdivEntrys

parent 5493df80
......@@ -86,7 +86,8 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
this->f = f;
buffers.resize(1);
buffers[0].init(f,Vertices,Indices);
buffers[0].reset(new SubdivEntry);
buffers[0]->init(f,Vertices,Indices);
//calc AABB
for (int i = 0; i < Vertices.size(); ++i) {
......@@ -102,8 +103,8 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
}
void Mesh::MeshEntry::update(GLuint VB, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices){
buffers.resize(buffers.size()+1);
SubdivEntry *entry = &buffers[buffers.size()-1];
SubdivEntry *entry = new SubdivEntry;
buffers.push_back(std::shared_ptr<SubdivEntry>(entry));
entry->init(f,VB,Vertices,Indices);
}
......@@ -461,11 +462,11 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
materials[MaterialIndex].texture.bind(f,GL_TEXTURE0);
}
if(entries[index].buffers.size()<= subdivision){
if(entries[index].buffers.size() <= subdivision){
subdivision = entries[index].buffers.size()-1;
}
SubdivEntry *entry = &entries[index].buffers[subdivision];
std::shared_ptr<SubdivEntry> entry = entries[index].buffers[subdivision];
// Draw Vertex Array
f->glBindBuffer(GL_ARRAY_BUFFER, entry->VB_handle);
......
#ifndef MESH_H
#define MESH_H
#include <memory>
#include <QtOpenGL>
#include <QOpenGLFunctions_4_3_Core>
#include <assimp/Importer.hpp>
......@@ -89,7 +90,7 @@ public:
QString name;
QVector<SubdivEntry> buffers;
QVector<std::shared_ptr<SubdivEntry>> buffers;
int materialIndex;
......
#include <memory>
#include "subdivision.h"
Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f)
......@@ -63,7 +65,7 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
if(level <= currentMax)
return;
Mesh::SubdivEntry* entry = &current_mesh->buffers[currentMax];
std::shared_ptr<Mesh::SubdivEntry> entry = current_mesh->buffers[currentMax];
input.vb_handle = entry->VB_handle;
input.vertex_buffer = entry->vertices;
......
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